diff --git a/beetsplug/lastgenre/__init__.py b/beetsplug/lastgenre/__init__.py index 3cf20b6ca..abc896baa 100644 --- a/beetsplug/lastgenre/__init__.py +++ b/beetsplug/lastgenre/__init__.py @@ -167,9 +167,13 @@ class LastGenrePlugin(plugins.BeetsPlugin): # The "write to files" option corresponds to the # import_write config value. write = config['import']['write'].get(bool) + source = self.config['source'].get() for album in lib.albums(ui.decargs(args)): tags = [] - lastfm_obj = LASTFM.get_album(album.albumartist, album.album) + if source is 'artist': + lastfm_obj = LASTFM.get_artist(album.albumartist) + else: + lastfm_obj = LASTFM.get_album(album.albumartist, album.album) if album.genre: tags.append(album.genre) @@ -191,15 +195,22 @@ class LastGenrePlugin(plugins.BeetsPlugin): return [lastgenre_cmd] def imported(self, session, task): + source = self.config['source'].get() tags = [] if task.is_album: album = session.lib.get_album(task.album_id) - lastfm_obj = LASTFM.get_album(album.albumartist, album.album) + if source is 'artist': + lastfm_obj = LASTFM.get_artist(album.albumartist) + else: + lastfm_obj = LASTFM.get_album(album.albumartist, album.album) if album.genre: tags.append(album.genre) else: item = task.item - lastfm_obj = LASTFM.get_track(item.artist, item.title) + if source is 'artist': + lastfm_obj = LASTFM.get_artist(item.artist) + else: + lastfm_obj = LASTFM.get_track(item.artist, item.title) if item.genre: tags.append(item.genre) diff --git a/docs/plugins/lastgenre.rst b/docs/plugins/lastgenre.rst index b8df9eed6..4b44bfb41 100644 --- a/docs/plugins/lastgenre.rst +++ b/docs/plugins/lastgenre.rst @@ -64,6 +64,18 @@ to use your own tree. .. _YAML: http://www.yaml.org/ .. _pyyaml: http://pyyaml.org/ +Genre Source +------------ + +When looking up genres for albums, you may specify whether you want to retrieve +the genre from the album, or from the artist by setting the ``source`` +configuration value:: + + lastgenre: + source: artist + +Currently the only available option is 'artist', any other value for ``source`` +will default to retrieving genres from the album. Running Manually ----------------