mirror of
https://github.com/beetbox/beets.git
synced 2025-12-31 21:12:43 +01:00
MetaSync: small refactoring + enhancements
- `sync_data` -> `sync_from_source` - properly catch ConfigValueError - avoiding iterating through library if we couldn't instantiate any meta sources - fix create_temporary_copy to actually make a tempdir
This commit is contained in:
parent
bba8647bac
commit
abd02052b9
3 changed files with 13 additions and 8 deletions
|
|
@ -15,12 +15,14 @@
|
|||
"""Synchronize information from music player libraries
|
||||
"""
|
||||
from abc import abstractmethod, ABCMeta
|
||||
from beets import ui
|
||||
from beets.plugins import BeetsPlugin
|
||||
import inspect
|
||||
import pkgutil
|
||||
from importlib import import_module
|
||||
|
||||
from beets.util.confit import ConfigValueError
|
||||
from beets import ui
|
||||
from beets.plugins import BeetsPlugin
|
||||
|
||||
|
||||
METASYNC_MODULE = 'beetsplug.metasync'
|
||||
|
||||
|
|
@ -34,7 +36,7 @@ class MetaSource(object):
|
|||
self._log = log
|
||||
|
||||
@abstractmethod
|
||||
def sync_data(self, item):
|
||||
def sync_from_source(self, item):
|
||||
pass
|
||||
|
||||
|
||||
|
|
@ -116,14 +118,17 @@ class MetaSyncPlugin(BeetsPlugin):
|
|||
except KeyError:
|
||||
self._log.error(u'Unknown metadata source \'{0}\''.format(
|
||||
player))
|
||||
except ImportError as e:
|
||||
except (ImportError, ConfigValueError) as e:
|
||||
self._log.error(u'Failed to instantiate metadata source '
|
||||
u'\'{0}\': {1}'.format(player, e))
|
||||
|
||||
if not meta_sources:
|
||||
return
|
||||
|
||||
# Sync the items with all of the meta sources
|
||||
for item in lib.items(query):
|
||||
for meta_source in meta_sources.values():
|
||||
meta_source.sync_data(item)
|
||||
meta_source.sync_from_source(item)
|
||||
|
||||
changed = ui.show_model_changes(item)
|
||||
|
||||
|
|
|
|||
|
|
@ -61,7 +61,7 @@ class Amarok(MetaSource):
|
|||
self.collection = \
|
||||
dbus.SessionBus().get_object('org.kde.amarok', '/Collection')
|
||||
|
||||
def sync_data(self, item):
|
||||
def sync_from_source(self, item):
|
||||
path = displayable_path(item.path)
|
||||
|
||||
# amarok unfortunately doesn't allow searching for the full path, only
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ from beetsplug.metasync import MetaSource
|
|||
|
||||
@contextmanager
|
||||
def create_temporary_copy(path):
|
||||
temp_dir = tempfile.gettempdir()
|
||||
temp_dir = tempfile.mkdtemp()
|
||||
temp_path = os.path.join(temp_dir, 'temp_itunes_lib')
|
||||
shutil.copyfile(path, temp_path)
|
||||
try:
|
||||
|
|
@ -76,7 +76,7 @@ class Itunes(MetaSource):
|
|||
(track['Name'], track['Album'], track['Album Artist']): track
|
||||
for track in raw_library['Tracks'].values()}
|
||||
|
||||
def sync_data(self, item):
|
||||
def sync_from_source(self, item):
|
||||
key = (item.title, item.album, item.albumartist)
|
||||
result = self.collection.get(key)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue