From 29db82a8de1853d8d4536d3f093a823cab65d6cc Mon Sep 17 00:00:00 2001 From: "Git Commiter for 96-fromsofia.net" <2a9-7cc@96-fromsofia.net> Date: Mon, 27 Feb 2023 01:46:06 +0000 Subject: [PATCH] First commit --- README.txt | 8 ++++++++ youtube-dl-batch.sh | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 README.txt create mode 100644 youtube-dl-batch.sh diff --git a/README.txt b/README.txt new file mode 100644 index 0000000..0f0c66d --- /dev/null +++ b/README.txt @@ -0,0 +1,8 @@ +DESCRIPTION: +A BASH script playing around youtube-dl. Will download the highest available video and audio quiality as mp4 files and then merge them together. Can be used to obtain high quality videos from youtube. You can also pass a list of URLs separated by a space. + +NOTE: +This script works around the youtube-dl utility meaning you will need to have the package installed on your system. + +AUTHOR: +96-fromsofia - 2A9-7CC@96-fromsofia.net || August 2021 diff --git a/youtube-dl-batch.sh b/youtube-dl-batch.sh new file mode 100644 index 0000000..1b1401a --- /dev/null +++ b/youtube-dl-batch.sh @@ -0,0 +1,41 @@ +#!/bin/bash + +# Promot for a URL +printf "************************************************************************************************************\n## Please provide the youtube URL of the movie you want to download ##\n************************************************************************************************************\n" +read -a list + +# Download and merge files for each URL provided +for i in "${list[@]}" ; do + printf "************************************************************************************************************\n## Please wait while the audio and video formats are being downloaded and the media has been merged.. ##\n## Currently downloading: $i ##\n************************************************************************************************************\n" + + #get the youtube-dl format codes for both the audio and video files + audio_code=$(youtube-dl -F $i | grep "m4a" | sort -k7n,7 | tail -1 | awk '{print $1}') + video_code=$(youtube-dl -F $i | grep "video only" | grep "mp4" | sort -k3n,3 | tail -1 | awk '{print $1}') + + # download the audio and video formats and save the output to above created temp file + movie_tmp=/tmp/movie_tmp.txt + youtube-dl -f $audio_code,$video_code $i -o '%(title)s.%(ext)s' &> $movie_tmp + + # generate file names from above said temp file + audio_file=$(grep "\[download\]\ Destination:" $movie_tmp | cut -c 25- | grep m4a) + video_file=$(grep "\[download\]\ Destination:" $movie_tmp | cut -c 25- | grep mp4) + movie_name=$(echo $audio_file | rev | cut -c 5- | rev) + + # allows to store strings with spaces in variables and then use mv/mkdir/rm on these + IFS=' +' + # make the movie directory and merge audio + video into the movie + mkdir $movie_name + cd $movie_name + ffmpeg -loglevel error -i "../$video_file" -i "../$audio_file" -strict -2 -codec copy "$movie_name.mp4" + + # clear no longer needed files + rm $movie_tmp ../$audio_file ../$video_file + + printf "************************************************************************************************************\n## The movie $movie_name has now been saved: ##\n$(date ; hostname ; pwd ; du -sh *)\n************************************************************************************************************" + + # resturn to directory user was prior to initiating this script. + cd .. +done + +exit