m3u: Derive track name from file name for non-extended M3U playlists.
This commit is contained in:
parent
ede5b8abff
commit
22690ee5a9
@ -39,6 +39,12 @@ Local backend
|
|||||||
- Made :confval:`local/data_dir` really deprecated. This change breaks older
|
- Made :confval:`local/data_dir` really deprecated. This change breaks older
|
||||||
versions of Mopidy-Local-SQLite and Mopidy-Local-Images.
|
versions of Mopidy-Local-SQLite and Mopidy-Local-Images.
|
||||||
|
|
||||||
|
M3U backend
|
||||||
|
-----------
|
||||||
|
|
||||||
|
- Derive track name from file name for non-extended M3U
|
||||||
|
playlists. (Fixes: :issue:`1364`, PR: :issue:`1369`)
|
||||||
|
|
||||||
MPD frontend
|
MPD frontend
|
||||||
------------
|
------------
|
||||||
|
|
||||||
|
|||||||
@ -99,7 +99,9 @@ def parse_m3u(file_path, media_dir=None):
|
|||||||
if extended and line.startswith('#EXTINF'):
|
if extended and line.startswith('#EXTINF'):
|
||||||
track = m3u_extinf_to_track(line)
|
track = m3u_extinf_to_track(line)
|
||||||
continue
|
continue
|
||||||
|
if not track.name:
|
||||||
|
name = os.path.basename(os.path.splitext(line)[0])
|
||||||
|
track = track.replace(name=urllib.parse.unquote(name))
|
||||||
if urllib.parse.urlsplit(line).scheme:
|
if urllib.parse.urlsplit(line).scheme:
|
||||||
tracks.append(track.replace(uri=line))
|
tracks.append(track.replace(uri=line))
|
||||||
elif os.path.normpath(line) == os.path.abspath(line):
|
elif os.path.normpath(line) == os.path.abspath(line):
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
#EXTM3U
|
#EXTM3U
|
||||||
# test
|
# test
|
||||||
#EXTINF:-1,song1
|
#EXTINF:-1,Song #1
|
||||||
# test
|
# test
|
||||||
song1.mp3
|
song1.mp3
|
||||||
|
|||||||
@ -1,3 +1,3 @@
|
|||||||
#EXTM3U
|
#EXTM3U
|
||||||
#EXTINF:-1,song1
|
#EXTINF:-1,Song #1
|
||||||
song1.mp3
|
song1.mp3
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
#EXTM3U
|
#EXTM3U
|
||||||
#EXTINF:-1,song1
|
#EXTINF:-1,Song #1
|
||||||
song1.mp3
|
song1.mp3
|
||||||
#EXTINF:60,song2
|
#EXTINF:60,Song #2
|
||||||
song2.mp3
|
song2.mp3
|
||||||
|
|||||||
@ -20,13 +20,15 @@ encoded_path = path_to_data_dir('æøå.mp3')
|
|||||||
song1_uri = path.path_to_uri(song1_path)
|
song1_uri = path.path_to_uri(song1_path)
|
||||||
song2_uri = path.path_to_uri(song2_path)
|
song2_uri = path.path_to_uri(song2_path)
|
||||||
song3_uri = path.path_to_uri(song3_path)
|
song3_uri = path.path_to_uri(song3_path)
|
||||||
|
song4_uri = 'http://example.com/foo%20bar.mp3'
|
||||||
encoded_uri = path.path_to_uri(encoded_path)
|
encoded_uri = path.path_to_uri(encoded_path)
|
||||||
song1_track = Track(uri=song1_uri)
|
song1_track = Track(name='song1', uri=song1_uri)
|
||||||
song2_track = Track(uri=song2_uri)
|
song2_track = Track(name='song2', uri=song2_uri)
|
||||||
song3_track = Track(uri=song3_uri)
|
song3_track = Track(name='φοο', uri=song3_uri)
|
||||||
encoded_track = Track(uri=encoded_uri)
|
song4_track = Track(name='foo bar', uri=song4_uri)
|
||||||
song1_ext_track = song1_track.replace(name='song1')
|
encoded_track = Track(name='æøå', uri=encoded_uri)
|
||||||
song2_ext_track = song2_track.replace(name='song2', length=60000)
|
song1_ext_track = song1_track.replace(name='Song #1')
|
||||||
|
song2_ext_track = song2_track.replace(name='Song #2', length=60000)
|
||||||
encoded_ext_track = encoded_track.replace(name='æøå')
|
encoded_ext_track = encoded_track.replace(name='æøå')
|
||||||
|
|
||||||
|
|
||||||
@ -84,9 +86,11 @@ class M3UToUriTest(unittest.TestCase):
|
|||||||
def test_file_with_uri(self):
|
def test_file_with_uri(self):
|
||||||
with tempfile.NamedTemporaryFile(delete=False) as tmp:
|
with tempfile.NamedTemporaryFile(delete=False) as tmp:
|
||||||
tmp.write(song1_uri)
|
tmp.write(song1_uri)
|
||||||
|
tmp.write('\n')
|
||||||
|
tmp.write(song4_uri)
|
||||||
try:
|
try:
|
||||||
tracks = self.parse(tmp.name)
|
tracks = self.parse(tmp.name)
|
||||||
self.assertEqual([song1_track], tracks)
|
self.assertEqual([song1_track, song4_track], tracks)
|
||||||
finally:
|
finally:
|
||||||
if os.path.exists(tmp.name):
|
if os.path.exists(tmp.name):
|
||||||
os.remove(tmp.name)
|
os.remove(tmp.name)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user