Archiving Youtube Videos


Archiving Youtube Videos

I wanted a way to archive some Youtube videos, as a way to make a local library of mine, for future reference of various projects. So, first i searched the Net, to find if someone else had the same idea and someone did... You can read the whole project of his here:

https://blog.ctms.me/posts/2023-12-18-download-options-youtube-archiving/

The guy did a great job figuring it out and it was (almost) exactly, what i wanted. Of course i had to make some of my own adjustments, to automate some things, specifically for the quality of the video to download. For some videos, i wanted high quality and for some others, low quality, mainly to save space on the hard drive. Videos that don't have text or many details, don't need to be downloaded in 10K resolution. So i made the following script, to add a parameter, to select the video quality. I also made sure, that the file format is gonna be .mp4 and not anything weird. The oneliner command, that uses the yt-dlp program, does all the job, on getting subtitles, thumbnail, making the correct sub-directory etc.

I also made another script, to crop videos in specific timing positions, as many of them have intros, advertisements or too much talk and i was only interested in specific parts of the video. This way i can save even more disk space.

Scripts

#!/usr/bin/bash

#https://blog.ctms.me/posts/2023-12-18-download-options-youtube-archiving/

#bash,No, parameters, passed
if [ $# -eq 0 ]; then
    echo ""
    echo "yt-downloader.sh <URL> [QUALITY]"
    echo ""
    echo "  Quality Paramaters / Default is 720p:"
    echo "    --360, -3 : 360p"
    echo "    --480, -4 : 480p"
    echo "    --720, -7 : 720p"
    echo "    --1080, -1 : 1080p"
    echo ""
    exit 1
fi

FILE="$1"
shift 1
QUALITY="136+234"

while [ True ]; do
  if [ "$1" = "--480" -o "$1" = "-4" ]; then
      QUALITY="135+234"
      shift 1
  elif [ "$1" = "--720" -o "$1" = "-7" ]; then
      QUALITY="136+234"
      shift 1
  elif [ "$1" = "--360" -o "$1" = "-3" ]; then
        QUALITY="134+234"
        shift 1
  elif [ "$1" = "--1080" -o "$1" = "-1" ]; then
      QUALITY="137+234"
      shift 1
   else
      break
  fi
done

yt-dlp --download-archive downloaded.txt -f $QUALITY -i -o "%(uploader)s/%(title)s.%(ext)s" --write-thumbnail --convert-thumbnails png --embed-thumbnail --write-subs --write-auto-subs --embed-subs --sub-langs en --embed-chapters --embed-metadata --sponsorblock-mark all,-filler --dateafter 20230615 --match-filters 'tags !*= shorts' --match-filter "is_live != true & was_live != true" "$FILE"
#!/usr/bin/bash

#bash,No, parameters, passed
if [ $# -eq 0 ] || [ "$#" -ne 3 ]; then
    echo ""
    echo "ffmpeg-crop.sh <START> <END> <FILE>"
    echo ""
    echo " START: Crop from time 00:00:00"
    echo " END  : Crop to time 00:00:00"
    echo " FILE : Input File"
    echo ""
    echo "Output file name is cropped-FILE"
    echo ""
    exit 1
fi

START="$1"
END="$2"
FILE="$3"

ffmpeg -i "$FILE" -ss "$START" -to "$END" -async 1 -c copy "cropped-$FILE" 

Add a comment

Previous Next