Merge branch 'develop' of github.com:RuudBurger/CouchPotatoServer into develop
This commit is contained in:
@@ -2,6 +2,8 @@ from couchpotato.core.event import addEvent
|
|||||||
from couchpotato.core.logger import CPLog
|
from couchpotato.core.logger import CPLog
|
||||||
from couchpotato.core.plugins.base import Plugin
|
from couchpotato.core.plugins.base import Plugin
|
||||||
from couchpotato.environment import Env
|
from couchpotato.environment import Env
|
||||||
|
from couchpotato.core.helpers.encoding import toSafeString
|
||||||
|
import os
|
||||||
|
|
||||||
log = CPLog(__name__)
|
log = CPLog(__name__)
|
||||||
|
|
||||||
@@ -16,6 +18,12 @@ class Downloader(Plugin):
|
|||||||
def download(self, data = {}):
|
def download(self, data = {}):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def createFileName(self, data, file, movie):
|
||||||
|
if "DOCTYPE nzb" not in file:
|
||||||
|
if data.get('type') == 'nzb':
|
||||||
|
return os.path.join('%s%s.%s' % (toSafeString(data.get('name')), self.cpTag(movie) , 'rar'))
|
||||||
|
return os.path.join('%s%s.%s' % (toSafeString(data.get('name')), self.cpTag(movie) , data.get('type')))
|
||||||
|
|
||||||
def cpTag(self, movie):
|
def cpTag(self, movie):
|
||||||
if Env.setting('enabled', 'renamer'):
|
if Env.setting('enabled', 'renamer'):
|
||||||
return '.cp(' + movie['library'].get('identifier') + ')' if movie['library'].get('identifier') else ''
|
return '.cp(' + movie['library'].get('identifier') + ')' if movie['library'].get('identifier') else ''
|
||||||
|
|||||||
@@ -11,36 +11,37 @@ class Blackhole(Downloader):
|
|||||||
type = ['nzb', 'torrent']
|
type = ['nzb', 'torrent']
|
||||||
|
|
||||||
def download(self, data = {}, movie = {}):
|
def download(self, data = {}, movie = {}):
|
||||||
|
|
||||||
if self.isDisabled() or not self.isCorrectType(data.get('type') or not self.conf('use_for') in ['both', data.get('type')]):
|
if self.isDisabled() or not self.isCorrectType(data.get('type') or not self.conf('use_for') in ['both', data.get('type')]):
|
||||||
return
|
return
|
||||||
|
|
||||||
directory = self.conf('directory')
|
directory = self.conf('directory')
|
||||||
|
|
||||||
if not directory or not os.path.isdir(directory):
|
if not directory or not os.path.isdir(directory):
|
||||||
log.error('No directory set for blackhole %s download.' % data.get('type'))
|
log.error('No directory set for blackhole %s download.' % data.get('type'))
|
||||||
else:
|
else:
|
||||||
fullPath = os.path.join(directory, '%s%s.%s' % (toSafeString(data.get('name')), self.cpTag(movie) , data.get('type')))
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if not os.path.isfile(fullPath):
|
file = data.get('download')(url = data.get('url'), nzb_id = data.get('id'))
|
||||||
log.info('Downloading %s to %s.' % (data.get('type'), fullPath))
|
|
||||||
|
|
||||||
try:
|
if len(file) < 50:
|
||||||
file = data.get('download')(url = data.get('url'), nzb_id = data.get('id'))
|
log.error('No nzb available!')
|
||||||
|
return False
|
||||||
|
|
||||||
|
fullPath = os.path.join(directory, self.createFileName(data, file, movie))
|
||||||
|
|
||||||
|
try:
|
||||||
|
if not os.path.isfile(fullPath):
|
||||||
|
log.info('Downloading %s to %s.' % (data.get('type'), fullPath))
|
||||||
with open(fullPath, 'wb') as f:
|
with open(fullPath, 'wb') as f:
|
||||||
f.write(file)
|
f.write(file)
|
||||||
except:
|
return True
|
||||||
log.debug('Failed download file: %s' % data.get('name'))
|
else:
|
||||||
return False
|
log.info('File %s already exists.' % fullPath)
|
||||||
|
return True
|
||||||
|
|
||||||
|
except:
|
||||||
|
log.error('Failed to download to blackhole %s' % traceback.format_exc())
|
||||||
|
pass
|
||||||
|
|
||||||
return True
|
|
||||||
else:
|
|
||||||
log.info('File %s already exists.' % fullPath)
|
|
||||||
return True
|
|
||||||
except:
|
except:
|
||||||
log.error('Failed to download to blackhole %s' % traceback.format_exc())
|
log.debug('Failed to download file: %s' % data.get('name'))
|
||||||
pass
|
return False
|
||||||
|
|
||||||
return False
|
return False
|
||||||
|
|||||||
@@ -44,13 +44,20 @@ class Sabnzbd(Downloader):
|
|||||||
|
|
||||||
nzb_file = data.get('download')(url = data.get('url'), nzb_id = data.get('id'))
|
nzb_file = data.get('download')(url = data.get('url'), nzb_id = data.get('id'))
|
||||||
|
|
||||||
|
if len(nzb_file) < 50:
|
||||||
|
log.error('No nzb available!')
|
||||||
|
return False
|
||||||
|
|
||||||
|
# If it's a .rar, it adds the .rar extension, otherwise it stays .nzb
|
||||||
|
nzb_filename = self.createFileName(data, nzb_file, movie)
|
||||||
|
|
||||||
if pp:
|
if pp:
|
||||||
params['script'] = pp_script_fn
|
params['script'] = pp_script_fn
|
||||||
|
|
||||||
url = cleanHost(self.conf('host')) + "api?" + urlencode(params)
|
url = cleanHost(self.conf('host')) + "api?" + urlencode(params)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
data = self.urlopen(url, params = {"nzbfile": (params['nzbname'] + ".nzb", nzb_file)}, multipart = True)
|
data = self.urlopen(url, params = {"nzbfile": (nzb_filename, nzb_file)}, multipart = True)
|
||||||
except Exception:
|
except Exception:
|
||||||
log.error("Unable to connect to SAB: %s" % traceback.format_exc())
|
log.error("Unable to connect to SAB: %s" % traceback.format_exc())
|
||||||
return False
|
return False
|
||||||
|
|||||||
@@ -0,0 +1,20 @@
|
|||||||
|
from .main import X264
|
||||||
|
|
||||||
|
def start():
|
||||||
|
return X264()
|
||||||
|
|
||||||
|
config = [{
|
||||||
|
'name': 'x264',
|
||||||
|
'groups': [
|
||||||
|
{
|
||||||
|
'tab': 'providers',
|
||||||
|
'name': '#alt.binaries.hdtv.x264',
|
||||||
|
'options': [
|
||||||
|
{
|
||||||
|
'name': 'enabled',
|
||||||
|
'type': 'enabler',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}]
|
||||||
@@ -0,0 +1,89 @@
|
|||||||
|
from couchpotato.core.event import fireEvent
|
||||||
|
from couchpotato.core.helpers.rss import RSS
|
||||||
|
from couchpotato.core.logger import CPLog
|
||||||
|
from couchpotato.core.providers.nzb.base import NZBProvider
|
||||||
|
from dateutil.parser import parse
|
||||||
|
from imdb.parser.http.bsouplxml._bsoup import SoupStrainer, BeautifulSoup
|
||||||
|
import urllib
|
||||||
|
import urllib2
|
||||||
|
from urllib import urlencode
|
||||||
|
from urllib import quote_plus
|
||||||
|
import time
|
||||||
|
import re
|
||||||
|
|
||||||
|
log = CPLog(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
class X264(NZBProvider, RSS):
|
||||||
|
|
||||||
|
urls = {
|
||||||
|
'download': 'http://85.214.105.230/get_nzb.php?id=%s§ion=hd',
|
||||||
|
'search': 'http://85.214.105.230/x264/requests.php?release=%s&status=FILLED&age=700&sort=ID',
|
||||||
|
'regex': '<tr class="req_filled"><td class="reqid">(?P<id>.*?)</td><td class="release">(?P<title>.*?)</td>',
|
||||||
|
}
|
||||||
|
|
||||||
|
def search(self, movie, quality):
|
||||||
|
|
||||||
|
results = []
|
||||||
|
if self.isDisabled() or not self.isAvailable(self.urls['search']):
|
||||||
|
return results
|
||||||
|
|
||||||
|
url = self.urls['search'] % quote_plus(movie['library']['titles'][0]['title'] + ' ' + quality.get('identifier'))
|
||||||
|
log.info('Searching: %s' % url)
|
||||||
|
|
||||||
|
try:
|
||||||
|
opener = urllib2.build_opener()
|
||||||
|
urllib2.install_opener(opener)
|
||||||
|
f = opener.open(url)
|
||||||
|
data = f.read()
|
||||||
|
f.close()
|
||||||
|
|
||||||
|
except (IOError, URLError):
|
||||||
|
log.error('Failed to open %s.' % url)
|
||||||
|
return results
|
||||||
|
|
||||||
|
match = re.compile(self.urls['regex'], re.DOTALL ).finditer(data)
|
||||||
|
|
||||||
|
for nzb in match:
|
||||||
|
new = {
|
||||||
|
'id': nzb.group('id'),
|
||||||
|
'name': nzb.group('title'),
|
||||||
|
'type': 'nzb',
|
||||||
|
'provider': self.getName(),
|
||||||
|
'age': self.calculateAge(time.time()),
|
||||||
|
'size': 9999,
|
||||||
|
'url': self.urls['download'] % (nzb.group('id')),
|
||||||
|
'download': self.download,
|
||||||
|
'detail_url': '',
|
||||||
|
'description': '',
|
||||||
|
'check_nzb': False,
|
||||||
|
}
|
||||||
|
|
||||||
|
new['score'] = fireEvent('score.calculate', new, movie, single = True)
|
||||||
|
is_correct_movie = fireEvent('searcher.correct_movie',
|
||||||
|
nzb = new, movie = movie, quality = quality,
|
||||||
|
imdb_results = False, single_category = False, single = True)
|
||||||
|
if is_correct_movie:
|
||||||
|
results.append(new)
|
||||||
|
self.found(new)
|
||||||
|
return results
|
||||||
|
|
||||||
|
def download(self, url = '', nzb_id = ''):
|
||||||
|
try:
|
||||||
|
log.info('Downloading nzb from #alt.binaries.hdtv.x264, request id: %s ' % nzb_id)
|
||||||
|
|
||||||
|
return self.urlopen(self.urls['download'] % nzb_id)
|
||||||
|
except Exception, e:
|
||||||
|
log.error('Failed downloading from #alt.binaries.hdtv.x264: %s' % e)
|
||||||
|
return False
|
||||||
|
|
||||||
|
def getFormatId(self, format):
|
||||||
|
for id, quality in self.format_ids.iteritems():
|
||||||
|
for q in quality:
|
||||||
|
if q == format:
|
||||||
|
return id
|
||||||
|
|
||||||
|
return self.cat_backup_id
|
||||||
|
|
||||||
|
def isEnabled(self):
|
||||||
|
return NZBProvider.isEnabled(self) and self.conf('enabled')
|
||||||
Reference in New Issue
Block a user