Skip to content

Commit

Permalink
Add date field to torrentproject
Browse files Browse the repository at this point in the history
This changes the search url from `/?t=abc` to `/browse?t=abc` because the latter provides a date.

The search results are identical with for most queries I've tried but sometimes it differs, so maybe using `/browse` isn't acceptable?
  • Loading branch information
ducalex committed Aug 20, 2024
1 parent cfe98da commit 443f710
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
23 changes: 19 additions & 4 deletions nova3/engines/torrentproject.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
#VERSION: 1.3
#VERSION: 1.4
#AUTHORS: mauricci

from helpers import retrieve_url
from novaprinter import prettyPrinter
import re

from datetime import datetime
from html.parser import HTMLParser
from urllib.parse import unquote

Expand All @@ -23,7 +24,14 @@ def __init__(self, url):
self.insideDataDiv = False
self.pageComplete = False
self.spanCount = -1
self.infoMap = {'name': 0, 'torrLink': 0, 'size': 5, 'seeds': 2, 'leech': 3}
self.infoMap = {
"name": 0,
"torrLink": 0,
"seeds": 2,
"leech": 3,
"pub_date": 4,
"size": 5,
}
self.fullResData = []
self.pageRes = []
self.singleResData = self.get_single_data()
Expand All @@ -36,7 +44,8 @@ def get_single_data(self):
'size': '-1',
'link': '-1',
'desc_link': '-1',
'engine_url': self.url
'engine_url': self.url,
'pub_date': '-1',
}

def handle_starttag(self, tag, attrs):
Expand Down Expand Up @@ -68,6 +77,12 @@ def handle_endtag(self, tag):
# ignore those with link and desc_link equals to -1
if self.singleResData['desc_link'] != '-1' \
or self.singleResData['link'] != '-1':
try:
date_string = self.singleResData['pub_date']
date = datetime.strptime(date_string, '%Y-%m-%d %H:%M:%S')
self.singleResData['pub_date'] = int(date.timestamp())
except Exception:
pass
try:
prettyPrinter(self.singleResData)
except Exception:
Expand Down Expand Up @@ -100,7 +115,7 @@ def search(self, what, cat='all'):
what = what.replace('%20', '+')
# analyze first 5 pages of results
for currPage in range(0, 5):
url = self.url + '?t={0}&p={1}'.format(what, currPage)
url = self.url + '/browse?t={0}&p={1}'.format(what, currPage)
html = retrieve_url(url)
parser.feed(html)
if len(parser.pageRes) <= 0:
Expand Down
2 changes: 1 addition & 1 deletion nova3/engines/versions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ limetorrents: 4.7
piratebay: 3.3
solidtorrents: 2.3
torlock: 2.23
torrentproject: 1.3
torrentproject: 1.4
torrentscsv: 1.4

0 comments on commit 443f710

Please sign in to comment.