1# -*- coding: UTF-8 -*- 2 3__revision__ = '$Id$' 4 5# Copyright (c) 2007-2009 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 re 27import string 28 29plugin_name = "DVD Empire" 30plugin_description = "International Retailer of DVD Movies" 31plugin_url = "www.dvdempire.com" 32plugin_language = _("English") 33plugin_author = "Michael Jahn" 34plugin_author_email = "<mikej06@hotmail.com>" 35plugin_version = "1.2" 36 37class Plugin(movie.Movie): 38 def __init__(self, id): 39 self.encode = 'iso-8859-1' 40 self.movie_id = id 41 self.url = "http://www.dvdempire.com" + str(self.movie_id) 42 43 def get_image(self): 44 tmp_page = gutils.trim(self.page, 'id="Boxcover"', '</div>') 45 self.image_url = gutils.trim(tmp_page, 'href="', '"') 46 47 def get_o_title(self): 48 self.o_title = gutils.strip_tags(gutils.trim(self.page, '<title>', '(')) 49 50 def get_title(self): 51 self.title = gutils.strip_tags(gutils.trim(self.page, '<title>', '(')) 52 53 def get_director(self): 54 self.director = gutils.trim(self.page, '<h3>Director</h3>', '</div>') 55 self.director = self.director.replace('</li><li', '</li>, <li') 56 self.director = self.director.replace(' ', '') 57 self.director = self.director.replace('•', '') 58 59 def get_plot(self): 60 self.plot = gutils.strip_tags(gutils.trim(self.page, 'Synopsis</h2>', '</div>')) 61 self.plot = self.plot.replace('\x93', '"') 62 self.plot = self.plot.replace('\x84', '"') 63 64 def get_year(self): 65 self.year = gutils.strip_tags(gutils.after(gutils.trim(self.page, 'Production Year', '<br'), '>')) 66 67 def get_runtime(self): 68 self.runtime = '' 69 tmp = gutils.strip_tags(gutils.trim(self.page, 'Length', '<br')) 70 #1 hrs. 59 mins. 71 try: 72 self.runtime = int(gutils.before(tmp, 'hrs')) * 60 + int(gutils.trim(tmp, '.', 'mins')) 73 except: 74 self.runtime = '' 75 76 def get_genre(self): 77 tmp = gutils.strip_tags(gutils.trim(self.page, '<h2>Categories</h2>', '</p>')) 78 tmp = tmp.replace('\r\n', '') 79 self.genre = re.sub('[ \t]+', ' ', tmp) 80 81 def get_cast(self): 82 self.cast = gutils.trim(self.page, '<h3>Cast</h3>', '</div>') 83 self.cast = self.cast.replace('<br>', '\n') 84 self.cast = self.cast.replace('<br />', '\n') 85 self.cast = self.cast.replace(' ', '') 86 self.cast = self.cast.replace('•', '') 87 self.cast = self.cast.replace('•', '') 88 self.cast = self.cast.replace('</li><li', '</li>\n<li') 89 self.cast = self.cast.replace('</li><!-- non-headliners --><li', '</li>\n<li') 90 self.cast = gutils.strip_tags(self.cast) 91 92 def get_classification(self): 93 self.classification = gutils.strip_tags(gutils.trim(self.page, 'Rating</strong>', '<br')) 94 95 def get_studio(self): 96 self.studio = gutils.strip_tags(gutils.trim(self.page, 'Studio</strong>', '<br')) 97 98 def get_o_site(self): 99 self.o_site = "" 100 101 def get_site(self): 102 self.site = self.url 103 104 def get_trailer(self): 105 self.trailer = "" 106 107 def get_country(self): 108 self.country = "" 109 110 def get_rating(self): 111 self.rating = gutils.clean(gutils.trim(self.page, 'Overall Rating:', ' out of')) 112 try: 113 tmp_float = float(self.rating) 114 tmp_float = round(2 * tmp_float, 0) 115 self.rating = str(tmp_float) 116 except: 117 self.rating = '0' 118 119 def get_notes(self): 120 self.notes = '' 121 tmp_page = gutils.trim(self.page, '<h3>Features</h3>', '</p>') 122 tmp_page = tmp_page.replace('<br>', '\n') 123 tmp_page = tmp_page.replace('<br />', '\n') 124 tmp_page = gutils.strip_tags(tmp_page) 125 if tmp_page != '': 126 self.notes = self.notes + 'Features:\n' + tmp_page + '\n\n' 127 tmp_page = gutils.trim(self.page, 'Video</strong>', '<strong>') 128 tmp_page = tmp_page.replace('\r\n', '') 129 tmp_page = re.sub('[ \t]+', ' ', tmp_page) 130 tmp_page = tmp_page.replace('<br>', '\n') 131 tmp_page = tmp_page.replace('<br />', '\n') 132 tmp_page = gutils.strip_tags(tmp_page) 133 if tmp_page != '': 134 self.notes = self.notes + 'Video:' + tmp_page 135 tmp_page = gutils.trim(self.page, 'Audio</strong>', '</div>') 136 tmp_page = tmp_page.replace('\r\n', '') 137 tmp_page = re.sub('[ \t]+', ' ', tmp_page) 138 tmp_page = tmp_page.replace('<br>', '\n') 139 tmp_page = tmp_page.replace('<br />', '\n') 140 tmp_page = tmp_page.replace('(more info)', '\n') 141 tmp_page = gutils.strip_tags(tmp_page) 142 if tmp_page != '': 143 self.notes = self.notes + 'Audio:' + tmp_page 144 145 def get_screenplay(self): 146 self.screenplay = gutils.strip_tags(gutils.trim(self.page, 'Writers</strong>', '<br')) 147 self.screenplay = self.screenplay.replace(' ', '') 148 self.screenplay = self.screenplay.replace('•', '') 149 150 def get_barcode(self): 151 self.barcode = gutils.trim(self.page, 'UPC Code</strong>', '<br') 152 153 154class SearchPlugin(movie.SearchMovie): 155 def __init__(self): 156 self.original_url_search = "http://www.dvdempire.com/allsearch/search?pageSize=100&q=" 157 self.translated_url_search = "http://www.dvdempire.com/allsearch/search?pageSize=100&q=" 158 self.encode = 'iso-8859-1' 159 160 def search(self,parent_window): 161 if not self.open_search(parent_window): 162 return None 163 return self.page 164 165 def get_searches(self): 166 split_pattern = re.compile('class="title"') 167 elements = split_pattern.split(self.page) 168 for index in range(1, len(elements), 1): 169 title_element = elements[index] 170 tmp_title = gutils.clean(gutils.strip_tags(gutils.trim(title_element, '>', '</a>'))) 171 tmp_title = string.replace(tmp_title, ' ', ' ') 172 tmp_title = string.replace(tmp_title, '&', '&') 173 tmp_title = string.replace(tmp_title, '"', '"') 174 if tmp_title != '': 175 self.ids.append(gutils.trim(elements[index], 'href="', '"')) 176 type = re.search('>Blu-ray</span>', title_element) 177 if type: 178 tmp_title = tmp_title + ' (Blu-ray)' 179 type = re.search('>DVD-Video</span>', title_element) 180 if type: 181 tmp_title = tmp_title + ' (DVD)' 182 self.titles.append(tmp_title) 183 184# 185# Plugin Test 186# 187class SearchPluginTest(SearchPlugin): 188 # 189 # Configuration for automated tests: 190 # dict { movie_id -> [ expected result count for original url, expected result count for translated url ] } 191 # 192 test_configuration = { 193 'Rocky Balboa' : [ 30, 30 ], 194 } 195 196class PluginTest: 197 # 198 # Configuration for automated tests: 199 # dict { movie_id -> dict { arribute -> value } } 200 # 201 # value: * True/False if attribute only should be tested for any value 202 # * or the expected value 203 # 204 test_configuration = { 205 '/1402424/meet-the-spartans-unrated-pit-of-death-edition-blu-ray.html' : { 206 'title' : 'Meet The Spartans: Unrated Pit Of Death Edition', 207 'o_title' : 'Meet The Spartans: Unrated Pit Of Death Edition', 208 'director' : 'Jason Friedberg, Aaron Seltzer', 209 'plot' : True, 210 'cast' : 'Carmen Electra\n\ 211Sean Maguire\n\ 212Ken Davitian', 213 'country' : False, 214 'genre' : 'Blu-ray, Comedy, Movies, Spoofs & Parodies', 215 'classification' : 'NR', 216 'studio' : '20th Century Fox', 217 'o_site' : False, 218 'site' : 'http://www.dvdempire.com/1402424/meet-the-spartans-unrated-pit-of-death-edition-blu-ray.html', 219 'trailer' : False, 220 'year' : 2008, 221 'notes' : 'Features:\n\ 222Audio Commentary By Cast And Crew\n\ 223Prepare For Thrusting Featurette\n\ 224Tour The Set With Ike Barinholtz Featurette\n\ 225Gag Reel\n\ 226Know Your Spartans Pop Culture Trivia Game\n\ 227Celebrity Kickoff Game\n\ 228Super Pit-Of-Death Ultimate Tactical Battle Challange Game\n\ 229Meet The Spartans: The Music\n\ 230Trivial Track\n\ 231Theatrical Trailers\n\ 232\n\ 233Video:\n\ 234 Widescreen 1.85:1 Color \n\ 235\n\ 236Audio:\n\ 237 French Dolby Digital Surround \n\ 238 Spanish Dolby Digital Surround \n\ 239 English DTS-HD MA 5.1', 240 'runtime' : 87, 241 'image' : True, 242 'rating' : 5, 243 'screenplay' : False, 244 'barcode' : '024543522614' 245 }, 246 } 247