如何使用Python中的youtube dl提取所有.mp4?
我正在尝试编写一个Python脚本,它可以以.mp4文件格式提取任何视频的下载链接。为此,我使用了如何使用Python中的youtube dl提取所有.mp4?,python,youtube,youtube-dl,Python,Youtube,Youtube Dl,我正在尝试编写一个Python脚本,它可以以.mp4文件格式提取任何视频的下载链接。为此,我使用了youtube dl,但它以.m3u8文件格式返回视频链接。如何以.mp4文件格式获取它们?格式mp4代码: 137:1080便士 136:720便士 135:480便士 134:360便士 133:240便士 import youtube_dl url = 'https://twitter.com/PassengersMovie/status/821025484150423557' with
youtube dl
,但它以.m3u8文件格式返回视频链接。如何以.mp4文件格式获取它们?格式mp4代码:
- 137:1080便士
- 136:720便士
- 135:480便士
- 134:360便士
- 133:240便士
import youtube_dl url = 'https://twitter.com/PassengersMovie/status/821025484150423557' with youtube_dl.YoutubeDL({'format':'137'}) as ydl: ydl.download([url])
- 137:1080便士
- 136:720便士
- 135:480便士
- 134:360便士
- 133:240便士
import youtube_dl url = 'https://twitter.com/PassengersMovie/status/821025484150423557' with youtube_dl.YoutubeDL({'format':'137'}) as ydl: ydl.download([url])
下载列表
import youtube_dl
from enum import Enum
class YLFormat(Enum):
m4a = '140' # audio only
mp4_144p = '160'
mp4_240p = '133'
mp4_360p = '134'
mp4_480p = '135'
mp4_720p = '136'
mp4_1080p = '137'
gp3_176_144 = '17' # 3gp: 176*144
gp3_320_240 = '36'
flv = '5'
webm = '43'
mp4_640_360 = '18' # 640 * 360
mp4_1280_720 = '22'
def download(url: str, options: dict):
with youtube_dl.YoutubeDL(options) as ydl:
ydl.download([url])
download_list = [ # edit this
('https://www.youtube.com/watch?v=vbttZVTSJRU', YLFormat.mp4_640_360, YLFormat.mp4_1280_720, ...),
]
for cur_data in download_list:
cur_url, tuple_format = cur_data[0], cur_data[1:]
for format_info in tuple_format:
if not isinstance(format_info, YLFormat):
print(f'the format is not correct. format: {format_info}')
continue
fmt_name, fmt = format_info.name, format_info.value
try:
download(cur_url, dict(format=fmt,
outtmpl=f'%(title)s-{fmt_name}.%(ext)s',
# ignoreerrors=True,
# quiet=True
))
except youtube_dl.utils.DownloadError:
print(f'download error: {cur_url} | {fmt_name}')
您可以使用以下脚本并仅编辑
下载列表
import youtube_dl
from enum import Enum
class YLFormat(Enum):
m4a = '140' # audio only
mp4_144p = '160'
mp4_240p = '133'
mp4_360p = '134'
mp4_480p = '135'
mp4_720p = '136'
mp4_1080p = '137'
gp3_176_144 = '17' # 3gp: 176*144
gp3_320_240 = '36'
flv = '5'
webm = '43'
mp4_640_360 = '18' # 640 * 360
mp4_1280_720 = '22'
def download(url: str, options: dict):
with youtube_dl.YoutubeDL(options) as ydl:
ydl.download([url])
download_list = [ # edit this
('https://www.youtube.com/watch?v=vbttZVTSJRU', YLFormat.mp4_640_360, YLFormat.mp4_1280_720, ...),
]
for cur_data in download_list:
cur_url, tuple_format = cur_data[0], cur_data[1:]
for format_info in tuple_format:
if not isinstance(format_info, YLFormat):
print(f'the format is not correct. format: {format_info}')
continue
fmt_name, fmt = format_info.name, format_info.value
try:
download(cur_url, dict(format=fmt,
outtmpl=f'%(title)s-{fmt_name}.%(ext)s',
# ignoreerrors=True,
# quiet=True
))
except youtube_dl.utils.DownloadError:
print(f'download error: {cur_url} | {fmt_name}')
我想您需要将其转换为mp4格式。我想您需要将其转换为mp4格式。如果我要提取所有可供下载的.mp4格式,该怎么办。添加循环代码,例如范围(3,8)中f的
:使用youtube_dl.YoutubeDL({'format':'13'+str(f)})作为ydl:…
以上答案在最新Linut Mint apt安装(下载版本2016.02.22-“YouTube说:无效参数”如果我想提取所有可供下载的.mp4格式,该怎么办。添加范围(3,8)中f的循环代码例如:使用YouTube_dl.YoutubeDL({'format':'13'+str(f)})作为ydl:…
以上答案在最新的Linut Mint apt安装中截至14.02.21不起作用(下载版本2016.02.22-“YouTube说:无效参数”以上答案在最新的Linut Mint apt安装中截至14.02.21不起作用(下载版本2016.02.22-实际终端输出为“格式不正确。格式:{format_info}”'所以不确定信息的格式parameter@Hektor您应该清楚地阅读答案,我说的是编辑下载列表
,因此如果您只是复制和粘贴,请从下载列表
中删除。
。我尝试更新youtube dl,然后重新运行,仍然可以。(操作系统:Windows 10
,youtube dl版本:2021.02.10
,Python:3.7.4
)是的,谢谢,我不得不下载最新版本的youtube dl,因为Mint存储库显然已过期5年。上述答案截至2012年2月14日,最新的Linut Mint apt安装不起作用(下载2016.02.22版-实际终端输出为“格式不正确。格式:{format_info}”'所以不确定信息的格式parameter@Hektor您应该清楚地阅读答案,我说的是编辑下载列表
,因此如果您只是复制和粘贴,请从下载列表
中删除。
。我尝试更新youtube dl,然后重新运行,仍然可以。(操作系统:Windows 10
,youtube dl版本:2021.02.10
,Python:3.7.4
)是的,谢谢,我不得不下载最新版本的youtube dl,因为造币厂的仓库显然已经过期5年了。