diff --git a/couchpotato/core/providers/userscript/allocine/main.py b/couchpotato/core/providers/userscript/allocine/main.py index 84afee18..5fe0cb02 100644 --- a/couchpotato/core/providers/userscript/allocine/main.py +++ b/couchpotato/core/providers/userscript/allocine/main.py @@ -1,34 +1,27 @@ +from beautifulsoup import BeautifulSoup +from couchpotato.core.event import fireEvent 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; -# -#})(); + def getMovie(self, url): + + if not 'fichefilm_gen_cfilm' in url: + return 'Url isn\'t from a movie' + + data = self.urlopen(url) + + html = BeautifulSoup(data) + title = html.find('title').contents[0].strip() + split = title.split(') - ') + + name = split[0][:-5].strip() + year = split[0][-4:] + + result = self.search(name, year) + if result: + movie = fireEvent('movie.info', identifier = result.get('imdb'), merge = True) + + return movie diff --git a/couchpotato/core/providers/userscript/appletrailers/main.py b/couchpotato/core/providers/userscript/appletrailers/main.py index 88f9f047..a138fd01 100644 --- a/couchpotato/core/providers/userscript/appletrailers/main.py +++ b/couchpotato/core/providers/userscript/appletrailers/main.py @@ -1,29 +1,24 @@ +from couchpotato.core.event import fireEvent from couchpotato.core.providers.userscript.base import UserscriptBase +import re 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; -# -#})(); + def getMovie(self, url): + + data = self.urlopen(url) + + name = re.search('(?P(var trailerTitle(.+);))', data) + name = name.group('id').split(' = \'')[1].strip()[:-2].decode('string_escape') + + date = re.search('(?P(var releaseDate(.+);))', data) + year = date.group('id').split(' = \'')[1].strip()[:-2] + + result = self.search(name, year) + if result: + movie = fireEvent('movie.info', identifier = result.get('imdb'), merge = True) + + return movie diff --git a/couchpotato/core/providers/userscript/base.py b/couchpotato/core/providers/userscript/base.py index 10ca6edf..eb2434aa 100644 --- a/couchpotato/core/providers/userscript/base.py +++ b/couchpotato/core/providers/userscript/base.py @@ -21,8 +21,12 @@ class UserscriptBase(Plugin): addEvent('userscript.get_movie_via_url', self.belongsTo) def search(self, name, year = None): - movie = fireEvent('movie.search', q = '%s %s' % (name, year), limit = 1) - return movie + movie = fireEvent('movie.search', q = '%s %s' % (name, year), limit = 1, merge = True) + + if len(movie) > 0: + return movie[0] + else: + return None def belongsTo(self, url):