add new script and some optimizations

This commit is contained in:
CoolnsX
2022-02-19 15:22:26 +05:30
parent 8118953030
commit 0e9dfc1577
4 changed files with 57 additions and 69 deletions

39
youtube
View File

@@ -11,38 +11,25 @@ c_magenta="\033[1;35m"
c_cyan="\033[1;36m"
c_reset="\033[0m"
#function to extract audio from video
ext_audio()
#function to download full video/audio
full()
{
[ -z "$2" ] &&
yt-dlp -o "$HOME/Videos/%(title)s.%(ext)s" "$1" ||
yt-dlp -f 'ba' -x --audio-format mp3 "$1" -o "$HOME/Music/%(title)s.%(ext)s"
}
#function to extract part of audio from video
part_audio()
{
video=$1
printf "${c_magenta}Enter Starting Point(hh:mm:ss)or(mm:ss)${c_reset}:"
read start
printf "${c_yellow}Enter Upto Seconds:${c_cyan}"
read end
ffmpeg -i $(yt-dlp -f 'ba' --get-url "$video") -ss $start -t $end -map a -q:a 0 "$HOME/Music/%(title)s.mp3"
}
#function to download full video
full_video()
{
yt-dlp -o "$HOME/Videos/%(title)s.%(ext)s" "$1"
}
# function to download part of a video and also split it for SNS...
part_video()
# function to download part of a video/audio..
part()
{
video=$1
printf "${c_magenta}Enter Start Point(hh:mm:ss)or(mm:ss)${c_reset}:"
read start
printf "${c_yellow}Enter End Point(hh:mm:ss)or(mm:ss):${c_cyan}"
read end
ffmpeg -i $(yt-dlp -f b --get-url "$video") -ss $start -to $end "$HOME/Videos/%(title)s.mp4"
[ -z "$2" ] &&
ffmpeg -i $(yt-dlp -f b --get-url "$video") -ss $start -to $end "$HOME/Videos/%(title)s.mp4" ||
ffmpeg -i $(yt-dlp -f 'ba' --get-url "$video") -ss $start -t $end -map a -q:a 0 "$HOME/Music/%(title)s.mp3"
}
#program starts from here..
@@ -53,13 +40,13 @@ printf "\n${c_reset}Enter choice:${c_green}"
read choice
case $choice in
a)
ext_audio "$x" && notify-send "Audio saved to Videos Directory" || notify-send -u critical "Error!!! Audio not Downloaded";;
full "$x" "1" && notify-send "Audio saved to Music Directory" || notify-send -u critical "Error!!! Audio not Downloaded";;
f)
part_audio "$x" && notify-send "Audio saved to Videos Directory" || notify-send -u critical "Error!!! Audio not Downloaded";;
part "$x" "1" && notify-send "Audio saved to Music Directory" || notify-send -u critical "Error!!! Audio not Downloaded";;
v)
full_video "$x" && notify-send "Video saved to Videos Directory" || notify-send -u critical "Error!!! Video not Downloaded";;
full "$x" && notify-send "Video saved to Videos Directory" || notify-send -u critical "Error!!! Video not Downloaded";;
p)
part_video "$x" && notify-send "Video saved to Videos Directory" || notify-send -u critical "Error!!! Video not Downloaded";;
part "$x" && notify-send "Video saved to Videos Directory" || notify-send -u critical "Error!!! Video not Downloaded";;
q)
break;;
esac