1

Update itunes plugin

This commit is contained in:
Kim Wittenburg
2018-09-03 21:44:39 +02:00
parent 1c964fd25f
commit b3624b3b06

View File

@@ -94,8 +94,7 @@ class SearchAPIPlugin(BeetsPlugin):
def scan_track_ids(self, session, task): def scan_track_ids(self, session, task):
self._log.debug("Scanning track IDs") self._log.debug("Scanning track IDs")
items = task.items if task.is_album else [ task.item ] for item in task.items:
for item in items:
with open(item.path, 'rb') as file: with open(item.path, 'rb') as file:
data = file.read(1000) # Song ID always seems to be around 600-700 bytes in data = file.read(1000) # Song ID always seems to be around 600-700 bytes in
location = data.find(b'song') location = data.find(b'song')
@@ -110,6 +109,7 @@ class SearchAPIPlugin(BeetsPlugin):
"""Returns a list of AlbumInfo objects for iTunes search results """Returns a list of AlbumInfo objects for iTunes search results
matching an album and artist. matching an album and artist.
""" """
try:
candidates = [] candidates = []
# Lookup the track ids assigned by iTunes Match # Lookup the track ids assigned by iTunes Match
if self.method in ['lookup', 'lookup (search fallback)', 'both']: if self.method in ['lookup', 'lookup (search fallback)', 'both']:
@@ -123,17 +123,17 @@ class SearchAPIPlugin(BeetsPlugin):
if self.method in ['search', 'both'] or (self.method == 'lookup (search fallback)' and len(candidates) == 0): if self.method in ['search', 'both'] or (self.method == 'lookup (search fallback)' and len(candidates) == 0):
candidates += self.search_albums(artist, album, va_likely) candidates += self.search_albums(artist, album, va_likely)
return candidates return candidates
except ConnectionError:
self._log.debug(u'Cannot search iTunes (no network connection)')
return []
def lookup_albums(self, items): def lookup_albums(self, items):
ids = [ str(_track_ids[item]) for item in items if item in _track_ids ] ids = [ str(_track_ids[item]) for item in items if item in _track_ids ]
def remove_found_tracks(album): def remove_found_tracks(album):
for track in album.get_tracks(): for track in album.get_tracks():
try: if track.track_id in ids:
ids.remove(track.track_id) ids.remove(track.track_id)
except ValueError:
pass
albums = [] albums = []
try:
for country in self.lookup_countries: for country in self.lookup_countries:
self._log.debug("Searching iTunes Store: {0}", country) self._log.debug("Searching iTunes Store: {0}", country)
try: try:
@@ -148,9 +148,6 @@ class SearchAPIPlugin(BeetsPlugin):
break break
except LookupError: except LookupError:
pass pass
except ConnectionError:
self._log.debug(u'Cannot search iTunes (no network connection)')
return []
return albums return albums
def search_albums(self, artist, album, va_likely): def search_albums(self, artist, album, va_likely):
@@ -167,9 +164,6 @@ class SearchAPIPlugin(BeetsPlugin):
try: try:
results = itunespy.search_album(query, country=country, limit=self.search_limit) results = itunespy.search_album(query, country=country, limit=self.search_limit)
albums += [self.make_album_info(result) for result in results] albums += [self.make_album_info(result) for result in results]
except ConnectionError:
self._log.debug(u'Cannot search iTunes (no network connection)')
return []
except LookupError: except LookupError:
self._log.debug(u'Search for {0} did return no results', query) self._log.debug(u'Search for {0} did return no results', query)
return [] return []