def video_downloader(video_url_list: List[str], download_folder: str) -> None:
"""
Download videos from a list of YouTube video URLs.
Args:
video_urls (List[str]): The list of YouTube video URLs to download.
download_folder (str): The folder to save the downloaded videos.
"""
successful_downloads = 0
valid_urls: List[str] = []
for url in video_url_list:
if not url:
continue
try:
with tempfile.TemporaryDirectory() as temp_dir:
cleaned_url = clean_youtube_url(url=url)
if _get_streams(url=cleaned_url, temp_dir=temp_dir):
create_folder(download_folder)
_merge_streams(
temp_dir=temp_dir, url=url, download_folder=download_folder
)
logger.info(f"The video from {url} was downloaded successfully")
successful_downloads += 1 …Run Code Online (Sandbox Code Playgroud) 我正在尝试通过pytube以下方式下载YouTube视频:
from pytube import YouTube
YouTube('http://youtube.com/watch?v=9bZkp7q19f0').streams.first().download()
Run Code Online (Sandbox Code Playgroud)
但该文件将具有与原始视频名称相同的名称。如何指定自定义文件名?
我正在尝试制作一个可以从 YouTube 下载整个播放列表的代码。它适用于某些播放列表,但不适用于少数播放列表。我在下面的代码中显示的播放列表之一。也可以随意在此代码上添加更多功能。如果已经有下载播放列表的代码,请与我分享链接
`
from bs4 import BeautifulSoup
from pytube import YouTube
import urllib.request
import time
import os
## list of link parsed by bs4
s = []
## to name and save the playlist folder and download path respectively
directory = 'Hacker101'
savePath = "G:/Download/video/"
path = os.path.join(savePath, directory)
## link parser
past_link_here = "https://www.youtube.com/playlist?list=PLxhvVyxYRviZd1oEA9nmnilY3PhVrt4nj"
html_page = urllib.request.urlopen(past_link_here)
x = html_page.read()
soup = BeautifulSoup(x, 'html.parser')
for link in soup.findAll('a'):
k = link.get('href')
if 'watch' in k:
s.append(k)
else:
pass …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 Python pytube3 制作 YouTube 视频下载器,但它没有下载所有视频。有些视频很容易下载,但有些视频无法下载,而是显示错误:
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Users\tarun\PycharmProjects\YTDownloader\venv\lib\site-packages\pytube\extract.py", line 297, in apply_descrambler
for format_item in formats
File "C:\Users\tarun\PycharmProjects\YTDownloader\venv\lib\site-packages\pytube\extract.py", line 297, in <listcomp>
for format_item in formats
KeyError: 'url'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\tarun\AppData\Local\Programs\Python\Python37-32\lib\tkinter\__init__.py", line 1705, in __call__
return self.func(*args)
File "C:/Users/tarun/PycharmProjects/YTDownloader/YTD.py", line 15, in video_download
my_video = YouTube(input_user)
File "C:\Users\tarun\PycharmProjects\YTDownloader\venv\lib\site-packages\pytube\__main__.py", line 92, in __init__
self.descramble()
File "C:\Users\tarun\PycharmProjects\YTDownloader\venv\lib\site-packages\pytube\__main__.py", line 132, in …Run Code Online (Sandbox Code Playgroud) 我已经学习了 Python 的基础知识,所以尝试了下面的代码
from pytube import YouTube
Save_path="E:\python\youtube downloader"
link="https://www.youtube.com/watch?v=xWOoBJUqlbI"
try:
yt=YouTube(link)
except:
print("Connection error!")
mp4file=yt.filter('mp4')
yt.set_filename("ashshak")
d_file=yt.get(mp4files[-1].extention,mp4files[-1].resolution)
try:
d_file.download(Save_path)
except:
print("Error in downlaod")
print("Download failed")
Run Code Online (Sandbox Code Playgroud)
当我尝试此代码或使用我在下面给出的 GUI 界面代码时,编译器将显示此错误。但我已经安装了“pip install pytube”库
Traceback (most recent call last):
File "E:\python\youtube downloader\practiceyoutube.py", line 1, in <module>
from pytube import YouTube
File "C:\Users\PC\AppData\Local\Programs\Python\Python36\lib\site-packages\pytube\__init__.py", line 16, in <module>
from pytube.streams import Stream
File "C:\Users\PC\AppData\Local\Programs\Python\Python36\lib\site-packages\pytube\streams.py", line 17, in <module>
from pytube import extract
File "C:\Users\PC\AppData\Local\Programs\Python\Python36\lib\site-packages\pytube\extract.py", line 7, in <module>
from pytube.compat import quote
ImportError: cannot import …Run Code Online (Sandbox Code Playgroud) 尝试运行我的小测试脚本时,Pytube 十分之五会向我发送此错误。
这是脚本:
import pytube
import urllib.request
from pytube import YouTube
yt = YouTube('https://www.youtube.com/watch?v=3NCyD3XoJgM')
print('Youtube video title is: ' + yt.title + '! Downloading now!')
Run Code Online (Sandbox Code Playgroud)
这是我得到的:
Traceback (most recent call last):
File "youtube.py", line 6, in <module>
yt = YouTube('https://www.youtube.com/watch?v=3NCyD3XoJgM')
File "C:\Users\test\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\pytube\__main__.py", line 91, in __init__
self.prefetch()
File "C:\Users\test\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\pytube\__main__.py", line 183, in prefetch
self.js_url = extract.js_url(self.watch_html)
File "C:\Users\test\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\pytube\extract.py", line 143, in js_url
base_js = get_ytplayer_config(html)["assets"]["js"]
KeyError: 'assets'
Run Code Online (Sandbox Code Playgroud)
我很困扰。我尝试重新安装 Python 和 pytube,但似乎无法解决此问题。越来越令人困惑的是,该脚本有一半时间有效,而另一半时间无效。
我安装了 pytube 来从一些 YouTube 视频中提取字幕。下面的代码都给出了 xml 标题。
from pytube import YouTube
yt = YouTube('https://www.youtube.com/watch?v=4ZQQofkz9eE')
caption = yt.captions['a.en']
print(caption.xml_captions)
Run Code Online (Sandbox Code Playgroud)
正如文档中提到的
yt = YouTube('http://youtube.com/watch?v=2lAe1cqCOXo')
caption = yt.captions.get_by_language_code('en')
caption.xml_captions
Run Code Online (Sandbox Code Playgroud)
但在这两种情况下,我都会得到 xml 输出,并且在使用时
print(caption.generate_srt_captions())
Run Code Online (Sandbox Code Playgroud)
我收到如下错误。你能帮忙看看如何提取srt格式吗?
KeyError
~/anaconda3/envs/myenv/lib/python3.6/site-packages/pytube/captions.py in
generate_srt_captions(self)
49 recompiles them into the "SubRip Subtitle" format.
50 """
51 return self.xml_caption_to_srt(self.xml_captions)
52
53 @staticmethod
~/anaconda3/envs/myenv/lib/python3.6/site-packages/pytube/captions.py in
xml_caption_to_srt(self, xml_captions)
81 except KeyError:
82 duration = 0.0
83 start = float(child.attrib["start"])
84 end = start + duration
85 sequence_number = i + 1 # convert …Run Code Online (Sandbox Code Playgroud) 我正在尝试从网址“https://www.youtube.com/watch?v=uyVYfSNb_Pc&list=PLBxwSeQlMDNiNt72UmSvKBLsxPgGY_Jy-”下载 YouTube 播放列表,但收到错误“get_throtdling_function_name:无法找到多个匹配”。
代码块是:
`
from pytube import Playlist
play_list = Playlist('https://www.youtube.com/watch?v=uyVYfSNb_Pc&list=PLBxwSeQlMDNiNt72UmSvKBLsxPgGY_Jy-')
print(f'Downloading: {play_list.title}')
for video in play_list.videos:
print(video.title)
st = video.streams.get_highest_resolution()
st.download(r'path') `
Run Code Online (Sandbox Code Playgroud)
我正在使用最新版本的 pytube。
我之前已经构建了这个 YouTube 下载器,但是当我最近测试它时;它停止工作了。
from pytube import YouTube
import ffmpeg
import os
raw = 'C:\ProgramData\ytChache'
path1 = 'C:\ProgramData\ytChache\Video\\'
path2 = 'C:\ProgramData\ytChache\Audio\\'
file_type = "mp4"
if os.path.exists(path1 and path2):
boo = True
else:
boo = False
while boo:
url = str(input("Link : "))
choice = int(input('Enter 1 for Only Audio and Enter 2 For Both Audio and Video \n: '))
video = YouTube(url)
Streams = video.streams
if choice == 1:
aud = Streams.filter(only_audio=True).first().download(path2)
elif choice == 2:
resol = str(input("Resolution : ")) …Run Code Online (Sandbox Code Playgroud) 使用以下代码使用 PyTube 库下载视频时:
yt.streams.get_highest_resolution().download("PATH", f"PATH.mp4")
Run Code Online (Sandbox Code Playgroud)
我收到错误:
raise RegexMatchError(caller="get_transform_object", pattern=pattern)
pytube.exceptions.RegexMatchError: get_transform_object: could not find match for var for={(.*?)};
Run Code Online (Sandbox Code Playgroud)
我在 Stack Overflow 和 PyTube 的 Git 存储库中看到了很多修复,但它们似乎涉及cypher.py. 我想知道如何交替get_transform_object班级cypher.py以匹配正则表达式检查。