From 3513283b2973c249818df021aa55da1860a6838a Mon Sep 17 00:00:00 2001 From: Alex Duchesne Date: Sat, 17 Aug 2024 13:56:06 -0400 Subject: [PATCH 1/5] Add date field to eztv --- nova3/engines/eztv.py | 22 +++++++++++++++++++++- nova3/engines/versions.txt | 2 +- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/nova3/engines/eztv.py b/nova3/engines/eztv.py index fb188fe..fc4ba87 100644 --- a/nova3/engines/eztv.py +++ b/nova3/engines/eztv.py @@ -1,10 +1,12 @@ -#VERSION: 1.15 +#VERSION: 1.16 # AUTHORS: nindogo # CONTRIBUTORS: Diego de las Heras (ngosang@hotmail.es) +import re import urllib.error import urllib.parse import urllib.request +from datetime import datetime, timedelta from html.parser import HTMLParser from novaprinter import prettyPrinter @@ -38,6 +40,7 @@ def handle_starttag(self, tag, attrs): self.current_item['leech'] = -1 self.current_item['size'] = -1 self.current_item['engine_url'] = self.url + self.current_item['pub_date'] = -1 if (tag == self.A and self.in_table_row and params.get('class') == 'magnet'): @@ -57,6 +60,23 @@ def handle_data(self, data): elif self.in_table_row and data.isnumeric(): self.current_item['seeds'] = int(data) + elif self.in_table_row: # Check for a relative time + if m := re.match(r'(\d+)h\s+(\d+)m', data): + date = datetime.now() - timedelta(hours=int(m.group(1)), minutes=int(m.group(2))) + self.current_item['pub_date'] = int(date.timestamp()) + elif m := re.match(r'(\d+)d\s+(\d+)h', data): + date = datetime.now() - timedelta(days=int(m.group(1)), hours=int(m.group(2))) + self.current_item['pub_date'] = int(date.timestamp()) + elif m := re.match(r'(\d+)\s+weeks?', data): + date = datetime.now() - timedelta(weeks=int(m.group(1))) + self.current_item['pub_date'] = int(date.timestamp()) + elif m := re.match(r'(\d+)\s+mo', data): + date = datetime.now() - timedelta(weeks=int(m.group(1)) * 4) + self.current_item['pub_date'] = int(date.timestamp()) + elif m := re.match(r'(\d+)\s+years?', data): + date = datetime.now() - timedelta(weeks=int(m.group(1)) * 52) + self.current_item['pub_date'] = int(date.timestamp()) + def handle_endtag(self, tag): if self.in_table_row and tag == self.TR: prettyPrinter(self.current_item) diff --git a/nova3/engines/versions.txt b/nova3/engines/versions.txt index c276897..6acc956 100644 --- a/nova3/engines/versions.txt +++ b/nova3/engines/versions.txt @@ -1,4 +1,4 @@ -eztv: 1.15 +eztv: 1.16 jackett: 4.0 limetorrents: 4.7 piratebay: 3.3 From 81f68fdd85bcbad0e47c1aa268407e3fac15bf14 Mon Sep 17 00:00:00 2001 From: Alex Duchesne Date: Sat, 17 Aug 2024 14:08:15 -0400 Subject: [PATCH 2/5] Appease linter by replacing m.group(n) with m[n] --- nova3/engines/eztv.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/nova3/engines/eztv.py b/nova3/engines/eztv.py index fc4ba87..329930b 100644 --- a/nova3/engines/eztv.py +++ b/nova3/engines/eztv.py @@ -62,19 +62,19 @@ def handle_data(self, data): elif self.in_table_row: # Check for a relative time if m := re.match(r'(\d+)h\s+(\d+)m', data): - date = datetime.now() - timedelta(hours=int(m.group(1)), minutes=int(m.group(2))) + date = datetime.now() - timedelta(hours=int(m[1]), minutes=int(m[2])) self.current_item['pub_date'] = int(date.timestamp()) elif m := re.match(r'(\d+)d\s+(\d+)h', data): - date = datetime.now() - timedelta(days=int(m.group(1)), hours=int(m.group(2))) + date = datetime.now() - timedelta(days=int(m[1]), hours=int(m[2])) self.current_item['pub_date'] = int(date.timestamp()) elif m := re.match(r'(\d+)\s+weeks?', data): - date = datetime.now() - timedelta(weeks=int(m.group(1))) + date = datetime.now() - timedelta(weeks=int(m[1])) self.current_item['pub_date'] = int(date.timestamp()) elif m := re.match(r'(\d+)\s+mo', data): - date = datetime.now() - timedelta(weeks=int(m.group(1)) * 4) + date = datetime.now() - timedelta(weeks=int(m[1]) * 4) self.current_item['pub_date'] = int(date.timestamp()) elif m := re.match(r'(\d+)\s+years?', data): - date = datetime.now() - timedelta(weeks=int(m.group(1)) * 52) + date = datetime.now() - timedelta(weeks=int(m[1]) * 52) self.current_item['pub_date'] = int(date.timestamp()) def handle_endtag(self, tag): From a6ec93a7690898c9615b723364a127a522dcf931 Mon Sep 17 00:00:00 2001 From: Alex Duchesne Date: Sat, 17 Aug 2024 14:49:38 -0400 Subject: [PATCH 3/5] Removed the requirement for walrus operator --- nova3/engines/eztv.py | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/nova3/engines/eztv.py b/nova3/engines/eztv.py index 329930b..91e935a 100644 --- a/nova3/engines/eztv.py +++ b/nova3/engines/eztv.py @@ -26,6 +26,13 @@ def __init__(self, url): HTMLParser.__init__(self) self.url = url + self.date_parsers = { + r"(\d+)h\s+(\d+)m": lambda m: timedelta(hours=int(m[1]), minutes=int(m[2])), + r"(\d+)d\s+(\d+)h": lambda m: timedelta(days=int(m[1]), hours=int(m[2])), + r"(\d+)\s+weeks?": lambda m: timedelta(weeks=int(m[1])), + r"(\d+)\s+mo": lambda m: timedelta(weeks=int(m[1]) * 4), + r"(\d+)\s+years?": lambda m: timedelta(weeks=int(m[1]) * 52), + } self.in_table_row = False self.current_item = {} @@ -61,21 +68,11 @@ def handle_data(self, data): self.current_item['seeds'] = int(data) elif self.in_table_row: # Check for a relative time - if m := re.match(r'(\d+)h\s+(\d+)m', data): - date = datetime.now() - timedelta(hours=int(m[1]), minutes=int(m[2])) - self.current_item['pub_date'] = int(date.timestamp()) - elif m := re.match(r'(\d+)d\s+(\d+)h', data): - date = datetime.now() - timedelta(days=int(m[1]), hours=int(m[2])) - self.current_item['pub_date'] = int(date.timestamp()) - elif m := re.match(r'(\d+)\s+weeks?', data): - date = datetime.now() - timedelta(weeks=int(m[1])) - self.current_item['pub_date'] = int(date.timestamp()) - elif m := re.match(r'(\d+)\s+mo', data): - date = datetime.now() - timedelta(weeks=int(m[1]) * 4) - self.current_item['pub_date'] = int(date.timestamp()) - elif m := re.match(r'(\d+)\s+years?', data): - date = datetime.now() - timedelta(weeks=int(m[1]) * 52) - self.current_item['pub_date'] = int(date.timestamp()) + for pattern, delta in self.date_parsers.items(): + m = re.match(pattern, data) + if m: + self.current_item["pub_date"] = int((datetime.now() - delta(m)).timestamp()) + break def handle_endtag(self, tag): if self.in_table_row and tag == self.TR: From a150c65731964648eeed295d1c986d0ce098f874 Mon Sep 17 00:00:00 2001 From: Alex Duchesne Date: Sat, 17 Aug 2024 14:53:10 -0400 Subject: [PATCH 4/5] Do the relative math inside the lambda, in case eztv ever gets absolute dates --- nova3/engines/eztv.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/nova3/engines/eztv.py b/nova3/engines/eztv.py index 91e935a..9f65629 100644 --- a/nova3/engines/eztv.py +++ b/nova3/engines/eztv.py @@ -26,12 +26,13 @@ def __init__(self, url): HTMLParser.__init__(self) self.url = url + now = datetime.now() self.date_parsers = { - r"(\d+)h\s+(\d+)m": lambda m: timedelta(hours=int(m[1]), minutes=int(m[2])), - r"(\d+)d\s+(\d+)h": lambda m: timedelta(days=int(m[1]), hours=int(m[2])), - r"(\d+)\s+weeks?": lambda m: timedelta(weeks=int(m[1])), - r"(\d+)\s+mo": lambda m: timedelta(weeks=int(m[1]) * 4), - r"(\d+)\s+years?": lambda m: timedelta(weeks=int(m[1]) * 52), + r"(\d+)h\s+(\d+)m": lambda m: now - timedelta(hours=int(m[1]), minutes=int(m[2])), + r"(\d+)d\s+(\d+)h": lambda m: now - timedelta(days=int(m[1]), hours=int(m[2])), + r"(\d+)\s+weeks?": lambda m: now - timedelta(weeks=int(m[1])), + r"(\d+)\s+mo": lambda m: now - timedelta(weeks=int(m[1]) * 4), + r"(\d+)\s+years?": lambda m: now - timedelta(weeks=int(m[1]) * 52), } self.in_table_row = False self.current_item = {} @@ -68,10 +69,10 @@ def handle_data(self, data): self.current_item['seeds'] = int(data) elif self.in_table_row: # Check for a relative time - for pattern, delta in self.date_parsers.items(): + for pattern, calc in self.date_parsers.items(): m = re.match(pattern, data) if m: - self.current_item["pub_date"] = int((datetime.now() - delta(m)).timestamp()) + self.current_item["pub_date"] = int(calc(m).timestamp()) break def handle_endtag(self, tag): From 634def43114aed64e23f048602f1f067c91e7f2c Mon Sep 17 00:00:00 2001 From: Alex Duchesne Date: Sat, 17 Aug 2024 15:05:07 -0400 Subject: [PATCH 5/5] Replaced weeks= by days= Whilst still not very accurate, it is closer to the truth than having all months be 28 days and all years be 364 days... --- nova3/engines/eztv.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/nova3/engines/eztv.py b/nova3/engines/eztv.py index 9f65629..6b63ac6 100644 --- a/nova3/engines/eztv.py +++ b/nova3/engines/eztv.py @@ -31,8 +31,8 @@ def __init__(self, url): r"(\d+)h\s+(\d+)m": lambda m: now - timedelta(hours=int(m[1]), minutes=int(m[2])), r"(\d+)d\s+(\d+)h": lambda m: now - timedelta(days=int(m[1]), hours=int(m[2])), r"(\d+)\s+weeks?": lambda m: now - timedelta(weeks=int(m[1])), - r"(\d+)\s+mo": lambda m: now - timedelta(weeks=int(m[1]) * 4), - r"(\d+)\s+years?": lambda m: now - timedelta(weeks=int(m[1]) * 52), + r"(\d+)\s+mo": lambda m: now - timedelta(days=int(m[1]) * 30), + r"(\d+)\s+years?": lambda m: now - timedelta(days=int(m[1]) * 365), } self.in_table_row = False self.current_item = {}