/
sceneelite.py
153 lines (125 loc) · 5.53 KB
/
sceneelite.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
# coding=utf-8
# Author: Gonçalo M. (aka duramato/supergonkas) <supergonkas@gmail.com>
#
# URL: https://sickrage.github.io
#
# 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/>.
from __future__ import unicode_literals
import traceback
from requests.compat import urljoin
from requests.utils import dict_from_cookiejar
from sickbeard import logger, tvcache
from sickrage.helper.common import try_int
from sickrage.providers.torrent.TorrentProvider import TorrentProvider
class SceneEliteProvider(TorrentProvider): # pylint: disable=too-many-instance-attributes
def __init__(self):
# Provider Init
TorrentProvider.__init__(self, 'SceneElite')
# Credentials
self.username = None
self.password = None
# Torrent Stats
self.minseed = None
self.minleech = None
self.freeleech = None
# URLs
self.url = 'https://sceneelite.org/'
self.urls = {
'login': urljoin(self.url, '/api/v1/auth'),
'search': urljoin(self.url, '/api/v1/torrents'),
'download': urljoin(self.url, '/api/v1/torrents/download/'),
}
# Proper Strings
self.proper_strings = ['PROPER', 'REPACK', 'REAL']
cache_params = {'RSS': ['']}
# Cache
self.cache = tvcache.TVCache(self, min_time=0.1, search_params=cache_params)
def login(self):
if any(dict_from_cookiejar(self.session.cookies).values()):
return True
login_params = {
'username': self.username,
'password': self.password
}
response = self.get_url(self.urls['login'], params=login_params, returns='json')
if not response:
logger.log('Unable to connect to provider', logger.WARNING)
return False
return True
def search(self, search_strings, age=0, ep_obj=None): # pylint: disable=too-many-locals, too-many-branches
results = []
if not self.login():
return results
# Search Params
search_params = {
'extendedSearch': 'false',
'hideOld': 'false',
'index': '0',
'limit': '100',
'order': 'asc',
'page': 'search',
'sort': 'n',
'categories[0]': 3,
'categories[1]': 6,
'categories[2]': 7
}
for mode in search_strings:
items = []
logger.log('Search Mode: {0}'.format(mode), logger.DEBUG)
for search_string in search_strings[mode]:
if mode != 'RSS':
logger.log('Search string: {0}'.format
(search_string), logger.DEBUG)
search_params['searchText'] = search_string
else:
search_params['page'] = 'last_seriebrowse'
results = []
search_url = self.urls['search']
try:
jdata = self.get_url(search_url, params=search_params, returns='json')
except ValueError:
logger.log('No data returned from provider', logger.DEBUG)
continue
for torrent in jdata:
try:
title = torrent.pop('name', '')
id = str(torrent.pop('id', ''))
if not id:
continue
seeders = try_int(torrent.pop('seeders', ''), 1)
leechers = try_int(torrent.pop('leechers', ''), 0)
freeleech = torrent.pop('frileech')
if self.freeleech and freeleech != 1:
continue
size = try_int(torrent.pop('size', ''), 0)
download_url = self.urls['download'] + id
# Filter unseeded torrent
if seeders < min(self.minseed, 1):
if mode != 'RSS':
logger.log("Discarding torrent because it doesn't meet the minimum seeders: {0}. Seeders: {1})".format(title, seeders), logger.DEBUG)
continue
item = {'title': title, 'link': download_url, 'size': size, 'seeders': seeders, 'leechers': leechers, 'pubdate': None, 'hash': None}
if mode != 'RSS':
logger.log('Found result: {0} with {1} seeders and {2} leechers'.format
(title, seeders, leechers), logger.DEBUG)
items.append(item)
except (AttributeError, TypeError, KeyError, ValueError, IndexError):
logger.log('Failed parsing provider. Traceback: {0!r}'.format
(traceback.format_exc()), logger.ERROR)
continue
results += items
return results
provider = SceneEliteProvider()