-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
158 lines (135 loc) · 5.88 KB
/
main.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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
from bs4 import BeautifulSoup
from couchpotato.core.helpers.encoding import tryUrlencode
from couchpotato.core.helpers.encoding import toSafeString
from couchpotato.core.helpers.variable import tryInt
from couchpotato.core.logger import CPLog
from couchpotato.environment import Env
from couchpotato.core.media._base.providers.torrent.base import TorrentProvider
from couchpotato.core.media.movie.providers.base import MovieProvider
import traceback
from urlparse import urlparse
import json
import re
import time
log = CPLog(__name__)
class t411(TorrentProvider, MovieProvider):
urls = {
'test' : 'https://t411.al',
'login' : 'https://api.t411.al/auth',
'login_check': 'https://api.t411.al/torrents/top/100',
'detail' : 'https://www.t411.al/torrents/?id=%s',
'search' : 'https://api.t411.al/torrents/search/%s?limit=200&cid=631',
'search2' : 'https://api.t411.al/torrents/search/%s?limit=200&cid=635',
'search3' : 'https://api.t411.al/torrents/search/%s?limit=200&cid=455',
'download' : 'https://api.t411.al/torrents/download/%s',
}
cat_ids = [
([28], ['720p', '1080p']),
([2], ['cam', 'ts', 'tc', 'r5', 'scr', 'dvdrip', 'brrip']),
([3], ['dvdr']),
]
http_time_between_calls = 1 #seconds
cat_backup_id = None
def _searchOnTitle(self, title, movie, quality, results):
log.debug('Searching T411 for %s' % (title))
url = self.urls['search'] % (title.replace(':', ''))
try:
output = self.getJsonData(url,cache_timeout = 30, headers = {"Authorization": self.token})
except: pass
for entry in output['torrents']:
try:
log.debug(entry)
#log.debug("NAME: "+entry['name']+" SIZE: "+self.parseSize(str(tryInt(tryInt(entry['size'])/1024))+"kb"))
results.append({
'id': entry['id'],
'name': entry['name'],
'url': self.urls['download'] % entry['id'],
'detail_url': self.urls['detail'] % entry['id'],
'size': self.parseSize(str(tryInt(tryInt(entry['size'])/1024))+"kb"),
'seeders': entry['seeders'],
'leechers': entry['leechers'],
})
except:
error = traceback.format_exc()
url = self.urls['search2'] % (title.replace(':', ''))
try:
output = self.getJsonData(url,cache_timeout = 30, headers = {"Authorization": self.token})
except: pass
for entry in output['torrents']:
try:
log.debug(entry)
#log.debug("NAME: "+entry['name']+" SIZE: "+self.parseSize(str(tryInt(tryInt(entry['size'])/1024))+"kb"))
results.append({
'id': entry['id'],
'name': entry['name'],
'url': self.urls['download'] % entry['id'],
'detail_url': self.urls['detail'] % entry['id'],
'size': self.parseSize(str(tryInt(tryInt(entry['size'])/1024))+"kb"),
'seeders': entry['seeders'],
'leechers': entry['leechers'],
})
except:
error = traceback.format_exc()
url = self.urls['search3'] % (title.replace(':', ''))
try:
output = self.getJsonData(url,cache_timeout = 30, headers = {"Authorization": self.token})
except: pass
for entry in output['torrents']:
try:
log.debug(entry)
#log.debug("NAME: "+entry['name']+" SIZE: "+self.parseSize(str(tryInt(tryInt(entry['size'])/1024))+"kb"))
results.append({
'id': entry['id'],
'name': entry['name'],
'url': self.urls['download'] % entry['id'],
'detail_url': self.urls['detail'] % entry['id'],
'size': self.parseSize(str(tryInt(tryInt(entry['size'])/1024))+"kb"),
'seeders': entry['seeders'],
'leechers': entry['leechers'],
})
except:
error = traceback.format_exc()
def login(self):
log.debug('Try to login on T411')
# Check if we are still logged in every 60 days
self.token = self.conf('token')
now = time.time()
if self.last_login_check and self.last_login_check < (now - 10):
try:
output = self.getJsonData(self.urls['login_check'],cache_timeout = 30, headers = "Authorization: %s" % self.token)
if self.loginCheckSuccess(output):
self.last_login_check = now
return True
except: pass
self.last_login_check = None
if self.last_login_check:
return True
try:
output = self.getJsonData(self.urls['login'], files=False, data = self.getLoginParams())
if self.loginSuccess(output):
self.last_login_check = now
self.conf('token',value = output['token'])
return True
error = 'unknown'
except:
error = traceback.format_exc()
def download(self, url = '', nzb_id = ''):
log.debug('Try to download %s from %s', (self.getName(), traceback.format_exc()))
try:
torrent = self.urlopen(url, files=False, headers = {"Authorization": self.conf('token')})
return torrent
except:
log.error('Failed getting release from %s: %s', (self.getName(), traceback.format_exc()))
return 'try_next'
def getLoginParams(self):
log.debug('Getting login params for T411')
return {
'username': self.conf('username'),
'password': self.conf('password'),
}
def loginSuccess(self, output):
log.debug('Checking login success for T411: %s' % ('True' if (output.has_key('error') != True) else 'False'))
#return True
return (output.has_key('error') != True)
loginCheckSuccess = loginSuccess
loginDownload = download