def get_searches(self): if self.page is None: # movie page self.ids.append(self.url) self.titles.append(gutils.convert_entities(self.title)) elif self.page is False: # no movie found self.number_results = 0 else: # multiple matches elements = self.page.split('<li ') self.number_results = elements[-1] if elements != '': for element in elements: if (element == ''): continue element = gutils.after(element, 'href="') self.ids.append('http://' + plugin_url_other + gutils.before(element, '"')) element_title = gutils.trim(element, '">', '</a>') element_title = element_title.replace('\t', '') element = gutils.after(element, 'class=searchResultDetails') element_year = gutils.trim(element, '>', '|') element_year = element_year.replace(" ", '') element_year = gutils.strip_tags(element_year) element_country = '' pos_country = element.find('countryIds') if pos_country != -1: element_country = gutils.trim(element[pos_country:], '">', '</a>') element = element_title.strip() if element_year: element += ' (' + element_year.strip() + ')' if element_country: element += ' - ' + element_country.strip() element = gutils.convert_entities(element) element = gutils.strip_tags(element) self.titles.append(element) else: self.number_results = 0
def get_searches(self): if self.page is None: # movie page self.ids.append(self.url) self.titles.append(gutils.convert_entities(self.title)) elif self.page is False: # no movie found self.number_results = 0 else: # multiple matches elements = string.split(self.page, '<li ') self.number_results = elements[-1] if (elements[0] <> ''): for element in elements: element = gutils.after(element, '<a href="') self.ids.append('http://' + plugin_server + gutils.before(element, '"')) element_title = gutils.trim(element, 'class="searchResultTitle"', '</a>') element_title = gutils.after(element_title, '">') element_title = string.replace(element_title, "\t", '') element = gutils.after(element, 'class="searchResultDetails"') element_year = gutils.trim(element, '>', '|') element_year = string.replace(element_year, " ", '') element_year = gutils.strip_tags(element_year) element_country = gutils.trim(element, '">', '</a>') element = string.strip(element_title) if (element_year <> ''): element = element + ' (' + string.strip(element_year) + ')' if (element_country <> ''): element = element + ' - ' + string.strip(element_country) element = gutils.convert_entities(element) element = gutils.strip_tags(element) self.titles.append(element) else: self.number_results = 0
def initialize(self): self.cast_page = self.open_page(url=self.url + '/fullcredits') self.plot_page = self.open_page(url=self.url + '/plotsummary') # looking for the original imdb page self.imdb_page = self.open_page(url="http://www.imdb.com/title/tt%s" % str(self.movie_id)) self.imdb_plot_page = self.open_page(url="http://www.imdb.com/title/tt%s/plotsummary" % str(self.movie_id)) # correction of all &#xxx entities self.page = gutils.convert_entities(self.page) self.cast_page = gutils.convert_entities(self.cast_page) self.plot_page = gutils.convert_entities(self.plot_page) self.imdb_page = gutils.convert_entities(self.imdb_page) self.imdb_plot_page = gutils.convert_entities(self.imdb_plot_page)
def initialize(self): self.cast_page = self.open_page(url=self.url + '/fullcredits') self.plot_page = self.open_page(url=self.url + '/plotsummary') # correction of all &#xxx entities self.page = self.page.decode(self.encode) self.page = gutils.convert_entities(self.page) self.page = self.page.encode(self.encode) self.cast_page = self.cast_page.decode(self.encode) self.cast_page = gutils.convert_entities(self.cast_page) self.cast_page = self.cast_page.encode(self.encode) self.plot_page = self.plot_page.decode(self.encode) self.plot_page = gutils.convert_entities(self.plot_page) self.plot_page = self.plot_page.encode(self.encode)
def get_searches(self): elements = string.split(self.page, '<td><b>') if (elements[0]<>''): for element in elements: self.ids.append(gutils.trim(element, 'ver.php?art=',"'")) self.titles.append(gutils.strip_tags(gutils.convert_entities(gutils.trim(element, "target='_top'>", '</a>'))))
def get_searches(self): elements = string.split(self.page, '<h4><a href="/film/fichefilm_gen_cfilm=') if (elements[0]<>''): for index in range(1, len(elements), 1): element = elements[index] self.ids.append(gutils.before(element, '.')) self.titles.append(gutils.strip_tags(gutils.convert_entities(gutils.trim(element, '>', '</a>'))))
def get_searches(self): if not self.page: return if len(self.page) < 20: # immidietly redirection to movie page self.number_results = 1 self.ids.append(self.page) self.titles.append(self.url) else: # multiple matches elements = string.split(self.page, '</a></b>') if (elements[0] <> ''): for index in range(0, len(elements) - 1, 1): element = elements[index] nextelement = elements[index + 1] id = gutils.trim(element, '<b><a href="/es/film', '.html') if id: self.ids.append(id) title = gutils.clean( gutils.after(element, '<b><a href="/es/film')).replace( "\n", "") title = gutils.strip_tags( gutils.convert_entities(gutils.after( title, '>'))) + ' ' + string.strip( gutils.before(nextelement, '<')) self.titles.append(title)
def get_searches(self): elements = string.split(self.page, '<li>') if (elements[0]<>''): for element in elements: self.ids.append(gutils.trim(element, '/title/tt','/?fr=')) self.titles.append(gutils.strip_tags(gutils.convert_entities(gutils.trim(element, ';fm=1">', '</li>'))))
def get_plot(self): self.plot = gutils.trim(self.page, '<div id="film-top-middle">', '</div>') if self.plot: self.plot = string.replace(self.plot, '’', "'") self.plot = string.replace(self.plot, '’', "'") self.plot = gutils.convert_entities(self.plot)
def get_searches(self): elements = string.split(self.page, "<li>") if elements[0] <> "": for element in elements: self.ids.append(gutils.trim(element, "/title/tt", "/?fr=")) self.titles.append(gutils.strip_tags(gutils.convert_entities(gutils.trim(element, ';fm=1">', "</li>"))))
def get_searches(self): elements = string.split(self.page, "<h3 style=\"margin:0px;\">") self.number_results = len(elements) - 1 if self.number_results > 0: i = 1 while i < len(elements): element = gutils.trim(elements[i], "<a", "</a>") y = gutils.trim(elements[i], "anno=", "\">") # print "******* elemento "+str(i)+" **********\n\n\n\n\n"+element+"\n******fine*******\n\n\n\n\n\n" # print "id = "+gutils.trim(element,"recensione.asp?id=","\"") # print "title = "+gutils.convert_entities(gutils.strip_tags(gutils.trim(element,'" title="', '"'))) self.ids.append( gutils.trim(element, "recensione.asp?id=", "\"")) self.titles.append( gutils.convert_entities( gutils.strip_tags( gutils.trim(element, '" title="', '"'))) + "\nAnno: " + y) i += 1 else: self.number_results = 0
def get_searches(self): if self.page == "": # immidietly redirection to movie page self.number_results = 1 self.ids.append(self.url) self.titles.append(gutils.convert_entities(self.title)) else: # multiple matches elements = string.split(self.page,"<a title=") self.number_results = elements[-1] if (elements[0]<>''): for element in elements: self.ids.append(gutils.trim(element,"href=\"","\">")) element = gutils.trim(element,"'","' href=") element = gutils.convert_entities(element) self.titles.append(element) else: self.number_results = 0
def get_searches(self): """Try to find both id and film title for each search result""" elements = re.split('index[.]php[?]op=Movie&id=([0-9]+)">', self.page) for index in range(2, len(elements), 2): id = elements[index - 1] title = gutils.before(elements[index], '<') self.ids.append(id) self.titles.append(gutils.strip_tags(gutils.convert_entities(title)))
def get_searches(self): if self.page is None: # immidietly redirection to movie page self.number_results = 1 self.ids.append(self.url) self.titles.append(gutils.convert_entities(self.title)) else: # multiple matches elements = string.split(self.page, "<li ") self.number_results = elements[-1] if elements[0] <> "": for element in elements: element = gutils.after(element, '<a class="searchResultTitle" href="') self.ids.append(gutils.before(element, '">')) element = gutils.trim(element, '">', "</a>") element = gutils.convert_entities(element) element = gutils.strip_tags(element) self.titles.append(element) else: self.number_results = 0
def get_searches(self): elements = string.split(self.page, '<td><b>') if (elements[0] <> ''): for element in elements: self.ids.append(gutils.trim(element, 'ver.php?art=', "'")) self.titles.append( gutils.strip_tags( gutils.convert_entities( gutils.trim(element, "target='_top'>", '</a>'))))
def get_searches(self): elements = string.split(self.page,"<td rowspan=\"4\" align=\"center\" valign=\"top\" style=\"padding:4px;\">") self.number_results = elements[-1] if (elements[0]<>''): for element in elements: self.ids.append(gutils.trim(element,"/dvd/detail.asp?id=","\">")) self.titles.append(gutils.convert_entities(gutils.trim(element,"\" class=\"dvd-search-title\">","</a>"))) else: self.number_results = 0
def get_searches(self): elements = string.split(self.page,"</br>") self.number_results = elements[-1] if (elements[0]<>''): for element in elements: self.ids.append(gutils.trim(element,"26mid%3d","\">")) self.titles.append(gutils.convert_entities(gutils.trim(element,(gutils.trim(element,"26mid%3d","\">"))+"\">","""</a></span>"""))) else: self.number_results = 0
def get_searches(self): """Try to find both id and film title for each search result""" elements = re.split('index[.]php[?]op=Movie&id=([0-9]+)" ', self.page) for index in range(2, len(elements), 2): id = elements[index - 1] title = gutils.clean(gutils.trim(elements[index], '>', '</')) if id and title: self.ids.append(id) self.titles.append(gutils.strip_tags(gutils.convert_entities(title)))
def get_searches(self): elements = string.split(self.page,"<li>") self.number_results = elements[-1] if (elements[0]<>''): for element in elements: self.ids.append(gutils.trim(element,"/film/film.asp?fi=","\"><b>")) self.titles.append(gutils.convert_entities(gutils.trim(element,"<b>","</b></a>"))) else: self.number_results = 0
def get_searches(self): elements = string.split(self.page, '<li>') self.number_results = elements[-1] if len(elements): for element in elements: self.ids.append(gutils.trim(element,"/film/film.asp?fi=", '"><')) self.titles.append(gutils.convert_entities(gutils.trim(element, '"bold">', '</span>'))) else: self.number_results = 0
def get_searches(self): elements = string.split(self.page,"</tr> <tr>") self.number_results = elements[-1] if (elements[0]<>''): for element in elements: self.ids.append(gutils.trim(element,"?IDfilm=","\" class=\"arial")) self.titles.append(gutils.convert_entities(gutils.strip_tags(gutils.trim(element,"12black3\">","</font><br>")))) else: self.number_results = 0
def get_searches(self): "Try to find both id and film title for each search result" elements = string.split(self.page, "<li>") self.number_results = elements[-1] if (elements[0] != ''): for element in elements: self.ids.append(gutils.trim(element, "?codice=", "\">")) self.titles.append(gutils.convert_entities(gutils.trim(element, "<b>", "</b>"))) else: self.number_results = 0
def get_searches(self): if self.page is None: # movie page self.number_results = 1 self.ids.append(self.url) self.titles.append(gutils.convert_entities(self.title)) elif self.page is False: # no movie found self.number_results = 0 else: # multiple matches elements = string.split(self.page, '<li ') self.number_results = elements[-1] if (elements[0]<>''): for element in elements: element = gutils.after(element, '<a class="searchResultTitle" href="') self.ids.append(gutils.before(element, '">')) element = gutils.trim(element, '">', '</a>') element = gutils.convert_entities(element) element = gutils.strip_tags(element) self.titles.append(element) else: self.number_results = 0
def get_cast(self): self.cast = '' self.cast = gutils.trim(self.cast_page, '<table class="cast">', '</table>') if self.cast == '': self.cast = gutils.trim(self.page, '<table class="cast">', '</table>') self.cast = string.replace(self.cast, ' ... ', _(' as ')) self.cast = string.replace(self.cast, '...', _(' as ')) self.cast = string.replace(self.cast, '</tr><tr>', "\n") self.cast = re.sub('</tr>[ \t]*<tr[ \t]*class="even">', "\n", self.cast) self.cast = re.sub('</tr>[ \t]*<tr[ \t]*class="odd">', "\n", self.cast) self.cast = gutils.convert_entities(self.cast)
def get_searches(self): elements = string.split(self.page,"</td><td>") self.number_results = elements[-1] if (len(elements[0])): for element in elements: element = string.replace(element,"</a>","") self.ids.append(gutils.trim(element,"?code=","'>")) self.titles.append(gutils.convert_entities(gutils.trim(element,"'>","</td><td width=6"))) else: self.number_results = 0
def get_searches(self): self.id = self.re_items=re.search(r"window.location.href='http://www.csfd.cz/film.php\?([^']*)'",self.page) if self.id: self.ids.append(self.id.group(1)) else: self.re_items=re.findall(r"href=[\"]{1}film\.php\?([^\"]+)[^>]*>([^<]+)</a>[ ]*([^<]*)",self.page) self.number_results = len(self.re_items) if (self.number_results > 0): for item in self.re_items: self.ids.append(item[0]) self.titles.append(gutils.convert_entities(item[1])+' '+item[2])
def search(self,parent_window): self.open_search(parent_window) tmp_page = gutils.trim(self.page, 'Here are the', '</TABLE>') if tmp_page == '': self.page = gutils.trim(self.page, '(Displaying', '<b>Suggestions For Improving Your Results</b>') else: self.page = tmp_page self.page = self.page.decode('iso-8859-1') # correction of all &#xxx entities self.page = gutils.convert_entities(self.page) return self.page
def get_searches(self): elements = string.split(self.page, '<h4><a href="/film/fichefilm_gen_cfilm=') if elements[0] <> "": for index in range(1, len(elements), 1): element = elements[index] self.ids.append(gutils.before(element, ".")) title = gutils.strip_tags(gutils.convert_entities(gutils.trim(element, ">", "</a>"))) year = gutils.clean(gutils.trim(element, "</h4>", "</h4>")) if year: self.titles.append(title + " (" + year + ")") else: self.titles.append(title)
def get_searches(self): elements = string.split(self.page, '<tr') self.number_results = elements[-1] if (elements[0]<>''): for element in elements: self.ids.append(gutils.trim(element, 'IDfilm=', '"')) title = gutils.convert_entities(gutils.strip_tags(gutils.after(gutils.trim(element, 'IDfilm=', '</a>'), '>'))) year = gutils.after(gutils.trim(element, '<td valign="bottom"', '</td>'), '>') self.titles.append(title + ' (' + year + ')') else: self.number_results = 0
def search(self,parent_window): self.open_search(parent_window) tmp = gutils.trim(self.page, ' angezeigt)', ' Treffergenauigkeit') if tmp == '': if self.PATTERN_POWERSEARCH.search(self.page) is None: self.page = '' else: self.page = tmp # correction of all &#xxx entities self.page = self.page.decode(self.encode) self.page = gutils.convert_entities(self.page) self.page = self.page.encode(self.encode) return self.page
def get_searches(self): if len(self.page) < 20: # immidietly redirection to movie page self.number_results = 1 self.ids.append(self.page) self.titles.append(self.url) else: # multiple matches elements = string.split(self.page, '</a></b>') if (elements[0]<>''): for element in elements[:-1]: self.ids.append(gutils.trim(element, '<b><a href="/es/film','.html')) title = gutils.after(element, '<b><a href="/es/film') self.titles.append(gutils.strip_tags(gutils.convert_entities(gutils.after(title, '>'))))
def get_searches(self): # Try to find both id and film title for each search result elements = string.split(self.page, "<li>") self.number_results = elements[-1] if elements[0] != "": for element in elements: id = gutils.trim(element, "?codice=", '">') if id <> "": self.ids.append(id) self.titles.append(gutils.convert_entities(gutils.trim(element, "<b>", "</b>"))) else: self.number_results = 0
def get_searches(self): elements = string.split(self.page, '<a href="/filmes/') self.number_results = elements[-1] if len(elements[0]): for element in elements: id = gutils.digits_only(gutils.before(element, '"')) title = gutils.clean(re.sub('</div>.*', '', string.replace(gutils.before(gutils.after(element, '>'), '</small>'), '<small>', ' / '))) if id and title and title[0] != '<': self.ids.append(id) self.titles.append(gutils.convert_entities(title)) else: self.number_results = 0
def get_searches(self): elements = string.split(self.page, '<a href=\'/film/fichefilm_gen_cfilm=') if (elements[0] <> ''): for index in range(1, len(elements), 1): element = elements[index] title = gutils.clean(gutils.convert_entities(gutils.trim(element, '>', '</a>'))) year = gutils.clean(gutils.trim(element, '<span class="fs11">', '<br')) if title: self.ids.append(gutils.before(element, '.')) if year: self.titles.append(title + ' (' + year + ')') else: self.titles.append(title)
def search(self, parent_window): if not self.open_search(parent_window): return None tmp = gutils.trim(self.page, " angezeigt)", " Treffergenauigkeit") if tmp == "": if self.PATTERN_POWERSEARCH.search(self.page) is None: self.page = "" else: self.page = tmp # correction of all &#xxx entities self.page = self.page.decode("iso8859-1") self.page = gutils.convert_entities(self.page) # self.page = self.page.encode(self.encode) return self.page
def search(self, parent_window): if not self.open_search(parent_window): return None tmp = gutils.trim(self.page, ' angezeigt)', ' Treffergenauigkeit') if tmp == '': if self.PATTERN_POWERSEARCH.search(self.page) is None: self.page = '' else: self.page = tmp # correction of all &#xxx entities self.page = self.page.decode('iso8859-1') self.page = gutils.convert_entities(self.page) #self.page = self.page.encode(self.encode) return self.page
def initialize(self): # OFDb didn't provide the runtime, studio and classification but it provide a link to the german imdb entry # lets use the imdb page, why not imdb_nr = gutils.trim(self.page, 'http://german.imdb.com/Title?', '"') if imdb_nr != '': self.imdb_page = self.open_page( url='http://www.imdb.com/title/tt' + imdb_nr) self.cert_page = self.open_page( url='http://www.imdb.com/title/tt' + imdb_nr + '/parentalguide') self.comp_page = self.open_page( url='http://www.imdb.com/title/tt' + imdb_nr + '/companycredits') else: imdb_nr = gutils.trim(self.page, 'http://www.imdb.com/Title?', '"') if imdb_nr != '': self.imdb_page = self.open_page( url='http://www.imdb.com/title/tt' + imdb_nr) self.cert_page = self.open_page( url='http://www.imdb.com/title/tt' + imdb_nr + '/parentalguide') self.comp_page = self.open_page( url='http://www.imdb.com/title/tt' + imdb_nr + '/companycredits') else: self.imdb_page = '' self.cert_page = '' self.comp_page = '' self.comp_page = gutils.convert_entities(self.comp_page) self.imdb_page = gutils.convert_entities(self.imdb_page) self.cert_page = gutils.convert_entities(self.cert_page) movie_id_elements = string.split(self.movie_id, ',') movie_id_elements[0] = string.replace(movie_id_elements[0], "film/", "") self.cast_page = self.open_page( url="http://www.ofdb.de/view.php?page=film_detail&fid=%s" % str(movie_id_elements[0]))
def get_searches(self): elements = string.split( self.page, "<td rowspan=\"4\" align=\"center\" valign=\"top\" style=\"padding:4px;\">" ) self.number_results = elements[-1] if (elements[0] <> ''): for element in elements: self.ids.append( gutils.trim(element, "/dvd/detail.asp?id=", "\">")) self.titles.append( gutils.convert_entities( gutils.trim(element, "\" class=\"dvd-search-title\">", "</a>"))) else: self.number_results = 0
def get_searches(self): elements = string.split(self.page, '<a href="/filmes/') self.number_results = elements[-1] if len(elements[0]): for element in elements: id = gutils.digits_only(gutils.before(element, '"')) title = gutils.clean( re.sub( '</div>.*', '', string.replace( gutils.before(gutils.after(element, '>'), '</small>'), '<small>', ' / '))) if id and title and title[0] != '<': self.ids.append(id) self.titles.append(gutils.convert_entities(title)) else: self.number_results = 0
def initialize(self): self.cast_page = self.open_page(url=self.url + '/fullcredits') self.plot_page = self.open_page(url=self.url + '/plotsummary') self.comp_page = self.open_page(url=self.url + '/companycredits') # looking for the original imdb page self.imdb_page = self.open_page(url="http://www.imdb.com/title/tt%s" % str(self.movie_id)) self.imdb_plot_page = self.open_page(url="http://www.imdb.com/title/tt%s/plotsummary" % str(self.movie_id)) # correction of all &#xxx entities self.page = gutils.convert_entities(self.page) self.cast_page = gutils.convert_entities(self.cast_page) self.plot_page = gutils.convert_entities(self.plot_page) self.comp_page = gutils.convert_entities(self.comp_page) self.imdb_page = gutils.convert_entities(self.imdb_page) self.imdb_plot_page = gutils.convert_entities(self.imdb_plot_page)
def get_searches(self): # Try to find both id and film title for each search result elements = string.split(self.page, "<li>") self.number_results = elements[-1] if (elements[0] != ''): for element in elements: id = gutils.trim(element, "?codice=", "\">") if id <> '': self.ids.append(id) title = self.capwords(gutils.convert_entities(gutils.trim(element, "<b>", "</b>"))) year = re.search('([[][0-9]{4}[]])', element) if year: year = year.group(0) if year: self.titles.append(title + ' ' + year) else: self.titles.append(title) else: self.number_results = 0
def get_searches(self): if self.page == '': # immediately redirection to movie page self.number_results = 1 self.ids.append(self.url) self.titles.append(gutils.convert_entities(self.title)) else: # multiple matches elements = string.split(self.page, "<tr") self.number_results = elements[-1] if (elements[0] <> ''): for element in elements: self.ids.append( gutils.trim(element, 'href="/strony/anime/', '" >')) element = gutils.after(element, " >\n\t") element = element.replace("</a>\n\t</td>\n", " (") element = element.replace("\t<td>", "") element = element.replace("</td>\n", "; ") element = element.replace("</tr>", "") element = element[:len(element) - 3] + ')' self.titles.append(element) else: self.number_results = 0
def search(self, parent_window): if not self.open_search(parent_window): return None tmp_page = gutils.trim(self.page, 'Titres Populaires', '</table>') if not tmp_page: has_results = re.search( '[(]Affichant [1-9][0-9]* Résultats[)]', self.page) if not has_results: # nothing or one result found, try another url which looks deeper in the imdb database # example: Adventures of Falcon -> one result, jumps directly to the movie page # which isn't supported by this plugin self.url = 'http://www.imdb.fr/find?more=tt&q=' if not self.open_search(parent_window): return None self.page = gutils.trim(self.page, '(Affichant', '>Suggestions pour améliorer') else: self.page = tmp_page self.page = self.page.decode('iso-8859-1') # correction of all &#xxx entities self.page = gutils.convert_entities(self.page) return self.page
def search(self, parent_window): if not self.open_search(parent_window): return None tmp_page = gutils.trim(self.page, 'Titoli popolari', '</table>') if not tmp_page: has_results = re.match( '[(]Visualizza [1-9][0-7]* risultat[io]*[)]', self.page) if not has_results: # nothing or one result found, try another url which looks deeper in the imdb database # example: Adventures of Falcon -> one result, jumps directly to the movie page # which isn't supported by this plugin self.url = 'http://italian.imdb.com/find?more=tt;q=' if not self.open_search(parent_window): return None self.page = gutils.trim( self.page, '(Visualizza', '>Suggerimenti per migliorare i tuoi risultati<') else: self.page = tmp_page self.page = self.page.decode('iso-8859-1') # correction of all &#xxx entities self.page = gutils.convert_entities(self.page) return self.page
def search(self, parent_window): if not self.open_search(parent_window): return None tmp_page = gutils.trim(self.page, 'Here are the', '</TABLE>') if not tmp_page: has_results = re.match('[(]Displaying [1-9][0-7]* Result[s]*[)]', self.page) if not has_results: # nothing or one result found, try another url which looks deeper in the imdb database # example: Adventures of Falcon -> one result, jumps directly to the movie page # which isn't supported by this plugin self.url = 'http://www.imdb.com/find?more=tt;q=' if not self.open_search(parent_window): return None self.page = gutils.trim( self.page, '(Displaying', '>Suggestions For Improving Your Results<') else: self.page = tmp_page self.page = self.page.decode('iso-8859-1') # correction of all &#xxx entities self.page = gutils.convert_entities(self.page) return self.page
def test_one_movie(self, movieplugin, logFile, results_expected): global myconfig result = True self.movie = movieplugin self.movie.parent_window = None self.movie.locations = self.locations self.movie.config = myconfig fields_to_fetch = [ 'o_title', 'title', 'director', 'plot', 'cast', 'country', 'genre', 'classification', 'studio', 'o_site', 'site', 'trailer', 'year', 'notes', 'runtime', 'image', 'rating', 'screenplay', 'cameraman', 'resolution', 'barcode' ] self.movie.fields_to_fetch = fields_to_fetch self.movie.get_movie(None) self.movie.parse_movie() results = {} if 'year' in fields_to_fetch: results['year'] = self.movie.year fields_to_fetch.pop(fields_to_fetch.index('year')) if 'runtime' in fields_to_fetch: results['runtime'] = self.movie.runtime fields_to_fetch.pop(fields_to_fetch.index('runtime')) if 'cast' in fields_to_fetch: results['cast'] = gutils.convert_entities(self.movie.cast) fields_to_fetch.pop(fields_to_fetch.index('cast')) if 'plot' in fields_to_fetch: results['plot'] = gutils.convert_entities(self.movie.plot) fields_to_fetch.pop(fields_to_fetch.index('plot')) if 'notes' in fields_to_fetch: results['notes'] = gutils.convert_entities(self.movie.notes) fields_to_fetch.pop(fields_to_fetch.index('notes')) if 'rating' in fields_to_fetch: if self.movie.rating: results['rating'] = float(self.movie.rating) fields_to_fetch.pop(fields_to_fetch.index('rating')) # poster if 'image' in fields_to_fetch: if self.movie.image: results['image'] = self.movie.image fields_to_fetch.pop(fields_to_fetch.index('image')) # other fields for i in fields_to_fetch: results[i] = gutils.convert_entities(self.movie[i]) # check the fields for i in results_expected: try: i_val = results_expected[i] if isinstance(i_val, bool): if i_val: if not results.has_key(i) or len(results[i]) < 1: print "Test error: %s: Value expected but nothing returned.\nKey: %s" % ( movieplugin.movie_id, i) logFile.write( "Test error: %s: Value expected but nothing returned.\nKey: %s\n\n" % (movieplugin.movie_id, i)) result = False else: if results.has_key(i): if isinstance(results[i], int) and results[i] == 0: continue if not isinstance(results[i], int) and len(results[i]) < 1: continue print "Test error: %s: No value expected but something returned.\nKey: %s\nValue: %s" % ( movieplugin.movie_id, i, results[i]) logFile.write( "Test error: %s: No value expected but something returned.\nKey: %s\nValue: %s\n\n" % (movieplugin.movie_id, i, results[i])) result = False else: if not results.has_key(i): print "Test error: %s: Value expected but nothing returned.\nKey: %s" % ( movieplugin.movie_id, i) logFile.write( "Test error: %s: Value expected but nothing returned.\nKey: %s\n\n" % (movieplugin.movie_id, i)) result = False else: if not results[i] == i_val: print "Test error: %s: Wrong value returned.\nKey: %s\nValue expected: %s\nValue returned: %s" % ( movieplugin.movie_id, i, i_val, results[i]) logFile.write( "Test error: %s: Wrong value returned.\nKey: %s\nValue expected: %s\nValue returned: %s\n\n" % (movieplugin.movie_id, i, i_val, results[i])) result = False except: log.exception(i + ' - ' + str(i_val) + ' - ' + str(results[i]) + ' - ' + str(movieplugin)) result = False return result
def initialize(self): self.page = gutils.convert_entities(self.page) self.cast_page = self.open_page(url=self.url + '/fullcredits') self.cast_page = gutils.convert_entities(self.cast_page) self.plot_page = self.open_page(url=self.url + '/plotsummary') self.plot_page = gutils.convert_entities(self.plot_page)
def initialize(self): self.page = gutils.convert_entities(self.page) self.page = self.page.replace(u'\x93', u'"') self.page = self.page.replace(u'\x94', u'"') self.page = self.page.replace(u'\x96', u'-')
def get_plot(self): self.plot = gutils.trim(self.plot_page, '<div id="swiki.2.1">', '</div>') self.plot = gutils.convert_entities(self.plot)
def populate_with_results(self): w = self.widgets['add'] m_id = None if self.founded_results_id: log.info("selected id: %s", self.founded_results_id) m_id = self.founded_results_id else: self.founded_results_id = 0 treeselection = self.widgets['results']['treeview'].get_selection() (tmp_model, tmp_iter) = treeselection.get_selected() if tmp_iter is None: return False m_id = tmp_model.get_value(tmp_iter, 0) self.treemodel_results.clear() self.widgets['results']['window'].hide() plugin_name = 'PluginMovie' + self.active_plugin plugin = __import__(plugin_name) self.movie = plugin.Plugin(m_id) self.movie.locations = self.locations self.movie.config = self.config fields_to_fetch = [ 'o_title', 'title', 'director', 'plot', 'cast', 'country', 'genre', 'classification', 'studio', 'o_site', 'site', 'trailer', 'year', 'notes', 'runtime', 'image', 'rating', 'screenplay', 'cameraman', 'resolution', 'barcode' ] # remove fields that user doesn't want to fetch: (see preferences window) fields_to_fetch = [ i for i in fields_to_fetch if self.config.get("s_%s" % i, True, section='add') ] if w['cb_only_empty'].get_active(): # only empty fields details = get_details(self) fields_to_fetch = [ i for i in fields_to_fetch if details[i] is None or details[i] == 0.0 ] self.movie.fields_to_fetch = fields_to_fetch if not self.movie.get_movie(w['window']): return None self.movie.parse_movie() if 'year' in fields_to_fetch: w['year'].set_value(int(self.movie.year)) fields_to_fetch.pop(fields_to_fetch.index('year')) if 'runtime' in fields_to_fetch: w['runtime'].set_value(int(self.movie.runtime)) fields_to_fetch.pop(fields_to_fetch.index('runtime')) if 'cast' in fields_to_fetch: cast_buffer = w['cast'].get_buffer() cast_buffer.set_text(gutils.convert_entities(self.movie.cast)) fields_to_fetch.pop(fields_to_fetch.index('cast')) if 'plot' in fields_to_fetch: plot_buffer = w['plot'].get_buffer() plot_buffer.set_text(gutils.convert_entities(self.movie.plot)) fields_to_fetch.pop(fields_to_fetch.index('plot')) if 'notes' in fields_to_fetch: notes_buffer = w['notes'].get_buffer() notes_buffer.set_text(gutils.convert_entities(self.movie.notes)) fields_to_fetch.pop(fields_to_fetch.index('notes')) if 'rating' in fields_to_fetch: if self.movie.rating: w['rating_slider'].set_value(float(self.movie.rating)) fields_to_fetch.pop(fields_to_fetch.index('rating')) if 'resolution' in fields_to_fetch: w['resolution'].get_child().set_text( gutils.convert_entities(self.movie.resolution)) fields_to_fetch.pop(fields_to_fetch.index('resolution')) # poster if 'image' in fields_to_fetch: w['image'].set_text('') if self.movie.image: image = os.path.join(self.locations['temp'], "poster_%s.jpg" % self.movie.image) try: handler = self.Image.set_from_file(image) pixbuf = self.Image.get_pixbuf() w['picture'].set_from_pixbuf(pixbuf.scale_simple(100, 140, 3)) w['image'].set_text(self.movie.image) w['aremove_poster'].set_sensitive(True) except: image = gutils.get_defaultimage_fname(self) handler = self.Image.set_from_file(image) w['picture'].set_from_pixbuf(self.Image.get_pixbuf()) w['aremove_poster'].set_sensitive(False) else: image = gutils.get_defaultimage_fname(self) handler = self.Image.set_from_file(image) Pixbuf = self.Image.get_pixbuf() w['picture'].set_from_pixbuf(Pixbuf) w['aremove_poster'].set_sensitive(False) fields_to_fetch.pop(fields_to_fetch.index('image')) # other fields for i in fields_to_fetch: w[i].set_text(gutils.convert_entities(self.movie[i]))
class ExportPlugin(Base): name = 'HTML' description = _('Plugin exports data using templates') author = 'Piotr Ożarowski' email = '*****@*****.**' version = '4.0' #==[ configuration - default values ]==========={{{ settings = { 'sorting': 'movies_title', 'sorting2': 'ASC', 'export_dir': '', 'template': 2, 'title': _("Griffith's movies list"), 'style': 0, 'custom_style': False, 'custom_style_file': None, 'split_num': 50, # split into x files/pages 'split_by': 1, # 0==files, 1==movies 'poster_convert': False, # dont convert 'poster_height': 200, 'poster_width': 150, 'poster_mode': 'RGB', # RGB == color, L == black and white 'poster_format': 'jpeg' } fields = { 'movies_cast': False, 'movies_classification': False, 'movies_country': True, 'movies_genre': True, 'movies_director': True, 'movies_image': True, 'movies_o_site': True, 'movies_site': True, 'movies_trailer': True, 'movies_loaned': False, 'movies_media_num': True, 'movies_number': True, 'movies_o_title': True, 'movies_plot': False, 'movies_rating': True, 'movies_runtime': True, 'movies_studio': False, 'movies_seen': True, 'movies_title': True, 'movies_year': True, 'movies_notes': False, 'movies_screenplay': False, 'movies_cameraman': False, 'movies_width': False, 'movies_height': False, 'movies_barcode': False, # 'movies_region' : False, # 'movies_layers' : False, # 'movies_condition' : False, # 'movies_color' : False, # 'movies_volume_id' : False, # 'movies_collection_id' : False, 'media_name': True, 'collections_name': True, 'volumes_name': True, # 'acodecs_name' : True, 'vcodecs_name': True, } fields_as_columns = { 'movies_cast': 'cast', 'movies_classification': 'classification', 'movies_country': 'country', 'movies_genre': 'genre', 'movies_director': 'director', 'movies_image': 'poster_md5', 'movies_o_site': 'o_site', 'movies_site': 'site', 'movies_trailer': 'trailer', 'movies_loaned': 'loaned', 'movies_media_num': 'media_num', 'movies_number': 'number', 'movies_o_title': 'o_title', 'movies_plot': 'plot', 'movies_rating': 'rating', 'movies_runtime': 'runtime', 'movies_studio': 'studio', 'movies_seen': 'seen', 'movies_title': 'title', 'movies_year': 'year', 'movies_notes': 'notes', 'movies_screenplay': 'screenplay', 'movies_cameraman': 'cameraman', 'movies_width': 'width', 'movies_height': 'height', 'movies_barcode': 'barcode', # 'movies_region' : 'region', # 'movies_layers' : 'layers', # 'movies_condition' : 'condition', # 'movies_color' : 'color', # 'movies_volume_id' : 'volume_id', # 'movies_collection_id' : 'collection_id', 'media_name': 'name', 'collections_name': 'name', 'volumes_name': 'name', # 'acodecs_name' : 'name', 'vcodecs_name': 'name', } names = { _('Cast'): 'movies_cast', _('Classification'): 'movies_classification', _('Country'): 'movies_country', _('Director'): 'movies_director', _('Genre'): 'movies_genre', _('Image'): 'movies_image', _('Official site'): 'movies_o_site', _('Site'): 'movies_site', _('Trailer'): 'movies_trailer', _('Loaned'): 'movies_loaned', _('Discs'): 'movies_media_num', _('Number'): 'movies_number', _('Original Title'): 'movies_o_title', _('Plot'): 'movies_plot', _('Rating'): 'movies_rating', _('Runtime'): 'movies_runtime', _('Studio'): 'movies_studio', _('Seen it'): 'movies_seen', _('Title'): 'movies_title', _('Year'): 'movies_year', _('Notes'): 'movies_notes', _('Screenplay'): 'movies_screenplay', _('Cameraman'): 'movies_cameraman', _('Width'): 'movies_width', _('Height'): 'movies_height', _('Barcode'): 'movies_barcode', # _('Region') : 'movies_region', # _('Layers') : 'movies_layers', # _('Condition') : 'movies_condition', # _('Color') : 'movies_color', # _('Volume') : 'movies_volume_id', # _('Collection') : 'movies_collection_id', _('Media'): 'media_name', _('Collection'): 'collections_name', _('Volume'): 'volumes_name', # _('Audio codecs') : 'acodecs_name', _('Video codec'): 'vcodecs_name', } #}}} def initialize(self): #{{{ self.fields_to_export = [] for field in ExportPlugin.fields: if field == 'movies_image': self.fields_to_export.append('movies.poster_md5') else: pos = field.find('_') self.fields_to_export.append("%s.%s" % (field[:pos], field[pos + 1:])) self.widgets = {} self.style_list = {} self.templates = self.make_template_list() # glade gf = os.path.join(self.locations['glade'], 'exporthtml.glade') self.load_configuration() self.define_widgets(gtk.glade.XML(gf)) self.fill_widgets() return True #}}} def load_configuration(self): #{{{ # persist config if self.config is not None: config = self.settings for name, value in config.items(): try: tmp = self.config.get(name, value, section='export-html') if isinstance(value, bool): config[name] = bool(int(tmp)) elif isinstance(value, int): config[name] = int(tmp) else: config[name] = tmp except: pass selected_fields = self.config.get('selected_fields', '', section='export-html') if selected_fields: for name in self.fields: self.fields[name] = False selected_fields = selected_fields.split(',') for selected_field in selected_fields: if selected_field in self.fields: self.fields[selected_field] = True #}}} def run(self): pass def get_node_value_by_language(self, parent, name, language='en'): #{{{ nodes = parent.getElementsByTagName(name) for node in nodes: if node.parentNode != parent: continue elif node.attributes.get('xml:lang') is not None: if node.attributes.get('xml:lang').value == language: return node.firstChild.nodeValue else: # set default value in case node has no xml:lang attribute value = node.firstChild.nodeValue return value #}}} def make_template_list(self): #{{{ language = 'en' if os.environ.has_key('LANG'): language = os.environ['LANG'][:2] templates = {} j = 0 # number of templates dirName = os.path.join(self.locations['share'], 'export_templates') items = os.listdir(dirName) items.sort() for i in items: fileName = os.path.join(dirName, i) if not os.path.islink(fileName) and os.path.isdir(fileName): # clear previous data doc = None styles = {} tpl_name = None tpl_author = None tpl_email = None tpl_version = None tpl_ext = None tpl_desc = None try: doc = minidom.parse(os.path.join(fileName, 'config.xml')) except: log.info( "Can't parse configuration file for template: %s" % fileName) continue for template in doc.getElementsByTagName('template'): tpl_name = self.get_node_value_by_language( template, 'name', language) tpl_author = template.getElementsByTagName( 'author')[0].firstChild.nodeValue tpl_email = template.getElementsByTagName( 'email')[0].firstChild.nodeValue tpl_version = template.getElementsByTagName( 'version')[0].firstChild.nodeValue tpl_ext = template.getElementsByTagName( 'extension')[0].firstChild.nodeValue tpl_desc = self.get_node_value_by_language( template, 'description', language) k = 0 # number of styles try: styles_list = template.getElementsByTagName( 'styles')[0].getElementsByTagName('style') for style in styles_list: tpl_style_name = self.get_node_value_by_language( style, 'name', language) tpl_style_file = style.getElementsByTagName( 'file')[0].firstChild.nodeValue # get preview if available try: tpl_style_preview = style.getElementsByTagName( 'preview')[0].firstChild.nodeValue except: tpl_style_preview = None styles[k] = { 'name': tpl_style_name, 'file': tpl_style_file, 'preview': tpl_style_preview } k = k + 1 except: styles = None if tpl_name == '': continue templates[j] = { 'dir': i, 'name': tpl_name, 'author': tpl_author, 'email': tpl_email, 'version': tpl_version, 'ext': tpl_ext, 'desc': tpl_desc, 'styles': styles } j = j + 1 return templates #}}} #==[ widgets ]=================================={{{ def define_widgets(self, glade_file): get = lambda x: glade_file.get_widget(x) self.widgets = { 'window': get('w_eh'), 'fcw': get('fcw'), 'box_include_1': get('box_include_1'), 'box_include_2': get('box_include_2'), 'box_include_3': get('box_include_3'), 'sb_split_num': get('sb_split_num'), 'rb_split_files': get('rb_split_files'), 'rb_split_movies': get('rb_split_movies'), 'entry_header': get('entry_header'), 'cb_custom_style': get('cb_custom_style'), 'cb_reverse': get('cb_reverse'), 'combo_style': get('combo_style'), 'combo_sortby': get('combo_sortby'), 'combo_theme': get('combo_theme'), 'fcb_custom_style_file': get('fcb_custom_style_file'), 'l_tpl_author': get('l_tpl_author'), 'l_tpl_email': get('l_tpl_email'), 'l_tpl_version': get('l_tpl_version'), 'l_tpl_desc': get('l_tpl_desc'), 'image_preview': get('image_preview'), 'vb_posters': get('vb_posters'), 'sb_height': get('sb_height'), 'sb_width': get('sb_width'), 'cb_black': get('cb_black'), 'combo_format': get('combo_format'), 'cb_convert': get('cb_convert'), } # define handlers for general events glade_file.signal_autoconnect({ 'on_export_button_clicked': self.export_data, 'on_rb_split_files_toggled': self.on_rb_split_files_toggled, 'on_rb_split_movies_toggled': self.on_rb_split_movies_toggled, 'on_cancel_button_clicked': self.on_quit, 'on_cb_data_toggled': self.on_cb_data_toggled, 'on_cb_custom_style_toggled': self.on_cb_custom_style_toggled, 'on_fcb_custom_style_file_activated': self.on_fcb_custom_style_file_activated, 'on_combo_style_changed': self.on_combo_style_changed, 'on_combo_theme_changed': self.on_combo_theme_changed, 'on_cb_convert_toggled': self.on_cb_convert_toggled, }) def fill_widgets(self): # themes for i in self.templates: self.widgets['combo_theme'].insert_text(i, self.templates[i]['name']) # sortby combo keys = self.names.keys() keys.sort() j = 0 pos_o_title = 0 for i in keys: self.widgets['combo_sortby'].append_text(i) if self.names[i] == self.settings['sorting']: pos_o_title = j j = j + 1 self.widgets['combo_sortby'].set_wrap_width(3) # include data j = 0 k = math.ceil(len(self.names) / float(3)) for i in keys: j = j + 1 field = self.names[i] self.widgets['cb_' + field] = gtk.CheckButton(i) self.widgets['cb_' + field].set_name("cb_%s" % field) self.widgets['cb_' + field].connect('toggled', self.on_cb_data_toggled) self.widgets['cb_' + field].set_active(self.fields[field]) if j <= k: self.widgets['box_include_1'].add(self.widgets["cb_%s" % field]) elif j <= 2 * k: self.widgets['box_include_2'].add(self.widgets["cb_%s" % field]) else: self.widgets['box_include_3'].add(self.widgets["cb_%s" % field]) self.widgets['box_include_1'].show_all() self.widgets['box_include_2'].show_all() self.widgets['box_include_3'].show_all() # set defaults -------------------------------- self.widgets['entry_header'].set_text(self.settings['title']) self.widgets['combo_sortby'].set_active(pos_o_title) if self.settings['sorting2'] == 'DESC': self.widgets['cb_reverse'].set_active(True) else: self.widgets['cb_reverse'].set_active(False) # template and theme style = self.settings[ 'style'] # save it temporary because change of the template set it 0 self.widgets['combo_theme'].set_active(self.settings['template']) self.widgets['combo_style'].set_active(style) self.widgets['cb_custom_style'].set_active( self.settings['custom_style']) if self.settings['custom_style_file']: self.widgets['fcb_custom_style_file'].set_filename( self.settings['custom_style_file']) # spliting self.widgets['sb_split_num'].set_value(self.settings['split_num']) if self.settings['split_by'] == 0: self.widgets['rb_split_files'].set_active(True) else: self.widgets['rb_split_movies'].set_active(True) # posters self.widgets['combo_format'].set_active(0) if self.settings['poster_format'] == 'PNG': self.widgets['combo_format'].set_active(1) elif self.settings['poster_format'] == 'GIF': self.widgets['combo_format'].set_active(2) if self.settings['poster_convert'] and self.settings[ 'poster_convert'] == True: self.widgets['cb_convert'].set_active(True) self.widgets['vb_posters'].set_sensitive(True) else: self.widgets['cb_convert'].set_active(False) self.widgets['vb_posters'].set_sensitive(False) self.widgets['sb_height'].set_value(self.settings['poster_height']) self.widgets['sb_width'].set_value(self.settings['poster_width']) if self.settings['poster_mode'] == 'L': self.widgets['cb_black'].set_active(True) # destination dir if self.settings['export_dir']: self.widgets['fcw'].set_current_folder(self.settings['export_dir']) #}}} #==[ callbacks ]================================{{{ # buttons: def on_quit(self, widget=None): self.widgets['window'].destroy() # data tab -------------------------------------#{{{ def on_rb_split_files_toggled(self, widget): self.settings['split_by'] = 0 # files def on_rb_split_movies_toggled(self, widget): self.settings['split_by'] = 1 # movies # export frame def on_cb_data_toggled(self, widget): self.fields[gutils.after(widget.get_name(), 'cb_')] = widget.get_active() # posters frame def on_cb_convert_toggled(self, widget): active = widget.get_active() self.settings['poster_convert'] = active if not active: self.widgets['vb_posters'].set_sensitive(False) else: self.widgets['vb_posters'].set_sensitive(True) #}}} # template tab ---------------------------------#{{{ def on_combo_theme_changed(self, widget): old_id = self.settings['template'] tpl_id = widget.get_active() self.settings['template'] = tpl_id # fill authors data self.widgets['l_tpl_author'].set_markup( "<i>%s</i>" % self.templates[tpl_id]['author']) self.widgets['l_tpl_email'].set_markup("<i>%s</i>" % self.templates[tpl_id]['email']) self.widgets['l_tpl_email'].set_selectable(True) self.widgets['l_tpl_version'].set_markup( "<i>%s</i>" % self.templates[tpl_id]['version']) self.widgets['l_tpl_desc'].set_markup("<i>%s</i>" % self.templates[tpl_id]['desc']) # remove old style list self.widgets['combo_style'].get_model().clear() # ... and add new if self.templates[tpl_id]['styles'] is not None: for i in self.templates[tpl_id]['styles']: self.widgets['combo_style'].insert_text( i, self.templates[tpl_id]['styles'][i] ['name']) # template name self.widgets['combo_style'].set_active(0) else: self.settings['style'] = None self.widgets['image_preview'].set_from_stock( gtk.STOCK_MISSING_IMAGE, gtk.ICON_SIZE_LARGE_TOOLBAR) def on_combo_style_changed(self, widget): self.settings['style'] = widget.get_active() self.widgets['cb_custom_style'].set_active(False) preview_file = None tpl_id = self.settings['template'] template_dir = os.path.join(self.locations['share'], 'export_templates', self.templates[tpl_id]['dir']) if self.settings['style'] > -1: preview_file = self.templates[self.settings['template']]['styles'][ self.settings['style']]['preview'] if preview_file is not None: preview_file = os.path.join(template_dir, preview_file) if preview_file is not None and not os.path.isfile(preview_file): preview_file = os.path.join( template_dir, 'preview.jpg') # try default preview image if not os.path.isfile(preview_file): preview_file = None if preview_file is not None: self.widgets['image_preview'].set_from_file(preview_file) else: self.widgets['image_preview'].set_from_stock( gtk.STOCK_MISSING_IMAGE, gtk.ICON_SIZE_LARGE_TOOLBAR) self.widgets['image_preview'].show() def on_cb_custom_style_toggled(self, widget): if widget.get_active(): self.settings['custom_style'] = True self.widgets['image_preview'].hide() else: self.settings['custom_style'] = False self.widgets['image_preview'].show() def on_fcb_custom_style_file_activated(self, widget): self.settings['custom_style_file'] = widget.get_filename() self.widgets['cb_custom_style'].set_active(True) #}}} }}} def make_navigation(self, pages, current): #{{{ if pages > 1: # navigation needed tpl_id = self.settings['template'] t = '<div class="navi">\n\t<p id="prev">' if current > 1: t += '<a href="./page_%s.%s">%s</a>' % \ (str(current-1), self.templates[tpl_id]['ext'], _('previous')) else: # first page t += _('previous') t += "</p>\n" for i in range(1, pages + 1): if i == current: t += '\t<p id="current">%s</p>\n' % str(i) else: t +='\t<p><a href="./page_%s.%s">%s</a></p>\n' % \ (str(i), self.templates[tpl_id]['ext'], str(i)) t += '\t<p id="next">' if pages > current: t +='<a href="./page_%s.%s">%s</a>' % \ (str(current+1), self.templates[tpl_id]['ext'], _('next')) else: # last page t += _('next') t += "</p>\n</div>" return t else: return '' #}}} def fill_template(self, template, field, data='', title='', remove=False): #{{{ start = template.find('<@' + field + '>') end = template.find('</@' + field + '>', start + 1) if start > -1 and end > -1: if remove == True: return template[:start] + template[end + 4 + len(field):] else: tmp = gutils.trim(template, '<@' + field + '>', '</@' + field + '>') tmp = tmp.replace("@DATA@", data) tmp = tmp.replace("@TITLE@", title) tmp = template[:start] + tmp + template[end + 4 + len(field):] if tmp.find('<@' + field + '>') != -1: tmp = self.fill_template(tmp, field, data, title, remove) return tmp else: return template #}}} def select(self): #{{{ config = self.settings # sort order TODO: update self.search_conditions["sort_by"] tmp = config['sorting'].split('_') sort_column = "%s.%s" % (tmp[0], '_'.join(tmp[1:])) if config['sorting2'] == 'ASC': sort_column += ' ASC' else: sort_column += ' DESC' self.search_conditions["sort_by"] = (sort_column, ) query = self.get_query() return query.execute() #}}} #==[ main function ]============================{{{ def export_data(self, widget): """Main exporting function""" config = self.settings fields = self.fields tid = config['template'] # get data from widgets self.settings['export_dir'] = self.widgets['fcw'].get_filename() self.settings['title'] = self.widgets['entry_header'].get_text( ).decode('utf-8') self.settings['sorting'] = self.names[ self.widgets['combo_sortby'].get_active_text().decode('utf-8')] if self.widgets['cb_reverse'].get_active(): self.settings['sorting2'] = 'DESC' else: self.settings['sorting2'] = 'ASC' self.settings['split_num'] = self.widgets[ 'sb_split_num'].get_value_as_int() self.settings['poster_height'] = self.widgets[ 'sb_height'].get_value_as_int() self.settings['poster_width'] = self.widgets[ 'sb_width'].get_value_as_int() if self.widgets['cb_black'].get_active(): self.settings['poster_mode'] = 'L' else: self.settings['poster_mode'] = 'RGB' self.settings['poster_format'] = self.widgets[ 'combo_format'].get_active_text() # persist config if self.config is not None: for name, value in config.items(): self.config.set(name, value, section='export-html') selected_fields = '' for name, value in self.fields.items(): if value: selected_fields = selected_fields + name + ',' self.config.set('selected_fields', selected_fields, section='export-html') self.config.save() # create directories if not config['export_dir']: log.info("Error: Folder name not set!") return 1 if not os.path.isdir(config['export_dir']): try: os.mkdir(config['export_dir']) except: gutils.error(_("Can't create %s!") % config['export_dir']) return 2 data_path = os.path.join(self.locations['share'], 'export_templates', self.templates[tid]['dir'], 'data') if os.path.isdir(data_path): try: gutils.copytree(data_path, config['export_dir']) except Exception, err: gutils.warning(str(err)) if fields['movies_image']: # import modules needed later # modules are needed at least to convert griffith.png to nopic.(gif|jpeg|png) from PIL import Image # py2exe problem workaround: if os.name == 'nt' or os.name.startswith('win'): # win32, win64 from PIL import PngImagePlugin from PIL import GifImagePlugin from PIL import JpegImagePlugin Image._initialized = 2 if not config['poster_convert']: config['poster_format'] = 'jpeg' # replace 'jpeg' posters_dir = os.path.join(config['export_dir'], 'posters') if os.path.isdir(posters_dir): if gutils.question( _("Directory %s already exists.\nDo you want to overwrite it?" ) % posters_dir, self.widgets['window']): try: shutil.rmtree(posters_dir) except: gutils.error( _("Can't remove %s!") % config['export_dir']) return 3 else: return 4 try: os.mkdir(posters_dir) except: gutils.error(_("Can't create %s!") % posters_dir) return 5 if config['custom_style']: if config['custom_style_file'] is not None and os.path.isfile( config['custom_style_file']): try: shutil.copy(config['custom_style_file'], config['export_dir']) except: gutils.warning(_("Can't copy %s!") % style_file) config['custom_style'] = False style = os.path.split(self.settings['custom_style_file'])[1] else: config['custom_style'] = False if config['style'] is not None and config['custom_style'] == False: style = self.templates[tid]['styles'][config['style']]['file'] style_path = os.path.join(self.locations['share'], 'export_templates', self.templates[tid]['dir'], style) try: shutil.copy(style_path, config['export_dir']) except: gutils.warning(_("Can't copy %s!") % style_path) # select exported movies exported_movies = self.select().fetchall() if self.settings['sorting'] in ('movies_title', 'movies_o_title'): # re-sorting movies case-insensitive and respect the current locale setting # if sorting by title or original title is selected import locale locale.setlocale(locale.LC_ALL, "") exported_movies.sort(cmp = locale.strcoll, \ key = lambda k: k[self.settings['sorting']] and k[self.settings['sorting']].lower() or '', \ reverse = self.settings['sorting2']=='DESC') number_of_exported_movies = len(exported_movies) if config['split_by'] == 1: # split by number of movies per page self.entries_per_page = config['split_num'] else: # split by number of pagess if number_of_exported_movies < config['split_num']: self.entries_per_page = 1 else: self.entries_per_page = int(number_of_exported_movies / config['split_num']) # calculate number of files to be created (pages) self.pages = int( math.ceil( float(number_of_exported_movies) / self.entries_per_page)) template_dir = os.path.join(self.locations['share'], 'export_templates', self.templates[tid]['dir']) try: filename = 'page.tpl' tpl_header = file(os.path.join(template_dir, filename), "r").read() except: gutils.error(_("Can't open %s!") % filename) return False tpl_header = self.fill_template(tpl_header, 'header', config['title']) try: tpl_header = self.fill_template(tpl_header, 'style', style) except: pass tmp = _('Document generated by Griffith v') + version.pversion + \ ' - Copyright (C) ' + version.pyear + ' ' + version.pauthor + ' - ' + \ _('Released Under the GNU/GPL License') tmp = gutils.html_encode(tmp) tmp = tmp.replace('@', ' at ') # prevent spam tpl_header = self.fill_template(tpl_header, 'copyright', tmp) tmp = None tpl_header = self.fill_template(tpl_header, 'pages', self.pages) # count exported fields rowspan = 0 for i in fields: if fields[i] == True: rowspan = rowspan + 1 rowspan = str(rowspan) tpl_header = self.fill_template(tpl_header, 'rowspan', rowspan) # split template tpl_tail = gutils.after(tpl_header, '<!-- /ITEMS -->') tpl_item = gutils.trim(tpl_header, '<!-- ITEMS -->', '<!-- /ITEMS -->') tpl_header = gutils.before(tpl_header, '<!-- ITEMS -->') # fill header for j in self.names: if self.fields[self.names[j]] == True: tpl_header = self.fill_template(tpl_header, self.names[j], '', j) else: tpl_header = self.fill_template(tpl_header, self.names[j], remove=True) # check if line break needs conversion if tpl_header.upper().find('XHTML 1.0') > -1: linebreak_replacement = '<br />' else: linebreak_replacement = None item = 1 # item's position on page (1 - first, ...) i = 1 page = 1 # page number for row in exported_movies: # fill items {{{ # check if new file has to be created if item == 1: filename = os.path.join( config['export_dir'], 'page_%s.' % page + self.templates[tid]['ext']) try: exported_file = file(filename, 'w') except: gutils.error(_("Can't create %s!") % filename) return False tmp2 = tpl_header + '' exported_file.write(self.fill_template(tmp2, 'page', str(page))) tmp2 = None # --------------------------------------------- tmp = tpl_item + '' # a copy (not a reference!) tmp = self.fill_template(tmp, 'id', str(item)) tmp = self.fill_template(tmp, 'item', str(i)) for j in self.names: if self.fields[self.names[j]] == True: if self.names[j] == 'movies_image': if row['movies_poster_md5']: #image = row['movies_poster_md5'] + '.' + config['poster_format'].lower() image = "%d.%s" % (row['movies_number'], config['poster_format'].lower()) tmp = self.fill_template(tmp, self.names[j], image, j) else: tmp = self.fill_template( tmp, self.names[j], 'nopic.' + config['poster_format'].lower(), j) elif row[self.names[j]] is None: tmp = self.fill_template(tmp, self.names[j], '', j) elif row[self.names[j]] is True: tmp = self.fill_template(tmp, self.names[j], _('Yes'), j) elif row[self.names[j]] is False: tmp = self.fill_template(tmp, self.names[j], _('No'), j) else: try: data = str(row[self.names[j]]).encode('utf-8') if linebreak_replacement is not None: data = data.replace('\r\n', linebreak_replacement) data = data.replace('\n', linebreak_replacement) tmp = self.fill_template(tmp, self.names[j], data, j) except UnicodeDecodeError: log.info( "Unicode Decode Error occurred while decoding %s (movie number: %s)" % (self.names[j], row['movies_number'])) data = str(row[self.names[j]]) if linebreak_replacement is not None: data = data.replace('\r\n', linebreak_replacement) data = data.replace('\n', linebreak_replacement) tmp = self.fill_template(tmp, self.names[j], data, j) except Exception, ex: log.info( "Error occurred while decoding %s (movie number: %s)" % (self.names[j], row['movies_number'])) else: tmp = self.fill_template(tmp, self.names[j], remove=True) tmp = gutils.convert_entities(tmp) exported_file.write(tmp) tmp = None # --------------------------------------------- # copy poster if fields['movies_image']: if row['movies_poster_md5']: image_file_src = gutils.get_image_fname( row['movies_poster_md5'], self.db) image_file_dst = os.path.join( posters_dir, "%d.%s" % (row['movies_number'], config['poster_format'].lower())) if not config['poster_convert']: # copy file try: shutil.copy(image_file_src, image_file_dst) except: log.info("Can't copy %s", image_file_src) else: # convert posters try: im = Image.open(image_file_src, 'r').convert(config['poster_mode']) im.thumbnail((config['poster_width'], config['poster_height']), Image.ANTIALIAS) im.save(image_file_dst, config['poster_format']) except: log.info("Can't convert %s", image_file_src) # close file if last item if ((page - 1) * self.entries_per_page) + item == number_of_exported_movies: tmp2 = tpl_tail + '' exported_file.write( self.fill_template(tmp2, 'navigation', self.make_navigation(self.pages, page))) exported_file.close() tmp2 = None # close file if last item in page elif item == self.entries_per_page: tmp2 = tpl_tail + '' exported_file.write( self.fill_template(tmp2, 'navigation', self.make_navigation(self.pages, page))) exported_file.close() page = page + 1 item = 1 tmp2 = None else: item = item + 1 i = i + 1
def sub_search(self): self.page = gutils.regextrim(self.page, ' resultado[s]*[)]', 'Sugerencias Para Mejorar Sus Resultados'); self.page = self.page.decode('iso-8859-15') # correction of all &#xxx entities self.page = gutils.convert_entities(self.page)
def search(self, parent_window): if not self.open_search(parent_window): return None self.page = gutils.convert_entities(self.page) return self.page