From dbf47c19375f2287ffccefc724a176f2e1c0102e Mon Sep 17 00:00:00 2001 From: lars Date: Tue, 8 Nov 2022 23:49:21 +0100 Subject: [PATCH] fixed crashing in youtube search --- src/scraping/youtube_music.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/scraping/youtube_music.py b/src/scraping/youtube_music.py index 940f6be..267a2b2 100644 --- a/src/scraping/youtube_music.py +++ b/src/scraping/youtube_music.py @@ -1,5 +1,6 @@ +from typing import List + import youtube_dl -import pandas as pd import logging import time @@ -15,10 +16,13 @@ WAIT_BETWEEN_BLOCK = 10 MAX_TRIES = 3 -def get_youtube_from_isrc(isrc: str): +def get_youtube_from_isrc(isrc: str) -> List[dict]: # https://stackoverflow.com/questions/63388364/searching-youtube-videos-using-youtube-dl with youtube_dl.YoutubeDL(YDL_OPTIONS) as ydl: - videos = ydl.extract_info(f"ytsearch:{isrc}", download=False)['entries'] + try: + videos = ydl.extract_info(f"ytsearch:{isrc}", download=False)['entries'] + except youtube_dl.utils.DownloadError: + return [] return [{ 'url': video[YOUTUBE_URL_KEY], @@ -27,8 +31,6 @@ def get_youtube_from_isrc(isrc: str): def get_youtube_url(row): - if pd.isna(row['isrc']): - return None real_title = row['title'].lower() final_result = None