1# -*- coding: utf-8 -*- 2 3__revision__ = '$Id$' 4 5# Copyright (c) 2006-2007 Piotr Ozarowski 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 = 'FDb' 30plugin_description = 'Internetowa baza filmowa' 31plugin_url = 'fdb.pl' 32plugin_language = _('Polish') 33plugin_author = 'Piotr Ożarowski, Bartosz Kurczewski' 34plugin_author_email = '<bartosz.kurczewski@gmail.com>' 35plugin_version = '1.16' 36 37class Plugin(movie.Movie): 38 TRAILER_PATTERN = re.compile('/film/.*/zwiastuny/odtwarzaj/[0-9]*') 39 40 def __init__(self, movie_id): 41 from md5 import md5 42 self.movie_id = md5(movie_id).hexdigest() 43 self.encode = 'utf-8' 44 if string.find(movie_id, 'http://') != -1: 45 self.url = str(movie_id) 46 else: 47 self.url = "http://fdb.pl/%s" % str(movie_id) 48 49 def get_image(self): 50 self.image_url = gutils.trim(self.page, 'class="gfx-poster"', '/></a>') 51 self.image_url = gutils.trim(self.image_url,'src="','"') 52 if self.image_url.endswith('http://fdb.pl/images/fdb2/add_poster.png?1214306282'): 53 self.image_url = '' 54 55 def get_o_title(self): 56 self.o_title = gutils.trim(self.page, '<h2 class="after-title">', '</h2>') 57 self.o_title = gutils.strip_tags(self.o_title) 58 self.o_title = string.strip(self.o_title) 59 if self.o_title == '': 60 self.o_title = self.get_title(True) 61 62 def get_title(self, extra=False): 63 data = gutils.trim(self.page,'<h1 id="movie-title">', '</h1>') 64 tmp = string.find(data, '(') 65 if tmp != -1: 66 data = data[:tmp] 67 if extra is False: 68 self.title = data 69 else: 70 return data 71 72 def get_director(self): 73 self.director = '' 74 elements = gutils.trim(self.page,'>Reżyseria: </h4>','</div>') 75 elements = string.split(elements, '</li>') 76 if elements[0] != '': 77 for element in elements: 78 element = gutils.trim(element, '>', '</a') 79 if element != '': 80 self.director += ', ' + element 81 self.director = string.replace(self.director[2:], ', (więcej)', '') 82 83 def get_screenplay(self): 84 self.screenplay = '' 85 elements = gutils.trim(self.page,'>Scenariusz: </h4>','</div>') 86 elements = string.split(elements, '</li>') 87 if elements[0] != '': 88 for element in elements: 89 element = gutils.trim(element, '>', '</a') 90 if element != '': 91 self.screenplay += ', ' + element 92 self.screenplay = string.replace(self.screenplay[2:], ', (więcej)', '') 93 94 95 def get_plot(self): 96 self.plot = gutils.trim(self.page,'Opis filmu','</div>') 97 self.plot = gutils.trim(self.plot,'<p>',"\n\n") 98 99 def get_year(self): 100 self.year = gutils.trim(self.page,'<small> (', ')</small>') 101 102 def get_runtime(self): 103 self.runtime = gutils.trim(self.page,'Czas trwania: </h4>','</div>') 104 self.runtime = gutils.trim(self.runtime,'<li>',' minut') 105 106 def get_genre(self): 107 self.genre = gutils.trim(self.page,'Gatunek: </h4>','</div>') 108 self.genre = gutils.trim(self.genre,'<li>','</li>') 109 self.genre = string.replace(self.genre, ' / ', ' | ') 110 111 def get_cast(self): 112 self.cast = gutils.trim(self.page,'<div class="cast">',"</div>") 113 tmpcast = gutils.trim(self.cast,"<table>\n",'</table>') 114 if tmpcast == '': 115 tmpcast = tmpcast = gutils.trim(self.cast,"<table>\n",'<div class="line">') 116 self.cast = tmpcast 117 if self.cast != '': 118 self.cast = gutils.strip_tags(self.cast) 119 self.cast = self.cast.replace(" ","") 120 self.cast = self.cast.replace(" ","") 121 self.cast = self.cast.replace("\n...\n\n ",_(' as ')) 122 self.cast = self.cast.replace("\n\n\n\n\n","") 123 124 def get_classification(self): 125 self.classification = gutils.trim(self.page,"Od lat: </h4>","</div>") 126 self.classification = gutils.trim(self.classification,'<li>','</li>') 127 128 def get_studio(self): 129 self.studio = '' 130 131 def get_o_site(self): 132 self.o_site = '' 133 134 def get_site(self): 135 self.site = self.url 136 137 def get_trailer(self): 138 trailer_url = self.TRAILER_PATTERN.findall(self.page) 139 if trailer_url: 140 self.trailer = 'http://fdb.pl' + trailer_url[0] 141 142 def get_country(self): 143 self.country = gutils.trim(self.page,'Kraj produkcji: </h4>','</div>') 144 self.country = gutils.trim(self.country,'<li>','</li>') 145 146 def get_rating(self): 147 self.rating = gutils.trim(self.page, 'class="vote"','/10</strong>') 148 self.rating = gutils.after(self.rating, '<strong>') 149 if self.rating: 150 self.rating = str(float(gutils.clean(self.rating))) 151 152class SearchPlugin(movie.SearchMovie): 153 def __init__(self): 154 self.encode = 'utf-8' 155 self.original_url_search = 'http://fdb.pl/szukaj/movies?query=' 156 self.translated_url_search = 'http://fdb.pl/szukaj/movies?query=' 157 158 def search(self,parent_window): 159 if not self.open_search(parent_window): 160 return None 161 tmp = string.find(self.page,'<h1>Wyniki wyszukiwania dla') 162 if tmp == -1: # already a movie page 163 self.page = '' 164 else: # multiple matches 165 self.page = gutils.before(self.page[tmp:],'>Mapa strony</h3>'); 166 return self.page 167 168 def get_searches(self): 169 if self.page == '': # movie page already 170 self.number_results = 1 171 self.ids.append(self.url) 172 self.titles.append(self.title) 173 else: # multiple matches 174 elements = string.split(self.page,'<div class="content">') 175 if len(elements)>1: 176 for element in elements: 177 tmpId = gutils.trim(element, '<a href="', '"') 178 if tmpId.startswith('/szukaj'): 179 continue 180 self.ids.append(tmpId) 181 element = gutils.strip_tags( 182 gutils.trim(element, '">', '</div>')) 183 element = element.replace("\n", '') 184 element = element.replace(' ', '') 185 element = element.replace('aka ', ' aka ') 186 element = element.replace('{{rate}}', ' ') 187 element = element.replace(' - Oryginalny', '') 188 self.titles.append(element) 189 else: 190 self.number_results = 0 191