download-vids.sh (1541B)
1 #!/bin/sh 2 3 LOC="${HOME}/Videos/YouTube" 4 targetDir="${LOC}/toDownload" 5 6 [ -d "$targetDir/done" ] || mkdir "$targetDir/done" 7 8 quality_options_videos="bestvideo[height<=480][vcodec*=avc]+bestaudio[ext=m4a]" 9 quality_options_shorts="bestvideo[width<=480][vcodec*=avc]+bestaudio[ext=m4a]" 10 filename_options="%(channel)s - %(title)s.%(ext)s" 11 sub_options="--embed-subs --all-subs" 12 13 if [ "$1" = "s" ]; then 14 targetDir="${targetDir}/Shorts" 15 elif [ "$1" = "v" ]; then 16 targetDir="${targetDir}/Videos" 17 fi 18 19 i=1 20 while read -r info_file; do 21 [ "$info_file" = "" ] && echo "No videos queued" && exit 22 video_name_channel="$(cat "$info_file" | head -n 2 | tac | awk '{print}' ORS=' - ' | sed 's/..$//g')" 23 echo "${i}: ${video_name_channel}" 24 i=$((i+1)) 25 done <<EOF 26 $(find "$targetDir/Shorts" "$targetDir/Videos" -type f | sort) 27 EOF 28 29 read -p "Select videos to download (e.g. 1 2 3): " toDownload 30 31 [ -f /tmp/to_download ] && rm /tmp/to_download 32 33 for i in $toDownload; do 34 path="$(find "$targetDir/Shorts" "$targetDir/Videos" -type f | sort | sed -n "${i}p")" 35 echo "$path" >> /tmp/to_download 36 done 37 38 while read -r path; do 39 id="$(basename "$path" | sed 's/.txt//g')" 40 if echo "$path" | grep -q Shorts; then 41 yt-dlp $sub_options -o "$filename_options" -f "$quality_options_shorts" -P "$LOC/Shorts" -- "$id" 42 else 43 yt-dlp $sub_options -o "$filename_options" -f "$quality_options_videos" -P "$LOC/Videos" -- "$id" 44 fi 45 if [ "$?" = "0" ]; then 46 mv "$path" "$targetDir/done" 47 fi 48 done <<EOF 49 $(cat /tmp/to_download) 50 EOF 51 52 [ -f /tmp/to_download ] && rm /tmp/to_download