-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathutils.py
More file actions
72 lines (54 loc) · 2.17 KB
/
utils.py
File metadata and controls
72 lines (54 loc) · 2.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
from headers import headers
from params import params
from htmlement import fromstring as parseHTML
class sharedData:
def __init__(self, debugInfo=False):
self.debugInfo = debugInfo
self.searchHeaders = headers
self.searchParams = params
if not self.debugInfo:
from cookies import cookies
else:
from cookiesDebug import cookies
self.searchCookies = cookies
def parseHTMLForSearchResults(self, htmlText, query):
self.htmlParsed = parseHTML(htmlText)
searchResultsParsed = {
'results': [],
}
loweredQuery = query.lower()
for element in self.htmlParsed.iter('a'):
link = element.attrib['href']
text = element.text
if not text:
continue
try:
int(text)
continue
except:
pass
loweredText = text.lower()
if loweredQuery not in loweredText:
continue
link = f'https://iptorrents.com{link}'
if '/t/' in link:
if self.debugInfo:
print(f'Found: {text} - {link}')
#print(htmlText, file=open('html.txt', 'w'))
torrentId = link.split('/t/')[1].split('/')[0]
dotTorrentDownloadLink = htmlText.split(f'<a href="/download.php/{torrentId}')[1].split('"')[0]
dotTorrentDownloadLink = f'https://iptorrents.com/download.php/{torrentId}/{dotTorrentDownloadLink}'
searchResultsParsed['results'].append(
{
'torrentName': text,
'torrentLink': link,
'dotTorrentDownloadLink': dotTorrentDownloadLink,
}
)
if len(searchResultsParsed['results']) != 0:
return searchResultsParsed
if self.debugInfo:
print(f'No results found for: {query}')
return False
if __name__ == "__main__":
print('Do not run me')