-#!/bin/sh
-
-YOUTUBEDL='/usr/local/bin/youtube-dl' # Absolute path to youtube-dl executable
-ARCHIVE='~/youtube_archive' # Absolute path to archive
-
-$YOUTUBEDL -U
-
-archive () {
- mkdir -p "$ARCHIVE/$1"
- cd "$ARCHIVE/$1"
- rmdir -- * 2> /dev/null
- rm -fv -- */*.part 2> /dev/null
- rm -rf $(find . -printf '%h\n' | sort | uniq -c | while read -r n d ; do [ $n -lt 5 ] && printf '%s\n' "$d" ; done) 2> /dev/null
-
- $YOUTUBEDL -q --get-id https://youtube.com/$2 | while read VIDEOID; do
- if [ -d "$ARCHIVE/$1/$VIDEOID" ]; then
- echo -e "\\n\\n$VIDEOID already archived, skipping…\\n\\n"
- else
- echo -r "\\n\\nArchiving $VIDEOID.\\n\\n"
- mkdir "$ARCHIVE/$1/$VIDEOID"
- cd "$ARCHIVE/$1/$VIDEOID"
- $YOUTUBEDL -o "%(upload_date)s.video" -- $VIDEOID
- ls *.video | cut -c1-8 > date.txt
- mv -v *.video video.mp4
- $YOUTUBEDL --get-title -- $VIDEOID > title.txt
- $YOUTUBEDL --get-description -- $VIDEOID > description.txt
- wget $($YOUTUBEDL --get-thumbnail -- $VIDEOID)
- mv -v *.jpg thumbnail.jpg
- fi
- done
-}
-
-# Enter channels here. For example:
-#
-# archive "Gronkh" Gronkh
-# archive "SpiegelTV" channel/UC1w6pNGiiLdZgyNpXUnA4Zw