Userscript add via url
This commit is contained in:
1 parent
d79a25bb5b
commit
9c7c5159e6
2 files changed
+31
-20
No files matched your search
@@ -1,6 +1,9 @@
|
|||||||
from couchpotato.core.event import addEvent
|
from couchpotato.api import addApiView
|
||||||
|
from couchpotato.core.event import addEvent, fireEvent
|
||||||
|
from couchpotato.core.helpers.request import getParam
|
||||||
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 urlparse import urlparse
|
||||||
|
|
||||||
log = CPLog(__name__)
|
log = CPLog(__name__)
|
||||||
|
|
||||||
@@ -13,14 +16,34 @@ class UserscriptBase(Plugin):
|
|||||||
excludes = []
|
excludes = []
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
addEvent('userscript.add_via_url', self.addViaUrl)
|
|
||||||
addEvent('userscript.get_includes', self.getInclude)
|
addEvent('userscript.get_includes', self.getInclude)
|
||||||
addEvent('userscript.get_excludes', self.getExclude)
|
addEvent('userscript.get_excludes', self.getExclude)
|
||||||
|
|
||||||
addEvent('userscript.get_version', self.getVersion)
|
addEvent('userscript.get_version', self.getVersion)
|
||||||
|
|
||||||
|
addApiView('userscript.add_via_url', self.addViaUrl)
|
||||||
|
|
||||||
|
def search(self, name, year = None):
|
||||||
|
|
||||||
|
movie = fireEvent('movie.search', q = '%s %s' % (name, year), limit = 1)
|
||||||
|
|
||||||
|
return movie
|
||||||
|
|
||||||
def addViaUrl(self):
|
def addViaUrl(self):
|
||||||
pass
|
|
||||||
|
url = getParam('url')
|
||||||
|
host = urlparse(url).hostname
|
||||||
|
|
||||||
|
# Check if the url matches the provider
|
||||||
|
is_provider = False
|
||||||
|
for include in self.includes:
|
||||||
|
if host in include:
|
||||||
|
is_provider = True
|
||||||
|
break
|
||||||
|
if not is_provider:
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
fireEvent()
|
||||||
|
|
||||||
def getInclude(self):
|
def getInclude(self):
|
||||||
return self.includes
|
return self.includes
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
from beautifulsoup import BeautifulSoup
|
from beautifulsoup import BeautifulSoup
|
||||||
|
from couchpotato.core.event import fireEvent
|
||||||
from couchpotato.core.providers.userscript.base import UserscriptBase
|
from couchpotato.core.providers.userscript.base import UserscriptBase
|
||||||
import re
|
import re
|
||||||
|
|
||||||
@@ -19,27 +20,14 @@ class IMDB(UserscriptBase):
|
|||||||
if 'seasons' in head.lower():
|
if 'seasons' in head.lower():
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
identifier = re.search('(?P<id>tt[0-9{7}]+)', url).group('id')
|
||||||
|
movie = fireEvent('movie.info', identifier = identifier)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
'id': re.search('(?P<id>tt[0-9{7}]+)', url).group('id'),
|
'id': re.search('(?P<id>tt[0-9{7}]+)', url).group('id'),
|
||||||
'year': self.getYear(html)
|
'year': self.getYear(html)
|
||||||
}
|
}
|
||||||
|
|
||||||
def getYear(self, html):
|
|
||||||
|
|
||||||
headers = html.findAll('h1')
|
|
||||||
|
|
||||||
tv_pattern = '/^\((TV|Video) ([0-9]+)\)$/';
|
|
||||||
|
|
||||||
try:
|
|
||||||
year = headers[0].findAll('a').text
|
|
||||||
return year
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
|
|
||||||
for head in headers:
|
|
||||||
match = re.search(tv_pattern, head)
|
|
||||||
if match:
|
|
||||||
return match[1]
|
|
||||||
|
|
||||||
#CouchPotato['imdb.com'] = (function(){
|
#CouchPotato['imdb.com'] = (function(){
|
||||||
#
|
#
|
||||||
|
|||||||
Reference in new issue
Block a user