Site Map - skip to main content

Hacker Public Radio

Your ideas, projects, opinions - podcasted.

New episodes every weekday Monday through Friday.
This page was generated by The HPR Robot at


hpr2710 :: Youtube downloader for channels

A followup to hpr2675 how you can download an entire youtube channel for local playout

<< First, < Previous, , Latest >>

Thumbnail of Ken Fallon
Hosted by Ken Fallon on Friday, 2018-12-21 is flagged as Explicit and is released under a CC-BY-SA license.
youtube, youtube-dl. 1.
The show is available on the Internet Archive at: https://archive.org/details/hpr2710

Listen in ogg, spx, or mp3 format. Play now:

Duration: 00:14:04

general.

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

Subscribe to the comments RSS feed.

Comment #1 posted on 2018-12-21 08:07:55 by Gustaf

Thank you

Nice one, this will come in handy. Thank you for posting

Leave Comment

Note to Verbose Commenters
If you can't fit everything you want to say in the comment below then you really should record a response show instead.

Note to Spammers
All comments are moderated. All links are checked by humans. We strip out all html. Feel free to record a show about yourself, or your industry, or any other topic we may find interesting. We also check shows for spam :).

Provide feedback
Your Name/Handle:
Title:
Comment:
Anti Spam Question: What does the letter P in HPR stand for?
Are you a spammer?
Who is the host of this show?
What does HPR mean to you?