spiralofhope logo
S
piral of Hope
Better software is possible.
Styles
Table of Contents

2010-05-10

Introduction  § 

I was sick and tired of screwing around with Firefox and multiple tabs, extensions and scripts for the Greasemonkey extension. I decided to research a proper way to bulk-download YouTube videos in a very simple way.

Tools  § 

  1. Firefox
  2. the Linky extension
    1. or Snap Links Plus
  3. Python
  4. youtube-dl

Steps  § 

>list.txt|\tac>list.txt
python ./youtube-dl \ 
--best-quality \
--batch-file ./list.txt \
-o '%(uploader)s - %(ord)s - %(title)s.%(ext)s'

You'll get a result like this:

[youtube] f0uMwUsa834: Downloading video info webpage 
[youtube] f0uMwUsa834: Extracting video information
[youtube] f0uMwUsa834: Format 37 not available
[youtube] f0uMwUsa834: Downloading video info webpage
[youtube] f0uMwUsa834: Extracting video information
[youtube] f0uMwUsa834: Format 22 not available
[youtube] f0uMwUsa834: Downloading video info webpage
[youtube] f0uMwUsa834: Extracting video information
[youtube] f0uMwUsa834: Format 35 not available
[youtube] f0uMwUsa834: Downloading video info webpage
[youtube] f0uMwUsa834: Extracting video information
[download] Destination: ItsJustSomeRandomGuy - 00019 - Goblin Bloggin'.mp4
[download] 31.4% of 17.51M at 198.08k/s ETA 01:02

If you manually edited the list and they're not a sequence of videos (or you don't care), then you can remove %(ord)s:

python ./youtube-dl \ 
--best-quality \
--batch-file ./list.txt \
-o '%(uploader)s - %(title)s.%(ext)s'

If you'd like to keep a log file so that you can notice any missing/private files, you can keep viewing the output and also create a log file using a 2>&1 redirection like this:

python ./youtube-dl \ 
--best-quality \
--batch-file ./list.txt \
-o '%(uploader)s - %(ord)s - %(title)s.%(ext)s' \
2>&1 | tee list.log

(I haven't experimented with removing the reliance on tee )

After everything has been processed, search the log file for ERROR:. Some of the error messages you may see include:

ERROR: Unable to retrieve video webpage:
ERROR: YouTube said: This is a private video. If you have been sent this video, please make sure you accept the sender's friend request.
ERROR: YouTube said: This video has been removed by the user.
ERROR: YouTube said: This video has been removed due to terms of use violation.

Apparently youtube-dl will abort when it comes to an error. So you'd need to copy the referred youtube video and find it in your log.txt, delete it and everything above it which was processed properly, and re-run the commandline to continue. I have not explored a way to ignore errors and continue on.

Renumbering Files  § 

I would appreciate a simple way of renumbering the files if someone forgets to duplicate the first video file.

awk for a text file:

awk '{$3=NR}{print}' list.txt

Some other ideas here: [1]

rename:

rename 'if (m/[0-9]+/) {$_ = "pg_".($&-1).".png";}' *.png

sed (untested by its author):

for fil in *; do 
newnum = $(($(echo $fil|sed 's/[^0-9]//g')-1))
newname = pg_${newnum}.png
mv $fil $newname
done

Shell/bash:

i=1 
for f in pg_*.pdf; do
i=$(printf %02d $i) #zero-pad "$i", if wanted
mv "$f" "${f/%_*.pdf/_$i.pdf}" #replace the orginal file ending with "$i.pdf"
let i++ #increment "$i" for the next file
done
web stats