File bonusdisc.py of Package picard

# -*- coding: utf-8 -*-

PLUGIN_NAME = 'Bonus Disc'
PLUGIN_AUTHOR = 'Jan van Thiel'
PLUGIN_DESCRIPTION = '''Based on a script by Lukas Lalinsky.<br/>
<br/>
Moves bonus disc and bonus disc titles from album titles to separate tags. For example:<br/>
<em>"Sleeping With Ghosts (bonus disc: Covers)"</em>
<ul>
    <li>album = <em>"Sleeping With Ghosts"</em></li>
    <li>bonusdisc = <em>"bonus"</em></li>
    <li>bonusdisctitle = <em>"Covers"</em></li>
</ul>'''
PLUGIN_VERSION = "0.1"
PLUGIN_API_VERSIONS = ["0.9.0", "0.10", "0.15"]

from picard.metadata import register_album_metadata_processor
import re

_bonusdisc_re = re.compile(r"\s+\(bonus disc(?::\s+([^)]+))?\)")

def remove_bonusdiscs(tagger, metadata, release):
    matches = _bonusdisc_re.search(metadata["album"])
    if matches:
    	metadata["bonusdisc"] = "bonus"
        if matches.group(1):
            metadata["bonusdisctitle"] = matches.group(1)
        metadata["album"] = _bonusdisc_re.sub('', metadata["album"])

register_album_metadata_processor(remove_bonusdiscs)