def stream(self, **kwargs): user = cherrypy.request.user user.active = datetime.datetime.now() remotes.update_user(user) if 'dead' in kwargs and kwargs['dead'] == 'true': raise cherrypy.HTTPError(status=503) if 'User-Agent' in cherrypy.request.headers: user_agent = cherrypy.request.headers['User-Agent'] else: user_agent = None # allow only one streaming client at once, or weird things might occur if (user.id in Play.STREAM_PLAYING and Play.STREAM_PLAYING[user.id] is not None and Play.STREAM_PLAYING[user.id] != user_agent): raise cherrypy.HTTPError(status=503) if user.id in Play.STREAM_MODE and Play.STREAM_MODE[user.id] is not None: mode = Play.STREAM_MODE[user.id] else: mode = 'regular' if mode == "random": track = queue_dao.get_random_track(user.id) current_seconds = 0 else: queue = queue_dao.get_next(user.id) if queue is not None: track = queue.track current_seconds = queue.current_seconds else: track = None if track is None: raise cherrypy.HTTPError(status=409) transcoder, format = transcoding.determine_transcoder( track, user_agent, [accept.value for accept in cherrypy.request.headers.elements('Accept')] ) cherrypy.log( '%s is streaming "%s" in %s (original was %s) with "%s"' % (user.login, track, format, track.format, user_agent) ) cherrypy.response.headers['Content-Type'] = format def track_generator(): yield track, current_seconds return transcoding.transcode(track_generator(), transcoder)
def test_transcode(self): library_start() # test ogg def track_generator(): yield self.session.query(Track).filter(Track.name == "opmuse").one(), 0 for data in transcoding.transcode(track_generator()): assert b"Ogg" in magic.from_buffer(data) break else: assert False # test mp3 def track_generator(): yield self.session.query(Track).filter(Track.name == "opmuse mp3").one(), 0 for data in transcoding.transcode(track_generator()): assert b"ID3" in magic.from_buffer(data) break else: assert False # TODO test skipping # test ogg to mp3 def track_generator(): yield self.session.query(Track).filter(Track.name == "opmuse").one(), 0 for data in transcoding.transcode(track_generator(), Mp3FFMPEGTranscoder): assert b"ID3" in magic.from_buffer(data) break else: assert False # test mp3 to ogg def track_generator(): yield self.session.query(Track).filter(Track.name == "opmuse mp3").one(), 0 for data in transcoding.transcode(track_generator(), OggFFMPEGTranscoder): assert b"Ogg" in magic.from_buffer(data) break else: assert False