Merge branch 'master' of github.com:CouchPotato/CouchPotato

Conflicts:
	couchpotato/core/plugins/searcher/__init__.py
This commit is contained in:
Ruud
2011-08-19 16:15:51 +02:00
37 changed files with 1183 additions and 81 deletions
@@ -34,6 +34,7 @@ class Blackhole(Downloader):
log.debug('Failed download file: %s' % data.get('name'))
return False
else:
log.info('Downloading: %s' % data.get('url'))
file = urllib.urlopen(data.get('url')).read()
with open(fullPath, 'wb') as f:
+30 -3
View File
@@ -1,20 +1,47 @@
from couchpotato.api import addApiView
from couchpotato.core.event import addEvent
from couchpotato.core.helpers.request import jsonified
from couchpotato.core.logger import CPLog
from couchpotato.core.plugins.base import Plugin
log = CPLog(__name__)
class Notification(Plugin):
default_title = 'CouchPotato'
test_message = 'ZOMG Lazors Pewpewpew!'
listen_to = []
dont_listen_to = []
def __init__(self):
addEvent('notify', self.notify)
addEvent('notify.%s' % self.getName().lower(), self.notify)
def notify(self, message = '', data = {}):
addApiView(self.testNotifyName(), self.test)
def notify(self, message = '', data = {}, type = ''):
pass
def test(self):
success = self.notify(message = self.test_message)
return jsonified({'success': success})
test_type = self.testNotifyName()
log.info('Sending test to %s' % test_type)
success = self.notify(
message = self.test_message,
data = {},
type = test_type
)
#return jsonified({'success': success})
def dontNotify(self, type = ''):
return (not type in self.listen_to and len(self.listen_to) == 0 and type != self.testNotifyName()) \
or type in self.dont_listen_to \
or self.isDisabled()
def testNotifyName(self):
return 'notify.%s.test' % self.getName().lower()
+3 -3
View File
@@ -2,13 +2,13 @@ from couchpotato.api import addApiView
from couchpotato.core.event import addEvent, fireEvent
from couchpotato.core.helpers.request import jsonified
from couchpotato.core.logger import CPLog
from couchpotato.core.plugins.base import Plugin
from couchpotato.core.notifications.base import Notification
import time
log = CPLog(__name__)
class CoreNotifier(Plugin):
class CoreNotifier(Notification):
messages = []
@@ -21,7 +21,7 @@ class CoreNotifier(Plugin):
self.registerStatic(__file__)
def notify(self, message = '', data = {}):
def notify(self, message = '', data = {}, type = None):
self.add(data = {
'message': message,
'raw': data,
+3 -9
View File
@@ -12,19 +12,13 @@ log = CPLog(__name__)
class Growl(Notification):
def __init__(self):
addEvent('notify', self.notify)
addEvent('notify.growl', self.notify)
addApiView('notify.growl.test', self.test)
listen_to = ['movie.downloaded', 'movie.snatched']
def conf(self, attr):
return Env.setting(attr, 'growl')
def notify(self, message = '', data = {}):
if self.isDisabled():
return
def notify(self, message = '', data = {}, type = None):
if self.dontNotify(type): return
hosts = [x.strip() for x in self.conf('host').split(",")]
password = self.conf('password')
@@ -0,0 +1,6 @@
from .main import History
def start():
return History()
config = []
@@ -0,0 +1,33 @@
from couchpotato import get_session
from couchpotato.core.event import addEvent
from couchpotato.core.logger import CPLog
from couchpotato.core.notifications.base import Notification
from couchpotato.core.settings.model import History as Hist
import time
log = CPLog(__name__)
class History(Notification):
listen_to = ['movie.downloaded', 'movie.snatched', 'movie.renaming.']
def __init__(self):
addEvent('notify', self.notify)
addEvent('app.load', self.test)
def notify(self, message = '', data = {}, type = None):
if self.dontNotify(type): return
db = get_session()
history = Hist(
added = int(time.time()),
message = message,
type = type,
release_id = data.get('id', 0)
)
db.add(history)
db.commit()
+6 -9
View File
@@ -1,5 +1,4 @@
from couchpotato.api import addApiView
from couchpotato.core.event import addEvent
from couchpotato.core.helpers.request import getParams, jsonified
from couchpotato.core.logger import CPLog
from couchpotato.core.notifications.base import Notification
@@ -19,11 +18,11 @@ log = CPLog(__name__)
class NMJ(Notification):
def __init__(self):
addEvent('notify', self.notify)
addEvent('notify.nmj', self.notify)
listen_to = ['movie.downloaded', 'movie.snatched']
def __init__(self):
super(NMJ, self).__init__()
addApiView('notify.nmj.test', self.test)
addApiView('notify.nmj.auto_config', self.autoConfig)
def conf(self, attr):
@@ -76,10 +75,8 @@ class NMJ(Notification):
'mount': mount,
})
def notify(self, message = '', data = {}):
if self.isDisabled():
return False
def notify(self, message = '', data = {}, type = None):
if self.dontNotify(type): return
host = self.conf('host')
mount = self.conf('mount')
@@ -16,19 +16,13 @@ class Notifo(Notification):
url = 'https://api.notifo.com/v1/send_notification'
def __init__(self):
addEvent('notify', self.notify)
addEvent('notify.notifo', self.notify)
addApiView('notify.notifo.test', self.test)
listen_to = ['movie.downloaded', 'movie.snatched']
def conf(self, attr):
return Env.setting(attr, 'notifo')
def notify(self, message = '', data = {}):
if self.isDisabled():
return False
def notify(self, message = '', data = {}, type = None):
if self.dontNotify(type): return
try:
data = urllib.urlencode({
+3 -9
View File
@@ -10,16 +10,10 @@ log = CPLog(__name__)
class Plex(Notification):
def __init__(self):
addEvent('notify', self.notify)
addEvent('notify.plex', self.notify)
listen_to = ['movie.downloaded', 'movie.snatched']
addApiView('notify.plex.test', self.test)
def notify(self, message = '', data = {}):
if self.isDisabled():
return
def notify(self, message = '', data = {}, type = None):
if self.dontNotify(type): return
log.info('Sending notification to Plex')
hosts = [x.strip() for x in self.conf('host').split(",")]
+3 -11
View File
@@ -1,5 +1,3 @@
from couchpotato.api import addApiView
from couchpotato.core.event import addEvent
from couchpotato.core.helpers.encoding import toUnicode
from couchpotato.core.logger import CPLog
from couchpotato.core.notifications.base import Notification
@@ -11,16 +9,10 @@ log = CPLog(__name__)
class Prowl(Notification):
def __init__(self):
addEvent('notify', self.notify)
addEvent('notify.prowl', self.notify)
listen_to = ['movie.downloaded', 'movie.snatched']
addApiView('notify.prowl.test', self.test)
def notify(self, message = '', data = {}):
if self.isDisabled():
return
def notify(self, message = '', data = {}, type = None):
if self.dontNotify(type): return
http_handler = HTTPSConnection('api.prowlapp.com')
+3 -11
View File
@@ -1,5 +1,3 @@
from couchpotato.api import addApiView
from couchpotato.core.event import addEvent
from couchpotato.core.logger import CPLog
from couchpotato.core.notifications.base import Notification
import base64
@@ -11,16 +9,10 @@ log = CPLog(__name__)
class XBMC(Notification):
def __init__(self):
addEvent('notify', self.notify)
addEvent('notify.xbmc', self.notify)
listen_to = ['movie.downloaded', 'movie.snatched']
addApiView('notify.xbmc.test', self.test)
def notify(self, message = '', data = {}):
if self.isDisabled():
return
def notify(self, message = '', data = {}, type = None):
if self.dontNotify(type): return
for host in [x.strip() for x in self.conf('host').split(",")]:
self.send({'command': 'ExecBuiltIn', 'parameter': 'Notification(CouchPotato, %s)' % message}, host)
+2 -2
View File
@@ -8,7 +8,7 @@ import os.path
import re
class Plugin():
class Plugin(object):
def conf(self, attr, default = None):
return Env.setting(attr, self.getName().lower(), default = default)
@@ -39,4 +39,4 @@ class Plugin():
return not self.isEnabled()
def isEnabled(self):
return self.conf('enabled')
return self.conf('enabled') or self.conf('enabled') == None
+9 -1
View File
@@ -149,6 +149,10 @@ class Renamer(Plugin):
if multiple:
cd += 1
# Notify on download
download_message = 'Download of %s (%s) successful.' % (group['library']['titles'][0]['title'], replacements['quality'])
fireEvent('notify', type = 'movie.downloaded', message = download_message, data = replacements)
# Before renaming, remove the lower quality files
db = get_session()
library = db.query(Library).filter_by(identifier = group['library']['identifier']).first()
@@ -172,6 +176,10 @@ class Renamer(Plugin):
for rename_me in rename_files:
filename = os.path.basename(rename_me)
rename_files[rename_me] = rename_me.replace(filename, '_EXISTS_%s' % filename)
# Notify on rename fail
download_message = 'Renaming of %s (%s) canceled, exists in %s already.' % (movie.library.titles[0].title, group['meta_data']['quality']['label'], release.quality.label)
fireEvent('notify', type = 'movie.renaming.canceled', message = download_message, data = group)
break
@@ -200,7 +208,7 @@ class Renamer(Plugin):
#print rename_me, rename_files[rename_me]
# Search for trailers
# Search for trailers etc
fireEvent('renamer.after', group)
def moveFile(self, old, dest, suppress = True):
+3 -1
View File
@@ -91,7 +91,6 @@ class Searcher(Plugin):
print successful
if successful:
log.info('Downloading of %s successful.' % nzb.get('name'))
# Mark release as snatched
db = get_session()
@@ -105,6 +104,9 @@ class Searcher(Plugin):
mvie.status_id = snatched_status.get('id')
db.commit()
log.info('Downloading of %s successful.' % nzb.get('name'))
fireEvent('notify', type = 'movie.snatched', message = 'Downloading of %s successful.' % nzb.get('name'), data = rls.to_dict())
return True
return False
@@ -0,0 +1,30 @@
from .main import Updater
def start():
return Updater()
config = [{
'name': 'updater',
'groups': [
{
'tab': 'general',
'name': 'updater',
'label': 'Updater',
'git_only': True,
'options': [
{
'name': 'enabled',
'default': True,
'type': 'enabler',
'description': 'Enable periodic update checking',
},
{
'name': 'automatic',
'default': False,
'type': 'enabler',
'description': 'Automaticly update when update is available',
},
],
},
],
}]
+79
View File
@@ -0,0 +1,79 @@
from couchpotato.core.event import addEvent, fireEvent
from couchpotato.core.logger import CPLog
from couchpotato.core.plugins.base import Plugin
from couchpotato.environment import Env
from git.repository import LocalRepository
import time
log = CPLog(__name__)
class Updater(Plugin):
git = 'git://github.com/CouchPotato/CouchPotato.git'
running = False
version = None
updateFailed = False
updateAvailable = False
updateVersion = None
lastCheck = 0
def __init__(self):
self.repo = LocalRepository(Env.get('app_dir'))
fireEvent('schedule.interval', 'updater.check', self.check, hours = 6)
addEvent('app.load', self.check)
def getVersion(self):
if not self.version:
try:
output = self.repo.getHead() # Yes, please
log.debug('Git version output: %s' % output.hash)
self.version = output.hash
except Exception, e:
log.error('Failed using GIT updater, running from source, you need to have GIT installed. %s' % e)
return 'No GIT'
return self.version
def check(self):
if self.updateAvailable or self.isDisabled():
return
current_branch = self.repo.getCurrentBranch().name
for branch in self.repo.getRemoteByName('origin').getBranches():
if current_branch == branch.name:
local = self.repo.getHead()
remote = branch.getHead()
if local.getDate() < remote.getDate():
if self.conf('automatic') and not self.updateFailed:
self.doUpdate()
else:
self.updateAvailable = True
self.updateVersion = remote.hash
self.lastCheck = time.time()
def doUpdate(self):
try:
log.info('Updating to latest version');
self.repo.pull()
return True
except Exception, e:
log.error('Failed updating via GIT: %s' % e)
self.updateFailed = True
return False
def isEnabled(self):
return Plugin.isEnabled(self) and Env.get('uses_git')
+1 -1
View File
@@ -64,7 +64,7 @@ class Provider(Plugin):
data = urllib2.urlopen(url).read()
except IOError, e:
log.debug(e)
log.error('Failed opening url, %s: %s' % (url, e))
data = ''
self.last_use = time.time()
@@ -0,0 +1,6 @@
from .main import CouchPotatoApi
def start():
return CouchPotatoApi()
config = []
@@ -0,0 +1,27 @@
from couchpotato.core.event import addEvent
from couchpotato.core.logger import CPLog
from couchpotato.core.providers.base import MovieProvider
from flask.helpers import json
log = CPLog(__name__)
class CouchPotatoApi(MovieProvider):
apiUrl = 'http://couchpotatoapp.com/api/%s/%s/'
def __init__(self):
addEvent('provider.movie.release_date', self.releaseDate)
def releaseDate(self, imdb_id):
data = self.urlopen(self.apiUrl % ('eta', id))
try:
dates = json.loads(data)
log.info('Found ETA for %s: %s' % (imdb_id, dates))
except Exception, e:
log.error('Error getting ETA for %s: %s' % (imdb_id, e))
return dates
@@ -111,7 +111,7 @@ class NZBMatrix(NZBProvider, RSS):
return results
def getApiExt(self):
return '&username=%s&apikey=%s' % (self.conf('username'), self.conf('apikey'))
return '&username=%s&apikey=%s' % (self.conf('username'), self.conf('api_key'))
def isEnabled(self):
return NZBProvider.isEnabled(self) and self.conf('username') and self.conf('api_key')
+5 -2
View File
@@ -2,8 +2,8 @@ from elixir.entity import Entity
from elixir.fields import Field
from elixir.options import options_defaults
from elixir.relationships import OneToMany, ManyToOne
from libs.elixir.options import using_options
from libs.elixir.relationships import ManyToMany
from elixir.options import using_options
from elixir.relationships import ManyToMany
from sqlalchemy.types import Integer, Unicode, UnicodeText, Boolean, Float, \
String
@@ -179,7 +179,10 @@ class History(Entity):
"""History of actions that are connected to a certain release,
such as, renamed to, downloaded, deleted, download subtitles etc"""
added = Field(Integer)
message = Field(UnicodeText())
type = Field(Unicode(50))
release = ManyToOne('Release')