Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Copy link
Owner Author

commented Oct 11, 2013

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
You can’t perform that action at this time.