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