-
Notifications
You must be signed in to change notification settings - Fork 481
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
20 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,12 @@ | ||
#VERSION: 1.15 | ||
#VERSION: 1.16 | ||
# AUTHORS: nindogo | ||
# CONTRIBUTORS: Diego de las Heras ([email protected]) | ||
|
||
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 | ||
|
@@ -24,6 +26,14 @@ def __init__(self, url): | |
HTMLParser.__init__(self) | ||
self.url = url | ||
|
||
now = datetime.now() | ||
self.date_parsers = { | ||
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(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 = {} | ||
|
||
|
@@ -38,6 +48,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 +68,13 @@ 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 | ||
for pattern, calc in self.date_parsers.items(): | ||
m = re.match(pattern, data) | ||
if m: | ||
self.current_item["pub_date"] = int(calc(m).timestamp()) | ||
break | ||
|
||
def handle_endtag(self, tag): | ||
if self.in_table_row and tag == self.TR: | ||
prettyPrinter(self.current_item) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
eztv: 1.15 | ||
eztv: 1.16 | ||
jackett: 4.0 | ||
limetorrents: 4.7 | ||
piratebay: 3.3 | ||
|