come posso scaricare i video di YouTube usando Python
Nov 02 2020
scrivo un semplice programma di download di YouTube
questo è il codice:
YouTube("https://youtu.be/7nXt6oggOlE").streams.first().download()
quando eseguo questo codice, ho ricevuto questo errore:
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'
Risposte
2 SachinRajput Nov 02 2020 at 11:12
Prova questo ha funzionato per me, potrebbe risolvere anche il tuo problema.
pip uninstall pytube
pip uninstall pytube3
python -m pip install git+https://github.com/nficano/pytube
2 Ragnar Nov 02 2020 at 13:01
Questo è quello che ho usato di recente
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)