dotfiles

regexghost dotfiles and scripts
git clone https://git.regexghost.com/dotfiles.git
Log | Files | Refs | README

download-vids.sh (2225B)


      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<=720][fps<=60][vcodec*=avc]+bestaudio[ext=m4a]"
      9 quality_options_shorts="bestvideo[width<=720][vcodec*=avc]+bestaudio[ext=m4a]"
     10 filename_options="%(channel)s - %(title)s.%(ext)s"
     11 sub_options="--embed-subs --sub-langs en.*"
     12 metadata_options="--embed-chapters"
     13 
     14 if [ "$1" = "s" ]; then
     15 	targetDir="${targetDir}/Shorts"
     16 elif [ "$1" = "v" ]; then
     17 	targetDir="${targetDir}/Videos"
     18 fi
     19 
     20 i=1
     21 while read -r info_file; do
     22 	[ "$info_file" = "" ] && echo "No videos queued" && exit
     23 	video_name_channel="$(cat "$info_file" | head -n 2 | tac | awk '{print}' ORS=' - ' | sed 's/..$//g')"
     24 	echo "${i}: ${video_name_channel}"
     25 	i=$((i+1))
     26 done <<EOF
     27 $(find "$targetDir/Shorts" "$targetDir/Videos" -type f | sort)
     28 EOF
     29 
     30 read -p "Select videos to download/delete (e.g. 1 2 -3): " toDownload
     31 
     32 [ -f /tmp/to_download ] && rm /tmp/to_download
     33 [ -f /tmp/to_delete ] && rm /tmp/to_delete
     34 
     35 [ "$toDownload" = "" ] && exit
     36 
     37 if [ "$toDownload" = "a" ] || [ "$toDownload" = "all" ]; then
     38 	find "$targetDir/Shorts" "$targetDir/Videos" -type f | sort >> /tmp/to_download
     39 else
     40 	for i in $toDownload; do
     41 		index="$(echo "$i" | sed 's/^-//g')"
     42 		path="$(find "$targetDir/Shorts" "$targetDir/Videos" -type f | sort | sed -n "${index}p")"
     43 		if [ "$(echo "$i" | cut -c 1)" = "-" ]; then
     44 			echo "$path" >> /tmp/to_delete
     45 		else
     46 			echo "$path" >> /tmp/to_download
     47 		fi
     48 	done
     49 fi
     50 
     51 if [ -f /tmp/to_delete ]; then
     52 	while read -r path; do
     53 		rm "$path"
     54 	done <<EOF
     55 $(cat /tmp/to_delete)
     56 EOF
     57 fi
     58 
     59 [ -f /tmp/to_download ] || exit
     60 
     61 while read -r path; do
     62 	id="$(basename "$path" | sed 's/.txt//g')"
     63 	if echo "$path" | grep -q Shorts; then
     64 		yt-dlp $sub_options $metadata_options -o "$filename_options" -f "$quality_options_shorts" -P "$LOC/Shorts" -- "$id"
     65 	else
     66 		yt-dlp $sub_options $metadata_options -o "$filename_options" -f "$quality_options_videos" -P "$LOC/Videos" -- "$id"
     67 	fi
     68 	if [ "$?" = "0" ]; then
     69 		mv "$path" "$targetDir/done"
     70 	fi
     71 done <<EOF
     72 $(cat /tmp/to_download)
     73 EOF
     74 
     75 [ -f /tmp/to_download ] && rm /tmp/to_download
     76 
     77 rm "$HOME/Videos/YouTube/Videos/*.json
     78 rm "$HOME/Videos/YouTube/Shorts/*.json