/
titansoftv.py
160 lines (120 loc) · 5.08 KB
/
titansoftv.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
159
160
# coding=utf-8
# URL: http://code.google.com/p/sickbeard
# Originally written for SickGear
#
# This file is part of SickRage.
#
# SickRage is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# SickRage is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with SickRage. If not, see <http://www.gnu.org/licenses/>.
import urllib
from sickbeard import logger
from sickbeard import tvcache
from sickbeard.helpers import mapIndexersToShow
from sickrage.helper.exceptions import AuthException
from sickrage.providers.torrent.TorrentProvider import TorrentProvider
class TitansOfTVProvider(TorrentProvider):
def __init__(self):
TorrentProvider.__init__(self, 'TitansOfTV')
self.supports_absolute_numbering = True
self.api_key = None
self.ratio = None
self.cache = TitansOfTVCache(self)
self.url = 'http://titansof.tv/api/torrents'
self.download_url = 'http://titansof.tv/api/torrents/%s/download?apikey=%s'
def seed_ratio(self):
return self.ratio
def _check_auth(self):
if not self.api_key:
raise AuthException('Your authentication credentials for ' + self.name + ' are missing, check your config.')
return True
def _checkAuthFromData(self, data):
if 'error' in data:
logger.log(u"Invalid api key. Check your settings", logger.WARNING)
return False
return True
def search(self, search_params, age=0, ep_obj=None):
# FIXME ADD MODE
self._check_auth()
results = []
params = {}
self.headers.update({'X-Authorization': self.api_key})
if search_params:
params.update(search_params)
searchURL = self.url + '?' + urllib.urlencode(params)
logger.log(u"Search string: %s " % search_params, logger.DEBUG)
logger.log(u"Search URL: %s" % searchURL, logger.DEBUG)
parsedJSON = self.get_url(searchURL, json=True) # do search
if not parsedJSON:
logger.log(u"No data returned from provider", logger.DEBUG)
return results
if self._checkAuthFromData(parsedJSON):
try:
found_torrents = parsedJSON['results']
except Exception:
found_torrents = {}
for result in found_torrents:
title = result.get('release_name', '')
tid = result.get('id', '')
download_url = self.download_url % (tid, self.api_key)
# FIXME size, seeders, leechers
size = -1
seeders = 1
leechers = 0
if not all([title, download_url]):
continue
# Filter unseeded torrent
# if seeders < self.minseed or leechers < self.minleech:
# if mode != 'RSS':
# logger.log(u"Discarding torrent because it doesn't meet the minimum seeders or leechers: {0} (S:{1} L:{2})".format(title, seeders, leechers), logger.DEBUG)
# continue
item = title, download_url, size, seeders, leechers
logger.log(u"Found result: %s " % title, logger.DEBUG)
results.append(item)
# FIXME SORTING
return results
def _get_season_search_strings(self, ep_obj):
search_params = {
'limit': 100,
'season': 'Season %02d' % ep_obj.scene_season
}
if ep_obj.show.indexer == 1:
search_params['series_id'] = ep_obj.show.indexerid
elif ep_obj.show.indexer == 2:
tvdbid = mapIndexersToShow(ep_obj.show)[1]
if tvdbid:
search_params['series_id'] = tvdbid
return [search_params]
def _get_episode_search_strings(self, ep_obj, add_string=''):
if not ep_obj:
return [{}]
search_params = {
'limit': 100,
'episode': 'S%02dE%02d' % (ep_obj.scene_season, ep_obj.scene_episode)
}
# Do a general name search for the episode, formatted like SXXEYY
if ep_obj.show.indexer == 1:
search_params['series_id'] = ep_obj.show.indexerid
elif ep_obj.show.indexer == 2:
tvdbid = mapIndexersToShow(ep_obj.show)[1]
if tvdbid:
search_params['series_id'] = tvdbid
return [search_params]
class TitansOfTVCache(tvcache.TVCache):
def __init__(self, provider_obj):
tvcache.TVCache.__init__(self, provider_obj)
# At least 10 minutes between queries
self.minTime = 10
def _getRSSData(self):
search_params = {'limit': 100}
return self.provider.search(search_params)
provider = TitansOfTVProvider()