def run(self): self._config.getLog().debug("ExternalSearchThread started"); while not self._stopped: (artist, album, cb, cb_arg) = self._queue.get(); if not artist and not album and not cb: self._stopped = True; else: assert(artist and cb); if album: query = artist.name + " " + album.name; else: query = artist.name; albumList = []; try: # Loop to get all the result "pages". An AmazonError kicks # us out of the loop. n = 1; while 1: results = amazon.searchByKeyword(query, product_line = "music", page = n); n += 1; for res in results: albumList.append(Album(res)); except amazon.NoLicenseKey, ex: assert(0); pass; except amazon.AmazonError, ex: # This is trown when there are no more result pages. pass; # Invlode the user callback with the results. cb(artist, album, albumList, cb_arg);
def run(self): while not self._stopped: (artist, album, cb, cb_arg) = self._queue.get() if not artist and not album and not cb: self._stopped = True else: assert (artist and cb) if album: query = artist.name + " " + album.name else: query = artist.name albumList = [] try: # Loop to get all the result "pages". An AmazonError kicks # us out of the loop. n = 1 while 1: results = amazon.searchByKeyword(query, product_line="music", page=n) n += 1 for res in results: albumList.append(AmazonAlbum(res)) except amazon.NoLicenseKey, ex: assert (0) pass except amazon.AmazonError, ex: # This is trown when there are no more result pages. pass # Invlode the user callback with the results. cb(artist, album, albumList, cb_arg)
def isbn(self, irc, msg, args, optlist, isbn): """[--url] <isbn> Returns the book matching the given ISBN number. If --url is specified, a link to amazon.com's page for the book will also be returned. """ url = False for (option, argument) in optlist: if option == 'url': url = True isbn = isbn.replace('-', '').replace(' ', '') attribs = { 'ProductName': 'title', 'Manufacturer': 'publisher', 'Authors': 'author', 'OurPrice': 'price', 'URL': 'url' } s = '%(title)s, written by %(author)s; published by ' \ '%(publisher)s; price: %(price)s%(url)s' channel = msg.args[0] bold = self.registryValue('bold', channel) region = self.registryValue('region', channel) try: book = amazon.searchByKeyword(isbn, locale=region) res = self._genResults(s, attribs, book, url, bold) if res: irc.reply(format('%L', res)) return except amazon.AmazonError, e: pass
def SearchByKeyword(repView, keywords=None, countryCode=None, category=None): """ Performs an amazon search by keyword and creates an AmazonCollection containing AmazonItem's for each product found that matches the search criteria (only retrieves the first 10 products). If an AmazonCollection already exists for the search criteria the method creates AmazonItem's for new products and adds them to the existing collection. The method can be used programatically or via user input. If no keywords, countryCode, and category variables are passed in, an Amazon Search By Keyword dialog is displayed for the user to choose the keywords, countryCode, and category. The method contacts the Amazon site specified by the countryCode and retrieves the products that match the search criteria. @type repView: A Repository.view @param repView: The repository view in which to create the AmazonItems' and AmazonCollection @type keywords: unicode @param keywords: The keywords to search on. If the value is None a dialog is displayed for the user to enter the information. @type countryCode: unicode @param countryCode: The countryCode of the amazon site to contact. If the value is None a dialog is displayed for the user to enter the information. @type category: unicode @param category: The category to search in. If the value is None a dialog is displayed for the user to enter the information. @rtype: AmazonCollection or None @return: An AmazonCollection containing AmazonItem's for each product or None if no products found or an error occurs. """ if keywords is None or countryCode is None or category is None: keywords, countryCode, category = AmazonDialog.promptKeywords() if _isEmpty(keywords): """ The user did not enter any text to search on or hit the cancel button """ return None while True: try: bags = amazon.searchByKeyword(keywords, locale=countryCode, product_line=category) return _AddToCollection(repView, keywords, countryCode, bags) except amazon.NoLicenseKey: if AmazonDialog.promptLicense(): continue return None except (amazon.AmazonError, AttributeError), e: dt = {'keywords': keywords} _showError(_(u"No Amazon products were found for keywords '%(keywords)s'") % dt) return None
def isbn(self, irc, msg, args, optlist, isbn): """[--url] <isbn> Returns the book matching the given ISBN number. If --url is specified, a link to amazon.com's page for the book will also be returned. """ url = False for (option, argument) in optlist: if option == 'url': url = True isbn = isbn.replace('-', '').replace(' ', '') attribs = {'ProductName' : 'title', 'Manufacturer' : 'publisher', 'Authors' : 'author', 'OurPrice' : 'price', 'URL' : 'url' } s = '%(title)s, written by %(author)s; published by ' \ '%(publisher)s; price: %(price)s%(url)s' channel = msg.args[0] bold = self.registryValue('bold', channel) region = self.registryValue('region', channel) try: book = amazon.searchByKeyword(isbn, locale=region) res = self._genResults(s, attribs, book, url, bold) if res: irc.reply(format('%L', res)) return except amazon.AmazonError, e: pass
def fetch_bigger_poster(self): match = 0 self.debug.show("fetching poster from amazon") movie = self.db.Movie.get_by(movie_id=self._movie_id) if movie is None: gutils.error(self,_("You have no movies in your database"), self.widgets['window']) return False current_poster = movie.image amazon.setLicense("04GDDMMXX8X9CJ1B22G2") locale = self.config.get('amazon_locale', 0, section='add') keyword = self.widgets['movie']['o_title'].get_text().decode('utf-8') if locale == '1': locale = 'uk' elif locale == '2': locale = 'de' keyword = self.widgets['movie']['title'].get_text().decode('utf-8') elif locale == '3': locale = 'ca' elif locale == '4': locale = 'fr' elif locale == '5': locale = 'jp' else: locale = None try: result = amazon.searchByKeyword(keyword, type="Large", product_line="DVD", locale=locale) self.debug.show("Posters found on amazon: %s posters" % result.TotalResults) except: gutils.warning(self, _("No posters found for this movie.")) return from widgets import connect_poster_signals, reconnect_add_signals connect_poster_signals(self, get_poster_select_dc, result, current_poster) if not len(result.Item): gutils.warning(self, _("No posters found for this movie.")) reconnect_add_signals(self) return for f in range(len(result.Item)): if self.widgets['movie']['o_title'].get_text().decode('utf-8') == result.Item[f].ItemAttributes.Title: get_poster(self, f, result, current_poster) return self.treemodel_results.clear() self.widgets['add']['b_get_from_web'].set_sensitive(False) # disable movie plugins (result window is shared) for f in range(len(result.Item)): if hasattr(result.Item[f], "LargeImage") and len(result.Item[f].LargeImage.URL): title = result.Item[f].ItemAttributes.Title myiter = self.treemodel_results.insert_before(None, None) self.treemodel_results.set_value(myiter, 0, str(f)) self.treemodel_results.set_value(myiter, 1, title) self.widgets['results']['window'].show() self.widgets['results']['window'].set_keep_above(True)
def fetch_bigger_poster(self): match = 0 self.debug.show("fetching poster from amazon") movie = self.db.Movie.get_by(movie_id=self._movie_id) if movie is None: gutils.error(self, _("You have no movies in your database"), self.widgets["window"]) return False current_poster = movie.image amazon.setLicense("04GDDMMXX8X9CJ1B22G2") locale = self.config.get("amazon_locale", 0) if locale == 1: locale = "uk" elif locale == 2: locale = "de" elif locale == 3: locale = "uk" else: locale = None try: result = amazon.searchByKeyword( self.widgets["movie"]["o_title"].get_text(), type="lite", product_line="dvd", locale=locale ) self.debug.show("Posters found on amazon: %s posters" % len(result)) except: gutils.warning(self, _("No posters found for this movie.")) return from widgets import connect_poster_signals, reconnect_add_signals connect_poster_signals(self, get_poster_select_dc, result, current_poster) if not len(result): gutils.warning(self, _("No posters found for this movie.")) reconnect_add_signals(self) return for f in range(len(result)): if self.widgets["movie"]["o_title"].get_text() == result[f].ProductName: get_poster(self, f, result, current_poster) return self.treemodel_results.clear() self.widgets["add"]["b_get_from_web"].set_sensitive(False) # disable movie plugins (result window is shared) for f in range(len(result)): if len(result[f].ImageUrlLarge): title = result[f].ProductName myiter = self.treemodel_results.insert_before(None, None) self.treemodel_results.set_value(myiter, 0, str(f)) self.treemodel_results.set_value(myiter, 1, title) self.widgets["results"]["window"].show() self.widgets["results"]["window"].set_keep_above(True)
def __init__(self,keywords=None,email=None, name=None, parent=None, kind=None, view=None): super(AmazonCollection, self).__init__(name, parent, kind, view) if keywords: bags = amazon.searchByKeyword(keywords) self.displayName = 'Amzn: ' + keywords elif email: results = amazon.searchWishListByEmail(email) customerName = results[0] bags = results[1] self.displayName = 'Amzn: ' + customerName else: bags = {} for aBag in bags: self.add(AmazonItem(aBag, view=view))
def __init__(self, keywords=None, email=None, name=None, parent=None, kind=None, view=None): super(AmazonCollection, self).__init__(name, parent, kind, view) if keywords: bags = amazon.searchByKeyword(keywords) self.displayName = 'Amzn: ' + keywords elif email: results = amazon.searchWishListByEmail(email) customerName = results[0] bags = results[1] self.displayName = 'Amzn: ' + customerName else: bags = {} for aBag in bags: self.add(AmazonItem(aBag, view=view))
def fetch_bigger_poster(self): match = 0 self.debug.show("fetching poster from amazon") this_movie = self.db.select_movie_by_num(self.e_number.get_text()) current_poster = this_movie[0]['image'] amazon.setLicense("04GDDMMXX8X9CJ1B22G2") try: result = amazon.searchByKeyword(self.e_original_title.get_text(), \ type="lite", product_line="dvd") self.debug.show("Posters found on amazon: %s posters" % len(result)) except: gutils.warning(self, _("No posters found for this movie.")) return widgets.connect_poster_signals(self, get_poster_select_dc, result, current_poster) if not len(result): gutils.warning(self, _("No posters found for this movie.")) return for f in range(len(result)): if self.e_original_title.get_text() == result[f].ProductName: get_poster(self, f, result, current_poster) return self.treemodel_results.clear() for f in range(len(result)): if (len(result[f].ImageUrlLarge)): title = result[f].ProductName self.debug.show(title) myiter = self.treemodel_results.insert_before(None, None) self.treemodel_results.set_value(myiter, 0, str(f)) self.treemodel_results.set_value(myiter, 1, title) self.w_results.show() self.w_results.set_keep_above(True)
def videos(self, irc, msg, args, optlist, keyword): """[--url] [--{dvd,vhs}] <keywords> Returns the videos matching the given <keyword> search. If --url is specified, a link to amazon.com's page for the video will also be returned. Search defaults to using --dvd. """ url = False product = 'dvd' for (option, _) in optlist: if option == 'url': url = True else: product = option attribs = { 'ProductName': 'title', 'Manufacturer': 'publisher', 'MpaaRating': 'mpaa', 'Media': 'media', 'ReleaseDate': 'date', 'OurPrice': 'price', 'URL': 'url' } s = '%(title)s (%(media)s), rated %(mpaa)s; released ' \ '%(date)s; published by %(publisher)s; price: %(price)s%(url)s' channel = msg.args[0] region = self.registryValue('region', channel) bold = self.registryValue('bold', channel) try: videos = amazon.searchByKeyword(keyword, product_line=product, locale=region) res = self._genResults(s, attribs, videos, url, bold) if res: irc.reply(format('%L', res)) return except amazon.AmazonError, e: pass
def videos(self, irc, msg, args, optlist, keyword): """[--url] [--{dvd,vhs}] <keywords> Returns the videos matching the given <keyword> search. If --url is specified, a link to amazon.com's page for the video will also be returned. Search defaults to using --dvd. """ url = False product = 'dvd' for (option, _) in optlist: if option == 'url': url = True else: product = option attribs = {'ProductName' : 'title', 'Manufacturer' : 'publisher', 'MpaaRating' : 'mpaa', 'Media' : 'media', 'ReleaseDate' : 'date', 'OurPrice' : 'price', 'URL' : 'url' } s = '%(title)s (%(media)s), rated %(mpaa)s; released ' \ '%(date)s; published by %(publisher)s; price: %(price)s%(url)s' channel = msg.args[0] region = self.registryValue('region', channel) bold = self.registryValue('bold', channel) try: videos = amazon.searchByKeyword(keyword, product_line=product, locale=region) res = self._genResults(s, attribs, videos, url, bold) if res: irc.reply(format('%L', res)) return except amazon.AmazonError, e: pass
def toolbar_icon_clicked(self, widget, movie): log.info("fetching poster from Amazon...") self.movie = movie locale = self.get_config_value("locale", "US").lower() accesskey = self.get_config_value("accesskey") secretkey = self.get_config_value("secretkey") if not accesskey or not secretkey: gutils.error( _("Please configure your Amazon Access Key ID and Secret Key correctly in the preferences dialog.") ) return False if movie is None: gutils.error(_("You have no movies in your database"), self.widgets["window"]) return False keyword = movie.o_title if locale == "de": keyword = movie.title try: amazon.setLicense(accesskey, secretkey) result = amazon.searchByTitle(keyword, type="Large", product_line="DVD", locale=locale) if hasattr(result, "TotalPages"): # get next result pages pages = int(result.TotalPages) page = 2 while page <= pages and page < 11: tmp = amazon.searchByTitle(keyword, type="Large", product_line="DVD", locale=locale, page=page) result.Item.extend(tmp.Item) page = page + 1 if not hasattr(result, "Item") or not len(result.Item): # fallback if nothing is found by title result = amazon.searchByKeyword(keyword, type="Large", product_line="DVD", locale=locale) if hasattr(result, "TotalPages"): # get next result pages pages = int(result.TotalPages) page = 2 while page <= pages and page < 11: tmp = amazon.searchByKeyword( keyword, type="Large", product_line="DVD", locale=locale, page=page ) result.Item.extend(tmp.Item) page = page + 1 self._result = result log.info("... %s posters found" % result.TotalResults) except: log.exception("") gutils.warning(_("No posters found for this movie.")) return if not hasattr(result, "Item") or not len(result.Item): gutils.warning(_("No posters found for this movie.")) return if len(result.Item) == 1: o_title = self.widgets["movie"]["o_title"].get_text().decode("utf-8") if o_title == result.Item[0].ItemAttributes.Title or keyword == result.Item[0].ItemAttributes.Title: self.get_poster(self.app, result.Item[0]) return # populate results window items = {} for i, item in enumerate(result.Item): if hasattr(item, "LargeImage") and len(item.LargeImage.URL): title = item.ItemAttributes.Title if hasattr(item.ItemAttributes, "ProductGroup"): title = title + u" - " + item.ItemAttributes.ProductGroup elif hasattr(item.ItemAttributes, "Binding"): title = title + u" - " + item.ItemAttributes.Binding if hasattr(item.ItemAttributes, "ReleaseDate"): title = title + u" - " + item.ItemAttributes.ReleaseDate[:4] elif hasattr(item.ItemAttributes, "TheatricalReleaseDate"): item.ItemAttributes.TheatricalReleaseDate[:4] if hasattr(item.ItemAttributes, "Studio"): title = title + u" - " + item.ItemAttributes.Studio items[i] = title populate_results_window(self.app.treemodel_results, items) self.widgets["add"]["b_get_from_web"].set_sensitive(False) # disable movie plugins (result window is shared) self.app._resultswin_process = ( self.on_result_selected ) # use this signal (will be reverted when window is closed) self.widgets["results"]["window"].show() self.widgets["results"]["window"].set_keep_above(True)
continue # avoid fetching again if we already had a suitable image if not images.has_key((track['album'],track['artist'])): query = "%(album)s + %(artist)s" % track # nasty hacks to get better hits. Is there a library out there # for this? Note we take out double quotes too: Amazon place # this string literally into their XML response, so can end up # giving us back: <Arg value="search"term" # name="KeywordSearch"> which is not well formed :-( for term in ["Disk 1", "Disk 2", '12"', '12 "','"','&']: query = query.replace(term,"") print " Searching for %s: " % query try: albums = amazon.searchByKeyword(query, type="lite", product_line="music") except amazon.AmazonError, e: print e albums = [] if len(albums) == 0: continue album = albums[0] try: image_data = urllib.urlopen(album.ImageUrlLarge).read() except: print " Failed to download from %s" % album.ImageUrlLarge continue loader = gtk.gdk.PixbufLoader()
def fetch_bigger_poster(self): match = 0 log.info("fetching poster from amazon...") movie = self.db.session.query(db.Movie).filter_by(movie_id=self._movie_id).first() if movie is None: gutils.error(self, _("You have no movies in your database"), self.widgets["window"]) return False current_poster_md5 = movie.poster_md5 if current_poster_md5: current_poster = gutils.get_image_fname(current_poster_md5, self.db) else: current_poster = None amazon.setLicense("04GDDMMXX8X9CJ1B22G2") locale = self.config.get("amazon_locale", 0, section="add") keyword = self.widgets["movie"]["o_title"].get_text() if locale == "1": locale = "uk" elif locale == "2": locale = "de" keyword = self.widgets["movie"]["title"].get_text() elif locale == "3": locale = "ca" elif locale == "4": locale = "fr" elif locale == "5": locale = "jp" else: locale = None try: result = amazon.searchByTitle(keyword, type="Large", product_line="DVD", locale=locale) if hasattr(result, "TotalPages"): # get next result pages pages = int(result.TotalPages) page = 2 while page <= pages and page < 11: tmp = amazon.searchByTitle(keyword, type="Large", product_line="DVD", locale=locale, page=page) result.Item.extend(tmp.Item) page = page + 1 if not hasattr(result, "Item") or not len(result.Item): # fallback if nothing is found by title result = amazon.searchByKeyword(keyword, type="Large", product_line="DVD", locale=locale) if hasattr(result, "TotalPages"): # get next result pages pages = int(result.TotalPages) page = 2 while page <= pages and page < 11: tmp = amazon.searchByKeyword(keyword, type="Large", product_line="DVD", locale=locale, page=page) result.Item.extend(tmp.Item) page = page + 1 log.info("... %s posters found" % result.TotalResults) except: gutils.warning(_("No posters found for this movie.")) return from widgets import connect_poster_signals, reconnect_add_signals connect_poster_signals(self, get_poster_select_dc, result, current_poster) if not hasattr(result, "Item") or not len(result.Item): gutils.warning(_("No posters found for this movie.")) reconnect_add_signals(self) return if len(result.Item) == 1: o_title = self.widgets["movie"]["o_title"].get_text().decode("utf-8") if o_title == result.Item[0].ItemAttributes.Title or keyword == result.Item[0].ItemAttributes.Title: get_poster(self, 0, result) return self.treemodel_results.clear() self.widgets["add"]["b_get_from_web"].set_sensitive(False) # disable movie plugins (result window is shared) for f in range(len(result.Item)): if hasattr(result.Item[f], "LargeImage") and len(result.Item[f].LargeImage.URL): title = result.Item[f].ItemAttributes.Title if hasattr(result.Item[f].ItemAttributes, "ProductGroup"): title = title + u" - " + result.Item[f].ItemAttributes.ProductGroup elif hasattr(result.Item[f].ItemAttributes, "Binding"): title = title + u" - " + result.Item[f].ItemAttributes.Binding if hasattr(result.Item[f].ItemAttributes, "ReleaseDate"): title = title + u" - " + result.Item[f].ItemAttributes.ReleaseDate[:4] elif hasattr(result.Item[f].ItemAttributes, "TheatricalReleaseDate"): result.Item[f].ItemAttributes.TheatricalReleaseDate[:4] if hasattr(result.Item[f].ItemAttributes, "Studio"): title = title + u" - " + result.Item[f].ItemAttributes.Studio myiter = self.treemodel_results.insert_before(None, None) self.treemodel_results.set_value(myiter, 0, str(f)) self.treemodel_results.set_value(myiter, 1, title) self.widgets["results"]["window"].show() self.widgets["results"]["window"].set_keep_above(True)
def fetch_bigger_poster(self): match = 0 log.info("fetching poster from amazon...") movie = self.db.session.query(db.Movie).filter_by(movie_id=self._movie_id).first() if movie is None: gutils.error(self,_("You have no movies in your database"), self.widgets['window']) return False current_poster_md5 = movie.poster_md5 if current_poster_md5: current_poster = gutils.get_image_fname(current_poster_md5, self.db) else: current_poster = None amazon.setLicense("04GDDMMXX8X9CJ1B22G2") locale = self.config.get('amazon_locale', 0, section='add') keyword = self.widgets['movie']['o_title'].get_text() if locale == '1': locale = 'uk' elif locale == '2': locale = 'de' keyword = self.widgets['movie']['title'].get_text() elif locale == '3': locale = 'ca' elif locale == '4': locale = 'fr' elif locale == '5': locale = 'jp' else: locale = None try: result = amazon.searchByTitle(keyword, type="Large", product_line="DVD", locale=locale) if hasattr(result, 'TotalPages'): # get next result pages pages = int(result.TotalPages) page = 2 while page <= pages and page < 11: tmp = amazon.searchByTitle(keyword, type='Large', product_line='DVD', locale=locale, page=page) result.Item.extend(tmp.Item) page = page + 1 if not hasattr(result, 'Item') or not len(result.Item): # fallback if nothing is found by title result = amazon.searchByKeyword(keyword, type="Large", product_line="DVD", locale=locale) if hasattr(result, 'TotalPages'): # get next result pages pages = int(result.TotalPages) page = 2 while page <= pages and page < 11: tmp = amazon.searchByKeyword(keyword, type='Large', product_line='DVD', locale=locale, page=page) result.Item.extend(tmp.Item) page = page + 1 log.info("... %s posters found" % result.TotalResults) except: gutils.warning(_("No posters found for this movie.")) return from widgets import connect_poster_signals, reconnect_add_signals connect_poster_signals(self, get_poster_select_dc, result, current_poster) if not hasattr(result, 'Item') or not len(result.Item): gutils.warning(_("No posters found for this movie.")) reconnect_add_signals(self) return if len(result.Item) == 1: o_title = self.widgets['movie']['o_title'].get_text().decode('utf-8') if o_title == result.Item[0].ItemAttributes.Title or keyword == result.Item[0].ItemAttributes.Title: get_poster(self, 0, result) return self.treemodel_results.clear() self.widgets['add']['b_get_from_web'].set_sensitive(False) # disable movie plugins (result window is shared) for f in range(len(result.Item)): if hasattr(result.Item[f], "LargeImage") and len(result.Item[f].LargeImage.URL): title = result.Item[f].ItemAttributes.Title if hasattr(result.Item[f].ItemAttributes, 'ProductGroup'): title = title + u' - ' + result.Item[f].ItemAttributes.ProductGroup elif hasattr(result.Item[f].ItemAttributes, 'Binding'): title = title + u' - ' + result.Item[f].ItemAttributes.Binding if hasattr(result.Item[f].ItemAttributes, 'ReleaseDate'): title = title + u' - ' + result.Item[f].ItemAttributes.ReleaseDate[:4] elif hasattr(result.Item[f].ItemAttributes, 'TheatricalReleaseDate'): result.Item[f].ItemAttributes.TheatricalReleaseDate[:4] if hasattr(result.Item[f].ItemAttributes, 'Studio'): title = title + u' - ' + result.Item[f].ItemAttributes.Studio myiter = self.treemodel_results.insert_before(None, None) self.treemodel_results.set_value(myiter, 0, str(f)) self.treemodel_results.set_value(myiter, 1, title) self.widgets['results']['window'].show() self.widgets['results']['window'].set_keep_above(True)
def toolbar_icon_clicked(self, widget, movie): log.info('fetching poster from Amazon...') self.movie = movie locale = self.get_config_value('locale', 'US').lower() accesskey = self.get_config_value('accesskey') secretkey = self.get_config_value('secretkey') if not accesskey or not secretkey: gutils.error(_('Please configure your Amazon Access Key ID and Secret Key correctly in the preferences dialog.')) return False if movie is None: gutils.error(_('You have no movies in your database'), self.widgets['window']) return False keyword = movie.o_title if locale == 'de': keyword = movie.title try: amazon.setLicense(accesskey, secretkey) result = amazon.searchByTitle(keyword, type='Large', product_line='DVD', locale=locale) if hasattr(result, 'TotalPages'): # get next result pages pages = int(result.TotalPages) page = 2 while page <= pages and page < 11: tmp = amazon.searchByTitle(keyword, type='Large', product_line='DVD', locale=locale, page=page) result.Item.extend(tmp.Item) page = page + 1 if not hasattr(result, 'Item') or not len(result.Item): # fallback if nothing is found by title result = amazon.searchByKeyword(keyword, type='Large', product_line='DVD', locale=locale) if hasattr(result, 'TotalPages'): # get next result pages pages = int(result.TotalPages) page = 2 while page <= pages and page < 11: tmp = amazon.searchByKeyword(keyword, type='Large', product_line='DVD', locale=locale, page=page) result.Item.extend(tmp.Item) page = page + 1 self._result = result log.info("... %s posters found" % result.TotalResults) except: log.exception('') gutils.warning(_('No posters found for this movie.')) return if not hasattr(result, 'Item') or not len(result.Item): gutils.warning(_('No posters found for this movie.')) return if len(result.Item) == 1: o_title = self.widgets['movie']['o_title'].get_text().decode('utf-8') if o_title == result.Item[0].ItemAttributes.Title or keyword == result.Item[0].ItemAttributes.Title: self.get_poster(self.app, result.Item[0]) return # populate results window items = {} for i, item in enumerate(result.Item): if hasattr(item, 'LargeImage') and len(item.LargeImage.URL): title = item.ItemAttributes.Title if hasattr(item.ItemAttributes, 'ProductGroup'): title = title + u' - ' + item.ItemAttributes.ProductGroup elif hasattr(item.ItemAttributes, 'Binding'): title = title + u' - ' + item.ItemAttributes.Binding if hasattr(item.ItemAttributes, 'ReleaseDate'): title = title + u' - ' + item.ItemAttributes.ReleaseDate[:4] elif hasattr(item.ItemAttributes, 'TheatricalReleaseDate'): item.ItemAttributes.TheatricalReleaseDate[:4] if hasattr(item.ItemAttributes, 'Studio'): title = title + u' - ' + item.ItemAttributes.Studio items[i] = title populate_results_window(self.app.treemodel_results, items) self.widgets['add']['b_get_from_web'].set_sensitive(False) # disable movie plugins (result window is shared) self.app._resultswin_process = self.on_result_selected # use this signal (will be reverted when window is closed) self.widgets['results']['window'].show() self.widgets['results']['window'].set_keep_above(True)
def findAlbum(self, artist, album): if self.enabled: try: return amazon.searchByKeyword(artist, album) except amazon.AmazonError: pass
def get_nearest_asin(product_name): return amazon.searchByKeyword(product_name)[0].Asin
if (searchLocale != "" and searchField != ""): collection = doc.createElement ("List") collection.setAttribute ("name", "Amazon Import") root.appendChild (collection) pythonBooks = None; if searchField == "authors": pythonBooks = amazon.searchByAuthor (query, locale=searchLocale, mode=searchMode) elif searchField == "asin": pythonBooks = amazon.searchByASIN (query, locale=searchLocale, mode=searchMode) elif searchField == "upc": pythonBooks = amazon.searchByUPC (query, locale=searchLocale, mode=searchMode) else: pythonBooks = amazon.searchByKeyword (query, locale=searchLocale, mode=searchMode) for book in pythonBooks: bookElement = doc.createElement ("Book") bookElement.setAttribute ("title", book.ProductName) for key in fieldMap.keys(): name = fieldMap[key] if name == None: name = key value = None try: value = getattr(book, key)
continue # avoid fetching again if we already had a suitable image if not images.has_key((track['album'], track['artist'])): query = "%(album)s + %(artist)s" % track # nasty hacks to get better hits. Is there a library out there # for this? Note we take out double quotes too: Amazon place # this string literally into their XML response, so can end up # giving us back: <Arg value="search"term" # name="KeywordSearch"> which is not well formed :-( for term in ["Disk 1", "Disk 2", '12"', '12 "', '"', '&']: query = query.replace(term, "") print " Searching for %s: " % query try: albums = amazon.searchByKeyword(query, type="lite", product_line="music") except amazon.AmazonError, e: print e albums = [] if len(albums) == 0: continue album = albums[0] try: image_data = urllib.urlopen(album.ImageUrlLarge).read() except: print " Failed to download from %s" % album.ImageUrlLarge continue loader = gtk.gdk.PixbufLoader()