Difference between revisions of "Download YouTube movies and Auto-Number Them"
(Created page with "--~~~~ ---- <br /> =YouTube-dl= <br /> This script requires [http://rg3.github.io/youtube-dl/download.html youtube-dl], which can be downloaded from GitHub. <br /> =Source= ...") |
(→Source) |
||
Line 11: | Line 11: | ||
<br /> | <br /> | ||
<source lang="python"> | <source lang="python"> | ||
+ | #! /usr/bin/env python | ||
# getYouTubeVids.py | # getYouTubeVids.py | ||
# (C) D. Thiebaut 2014 | # (C) D. Thiebaut 2014 | ||
Line 24: | Line 25: | ||
import subprocess | import subprocess | ||
+ | #--- the name to be given to all the downloaded videos --- | ||
filename = "Qt5Tutorials_Thiebaut_%02d" | filename = "Qt5Tutorials_Thiebaut_%02d" | ||
+ | #--- the video URLs. Could also just use the last part of the URL, e.g. "EAdAvMc1MCI" --- | ||
vids = [ "http://www.youtube.com/watch?v=EAdAvMc1MCI", | vids = [ "http://www.youtube.com/watch?v=EAdAvMc1MCI", | ||
"http://www.youtube.com/watch?v=XmzqZmr-S-Q" ] | "http://www.youtube.com/watch?v=XmzqZmr-S-Q" ] | ||
+ | #--- download each video and store it under the selected filename, --- | ||
+ | #--- and keep the original extension. --- | ||
for i,vid in enumerate(vids): | for i,vid in enumerate(vids): | ||
thisFileName = filename % (i+1) + ".%(ext)s" | thisFileName = filename % (i+1) + ".%(ext)s" | ||
Line 41: | Line 46: | ||
</source> | </source> | ||
<br /> | <br /> | ||
+ | =Execution= | ||
<br /> | <br /> | ||
+ | In a terminal/console window, first make the script executable: | ||
<br /> | <br /> | ||
+ | chmod a+x getYouTubeVids.py | ||
<br /> | <br /> | ||
+ | Then download the videos | ||
+ | <br /> | ||
+ | ./getYouTubeVids.py | ||
<br /> | <br /> | ||
<br /> | <br /> |
Latest revision as of 09:18, 23 March 2014
--D. Thiebaut (talk) 10:15, 23 March 2014 (EDT)
YouTube-dl
This script requires youtube-dl, which can be downloaded from GitHub.
Source
#! /usr/bin/env python
# getYouTubeVids.py
# (C) D. Thiebaut 2014
# given a list of youtube videos stored in the array vids, and a
# filename variable that represents the name of the videos, including
# a numbering scheme (%02d means 2 decimals with leading 0, i.e. 01,
# 02, etc., the program will fetch the videos using the command
# youtube-dl (to be downloaded from some other site) and will store
# all the movie files under the given filename format.
# Assumes Python V 2.7. Switch the print statements around for
# Python 3+
import subprocess
#--- the name to be given to all the downloaded videos ---
filename = "Qt5Tutorials_Thiebaut_%02d"
#--- the video URLs. Could also just use the last part of the URL, e.g. "EAdAvMc1MCI" ---
vids = [ "http://www.youtube.com/watch?v=EAdAvMc1MCI",
"http://www.youtube.com/watch?v=XmzqZmr-S-Q" ]
#--- download each video and store it under the selected filename, ---
#--- and keep the original extension. ---
for i,vid in enumerate(vids):
thisFileName = filename % (i+1) + ".%(ext)s"
#print( "youtube-dl -o \"" + thisFileName + "\" " + vid )
print "youtube-dl -o \"" + thisFileName + "\" " + vid
#call( ["youtube-dl", "-o", thisFileName, vid ] )
subprocess.Popen( ["youtube-dl", "-o", thisFileName, vid ],
stdout = subprocess.PIPE,
stderr= subprocess.PIPE ).communicate()
#print( "done" )
print "done"
Execution
In a terminal/console window, first make the script executable:
chmod a+x getYouTubeVids.py
Then download the videos
./getYouTubeVids.py