refactored

This commit is contained in:
Lars Noack 2022-11-22 13:47:33 +01:00
parent 7bab6e3006
commit ef362dd2a4

View File

@ -35,30 +35,30 @@ class Youtube(AudioSource):
} for video in videos] } for video in videos]
@classmethod @classmethod
def fetch_source(cls, row: dict): def fetch_source(cls, song: song_objects.Song):
# https://stackoverflow.com/questions/63388364/searching-youtube-videos-using-youtube-dl # https://stackoverflow.com/questions/63388364/searching-youtube-videos-using-youtube-dl
super().fetch_source(row) super().fetch_source(song)
if row['isrc'] is None: if not song.has_isrc():
return None return
real_title = row['title'].lower() real_title = song.title.lower()
final_result = None final_result = None
results = cls.get_youtube_from_isrc(row['isrc']) results = cls.get_youtube_from_isrc(song.isrc)
for result in results: for result in results:
video_title = result['title'].lower() video_title = result.title.lower()
match, distance = phonetic_compares.match_titles(video_title, real_title) match, distance = phonetic_compares.match_titles(video_title, real_title)
if match: if match:
logger.warning( # logger.warning(
f"dont downloading {result['url']} cuz the phonetic distance ({distance}) between {real_title} and {video_title} is to high.") # f"dont downloading {result['url']} cuz the phonetic distance ({distance}) between {real_title} and {video_title} is to high.")
continue continue
final_result = result final_result = result
if final_result is None: if final_result is None:
return None return False
return final_result['url'] return final_result['url']
@classmethod @classmethod