1
# -*- coding: UTF-8 -*-
3
__revision__ = '$Id: PluginMovieMyMoviesIt.py 1391 2010-01-09 21:54:24Z piotrek $'
7
# This program is free software; you can redistribute it and/or modify
8
# it under the terms of the GNU General Public License as published by
9
# the Free Software Foundation; either version 2 of the License, or
10
# (at your option) any later version.
12
# This program is distributed in the hope that it will be useful,
13
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU Library General Public License for more details.
17
# You should have received a copy of the GNU General Public License
18
# along with this program; if not, write to the Free Software
19
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
21
# You may use and distribute this software under the terms of the
22
# GNU General Public License, version 2 or later
24
from gettext import gettext as _
30
plugin_name = "MyMoviesIt"
31
plugin_description = "mymovies.it"
32
plugin_url = "www.mymovies.it"
33
plugin_language = _("Italian")
34
plugin_author = "Giovanni Sposito, Filippo Valsorda"
35
plugin_author_email = "<giovanni.sposito@gmail.com>, <filosottile.wiki@gmail.com>"
36
plugin_version = "0.2"
38
class Plugin(movie.Movie):
40
def __init__(self, id):
41
self.encode = 'iso-8859-1'
43
self.url = "http://www.mymovies.it/dizionario/recensione.asp?id=%s" % self.movie_id
46
tmp_image = string.find(self.page, '<img style="float:left; border:solid 1px gray; padding:3px; margin:5px;" src="')
50
self.image_url = gutils.trim(self.page[tmp_image:], 'src="', '"')
52
def get_o_title(self):
53
tmp = gutils.trim(self.page, 'Titolo originale <em>', '</em>')
55
self.o_title = gutils.trim(self.page, '<h1 style="margin-bottom:3px;">', '</h1>')
60
self.title = gutils.trim(self.page, '<h1 style="margin-bottom:3px;">', '</h1>')
62
def get_director(self):
63
pos_iniziale = string.find(self.page, '<div style="text-align:left" class="linkblu">')
64
self.director = gutils.trim(self.page[pos_iniziale:],'Un film di <a','</a>')
65
self.director = gutils.after(self.director,'>')
67
self.director = gutils.trim(self.page[pos_iniziale:], 'Un film di ', 'Con')
68
if len(self.director) > 25:
69
self.director = gutils.trim(self.page[pos_iniziale:],'Un film di ','<')
72
pos_iniziale = string.find(self.page, '<div id="recensione">')
73
self.plot = gutils.trim(self.page[pos_iniziale:],'<p>','</p>')
74
if '</a>' in self.plot:
75
self.plot = gutils.after(self.plot, '</a>')
78
self.year = gutils.regextrim(self.page,'<strong> <a title="Film [0-9]+" href="http://www.mymovies.it/film/[0-9]+/">', '</a></strong>')
80
def get_runtime(self):
81
self.runtime = gutils.trim(self.page, 'durata ', ' min.')
84
self.genre = gutils.regextrim(self.page,'<a title="Film [a-zA-Z]+" href="http://www.mymovies.it/film/[a-zA-Z]+/">', '</a>')
86
def get_cast(self): # TODO
87
tmp = string.find(self.page, 'Con <a')
88
self.cast = gutils.trim(self.page[tmp:],'Con ','</a>.')
89
self.cast = string.replace(self.cast, ',', '\n')
91
def get_classification(self):
92
self.classification = ''
99
#tmp = gutils.trim(self.page, 'http://www.imdb.com', '"')
101
# self.o_site = 'http://www.imdb.com' + tmp
106
def get_trailer(self):
107
self.trailer = "http://www.mymovies.it/trailer/?id=%s" % self.movie_id
109
def get_country(self):
110
pos = string.find(self.page, ' min.')
111
self.country = gutils.trim(self.page[pos+2:], '- ', ' <')
113
def get_rating(self):
114
rat = gutils.trim(self.page, '<div style="text-align:center; font-size:23px; font-weight:bold; letter-spacing:1px; margin:0px 11px 7px 11px">', '<span style="font-size:11px">/5</span></div>')
116
self.rating = int(round(float(rat.replace(',', '.'))*2, 0))
122
#tmp = gutils.trim(self.page, 'Alt. titel:', '</span>')
124
# self.notes = self.notes + 'Alt. titel:' + string.strip(gutils.strip_tags(tmp))
127
class SearchPlugin(movie.SearchMovie):
130
self.original_url_search = "http://www.mymovies.it/database/ricerca/?q="
131
self.translated_url_search = "http://www.mymovies.it/database/ricerca/?q="
132
self.encode = 'iso-8859-1'
134
def search(self,parent_window):
135
if not self.open_search(parent_window):
140
def sub_search(self):
141
self.page = gutils.trim(self.page, "ho trovato i seguenti risultati:", "Altri risultati tra i film con la parola")
143
def get_searches(self):
144
elements = string.split(self.page,"<h3 style=\"margin:0px;\">")
145
self.number_results = len(elements) - 1
147
if self.number_results > 0:
149
while i < len(elements):
150
element = gutils.trim(elements[i],"<a","</a>")
151
# print "******* elemento "+str(i)+" **********\n\n\n\n\n"+element+"\n******fine*******\n\n\n\n\n\n"
152
# print "id = "+gutils.trim(element,"recensione.asp?id=","\"")
153
# print "title = "+gutils.convert_entities(gutils.strip_tags(gutils.trim(element,'" title="', '"')))
155
self.ids.append(gutils.trim(element,"recensione.asp?id=","\""))
156
self.titles.append(gutils.convert_entities(gutils.strip_tags(gutils.trim(element,'" title="', '"'))))
159
self.number_results = 0
164
class SearchPluginTest(SearchPlugin):
166
# Configuration for automated tests:
167
# dict { movie_id -> expected result count }
169
test_configuration = {
175
# Configuration for automated tests:
176
# dict { movie_id -> dict { arribute -> value } }
178
# value: * True/False if attribute should only be tested for any value
179
# * or the expected value
181
test_configuration = {
183
'title' : 'Rocky Balboa',
184
'o_title' : 'Rocky Balboa',
185
'director' : 'Sylvester Stallone',
186
'genre' : 'Sportivo',