~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/PluginMovieMyMoviesIt.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: PluginMovieMyMoviesIt.py 1391 2010-01-09 21:54:24Z piotrek $'
4
 
 
5
 
# Copyright (c) 2007
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
 
from gettext import gettext as _
25
 
import gutils
26
 
import movie
27
 
import string
28
 
import re
29
 
 
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"
37
 
 
38
 
class Plugin(movie.Movie):
39
 
 
40
 
    def __init__(self, id):
41
 
        self.encode = 'iso-8859-1'
42
 
        self.movie_id = id
43
 
        self.url = "http://www.mymovies.it/dizionario/recensione.asp?id=%s" % self.movie_id
44
 
 
45
 
    def get_image(self):
46
 
        tmp_image = string.find(self.page, '<img style="float:left; border:solid 1px gray; padding:3px; margin:5px;" src="')
47
 
        if tmp_image == -1:
48
 
            self.image_url = ''
49
 
        else:
50
 
            self.image_url = gutils.trim(self.page[tmp_image:], 'src="', '"')
51
 
 
52
 
    def get_o_title(self):
53
 
        tmp = gutils.trim(self.page, 'Titolo originale <em>', '</em>')
54
 
        if not tmp:
55
 
            self.o_title = gutils.trim(self.page, '<h1 style="margin-bottom:3px;">', '</h1>')
56
 
        else:
57
 
            self.o_title = tmp
58
 
 
59
 
    def get_title(self):
60
 
        self.title = gutils.trim(self.page, '<h1 style="margin-bottom:3px;">', '</h1>')
61
 
 
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,'>')
66
 
        if not 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 ','<')
70
 
 
71
 
    def get_plot(self):
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>')
76
 
 
77
 
    def get_year(self):
78
 
        self.year = gutils.regextrim(self.page,'<strong> <a title="Film [0-9]+" href="http://www.mymovies.it/film/[0-9]+/">', '</a></strong>')
79
 
 
80
 
    def get_runtime(self):
81
 
        self.runtime = gutils.trim(self.page, 'durata ', ' min.')
82
 
 
83
 
    def get_genre(self):
84
 
        self.genre = gutils.regextrim(self.page,'<a title="Film [a-zA-Z]+" href="http://www.mymovies.it/film/[a-zA-Z]+/">', '</a>')
85
 
 
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')
90
 
 
91
 
    def get_classification(self):
92
 
        self.classification = ''
93
 
 
94
 
    def get_studio(self):
95
 
        self.studio = ''
96
 
 
97
 
    def get_o_site(self):
98
 
        self.o_site = ''
99
 
        #tmp = gutils.trim(self.page, 'http://www.imdb.com', '"')
100
 
        #if tmp != '':
101
 
        #    self.o_site = 'http://www.imdb.com' + tmp
102
 
 
103
 
    def get_site(self):
104
 
        self.site = self.url
105
 
 
106
 
    def get_trailer(self):
107
 
        self.trailer = "http://www.mymovies.it/trailer/?id=%s" % self.movie_id
108
 
 
109
 
    def get_country(self):
110
 
        pos = string.find(self.page, ' min.')
111
 
        self.country = gutils.trim(self.page[pos+2:], '- ', '  <')
112
 
 
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>')
115
 
        if rat != '':
116
 
            self.rating = int(round(float(rat.replace(',', '.'))*2, 0))
117
 
        else:
118
 
            self.rating = 0
119
 
 
120
 
    def get_notes(self):
121
 
        #self.notes = ''
122
 
        #tmp = gutils.trim(self.page, 'Alt. titel:', '</span>')
123
 
        #if tmp:
124
 
        #    self.notes = self.notes + 'Alt. titel:' + string.strip(gutils.strip_tags(tmp))
125
 
        self.notes = ''
126
 
 
127
 
class SearchPlugin(movie.SearchMovie):
128
 
 
129
 
    def __init__(self):
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'
133
 
 
134
 
    def search(self,parent_window):
135
 
        if not self.open_search(parent_window):
136
 
            return None
137
 
        #self.sub_search()
138
 
        return self.page
139
 
 
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")
142
 
 
143
 
    def get_searches(self):
144
 
        elements = string.split(self.page,"<h3 style=\"margin:0px;\">")
145
 
        self.number_results = len(elements) - 1
146
 
 
147
 
        if self.number_results > 0:
148
 
            i = 1
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="', '"')))
154
 
 
155
 
                self.ids.append(gutils.trim(element,"recensione.asp?id=","\""))
156
 
                self.titles.append(gutils.convert_entities(gutils.strip_tags(gutils.trim(element,'" title="', '"'))))
157
 
                i += 1
158
 
        else:
159
 
            self.number_results = 0
160
 
 
161
 
#
162
 
# Plugin Test
163
 
#
164
 
class SearchPluginTest(SearchPlugin):
165
 
    #
166
 
    # Configuration for automated tests:
167
 
    # dict { movie_id -> expected result count }
168
 
    #
169
 
    test_configuration = {
170
 
        'Rocky Balboa'            : 1
171
 
    }
172
 
 
173
 
class PluginTest:
174
 
    #
175
 
    # Configuration for automated tests:
176
 
    # dict { movie_id -> dict { arribute -> value } }
177
 
    #
178
 
    # value: * True/False if attribute should only be tested for any value
179
 
    #        * or the expected value
180
 
    #
181
 
    test_configuration = {
182
 
        '44566' : {
183
 
            'title'             : 'Rocky Balboa',
184
 
            'o_title'             : 'Rocky Balboa',
185
 
            'director'            : 'Sylvester Stallone',
186
 
            'genre'                : 'Sportivo',
187
 
            'year'                : 2006
188
 
        }
189
 
    }