Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- echo "This is a simple (and low quality) script to download all videos from"
- echo youtube playlist and convert them to mp3. it use youtube-dl and ffmpeg
- echo binaries to achieve this. To use this you will need ID of a YouTube
- echo playlist and internet connection to download videos. This script will
- echo need autnentication via sudo once for installing or updating ffmpeg
- echo in the following steps it will ask for some info like playlisy id.
- echo working directory, prefered video formats etc. There is no default so
- echo you must answer all questions in the following steps!
- echo This script for now works only with ubuntu based Operating system!
- echo
- echo ------------------------------------------------------------------------
- echo
- echo Enter the playlist ID
- echo If your playlist url is http://www.youtube.com/playlist?list=PLpsNuha2_QyaGF2AX813SJP9Tqj4rjxls
- echo then playlist id is PLpsNuha2_QyaGF2AX813SJP9Tqj4rjxls
- echo example playlist id: PLpsNuha2_QyaGF2AX813SJP9Tqj4rjxls
- read PLAYLIST
- PLAYLISTURL=https://www.youtube.com/view_play_list?p=$PLAYLIST
- echo Ok, Playlist is $PLAYLISTURL
- echo Enter directory to use
- echo you can use relative directory like Videos or absulute path like /home/user/youtube-videos
- echo you do not need to create the directory manually.
- echo Script will create the folder automatically if not exist.
- echo IF YOU ARE USING EXISTING FOLDER IS SHOULD BE EMPTY!
- echo example relative directory: Videos
- echo example relative directory: youtube/Videos
- echo example absulute path: /home/user/youtube/Videos
- read DIRT
- echo Ok, directory is $DIRT
- echo Checking if your prefered directory exist and creating automatically if not exist
- mkdir -p $DIRT
- echo Changing to working directory
- cd $DIRT
- echo please select your prefered video quality
- echo higher quality will result higher file size and take longer to download
- echo For your referance here is some common code for quality
- echo you can see all supported codes at https://en.wikipedia.org/wiki/YouTube#Quality_and_codecs
- echo
- echo "144p/3gp: 17 (Very Low Quality)"
- echo "240p/3gp: 36 (Low Quality)"
- echo "240p/flv: 5 (Low Quality)"
- echo "360p/mp4: 18 (Medium Quality) - Prefered For most videos"
- echo "480p/flv: 35 (High Quality)"
- echo "720p/mp4: 22 (High Quality HD resulation) - Prefered for Screen presentation, video tutorials"
- echo "1080p/mp4: 37 (Very High Quality FullHD resulation)"
- echo
- echo Input the appropriate code below
- echo for best results use mp4 formats
- echo you can prefer two or three types at once.
- echo If first one is not avaulable next one will be used and so on
- echo "just make sure you are using same container/file format (mp4 or flv)"
- echo example of single code 18
- echo example of multiple preferance: 37/22/18
- read Q
- echo Please input file format of that code
- echo Your file format must match with quality code.
- echo for instance, if you chose code 18 your file time is mp4
- echo acceptable values mp4 flv 3gp
- echo example input: mp4
- read T
- echo "Ok, your selected quality code(s): $Q and file format: $T"
- echo please set a bitrate for converted audio/mp3 files
- echo higher bitrate will result better quality and larger file size
- echo you should input bitrate as a number and k in the end
- echo here are some most common example
- echo 24k 32k 64k 96k 128k 192k 256k
- echo only one is allowed
- echo example input 128k
- read AQ
- echo ok, your selected audio bitrate for converted mp3 is $AQ
- echo this script needs youtube-dl and ffmpeg binaries to work.
- echo checking if they are installed
- echo if they are not installed script will try to install them automatically
- echo this will also upgrade outdated binary if needed
- echo you may need to authenticate
- echo this may take some time
- # latest version of youtube-dl is important and generally
- # not available in distributions repository. So this check
- # will add addiional ppa for it if needed.
- if [ "$(which youtube-dl)" = '' ]; then
- echo youtube-dl binary not found. To install latest version of
- echo youtube-dl we will add webupd8 ppa
- echo please hit enter when asked to add this ppa and continue
- sudo add-apt-repository ppa:nilarimogard/webupd8
- fi
- # Even if system has youtube-dl and ffmpeg installed this
- # process will make sure they are latest version and/or
- # update them if needed.
- sudo apt-get -qq update
- sudo apt-get -y -qq install youtube-dl ffmpeg
- echo all required binaries are present, installed or upgraded as needed
- echo We are good to go!
- echo Have some coffee while we finish downloading and converting.
- echo Downloading videos with youtube-dl binary
- echo this will take some time according to your quality selection and internet speed!
- youtube-dl -citA -f $Q $PLAYLISTURL
- echo All videos have been downloaded.
- echo If there was any problem with one or two videos are were ignored
- echo Download complete!
- echo Converting to mp3 using ffmpeg binary
- echo this will take some time according to your processor power!
- for F in *.$T
- do
- ffmpeg -i "$F" -acodec libmp3lame -ab $AQ "${F%.$T}.mp3"
- echo all files have been converted.
- echo If there was any problem with one or two videos are were ignored
- echo Conversation complete!
- echo we will move mp3 files to a folder called mp3 inside your selected directory
- echo for easier access and seperation between video and audio files
- echo Creating mp3 directory to move mp3 files
- mkdir -p mp3
- echo Moving all mp3 files to mp3 folder
- mv -f -t mp3 *.mp3
- echo File moving complete!
- echo Everything done thanks to powerful youtube-dl, ffmpeg and bash!
- echo Thank you very much for using this script!
- echo You will find all mp4/video files in your specified $DIRT folder.
- echo You will find all mp3/audio files in mp3 folder inside your specified $DIRT folder.
- echo If you have any question, feedback or suggestion please email me at kuasha420@gmail.com
- echo Bye!
- done
Advertisement
Add Comment
Please, Sign In to add comment