Move proxy getter to global torrent provider
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
from couchpotato.core.helpers.variable import getImdb, md5
|
||||
from couchpotato.core.helpers.variable import getImdb, md5, cleanHost
|
||||
from couchpotato.core.logger import CPLog
|
||||
from couchpotato.core.providers.base import YarrProvider
|
||||
from couchpotato.environment import Env
|
||||
import time
|
||||
|
||||
log = CPLog(__name__)
|
||||
|
||||
@@ -9,6 +11,9 @@ class TorrentProvider(YarrProvider):
|
||||
|
||||
protocol = 'torrent'
|
||||
|
||||
proxy_domain = None
|
||||
proxy_list = []
|
||||
|
||||
def imdbMatch(self, url, imdbId):
|
||||
if getImdb(url) == imdbId:
|
||||
return True
|
||||
@@ -25,6 +30,42 @@ class TorrentProvider(YarrProvider):
|
||||
|
||||
return False
|
||||
|
||||
def getDomain(self, url = ''):
|
||||
|
||||
forced_domain = self.conf('domain')
|
||||
if forced_domain:
|
||||
return cleanHost(forced_domain).rstrip('/') + url
|
||||
|
||||
if not self.proxy_domain:
|
||||
for proxy in self.proxy_list:
|
||||
|
||||
prop_name = 'proxy.%s' % proxy
|
||||
last_check = float(Env.prop(prop_name, default = 0))
|
||||
if last_check > time.time() - 1209600:
|
||||
continue
|
||||
|
||||
data = ''
|
||||
try:
|
||||
data = self.urlopen(proxy, timeout = 3, show_error = False)
|
||||
except:
|
||||
log.debug('Failed %s proxy %s', (self.getName(), proxy))
|
||||
|
||||
if self.correctProxy(data):
|
||||
log.debug('Using proxy for %s: %s', (self.getName(), proxy))
|
||||
self.proxy_domain = proxy
|
||||
break
|
||||
|
||||
Env.prop(prop_name, time.time())
|
||||
|
||||
if not self.proxy_domain:
|
||||
log.error('No %s proxies left, please add one in settings, or let us know which one to add on the forum.', self.getName())
|
||||
return None
|
||||
|
||||
return cleanHost(self.proxy_domain).rstrip('/') + url
|
||||
|
||||
def correctProxy(self):
|
||||
return True
|
||||
|
||||
class TorrentMagnetProvider(TorrentProvider):
|
||||
|
||||
protocol = 'torrent_magnet'
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
from bs4 import BeautifulSoup
|
||||
from couchpotato.core.helpers.variable import tryInt, cleanHost
|
||||
from couchpotato.core.helpers.variable import tryInt
|
||||
from couchpotato.core.logger import CPLog
|
||||
from couchpotato.core.providers.torrent.base import TorrentMagnetProvider
|
||||
from couchpotato.environment import Env
|
||||
import re
|
||||
import time
|
||||
import traceback
|
||||
|
||||
log = CPLog(__name__)
|
||||
@@ -36,10 +34,6 @@ class KickAssTorrents(TorrentMagnetProvider):
|
||||
'http://www.kickassproxy.info',
|
||||
]
|
||||
|
||||
def __init__(self):
|
||||
self.domain = self.conf('domain')
|
||||
super(KickAssTorrents, self).__init__()
|
||||
|
||||
def _search(self, movie, quality, results):
|
||||
|
||||
data = self.getHTMLData(self.urls['search'] % (self.getDomain(), 'm', movie['library']['identifier'].replace('tt', '')))
|
||||
@@ -117,31 +111,5 @@ class KickAssTorrents(TorrentMagnetProvider):
|
||||
def isEnabled(self):
|
||||
return super(KickAssTorrents, self).isEnabled() and self.getDomain()
|
||||
|
||||
def getDomain(self, url = ''):
|
||||
|
||||
if not self.domain:
|
||||
for proxy in self.proxy_list:
|
||||
|
||||
prop_name = 'kat_proxy.%s' % proxy
|
||||
last_check = float(Env.prop(prop_name, default = 0))
|
||||
if last_check > time.time() - 1209600:
|
||||
continue
|
||||
|
||||
data = ''
|
||||
try:
|
||||
data = self.urlopen(proxy, timeout = 3, show_error = False)
|
||||
except:
|
||||
log.debug('Failed kat proxy %s', proxy)
|
||||
|
||||
if 'search query' in data.lower():
|
||||
log.debug('Using proxy: %s', proxy)
|
||||
self.domain = proxy
|
||||
break
|
||||
|
||||
Env.prop(prop_name, time.time())
|
||||
|
||||
if not self.domain:
|
||||
log.error('No kat proxies left, please add one in settings, or let us know which one to add on the forum.')
|
||||
return None
|
||||
|
||||
return cleanHost(self.domain).rstrip('/') + url
|
||||
def correctProxy(self, data):
|
||||
return 'search query' in data.lower()
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
from bs4 import BeautifulSoup
|
||||
from couchpotato.core.helpers.encoding import toUnicode, tryUrlencode
|
||||
from couchpotato.core.helpers.variable import tryInt, cleanHost
|
||||
from couchpotato.core.helpers.variable import tryInt
|
||||
from couchpotato.core.logger import CPLog
|
||||
from couchpotato.core.providers.torrent.base import TorrentMagnetProvider
|
||||
from couchpotato.environment import Env
|
||||
import re
|
||||
import time
|
||||
import traceback
|
||||
|
||||
log = CPLog(__name__)
|
||||
@@ -30,8 +28,8 @@ class ThePirateBay(TorrentMagnetProvider):
|
||||
http_time_between_calls = 0
|
||||
|
||||
proxy_list = [
|
||||
'https://thepiratebay.se',
|
||||
'https://tpb.ipredator.se',
|
||||
'https://thepiratebay.se',
|
||||
'https://depiraatbaai.be',
|
||||
'https://piratereverse.info',
|
||||
'https://tpb.pirateparty.org.uk',
|
||||
@@ -43,10 +41,6 @@ class ThePirateBay(TorrentMagnetProvider):
|
||||
'https://kuiken.co',
|
||||
]
|
||||
|
||||
def __init__(self):
|
||||
self.domain = self.conf('domain')
|
||||
super(ThePirateBay, self).__init__()
|
||||
|
||||
def _searchOnTitle(self, title, movie, quality, results):
|
||||
|
||||
page = 0
|
||||
@@ -108,38 +102,11 @@ class ThePirateBay(TorrentMagnetProvider):
|
||||
except:
|
||||
log.error('Failed getting results from %s: %s', (self.getName(), traceback.format_exc()))
|
||||
|
||||
|
||||
def isEnabled(self):
|
||||
return super(ThePirateBay, self).isEnabled() and self.getDomain()
|
||||
|
||||
def getDomain(self, url = ''):
|
||||
|
||||
if not self.domain:
|
||||
for proxy in self.proxy_list:
|
||||
|
||||
prop_name = 'tpb_proxy.%s' % proxy
|
||||
last_check = float(Env.prop(prop_name, default = 0))
|
||||
if last_check > time.time() - 1209600:
|
||||
continue
|
||||
|
||||
data = ''
|
||||
try:
|
||||
data = self.urlopen(proxy, timeout = 3, show_error = False)
|
||||
except:
|
||||
log.debug('Failed tpb proxy %s', proxy)
|
||||
|
||||
if 'title="Pirate Search"' in data:
|
||||
log.debug('Using proxy: %s', proxy)
|
||||
self.domain = proxy
|
||||
break
|
||||
|
||||
Env.prop(prop_name, time.time())
|
||||
|
||||
if not self.domain:
|
||||
log.error('No TPB proxies left, please add one in settings, or let us know which one to add on the forum.')
|
||||
return None
|
||||
|
||||
return cleanHost(self.domain).rstrip('/') + url
|
||||
def correctProxy(self, data):
|
||||
return 'title="Pirate Search"' in data
|
||||
|
||||
def getMoreInfo(self, item):
|
||||
full_description = self.getCache('tpb.%s' % item['id'], item['detail_url'], cache_timeout = 25920000)
|
||||
|
||||
Reference in New Issue
Block a user