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 InfoEx options. 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 essing a video._oentication purposes.videopassword: Password accessing a . .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 aget shelld: Useget shell/.netose. 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 POms in . 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 as JSON.dump_single_json: Force printing the info_dict of the whle playor single single lists single lists playor表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 listsubt list 完成, list listth 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 implementation _unplayable_form: Alatsabled_formalcyector" for an implementation _unplayable_formables: Alats untracted tos unplayables allow_unplayable_form: Alats; 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 Forming" forming " forming for sidook sortm s. 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。 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 (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 usedouttmpl_na_placeholder: Placeholder for string can also be usedouttmpl_na_placeholder: Placeholder for unilableres names. 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 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 allowedoversed: Overrem 研究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 receivedm titled. 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: Display progress in console window's titlebar.writedescription: Display progress in console window's titlebar.writedescription: Write the video.r. 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 vidisk unless writeinfojson is also givenwriteannotations: Write the video unless write xml al. 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, interformal interform, pfile), pfile (.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 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 langualges of the subtitles to download (can be comables the reava traua3) to list list to download ( 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 a playlist if in doubt.userage_limit: intage perage the intage sentage inrepulents intage'sage the intage intage the intage intage the int. years. Unsuitable videos for the given age are skipped.min_views: An integer representing the minimum view count the</span