1
# -*- coding: utf-8 -*-
5
# Copyright (c) 2010-2015 Enrico Carlesso
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
27
plugin_name = 'IMDb-IT'
28
plugin_description = 'Internet Movie Database in Italiano'
29
plugin_url = 'italian.imdb.com'
30
plugin_language = _('Italian')
31
plugin_author = 'Enrico Carlesso'
32
plugin_author_email = 'enrico@ecarlesso.org'
33
plugin_version = '0.1'
35
class Plugin(movie.Movie):
36
def __init__(self, id):
37
self.encode = 'iso8859-1'
39
self.url = "http://italian.imdb.com/title/tt%s" % self.movie_id
40
self.o_url = "http://imdb.com/title/tt%s" % self.movie_id
43
self.cast_page = self.open_page(url=self.url + '/fullcredits')
44
self.plot_page = self.open_page(url=self.url + '/plotsummary')
45
self.o_page = self.open_page(url=self.o_url)
48
tmp = string.find(self.page, 'a name="poster"')
49
if tmp == -1: # poster not available
52
self.image_url = gutils.trim(self.page[tmp:], 'src="', '"')
54
def get_o_title(self):
55
self.o_title = gutils.regextrim(self.o_page, '<h1>', '([ ]|[&][#][0-9]+[;])<span')
56
if self.o_title == '':
57
self.o_title = re.sub('[(].*', '', gutils.trim(self.o_page, '<title>', '</title>'))
59
def get_title(self): # same as get_o_title()
60
self.title = gutils.regextrim(self.page, '<h1>', '([ ]|[&][#][0-9]+[;])<span')
62
self.title = re.sub('[(].*', '', gutils.trim(self.page, '<title>', '</title>'))
64
def get_director(self):
66
parts = re.split('<a href=', gutils.trim(self.cast_page, '>Regia di<', '</table>'))
68
for part in parts[1:]:
69
director = gutils.trim(part, '>', '<')
70
self.director = self.director + director + ', '
71
self.director = self.director[0:len(self.director) - 2]
74
self.plot = gutils.regextrim(self.page, '<h5>Plot:</h5>', '(</div>|<a href.*)')
75
self.plot = self.__before_more(self.plot)
76
elements = string.split(self.plot_page, '<p class="plotpar">')
78
self.plot = self.plot + '\n\n'
80
for element in elements:
82
self.plot = self.plot + gutils.strip_tags(gutils.before(element, '</a>')) + '\n\n'
85
self.year = gutils.trim(self.o_page, '<a href="/Sections/Years/', '</a>')
86
self.year = gutils.after(self.year, '">')
88
def get_runtime(self):
89
self.runtime = gutils.trim(self.page, '<h5>Durata:</h5>', ' min')
92
self.genre = gutils.trim(self.page, '<h5>Genere:</h5>', '</div>')
93
self.genre = self.__before_more(self.genre)
97
self.cast = gutils.trim(self.cast_page, '<table class="cast">', '</table>')
99
self.cast = gutils.trim(self.page, '<table class="cast">', '</table>')
100
self.cast = string.replace(self.cast, ' ... ', _(' as '))
101
self.cast = string.replace(self.cast, '...', _(' as '))
102
self.cast = string.replace(self.cast, '</tr><tr>', "\n")
103
self.cast = re.sub('</tr>[ \t]*<tr[ \t]*class="even">', "\n", self.cast)
104
self.cast = re.sub('</tr>[ \t]*<tr[ \t]*class="odd">', "\n", self.cast)
105
self.cast = self.__before_more(self.cast)
107
def get_classification(self):
108
self.classification = gutils.trim(self.page, '<h5><a href="/mpaa">MPAA</a>:</h5>', '</div>')
109
self.classification = gutils.trim(self.classification, 'Rated ', ' ')
111
def get_studio(self):
112
self.studio = gutils.trim(self.page, '<h5>Compagnia:</h5>', '</a>')
114
def get_o_site(self):
118
self.site = "http://italian.imdb.com/title/tt%s" % self.movie_id
120
def get_trailer(self):
121
self.trailer = "http://italian.imdb.com/title/tt%s/trailers" % self.movie_id
123
def get_country(self):
124
self.country = gutils.trim(self.page, '<h5>Nazionalità:</h5>', '</div>')
125
self.country = re.sub('[\n]+', '', self.country)
127
def get_rating(self):
128
pattern = re.compile('>([0-9]([.][0-9])*)[/][0-9][0-9]<')
129
result = pattern.search(self.o_page)
131
self.rating = result.groups()[0]
134
self.rating = round(float(self.rating), 0)
142
language = gutils.trim(self.page, '<h5>Lingua:</h5>', '</div>')
143
language = gutils.strip_tags(language)
144
language = re.sub('[\n]+', '', language)
145
language = re.sub('[ ]+', ' ', language)
146
language = language.rstrip()
147
color = gutils.trim(self.page, '<h5>Colore:</h5>', '</div>')
148
color = gutils.strip_tags(color)
149
color = re.sub('[\n]+', '', color)
150
color = re.sub('[ ]+', ' ', color)
151
color = color.rstrip()
152
sound = gutils.trim(self.page, '<h5>Sonoro:</h5>', '</div>')
153
sound = gutils.strip_tags(sound)
154
sound = re.sub('[\n]+', '', sound)
155
sound = re.sub('[ ]+', ' ', sound)
156
sound = sound.rstrip()
157
tagline = gutils.trim(self.page, '<h5>Trama:</h5>', '</div>')
158
tagline = self.__before_more(tagline)
159
tagline = gutils.strip_tags(tagline)
160
tagline = re.sub('[\n]+', '', tagline)
161
tagline = re.sub('[ ]+', ' ', tagline)
162
tagline = tagline.rstrip()
164
self.notes = "%s: %s\n" %(_('Language'), language)
166
self.notes += "%s: %s\n" %(gutils.strip_tags(_('<b>Audio</b>')), sound)
168
self.notes += "%s: %s\n" %(_('Color'), color)
169
if len(tagline)>0 and tagline != "Aggiungi o traduci un riassunto della trama":
170
self.notes += "%s: %s\n" %('Tagline', tagline)
172
def get_screenplay(self):
174
parts = re.split('<a href=', gutils.trim(self.cast_page, '>Scritto da<', '</table>'))
176
for part in parts[1:]:
177
screenplay = gutils.trim(part, '>', '<')
178
if screenplay == 'WGA':
180
screenplay = screenplay.replace(' (scritto da)', '')
181
screenplay = screenplay.replace(' e<', '<')
182
self.screenplay = self.screenplay + screenplay + ', '
183
if len(self.screenplay) > 2:
184
self.screenplay = self.screenplay[0:len(self.screenplay) - 2]
186
def get_cameraman(self):
189
def __before_more(self, data):
190
tmp = string.find(data, '>ancora<')
192
data = data[:tmp] + '>'
195
class SearchPlugin(movie.SearchMovie):
196
PATTERN = re.compile(r"""<A HREF=['"]/title/tt([0-9]+)/["']>(.*?)</LI>""")
197
PATTERN2 = re.compile(r"""<a href=['"]/title/tt([0-9]+)/["'](.*?)</tr>""")
200
self.original_url_search = 'http://italian.imdb.com/find?s=tt;q='
201
self.translated_url_search = 'http://italian.imdb.com/find?s=tt;q='
202
self.encode = 'iso8859-1'
204
def search(self, parent_window):
205
if not self.open_search(parent_window):
207
tmp_page = gutils.trim(self.page, 'Titoli popolari', '</table>')
209
has_results = re.match('[(]Visualizza [1-9][0-7]* risultat[io]*[)]', self.page)
211
# nothing or one result found, try another url which looks deeper in the imdb database
212
# example: Adventures of Falcon -> one result, jumps directly to the movie page
213
# which isn't supported by this plugin
214
self.url = 'http://italian.imdb.com/find?more=tt;q='
215
if not self.open_search(parent_window):
217
self.page = gutils.trim(self.page, '(Visualizza', '>Suggerimenti per migliorare i tuoi risultati<')
220
self.page = self.page.decode('iso-8859-1')
221
# correction of all &#xxx entities
222
self.page = gutils.convert_entities(self.page)
225
def get_searches(self):
226
elements = re.split('<LI>', self.page)
227
if len(elements) < 2:
228
elements = string.split(self.page, '<tr>')
230
for element in elements[1:]:
231
match = self.PATTERN2.findall(element)
233
tmp = re.sub('^[0-9]+[.]', '', gutils.clean(gutils.after(match[0][1], '>')))
234
self.ids.append(match[0][0])
235
self.titles.append(tmp)
237
for element in elements[1:]:
238
match = self.PATTERN.findall(element)
240
tmp = gutils.clean(match[0][1])
241
self.ids.append(match[0][0])
242
self.titles.append(tmp)