标签: pytube

如何使用 pytube 下载 YouTube 视频片段?

我一直在尝试下载 YouTube 视频的某些部分。漫长的方法是下载视频然后提取其中的特定部分。但当涉及到包含长视频的大数据集时,该方法的成本就很高。

该代码有效。但下载整个视频而不是特定部分。

from pytube import YouTube

YouTube('https://www.youtube.com/embed/yf8Ub90OWFM?start=15&end=25').streams.first().download()
Run Code Online (Sandbox Code Playgroud)

预期结果:10 秒视频,时间间隔为 15-25 秒。

python pytube

3
推荐指数
1
解决办法
6946
查看次数

在 pytube 中显示进度

import pytube
def video_downloader():

    vid_url=str(input("Enter Video URL: "))
    print('Connecting, Please wait...')
    video=pytube.YouTube(vid_url)
    Streams=video.streams
    File_name=input('File Name:')
    Format=input('Audio Or Video :')

    if Format=='Audio':
        Filter=Streams.get_audio_only(subtype='mp4')
    if Format=='Video':
        Filter=Streams.get_highest_resolution()
    print('Now downloading:',video.title)
    sizer=round(Filter.filesize/1000000)
    print('Size:',sizer,'MB')


    Filter.download(filename=str(File_name))
    print('Done!')
video_downloader()
Run Code Online (Sandbox Code Playgroud)

这是我最近制作的一个脚本,用于使用 pytube 从 youtube 下载视频和音频文件,但我很难尝试添加一个函数或可以向用户显示下载进度的东西。即: 1% 完成 2% 完成等任何帮助将不胜感激:)

python web-scraping progress-bar pytube

3
推荐指数
1
解决办法
4763
查看次数

如何使 pytube 打印所有可用分辨率并用户输入一个

简介:所以我正在尝试制作一个 pytube 项目,但我陷入了这一步,

问题:我不知道如何让 pytube 列出所有可用的分辨率


from pytube import YouTube

# import the package
print("Please Paste The URL of the youtube video")
url = input()
# URL (user input)
my_video = YouTube(url)
print(my_video.title)
# Title of The Video

#Now for the Thumbnail Image
print("Thumbnail URL")
print(my_video.thumbnail_url)

#To Download the video with the users Choice of resolution

print("Choose A Resolution Please")
for stream in my_video.stream:
    print(stream)
#command for downloading the video
my_video.download()
Run Code Online (Sandbox Code Playgroud)

python pytube

3
推荐指数
1
解决办法
3717
查看次数

需要更快地将 YouTube 链接转换为声音文件

我有一个 YouTube 链接列表,我只想下载声音文件(专辑列表,然后我要将其转换为 .wav 文件进行分析)。我一直在使用 Pytube,但它非常慢,我希望找到一种方法,可以在实际下载或处理文件之前对其进行压缩,以便更快地提供文件。我正在使用的代码如下:

from pytube import YouTube
import time

t1 = time.time()
myAudioStream = YouTube("https://www.youtube.com/watch?v=U_SLL3-NEMM").streams.last()
t2 = time.time()
print(t2-t1)
myAudioStream.download("C:\\Users\\MyUser\\Python Projects\\AlbumFiles\\")
t3 = time.time()
print(t3-t2)
Run Code Online (Sandbox Code Playgroud)

那里的链接目前只是一首歌,因为我想知道需要多长时间,但仍然需要大约 200 秒。如果我想下载 4-8 倍大的内容,可能需要很长时间才能完成。在处理这些数据时我可以做些什么来加快速度?

python pytube

2
推荐指数
1
解决办法
2038
查看次数

如何使用 Python 下载 YouTube 视频?

我正在尝试使用它在 python 中的 url 下载 YouTube 视频,但我得到:

urllib.error.HTTPError:HTTP 错误 403:禁止

我正在使用 Python 库pytube下载 youtube 视频。这是我的代码:

#importing the module 
from pytube import YouTube 
  
my=YouTube("https://www.youtube.com/watch?v=R4em3LKQCAQ").streams.first()
my.download()
Run Code Online (Sandbox Code Playgroud)

我收到如下错误

引发 HTTPError(req.full_url, code, msg, hdrs, fp)

urllib.error.HTTPError:HTTP 错误 403:禁止

python pytube

2
推荐指数
1
解决办法
2316
查看次数

我正在尝试使用 pytube 下载视频,但由于某种原因没有下载声音

运行以下程序时,会下载视频,但似乎没有声音。有人可以帮我修复它吗?

from pytube import YouTube

path = '/home/15g2leve'
url = "https://www.youtube.com/watch?v=GyQjVtIGQg8"
resol = "1080p"
file_type = "mp4"


video = YouTube(url)

Streams = video.streams

vid = Streams.filter(res = resol, file_extension = file_type).first()

vid.download(path)
Run Code Online (Sandbox Code Playgroud)

python pytube

2
推荐指数
1
解决办法
1万
查看次数

如何使用 pytube 快速获取 YouTube 播放列表中的视频标题?

我需要获取 1(播放列表的视频链接列表)和 2(播放列表的视频名称列表)。这就是我正在做的事情。

from pytube import YouTube, Playlist

playlist_link = "https://www.youtube.com/playlist?list=PLJKfZ_cKGyLdYqdzGLCJPbsi9UGCcEc5e"

video_links = Playlist(playlist_link).video_urls

video_titles = []
for link in video_links:
    video_titles.append(YouTube(link).title)
Run Code Online (Sandbox Code Playgroud)

虽然这可行,但获取所有标题需要很长时间,因为每个链接都必须转换为 YouTube 对象,是否有更快的方法来做到这一点?

python youtube pytube

2
推荐指数
1
解决办法
3574
查看次数

pytube.exceptions.RegexMatchError: get_throttling_function_name: 找不到多个匹配项

我曾经通过以下方式下载歌曲:

from pytube import YouTube
video = YouTube('https://www.youtube.com/watch?v=AWXvSBHB210')
video.streams.get_by_itag(251).download()
Run Code Online (Sandbox Code Playgroud)

从今天开始出现这个错误:

回溯(最近一次调用):文件“C:\Users\Me\AppData\Local\Programs\Python\Python39\lib\site-packages\pytube_ main _.py”,第 170 行,在 fmt_streams extract.apply_signature(stream_manifest , self.vid_info, self.js) 文件 "C:\Users\Me\AppData\Local\Programs\Python\Python39\lib\site-packages\pytube\extract.py", line 409, in apply_signature cipher = Cipher( js=js) 文件 "C:\Users\Me\AppData\Local\Programs\Python\Python39\lib\site-packages\pytube\cipher.py", line 43, in init self.throttling_plan = get_throttling_plan(js) 文件“C:\Users\Me\AppData\Local\Programs\Python\Python39\lib\site-packages\pytube\cipher.py”,第 387 行,在 get_throttling_plan raw_code = get_throttling_function_code(js ) 文件“C:\Users\Me\AppData\Local\Programs\Python\Python39\lib\site-packages\pytube\cipher.py”,第 293 行,get_throttling_function_code name = re.escape(get_throttling_function_name(js)) 文件“C:\Users\Me\AppData\Local\Programs\Python\Python39\lib\site-packages\pytube\cipher.py”,第 278 行,在 get_throttling_function_name 中引发 RegexMatchError( pytube.exceptions.RegexMatchError: get_throttling_function_name: 找不到匹配多个

在处理上述异常的过程中,又发生了一个异常:

回溯(最近一次通话):文件“C:\Users\Me\Documents\YouTubeDownloader.py”,第 3 行,在 video.streams.get_by_itag(251).download() 文件“C:\Users\Me\AppData \Local\Programs\Python\Python39\lib\site-packages\pytube_ main _.py”,第 285 行,在流中返回 StreamQuery(self.fmt_streams) 文件“C:\Users\Me\AppData\Local\Programs\Python \Python39\lib\site-packages\pytube_ main _.py”,第 177 行,在 …

python-3.x pytube

2
推荐指数
4
解决办法
686
查看次数

“AttributeError:部分初始化的模块‘pytube’没有属性‘YouTube’(很可能是由于循环导入)”

这是代码:

import pytube as p
video_url = input("Enter the link: ")
youtube = p.YouTube(video_url)
filters = youtube.streams.filter(progressive=True, file_extension="mp4")
filters.get_highest_resolution().download("MyPath")
Run Code Online (Sandbox Code Playgroud)

我尝试编写代码来下载 YouTube 视频。但它抛出一个错误:

AttributeError:部分初始化的模块“pytube”没有属性“YouTube”(很可能是由于循环导入)`

完整的错误消息

我什至从网上复制粘贴代码,重新安装Python,并重新安装pytube,但没有任何效果。更令人沮丧的是,当我几个月前执行它时,它运行得很好。

python importerror pytube

2
推荐指数
1
解决办法
1445
查看次数

Pytube 'YouTube' 对象没有属性 'filter'

我正在尝试使用 pytube 从 Youtube 下载,首先我遇到了一个常见问题,我认为这是模块本身的问题,所以我使用 github 对其进行了升级,然后此代码中出现了另一个错误:

#importing the module
from pytube import YouTube

#where to Save
save_path = "E:\Mohamed's sessions\pytube"

#link of the youtube video to be downloaded
link = "https://www.youtube.com/watch?v=w9TcErzdoTg"


#creating an object using YouTube which was imported beofre
yt = YouTube(link)  # now this yt is an object created by the class youtube and has the attribute link

#filtering out all the files with mp4 extinsion
mp4files = yt.filter("mp4")

#setting the video name
yt.set_filename("Reiner and Bertholdt Transformation …
Run Code Online (Sandbox Code Playgroud)

python pytube

1
推荐指数
1
解决办法
6085
查看次数