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 fordown the Infon options. that 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 Adobevid.ap_mapso system. : 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: Usecred shelld.com 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 stout。 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)force 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 notfiles. 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's as arlment the as aril 3_ft takes 'ctx' as arlal_s arl. 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 ableu ich 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 conameers formatnot. 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. filecheck_formats Whether to test if the formats are downloadable. filecheck_check bes, nocse, nats '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 (inils : 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 sholdoutso be : 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/load on downsload not . 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 a Overst extractor names thatswoo rite 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 Processing tiareh. : 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 tlebar.wion scriptionoffilewion scription. 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 givenwritewrite nail 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 swoolrites: Wcurfile, interform. /.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)writesubtviditvid: Wtvideoovidles amot:c8888888888885888888 月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 subit 到 subtcan to trales to be be list toal list to trales toal list to trawles" list to tiable" subtitles. The language can be prefixed with a "-" to exclude it from the requested languages, eg ['all', '-live_chat']keepvideo: Keep the video file after post-proces 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 play list. 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