한 번만 더 해보자

[Python] youtube-dl: Unable to extract uploader id / KeyError: 'like_count' 본문

언어/Python

[Python] youtube-dl: Unable to extract uploader id / KeyError: 'like_count'

정 하임 2023. 2. 28. 19:40

상황

pafy를 이용해서 유튜브를 재생하려 했는데 에러가 발생했다

 

 

원인

코드가 업데이트 되어서 수정해야한다

 

 

Unable to extract uploader id

Traceback (most recent call last):
  File "C:\\Users\\yolov7\\detect.py", line 199, in 
    detect()
  File "C:\\Users\\yolov7\\detect.py", line 57, in detect
    dataset = LoadStreams(source, img_size=imgsz, stride=stride)
  File "C:\\Users\\yolov7\\utils\\datasets.py", line 288, in __init__
    url = pafy.new(url).getbest(preftype="mp4").url
  File "C:\\Users\\anaconda3\\envs\\ve\\lib\\site-packages\\pafy\\pafy.py", line 124, in new
    return Pafy(url, basic, gdata, size, callback, ydl_opts=ydl_opts)
  File "C:\\Users\\anaconda3\\envs\\ve\\lib\\site-packages\\pafy\\backend_youtube_dl.py", line 31, in __init__
    super(YtdlPafy, self).__init__(*args, **kwargs)
  File "C:\\Users\\anaconda3\\envs\\ve\\lib\\site-packages\\pafy\\backend_shared.py", line 97, in __init__
    self._fetch_basic()
  File "C:\\Users\\anaconda3\\envs\\ve\\lib\\site-packages\\pafy\\backend_youtube_dl.py", line 43, in _fetch_basic
    raise IOError(str(e).replace('YouTube said', 'Youtube says'))
OSError: ERROR: Unable to extract uploader id; please report this issue on <https://yt-dl.org/bug> . Make sure you are using the latest version; see  <https://yt-dl.org/update>  on how to update. Be sure to call youtube-dl with the --verbose flag and include its complete output.

/yt_dlp/extractor/youtube.py

/youtube_dl/extractor/youtube.py

파일 두 개 모두 수정해야 한다

#	'uploader_id': self._search_regex(r'/(?:channel|user)/([^/?&#]+)', owner_profile_url, 'uploader id') if owner_profile_url else None,
'uploader_id': self._search_regex(r'/(?:channel/|user/|(?=@))([^/?&#]+)', owner_profile_url, 'uploader id', default=None),

수정했는데도 KeyError: 'like_count' 에러가 발생해서 또 코드 수정했다

 

 

 

KeyError: 'like_count'

1/1: <https://www.youtube.com/watch?v=dOp0oWFHUWw>... Traceback (most recent call last):
  File "C:\\Users\\yolov7\\detect.py", line 199, in 
    detect()
  File "C:\\Users\\yolov7\\detect.py", line 57, in detect
    dataset = LoadStreams(source, img_size=imgsz, stride=stride)
  File "C:\\Users\\yolov7\\utils\\datasets.py", line 288, in __init__
    url = pafy.new(url).getbest(preftype="mp4").url
  File "C:\\Users\\anaconda3\\envs\\ve\\lib\\site-packages\\pafy\\pafy.py", line 124, in new
    return Pafy(url, basic, gdata, size, callback, ydl_opts=ydl_opts)
  File "C:\\Users\\anaconda3\\envs\\ve\\lib\\site-packages\\pafy\\backend_youtube_dl.py", line 31, in __init__
    super(YtdlPafy, self).__init__(*args, **kwargs)
  File "C:\\Users\\anaconda3\\envs\\ve\\lib\\site-packages\\pafy\\backend_shared.py", line 97, in __init__
    self._fetch_basic()
  File "C:\\Users\\anaconda3\\envs\\ve\\lib\\site-packages\\pafy\\backend_youtube_dl.py", line 53, in _fetch_basic
    self._likes = self._ydl_info['like_count']
KeyError: 'like_count'

/pafy/backend_youtube.py 코드 수정

# self._likes = self._ydl_info['like_count']
# self._dislikes = self._ydl_info['dislike_count']

self._likes = self._ydl_info.get('like_count',0)
self._dislikes = self._ydl_info.get('dislike_count',0)
반응형