Skip to content

Commit

Permalink
Load metadata sync plugins dynamically.
Browse files Browse the repository at this point in the history
  • Loading branch information
pprkut committed Mar 31, 2015
1 parent a09acc2 commit 5083471
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions beetsplug/psync/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,15 @@
"""Synchronize information from music player libraries
"""

from beets import ui
from beets import ui, logging
from beets.plugins import BeetsPlugin
from beets.dbcore import types
from beets.library import DateType
from sys import modules
import inspect

# Loggers.
log = logging.getLogger('beets.psync')


class PSyncPlugin(BeetsPlugin):
Expand Down Expand Up @@ -57,13 +62,22 @@ def func(self, lib, opts, args):
sources = {}

for player in source:
if player == u'amarok':
from beetsplug.psync import amarok
__import__('beetsplug.psync', fromlist=[str(player)])

module = 'beetsplug.psync.' + player

sources[u'amarok'] = amarok.Amarok()
else:
if module not in modules.keys():
log.error(u'Unknown metadata source \'' + player + '\'')
continue

classes = inspect.getmembers(modules[module], inspect.isclass)

for entry in classes:
if entry[0].lower() == player:
sources[player] = entry[1]()
else:
continue

for item in lib.items(query):
for player in sources.values():
player.get_data(item)
Expand Down

0 comments on commit 5083471

Please sign in to comment.