làm cách nào để tải video youtube bằng python
Nov 02 2020
tôi viết một chương trình tải xuống youtube đơn giản
đây là mã:
YouTube("https://youtu.be/7nXt6oggOlE").streams.first().download()
khi tôi thực thi mã này, tôi gặp lỗi này:
File "<stdin>", line 1, in <module>
File "C:\Users\ajaym\AppData\Local\Programs\Python\Python37\lib\site-packages\pytube\__main__.py", line 91, in __init__
self.prefetch()
File "C:\Users\ajaym\AppData\Local\Programs\Python\Python37\lib\site-packages\pytube\__main__.py", line 183, in prefetch
self.js_url = extract.js_url(self.watch_html)
File "C:\Users\ajaym\AppData\Local\Programs\Python\Python37\lib\site-packages\pytube\extract.py", line 143, in js_url
base_js = get_ytplayer_config(html)["assets"]["js"]
KeyError: 'assets'
Trả lời
2 SachinRajput Nov 02 2020 at 11:12
Hãy thử cách này, nó có hiệu quả với tôi.
pip uninstall pytube
pip uninstall pytube3
python -m pip install git+https://github.com/nficano/pytube
2 Ragnar Nov 02 2020 at 13:01
Đây là những gì tôi đã sử dụng gần đây
from pytube import YouTube
import os
link = "https://www.youtube.com/watch?v=wl8X-kV-gmU&ab_channel=MixHound"
path = 'C:\\YouTube_download_path'
def downloadYouTube(videourl, path):
yt = YouTube(videourl)
yt = yt.streams.filter(progressive=True, file_extension='mp4').order_by('resolution').desc().first()
if not os.path.exists(path):
os.makedirs(path)
yt.download(path)
downloadYouTube(link, path)