Site Map - skip to main content - dyslexic font - mobile - text - print

Hacker Public Radio

Your ideas, projects, opinions - podcasted.

New episodes Monday through Friday.


hpr2710 :: Youtube downloader for channels

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

<< First, < Previous, Next >, Latest >>

Host Image
Hosted by Ken Fallon on 2018-12-21 is flagged as Explicit and is released under a CC-BY-SA license.
Tags: youtube, youtube-dl.
Listen in ogg, spx, or mp3 format. | Comments (0)

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 http://thebestofyoutube.com
# (c) Ken Fallon http://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.

<< First, < Previous, Next >, Latest >>

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 P in HPR stand for ?
Are you a spammer →
Who hosted this show →
What does HPR mean to you ?