Skip to content

Instantly share code, notes, and snippets.

@arxae
Created July 6, 2016 03:24
Show Gist options
  • Save arxae/0b1a2e508236a28bc45f2af58a3648d9 to your computer and use it in GitHub Desktop.
Save arxae/0b1a2e508236a28bc45f2af58a3648d9 to your computer and use it in GitHub Desktop.
Archives youtube channels.
#!/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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment