From c93277812ea3eb574361594c6390a005e752d135 Mon Sep 17 00:00:00 2001 From: Viktor Lindgren Date: Sat, 21 Sep 2013 16:26:33 +0200 Subject: [PATCH] Added --lastrun option. This feature is useful for subscription as it remember when it last time ran in order to not try to download earlier videos that may have been seen and deleted already. --- README.md | 2 ++ youtube_dl/__init__.py | 12 +++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index f54945acc..c142a7da6 100644 --- a/README.md +++ b/README.md @@ -46,6 +46,8 @@ which means you can modify it, redistribute it or use it however you like. --date DATE download only videos uploaded in this date --datebefore DATE download only videos uploaded before this date --dateafter DATE download only videos uploaded after this date + --lastrun FILE reads and update the FILE with last completed run. + It sets --dateafter to the DATE from the FILE. ## Download Options: -r, --rate-limit LIMIT maximum download rate (e.g. 50k or 44.6m) diff --git a/youtube_dl/__init__.py b/youtube_dl/__init__.py index 1ed30aae3..b47eebbba 100644 --- a/youtube_dl/__init__.py +++ b/youtube_dl/__init__.py @@ -181,6 +181,7 @@ def parseOpts(overrideArguments=None): selection.add_option('--date', metavar='DATE', dest='date', help='download only videos uploaded in this date', default=None) selection.add_option('--datebefore', metavar='DATE', dest='datebefore', help='download only videos uploaded before this date', default=None) selection.add_option('--dateafter', metavar='DATE', dest='dateafter', help='download only videos uploaded after this date', default=None) + selection.add_option('--lastrun', metavar='FILE', dest='lastrun', help='reads and update the file with last completed run. It sets --dateafter to this value.', default=None) authentication.add_option('-u', '--username', @@ -532,7 +533,12 @@ def _real_main(argv=None): if opts.date is not None: date = DateRange.day(opts.date) else: - date = DateRange(opts.dateafter, opts.datebefore) + if opts.lastrun: + with open(opts.lastrun, "r") as conf: + date = DateRange(conf.read(), opts.datebefore) + else: + date = DateRange(opts.dateafter, opts.datebefore) + # --all-sub automatically sets --write-sub if --write-auto-sub is not given # this was the old behaviour if only --all-sub was given. @@ -668,6 +674,10 @@ def _real_main(argv=None): except (IOError, OSError) as err: sys.exit(u'ERROR: unable to save cookie jar') + if opts.lastrun and retcode is 0: + with open(opts.lastrun, "w") as conf: + conf.write(date_from_str("now")) + sys.exit(retcode) def main(argv=None):