Skip to content

Commit

Permalink
Merge 3d03923 into 5517ce1
Browse files Browse the repository at this point in the history
  • Loading branch information
adamjakab committed Apr 22, 2020
2 parents 5517ce1 + 3d03923 commit 40dd19e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
2 changes: 1 addition & 1 deletion beetsplug/yearfixer/about.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
__email__ = u'adam@jakab.pro'
__copyright__ = u'Copyright (c) 2020, {} <{}>'.format(__author__, __email__)
__license__ = u'License :: OSI Approved :: MIT License'
__version__ = u'0.0.2'
__version__ = u'0.0.3'
__status__ = u'Kickstarted'

__PACKAGE_TITLE__ = u'YearFixer'
Expand Down
23 changes: 14 additions & 9 deletions beetsplug/yearfixer/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
from optparse import OptionParser

import requests
from beets.dbcore.query import NumericQuery, MatchQuery, AndQuery, OrQuery, NoneQuery
from beets.dbcore.query import NumericQuery, MatchQuery, AndQuery, OrQuery, \
NoneQuery
from beets.library import Library, Item, parse_query_parts
from beets.ui import Subcommand, decargs
from beets.util.confit import Subview

from beetsplug.yearfixer import common


Expand Down Expand Up @@ -76,16 +76,19 @@ def handle_main_task(self):
item.store()

def process_item(self, item: Item):
self._say("Finding year for: {}".format(item), log_only=True)
self._say("Fixing item: {}".format(item), log_only=True)

year = item.get("year")
original_year = item.get("original_year")

if not original_year or self.cfg_force:
mbdata = self._get_mb_data(item)
if mbdata:
original_year = common.extract_original_year_from_mb_data(mbdata)
self._say("Got `original_year`: {}".format(original_year))
extracted = common.extract_original_year_from_mb_data(mbdata)
if extracted:
original_year = extracted
self._say("Got (MusicBrainz) recording `original_year`: {}"
.format(original_year))

if not original_year:
original_year = self.get_mean_value_for_album(item, "original_year")
Expand Down Expand Up @@ -161,7 +164,7 @@ def _get_mb_data(self, item: Item):
self._say(err, is_error=True)
return data

self._say(u'fetching URL: {}'.format(url))
# self._say(u'fetching URL: {}'.format(url))

headers = {
'User-Agent': '{pt}/{ver} ( {url} )'.format(
Expand All @@ -177,7 +180,7 @@ def _get_mb_data(self, item: Item):

while not data:
retries += 1
self._say('Retry #{}'.format(retries))
# self._say('Retry #{}'.format(retries))
if retries > max_retries:
self._say("Maximum({}) retries reached. Abandoning.".format(max_retries), is_error=True)
break
Expand All @@ -189,8 +192,10 @@ def _get_mb_data(self, item: Item):
break

if res.status_code == 503:
# we hit the query limit - https://musicbrainz.org/doc/XML_Web_Service/Rate_Limiting
self._say('Query LIMIT Hit!')
# we hit the query limit -
# https://musicbrainz.org/doc/XML_Web_Service/Rate_Limiting
self._say('Retry #{} - Query LIMIT Hit! sleeping {}s.'
.format(retries, sleep_time))
time.sleep(sleep_time)
continue

Expand Down

0 comments on commit 40dd19e

Please sign in to comment.