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.
This commit is contained in:
Viktor Lindgren 2013-09-21 16:26:33 +02:00
parent b00ca882a4
commit c93277812e
2 changed files with 13 additions and 1 deletions

View File

@ -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 --date DATE download only videos uploaded in this date
--datebefore DATE download only videos uploaded before this date --datebefore DATE download only videos uploaded before this date
--dateafter DATE download only videos uploaded after 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: ## Download Options:
-r, --rate-limit LIMIT maximum download rate (e.g. 50k or 44.6m) -r, --rate-limit LIMIT maximum download rate (e.g. 50k or 44.6m)

View File

@ -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('--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('--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('--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', authentication.add_option('-u', '--username',
@ -532,7 +533,12 @@ def _real_main(argv=None):
if opts.date is not None: if opts.date is not None:
date = DateRange.day(opts.date) date = DateRange.day(opts.date)
else: 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 # --all-sub automatically sets --write-sub if --write-auto-sub is not given
# this was the old behaviour if only --all-sub was 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: except (IOError, OSError) as err:
sys.exit(u'ERROR: unable to save cookie jar') 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) sys.exit(retcode)
def main(argv=None): def main(argv=None):