def test_normalize_stopwords(self): info_l = [ {'album': 'pippo', 'artist': u'The Beatles'}, {'album': 'pippo', 'artist': u'Beatles'} ] for info in info_l: ret = MediaManager.normalize_artist(info, stopwords=True) assert ret == 'beatles'
def test_normalize(self): info_l = [ {'album': 'pippo', 'artist': u'Fiorella Mannoia'}, {'album': 'pippo', 'artist': u'Fiorella_Mannoia'} ] for info in info_l: ret = MediaManager.normalize_artist(info) assert ret == 'fiorellamannoia'
def test_normalize_stopwords(self): info_l = [{ 'album': 'pippo', 'artist': u'The Beatles' }, { 'album': 'pippo', 'artist': u'Beatles' }] for info in info_l: ret = MediaManager.normalize_artist(info, stopwords=True) assert ret == 'beatles'
def test_normalize(self): info_l = [{ 'album': 'pippo', 'artist': u'Fiorella Mannoia' }, { 'album': 'pippo', 'artist': u'Fiorella_Mannoia' }] for info in info_l: ret = MediaManager.normalize_artist(info) assert ret == 'fiorellamannoia'
def cover_art_worker(cache_dir, cover_search=cover_search): log.info("starting downloader thread with tmp_dir: %s" % cache_dir) info = True while info: info = q.get() try: cover_art_path = os.path.join("/", cache_dir, MediaManager.cover_art_uuid(info)) log.info("coverart %s: searching album: %s " % (info.get('id'), info.get('album'))) covers = cover_search(info.get('album')) for cover in covers: # TODO consider multiple authors in info # ex. Actually "U2 & Frank Sinatra" != "U2" # leads to a false negative # TODO con print "confronting info: %s with: %s" % (info, cover) normalize_info, normalize_cover = map( MediaManager.normalize_artist, [info, cover]) full_match = len(set([normalize_info, normalize_cover])) == 1 stopwords_match = len( set([ MediaManager.normalize_artist(x, stopwords=True) for x in [info, cover] ])) == 1 partial_match = len([ x for x in normalize_info if x not in normalize_cover ]) == 0 if full_match or stopwords_match or partial_match: log.warn("Saving image %s -> %s" % (cover.get('cover_small'), cover_art_path)) fd = open(cover_art_path, "w") fd.write(urlopen(cover.get('cover_small')).read()) fd.close() else: log.info("Artist mismatch: %s, %s" % tuple([ x.get('artist', x.get('name')) for x in [info, cover] ])) except Exception as e: log.error("Error while downloading albumart.", e) q.task_done() log.warn("finish download thread")
def cover_art_worker(cache_dir, cover_search=cover_search): log.info("starting downloader thread with tmp_dir: %s" % cache_dir) info = True while info: info = q.get() try: cover_art_path = os.path.join("/", cache_dir, MediaManager.cover_art_uuid(info) ) log.info("coverart %s: searching album: %s " % ( info.get('id'), info.get('album'))) covers = cover_search(info.get('album')) for cover in covers: # TODO consider multiple authors in info # ex. Actually "U2 & Frank Sinatra" != "U2" # leads to a false negative # TODO con print "confronting info: %s with: %s" % (info, cover) normalize_info, normalize_cover = map( MediaManager.normalize_artist, [info, cover]) full_match = len(set([normalize_info, normalize_cover])) == 1 stopwords_match = len(set([MediaManager.normalize_artist( x, stopwords=True) for x in [info, cover]])) == 1 partial_match = len( [x for x in normalize_info if x not in normalize_cover]) == 0 if full_match or stopwords_match or partial_match: log.warn("Saving image %s -> %s" % ( cover.get('cover_small'), cover_art_path) ) fd = open(cover_art_path, "w") fd.write(urlopen(cover.get('cover_small')).read()) fd.close() else: log.info("Artist mismatch: %s, %s" % tuple( [x.get('artist', x.get('name')) for x in [info, cover]]) ) except Exception as e: log.error("Error while downloading albumart.", e) q.task_done() log.warn("finish download thread")