Fix optional relative_to

This commit is contained in:
Dang Mai 2013-01-30 08:25:18 -05:00
parent 4312fd3914
commit 70240bf4b1

View file

@ -2,7 +2,7 @@ from __future__ import print_function
from beets.plugins import BeetsPlugin
from beets import config, ui
from beets.util import syspath
from beets.util import normpath, syspath
import os
database_changed = False
@ -12,10 +12,16 @@ library = None
def update_playlists(lib):
playlists = config['smartplaylist']['playlists'].get(list)
playlist_dir = config['smartplaylist']['playlist_dir'].get(unicode)
relative_to = config['smartplaylist']['relative_to'].get(unicode)
relative_to = config['smartplaylist']['relative_to'].get()
if relative_to:
relative_to = normpath(relative_to)
for playlist in playlists:
items = lib.items(playlist['query'])
paths = [os.path.relpath(item.path, relative_to) for item in items]
if relative_to:
paths = [os.path.relpath(item.path, relative_to) for item in items]
else:
paths = [item.path for item in items]
basename = playlist['name'].encode('utf8')
m3u_path = os.path.join(playlist_dir, basename)
with open(syspath(m3u_path), 'w') as f:
@ -27,7 +33,7 @@ class SmartPlaylistPlugin(BeetsPlugin):
def __init__(self):
super(SmartPlaylistPlugin, self).__init__()
self.config.add({
'mpd_music_dir': u'',
'relative_to': None,
'playlists': []
})