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

« back to all changes in this revision

Viewing changes to lib/plugins/movie/PluginMovieAllRovi.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: PluginMovieAllRovi.py 1605 2011-12-18 22:35:25Z piotrek $'
 
4
 
 
5
# Copyright (c) 2009-2011
 
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
 
25
import movie
 
26
import string, re
 
27
 
 
28
plugin_name         = "rovi"
 
29
plugin_description  = "rovi"
 
30
plugin_url          = "www.allrovi.com"
 
31
plugin_language     = _("English")
 
32
plugin_author       = "Michael Jahn"
 
33
plugin_author_email = "griffith@griffith.cc"
 
34
plugin_version      = "2.0"
 
35
 
 
36
class Plugin(movie.Movie):
 
37
    def __init__(self, id):
 
38
        self.encode = 'utf-8'
 
39
        self.movie_id = id
 
40
        self.url = 'http://www.allrovi.com/movies/movie/' + str(self.movie_id)
 
41
 
 
42
    def initialize(self):
 
43
        self.page_cast = self.open_page(url = 'http://www.allrovi.com/movies/movie/' + str(self.movie_id) + '/cast_crew')
 
44
 
 
45
    def get_image(self):
 
46
        self.image_url = gutils.trim(self.page, '<img class="cover-art" src="', '"')
 
47
 
 
48
    def get_o_title(self):
 
49
        self.o_title = gutils.regextrim(self.page, '<div class="page-heading">', '(</div>|<span>)')
 
50
 
 
51
    def get_title(self):
 
52
        self.title = gutils.regextrim(self.page, '<div class="page-heading">', '(</div>|<span>)')
 
53
 
 
54
    def get_director(self):
 
55
        self.director = gutils.trim(self.page, '<dt>directed by</dt>', '</ul>')
 
56
 
 
57
    def get_plot(self):
 
58
        self.plot = gutils.trim(self.page, '>synopsis', '</p>')
 
59
 
 
60
    def get_year(self):
 
61
        self.year = gutils.after(gutils.trim(self.page, '<dt>release date</dt>', '</div>'), ',')
 
62
 
 
63
    def get_runtime(self):
 
64
        self.runtime = ''
 
65
 
 
66
    def get_genre(self):
 
67
        self.genre = gutils.trim(self.page, '<dt>genres</dt>', '</ul>')
 
68
 
 
69
    def get_cast(self):
 
70
        self.cast = ''
 
71
        tmp = gutils.trim(self.page_cast, '<h2>cast</h2>', '</table>')
 
72
        elements = string.split(tmp, '<td class="name">')
 
73
        for element in elements:
 
74
            element = string.replace(element, '</a>', '$$$')
 
75
            self.cast = self.cast + string.replace(re.sub('[$][$][$]$', '', re.sub('[ ]+', ' ', string.replace(gutils.clean(element), '\n', ''))), '$$$', _(' as ')) + '\n'
 
76
 
 
77
    def get_classification(self):
 
78
        self.classification = ''
 
79
 
 
80
    def get_studio(self):
 
81
        self.studio = gutils.regextrim(self.page, '<dt>produced by</dt>', '(</div>|<dt>)')
 
82
 
 
83
    def get_o_site(self):
 
84
        self.o_site = ''
 
85
 
 
86
    def get_site(self):
 
87
        self.site = self.url
 
88
 
 
89
    def get_trailer(self):
 
90
        self.trailer = ''
 
91
 
 
92
    def get_country(self):
 
93
        self.country = gutils.regextrim(self.page, '<dt>countries</dt>', '(</div>|<dt>)')
 
94
 
 
95
    def get_rating(self):
 
96
        self.rating = (len(string.split(gutils.trim(self.page, '<dt>rovi rating</dt>', '</div>'), '"star full"')) - 1) * 2
 
97
 
 
98
    def get_notes(self):
 
99
        self.notes = ''
 
100
 
 
101
    def get_cameraman(self):
 
102
        self.cameraman = ''
 
103
        tmp = gutils.trim(self.page_cast, '<h2>crew</h2>', '</dl>')
 
104
        elements = string.split(tmp, '<dt>')
 
105
        for element in elements:
 
106
            if string.find(element, 'Cinematographer') > 0:
 
107
                self.cameraman = gutils.clean(gutils.before(element, '</a>'))
 
108
 
 
109
    def get_screenplay(self):
 
110
        self.screenplay = ''
 
111
        tmp = gutils.trim(self.page_cast, '<h2>crew</h2>', '</dl>')
 
112
        elements = string.split(tmp, '<dt>')
 
113
        for element in elements:
 
114
            if string.find(element, 'Screenwriter') > 0:
 
115
                self.screenplay = gutils.clean(gutils.before(element, '</a>'))
 
116
 
 
117
    def get_barcode(self):
 
118
        self.barcode = ''
 
119
 
 
120
 
 
121
class SearchPlugin(movie.SearchMovie):
 
122
    def __init__(self):
 
123
        self.original_url_search = "http://www.allrovi.com/search/ajax_more_results/movies/%s/0/100"
 
124
        self.translated_url_search = "http://www.allrovi.com/search/ajax_more_results/movies/%s/0/100"
 
125
        self.encode = 'utf-8'
 
126
 
 
127
    def search(self,parent_window):
 
128
        if not self.open_search(parent_window):
 
129
            return None
 
130
        return self.page
 
131
 
 
132
    def get_searches(self):
 
133
        elements = re.split('<tr>', self.page)
 
134
        for index in range(1, len(elements), 1):
 
135
            element = elements[index]
 
136
            titleandid = gutils.trim(element, '<td class="title">', '</td>')
 
137
            title = gutils.clean(titleandid)
 
138
            id = gutils.trim(titleandid, 'href="', '"')
 
139
            idstart = string.rfind(id, '/')
 
140
            id = id[idstart + 1:]
 
141
            year = gutils.trim(element, '<td class="year">', '</td>')
 
142
            self.ids.append(id)
 
143
            self.titles.append(title + ' (' + gutils.clean(year)+ ')')
 
144
 
 
145
#
 
146
# Plugin Test
 
147
#
 
148
class SearchPluginTest(SearchPlugin):
 
149
    #
 
150
    # Configuration for automated tests:
 
151
    # dict { movie_id -> [ expected result count for original url, expected result count for translated url ] }
 
152
    #
 
153
    test_configuration = {
 
154
        'Rocky' : [ 57, 57 ],
 
155
    }
 
156
 
 
157
class PluginTest:
 
158
    #
 
159
    # Configuration for automated tests:
 
160
    # dict { movie_id -> dict { arribute -> value } }
 
161
    #
 
162
    # value: * True/False if attribute only should be tested for any value
 
163
    #        * or the expected value
 
164
    #
 
165
    test_configuration = {
 
166
        'rocky-balboa-v337682' : { 
 
167
            'title'               : 'Rocky Balboa',
 
168
            'o_title'             : 'Rocky Balboa',
 
169
            'director'            : 'Sylvester Stallone',
 
170
            'plot'                : True,
 
171
            'cast'                : 'Sylvester Stallone' + _(' as ') + ' Rocky Balboa\n\
 
172
Burt Young' + _(' as ') + ' Paulie\n\
 
173
Antonio Tarver' + _(' as ') + ' Mason "The Line" Dixon\n\
 
174
Geraldine Hughes' + _(' as ') + ' Marie\n\
 
175
Milo Ventimiglia' + _(' as ') + ' Rocky Balboa Jr.\n\
 
176
Tony Burton' + _(' as ') + ' Duke\n\
 
177
A.J. Benza' + _(' as ') + ' L.C.\n\
 
178
James Francis Kelly III' + _(' as ') + ' Steps\n\
 
179
Lou DiBella\n\
 
180
Mike Tyson' + _(' as ') + ' Himself\n\
 
181
Woodrow W. Paige\n\
 
182
Skip Bayless\n\
 
183
Jay Crawford\n\
 
184
Brian Kenny\n\
 
185
Dana Jacobson\n\
 
186
Chuck Johnson\n\
 
187
Jim Lampley\n\
 
188
Larry Merchant\n\
 
189
Max Kellerman\n\
 
190
Leroy Neiman\n\
 
191
Bert Randolph Sugar\n\
 
192
Bernard Fernandez\n\
 
193
Michael Buffer\n\
 
194
Talia Shire',
 
195
            'country'             : 'USA',
 
196
            'genre'               : 'Drama',
 
197
            'classification'      : False,
 
198
            'studio'              : 'Columbia Pictures, MGM, Revolution Studios, Chartoff Winkler Productions',
 
199
            'o_site'              : False,
 
200
            'site'                : 'http://www.allrovi.com/movies/movie/rocky-balboa-v337682',
 
201
            'trailer'             : False,
 
202
            'year'                : 2006,
 
203
            'notes'               : False,
 
204
            'runtime'             : False,
 
205
            'image'               : True,
 
206
            'rating'              : 6,
 
207
            'cameraman'           : 'Clark Mathis',
 
208
            'screenplay'          : 'Sylvester Stallone',
 
209
            'barcode'             : False
 
210
        },
 
211
    }