pafy
https://github.com/mps-youtube/pafy
GitHub - mps-youtube/pafy: Python library to download YouTube content and retrieve metadata
Python library to download YouTube content and retrieve metadata - GitHub - mps-youtube/pafy: Python library to download YouTube content and retrieve metadata
github.com
How to use ?
다음과 같이 instance를 선언한 뒤 필요한 정보를 얻을 수 있다.
import pafy
url = "https://www.youtube.com/watch?v=bMt47wvK6u0"
video = pafy.new(url)
print(video.title)
# 'Richard Jones: Introduction to game programming - PyCon 2014'
print(video.rating)
# 5.0
print(video.viewcount, video.author, video.length)
# (1916, 'PyCon 2014', 10394)
print(video.duration, video.likes, video.dislikes)
# ('02:53:14', 25, 0)
print(video.description)
# Speaker: Richard Jones
# This tutorial will walk the attendees through development of a simple game using PyGame with time left over for some experimentation and exploration of different types of games.
# Slides can be found at: https://speakerdeck.com/pycon2014 and https://github.com/PyCon/2014-slides
다음과 같이 cv2를 사용하여 영상 처리에 사용할 수 있다.
import cv2
video = video.getbest(preftype="mp4")
cap = cv2.VideoCapture(video.url)
# get video size
frameWidth = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
frameHeight = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
# get video fps
frameRate = int(cap.get(cv2.CAP_PROP_FPS))
Error
1. raise RegexNotFoundError('Unable to extract %s' % _name)
youtube_dl.utils.RegexNotFoundError: 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.
https://github.com/ytdl-org/youtube-dl/issues/31530#issuecomment-1433936907
[YouTube] Unable to extract uploader id · Issue #31530 · ytdl-org/youtube-dl
This issue is solved: read the Description below If you still want to comment after reading that, think again: first read this post below to avoid your comment being deleted or marked as spam. Chec...
github.com
Solution
[python이 설치된 path]/[python 버전]/libs/site-packages/youtube_dl/youtube.py 중 다음 line을 수정
# line 1794
# before
'uploader_id': self._search_regex(r'/(?:channel|user)/([^/?&#]+)', owner_profile_url, 'uploader id') if owner_profile_url else None,
# after
'uploader_id': self._search_regex(r'/(?:channel|user)/([^/?&#]+)', owner_profile_url, 'uploader id', fatal=False) if owner_profile_url else None,
2. KeyError: 'like_count'
self._likes = self._ydl_info['like_count']
KeyError: 'like_count'
https://github.com/mps-youtube/pafy/pull/288#issuecomment-812841914
Get video info even if no likes/dislikes exist by noembryo · Pull Request #288 · mps-youtube/pafy
If no likes/dislikes exist we get 0 not KeyError..
github.com
Solution
[python이 설치된 path]/[python 버전]/libs/site-packages/pafy/backend_youtube_dl.py 중 다음 line을 수정
# line 53 and 54
# before
self._likes = self._ydl_info['like_count']
self._dislikes = self._ydl_info['dislike_count']
# after
self._likes = self._ydl_info.get('like_count',0)
self._dislikes = self._ydl_info.get('dislike_count',0)
'Develop > Python' 카테고리의 다른 글
[Python] 화면 캡쳐 라이브러리 처리 속도 비교 (0) | 2023.11.02 |
---|---|
[Python] pytube로 Youtube 영상 처리 (0) | 2023.07.18 |
[Python] Poetry 설치 & 간단한 실습 (FastAPI) (0) | 2023.07.03 |
[Python] nohup으로 .py 백그라운드 실행 (0) | 2023.06.08 |
[Python] 우선순위 큐 (Priority Queue) (0) | 2023.01.17 |