Enable both nzb and torrent by default
Use default user download dir and enable blackhole
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
from .main import Blackhole
|
||||
from couchpotato.core.helpers.variable import getDownloadDir
|
||||
|
||||
def start():
|
||||
return Blackhole()
|
||||
@@ -16,7 +17,7 @@ config = [{
|
||||
'options': [
|
||||
{
|
||||
'name': 'enabled',
|
||||
'default': 0,
|
||||
'default': True,
|
||||
'type': 'enabler',
|
||||
'radio_group': 'nzb,torrent',
|
||||
},
|
||||
@@ -24,6 +25,7 @@ config = [{
|
||||
'name': 'directory',
|
||||
'type': 'directory',
|
||||
'description': 'Directory where the .nzb (or .torrent) file is saved to.',
|
||||
'default': getDownloadDir()
|
||||
},
|
||||
{
|
||||
'name': 'use_for',
|
||||
|
||||
@@ -63,11 +63,21 @@ def fireEvent(name, *args, **kwargs):
|
||||
except: pass
|
||||
|
||||
e = events[name]
|
||||
if not options['in_order']: e.lock.acquire()
|
||||
|
||||
# Lock this event
|
||||
e.lock.acquire()
|
||||
|
||||
e.asynchronous = False
|
||||
e.in_order = options['in_order']
|
||||
|
||||
# Make sure only 1 event is fired at a time when order is wanted
|
||||
kwargs['event_order_lock'] = threading.RLock() if options['in_order'] or options['single'] else None
|
||||
kwargs['event_return_on_result'] = options['single']
|
||||
|
||||
# Fire
|
||||
result = e(*args, **kwargs)
|
||||
if not options['in_order']: e.lock.release()
|
||||
|
||||
# Release lock for this event
|
||||
e.lock.release()
|
||||
|
||||
if options['single'] and not options['merge']:
|
||||
results = None
|
||||
|
||||
@@ -9,15 +9,34 @@ import sys
|
||||
|
||||
log = CPLog(__name__)
|
||||
|
||||
def getUserDir():
|
||||
try:
|
||||
import pwd
|
||||
os.environ['HOME'] = pwd.getpwuid(os.geteuid()).pw_dir
|
||||
except:
|
||||
pass
|
||||
|
||||
return os.path.expanduser('~')
|
||||
|
||||
def getDownloadDir():
|
||||
user_dir = getUserDir()
|
||||
|
||||
# OSX
|
||||
if 'darwin' in platform.platform().lower():
|
||||
return os.path.join(user_dir, 'Downloads')
|
||||
|
||||
if os.name == 'nt':
|
||||
return os.path.join(user_dir, 'Downloads')
|
||||
|
||||
return user_dir
|
||||
|
||||
def getDataDir():
|
||||
|
||||
# Windows
|
||||
if os.name == 'nt':
|
||||
return os.path.join(os.environ['APPDATA'], 'CouchPotato')
|
||||
|
||||
import pwd
|
||||
os.environ['HOME'] = pwd.getpwuid(os.geteuid()).pw_dir
|
||||
user_dir = os.path.expanduser('~')
|
||||
user_dir = getUserDir()
|
||||
|
||||
# OSX
|
||||
if 'darwin' in platform.platform().lower():
|
||||
|
||||
@@ -17,6 +17,9 @@ class CPLog(object):
|
||||
def info(self, msg, replace_tuple = ()):
|
||||
self.logger.info(self.addContext(msg, replace_tuple))
|
||||
|
||||
def info2(self, msg, replace_tuple = ()):
|
||||
self.logger.log(19, self.addContext(msg, replace_tuple))
|
||||
|
||||
def debug(self, msg, replace_tuple = ()):
|
||||
self.logger.debug(self.addContext(msg, replace_tuple))
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
from couchpotato.api import addApiView
|
||||
from couchpotato.core.helpers.request import getParam, jsonified
|
||||
from couchpotato.core.helpers.variable import getUserDir
|
||||
from couchpotato.core.plugins.base import Plugin
|
||||
import ctypes
|
||||
import os
|
||||
@@ -65,15 +66,7 @@ class FileBrowser(Plugin):
|
||||
def view(self):
|
||||
|
||||
path = getParam('path', '/')
|
||||
|
||||
# Set proper home dir for some systems
|
||||
try:
|
||||
import pwd
|
||||
os.environ['HOME'] = pwd.getpwuid(os.geteuid()).pw_dir
|
||||
except:
|
||||
pass
|
||||
|
||||
home = os.path.expanduser('~')
|
||||
home = getUserDir()
|
||||
|
||||
if not path:
|
||||
path = home
|
||||
|
||||
@@ -37,7 +37,7 @@ Page.Wizard = new Class({
|
||||
},
|
||||
'downloaders': {
|
||||
'title': 'What download apps are you using?',
|
||||
'description': 'CP needs an external download app to work with. Choose one below. For more downloaders check settings after you have filled in the wizard. If your download app isn\'t in the list, use Blackhole.'
|
||||
'description': 'CP needs an external download app to work with. Choose one below. For more downloaders check settings after you have filled in the wizard. If your download app isn\'t in the list, use the default Blackhole.'
|
||||
},
|
||||
'providers': {
|
||||
'title': 'Are you registered at any of these sites?',
|
||||
|
||||
@@ -15,7 +15,7 @@ config = [{
|
||||
{
|
||||
'name': 'enabled',
|
||||
'type': 'enabler',
|
||||
'default': False,
|
||||
'default': True,
|
||||
},
|
||||
],
|
||||
},
|
||||
|
||||
@@ -15,6 +15,7 @@ config = [{
|
||||
{
|
||||
'name': 'enabled',
|
||||
'type': 'enabler',
|
||||
'default': True,
|
||||
},
|
||||
],
|
||||
},
|
||||
|
||||
@@ -16,7 +16,7 @@ config = [{
|
||||
{
|
||||
'name': 'enabled',
|
||||
'type': 'enabler',
|
||||
'default': False,
|
||||
'default': True,
|
||||
},
|
||||
],
|
||||
},
|
||||
|
||||
@@ -94,6 +94,7 @@ class KickAssTorrents(TorrentProvider):
|
||||
is_correct_movie = fireEvent('searcher.correct_movie',
|
||||
nzb = new, movie = movie, quality = quality,
|
||||
imdb_results = True, single = True)
|
||||
|
||||
if is_correct_movie:
|
||||
results.append(new)
|
||||
self.found(new)
|
||||
|
||||
@@ -15,7 +15,7 @@ config = [{
|
||||
{
|
||||
'name': 'enabled',
|
||||
'type': 'enabler',
|
||||
'default': False,
|
||||
'default': True,
|
||||
},
|
||||
],
|
||||
},
|
||||
|
||||
@@ -16,7 +16,7 @@ config = [{
|
||||
{
|
||||
'name': 'enabled',
|
||||
'type': 'enabler',
|
||||
'default': False
|
||||
'default': True
|
||||
},
|
||||
{
|
||||
'name': 'domain',
|
||||
|
||||
+41
-19
@@ -95,7 +95,6 @@ class Event(object):
|
||||
(None, None, handler), ... # asynchronous execution
|
||||
)
|
||||
"""
|
||||
self.in_order = False
|
||||
self.name = name
|
||||
self.asynchronous = asynch
|
||||
self.exc_info = exc_info
|
||||
@@ -142,11 +141,16 @@ class Event(object):
|
||||
def fire(self, *args, **kwargs):
|
||||
""" Stores all registered handlers in a queue for processing """
|
||||
self.queue = Queue.Queue()
|
||||
self.result = {}
|
||||
result = {}
|
||||
|
||||
if self.handlers:
|
||||
|
||||
max_threads = self._threads()
|
||||
max_threads = 1 if kwargs.get('event_order_lock') else self._threads()
|
||||
|
||||
# Set global result
|
||||
def add_to(key, value):
|
||||
result[key] = value
|
||||
kwargs['event_add_to_result'] = add_to
|
||||
|
||||
for i in range(max_threads):
|
||||
t = threading.Thread(target = self._execute,
|
||||
@@ -159,17 +163,12 @@ class Event(object):
|
||||
|
||||
if self.asynchronous:
|
||||
handler_, memoize, timeout = self.handlers[handler]
|
||||
self.result[handler] = (None, None, handler_)
|
||||
result[handler] = (None, None, handler_)
|
||||
|
||||
if not self.asynchronous:
|
||||
self.queue.join()
|
||||
|
||||
res = self.result or None
|
||||
|
||||
# Cleanup
|
||||
self.result = {}
|
||||
|
||||
return res
|
||||
return result
|
||||
|
||||
def count(self):
|
||||
""" Returns the count of registered handlers """
|
||||
@@ -181,24 +180,47 @@ class Event(object):
|
||||
self.memoize.clear()
|
||||
|
||||
def _execute(self, *args, **kwargs):
|
||||
|
||||
# Remove get and set from kwargs
|
||||
add_to_result = kwargs.get('event_add_to_result')
|
||||
del kwargs['event_add_to_result']
|
||||
|
||||
# Get and remove order lock
|
||||
order_lock = kwargs.get('event_order_lock')
|
||||
try: del kwargs['event_order_lock']
|
||||
except: pass
|
||||
|
||||
# Get and remove return on first
|
||||
return_on_result = kwargs.get('event_return_on_result')
|
||||
try: del kwargs['event_return_on_result']
|
||||
except: pass
|
||||
|
||||
got_results = False
|
||||
|
||||
""" Executes all handlers stored in the queue """
|
||||
while True:
|
||||
|
||||
try:
|
||||
h_ = self.queue.get(timeout = 2)
|
||||
handler, memoize, timeout = self.handlers[h_]
|
||||
|
||||
if self.lock and self.in_order:
|
||||
self.lock.acquire()
|
||||
if return_on_result and got_results:
|
||||
continue
|
||||
|
||||
if order_lock:
|
||||
order_lock.acquire()
|
||||
|
||||
try:
|
||||
r = self._memoize(memoize, timeout, handler, *args, **kwargs)
|
||||
if not self.asynchronous:
|
||||
self.result[h_] = tuple(r)
|
||||
if not return_on_result or (return_on_result and r[1]):
|
||||
add_to_result(h_, tuple(r))
|
||||
got_results = True
|
||||
|
||||
except Exception:
|
||||
if not self.asynchronous:
|
||||
self.result[h_] = (False, self._error(sys.exc_info()),
|
||||
handler)
|
||||
add_to_result(h_, (False, self._error(sys.exc_info()),
|
||||
handler))
|
||||
else:
|
||||
self.error_handler(sys.exc_info())
|
||||
finally:
|
||||
@@ -206,8 +228,8 @@ class Event(object):
|
||||
if not self.asynchronous:
|
||||
self.queue.task_done()
|
||||
|
||||
if self.lock and self.in_order:
|
||||
self.lock.release()
|
||||
if order_lock:
|
||||
order_lock.release()
|
||||
|
||||
if self.queue.empty():
|
||||
raise Queue.Empty
|
||||
@@ -257,7 +279,7 @@ class Event(object):
|
||||
args.insert(0, self.sender)
|
||||
|
||||
if not memoize:
|
||||
if timeout <= 0: #no time restriction
|
||||
if timeout <= 0: #no time restriction
|
||||
result = [True, handler(*args, **kwargs), handler]
|
||||
return result
|
||||
|
||||
@@ -273,7 +295,7 @@ class Event(object):
|
||||
if args_ == args and kwargs_ == kwargs:
|
||||
return [True, result, handler]
|
||||
|
||||
if timeout <= 0: #no time restriction
|
||||
if timeout <= 0: #no time restriction
|
||||
result = handler(*args, **kwargs)
|
||||
else:
|
||||
result = self._timeout(timeout, handler, *args, **kwargs)
|
||||
|
||||
Reference in New Issue
Block a user