![]() |
YouTube >
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 ∞
Steps ∞
- View your list of URLs in the appropriate manner. For example, view the expanded uploads-only and sorted-by-date version of a user’s videos.
-
Get your list of URLs. You can do this in some manual way if you wish, but I prefer Firefox and the Linky extension.
- With Linky: Select, then right-click > Linky > Copy Selected Links to Clipboard
- With Snap Links Plus: By default it is right-click-drag to draw a box. Wait for the dashed line to appear around your links. Hold control and then let go of the mouse button > Copy To Clipboard
-
Paste your links into an empty text file.
- If you used Snap Links Plus, you need to convert the spaces into carriage returns using your favourite text editor.
- If your list of videos is sorted by date, and you want to appropriately number them, then reverse the order of the items in the list:
>list.txt|\tac>list.txt
- Also edit list.txt to duplicate the first entry so it’s on two lines. This is a workaround to fix the user-issue “works as intended” numbering that starts counting at zero because programmers are fucktarded like that.
-
Then run this commandline:
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: <urlopen error unknown url type: <your text> : 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
There are some other ideas in bash script to rename (renumber) files
rename:
rename 'if (m/[0-9]+/) {$_ = "pg_".($&-1).".png";}' *.png
sed (untested by its author): [ 1 ] Note that for technical reasons there is a unicode character ❲ and not a left paren (
for fil in *; do newnum = $❲($(echo $fil|sed 's/[^0-9]//g')-1)) newname = pg_${newnum}.png mv $fil $newname done
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
Footnotes
| ^ 1 | Note that for technical reasons there is a unicode character ❲ and not a left paren ( |

