VideoDownloader是一个基于yt-dlp
的python库开发的视频下载程序。
yt-dlp 是一款功能丰富的命令行音频/视频下载器,支持数千个网站。该项目是基于现已停用的 youtube-dlc 的 youtube-dl 的一个分支。
yt-dlp基本支持所有常见的视频网站,它是一个功能十分强大、参数十分丰富的命令行程序。本项目基于yt-dlp的python库(yt_dlp)进行开发,使用tkinter库构建了用于视频下载的GUI应用程序,免去了在命令行输入冗长的命令的过程,带给您一个轻松的下载体验。
默认使用Windows环境,我使用 pycharm+Anaconda:
python>=3.8
ffmpeg,用于下载后自动合并音频和视频,注意是ffmpeg的二进制可执行文件,而不是python库,记得添加到环境变量,如:D:ffmpegbin
(1)克隆本项目
git clone [email protected]:CQUPTLei/VideoDownloader.git
(2)为项目新建conda虚拟环境,示例:
conda create -n videodownload python=3.12
(3)使用pip安装yt_dlp库:
conda activate videodownload pip install yt-dlp
Linux下,以Ubuntu24.04为例,使用vim编辑,python venv虚拟环境(你使用conda也可以):
(1)克隆项目到本地
git clone [email protected]:CQUPTLei/VideoDownloader.git
(2)安装python venv
apt install python3.12-venv
(3)创建虚拟环境
python3 -m venv downloader
(4)激活虚拟环境
source downloader/bin/activate
(5)安装相关库
pip install yt-dlp sudo apt install python3-tk pip install prettytable# 打包用pip install pyinstaller
(6)给main.py可执行权限
sudo chmod 775 main.py
(7)执行(注意路径)
python3 main.py
可能的修改:如果使用了从浏览器获取cookies文件,可能需要修改路径,默认保存位置可能需要修改。
Windows:
安装pyinstaller库:
pip install pyinstaller
打包命令示例,注意各个路径,下面的代码是在main.py所在目录执行的:
pyinstaller -F --paths=D:anacondaenvsvideodownloadLibsite-packages --python=D:anacondaenvsvideodownloadpythonw.exe --noconsole --icon=icon1.ico --name=Downloader main.py
Ubuntu:
一个简单示例:
pyinstaller -F --paths=/home/moon/VideoDownloader/downloader/lib/python3.12/site-packages --python=/home/moon/VideoDownloader/downloader/bin/python312 --noconsole --icon=icon1.ico --name=Downloader main.py
MacOS:
添加对视频列表的处理和下载;
同时进行多个下载任务;
支持更多的自定义参数;
...
yt_dlp在pypi上没有专门的参考手册,github和pypi上都写得的yt-dlp命令行程序的可用参数,但你可以阅读yt_dlp的具体实现:YoutubeDL.py
来获取可用参数和含义。
以下主要是yt_dlp.YoutubeDL(download_opts)
方法支持的参数。
YoutubeDL objects accept a lot of parameters. In order not to saturatethe object constructor with arguments, it receives a dictionary ofoptions instead. These options are available through the paramsattribute for the InfoExtractors to use. The YoutubeDL alsoregisters itself as the downloader in charge for the InfoExtractorsthat are added to it, so this is a "mutual registration". Available options:username: Username for authentication purposes.password: Password for authentication purposes.videopassword: Password for accessing a video.ap_mso: Adobe Pass multiple-system operator identifier.ap_username: Multiple-system operator account username.ap_password: Multiple-system operator account password.usenetrc: Use netrc for authentication instead.netrc_location: Location of the netrc file. Defaults to ~/.netrc.netrc_cmd: Use a shell command to get credentialsverbose: Print additional info to stdout.quiet: Do not print messages to stdout.no_warnings: Do not print out anything for warnings.forceprint: A dict with keys WHEN mapped to a list of templates to print to stdout. The allowed keys are video or any of the items in utils.POSTPROCESS_WHEN. For compatibility, a single list is also acceptedprint_to_file: A dict with keys WHEN (same as forceprint) mapped to a list of tuples with (template, filename)forcejson: Force printing info_dict as JSON.dump_single_json: Force printing the info_dict of the whole playlist (or video) as a single JSON line.force_write_download_archive: Force writing download archive regardless of 'skip_download' or 'simulate'.simulate: Do not download the video files. If unset (or None), simulate only if listsubtitles, listformats or list_thumbnails is usedformat: Video format code. see "FORMAT SELECTION" for more details. You can also pass a function. The function takes 'ctx' as argument and returns the formats to download. See "build_format_selector" for an implementationallow_unplayable_formats: Allow unplayable formats to be extracted and downloaded.ignore_no_formats_error: Ignore "No video formats" error. Usefull for extracting metadata even if the video is not actually available for download (experimental)format_sort: A list of fields by which to sort the video formats. See "Sorting Formats" for more details.format_sort_force: Force the given format_sort. see "Sorting Formats" for more details.prefer_free_formats: Whether to prefer video formats with free containers over non-free ones of same quality.allow_multiple_video_streams: Allow multiple video streams to be merged into a single fileallow_multiple_audio_streams: Allow multiple audio streams to be merged into a single filecheck_formats Whether to test if the formats are downloadable. Can be True (check all), False (check none), 'selected' (check selected formats), or None (check only if requested by extractor)paths: Dictionary of output paths. The allowed keys are 'home' 'temp' and the keys of OUTTMPL_TYPES (in utils/_utils.py)outtmpl: Dictionary of templates for output names. Allowed keys are 'default' and the keys of OUTTMPL_TYPES (in utils/_utils.py). For compatibility with youtube-dl, a single string can also be usedouttmpl_na_placeholder: Placeholder for unavailable meta fields.restrictfilenames: Do not allow "&" and spaces in file namestrim_file_name: Limit length of filename (extension excluded)windowsfilenames: Force the filenames to be windows compatibleignoreerrors: Do not stop on download/postprocessing errors. Can be 'only_download' to ignore only download errors. Default is 'only_download' for CLI, but False for APIskip_playlist_after_errors: Number of allowed failures until the rest of the playlist is skippedallowed_extractors: List of regexes to match against extractor names that are allowedoverwrites: Overwrite all video and metadata files if True, overwrite only non-video files if None and don't overwrite any file if Falseplaylist_items: Specific indices of playlist to download.playlistrandom: Download playlist items in random order.lazy_playlist: Process playlist entries as they are received.matchtitle: Download only matching titles.rejecttitle: Reject downloads for matching titles.logger: Log messages to a logging.Logger instance.logtostderr: Print everything to stderr instead of stdout.consoletitle: Display progress in console window's titlebar.writedescription: Write the video description to a .description filewriteinfojson: Write the video description to a .info.json fileclean_infojson: Remove internal metadata from the infojsongetcomments: Extract video comments. This will not be written to disk unless writeinfojson is also givenwriteannotations: Write the video annotations to a .annotations.xml filewritethumbnail: Write the thumbnail image to a fileallow_playlist_files: Whether to write playlists' description, infojson etc also to disk when using the 'write*' optionswrite_all_thumbnails: Write all thumbnail formats to fileswritelink: Write an internet shortcut file, depending on the current platform (.url/.webloc/.desktop)writeurllink: Write a Windows internet shortcut file (.url)writewebloclink: Write a macOS internet shortcut file (.webloc)writedesktoplink: Write a Linux internet shortcut file (.desktop)writesubtitles: Write the video subtitles to a filewriteautomaticsub: Write the automatically generated subtitles to a filelistsubtitles: Lists all available subtitles for the videosubtitlesformat: The format code for subtitlessubtitleslangs: List of languages of the subtitles to download (can be regex). The list may contain "all" to refer to all the available subtitles. The language can be prefixed with a "-" to exclude it from the requested languages, e.g. ['all', '-live_chat']keepvideo: Keep the video file after post-processingdaterange: A utils.DateRange object, download only if the upload_date is in the range.skip_download: Skip the actual download of the video filecachedir: Location of the cache files in the filesystem. False to disable filesystem cache.noplaylist: Download single video instead of a playlist if in doubt.age_limit: An integer representing the user's age in years. Unsuitable videos for the given age are skipped.min_views: An integer representing the minimum view count the