LET'S CLone MPLAYER

Okay, not really. But close enough :-)

FEATURES

Playback
Show song information
Display progress
Stop

Which should be easy enough, right?
Buuut...

The current state of python media PLAYBACK

Python is great for lots of things. Writing web applications, scripting servers, data analysis. You name it, there's a library for it.

THE CURRENT STATE OF PYTHON MEDIA PLAYBACK

Want to write a media player? You're out of luck. PyMedia, a leading contender for THE library of choice for media playback, has been dead since 2006. PyFFMpeg, the Python bindings for the popular FFMpeg library, broke after the latter API changed, and hasn't been fixed since.

THE CURRENT STATE OF PYTHON MEDIA PLAYBACK

This leaves PyGame as our only option, though it's primary use case is video game development. It's not perfect, but it will do.

        import pygame
        
        pygame.mixer.music.load(filename)
    

READING MEDIA FILE METADATA

For reading file metadata, we're spoilt for choice.
I went with Mutagen, which has support for reading the ID3 tags typically used in MP3s, along with PyDub for extracting the song duration.
    from pydub import AudioSegment
    from mutagen.easyid3 import EasyID3

The command line

Remember, MPlayer is primarily a shell application,
so any self-respecting clone will keep the tradition.

beautiful cli tools

Clint!
    
        from clint import textui
        
        print textui.colored.blue("Look! Pretty colours")
        # Easy progress bars in the shell, too? Is it Christmas already?
        # Elegant implementation of progress bars using iterators
        progress_bar = textui.progress.bar(range(song_length))
    

how big is it?

Cheza: 93 lines of code
MPlayer: 451,878


MPlayer, of course, does a lot more than Cheza ever will,
but I hope that gives you a taste of the power of Python.

LET'S CLone MPLAYER

By Okal Otieno

LET'S CLone MPLAYER

  • 245