From 3103a24a55ae6c5b23e54f78f91c86d0e9955669 Mon Sep 17 00:00:00 2001 From: Ruud Date: Wed, 12 Oct 2011 13:47:00 +0200 Subject: [PATCH] Userscript provider parsers --- couchpotato/core/providers/userscript/base.py | 7 +++- .../core/providers/userscript/imdb/main.py | 4 +-- .../providers/userscript/moviemeter/main.py | 35 ------------------- .../providers/userscript/sharethe/main.py | 34 ------------------ .../core/providers/userscript/tmdb/main.py | 30 ++++------------ .../core/providers/userscript/trakt/main.py | 30 ---------------- .../core/providers/userscript/whiwa/main.py | 35 ------------------- 7 files changed, 13 insertions(+), 162 deletions(-) diff --git a/couchpotato/core/providers/userscript/base.py b/couchpotato/core/providers/userscript/base.py index d60ea5a2..ec7693ff 100644 --- a/couchpotato/core/providers/userscript/base.py +++ b/couchpotato/core/providers/userscript/base.py @@ -1,4 +1,5 @@ from couchpotato.core.event import addEvent, fireEvent +from couchpotato.core.helpers.variable import getImdb from couchpotato.core.logger import CPLog from couchpotato.core.plugins.base import Plugin from urlparse import urlparse @@ -42,7 +43,11 @@ class UserscriptBase(Plugin): return def getMovie(self, url): - return None + data = self.urlopen(url) + return self.getInfo(getImdb(data)) + + def getInfo(self, identifier): + return fireEvent('movie.info', identifier = identifier, merge = True) def getInclude(self): return self.includes diff --git a/couchpotato/core/providers/userscript/imdb/main.py b/couchpotato/core/providers/userscript/imdb/main.py index 85296d3e..06f6f162 100644 --- a/couchpotato/core/providers/userscript/imdb/main.py +++ b/couchpotato/core/providers/userscript/imdb/main.py @@ -21,6 +21,4 @@ class IMDB(UserscriptBase): return 'IMDB url is a TV Show' identifier = re.search('(?Ptt[0-9{7}]+)', url).group('id') - movie = fireEvent('movie.info', identifier = identifier, merge = True) - - return movie + return fireEvent('movie.info', identifier = identifier, merge = True) diff --git a/couchpotato/core/providers/userscript/moviemeter/main.py b/couchpotato/core/providers/userscript/moviemeter/main.py index f5ecb898..3593d432 100644 --- a/couchpotato/core/providers/userscript/moviemeter/main.py +++ b/couchpotato/core/providers/userscript/moviemeter/main.py @@ -4,38 +4,3 @@ 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; -# -#})(); diff --git a/couchpotato/core/providers/userscript/sharethe/main.py b/couchpotato/core/providers/userscript/sharethe/main.py index 9320bf86..d22b67eb 100644 --- a/couchpotato/core/providers/userscript/sharethe/main.py +++ b/couchpotato/core/providers/userscript/sharethe/main.py @@ -4,37 +4,3 @@ 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; -# -#})(); diff --git a/couchpotato/core/providers/userscript/tmdb/main.py b/couchpotato/core/providers/userscript/tmdb/main.py index 90207c93..d58d8197 100644 --- a/couchpotato/core/providers/userscript/tmdb/main.py +++ b/couchpotato/core/providers/userscript/tmdb/main.py @@ -1,31 +1,13 @@ +from couchpotato.core.event import fireEvent from couchpotato.core.providers.userscript.base import UserscriptBase +import re 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; -# -#})(); + def getMovie(self, url): + match = re.search('(?P\d+)', url) + movie = fireEvent('movie.info_by_tmdb', id = match.group('id'), merge = True) + return self.getInfo(movie['imdb']) diff --git a/couchpotato/core/providers/userscript/trakt/main.py b/couchpotato/core/providers/userscript/trakt/main.py index 3c0570b9..43e06dee 100644 --- a/couchpotato/core/providers/userscript/trakt/main.py +++ b/couchpotato/core/providers/userscript/trakt/main.py @@ -5,33 +5,3 @@ 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; -# -#})(); diff --git a/couchpotato/core/providers/userscript/whiwa/main.py b/couchpotato/core/providers/userscript/whiwa/main.py index 86617e0f..40ffa2a9 100644 --- a/couchpotato/core/providers/userscript/whiwa/main.py +++ b/couchpotato/core/providers/userscript/whiwa/main.py @@ -4,38 +4,3 @@ 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; -# -#})();