1# -*- coding: UTF-8 -*- 2 3# $Id$ 4 5# Copyright (c) 2005-2009 Vasco Nunes 6# You may use and distribute this software under the terms of the 7# GNU General Public License, version 2 or later 8 9import gutils 10import movie,string,re 11 12plugin_name = "Moviefone" 13plugin_description = "A Service of America Online" 14plugin_url = "www.moviefone.de" 15plugin_language = _("English") 16plugin_author = "Vasco Nunes" 17plugin_version = "0.4" 18 19class Plugin(movie.Movie): 20 BASEURL = "http://www.moviefone.com/movie/%s" 21 22 def __init__(self, id): 23 self.movie_id = id 24 self.url = self.BASEURL % self.movie_id + '/main' 25 26 def initialize(self): 27 self.page_main = self.page 28 self.page_synopsis = self.open_page(self.parent_window, url = self.BASEURL % self.movie_id + '/synopsis') 29 self.page_cast = self.open_page(self.parent_window, url = self.BASEURL % self.movie_id + '/credits') 30 31 def get_image(self): 32 self.image_url = gutils.trim(self.page_main, 'http://www.aolcdn.com/mf_movies/', '"') 33 self.image_url = 'http://www.aolcdn.com/mf_movies/' + self.image_url 34 35 def get_o_title(self): 36 self.o_title = gutils.trim(self.page_main, '<h1>', '</h1>') 37 38 def get_title(self): 39 self.title = gutils.trim(self.page_main, '<h1>', '</h1>') 40 41 def get_director(self): 42 self.director = gutils.trim(self.page_main, '<dt>Director(s)</dt>', '</dl>') 43 self.director = gutils.strip_tags(self.director.replace('</dd>', ',')) 44 self.director = re.sub(',[ ]*$', '', self.director) 45 46 def get_plot(self): 47 self.plot = gutils.trim(self.page_synopsis, '<h3>Synopsis</h3>', '</p>') 48 self.plot = string.strip(gutils.strip_tags(self.plot)) 49 50 def get_year(self): 51 self.year = gutils.trim(self.page_synopsis, 'Theatrical Release Date:', '<div class="row') 52 self.year = string.strip(gutils.strip_tags(self.year)) 53 self.year = re.sub('[0-9][0-9]/[0-9][0-9]/', '', self.year) 54 55 def get_runtime(self): 56 self.runtime = string.strip(gutils.strip_tags(gutils.regextrim(self.page_main, '<dt>Runtime</dt>', ' min[. ]*</dd>'))) 57 58 def get_genre(self): 59 self.genre = gutils.trim(self.page_synopsis, 'Genre(s):', '<div class="row') 60 self.genre = gutils.strip_tags(self.genre) 61 62 def get_cast(self): 63 self.cast = '' 64 tmp = re.split('(?:[<]div[ \t]+class="name"[>])', self.page_cast) 65 for index in range(1, len(tmp), 1): 66 entry = tmp[index] 67 if string.find(entry, '<h3>Director</h3>') >= 0 or string.find(entry, '<h3>Producer</h3>') >= 0 or string.find(entry, '<h3>Writer</h3>') >= 0: 68 break 69 name = string.strip(gutils.strip_tags(gutils.before(entry, '</div>'))) 70 role = string.strip(gutils.strip_tags(gutils.trim(entry, '<div class="role">', '</div>'))) 71 if role: 72 self.cast = self.cast + name + _(' as ') + role + '\n' 73 else: 74 self.cast = self.cast + name + '\n' 75 76 def get_classification(self): 77 self.classification = gutils.trim(self.page_synopsis, 'Rating:', '<div class="row') 78 self.classification = gutils.strip_tags(self.classification) 79 80 def get_studio(self): 81 self.studio = gutils.trim(self.page_synopsis, 'Production Co.:', '<div class="row') 82 self.studio = gutils.strip_tags(self.studio) 83 84 def get_o_site(self): 85 self.o_site = "" 86 87 def get_site(self): 88 self.site = self.url 89 90 def get_trailer(self): 91 self.trailer = '' 92 93 def get_country(self): 94 self.country = gutils.trim(self.page_synopsis, 'Country of Origin:', '<div class="row') 95 self.country = gutils.strip_tags(self.country) 96 97 def get_rating(self): 98 self.rating = '0' 99 tmp = gutils.trim(self.page_main, '<dt>Critics Say</dt>', '</dd>') 100 parts = re.split('(starAvg3)', tmp) 101 if parts and len(parts): 102 self.rating = len(parts) - 1 103 104class SearchPlugin(movie.SearchMovie): 105 PATTERN = re.compile('<a[ \t]+href="/movie/([^/]+/[0-9]+)/main"[ \t]+class="title">([^<]+)(?:[^(]+)[(]([0-9]+)[)]') 106 SUBPAGE_PATTERN = re.compile('(?:movies[?]subCategory=&restrictToCategory=&page=)([0-9]+)') 107 108 def __init__(self): 109 self.original_url_search = "http://www.moviefone.com/search/%s/movies"; 110 self.translated_url_search = "http://www.moviefone.com/search/%s/movies"; 111 112 def search(self,parent_window): 113 if not self.open_search(parent_window): 114 return None 115 subpages = self.SUBPAGE_PATTERN.split(self.page) 116 if len(subpages) > 4: 117 maxsubpage = subpages[len(subpages) - 4] 118 completepage = self.page 119 try: 120 for subpage in range(1, int(maxsubpage) + 1, 1): 121 self.url = "http://www.moviefone.com/search/%s/movies?subCategory=&restrictToCategory=&page=" + str(subpage) 122 if not self.open_search(parent_window): 123 return None 124 completepage = completepage + self.page 125 finally: 126 self.page = completepage 127 return self.page 128 129 def get_searches(self): 130 elements = self.PATTERN.split(self.page) 131 132 for index in range(1, len(elements), 4): 133 id = elements[index] 134 title = elements[index + 1] 135 year = elements[index + 2] 136 self.ids.append(id) 137 self.titles.append(title + ' (' + year + ')') 138