fixed crashing in youtube search
This commit is contained in:
parent
5486f7f8d1
commit
dbf47c1937
@ -1,5 +1,6 @@
|
|||||||
|
from typing import List
|
||||||
|
|
||||||
import youtube_dl
|
import youtube_dl
|
||||||
import pandas as pd
|
|
||||||
import logging
|
import logging
|
||||||
import time
|
import time
|
||||||
|
|
||||||
@ -15,10 +16,13 @@ WAIT_BETWEEN_BLOCK = 10
|
|||||||
MAX_TRIES = 3
|
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
|
# https://stackoverflow.com/questions/63388364/searching-youtube-videos-using-youtube-dl
|
||||||
with youtube_dl.YoutubeDL(YDL_OPTIONS) as ydl:
|
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 [{
|
return [{
|
||||||
'url': video[YOUTUBE_URL_KEY],
|
'url': video[YOUTUBE_URL_KEY],
|
||||||
@ -27,8 +31,6 @@ def get_youtube_from_isrc(isrc: str):
|
|||||||
|
|
||||||
|
|
||||||
def get_youtube_url(row):
|
def get_youtube_url(row):
|
||||||
if pd.isna(row['isrc']):
|
|
||||||
return None
|
|
||||||
real_title = row['title'].lower()
|
real_title = row['title'].lower()
|
||||||
|
|
||||||
final_result = None
|
final_result = None
|
||||||
|
Loading…
Reference in New Issue
Block a user