Merge branch 'refs/heads/develop'
This commit is contained in:
@@ -35,6 +35,13 @@ config = [{
|
|||||||
'type': 'dropdown',
|
'type': 'dropdown',
|
||||||
'values': [('usenet & torrents', 'both'), ('usenet', 'nzb'), ('torrent', 'torrent')],
|
'values': [('usenet & torrents', 'both'), ('usenet', 'nzb'), ('torrent', 'torrent')],
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
'name': 'create_subdir',
|
||||||
|
'default': 0,
|
||||||
|
'type': 'bool',
|
||||||
|
'advanced': True,
|
||||||
|
'description': 'Create a sub directory when saving the .nzb (or .torrent).',
|
||||||
|
},
|
||||||
{
|
{
|
||||||
'name': 'manual',
|
'name': 'manual',
|
||||||
'default': 0,
|
'default': 0,
|
||||||
|
|||||||
@@ -33,17 +33,27 @@ class Blackhole(Downloader):
|
|||||||
log.error('No nzb/torrent available: %s', data.get('url'))
|
log.error('No nzb/torrent available: %s', data.get('url'))
|
||||||
return False
|
return False
|
||||||
|
|
||||||
fullPath = os.path.join(directory, self.createFileName(data, filedata, movie))
|
file_name = self.createFileName(data, filedata, movie)
|
||||||
|
full_path = os.path.join(directory, file_name)
|
||||||
|
|
||||||
|
if self.conf('create_subdir'):
|
||||||
|
try:
|
||||||
|
new_path = os.path.splitext(full_path)[0]
|
||||||
|
if not os.path.exists(new_path):
|
||||||
|
os.makedirs(new_path)
|
||||||
|
full_path = os.path.join(new_path, file_name)
|
||||||
|
except:
|
||||||
|
log.error('Couldnt create sub dir, reverting to old one: %s', full_path)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if not os.path.isfile(fullPath):
|
if not os.path.isfile(full_path):
|
||||||
log.info('Downloading %s to %s.', (data.get('protocol'), fullPath))
|
log.info('Downloading %s to %s.', (data.get('protocol'), full_path))
|
||||||
with open(fullPath, 'wb') as f:
|
with open(full_path, 'wb') as f:
|
||||||
f.write(filedata)
|
f.write(filedata)
|
||||||
os.chmod(fullPath, Env.getPermission('file'))
|
os.chmod(full_path, Env.getPermission('file'))
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
log.info('File %s already exists.', fullPath)
|
log.info('File %s already exists.', full_path)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
except:
|
except:
|
||||||
|
|||||||
+28
-19
@@ -1,6 +1,8 @@
|
|||||||
from couchpotato.core.event import fireEvent
|
from couchpotato.core.event import fireEvent
|
||||||
from couchpotato.core.logger import CPLog
|
from couchpotato.core.logger import CPLog
|
||||||
|
from importlib import import_module
|
||||||
import os
|
import os
|
||||||
|
import sys
|
||||||
import traceback
|
import traceback
|
||||||
|
|
||||||
log = CPLog(__name__)
|
log = CPLog(__name__)
|
||||||
@@ -11,17 +13,6 @@ class Loader(object):
|
|||||||
providers = {}
|
providers = {}
|
||||||
modules = {}
|
modules = {}
|
||||||
|
|
||||||
def addPath(self, root, base_path, priority, recursive = False):
|
|
||||||
for filename in os.listdir(os.path.join(root, *base_path)):
|
|
||||||
path = os.path.join(os.path.join(root, *base_path), filename)
|
|
||||||
if os.path.isdir(path) and filename[:2] != '__':
|
|
||||||
if u'__init__.py' in os.listdir(path):
|
|
||||||
new_base_path = ''.join(s + '.' for s in base_path) + filename
|
|
||||||
self.paths[new_base_path.replace('.', '_')] = (priority, new_base_path, path)
|
|
||||||
|
|
||||||
if recursive:
|
|
||||||
self.addPath(root, base_path + [filename], priority, recursive = True)
|
|
||||||
|
|
||||||
def preload(self, root = ''):
|
def preload(self, root = ''):
|
||||||
core = os.path.join(root, 'couchpotato', 'core')
|
core = os.path.join(root, 'couchpotato', 'core')
|
||||||
|
|
||||||
@@ -38,6 +29,14 @@ class Loader(object):
|
|||||||
# Add media to loader
|
# Add media to loader
|
||||||
self.addPath(root, ['couchpotato', 'core', 'media'], 25, recursive = True)
|
self.addPath(root, ['couchpotato', 'core', 'media'], 25, recursive = True)
|
||||||
|
|
||||||
|
# Add custom plugin folder
|
||||||
|
from couchpotato.environment import Env
|
||||||
|
custom_plugin_dir = os.path.join(Env.get('data_dir'), 'custom_plugins')
|
||||||
|
if os.path.isdir(custom_plugin_dir):
|
||||||
|
sys.path.insert(0, custom_plugin_dir)
|
||||||
|
self.paths['custom_plugins'] = (30, '', custom_plugin_dir)
|
||||||
|
|
||||||
|
# Loop over all paths and add to module list
|
||||||
for plugin_type, plugin_tuple in self.paths.iteritems():
|
for plugin_type, plugin_tuple in self.paths.iteritems():
|
||||||
priority, module, dir_name = plugin_tuple
|
priority, module, dir_name = plugin_tuple
|
||||||
self.addFromDir(plugin_type, priority, module, dir_name)
|
self.addFromDir(plugin_type, priority, module, dir_name)
|
||||||
@@ -45,8 +44,9 @@ class Loader(object):
|
|||||||
def run(self):
|
def run(self):
|
||||||
did_save = 0
|
did_save = 0
|
||||||
|
|
||||||
for priority in self.modules:
|
for priority in sorted(self.modules):
|
||||||
for module_name, plugin in sorted(self.modules[priority].iteritems()):
|
for module_name, plugin in sorted(self.modules[priority].iteritems()):
|
||||||
|
|
||||||
# Load module
|
# Load module
|
||||||
try:
|
try:
|
||||||
if plugin.get('name')[:2] == '__':
|
if plugin.get('name')[:2] == '__':
|
||||||
@@ -55,7 +55,6 @@ class Loader(object):
|
|||||||
m = self.loadModule(module_name)
|
m = self.loadModule(module_name)
|
||||||
if m is None:
|
if m is None:
|
||||||
continue
|
continue
|
||||||
m = getattr(m, plugin.get('name'))
|
|
||||||
|
|
||||||
log.info('Loading %s: %s', (plugin['type'], plugin['name']))
|
log.info('Loading %s: %s', (plugin['type'], plugin['name']))
|
||||||
|
|
||||||
@@ -77,10 +76,23 @@ class Loader(object):
|
|||||||
if did_save:
|
if did_save:
|
||||||
fireEvent('settings.save')
|
fireEvent('settings.save')
|
||||||
|
|
||||||
|
def addPath(self, root, base_path, priority, recursive = False):
|
||||||
|
root_path = os.path.join(root, *base_path)
|
||||||
|
for filename in os.listdir(root_path):
|
||||||
|
path = os.path.join(root_path, filename)
|
||||||
|
if os.path.isdir(path) and filename[:2] != '__':
|
||||||
|
if u'__init__.py' in os.listdir(path):
|
||||||
|
new_base_path = ''.join(s + '.' for s in base_path) + filename
|
||||||
|
self.paths[new_base_path.replace('.', '_')] = (priority, new_base_path, path)
|
||||||
|
|
||||||
|
if recursive:
|
||||||
|
self.addPath(root, base_path + [filename], priority, recursive = True)
|
||||||
|
|
||||||
def addFromDir(self, plugin_type, priority, module, dir_name):
|
def addFromDir(self, plugin_type, priority, module, dir_name):
|
||||||
|
|
||||||
# Load dir module
|
# Load dir module
|
||||||
self.addModule(priority, plugin_type, module, os.path.basename(dir_name))
|
if module and len(module) > 0:
|
||||||
|
self.addModule(priority, plugin_type, module, os.path.basename(dir_name))
|
||||||
|
|
||||||
for name in os.listdir(dir_name):
|
for name in os.listdir(dir_name):
|
||||||
if os.path.isdir(os.path.join(dir_name, name)) and name != 'static' and os.path.isfile(os.path.join(dir_name, name, '__init__.py')):
|
if os.path.isdir(os.path.join(dir_name, name)) and name != 'static' and os.path.isfile(os.path.join(dir_name, name, '__init__.py')):
|
||||||
@@ -123,6 +135,7 @@ class Loader(object):
|
|||||||
if not self.modules.get(priority):
|
if not self.modules.get(priority):
|
||||||
self.modules[priority] = {}
|
self.modules[priority] = {}
|
||||||
|
|
||||||
|
module = module.lstrip('.')
|
||||||
self.modules[priority][module] = {
|
self.modules[priority][module] = {
|
||||||
'priority': priority,
|
'priority': priority,
|
||||||
'module': module,
|
'module': module,
|
||||||
@@ -132,11 +145,7 @@ class Loader(object):
|
|||||||
|
|
||||||
def loadModule(self, name):
|
def loadModule(self, name):
|
||||||
try:
|
try:
|
||||||
m = __import__(name)
|
return import_module(name)
|
||||||
splitted = name.split('.')
|
|
||||||
for sub in splitted[1:-1]:
|
|
||||||
m = getattr(m, sub)
|
|
||||||
return m
|
|
||||||
except ImportError:
|
except ImportError:
|
||||||
log.debug('Skip loading module plugin %s: %s', (name, traceback.format_exc()))
|
log.debug('Skip loading module plugin %s: %s', (name, traceback.format_exc()))
|
||||||
return None
|
return None
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
from .main import Custom
|
||||||
|
|
||||||
|
def start():
|
||||||
|
return Custom()
|
||||||
|
|
||||||
|
config = []
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
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__)
|
||||||
|
|
||||||
|
|
||||||
|
class Custom(Plugin):
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
addEvent('app.load', self.createStructure)
|
||||||
|
|
||||||
|
def createStructure(self):
|
||||||
|
|
||||||
|
custom_dir = os.path.join(Env.get('data_dir'), 'custom_plugins')
|
||||||
|
|
||||||
|
if not os.path.isdir(custom_dir):
|
||||||
|
self.makeDir(custom_dir)
|
||||||
|
self.createFile(os.path.join(custom_dir, '__init__.py'), '# Don\'t remove this file')
|
||||||
@@ -222,9 +222,10 @@ class Manage(Plugin):
|
|||||||
|
|
||||||
groups = fireEvent('scanner.scan', folder = folder, files = files, single = True)
|
groups = fireEvent('scanner.scan', folder = folder, files = files, single = True)
|
||||||
|
|
||||||
for group in groups.itervalues():
|
if groups:
|
||||||
if group['library'] and group['library'].get('identifier'):
|
for group in groups.itervalues():
|
||||||
fireEvent('release.add', group = group)
|
if group['library'] and group['library'].get('identifier'):
|
||||||
|
fireEvent('release.add', group = group)
|
||||||
|
|
||||||
def getDiskSpace(self):
|
def getDiskSpace(self):
|
||||||
|
|
||||||
|
|||||||
@@ -25,7 +25,9 @@ class Scanner(Plugin):
|
|||||||
'media': 314572800, # 300MB
|
'media': 314572800, # 300MB
|
||||||
'trailer': 1048576, # 1MB
|
'trailer': 1048576, # 1MB
|
||||||
}
|
}
|
||||||
ignored_in_path = [os.path.sep + 'extracted' + os.path.sep, 'extracting', '_unpack', '_failed_', '_unknown_', '_exists_', '_failed_remove_', '_failed_rename_', '.appledouble', '.appledb', '.appledesktop', os.path.sep + '._', '.ds_store', 'cp.cpnfo'] #unpacking, smb-crap, hidden files
|
ignored_in_path = [os.path.sep + 'extracted' + os.path.sep, 'extracting', '_unpack', '_failed_', '_unknown_', '_exists_', '_failed_remove_',
|
||||||
|
'_failed_rename_', '.appledouble', '.appledb', '.appledesktop', os.path.sep + '._', '.ds_store', 'cp.cpnfo',
|
||||||
|
'thumbs.db', 'ehthumbs.db', 'desktop.ini'] #unpacking, smb-crap, hidden files
|
||||||
ignore_names = ['extract', 'extracting', 'extracted', 'movie', 'movies', 'film', 'films', 'download', 'downloads', 'video_ts', 'audio_ts', 'bdmv', 'certificate']
|
ignore_names = ['extract', 'extracting', 'extracted', 'movie', 'movies', 'film', 'films', 'download', 'downloads', 'video_ts', 'audio_ts', 'bdmv', 'certificate']
|
||||||
extensions = {
|
extensions = {
|
||||||
'movie': ['mkv', 'wmv', 'avi', 'mpg', 'mpeg', 'mp4', 'm2ts', 'iso', 'img', 'mdf', 'ts', 'm4v'],
|
'movie': ['mkv', 'wmv', 'avi', 'mpg', 'mpeg', 'mp4', 'm2ts', 'iso', 'img', 'mdf', 'ts', 'm4v'],
|
||||||
@@ -747,8 +749,10 @@ class Scanner(Plugin):
|
|||||||
identifier = file_path.replace(folder, '').lstrip(os.path.sep) # root folder
|
identifier = file_path.replace(folder, '').lstrip(os.path.sep) # root folder
|
||||||
identifier = os.path.splitext(identifier)[0] # ext
|
identifier = os.path.splitext(identifier)[0] # ext
|
||||||
|
|
||||||
path_split = splitString(identifier, os.path.sep)
|
try:
|
||||||
identifier = path_split[-2] if len(path_split) > 1 and len(path_split[-2]) > len(path_split[-1]) else path_split[-1] # Only get filename
|
path_split = splitString(identifier, os.path.sep)
|
||||||
|
identifier = path_split[-2] if len(path_split) > 1 and len(path_split[-2]) > len(path_split[-1]) else path_split[-1] # Only get filename
|
||||||
|
except: pass
|
||||||
|
|
||||||
if exclude_filename:
|
if exclude_filename:
|
||||||
identifier = identifier[:len(identifier) - len(os.path.split(identifier)[-1])]
|
identifier = identifier[:len(identifier) - len(os.path.split(identifier)[-1])]
|
||||||
|
|||||||
@@ -542,7 +542,7 @@
|
|||||||
line-height: 140%;
|
line-height: 140%;
|
||||||
cursor: help;
|
cursor: help;
|
||||||
}
|
}
|
||||||
.page .combined_table .head abbr.use, .page .combined_table .head abbr.automation_urls_use {
|
.page .combined_table .head abbr:first-child {
|
||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
.page .combined_table .head abbr.host {
|
.page .combined_table .head abbr.host {
|
||||||
|
|||||||
@@ -0,0 +1,38 @@
|
|||||||
|
"""Backport of importlib.import_module from 3.x."""
|
||||||
|
# While not critical (and in no way guaranteed!), it would be nice to keep this
|
||||||
|
# code compatible with Python 2.3.
|
||||||
|
import sys
|
||||||
|
|
||||||
|
def _resolve_name(name, package, level):
|
||||||
|
"""Return the absolute name of the module to be imported."""
|
||||||
|
if not hasattr(package, 'rindex'):
|
||||||
|
raise ValueError("'package' not set to a string")
|
||||||
|
dot = len(package)
|
||||||
|
for x in xrange(level, 1, -1):
|
||||||
|
try:
|
||||||
|
dot = package.rindex('.', 0, dot)
|
||||||
|
except ValueError:
|
||||||
|
raise ValueError("attempted relative import beyond top-level "
|
||||||
|
"package")
|
||||||
|
return "%s.%s" % (package[:dot], name)
|
||||||
|
|
||||||
|
|
||||||
|
def import_module(name, package=None):
|
||||||
|
"""Import a module.
|
||||||
|
|
||||||
|
The 'package' argument is required when performing a relative import. It
|
||||||
|
specifies the package to use as the anchor point from which to resolve the
|
||||||
|
relative import to an absolute import.
|
||||||
|
|
||||||
|
"""
|
||||||
|
if name.startswith('.'):
|
||||||
|
if not package:
|
||||||
|
raise TypeError("relative imports require the 'package' argument")
|
||||||
|
level = 0
|
||||||
|
for character in name:
|
||||||
|
if character != '.':
|
||||||
|
break
|
||||||
|
level += 1
|
||||||
|
name = _resolve_name(name[level:], package, level)
|
||||||
|
__import__(name)
|
||||||
|
return sys.modules[name]
|
||||||
Reference in New Issue
Block a user