From ea03f3fc4d8317f22e5395a463a849c63fdc1f44 Mon Sep 17 00:00:00 2001 From: panni Date: Sun, 12 Apr 2020 22:47:21 +0200 Subject: [PATCH] providers: addic7ed: properly compare last_dl, add last_reset tracking info to log #723 --- .../Shared/subliminal_patch/providers/addic7ed.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Contents/Libraries/Shared/subliminal_patch/providers/addic7ed.py b/Contents/Libraries/Shared/subliminal_patch/providers/addic7ed.py index 87dbb8fa..f460cb22 100644 --- a/Contents/Libraries/Shared/subliminal_patch/providers/addic7ed.py +++ b/Contents/Libraries/Shared/subliminal_patch/providers/addic7ed.py @@ -403,10 +403,14 @@ class Addic7edProvider(_Addic7edProvider): def download_subtitle(self, subtitle): last_dl = region.get("addic7ed_dl_ts") + last_reset = region.get("addic7ed_dl_ts_lr") amount = region.get("addic7ed_dl_amount") if amount is NO_VALUE: amount = 0 + if last_reset is NO_VALUE: + last_reset = "never" + cap = self.vip and 80 or 40 # we may be falsely assuming germany here; also they might just use UTC. @@ -414,9 +418,11 @@ class Addic7edProvider(_Addic7edProvider): midnight = datetime.datetime.combine(germany_now, datetime.time.min) # reset at night - if last_dl <= midnight: + if last_dl and last_dl != NO_VALUE and last_dl <= midnight: logger.info("Reset dl amount (max: %s)", cap) region.set("addic7ed_dl_amount", 0) + region.set("addic7ed_dl_ts_lr", germany_now) + last_reset = germany_now amount = 0 if amount >= cap: @@ -444,3 +450,4 @@ class Addic7edProvider(_Addic7edProvider): subtitle.content = fix_line_ending(r.content) region.set("addic7ed_dl_amount", amount + 1) region.set("addic7ed_dl_ts", germany_now) + logger.info("Used %s/%s of downloads since %s", (amount + 1, cap, last_reset))