Skip to content

Instantly share code, notes, and snippets.

@viktorlindgren
Last active December 23, 2015 14:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save viktorlindgren/6649810 to your computer and use it in GitHub Desktop.
Save viktorlindgren/6649810 to your computer and use it in GitHub Desktop.
Subscript system of one Youtube channel using youtube-dl that only downloads newer videos since last time ran. youtube-dl can be found at http://rg3.github.io/youtube-dl/
from datetime import date, datetime
from subprocess import Popen, PIPE
import sys
DATEFORMAT = "%Y%m%d"
CONFPATH = 'last_updated.txt'
CMD = '''\
youtube-dl.exe -ci -w -o "%(title)s.%(ext)s" http://www.youtube.com/user/WTii1 --match-title "Warcraft 3.*"\
'''
def ytdl():
global DATEFORMAT,CONFPATH,CMD
last_updated = None
try:
with open(CONFPATH, "r") as conf:
last_updated = datetime.strptime(conf.readline().strip(), DATEFORMAT)
except:
last_updated = date.today()
print "No config file found! Picking only today"
CMD += " --dateafter %s" % last_updated.strftime(DATEFORMAT)
print "Executing %s" % CMD
process = Popen(CMD, shell=True ,stdout=PIPE, stderr=PIPE)
# This does not show progressbar while downloading
# for line in iter(process.stdout.readline, ''): print line,
# instead, loop each character
while True:
out = process.stdout.read(1)
if out == '' and process.poll() != None:
break
if out != '':
sys.stdout.write(out)
sys.stdout.flush()
print "Saving config"
with open(CONFPATH, "w") as conf:
conf.write(date.today().strftime(DATEFORMAT))
if __name__ == "__main__":
ytdl()
@viktorlindgren
Copy link
Author

Made this built for youtube-dl and a pull request but instead a better solution was built by them. See the --download-archive option.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment