~ubuntu-branches/ubuntu/quantal/griffith/quantal

« back to all changes in this revision

Viewing changes to .pc/debian-changes-0.12.1-2/lib/plugins/movie/PluginMovieIMDB-it.py

  • Committer: Package Import Robot
  • Author(s): Piotr Ożarowski
  • Date: 2011-12-18 21:15:25 UTC
  • mfrom: (1.1.17) (3.1.11 sid)
  • Revision ID: package-import@ubuntu.com-20111218211525-endbgt82m3jh9gde
Tags: 0.13-1
* New upstream release
* VCS-* fields removed (berlios will be shutdown)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# -*- coding: utf-8 -*-
2
 
 
3
 
__revision__ = '$Id$'
4
 
 
5
 
# Copyright (c) 2010-2015 Enrico Carlesso
6
 
#
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.
11
 
#
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.
16
 
#
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
20
 
 
21
 
# You may use and distribute this software under the terms of the
22
 
# GNU General Public License, version 2 or later
23
 
 
24
 
import gutils, movie
25
 
import string, re
26
 
 
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'
34
 
 
35
 
class Plugin(movie.Movie):
36
 
    def __init__(self, id):
37
 
        self.encode   = 'iso8859-1'
38
 
        self.movie_id = id
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
41
 
 
42
 
    def initialize(self):
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)
46
 
 
47
 
    def get_image(self):
48
 
        tmp = string.find(self.page, 'a name="poster"')
49
 
        if tmp == -1:        # poster not available
50
 
            self.image_url = ''
51
 
        else:
52
 
            self.image_url = gutils.trim(self.page[tmp:], 'src="', '"')
53
 
 
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>'))
58
 
 
59
 
    def get_title(self):    # same as get_o_title()
60
 
        self.title = gutils.regextrim(self.page, '<h1>', '([ ]|[&][#][0-9]+[;])<span')
61
 
        if self.title == '':
62
 
            self.title = re.sub('[(].*', '', gutils.trim(self.page, '<title>', '</title>'))
63
 
 
64
 
    def get_director(self):
65
 
        self.director = ''
66
 
        parts = re.split('<a href=', gutils.trim(self.cast_page, '>Regia di<', '</table>'))
67
 
        if len(parts) > 1:
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]
72
 
 
73
 
    def get_plot(self):
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">')
77
 
        if len(elements) > 1:
78
 
            self.plot = self.plot + '\n\n'
79
 
            elements[0] = ''
80
 
            for element in elements:
81
 
                if element <> '':
82
 
                    self.plot = self.plot + gutils.strip_tags(gutils.before(element, '</a>')) + '\n\n'
83
 
 
84
 
    def get_year(self):
85
 
        self.year = gutils.trim(self.o_page, '<a href="/Sections/Years/', '</a>')
86
 
        self.year = gutils.after(self.year, '">')
87
 
 
88
 
    def get_runtime(self):
89
 
        self.runtime = gutils.trim(self.page, '<h5>Durata:</h5>', ' min')
90
 
 
91
 
    def get_genre(self):
92
 
        self.genre = gutils.trim(self.page, '<h5>Genere:</h5>', '</div>')
93
 
        self.genre = self.__before_more(self.genre)
94
 
 
95
 
    def get_cast(self):
96
 
        self.cast = ''
97
 
        self.cast = gutils.trim(self.cast_page, '<table class="cast">', '</table>')
98
 
        if self.cast == '':
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)
106
 
 
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 ', ' ')
110
 
 
111
 
    def get_studio(self):
112
 
        self.studio = gutils.trim(self.page, '<h5>Compagnia:</h5>', '</a>')
113
 
 
114
 
    def get_o_site(self):
115
 
        self.o_site = ''
116
 
 
117
 
    def get_site(self):
118
 
        self.site = "http://italian.imdb.com/title/tt%s" % self.movie_id
119
 
 
120
 
    def get_trailer(self):
121
 
        self.trailer = "http://italian.imdb.com/title/tt%s/trailers" % self.movie_id
122
 
 
123
 
    def get_country(self):
124
 
        self.country = gutils.trim(self.page, '<h5>Nazionalità:</h5>', '</div>')
125
 
        self.country = re.sub('[\n]+', '', self.country)
126
 
 
127
 
    def get_rating(self):
128
 
        pattern = re.compile('>([0-9]([.][0-9])*)[/][0-9][0-9]<')
129
 
        result = pattern.search(self.o_page)
130
 
        if result:
131
 
            self.rating = result.groups()[0]
132
 
            if self.rating:
133
 
                try:
134
 
                    self.rating = round(float(self.rating), 0)
135
 
                except Exception, e:
136
 
                    self.rating = 0
137
 
        else:
138
 
            self.rating = 0
139
 
 
140
 
    def get_notes(self):
141
 
        self.notes = ''
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()
163
 
        if len(language)>0:
164
 
            self.notes = "%s: %s\n" %(_('Language'), language)
165
 
        if len(sound)>0:
166
 
            self.notes += "%s: %s\n" %(gutils.strip_tags(_('<b>Audio</b>')), sound)
167
 
        if len(color)>0:
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)
171
 
 
172
 
    def get_screenplay(self):
173
 
        self.screenplay = ''
174
 
        parts = re.split('<a href=', gutils.trim(self.cast_page, '>Scritto da<', '</table>'))
175
 
        if len(parts) > 1:
176
 
            for part in parts[1:]:
177
 
                screenplay = gutils.trim(part, '>', '<')
178
 
                if screenplay == 'WGA':
179
 
                    continue
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]
185
 
 
186
 
    def get_cameraman(self):
187
 
        self.cameraman = ''
188
 
 
189
 
    def __before_more(self, data):
190
 
        tmp = string.find(data, '>ancora<')
191
 
        if tmp > 0:
192
 
            data = data[:tmp] + '>'
193
 
        return data
194
 
 
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>""")
198
 
 
199
 
    def __init__(self):
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'
203
 
 
204
 
    def search(self, parent_window):
205
 
        if not self.open_search(parent_window):
206
 
            return None
207
 
        tmp_page = gutils.trim(self.page, 'Titoli popolari', '</table>')
208
 
        if not tmp_page:
209
 
            has_results = re.match('[(]Visualizza [1-9][0-7]* risultat[io]*[)]', self.page)
210
 
            if not has_results:
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):
216
 
                    return None
217
 
            self.page = gutils.trim(self.page, '(Visualizza', '>Suggerimenti per migliorare i tuoi risultati<')
218
 
        else:
219
 
            self.page = tmp_page
220
 
        self.page = self.page.decode('iso-8859-1')
221
 
        # correction of all &#xxx entities
222
 
        self.page = gutils.convert_entities(self.page)
223
 
        return self.page
224
 
 
225
 
    def get_searches(self):
226
 
        elements = re.split('<LI>', self.page)
227
 
        if len(elements) < 2:
228
 
            elements = string.split(self.page, '<tr>')
229
 
            if len(elements):
230
 
                for element in elements[1:]:
231
 
                    match = self.PATTERN2.findall(element)
232
 
                    if len(match):
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)
236
 
        else:
237
 
            for element in elements[1:]:
238
 
                match = self.PATTERN.findall(element)
239
 
                if len(match):
240
 
                    tmp = gutils.clean(match[0][1])
241
 
                    self.ids.append(match[0][0])
242
 
                    self.titles.append(tmp)