From 77e53e5e1eef8f6ffdd045b2cfb844db95e498cb Mon Sep 17 00:00:00 2001 From: lars Date: Mon, 24 Oct 2022 12:17:22 +0200 Subject: [PATCH] addet multiple tries to youtube downloading --- src/__pycache__/youtube_music.cpython-310.pyc | Bin 1776 -> 2173 bytes src/main.py | 2 +- src/youtube_music.py | 29 +++++++++++++----- 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/src/__pycache__/youtube_music.cpython-310.pyc b/src/__pycache__/youtube_music.cpython-310.pyc index 33f5d80c89aae3d64885abacfb32cf9c1c2e00e5..09c6d05c9123095646f87279d1c842317fba0957 100644 GIT binary patch delta 1112 zcmY*Y&2QX96rUM?tk-MrI@?8QT2z@*N>^=>kdOd@D%!9Tp^%Df)D&N=ZQf+%#Id8X zmuOdx_K+O;P_!2$QYk&cg&X`6+>ki<+EX}jERm}6o>N4b(fiHseT?V5H{-wDXWsSH zb!~>j-nhSR)ERq1%F9DX;SaNr!c(nWg{S_ekZlr8YKg!&Zb0#7!ix6gw)*_LzroHN;g_RBi(KAzZT z-OdT+w0!u>JN60Xd!iv6{`nhsX20?W9ZZ~++8E-}_$mUK{>aq)>~*op-PyO|B43#O zBz`t2NIA1mdlk)vb|1~ZYj5!O>~HOh={z|rI8Wbd4P_pV(@{QpD8rG8FQ73aXmXu9 z+!2)s3pJnX&vj(#P1>mEDw690>A%B7LMbnzWPczOSkeO96SxXoHEQJ)3^1W~qzyS( zg$DH_eNUhGIXmWs{+NH~?HPq}EDAB?kFif{4495{UpwP{_BP9I?xKh0mnam`$B3M5 zYMc6a^URYQ$0pbX|A9dxuOT{*4EkR23D0X=hFYltTryRxnOhjtdZbmB`mvo`6~o*M z4&FS2xo?Dt2lm-6>$aDbJL?!CfCyhGJh}}M2Vt{=yG+9mWFELqFMyh z=F%8V^C-?r_v065_LNGM@+sgo3aEd6`$4$6vefIB?X}xWtKpsA>RPY29Nzit-r`-n z!Dw5SMixuC(>2v)+D9iTmo^(4Q7prop#VsyqaKX)I z!a#f~8V+yrtIs`g9=$eiqjb19Rrai5E={@OxUqY#Dy=kk1_=x@brEgq5`jnC%Au delta 712 zcmY+BPis>_5WshK_q}Xh-b!n+1(kDe4ig@=9t-_tGDPw8FwkAECyqR*I9)*ApKO!AritqchYHOT{j>Q|EaLb@ZN@xnzSs zrSwO>1PjR_|KQq1#!Fs_WymG(!~+Wd5M?MPOY&ZM&L(G=x3vmQ-3xc4ey{&Thketw z!FWEI$kON%NKjzP6xjm8UvX%nNY_bYBn+t4MK%Poob2pL&_Ne7Q_%!e1CH6L9Eu*> zhk-bNw}qh`$bCM5CLGY^A2MW;##jK&YV0zLt1qAg%#O#THdyiQnq2b9c{8dAPGto}36?J1%vYG!cJ==7V;_+F6qDyisz`;G@4)Ld-%fssL z*}7DPVW-jRhGFX8+PHt`TJkz`WmK58kh(jKE;eGbXb)MoIB$`+I88`J+%smuy7n3W z73?-TnhMI>was<2YBNQP<2H{!NZsf}*l+7K`vvg|K{0iXdRE{G33;x3RaB=Ww-E(C H$X|Z|h7gFw diff --git a/src/main.py b/src/main.py index 87264dc..47a1665 100644 --- a/src/main.py +++ b/src/main.py @@ -71,4 +71,4 @@ def cli(start_at: int = 0): if __name__ == "__main__": - cli(start_at=0) + cli(start_at=3) diff --git a/src/youtube_music.py b/src/youtube_music.py index 6f8eaf7..c469378 100644 --- a/src/youtube_music.py +++ b/src/youtube_music.py @@ -2,10 +2,13 @@ import youtube_dl import pandas as pd import jellyfish import logging +import time - -YDL_OPTIONS = {'format': 'bestaudio', 'noplaylist':'True'} +YDL_OPTIONS = {'format': 'bestaudio', 'noplaylist': 'True'} YOUTUBE_URL_KEY = 'webpage_url' +WAIT_BETWEEN_BLOCK = 10 +MAX_TRIES = 3 + def get_youtube_from_isrc(isrc: str): # https://stackoverflow.com/questions/63388364/searching-youtube-videos-using-youtube-dl @@ -19,6 +22,7 @@ def get_youtube_from_isrc(isrc: str): 'title': video['title'] } + def get_youtube_url(row): if pd.isna(row['isrc']): return None @@ -31,11 +35,13 @@ def get_youtube_url(row): print(real_title, video_title, phonetic_distance) if phonetic_distance > 1: - logging.warning(f"dont downloading {result['url']} cuz the phonetic distance ({phonetic_distance}) between {real_title} and {video_title} is to high.") + logging.warning( + f"dont downloading {result['url']} cuz the phonetic distance ({phonetic_distance}) between {real_title} and {video_title} is to high.") return None return result['url'] -def download(row): + +def download(row, trie: int = 0): url = row['url'] file_ = row['file'] options = { @@ -49,11 +55,20 @@ def download(row): 'outtmpl': file_ } - with youtube_dl.YoutubeDL(options) as ydl: - ydl.download([url]) + try: + with youtube_dl.YoutubeDL(options) as ydl: + ydl.download([url]) + except youtube_dl.utils.DownloadError: + logging.warning(f"youtube blocked downloading. ({trie}-{MAX_TRIES})") + if trie >= MAX_TRIES: + logging.warning("too many tries, returning") + logging.warning(f"retrying in {WAIT_BETWEEN_BLOCK} seconds again") + time.sleep(WAIT_BETWEEN_BLOCK) + return download(row, trie=trie+1) + if __name__ == "__main__": - # example isrc that exists on youtube music + # example isrc that exists on YouTube music ISRC = "DEUM71500715" result = get_youtube_from_isrc(ISRC) print(result)