1
# -*- coding: UTF-8 -*-
3
__revision__ = '$Id: PluginMoviePTGate.py 1154 2009-02-08 23:20:39Z piotrek $'
5
# Copyright (c) 2005-2009 Vasco Nunes, Piotr Ozarowski
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.
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.
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
21
# You may use and distribute this software under the terms of the
22
# GNU General Public License, version 2 or later
29
plugin_name = "PTGate"
30
plugin_description = "Cinema PTGate"
31
plugin_url = "cinema.ptgate.pt"
32
plugin_language = _("Portuguese")
33
plugin_author = "Vasco Nunes"
34
plugin_author_email = "<vasco.m.nunes@gmail.com>"
35
plugin_version = "0.5"
37
class Plugin(movie.Movie):
38
def __init__(self, id):
39
self.encode ='iso-8859-1'
41
self.url = "http://cinema.ptgate.pt/filmes/" + str(self.movie_id)
44
self.page = gutils.convert_entities(self.page)
45
self.page = self.page.replace(u'\x93', u'"')
46
self.page = self.page.replace(u'\x94', u'"')
47
self.page = self.page.replace(u'\x96', u'-')
50
self.image_url = 'http://cinema.ptgate.pt/Movies/' + str(self.movie_id) + '.jpg'
52
def get_o_title(self):
53
self.o_title = gutils.trim(gutils.after(self.page, u'<h2>'), u'›', u'<br />') # <-- ›
54
self.o_title = self.o_title.encode(self.encode)
57
self.title = gutils.trim(self.page, u'<h2>', u'</h2>')
58
self.title = self.title.encode(self.encode)
60
def get_director(self):
61
self.director = gutils.trim(self.page, u'<b>realização</b><br />', u'<br />')
62
self.director = self.director.encode(self.encode)
65
self.plot = gutils.trim(self.page, u'<b>sinopse</b><br />', u'<br />')
66
self.plot = self.plot.encode(self.encode)
67
self.plot = string.replace(self.plot, "'", "\"")
68
self.plot = string.replace(self.plot, "'", "\"")
71
self.year = gutils.trim(self.page, u'<b>ano</b>: ', u'<br />')
73
def get_runtime(self):
77
self.genre = gutils.trim(self.page, u'<b>género</b>: ', u'<br />')
78
self.genre = self.genre.encode(self.encode)
81
self.cast = gutils.trim(self.page, u'pretes</b><br />', u'<br />')
82
self.cast = gutils.strip_tags(self.cast)
83
self.cast = string.replace(self.cast, ', ', '\n')
85
def get_classification(self):
86
self.classification = ''
93
tmp = string.find(self.page, u'(site oficial)')
95
index = string.rfind(self.page[:tmp], u'<a href="')
97
self.o_site = gutils.before(self.page[index + 9:], '"')
101
tmp = string.find(self.page, u'www.imdb.com/title/')
103
self.site = u'http://www.imdb.com/title/' + gutils.before(self.page[tmp:], '"')
105
def get_trailer(self):
107
tmp = string.find(self.page, u'(trailers)')
109
index = string.rfind(self.page[:tmp], u'<a href="')
111
self.trailer = gutils.before(self.page[index + 9:], '"')
113
def get_country(self):
114
self.country = gutils.trim(self.page, u'<b>país</b>: ', '<br />')
115
self.country = self.country.encode(self.encode)
118
self.notes = gutils.trim(self.page,"prémios e nomeações</b><br /><b>", "<td width=6 background='Images/group_r.gif'")
119
self.notes = gutils.strip_tags(self.notes)
121
def get_rating(self):
122
tmp = re.findall('[0-9.]+', string.replace(gutils.clean('<' + gutils.trim(self.page, u'imgs/blank.gif"', u'</small>')), u' ', ''))
123
if tmp and len(tmp) > 0:
124
self.rating = float(tmp[0])
126
self.rating = round(self.rating * 2)
130
class SearchPlugin(movie.SearchMovie):
132
self.original_url_search = 'http://cinema.ptgate.pt/pesquisa/?q='
133
self.translated_url_search = 'http://cinema.ptgate.pt/pesquisa/?q='
134
self.encode = 'iso-8859-1'
136
def search(self,parent_window):
137
self.open_search(parent_window)
140
def get_searches(self):
141
elements = string.split(self.page, '<a href="/filmes/')
142
self.number_results = elements[-1]
145
for element in elements:
146
id = gutils.digits_only(gutils.before(element, '"'))
147
title = gutils.clean(re.sub('</div>.*', '', string.replace(gutils.before(gutils.after(element, '>'), '</small>'), '<small>', ' / ')))
148
if id and title and title[0] != '<':
150
self.titles.append(gutils.convert_entities(title))
152
self.number_results = 0