def put(self, id: int) -> bool: """ Change the track details :param id: The ID of the track :return: Always true """ args = self._parser.parse_args(strict=True) track = library.Track(id) if args['title'] is not None: track.title = args['title'] if args['artist'] is not None: track.artist = args['artist'] return True
def get(self, id: int) -> typing.Dict: """ Get the track information for a given track :param id: The ID of the track :return: The track information """ track = library.Track(id) last_play = track.last_play() return { 'title': track.title, 'artist': track.artist, 'length': track.length, 'last_play': None if last_play is None else last_play.isoformat() }
def get(self, id: int) -> typing.Dict: """ Get a list of all the tracks matching the query :param id: The ID of the track :return: A list of all tracks matching """ def generate(track_): with open(track_.location, 'rb') as file_: data = file_.read(1024) while data: yield data data = file_.read(1024) track = library.Track(id) mimetype, encoding = mimetypes.guess_type(track.location) if mimetype is None: mimetype = 'audio/mpeg' return flask.Response(generate(track), mimetype=mimetype)
def put(self, id: int) -> bool: """ Change the track details :param id: The ID of the track :return: Always true """ args = self._parser.parse_args(strict=True) track = library.Track(id) if args.title is not None: track.title = args.title if args.artist is not None: track.artist = args.artist socketio = flask.current_app.extensions['socketio'] socketio.emit( 'track_update', { 'id': id, 'title': track.title, 'artist': track.artist, 'length': track.length }) return True