【最全】you

您所在的位置:网站首页 youtube视频url源代码怎么找 【最全】you

【最全】you

2024-01-08 19:37| 来源: 网络整理| 查看: 265

目录 一、ffmpeg、you-get、youtube-dl简介二、ffmpeg、you-get、youtube-dl安装2.1 安装2.2 配置 三、you-get使用四、youtube-dl使用4.1 常用选项● 获取视频格式列表●下载指定格式(format)视频●保存到指定位置 4.2 综合使用 五、附录:youtube-dl参数及说明5.1帮助内容原文:5.2帮助内容译文: 5.21常规选项 5.22网络选项 5.23地理区域限制 5.24视频选择 5.25下载选项 5.26文件系统选项 5.27缩略图选项 5.28 详细程度/模拟选项 5.29工作环境选项 5.30视频格式选项 5.31字幕选项 5.32身份验证选项 5.33Adobe 通行证选项 5.34后处理选项

一、ffmpeg、you-get、youtube-dl简介

直接在github上搜索这些项目也可以查看简介、下载等。

you-get:   You-Get 是一个小型命令行实用程序,用于从 Web 下载媒体内容(视频、音频、图像)。 youtube-dl:   youtube-dl 是一款基于 Python 的小型命令行工具,允许从 YouTube、Dailymotion、Google Video、Photobucket、Facebook、Yahoo、Metacafe、Depositfiles、Bilibili 和类似网站下载视频。 它是用 pygtk 编写的,需要 Python 解释器来运行,它不受平台限制,可以在任何 GNU/Linux、Windows 或 macOS 系统上运行。   youtube-dl 还允许选择特定的可用视频质量格式进行下载,或让程序本身自动从网站下载更高质量的视频。它还支持特定的播放列表下载,在下载的视频文件中添加自定义或原始标题的选项,并支持proxy等。 ffmpeg:   FFmpeg 是处理多媒体内容(例如音频、视频、字幕和相关元数据)的库和工具的集合。FFmpeg 是处理多媒体内容(例如音频、视频、字幕和相关元数据)的库和工具的集合。

在这里使用ffmpeg的原因是:you-get和youtube-dl下载的内容可能是音视频分开下载的(某些分辨率或者某些站点),用视频剪辑软件合并又要浪费一定的时间,而安装ffmpeg之后,则可以自动合并(merge)。

二、ffmpeg、you-get、youtube-dl安装 2.1 安装 直接在github上搜索,安装项目里面的说明下载安装。通常是使用pip或者conda来安装。下载exe版本,我已经放在我的仓库里面了(也可以github或者gitee上搜索下载)。

下载链接。

2.2 配置

配置很简单,添加到环境变量(Path)就可以了。 其中,ffmpeg不是单独的可执行文件,把文件夹中的bin文件夹添加到环境变量就可以了。 如下是我的设置: 在这里插入图片描述

配置好之后,在命令行即可使用对应命令: 在这里插入图片描述

三、you-get使用

详细的使用见文章:You-get && FFmpeg,由于某种原因,翻译成英文才发布成功,不过不难读懂。

在这里,我使用python脚本的方式演示youtube视频的下载(需要proxy)。

代码:

# -*- coding = utf-8 -*- # @TIME : 2022/10/24 下午 4:02 # @Author : CQUPTLei # @File : YouTube_download.py.py # @Softeare : PyCharm import time import os from you_get import common ''' 默认参数 ''' #视频链接 v_url = 'https://www.bilibili.com/video/BV1JF411L7zw?spm_id_from=333.851.b_7265636f6d6d656e64.5' #保存格式 v_format = 'dash-flv' #保存路径 save_dir = 'D:\Python_Study\File_Save\IU' #提示信息打印函数 #'\033[5;36m' 用来设置输出内容的字体颜色和背景颜色 def LOG(info): print('\033[5;36m' + 'You-get: ' + time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time())) + ' '+info + '\033[0m') #设置要下载的视频连接 LOG("输入要下载的视频链接:") url=input("URL:") if url=='': pass else: v_url=url.replace('&','"&"') #print(v_url) #v_url=url #设置代理,默认不设置 #也可以在pycharm设置中设置(proxy) # LOG("是否需要设置代理下载(y/n)?") # proxy=input() # if proxy=='y': # common.set_http_proxy(input("请输入代理服务器和端口,例如:127.0.0.1:1080")) # elif proxy=='': # pass #或者直接设置 # common.set_http_proxy('127.0.0.1:7890') #打印输出可供选择的清晰度 LOG("正在加载可供下载的清晰度...") if input()=='': pass os.system('you-get -i '+v_url) #选择清晰度默认MP4最高画质 LOG("请输入你要下载的清晰度(默认dash-flv):") quality=input("format select:") if quality=='': pass else: v_format=quality #设置保存路径,默认为D:\Python_Study\File_Save LOG("请设置保存路径(默认路径为:D:\Python_Study\File_Save)") path=input("save path:") if path=='': pass else: save_dir=path #根据设置的参数进行下载 LOG("开始下载...") common.any_download(url=v_url,stream_id=v_format,info_only=False,output_dir=save_dir,merge=True) LOG("下载完毕")

效果: 视频地址: [IU] Blueming Live Clip (2019 IU Tour Concert ‘Love, poem’) 在这里插入图片描述

ffmpeg自动运行:

在这里插入图片描述

保存下来的视频: 在这里插入图片描述

四、youtube-dl使用 4.1 常用选项 ● 获取视频格式列表 youtube-dl -F URL

在这里插入图片描述

●下载指定格式(format)视频 youtube-dl -f format URL

format可以使用上面列出的,也可以: best 选择最佳质量的音/视频文件 worst 选择质量最差的格式(视频和音频) bestvideo 选择最佳质量的仅视频格式(例如DASH视频),可能无法使用。 worstvideo选择质量最差的纯视频格式,可能无法使用。 bestaudio 选择最优质的音频格式,可能无法使用。 worstaudio 选择质量最差的音频格式,可能无法使用。

还可以这样组合:

youtube-dl -f bestvideo+bestaudio URL

如果要分开下载把“+”改成“,”即可。

●保存到指定位置

不支持直接指定输出位置,但可以采用以下方法:

使用’-o’参数,同时指定输出目录和保存的文件名称。如 youtube-dl -o 'D:\Python_Study\File_Save\JayChou\name.flv' URL,如果只写了保存文件名称,则会默认保存在user目录之下,如果没有写‘-o’参数,则默认为视频标题,默认保存在user下。使用’cd’命令进入到文件保存位置,再下载。 4.2 综合使用

这里写一个bat脚本演示,读者使用时注意将编码设置为ANSI。

@echo off ::olor 02 ::==========================目录设置======================== ::默认下载目录 :default_save_dir set default_dir=D:\Python_Study\File_Save\test pushd %default_dir% echo 默认保存路径是:%cd% set /p mode=是否需要重新设置保存目录?(y/n) if /i %mode%==y call :set_dir if /i %mode%==n call :download if /i not %mode%==y if /i not %mode%==n echo 输入有误 echo. call :default_save_dir ::==========================下载======================== ::下载视频,不点击退出则可一直在上述文件夹下下载 :download echo. set /p url=请输入视频URL: set url=%url:&=^^^&% ::打印可供下载的视频格式 youtube-dl -F %url% if errorlevel 1 goto :download echo. set /p code=请输入视频格式(format): ::开始下载 youtube-dl -f %code% %url% goto :download ::::==========================手动设置目录======================== :set_dir echo. set /p dir=请输入保存路径: set dir=%dir:/=\% ::保存并切换到该目录 pushd %dir% ::比较当前路径与前面输入的路径是否一致,%cd%表示当前的绝对路径 if /i not %dir%==%cd% goto :set_dir echo 现在的下载目录为:%cd%

效果: 在这里插入图片描述 可见速度比较慢。 在同一网络,同一proxy之下,使用youtube-dl的升级版yt-dlp速度很快,如下: 在这里插入图片描述 对于yt-dlp的介绍见后续文章。

五、附录:youtube-dl参数及说明

youtube-dl的说明内容比较多(57KB左右),直接在命令行使用youtube-dl -h命令打印显示不完整(增大缓冲区也不行),这里直接将输出重定向,保存到文本中。 命令:youtube-dl -h >C:\Users\secret\Desktop\help.txt

5.1帮助内容原文: Usage: youtube-dl.exe [OPTIONS] URL [URL...] Options: General Options: -h, --help Print this help text and exit --version Print program version and exit -U, --update Update this program to latest version. Make sure that you have sufficient permissions (run with sudo if needed) -i, --ignore-errors Continue on download errors, for example to skip unavailable videos in a playlist --abort-on-error Abort downloading of further videos (in the playlist or the command line) if an error occurs --dump-user-agent Display the current browser identification --list-extractors List all supported extractors --extractor-descriptions Output descriptions of all supported extractors --force-generic-extractor Force extraction to use the generic extractor --default-search PREFIX Use this prefix for unqualified URLs. For example "gvsearch2:" downloads two videos from google videos for youtube- dl "large apple". Use the value "auto" to let youtube-dl guess ("auto_warning" to emit a warning when guessing). "error" just throws an error. The default value "fixup_error" repairs broken URLs, but emits an error if this is not possible instead of searching. --ignore-config Do not read configuration files. When given in the global configuration file /etc/youtube-dl.conf: Do not read the user configuration in ~/.config /youtube-dl/config (%APPDATA%/youtube- dl/config.txt on Windows) --config-location PATH Location of the configuration file; either the path to the config or its containing directory. --flat-playlist Do not extract the videos of a playlist, only list them. --mark-watched Mark videos watched (YouTube only) --no-mark-watched Do not mark videos watched (YouTube only) --no-color Do not emit color codes in output Network Options: --proxy URL Use the specified HTTP/HTTPS/SOCKS proxy. To enable SOCKS proxy, specify a proper scheme. For example socks5://127.0.0.1:1080/. Pass in an empty string (--proxy "") for direct connection --socket-timeout SECONDS Time to wait before giving up, in seconds --source-address IP Client-side IP address to bind to -4, --force-ipv4 Make all connections via IPv4 -6, --force-ipv6 Make all connections via IPv6 Geo Restriction: --geo-verification-proxy URL Use this proxy to verify the IP address for some geo-restricted sites. The default proxy specified by --proxy (or none, if the option is not present) is used for the actual downloading. --geo-bypass Bypass geographic restriction via faking X-Forwarded-For HTTP header --no-geo-bypass Do not bypass geographic restriction via faking X-Forwarded-For HTTP header --geo-bypass-country CODE Force bypass geographic restriction with explicitly provided two-letter ISO 3166-2 country code --geo-bypass-ip-block IP_BLOCK Force bypass geographic restriction with explicitly provided IP block in CIDR notation Video Selection: --playlist-start NUMBER Playlist video to start at (default is 1) --playlist-end NUMBER Playlist video to end at (default is last) --playlist-items ITEM_SPEC Playlist video items to download. Specify indices of the videos in the playlist separated by commas like: "--playlist-items 1,2,5,8" if you want to download videos indexed 1, 2, 5, 8 in the playlist. You can specify range: "--playlist-items 1-3,7,10-13", it will download the videos at index 1, 2, 3, 7, 10, 11, 12 and 13. --match-title REGEX Download only matching titles (regex or caseless sub-string) --reject-title REGEX Skip download for matching titles (regex or caseless sub-string) --max-downloads NUMBER Abort after downloading NUMBER files --min-filesize SIZE Do not download any videos smaller than SIZE (e.g. 50k or 44.6m) --max-filesize SIZE Do not download any videos larger than SIZE (e.g. 50k or 44.6m) --date DATE Download only videos uploaded in this date --datebefore DATE Download only videos uploaded on or before this date (i.e. inclusive) --dateafter DATE Download only videos uploaded on or after this date (i.e. inclusive) --min-views COUNT Do not download any videos with less than COUNT views --max-views COUNT Do not download any videos with more than COUNT views --match-filter FILTER Generic video filter. Specify any key (see the "OUTPUT TEMPLATE" for a list of available keys) to match if the key is present, !key to check if the key is not present, key > NUMBER (like "comment_count > 12", also works with >=,


【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3