Package: ytdl
ytdlYet another CLI based YouTube downloader tool for linux.Features:Download only neccessary stream, not the whole videoDownload all videos or audios belong to a playlistDownload with custom name and boundingJust gather your favourite videos into a playlist, then let'sytdldownload them overnight.PrerequisitesFedora 32+, Ubuntu 20+, Debian 10+python3.6.5 or newerffmpeg4.0 or newerYouTube API keyInstallRecommend to usepipx:pipxinstallytdl
ytdlconfigHowever,pipmay work too:pipinstallytdl# don'tsudopipinstallytdlBuild from source requirespoetry:gitclonegit@github.com:ndaidong/ytdl.git&&cdytdl
poetryinstall# use raw scriptpoetryrunpythonmain.pyinfo
poetryrunpythonmain.py[command][arguments]# build wheel to `./dist` folderpoetrybuild# then install itpipxinstalldist/ytdl-VERSION-py3-none-any.whl# test itytdlinfoCLIsBasic commandsCommandDescriptionShortcutytdl config KEY VALUESet config valuecytdl config KEYShow config propertyytdl playlist PLAYLIST_URLGet playlist indexpytdl video VIDEO_URLDownload a videovytdl audio VIDEO_URLDownload audio onlyaAlmost cases,VIDEO_URLandPLAYLIST_URLcan be replaced with video ID or playlist ID.Advanced usageConfigThere are 2 properties to configure:api_keyandstore_dir.
At the first time,api_keyis empty and you have to set it before using other features.# set new `api_key`ytdlconfigapi_keyYOUR_OWN_YOUTUBE_API_KEY# change `store_dir` to new pathytdlconfigstore_dir/storage/downloads/youtube# get the current value of `api_key`ytdlconfigapi_key# show allytdlconfigBy default,store_diris being set to/home/{YOUR_USER_NAME}/ytdl_files, you should change it to more appropriate place.PlaylistNote that this command does not download actual video/audio, but a list of indexed items.# get playlist metadata into `{store_dir}/{title}.json`# this file contains a list of videos with their ID and title to download laterytdlplaylisthttps://www.youtube.com/playlist?list=PLAYLIST_ID# get playlist metadata into `{store_dir}/my_custom_playlist_name.json`ytdlplaylisthttps://www.youtube.com/playlist?list=PLAYLIST_IDmy_custom_playlist_nameFor example if we download the playlistLinux Tips and TricksThe indexed file looks like below:Then we will have some powerful ways to download the videos in this list withytdl videoorytdl audio.VideoDownload a single video file.# download a video file to `{store_dir}/video/{VIDEO_TITLE}.mp4`ytdlvideohttps://www.youtube.com/watch?v=VIDEO_ID# custom nameytdlvideohttps://www.youtube.com/watch?v=VIDEO_IDmy_custom_video_nameTo download multi items from indexed playlist, please refer the following arguments:--index_file: path to playlist index file (required)--since: video ID of the video where you want to start downloading from--limit: number of items to download, count fromsinceor the begining of the list--prefix_name: to auto naming downloaded file--prefix_num: to auto naming downloaded fileExamples:# download all videos from saved playlist index file above# these video files will be stored in `{store_dir}/video`ytdlvideo--index_file"/path/to/Linux Tips and Tricks.json"# download 5 videos from saved playlist index file above, since first itemytdlvideo--index_file"/path/to/Linux Tips and Tricks.json"--limit5# download 5 videos from saved playlist index file above, with prefix nameytdlvideo--index_file"/path/to/Linux Tips and Tricks.json"--limit5--prefix_name"Linux Tutorial"# downloaded videos should look like "Linux Tutorial - 1.mp4", "Linux Tutorial - 2.mp4" and so on# prefix_name will be useful when you want to put these files into an already created list for your different purpose# download 5 videos from saved playlist index file above, with prefix name and prefix numberytdlvideo--index_file"/path/to/Linux Tips and Tricks.json"--limit5--prefix_name"Linux Tutorial"--prefix_num25# this will be useful for the playlists those are splited to multi parts# in this case, your serie "Linux Tutorial" had already 24 items before, now count from 25 onwards# downloaded videos should look like "Linux Tutorial - 25.mp4", "Linux Tutorial - 26.mp4" and so on# similar to above command, but start from given itemytdlvideo--index_file"/path/to/Linux Tips and Tricks.json"--sinceVIDEO_ID--limit5--prefix_name"Linux Tutorial"--prefix_num25While downloading video, the stream with highestresolutionwill be selected.AudioThis is similar toytdl video, but only download audio file.
While downloading, the stream with highestabr(average bitrate) will be selected.# download a audio file to `{store_dir}/audio/{VIDEO_TITLE}.mp3`ytdlaudiohttps://www.youtube.com/watch?v=VIDEO_ID# custom nameytdlaudiohttps://www.youtube.com/watch?v=VIDEO_IDmy_custom_audio_nameTo download multi items from indexed playlist, please refer the following arguments:--index_file: path to playlist index file (required)--since: video ID of the video where you want to start downloading from--limit: number of items to download, count fromsinceor the begining of the list--prefix_name: to auto naming downloaded file--prefix_num: to auto naming downloaded fileExamples:# download all audios from saved playlist index file above# these audio files will be stored in `{store_dir}/audio`ytdlaudio--index_file"/path/to/Linux Tips and Tricks.json"# download 5 audios from saved playlist index file above, since first itemytdlaudio--index_file"/path/to/Linux Tips and Tricks.json"--limit5# download 5 audios from saved playlist index file above, with prefix nameytdlaudio--index_file"/path/to/Linux Tips and Tricks.json"--limit5--prefix_name"Linux Tutorial"# downloaded audios should look like "Linux Tutorial - 1.mp3", "Linux Tutorial - 2.mp3" and so on# prefix_name will be useful when you want to put these files into an already created list for your different purpose# download 5 audios from saved playlist index file above, with prefix name and prefix numberytdlaudio--index_file"/path/to/Linux Tips and Tricks.json"--limit5--prefix_name"Linux Tutorial"--prefix_num25# this will be useful for the playlists those are splited to multi parts# in this case, your serie "Linux Tutorial" had already 24 items before, now count from 25 onwards# downloaded audios should look like "Linux Tutorial - 25.mp3", "Linux Tutorial - 26.mp3" and so on# similar to above command, but start from given itemytdlaudio--index_file"/path/to/Linux Tips and Tricks.json"--sinceVIDEO_ID--limit5--prefix_name"Linux Tutorial"--prefix_num25Downloaded stream will be converted to .mp3 withffmpeg.DependenciesThis lib was built on top of the following packages:DependencyLicensepytube3MITpython-youtubeMITpython-fireApache License v2Testgitclonegit@github.com:ndaidong/ytdl.git&&cdytdl
poetryinstallYOUTUBE_API_KEY=your_own_key./run_test.shLicenseThe MIT License (MIT)