-
-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathsnowfl.py
More file actions
68 lines (57 loc) · 2.47 KB
/
snowfl.py
File metadata and controls
68 lines (57 loc) · 2.47 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
# VERSION: 1.3
# AUTHORS: LightDestory (https://github.com/LightDestory)
# Based on gitDew work (https://github.com/gitDew/qbittorrent-snowfl-search-plugin)
import urllib.parse
import json
import random
import re
import string
import time
from helpers import retrieve_url
from novaprinter import prettyPrinter
class snowfl(object):
url = 'https://snowfl.com/'
name = 'Snowfl'
# No categories provided
supported_categories = {'all': '0'}
class Parser:
def __init__(self, url):
self.url = url
self.token = self.__retrieveToken()
def feed(self, collection):
for torrent in collection:
data = {
'link': torrent['magnet'] if "magnet" in torrent else urllib.parse.quote(torrent['url']),
'name': torrent['name'],
'size': torrent['size'],
'seeds': torrent['seeder'],
'leech': torrent['leecher'],
'engine_url': self.url,
'desc_link': torrent['url']
}
prettyPrinter(data)
def __retrieveToken(self):
index_html = retrieve_url(self.url + "index.html")
file_name = re.findall(r'.+?\"(b.min.js\?.+)\"', index_html)[0]
script = retrieve_url(self.url + file_name)
# Retrieving the token
token = re.findall(r'\"([a-zA-Z0-9]+)\";\$\(\(function\(\){var e,t,n,r,o,a,i=', script)[0]
return token
def generateQuery(self, what):
random_str = ''.join(random.choice(string.ascii_lowercase + string.digits) for _ in range(8))
return '{0}/{1}/{2}/{3}/0/SEED/NONE/1?_={4}'.format(self.url, self.token, what, random_str,
str(int(time.time() * 1000)))
def download_torrent(self, info):
if "magnet:?" in info:
print('{0} {1}'.format(info, info))
else:
torrent_page = retrieve_url(urllib.parse.unquote(info))
magnet_match = re.search(r'\"(magnet:.*?)\"', torrent_page)
if magnet_match and magnet_match.groups():
print('{0} {1}'.format(magnet_match.groups()[0], info))
else:
raise Exception('Error, please fill a bug report!')
def search(self, what, cat='all'):
parser = self.Parser(self.url)
what = parser.generateQuery(what)
parser.feed(json.loads(retrieve_url(what)))