blackhole
This commit is contained in:
@@ -2,6 +2,7 @@ from couchpotato.core.event import addEvent
|
||||
from couchpotato.core.logger import CPLog
|
||||
from couchpotato.core.plugins.base import Plugin
|
||||
from couchpotato.environment import Env
|
||||
import os
|
||||
|
||||
log = CPLog(__name__)
|
||||
|
||||
@@ -16,8 +17,11 @@ class Downloader(Plugin):
|
||||
def download(self, data = {}):
|
||||
pass
|
||||
|
||||
def createFileExtension(self, data = {}, content):
|
||||
pass
|
||||
def createFileName(self, directory, data = {}, content, movie):
|
||||
if "DOCTYPE nzb" not in content:
|
||||
if data.get('type') == 'nzb':
|
||||
return os.path.join(directory, '%s%s.%s' % (toSafeString(data.get('name')), self.cpTag(movie) , 'rar')
|
||||
return os.path.join(directory, '%s%s.%s' % (toSafeString(data.get('name')), self.cpTag(movie) , data.get('type'))
|
||||
|
||||
def cpTag(self, movie):
|
||||
if Env.setting('enabled', 'renamer'):
|
||||
|
||||
@@ -10,12 +10,6 @@ class Blackhole(Downloader):
|
||||
|
||||
type = ['nzb', 'torrent']
|
||||
|
||||
def createFileExtension(self, data = {}, content):
|
||||
if "DOCTYPE nzb" not in content:
|
||||
if data.get('type') == 'nzb':
|
||||
return 'rar'
|
||||
return data.get('type')
|
||||
|
||||
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')]):
|
||||
@@ -31,12 +25,15 @@ class Blackhole(Downloader):
|
||||
if "no nzb" in file:
|
||||
log.error('No nzb available!')
|
||||
|
||||
fileExtension = createFileExtension(data, file)
|
||||
fullPath = os.path.join(directory, '%s%s.%s' % (toSafeString(data.get('name')), self.cpTag(movie) , fileExtension)
|
||||
fullPath = self.createFileName(directory, data, file, movie)
|
||||
|
||||
try:
|
||||
if not os.path.isfile(fullPath):
|
||||
log.info('Downloading %s to %s.' % (data.get('type'), fullPath))
|
||||
else:
|
||||
log.info('File %s already exists.' % fullPath)
|
||||
return True
|
||||
|
||||
except:
|
||||
log.error('Failed to download to blackhole %s' % traceback.format_exc())
|
||||
pass
|
||||
@@ -44,11 +41,6 @@ class Blackhole(Downloader):
|
||||
with open(fullPath, 'wb') as f:
|
||||
f.write(file)
|
||||
except:
|
||||
log.debug('Failed download file: %s' % data.get('name'))
|
||||
log.debug('Failed to download file: %s' % data.get('name'))
|
||||
return False
|
||||
|
||||
return True
|
||||
else:
|
||||
log.info('File %s already exists.' % fullPath)
|
||||
return True
|
||||
return False
|
||||
|
||||
Reference in New Issue
Block a user