Substitute file: with file:// all over
This commit is contained in:
parent
d24a81425c
commit
c93d8470ce
@ -170,8 +170,8 @@ class GStreamerStoredPlaylistsController(BaseStoredPlaylistsController):
|
||||
|
||||
with open(file_path, 'w') as file:
|
||||
for track in playlist.tracks:
|
||||
if track.uri.startswith('file:'):
|
||||
file.write(track.uri[len('file:'):] + '\n')
|
||||
if track.uri.startswith('file://'):
|
||||
file.write(track.uri[len('file://'):] + '\n')
|
||||
else:
|
||||
file.write(track.uri + '\n')
|
||||
|
||||
|
||||
@ -124,11 +124,11 @@ def m3u_to_uris(file_path):
|
||||
if line.startswith('#'):
|
||||
continue
|
||||
|
||||
if line.startswith('file:'):
|
||||
if line.startswith('file://'):
|
||||
uris.append(line)
|
||||
else:
|
||||
file = os.path.join(folder, line)
|
||||
path = urllib.pathname2url(file.encode('utf-8'))
|
||||
uris.append('file:' + path)
|
||||
uris.append('file://' + path)
|
||||
|
||||
return uris
|
||||
|
||||
@ -14,7 +14,7 @@ folder = os.path.dirname(__file__)
|
||||
folder = os.path.join(folder, '..', 'data')
|
||||
folder = os.path.abspath(folder)
|
||||
song = os.path.join(folder, 'song%s.wav')
|
||||
generate_song = lambda i: 'file:' + urllib.pathname2url(song % i)
|
||||
generate_song = lambda i: 'file://' + urllib.pathname2url(song % i)
|
||||
|
||||
# FIXME can be switched to generic test
|
||||
class GStreamerCurrentPlaylistHandlerTest(BaseCurrentPlaylistControllerTest, unittest.TestCase):
|
||||
@ -28,7 +28,7 @@ class GStreamerPlaybackControllerTest(BasePlaybackControllerTest, unittest.TestC
|
||||
backend_class = GStreamerBackend
|
||||
|
||||
def add_track(self, file):
|
||||
uri = 'file:' + urllib.pathname2url(os.path.join(folder, file))
|
||||
uri = 'file://' + urllib.pathname2url(os.path.join(folder, file))
|
||||
track = Track(uri=uri, id=1, length=4464)
|
||||
self.backend.current_playlist.add(track)
|
||||
|
||||
@ -82,7 +82,7 @@ class GStreamerBackendStoredPlaylistsControllerTest(BaseStoredPlaylistsControlle
|
||||
|
||||
def test_playlist_contents_get_written_to_disk(self):
|
||||
track = Track(uri=generate_song(1))
|
||||
uri = track.uri[len('file:'):]
|
||||
uri = track.uri[len('file://'):]
|
||||
playlist = Playlist(tracks=[track], name='test')
|
||||
file_path = os.path.join(settings.PLAYLIST_FOLDER, 'test.m3u')
|
||||
|
||||
@ -95,7 +95,7 @@ class GStreamerBackendStoredPlaylistsControllerTest(BaseStoredPlaylistsControlle
|
||||
|
||||
def test_playlists_are_loaded_at_startup(self):
|
||||
track = Track(uri=generate_song(1))
|
||||
uri = track.uri[len('file:'):]
|
||||
uri = track.uri[len('file://'):]
|
||||
playlist = Playlist(tracks=[track], name='test')
|
||||
file_path = os.path.join(settings.PLAYLIST_FOLDER, 'test.m3u')
|
||||
|
||||
|
||||
@ -17,9 +17,9 @@ def data(name):
|
||||
song1_path = data('song1.mp3')
|
||||
song2_path = data('song2.mp3')
|
||||
encoded_path = data(u'æøå.mp3')
|
||||
song1_uri = 'file:' + urllib.pathname2url(song1_path)
|
||||
song2_uri = 'file:' + urllib.pathname2url(song2_path)
|
||||
encoded_uri = 'file:' + urllib.pathname2url(encoded_path.encode('utf-8'))
|
||||
song1_uri = 'file://' + urllib.pathname2url(song1_path)
|
||||
song2_uri = 'file://' + urllib.pathname2url(song2_path)
|
||||
encoded_uri = 'file://' + urllib.pathname2url(encoded_path.encode('utf-8'))
|
||||
|
||||
|
||||
class M3UToUriTest(unittest.TestCase):
|
||||
@ -39,9 +39,8 @@ class M3UToUriTest(unittest.TestCase):
|
||||
with tempfile.NamedTemporaryFile() as file:
|
||||
file.write(song1_path)
|
||||
file.flush()
|
||||
|
||||
uris = m3u_to_uris(file.name)
|
||||
self.assertEqual([song1_uri], uris)
|
||||
self.assertEqual([song1_uri], uris)
|
||||
|
||||
def test_file_with_multiple_absolute_files(self):
|
||||
with tempfile.NamedTemporaryFile() as file:
|
||||
@ -49,17 +48,15 @@ class M3UToUriTest(unittest.TestCase):
|
||||
file.write('# comment \n')
|
||||
file.write(song2_path)
|
||||
file.flush()
|
||||
|
||||
uris = m3u_to_uris(file.name)
|
||||
self.assertEqual([song1_uri, song2_uri], uris)
|
||||
self.assertEqual([song1_uri, song2_uri], uris)
|
||||
|
||||
def test_file_with_uri(self):
|
||||
with tempfile.NamedTemporaryFile() as file:
|
||||
file.write(song1_uri)
|
||||
file.flush()
|
||||
|
||||
uris = m3u_to_uris(file.name)
|
||||
self.assertEqual([song1_uri], uris)
|
||||
self.assertEqual([song1_uri], uris)
|
||||
|
||||
def test_encoding_is_latin1(self):
|
||||
uris = m3u_to_uris(data('encoding.m3u'))
|
||||
|
||||
Loading…
Reference in New Issue
Block a user