mirror of
https://github.com/beetbox/beets.git
synced 2025-12-15 13:07:09 +01:00
more bytecasting in smartplaylist plugin
This commit is contained in:
parent
7c77201857
commit
cb54955485
2 changed files with 11 additions and 8 deletions
|
|
@ -20,7 +20,7 @@ from __future__ import division, absolute_import, print_function
|
|||
|
||||
from beets.plugins import BeetsPlugin
|
||||
from beets import ui
|
||||
from beets.util import mkdirall, normpath, syspath
|
||||
from beets.util import mkdirall, normpath, syspath, bytestring_path
|
||||
from beets.library import Item, Album, parse_query_string
|
||||
from beets.dbcore import OrQuery
|
||||
from beets.dbcore.query import MultipleSort, ParsingError
|
||||
|
|
@ -165,6 +165,7 @@ class SmartPlaylistPlugin(BeetsPlugin):
|
|||
len(self._matched_playlists))
|
||||
|
||||
playlist_dir = self.config['playlist_dir'].as_filename()
|
||||
playlist_dir = bytestring_path(playlist_dir)
|
||||
relative_to = self.config['relative_to'].get()
|
||||
if relative_to:
|
||||
relative_to = normpath(relative_to)
|
||||
|
|
@ -194,9 +195,11 @@ class SmartPlaylistPlugin(BeetsPlugin):
|
|||
m3us[m3u_name].append(item_path)
|
||||
# Now iterate through the m3us that we need to generate
|
||||
for m3u in m3us:
|
||||
m3u_path = normpath(os.path.join(playlist_dir, m3u))
|
||||
m3u_path = normpath(os.path.join(playlist_dir,
|
||||
bytestring_path(m3u)))
|
||||
mkdirall(m3u_path)
|
||||
with open(syspath(m3u_path), 'wb') as f:
|
||||
for path in m3us[m3u]:
|
||||
f.write(path + b'\n')
|
||||
|
||||
self._log.info(u"{0} playlists updated", len(self._matched_playlists))
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ from beetsplug.smartplaylist import SmartPlaylistPlugin
|
|||
from beets.library import Item, Album, parse_query_string
|
||||
from beets.dbcore import OrQuery
|
||||
from beets.dbcore.query import NullSort, MultipleSort, FixedFieldSort
|
||||
from beets.util import syspath
|
||||
from beets.util import syspath, bytestring_path
|
||||
from beets.ui import UserError
|
||||
from beets import config
|
||||
|
||||
|
|
@ -156,10 +156,10 @@ class SmartPlaylistTest(unittest.TestCase):
|
|||
lib = Mock()
|
||||
lib.items.return_value = [i]
|
||||
lib.albums.return_value = []
|
||||
pl = 'my_playlist.m3u', (q, None), (a_q, None)
|
||||
pl = b'my_playlist.m3u', (q, None), (a_q, None)
|
||||
spl._matched_playlists = [pl]
|
||||
|
||||
dir = mkdtemp()
|
||||
dir = bytestring_path(mkdtemp())
|
||||
config['smartplaylist']['relative_to'] = False
|
||||
config['smartplaylist']['playlist_dir'] = dir
|
||||
try:
|
||||
|
|
@ -177,7 +177,7 @@ class SmartPlaylistTest(unittest.TestCase):
|
|||
content = f.read()
|
||||
rmtree(dir)
|
||||
|
||||
self.assertEqual(content, "/tagada.mp3\n")
|
||||
self.assertEqual(content, b'/tagada.mp3\n')
|
||||
|
||||
|
||||
class SmartPlaylistCLITest(unittest.TestCase, TestHelper):
|
||||
|
|
@ -203,7 +203,7 @@ class SmartPlaylistCLITest(unittest.TestCase, TestHelper):
|
|||
self.run_with_output(u'splupdate', u'tagada')
|
||||
|
||||
self.run_with_output(u'splupdate', u'my_playlist')
|
||||
m3u_path = path.join(self.temp_dir, 'my_playlist.m3u')
|
||||
m3u_path = path.join(self.temp_dir, b'my_playlist.m3u')
|
||||
self.assertTrue(path.exists(m3u_path))
|
||||
with open(m3u_path, 'rb') as f:
|
||||
self.assertEqual(f.read(), self.item.path + b"\n")
|
||||
|
|
@ -215,7 +215,7 @@ class SmartPlaylistCLITest(unittest.TestCase, TestHelper):
|
|||
remove(m3u_path)
|
||||
|
||||
self.run_with_output(u'splupdate')
|
||||
for name in (u'my_playlist.m3u', u'all.m3u'):
|
||||
for name in (b'my_playlist.m3u', b'all.m3u'):
|
||||
with open(path.join(self.temp_dir, name), 'rb') as f:
|
||||
self.assertEqual(f.read(), self.item.path + b"\n")
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue