[python] yt_dlp 라이브러리 hang 걸리는 에러 해결 하기
/usr/local/lib/python3.8/dist-packages/yt_dlp/downloader/http.py
-> 유튜브 Url open 하고 다운로드를 거의 무한시간 반복한다. parameter로 라이브러리에서 처리 하게 하면 가장 좋은 방법이지만
ydl_opts = {
"format": '(best[ext=mp4]/best_audio)[protocol^=http]',
"max-filesize":"100M",
"overwrites": True,
"outtmpl": save_video_path,
"progress_hooks": [my_my_hook],
'socket_timeout': 60,
'ignoreerrors': True,
"verbose" : True,
"compat_opts" : "abort-on-error"
}
위 방법 처럼해봐도 socket_timeout 은 네트워크 연결 타임아웃이라 소용이 없고 해서 라이브러리 내부에서 직접 수정을 했다.
테스트 해본 결과 대부분의 영상이 100회 내에서 끝나지만 영상 길이와 상관없이 100회가 넘어가는 영상 또한 존재 하기 때문에
잘 선택해서 테스트 해보면 될것같고. 영상이 자체에 문제가 있는지 아무리 시도를 해도 안되는 영상은 다운을 받을 수가 없으니
영상을 다운 받고 싶다 하면 방법을 찾아 봐야 할것같다. github에서 Issue 찾아보니 오디오와 비디오가 분리되거나 네트워크 연결이거나
하는 다양한 문제가 있던데.. 그건 담에 시간 많을때 해결 방법을 찾아 보겠다.
cnt = 0
for retry in RetryManager(self.params.get('retries'), self.report_retry):
cnt += 1
print(f'cnt : {cnt}')
# 원하는 횟수만큼 반복하게 해야함
if cnt > 100 :
close_stream()
raise
try:
establish_connection()
return download()
except RetryDownload as err:
retry.error = err.source_error
continue
except NextFragment:
retry.error = None
retry.attempt -= 1
continue
except SucceedDownload:
return True
except: # noqa: E722
close_stream()