Extension -> Userscript

This commit is contained in:
Ruud
2011-09-27 07:51:06 +02:00
parent ff9a5971c4
commit d79a25bb5b
22 changed files with 38 additions and 38 deletions
@@ -0,0 +1,6 @@
from .main import AlloCine
def start():
return AlloCine()
config = []
@@ -0,0 +1,34 @@
from couchpotato.core.providers.userscript.base import UserscriptBase
class AlloCine(UserscriptBase):
includes = ['http://www.allocine.fr/film/*']
#CouchPotato['allocine.fr'] = (function(){
#
# function isMovie(){
# var pattern = /fichefilm_gen_cfilm=\d+?\.html$/;
# matched = location.href.match(pattern);
# return null != matched;
# }
#
# function getId() {
# var name = document.title.substr(0, document.title.indexOf(" -")).replace(/ /g, "+");
# lib.search(name, getYear())
# }
#
# function getYear(){
# var year = new RegExp("\\d{4}", document.title)
# return year;
# }
#
# function constructor(){
# if(isMovie()){
# lib.osd(getId(), getYear());
# }
# }
#
# return constructor;
#
#})();
@@ -0,0 +1,6 @@
from .main import AppleTrailers
def start():
return AppleTrailers()
config = []
@@ -0,0 +1,29 @@
from couchpotato.core.providers.userscript.base import UserscriptBase
class AppleTrailers(UserscriptBase):
includes = ['http://trailers.apple.com/trailers/*']
#CouchPotato['trailers.apple.com'] = (function(){
#
# function getId() {
# var name = document.title.substr(0, document.title.indexOf(" -")).replace(/ /g, "+");
# return lib.search(name, getYear())
#
# }
#
# function getYear(){
# var release_date = document.getElementById("view-showtimes").parentNode.innerHTML;
# var year = new RegExp("\\d{4}", release_date)
#
# return year;
# }
#
# function constructor(){
# getId();
# }
#
# return constructor;
#
#})();
@@ -0,0 +1,32 @@
from couchpotato.core.event import addEvent
from couchpotato.core.logger import CPLog
from couchpotato.core.plugins.base import Plugin
log = CPLog(__name__)
class UserscriptBase(Plugin):
version = 1
includes = []
excludes = []
def __init__(self):
addEvent('userscript.add_via_url', self.addViaUrl)
addEvent('userscript.get_includes', self.getInclude)
addEvent('userscript.get_excludes', self.getExclude)
addEvent('userscript.get_version', self.getVersion)
def addViaUrl(self):
pass
def getInclude(self):
return self.includes
def getExclude(self):
return self.excludes
def getVersion(self):
return self.version
@@ -0,0 +1,6 @@
from .main import IMDB
def start():
return IMDB()
config = []
@@ -0,0 +1,82 @@
from beautifulsoup import BeautifulSoup
from couchpotato.core.providers.userscript.base import UserscriptBase
import re
class IMDB(UserscriptBase):
includes = ['http*://*.imdb.com/title/tt*', 'http*://imdb.com/title/tt*']
def getMovie(self, url):
data = self.urlopen(url)
html = BeautifulSoup(data)
headers = html.findAll('h5')
# Don't add TV show
for head in headers:
if 'seasons' in head.lower():
return False
return {
'id': re.search('(?P<id>tt[0-9{7}]+)', url).group('id'),
'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(){
#
# function isMovie(){
# var series = document.getElementsByTagName('h5')
# for (var i = 0; i < series.length; i++) {
# if (series[i].innerHTML == 'Seasons:') {
# return false;
# }
# }
# return true;
# }
#
# function getId(){
# return 'tt' + location.href.replace(/[^\d+]+/g, '');
# }
#
# function getYear(){
# try {
# return document.getElementsByTagName('h1')[0].getElementsByTagName('a')[0].text;
# } catch (e) {
# var spans = document.getElementsByTagName('h1')[0].getElementsByTagName('span');
# var pattern = /^\((TV|Video) ([0-9]+)\)$/;
# for (var i = 0; i < spans.length; i++) {
# if (spans[i].innerHTML.search(pattern)) {
# return spans[i].innerHTML.match(pattern)[1];
# }
# }
# }
# }
#
# var constructor = function(){
# if(isMovie()){
# lib.osd(getId(), getYear());
# }
# }
#
# return constructor;
#
#})();
@@ -0,0 +1,6 @@
from .main import MovieMeter
def start():
return MovieMeter()
config = []
@@ -0,0 +1,41 @@
from couchpotato.core.providers.userscript.base import UserscriptBase
class MovieMeter(UserscriptBase):
includes = ['http://*.moviemeter.nl/film/*', 'http://moviemeter.nl/film/*']
#CouchPotato['moviemeter.nl'] = (function(){
#
# function isMovie(){
# var pattern = /[^/]+\/?$/;
# var html = document.getElementsByTagName('h1')[0].innerHTML
# matched = location.href.match(pattern);
# return null != matched;
# }
#
# function getId(){
# var pattern = /imdb\.com\/title\/tt(\d+)/;
# var html = document.getElementsByTagName('html')[0].innerHTML;
# var imdb_id = html.match(pattern)[1];
# return imdb_id;
#
# }
#
# function getYear(){
# var pattern = /(\d+)[^\d]*$/;
# var html = document.getElementsByTagName('h1')[0].innerHTML;
# var year = html.match(pattern)[1];
# return year;
#
# }
#
# function constructor(){
# if(isMovie()){
# lib.osd(getId(), getYear());
# }
# }
#
# return constructor;
#
#})();
@@ -0,0 +1,6 @@
from .main import ShareThe
def start():
return ShareThe()
config = []
@@ -0,0 +1,40 @@
from couchpotato.core.providers.userscript.base import UserscriptBase
class ShareThe(UserscriptBase):
includes = ['http://*.sharethe.tv/movies/*', 'http://sharethe.tv/movies/*']
#CouchPotato['sharethe.tv'] = (function(){
#
# function isMovie(){
# var pattern = /movies\/[^/]+\/?$/;
# matched = location.href.match(pattern);
# return null != matched;
# }
#
# function getId(){
# var pattern = /imdb\.com\/title\/tt(\d+)/;
# var html = document.getElementsByTagName('html')[0].innerHTML;
# var imdb_id = html.match(pattern)[1];
# return imdb_id;
#
# }
#
# function getYear(){
# var pattern = /(\d+)[^\d]*$/;
# var html = document.getElementsByTagName('html')[0].innerHTML;
# var year = html.match(pattern)[1];
# return year;
#
# }
#
# function constructor(){
# if(isMovie()){
# lib.osd(getId(), getYear());
# }
# }
#
# return constructor;
#
#})();
@@ -0,0 +1,6 @@
from .main import TMDB
def start():
return TMDB()
config = []
@@ -0,0 +1,31 @@
from couchpotato.core.providers.userscript.base import UserscriptBase
class TMDB(UserscriptBase):
includes = ['http://www.themoviedb.org/movie/*']
#CouchPotato['themoviedb.org'] = (function(){
#
# var obj = this;
#
# function getId() {
#
# name = document.title.substr(0, document.title.indexOf("TMDb")-3).replace(/ /g, "+");
# lib.search(name, getYear())
#
# }
#
# function getYear(){
# var year = document.getElementById("year").innerHTML;
# year = year.substr(1, year.length-2);
# return year;
# }
#
# function constructor(){
# getId();
# }
#
# return constructor;
#
#})();
@@ -0,0 +1,6 @@
from .main import Trakt
def start():
return Trakt()
config = []
@@ -0,0 +1,37 @@
from couchpotato.core.providers.userscript.base import UserscriptBase
class Trakt(UserscriptBase):
includes = ['http://trakt.tv/movie/*', 'http://*.trakt.tv/movie/*']
excludes = ['http://trakt.tv/movie/*/*', 'http://*.trakt.tv/movie/*/*']
#CouchPotato['trakt.tv'] = (function(){
#
# var imdb_input = null;
# var year_input = null;
#
# function isMovie(){
# imdb_input = document.getElementById("meta-imdb-id");
# year_input = document.getElementById("meta-year");
# return (null != imdb_input) && (null != year_input);
# }
#
# function getId(){
# return imdb_input.value.substr(2);
# }
#
# function getYear(){
# return year_input.value;
#
# }
#
# function constructor(){
# if(isMovie()){
# lib.osd(getId(), getYear());
# }
# }
#
# return constructor;
#
#})();
@@ -0,0 +1,6 @@
from .main import WHiWA
def start():
return WHiWA()
config = []
@@ -0,0 +1,41 @@
from couchpotato.core.providers.userscript.base import UserscriptBase
class WHiWA(UserscriptBase):
includes = ['http://whiwa.net/stats/movie/*']
#CouchPotato['whiwa.net'] = (function(){
#
# function isMovie(){
# var pattern = /[^/]+\/?$/;
# var html = document.getElementsByTagName('h3')[0].innerHTML
# var matched = location.href.match(pattern);
# return null != matched;
# }
#
# function getId(){
# var pattern = /imdb\.com\/title\/tt(\d+)/;
# var html = document.getElementsByTagName('html')[0].innerHTML;
# var imdb_id = html.match(pattern)[1];
# return imdb_id;
#
# }
#
# function getYear(){
# var pattern = /(\d+)[^\d]*$/;
# var html = document.getElementsByTagName('h3')[0].innerHTML;
# var year = html.match(pattern)[1];
# return year;
#
# }
#
# function constructor(){
# if(isMovie()){
# lib.osd(getId(), getYear());
# }
# }
#
# return constructor;
#
#})();