MusicBrainz Picard/Plugins/API: Difference between revisions
From MusicBrainz Wiki
Jump to navigationJump to search
((Imported from MoinMoin)) |
((Imported from MoinMoin)) |
||
Line 2: | Line 2: | ||
API documentation for [[Picard Qt|PicardQt]] plugins. |
API documentation for [[Picard Qt|PicardQt]] plugins. |
||
==Metadata Processors== |
|||
[[MusicBrainz]] metadata can be post-processed at two levels, album and track. |
|||
Album metadata example: |
|||
<pre> |
|||
1 PLUGIN_NAME = 'Disc Numbers' |
|||
2 PLUGIN_AUTHOR = 'Lukas Lalinsky' |
|||
3 PLUGIN_DESCRIPTION = 'Moves disc numbers from album titles to tags.' |
|||
⚫ | |||
5 from picard.metadata import register_album_metadata_processor |
|||
6 import re |
|||
⚫ | |||
8 def remove_discnumbers(metadata, release): |
|||
9 matches = re.search(r"\(disc (\d+)\)", metadata["album"]) |
|||
10 if matches: |
|||
11 metadata["discnumber"] = matches.group(1) |
|||
12 metadata["album"] = re.sub(r"\(disc \d+\)", "", metadata["album"]) |
|||
13 |
|||
14 register_album_metadata_processor(remove_discnumbers) |
|||
</pre> |
|||
Track metadata example: |
|||
<pre> |
|||
1 PLUGIN_NAME = 'Feat. Artists' |
|||
2 PLUGIN_AUTHOR = 'Lukas Lalinsky' |
|||
3 PLUGIN_DESCRIPTION = 'Removes feat. artists from track titles.' |
|||
4 |
|||
5 from picard.metadata import register_track_metadata_processor |
|||
6 import re |
|||
7 |
|||
8 def remove_featartists(metadata, release, track): |
|||
9 metadata["title"] = re.sub(r"\(feat. [^)]*\)", "", metadata["title"]) |
|||
10 |
|||
11 register_track_metadata_processor(remove_featartists) |
|||
</pre> |
|||
==Tagger Script Functions== |
==Tagger Script Functions== |
||
Line 10: | Line 49: | ||
<pre> |
<pre> |
||
1 PLUGIN_NAME = 'Initials' |
|||
⚫ | |||
2 PLUGIN_AUTHOR = 'Lukas Lalinsky' |
|||
⚫ | |||
3 |
3 PLUGIN_DESCRIPTION = 'Provides tagger script function $initials(text).' |
||
4 |
|||
⚫ | |||
⚫ | |||
⚫ | |||
6 |
|||
⚫ | |||
7 def initials(parser, text): |
|||
⚫ | |||
9 |
|||
⚫ | |||
</pre> |
</pre> |
||
Revision as of 20:42, 20 January 2007
APIs for PicardQt Plugins
API documentation for PicardQt plugins.
Metadata Processors
MusicBrainz metadata can be post-processed at two levels, album and track.
Album metadata example:
1 PLUGIN_NAME = 'Disc Numbers' 2 PLUGIN_AUTHOR = 'Lukas Lalinsky' 3 PLUGIN_DESCRIPTION = 'Moves disc numbers from album titles to tags.' 4 5 from picard.metadata import register_album_metadata_processor 6 import re 7 8 def remove_discnumbers(metadata, release): 9 matches = re.search(r"\(disc (\d+)\)", metadata["album"]) 10 if matches: 11 metadata["discnumber"] = matches.group(1) 12 metadata["album"] = re.sub(r"\(disc \d+\)", "", metadata["album"]) 13 14 register_album_metadata_processor(remove_discnumbers)
Track metadata example:
1 PLUGIN_NAME = 'Feat. Artists' 2 PLUGIN_AUTHOR = 'Lukas Lalinsky' 3 PLUGIN_DESCRIPTION = 'Removes feat. artists from track titles.' 4 5 from picard.metadata import register_track_metadata_processor 6 import re 7 8 def remove_featartists(metadata, release, track): 9 metadata["title"] = re.sub(r"\(feat. [^)]*\)", "", metadata["title"]) 10 11 register_track_metadata_processor(remove_featartists)
Tagger Script Functions
To define new tagger script function use register_script_function(function, name=None)
from module picard.script
.
Example:
1 PLUGIN_NAME = 'Initials' 2 PLUGIN_AUTHOR = 'Lukas Lalinsky' 3 PLUGIN_DESCRIPTION = 'Provides tagger script function $initials(text).' 4 5 from picard.script import register_script_function 6 7 def initials(parser, text): 8 return "".join(a[:1] for a in text.split(" ") if a[:1].isalpha()) 9 10 register_script_function(initials)