7d6d3ba09f7a7efc811bab632e79f797d0cf6aab
1#!/bin/sh
2
3YOUTUBEDL='/usr/local/bin/youtube-dl' # Absolute path to youtube-dl executable
4ARCHIVE='~/youtube_archive' # Absolute path to archive
5
6$YOUTUBEDL -U
7
8archive () {
9 mkdir -p "$ARCHIVE/$1"
10 cd "$ARCHIVE/$1"
11 rmdir -- * 2> /dev/null
12 rm -fv -- */*.part 2> /dev/null
13 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
14
15 $YOUTUBEDL -q --get-id https://youtube.com/$2 | while read VIDEOID; do
16 if [ -d "$ARCHIVE/$1/$VIDEOID" ]; then
17 echo -e "\\n\\n$VIDEOID already archived, skipping…\\n\\n"
18 else
19 echo -r "\\n\\nArchiving $VIDEOID.\\n\\n"
20 mkdir "$ARCHIVE/$1/$VIDEOID"
21 cd "$ARCHIVE/$1/$VIDEOID"
22 $YOUTUBEDL -o "%(upload_date)s.video" -- $VIDEOID
23 ls *.video | cut -c1-8 > date.txt
24 mv -v *.video video.mp4
25 $YOUTUBEDL --get-title -- $VIDEOID > title.txt
26 $YOUTUBEDL --get-description -- $VIDEOID > description.txt
27 wget $($YOUTUBEDL --get-thumbnail -- $VIDEOID)
28 mv -v *.jpg thumbnail.jpg
29 fi
30 done
31}
32
33# Enter channels here. For example:
34#
35# archive "Gronkh" Gronkh
36# archive "SpiegelTV" channel/UC1w6pNGiiLdZgyNpXUnA4Zw