Hacker Public Radio

Your ideas, projects, opinions - podcasted.

New episodes Monday through Friday.


HPR2710: Youtube downloader for channels

Hosted by Ken Fallon on 2018-12-21 00:00:00
Download or Listen

I had a very similar problem to Ahuka aka Kevin, in hpr2675 :: YouTube Playlists. I wanted to be able to download an entire youtube channel and store them so that I could play them in the order that they were posted.

Add the url's to a file called subscriptions.txt.

#LASTRUN: 20181030
# /home/ken/sourcecode/personal/bestofyoutube/youtube-channel-watcher.bash
#
# Big Clive 
https://www.youtube.com/channel/UCtM5z2gkrGRuWd0JQMx76qA	20181030
# Essential Craftsman
https://www.youtube.com/channel/UCzr30osBdTmuFUS8IfXtXmg

Then run the script

#!/bin/bash
# Downloads videos from youtube based on selection from https://thebestofyoutube.com
# (c) Ken Fallon https://kenfallon.com
# Released under the CC-0

savepath="/mnt/media/Videos/channels"
subscriptions="${savepath}/subscriptions.txt"
YOUNGERTHAN="20010101"
RUNDATE=$(date +%Y%m%d)
youtubedl="/home/ken/sourcecode/youtube-dl/youtube-dl"
#DRYRUN="echo DEBUG: "

if [ ! -e "${subscriptions}" ]
then
	echo "Cannot find subscription file "${subscriptions}""
	exit 1
fi

if [ "$(grep "#LASTRUN: " "${subscriptions}" | wc -l )" -eq 0 ]
then
	sed --follow-symlinks '1s/^/#LASTRUN: n/' -i "${subscriptions}"
fi

# Read the subscriptions
cat "${subscriptions}" | grep -v '#' | while read channel_info
do
	if [ "$(echo "${channel_info}" | grep -P 't' | wc -l )" -eq 0 ]
	then
		DATEAFTER="--dateafter ${YOUNGERTHAN}"
	else
		DATEAFTER="--dateafter $(echo "${channel_info}" | awk '{print $NF}' )"
	fi
	channel="$(echo "${channel_info}" | awk '{print $1}' )"
	echo "Processing Channel "${channel}" since ${DATEAFTER}"
	${DRYRUN} ${youtubedl} ${DATEAFTER} --ignore-errors --no-mtime --restrict-filenames --format mp4 -o ${savepath}'/%(uploader)s/%(upload_date)s-%(title)s⋄%(id)s.%(ext)s' ${channel}
	${DRYRUN} sed --follow-symlinks "s,${channel}.*$,${channel}t${RUNDATE},g" -i "${subscriptions}"
done

${DRYRUN} sed --follow-symlinks "s/#LASTRUN: .*$/#LASTRUN: ${RUNDATE}/" -i "${subscriptions}"

Comments



More Information...


Copyright Information

Unless otherwise stated, our shows are released under a Creative Commons Attribution-ShareAlike 3.0 Unported (CC BY-SA 3.0) license.

The HPR Website Design is released to the Public Domain.