Skip to content

Commit

Permalink
- Added hooks to manipulate fetched album and track info
Browse files Browse the repository at this point in the history
- Integrated support for plugins
- Added documentation
- Updated changelog
  • Loading branch information
m-urban committed Jun 10, 2015
1 parent ce91a0c commit 9de3bd4
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 4 deletions.
28 changes: 24 additions & 4 deletions beets/autotag/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,10 @@ def album_for_mbid(release_id):
if the ID is not found.
"""
try:
return mb.album_for_id(release_id)
album = mb.album_for_id(release_id)
if album:
plugins.send('albuminfo_received', info=album)
return album
except mb.MusicBrainzAPIError as exc:
exc.log(log)

Expand All @@ -521,22 +524,31 @@ def track_for_mbid(recording_id):
if the ID is not found.
"""
try:
return mb.track_for_id(recording_id)
track = mb.track_for_id(recording_id)
if track:
plugins.send('trackinfo_received', info=track)
return track
except mb.MusicBrainzAPIError as exc:
exc.log(log)


def albums_for_id(album_id):
"""Get a list of albums for an ID."""
candidates = [album_for_mbid(album_id)]
candidates.extend(plugins.album_for_id(album_id))
plugin_albums = plugins.album_for_id(album_id)
for a in plugin_albums:
plugins.send('trackinfo_received', info=a)
candidates.extend(plugin_albums)
return filter(None, candidates)


def tracks_for_id(track_id):
"""Get a list of tracks for an ID."""
candidates = [track_for_mbid(track_id)]
candidates.extend(plugins.track_for_id(track_id))
plugin_tracks = plugins.track_for_id(track_id)
for t in plugin_tracks:
plugins.send('trackinfo_received', info=t)
candidates.extend(plugin_tracks)
return filter(None, candidates)


Expand Down Expand Up @@ -566,6 +578,10 @@ def album_candidates(items, artist, album, va_likely):
# Candidates from plugins.
out.extend(plugins.candidates(items, artist, album, va_likely))

# Notify subscribed plugins about fetched album info
for a in out:
plugins.send('albuminfo_received', info=a)

return out


Expand All @@ -586,4 +602,8 @@ def item_candidates(item, artist, title):
# Plugin candidates.
out.extend(plugins.item_candidates(item, artist, title))

# Notify subscribed plugins about fetched album info
for i in out:
plugins.send('trackinfo_received', info=i)

return out
4 changes: 4 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ New features:
:bug:`1104` :bug:`1493`
* :doc:`/plugins/plexupdate`: A new ``token`` configuration option lets you
specify a key for Plex Home setups. Thanks to :user:`edcarroll`. :bug:`1494`
* :doc:`/dev/plugins`: New hooks ``albuminfo_received`` and
``trackinfo_received`` have been added for developers who would like to
intercept fetched meta data, before they are applied in tag manipulation
operations. :bug:`872`


Fixes:
Expand Down
16 changes: 16 additions & 0 deletions docs/dev/plugins.rst
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,22 @@ The events currently available are:
* *import_begin*: called just before a ``beet import`` session starts up.
Parameter: ``session``.

* *trackinfo_received*: called after meta data for a track item has been fetched
from disparate sources, such as MusicBrainz. Gives a developer the option to
intercept the fetched TrackInfo object. Can be used to modify tags on a ``beet
import`` operation or during later adjustments, such as ``mbsync``. Can be
slow, as event is fired for any fetched possible match *before* user or
autotagger selection was made.
Parameter: ``info``.

* *albuminfo_received*: called after meta data for an album item has been
fetched from disparate sources, such as MusicBrainz. Gives a developer the
option to intercept the fetched AlbumInfo object. Can be used to modify tags
on a ``beet import`` operation or during later adjustments, such as
``mbsync``. Can be slow, as event is fired for any fetched possible match
*before* user or autotagger selection was made.
Parameter: ``info``.

The included ``mpdupdate`` plugin provides an example use case for event listeners.

Extend the Autotagger
Expand Down

0 comments on commit 9de3bd4

Please sign in to comment.