fixed bug with the youtube downloader where it chrashes if no results are found. Now checking all results of an search for a close enough title
This commit is contained in:
Binary file not shown.
Binary file not shown.
@@ -7,7 +7,6 @@ import logging
|
||||
import requests
|
||||
import os
|
||||
|
||||
# "/home/lars/Projekts/big projects/music-downloader/venv/bin/python3.10" "/home/lars/Projekts/big projects/music-downloader/src/main.py"
|
||||
|
||||
TEMP = "temp"
|
||||
STEP_ONE_CACHE = ".cache1.csv"
|
||||
|
||||
@@ -49,6 +49,7 @@ class Search:
|
||||
|
||||
metadata_list = []
|
||||
if kind == "artist":
|
||||
|
||||
metadata_list = self.download_artist(mb_id)
|
||||
elif kind == "release":
|
||||
metadata_list = self.download_release(mb_id)
|
||||
@@ -72,7 +73,6 @@ class Search:
|
||||
|
||||
for i, release in enumerate(result["artist"]["release-list"]):
|
||||
metadata_list.extend(self.download_release(release["id"], i))
|
||||
|
||||
return metadata_list
|
||||
|
||||
def download_release(self, mb_id, album_sort: int = None):
|
||||
|
||||
@@ -7,6 +7,7 @@ import phonetic_compares
|
||||
|
||||
YDL_OPTIONS = {'format': 'bestaudio', 'noplaylist': 'True'}
|
||||
YOUTUBE_URL_KEY = 'webpage_url'
|
||||
YOUTUBE_TITLE_KEY = 'title'
|
||||
WAIT_BETWEEN_BLOCK = 10
|
||||
MAX_TRIES = 3
|
||||
|
||||
@@ -14,13 +15,12 @@ MAX_TRIES = 3
|
||||
def get_youtube_from_isrc(isrc: str):
|
||||
# https://stackoverflow.com/questions/63388364/searching-youtube-videos-using-youtube-dl
|
||||
with youtube_dl.YoutubeDL(YDL_OPTIONS) as ydl:
|
||||
video = ydl.extract_info(f"ytsearch:{isrc}", download=False)['entries'][0]
|
||||
if YOUTUBE_URL_KEY not in video:
|
||||
return None
|
||||
return {
|
||||
videos = ydl.extract_info(f"ytsearch:{isrc}", download=False)['entries']
|
||||
|
||||
return [{
|
||||
'url': video[YOUTUBE_URL_KEY],
|
||||
'title': video['title']
|
||||
}
|
||||
'title': video[YOUTUBE_TITLE_KEY]
|
||||
} for video in videos]
|
||||
|
||||
|
||||
def get_youtube_url(row):
|
||||
@@ -28,16 +28,22 @@ def get_youtube_url(row):
|
||||
return None
|
||||
real_title = row['title'].lower()
|
||||
|
||||
result = get_youtube_from_isrc(row['isrc'])
|
||||
video_title = result['title'].lower()
|
||||
final_result = None
|
||||
results = get_youtube_from_isrc(row['isrc'])
|
||||
for result in results:
|
||||
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:
|
||||
logging.warning(
|
||||
f"dont downloading {result['url']} cuz the phonetic distance ({distance}) between {real_title} and {video_title} is to high.")
|
||||
continue
|
||||
|
||||
if match:
|
||||
logging.warning(
|
||||
f"dont downloading {result['url']} cuz the phonetic distance ({distance}) between {real_title} and {video_title} is to high.")
|
||||
final_result = result
|
||||
|
||||
if final_result is None:
|
||||
return None
|
||||
return result['url']
|
||||
return final_result['url']
|
||||
|
||||
|
||||
def download(row, trie: int = 0):
|
||||
|
||||
Reference in New Issue
Block a user