Merge PR #1343 from blueyed/track_to_mpd_format-skip-empty-uri into release-1.1
Rebased from develop onto release-1.1, fixed tests, and added changelog. Fixes #1343
This commit is contained in:
commit
d79d44747d
@ -26,6 +26,8 @@ Bug fix release.
|
||||
- Main: Catch errors when loading :confval:`logging/config_file`. (Fixes:
|
||||
:issue:`1320`)
|
||||
|
||||
- MPD: Don't return tracks with empty URIs. (Partly fixes: :issue:`1340`)
|
||||
|
||||
|
||||
v1.1.1 (2015-09-14)
|
||||
===================
|
||||
|
||||
@ -1,11 +1,15 @@
|
||||
from __future__ import absolute_import, unicode_literals
|
||||
|
||||
import datetime
|
||||
import logging
|
||||
import re
|
||||
|
||||
from mopidy.models import TlTrack
|
||||
from mopidy.mpd.protocol import tagtype_list
|
||||
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
# TODO: special handling of local:// uri scheme
|
||||
normalize_path_re = re.compile(r'[^/]+')
|
||||
|
||||
@ -34,8 +38,12 @@ def track_to_mpd_format(track, position=None, stream_title=None):
|
||||
else:
|
||||
(tlid, track) = (None, track)
|
||||
|
||||
if not track.uri:
|
||||
logger.warning('Ignoring track without uri')
|
||||
return []
|
||||
|
||||
result = [
|
||||
('file', track.uri or ''),
|
||||
('file', track.uri),
|
||||
('Time', track.length and (track.length // 1000) or 0),
|
||||
('Artist', concat_multi_values(track.artists, 'name')),
|
||||
('Album', track.album and track.album.name or ''),
|
||||
@ -164,7 +172,9 @@ def tracks_to_mpd_format(tracks, start=0, end=None):
|
||||
assert len(tracks) == len(positions)
|
||||
result = []
|
||||
for track, position in zip(tracks, positions):
|
||||
result.append(track_to_mpd_format(track, position))
|
||||
formatted_track = track_to_mpd_format(track, position)
|
||||
if formatted_track:
|
||||
result.append(formatted_track)
|
||||
return result
|
||||
|
||||
|
||||
|
||||
@ -56,7 +56,7 @@ class TrackMpdFormatTest(unittest.TestCase):
|
||||
|
||||
def test_track_to_mpd_format_with_position_and_tlid(self):
|
||||
result = translator.track_to_mpd_format(
|
||||
TlTrack(2, Track()), position=1)
|
||||
TlTrack(2, Track(uri='a uri')), position=1)
|
||||
self.assertIn(('Pos', 1), result)
|
||||
self.assertIn(('Id', 2), result)
|
||||
|
||||
@ -153,13 +153,17 @@ class PlaylistMpdFormatTest(unittest.TestCase):
|
||||
|
||||
def test_mpd_format(self):
|
||||
playlist = Playlist(tracks=[
|
||||
Track(track_no=1), Track(track_no=2), Track(track_no=3)])
|
||||
Track(uri='foo', track_no=1),
|
||||
Track(uri='bar', track_no=2),
|
||||
Track(uri='baz', track_no=3)])
|
||||
result = translator.playlist_to_mpd_format(playlist)
|
||||
self.assertEqual(len(result), 3)
|
||||
|
||||
def test_mpd_format_with_range(self):
|
||||
playlist = Playlist(tracks=[
|
||||
Track(track_no=1), Track(track_no=2), Track(track_no=3)])
|
||||
Track(uri='foo', track_no=1),
|
||||
Track(uri='bar', track_no=2),
|
||||
Track(uri='baz', track_no=3)])
|
||||
result = translator.playlist_to_mpd_format(playlist, 1, 2)
|
||||
self.assertEqual(len(result), 1)
|
||||
self.assertEqual(dict(result[0])['Track'], 2)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user