Skip to content

Commit

Permalink
try to search for videos if no song is found instead of skipping
Browse files Browse the repository at this point in the history
  • Loading branch information
Maritsu committed Jul 11, 2024
1 parent 73a1298 commit 155a5cd
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions spotify_dl/youtube.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,11 @@ def dump_json(songs):
# Reduce results to array of titles and video IDs
search_results = ym.search(query, filter="songs")
if len(search_results) == 0:
log.error(f"No results found for {query}, skipping.")
continue
log.warning("No song results found for %s, retrying.", query)
search_results = ym.search(query, filter="videos")
if len(search_results) == 0:
log.error("No search results found for %s, skipping.", query)
continue
result_titles, result_ids = zip(*map(
lambda d: (f"{d['artists'][0]['name']} - {d['title']}".replace(":", "").replace('"', ""), d["videoId"]),
search_results
Expand Down Expand Up @@ -220,8 +223,11 @@ def find_and_download_songs(kwargs):
# Reduce search results to array of titles and video IDs
search_results = ym.search(query, filter="songs")
if len(search_results) == 0:
log.error(f"No results found for {query}, skipping.")
continue
log.warning("No song results found for %s, retrying.", query)
search_results = ym.search(query, filter="videos")
if len(search_results) == 0:
log.error("No search results found for %s, skipping.", query)
continue
result_titles, result_ids = zip(*map(
lambda d: (f"{d['artists'][0]['name']} - {d['title']}".replace(":", "").replace('"', ""), d["videoId"]),
search_results
Expand Down

0 comments on commit 155a5cd

Please sign in to comment.