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 7b5028f commit bf1c60e
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions beetsplug/psync/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +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 +61,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) ])

sources[u'amarok'] = amarok.Amarok()
else:
module = 'beetsplug.psync.' + player

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 bf1c60e

Please sign in to comment.