-
Notifications
You must be signed in to change notification settings - Fork 1
/
torrent.py
113 lines (94 loc) · 3.44 KB
/
torrent.py
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
import urllib.parse
class Torrent():
def __init__(self,thash,title,date,categ,size_Mb,seeds,peers):
self.thash = thash
self.title = title
self.date = date
self.categ = categ
self.size_Mb = size_Mb
self.seeds = seeds
self.peers = int(peers) + int(seeds)
@classmethod
def Format_Size(cls, torrent_Obj):
size_Mb = torrent_Obj.size_Mb
GB = 1024
TB = 1024 * GB
if (size_Mb > TB):
size = "{:.2f}".format(size_Mb/TB)
size_Unit = "TB"
elif (size_Mb > GB):
size = "{:.2f}".format(size_Mb/GB)
size_Unit = "GB"
else:
size = "{}".format(size_Mb)
size_Unit = "MB"
return "{} {}".format(size,size_Unit)
@classmethod
def Format_Age(cls, torrent_Obj):
time_Duration = TorrentzEngine.Calc_Age(torrent_Obj)
seconds = time_Duration.total_seconds()
minute = 60
hour = 60 * minute
day = 24 * hour
week = 7 * day
month = 30 * day
year = 365 * day
if (seconds > year):
age = seconds//year
age_Unit = "years"
elif (seconds > month):
age = seconds//month
age_Unit = "months"
elif (seconds > week):
age = seconds//week
age_Unit = "weeks"
elif (seconds > day):
age = seconds//day
age_Unit = "days"
elif (seconds > hour):
age = seconds//hour
age_Unit = "hours"
elif (seconds > minute):
age = seconds//minute
age_Unit = "minutes"
if (age == 1):
age_Unit = age_Unit[:-1]
return "{} {}".format(int(age), age_Unit)
class TorrentzEngine():
base_Url = "http://torrentz.in"
base_Url_Alt = "http://torrentz.eu"
trackers = """&tr=udp%3A%2F%2Fopen.demonii.com%3A1337%2Fannounce
&tr=udp%3A%2F%2Ftracker.leechers-paradise.org%3A6969
&tr=udp%3A%2F%2Fexodus.desync.com%3A6969
&tr=udp%3A%2F%2Ftracker.coppersurfer.tk%3A6969
&tr=udp%3A%2F%2F9.rarbg.com%3A2710%2Fannounce"""
categories = ("Any","Anime","Applications","Books","Comics","Games","Movies","Music","Software","TV")
categories_Keywords = { "Anime" : ["anime"],
"Application" : ["app"],
"Books" : ["book"],
"Games" : ["game"],
"Movies" : ["movie",],
"Music" : ["music"],
"TV" : ["tv"],
"Adult" : ["-xxx","-porn"],
"Comics" : ["comics"],
"Any" : [""],
"Software":["software"]
}
@classmethod
def Feed_Url(cls, query, page=1):
url = "{}/feed?q={}&p={}".format(cls.base_Url, query, page)
return url
@classmethod
def Magnet_Link(cls, title, thash):
name = "&{}".format(urllib.parse.urlencode({'dn':title}))
link = "magnet:?xt=urn:btih:{}{}{}".format(thash, name, cls.trackers)
return link
@classmethod
def Desc_Link(cls, thash):
link = "{}/{}".format(cls.base_Url, thash)
return link
@classmethod
def Calc_Age(cls, tor_Obj):
time_Duration = tor_Obj.date.utcnow() - tor_Obj.date
return time_Duration