einsteinx2/WaveBox — pull request #143 by mdlayher (2013-08-09 03:15:40+00:00)
Title: NowPlaying Service!

I got the urge to work on this today, so here it is! I've created a service which keeps track of the currently playing song by user and client name. It supports both Song and Video objects, and works as follows:

- User hits stream or transcode APIs
- If `NowPlayingService` is running, media item is registered
- If a track is already registered with matching user name and client name, the track is overwritten.
- If track is not registered, it is added to the list.
- A timer is set to expire at the end of a song's duration, so that songs are guaranteed to expire and be unregistered at the end of their play time, without need for client intervention.

To interface with this service, I have created the `NowPlayingApiHandler`. When provided no parameters, this handler returns a list of all currently playing media. When provided a user, it filters only now playing tracks for a given user. When provided a client, it filters only now playing tracks for a given client. Both can be used in tandem as well.

The only part I'm a bit dissatisfied with is that I am currently using a list of `Dictionary`, rather than a full-fledged object. Because this "model" would never touch the database, I felt that I should leave it this way. This may be reworked after some discussion!