) from picard.config import get_config from picard.const import ( ACOUSTICBRAINZ_HOST, ACOUSTICBRAINZ_PORT, EXTRACTOR_NAMES, ) from picard.util import ( find_executable, load_json, run_executable, ) from picard.util.thread import run_task from picard.webservice import ratecontrol ratecontrol.set_minimum_delay((ACOUSTICBRAINZ_HOST, ACOUSTICBRAINZ_PORT), 1000) ABExtractorProperties = namedtuple('ABExtractorProperties', ('path', 'version', 'sha', 'mtime_ns')) class ABExtractor: def __init__(self): self._init_cache() def _init_cache(self): self.cache = defaultdict(lambda: None) def get(self, config=None): if not config: config = get_config()
config, ) from picard.const import ( ACOUSTID_HOST, ACOUSTID_KEY, ACOUSTID_PORT, CAA_HOST, CAA_PORT, ) from picard.webservice import ( CLIENT_STRING, DEFAULT_RESPONSE_PARSER_TYPE, ratecontrol, ) ratecontrol.set_minimum_delay((ACOUSTID_HOST, ACOUSTID_PORT), 333) ratecontrol.set_minimum_delay((CAA_HOST, CAA_PORT), 0) def escape_lucene_query(text): return re.sub(r'([+\-&|!(){}\[\]\^"~*?:\\/])', r'\\\1', text) def _wrap_xml_metadata(data): return ( '<?xml version="1.0" encoding="UTF-8"?>' '<metadata xmlns="http://musicbrainz.org/ns/mmd-2.0#">%s</metadata>' % data) class APIHelper(object):
config, ) from picard.const import ( ACOUSTID_HOST, ACOUSTID_KEY, ACOUSTID_PORT, CAA_HOST, CAA_PORT, ) from picard.webservice import ( CLIENT_STRING, DEFAULT_RESPONSE_PARSER_TYPE, ratecontrol, ) ratecontrol.set_minimum_delay((ACOUSTID_HOST, ACOUSTID_PORT), 333) ratecontrol.set_minimum_delay((CAA_HOST, CAA_PORT), 0) def escape_lucene_query(text): return re.sub(r'([+\-&|!(){}\[\]\^"~*?:\\/])', r'\\\1', text) def _wrap_xml_metadata(data): return ('<?xml version="1.0" encoding="UTF-8"?>' + '<metadata xmlns="http://musicbrainz.org/ns/mmd-2.0#">%s</metadata>' % data) class APIHelper(object): def __init__(self, host, port, api_path, webservice):
from picard.config import BoolOption, IntOption, TextOption from picard.metadata import register_track_metadata_processor from picard.plugins.lastfm.ui_options_lastfm import Ui_LastfmOptionsPage from picard.ui.options import register_options_page, OptionsPage from picard.util import build_qurl from picard.webservice import ratecontrol LASTFM_HOST = 'ws.audioscrobbler.com' LASTFM_PORT = 80 LASTFM_PATH = '/2.0/' LASTFM_API_KEY = '0a210a4a6741f2ec8f27a791b9d5d971' # From https://www.last.fm/api/tos, 2018-09-04 # 4.4 […] You will not make more than 5 requests per originating IP address per # second, averaged over a 5 minute period, without prior written consent. […] ratecontrol.set_minimum_delay((LASTFM_HOST, LASTFM_PORT), 200) # Cache for Tags to avoid re-requesting tags within same Picard session _cache = {} # Keeps track of requests for tags made to webservice API but not yet returned # (to avoid re-requesting the same URIs) _pending_requests = {} # TODO: move this to an options page TRANSLATE_TAGS = { "hip hop": "Hip-Hop", "synth-pop": "Synthpop", "electronica": "Electronic", } TITLE_CASE = True
def __init__(self): super(ApiseedsLyricsMetadataProcessor, self).__init__() ratecontrol.set_minimum_delay((self.apiseeds_host, self.apiseeds_port), self.apiseeds_delay)
def __init__(self): super().__init__() ratecontrol.set_minimum_delay((self.happidev_host, self.happidev_port), self.happidev_delay)
_CAA_THUMBNAIL_SIZE_MAP = OrderedDict([ (250, CaaSizeItem('250', N_('250 px'))), (500, CaaSizeItem('500', N_('500 px'))), (1200, CaaSizeItem('1200', N_('1200 px'))), (-1, CaaSizeItem(None, N_('Full size'))), ]) _CAA_THUMBNAIL_SIZE_ALIASES = { '500': 'large', '250': 'small', } _CAA_IMAGE_SIZE_DEFAULT = 500 _CAA_IMAGE_TYPE_DEFAULT_INCLUDE = ['front'] _CAA_IMAGE_TYPE_DEFAULT_EXCLUDE = ['raw/unedited', 'watermark'] ratecontrol.set_minimum_delay((CAA_HOST, CAA_PORT), 0) ratecontrol.set_minimum_delay(('archive.org', 443), 0) def caa_url_fallback_list(desired_size, thumbnails): """List of thumbnail urls equal or smaller than size, in size decreasing order It is used for find the "best" thumbnail according to: - user choice - thumbnail availability If user choice isn't matching an available thumbnail size, a fallback to smaller thumbnails is possible This function returns the list of possible urls, ordered from the biggest matching the user choice to the smallest one. Of course, if none are possible, the returned list may be empty. """ reversed_map = OrderedDict(reversed(list(_CAA_THUMBNAIL_SIZE_MAP.items())))
TextOption, ) from picard.webservice import ratecontrol from .ui_options_theaudiodb import Ui_TheAudioDbOptionsPage THEAUDIODB_HOST = "www.theaudiodb.com" THEAUDIODB_PORT = 443 THEAUDIODB_APIKEY = 'MWQ2NTY1NjQ2OTRmMTM0ZDY1NjU2NA==' OPTION_CDART_ALWAYS = "always" OPTION_CDART_NEVER = "never" OPTION_CDART_NOALBUMART = "noalbumart" # No rate limit for TheAudioDB. ratecontrol.set_minimum_delay((THEAUDIODB_HOST, THEAUDIODB_PORT), 0) class TheAudioDbOptionsPage(ProviderOptions): _options_ui = Ui_TheAudioDbOptionsPage options = [ TextOption("setting", "theaudiodb_use_cdart", OPTION_CDART_NOALBUMART), BoolOption("setting", "theaudiodb_use_high_quality", False), ] def load(self): if config.setting["theaudiodb_use_cdart"] == OPTION_CDART_ALWAYS: self.ui.theaudiodb_cdart_use_always.setChecked(True) elif config.setting["theaudiodb_use_cdart"] == OPTION_CDART_NEVER:
PLUGIN_API_VERSIONS = ["2.0", "2.1", "2.2"] PLUGIN_LICENSE = 'WTFPL' PLUGIN_LICENSE_URL = 'http://www.wtfpl.net/' import re from functools import partial from picard import config, log from picard.metadata import register_track_metadata_processor from picard.plugins.wikidata.ui_options_wikidata import Ui_WikidataOptionsPage from picard.ui.options import register_options_page, OptionsPage from picard.webservice import ratecontrol WIKIDATA_HOST = 'www.wikidata.org' WIKIDATA_PORT = 443 ratecontrol.set_minimum_delay((WIKIDATA_HOST, WIKIDATA_PORT), 0) def parse_ignored_tags(ignore_tags_setting): ignore_tags = [] for tag in ignore_tags_setting.lower().split(','): if not tag: break tag = tag.strip() if tag.startswith('/') and tag.endswith('/'): try: tag = re.compile(tag[1:-1]) except re.error: log.error('Error parsing ignored tag "%s"', tag, exc_info=True) ignore_tags.append(tag) return ignore_tags