1# -*- coding: UTF-8 -*-
2
3__revision__ = '$Id$'
4
5# Copyright (c) 2007-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
24import gutils
25import movie
26import string
27import re
28
29plugin_name         = "Filmtipset.se"
30plugin_description  = "Filmtipset.se"
31plugin_url          = "www.filmtipset.se"
32plugin_language     = _("Swedish")
33plugin_author       = "Michael Jahn"
34plugin_author_email = "<mikej06@hotmail.com>"
35plugin_version      = "1.2"
36
37class Plugin(movie.Movie):
38
39    def __init__(self, id):
40        self.encode   = 'iso-8859-1'
41        self.movie_id = id
42        self.url      = 'http://www.filmtipset.se/film/' + str(self.movie_id)
43
44    def get_image(self):
45        self.image_url = ''
46        tmp = gutils.trim(self.page, 'src="http://images.filmtipset.se/posters/', '"')
47        if tmp != '':
48            self.image_url = 'http://images.filmtipset.se/posters/' + tmp
49
50    def get_o_title(self):
51        self.o_title = gutils.trim(self.page, 'Originaltitel:', '</tr>')
52        if self.o_title == '':
53            self.o_title = gutils.trim(self.page, '<h1>', '</h1>')
54
55    def get_title(self):
56        self.title = gutils.after(gutils.trim(self.page, 'class="movie_header"', '<td'), '>')
57
58    def get_director(self):
59        self.director = gutils.trim(self.page, 'Regiss&ouml;r:', '</tr>')
60
61    def get_plot(self):
62        self.plot = gutils.regextrim(self.page, '<h2>Om [^>]*[>]', '</tr>')
63
64    def get_year(self):
65        self.year = gutils.trim(self.page, 'Utgivnings&aring;r:', '</tr>')
66
67    def get_runtime(self):
68        self.runtime = gutils.trim(self.page, 'L&auml;ngd:', ' min').strip()
69
70    def get_genre(self):
71        self.genre = gutils.trim(self.page, 'Nyckelord:', '</tr>').strip()
72        if self.genre == '':
73            self.genre = gutils.trim(self.page, 'Genre:</h2>', '</tr>').strip()
74
75    def get_cast(self):
76        self.cast = gutils.regextrim(self.page, 'Sk&aring;despelare[^:]*[:]', '</tr>')
77        self.cast = self.cast.replace(', ', '\n')
78
79    def get_classification(self):
80        self.classification = ''
81
82    def get_studio(self):
83        self.studio = ''
84
85    def get_o_site(self):
86        self.o_site = ''
87        tmp = gutils.trim(self.page, 'http://www.imdb.com', '"')
88        if tmp != '':
89            self.o_site = 'http://www.imdb.com' + tmp
90
91    def get_site(self):
92        self.site = self.url
93
94    def get_trailer(self):
95        self.trailer = ""
96
97    def get_country(self):
98        self.country = gutils.trim(self.page, 'Produktionsland:', '</span>').strip()
99
100    def get_rating(self):
101        self.rating = "0"
102        tmp = gutils.trim(self.page, 'grade_images/grade1', '_')
103        try:
104            self.rating = str(int(tmp) * 2)
105        except:
106            pass
107
108    def get_notes(self):
109        self.notes = ''
110        tmp = gutils.trim(self.page, 'Alt. titel:', '</span>')
111        if tmp != '':
112            self.notes = self.notes + 'Alt. titel:' + gutils.strip_tags(tmp).strip()
113
114    def get_screenplay(self):
115        self.screenplay = gutils.trim(self.page, 'Manus:', '</tr>')
116
117class SearchPlugin(movie.SearchMovie):
118
119    def __init__(self):
120        self.original_url_search   = "http://www.filmtipset.se/search.cgi?field=name&field=orgname&show_graded=1&search_value="
121        self.translated_url_search = "http://www.filmtipset.se/search.cgi?field=name&field=orgname&show_graded=1&search_value="
122        self.encode                = 'iso-8859-1'
123
124    def search(self,parent_window):
125        if not self.open_search(parent_window):
126            return None
127        tmp_page = gutils.trim(self.page, 'Matchning', 'Hittade')
128        if tmp_page == '':
129            tmp_page = gutils.trim(self.page, 'Matchning', 'Visa fler')
130        self.page = tmp_page
131        return self.page
132
133    def get_searches(self):
134        elements1 = re.split('href="film/', self.page)
135        elements1[0] = None
136        for element in elements1:
137            if element != None:
138                searchResult = re.search('["&?]', element)
139                if searchResult is None:
140                    self.ids.append(gutils.before(element, '"'))
141                else:
142                    self.ids.append(element[:searchResult.end() - 1])
143                self.titles.append(
144                    gutils.strip_tags(gutils.trim(element, '>', '</a>')) + ' / ' +
145                    gutils.clean(gutils.trim(element, 'Originaltitel:', '</div>').replace('&nbsp;', ' '))
146                )
147
148#
149# Plugin Test
150#
151class SearchPluginTest(SearchPlugin):
152    #
153    # Configuration for automated tests:
154    # dict { movie_id -> [ expected result count for original url, expected result count for translated url ] }
155    #
156    test_configuration = {
157        'Rocky' : [ 19, 19 ],
158    }
159
160class PluginTest:
161    #
162    # Configuration for automated tests:
163    # dict { movie_id -> dict { arribute -> value } }
164    #
165    # value: * True/False if attribute only should be tested for any value
166    #        * or the expected value
167    #
168    test_configuration = {
169        'rocky-balboa.html' : {
170            'title'               : 'Rocky Balboa',
171            'o_title'             : 'Rocky Balboa',
172            'director'            : 'Sylvester Stallone',
173            'plot'                : True,
174            'cast'                : 'Sylvester Stallone\n\
175Burt Young\n\
176Milo Ventimiglia\n\
177Geraldine Hughes\n\
178Antonio Tarver\n\
179James Francis Kelly III\n\
180Tony Burton\n\
181Henry G Sanders',
182            'country'             : 'USA',
183            'genre'               : 'Drama, Action',
184            'classification'      : False,
185            'studio'              : False,
186            'o_site'              : 'http://www.imdb.com/title/tt0479143/',
187            'site'                : 'http://www.filmtipset.se/film/rocky-balboa.html',
188            'trailer'             : False,
189            'year'                : 2006,
190            'notes'               : False,
191            'runtime'             : 102,
192            'image'               : True,
193            'rating'              : 6,
194            'cameraman'           : False,
195            'screenplay'          : 'Sylvester Stallone',
196            'barcode'             : False
197        },
198    }
199