Move proxy getter to global torrent provider
This commit is contained in:
1 parent
3442129610
commit
3f37fc1e11
3 files changed
+49
-73
No files matched your search
@@ -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.logger import CPLog
|
||||||
from couchpotato.core.providers.base import YarrProvider
|
from couchpotato.core.providers.base import YarrProvider
|
||||||
|
from couchpotato.environment import Env
|
||||||
|
import time
|
||||||
|
|
||||||
log = CPLog(__name__)
|
log = CPLog(__name__)
|
||||||
|
|
||||||
@@ -9,6 +11,9 @@ class TorrentProvider(YarrProvider):
|
|||||||
|
|
||||||
protocol = 'torrent'
|
protocol = 'torrent'
|
||||||
|
|
||||||
|
proxy_domain = None
|
||||||
|
proxy_list = []
|
||||||
|
|
||||||
def imdbMatch(self, url, imdbId):
|
def imdbMatch(self, url, imdbId):
|
||||||
if getImdb(url) == imdbId:
|
if getImdb(url) == imdbId:
|
||||||
return True
|
return True
|
||||||
@@ -25,6 +30,42 @@ class TorrentProvider(YarrProvider):
|
|||||||
|
|
||||||
return False
|
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):
|
class TorrentMagnetProvider(TorrentProvider):
|
||||||
|
|
||||||
protocol = 'torrent_magnet'
|
protocol = 'torrent_magnet'
|
||||||
|
|||||||
@@ -1,10 +1,8 @@
|
|||||||
from bs4 import BeautifulSoup
|
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.logger import CPLog
|
||||||
from couchpotato.core.providers.torrent.base import TorrentMagnetProvider
|
from couchpotato.core.providers.torrent.base import TorrentMagnetProvider
|
||||||
from couchpotato.environment import Env
|
|
||||||
import re
|
import re
|
||||||
import time
|
|
||||||
import traceback
|
import traceback
|
||||||
|
|
||||||
log = CPLog(__name__)
|
log = CPLog(__name__)
|
||||||
@@ -36,10 +34,6 @@ class KickAssTorrents(TorrentMagnetProvider):
|
|||||||
'http://www.kickassproxy.info',
|
'http://www.kickassproxy.info',
|
||||||
]
|
]
|
||||||
|
|
||||||
def __init__(self):
|
|
||||||
self.domain = self.conf('domain')
|
|
||||||
super(KickAssTorrents, self).__init__()
|
|
||||||
|
|
||||||
def _search(self, movie, quality, results):
|
def _search(self, movie, quality, results):
|
||||||
|
|
||||||
data = self.getHTMLData(self.urls['search'] % (self.getDomain(), 'm', movie['library']['identifier'].replace('tt', '')))
|
data = self.getHTMLData(self.urls['search'] % (self.getDomain(), 'm', movie['library']['identifier'].replace('tt', '')))
|
||||||
@@ -117,31 +111,5 @@ class KickAssTorrents(TorrentMagnetProvider):
|
|||||||
def isEnabled(self):
|
def isEnabled(self):
|
||||||
return super(KickAssTorrents, self).isEnabled() and self.getDomain()
|
return super(KickAssTorrents, self).isEnabled() and self.getDomain()
|
||||||
|
|
||||||
def getDomain(self, url = ''):
|
def correctProxy(self, data):
|
||||||
|
return 'search query' in data.lower()
|
||||||
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
|
|
||||||
@@ -1,11 +1,9 @@
|
|||||||
from bs4 import BeautifulSoup
|
from bs4 import BeautifulSoup
|
||||||
from couchpotato.core.helpers.encoding import toUnicode, tryUrlencode
|
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.logger import CPLog
|
||||||
from couchpotato.core.providers.torrent.base import TorrentMagnetProvider
|
from couchpotato.core.providers.torrent.base import TorrentMagnetProvider
|
||||||
from couchpotato.environment import Env
|
|
||||||
import re
|
import re
|
||||||
import time
|
|
||||||
import traceback
|
import traceback
|
||||||
|
|
||||||
log = CPLog(__name__)
|
log = CPLog(__name__)
|
||||||
@@ -30,8 +28,8 @@ class ThePirateBay(TorrentMagnetProvider):
|
|||||||
http_time_between_calls = 0
|
http_time_between_calls = 0
|
||||||
|
|
||||||
proxy_list = [
|
proxy_list = [
|
||||||
'https://thepiratebay.se',
|
|
||||||
'https://tpb.ipredator.se',
|
'https://tpb.ipredator.se',
|
||||||
|
'https://thepiratebay.se',
|
||||||
'https://depiraatbaai.be',
|
'https://depiraatbaai.be',
|
||||||
'https://piratereverse.info',
|
'https://piratereverse.info',
|
||||||
'https://tpb.pirateparty.org.uk',
|
'https://tpb.pirateparty.org.uk',
|
||||||
@@ -43,10 +41,6 @@ class ThePirateBay(TorrentMagnetProvider):
|
|||||||
'https://kuiken.co',
|
'https://kuiken.co',
|
||||||
]
|
]
|
||||||
|
|
||||||
def __init__(self):
|
|
||||||
self.domain = self.conf('domain')
|
|
||||||
super(ThePirateBay, self).__init__()
|
|
||||||
|
|
||||||
def _searchOnTitle(self, title, movie, quality, results):
|
def _searchOnTitle(self, title, movie, quality, results):
|
||||||
|
|
||||||
page = 0
|
page = 0
|
||||||
@@ -108,38 +102,11 @@ class ThePirateBay(TorrentMagnetProvider):
|
|||||||
except:
|
except:
|
||||||
log.error('Failed getting results from %s: %s', (self.getName(), traceback.format_exc()))
|
log.error('Failed getting results from %s: %s', (self.getName(), traceback.format_exc()))
|
||||||
|
|
||||||
|
|
||||||
def isEnabled(self):
|
def isEnabled(self):
|
||||||
return super(ThePirateBay, self).isEnabled() and self.getDomain()
|
return super(ThePirateBay, self).isEnabled() and self.getDomain()
|
||||||
|
|
||||||
def getDomain(self, url = ''):
|
def correctProxy(self, data):
|
||||||
|
return 'title="Pirate Search"' in data
|
||||||
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 getMoreInfo(self, item):
|
def getMoreInfo(self, item):
|
||||||
full_description = self.getCache('tpb.%s' % item['id'], item['detail_url'], cache_timeout = 25920000)
|
full_description = self.getCache('tpb.%s' % item['id'], item['detail_url'], cache_timeout = 25920000)
|
||||||
|
|||||||
Reference in new issue
Block a user