mpd: Use file:// URIs in tag_cache
file:// URIs are uriencoded, and will thus conserve the encoding of the file paths. We cannot just convert file paths in other encodings to UTF-8, because then we won't find the files we point to.
This commit is contained in:
parent
4e4df2adf2
commit
beac2e80ed
@ -154,7 +154,6 @@ def tracks_to_tag_cache_format(tracks):
|
||||
|
||||
def _add_to_tag_cache(result, folders, files):
|
||||
music_folder = settings.LOCAL_MUSIC_PATH
|
||||
regexp = '^' + re.escape(music_folder).rstrip('/') + '/?'
|
||||
|
||||
for path, entry in folders.items():
|
||||
name = os.path.split(path)[1]
|
||||
@ -168,9 +167,8 @@ def _add_to_tag_cache(result, folders, files):
|
||||
result.append(('songList begin',))
|
||||
for track in files:
|
||||
track_result = dict(track_to_mpd_format(track))
|
||||
path = uri_to_path(track_result['file'])
|
||||
track_result['mtime'] = get_mtime(path)
|
||||
track_result['file'] = re.sub(regexp, '', path)
|
||||
track_result['mtime'] = get_mtime(uri_to_path(track_result['file']))
|
||||
track_result['file'] = track_result['file']
|
||||
track_result['key'] = os.path.basename(track_result['file'])
|
||||
track_result = order_mpd_track_info(track_result.items())
|
||||
result.extend(track_result)
|
||||
|
||||
@ -4,7 +4,7 @@ import datetime
|
||||
import os
|
||||
|
||||
from mopidy import settings
|
||||
from mopidy.utils.path import mtime, uri_to_path
|
||||
from mopidy.utils.path import mtime
|
||||
from mopidy.frontends.mpd import translator, protocol
|
||||
from mopidy.models import Album, Artist, TlTrack, Playlist, Track
|
||||
|
||||
@ -131,10 +131,7 @@ class TracksToTagCacheFormatTest(unittest.TestCase):
|
||||
mtime.undo_fake()
|
||||
|
||||
def translate(self, track):
|
||||
folder = settings.LOCAL_MUSIC_PATH
|
||||
result = dict(translator.track_to_mpd_format(track))
|
||||
result['file'] = uri_to_path(result['file'])
|
||||
result['file'] = result['file'][len(folder) + 1:]
|
||||
result['key'] = os.path.basename(result['file'])
|
||||
result['mtime'] = mtime('')
|
||||
return translator.order_mpd_track_info(result.items())
|
||||
@ -197,7 +194,7 @@ class TracksToTagCacheFormatTest(unittest.TestCase):
|
||||
result = self.consume_headers(result)
|
||||
song_list, result = self.consume_song_list(result)
|
||||
|
||||
self.assertEqual(song_list, formated)
|
||||
self.assertEqual(formated, song_list)
|
||||
self.assertEqual(len(result), 0)
|
||||
|
||||
def test_tag_cache_has_formated_track_with_key_and_mtime(self):
|
||||
@ -208,7 +205,7 @@ class TracksToTagCacheFormatTest(unittest.TestCase):
|
||||
result = self.consume_headers(result)
|
||||
song_list, result = self.consume_song_list(result)
|
||||
|
||||
self.assertEqual(song_list, formated)
|
||||
self.assertEqual(formated, song_list)
|
||||
self.assertEqual(len(result), 0)
|
||||
|
||||
def test_tag_cache_suports_directories(self):
|
||||
@ -224,7 +221,7 @@ class TracksToTagCacheFormatTest(unittest.TestCase):
|
||||
|
||||
song_list, result = self.consume_song_list(folder)
|
||||
self.assertEqual(len(result), 0)
|
||||
self.assertEqual(song_list, formated)
|
||||
self.assertEqual(formated, song_list)
|
||||
|
||||
def test_tag_cache_diretory_header_is_right(self):
|
||||
track = Track(uri='file:///dir/subdir/folder/sub/song.mp3')
|
||||
@ -256,7 +253,7 @@ class TracksToTagCacheFormatTest(unittest.TestCase):
|
||||
|
||||
song_list, result = self.consume_song_list(folder)
|
||||
self.assertEqual(len(result), 0)
|
||||
self.assertEqual(song_list, formated)
|
||||
self.assertEqual(formated, song_list)
|
||||
|
||||
def test_tag_cache_supports_multiple_tracks(self):
|
||||
tracks = [
|
||||
@ -273,7 +270,7 @@ class TracksToTagCacheFormatTest(unittest.TestCase):
|
||||
result = self.consume_headers(result)
|
||||
song_list, result = self.consume_song_list(result)
|
||||
|
||||
self.assertEqual(song_list, formated)
|
||||
self.assertEqual(formated, song_list)
|
||||
self.assertEqual(len(result), 0)
|
||||
|
||||
def test_tag_cache_supports_multiple_tracks_in_dirs(self):
|
||||
@ -292,12 +289,12 @@ class TracksToTagCacheFormatTest(unittest.TestCase):
|
||||
folder, result = self.consume_directory(result)
|
||||
song_list, song_result = self.consume_song_list(folder)
|
||||
|
||||
self.assertEqual(song_list, formated[1])
|
||||
self.assertEqual(formated[1], song_list)
|
||||
self.assertEqual(len(song_result), 0)
|
||||
|
||||
song_list, result = self.consume_song_list(result)
|
||||
self.assertEqual(len(result), 0)
|
||||
self.assertEqual(song_list, formated[0])
|
||||
self.assertEqual(formated[0], song_list)
|
||||
|
||||
|
||||
class TracksToDirectoryTreeTest(unittest.TestCase):
|
||||
|
||||
Loading…
Reference in New Issue
Block a user