From 1379c38370770a994da67bbe48c2fff297f0b600 Mon Sep 17 00:00:00 2001 From: Thomas Adamcik Date: Thu, 5 Dec 2013 22:56:19 +0100 Subject: [PATCH] audio: Improve audio_data_to_track handling. - Handle missing or none data for duration and mtime - Add organization, location and copyright mapping used for streams. --- mopidy/audio/scan.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/mopidy/audio/scan.py b/mopidy/audio/scan.py index 6999d664..f797a84d 100644 --- a/mopidy/audio/scan.py +++ b/mopidy/audio/scan.py @@ -132,7 +132,7 @@ def audio_data_to_track(data): def _retrieve(source_key, target_key, target): if source_key in data: - target[target_key] = data[source_key] + target.setdefault(target_key, data[source_key]) _retrieve(gst.TAG_ALBUM, 'name', album_kwargs) _retrieve(gst.TAG_TRACK_COUNT, 'num_tracks', album_kwargs) @@ -155,6 +155,11 @@ def audio_data_to_track(data): _retrieve( 'musicbrainz-albumartistid', 'musicbrainz_id', albumartist_kwargs) + # For streams, will not override if a better value has already been set. + _retrieve(gst.TAG_ORGANIZATION, 'name', track_kwargs) + _retrieve(gst.TAG_LOCATION, 'comment', track_kwargs) + _retrieve(gst.TAG_COPYRIGHT, 'comment', track_kwargs) + if gst.TAG_DATE in data and data[gst.TAG_DATE]: date = data[gst.TAG_DATE] try: @@ -167,9 +172,13 @@ def audio_data_to_track(data): if albumartist_kwargs: album_kwargs['artists'] = [Artist(**albumartist_kwargs)] + if data['mtime']: + track_kwargs['last_modified'] = int(data['mtime']) + + if data[gst.TAG_DURATION]: + track_kwargs['length'] = data[gst.TAG_DURATION] // gst.MSECOND + track_kwargs['uri'] = data['uri'] - track_kwargs['last_modified'] = int(data['mtime']) - track_kwargs['length'] = data[gst.TAG_DURATION] // gst.MSECOND track_kwargs['album'] = Album(**album_kwargs) if ('name' in artist_kwargs