def searchPeople(self, name, lang=False): """Searches for a People by name. Returns a list if matching persons and a dictionary of their attributes """ tmp_name = name.strip().replace(u' ',u'+') try: id_url = urllib.quote(tmp_name.encode("utf-8")) except (UnicodeEncodeError, TypeError): id_url = urllib.quote(tmp_name) if lang: # Override language URL = self.config[u'urls'][u'person.search'].replace(self.lang_url % self.config['language'], self.lang_url % lang) else: URL = self.config[u'urls'][u'person.search'] url = URL % (id_url) if self.config['debug_enabled']: # URL so that raw TMDB XML data can be viewed in a browser sys.stderr.write(u'\nDEBUG: XML URL:%s\n\n' % url) etree = XmlHandler(url).getEt() if etree is None: raise TmdbMovieOrPersonNotFound(u'No People matches found for the name (%s)' % name) if not etree.find(u"people").find(u"person"): raise TmdbMovieOrPersonNotFound(u'No People matches found for the name (%s)' % name) people = [] for item in etree.find(u"people").getchildren(): if item.tag == u"person": person = {} for p in item.getchildren(): if p.tag != u'images': person[p.tag] = self.textUtf8(p.text.strip()) elif len(p.getchildren()): person[p.tag] = {} for image in p.getchildren(): person[p.tag][image.get('size')] = image.get('url').strip() people.append(person) # Check if no ui has been requested and therefore just return the raw search results. if (self.config['interactive'] == False and self.config['select_first'] == False and self.config['custom_ui'] == None) or not len(people): return people # Select the first result (most likely match) or invoke user interaction to select the correct movie if self.config['custom_ui'] is not None: self.log.debug("Using custom UI %s" % (repr(self.config['custom_ui']))) ui = self.config['custom_ui'](config = self.config, log = self.log, searchTerm = name.strip()) else: if not self.config['interactive']: self.log.debug('Auto-selecting first search result using BaseUI') ui = BaseUI(config = self.config, log = self.log, searchTerm = name.strip()) else: self.log.debug('Interactivily selecting movie using ConsoleUI') ui = ConsoleUI(config = self.config, log = self.log, searchTerm = name.strip()) return ui.selectMovieOrPerson(people)
def searchTitle(self, title, lang=False): """Searches for a film by its title. Returns SearchResults (a list) containing all matches (Movie instances) """ if lang: # Override language URL = self.config[u'urls'][u'movie.search'].replace(self.lang_url % self.config['language'], self.lang_url % lang) else: URL = self.config[u'urls'][u'movie.search'] org_title = title title = urllib.quote(title.encode("utf-8")) url = URL % (title) if self.config['debug_enabled']: # URL so that raw TMDB XML data can be viewed in a browser sys.stderr.write(u'\nDEBUG: XML URL:%s\n\n' % url) etree = XmlHandler(url).getEt() if etree is None: raise TmdbMovieOrPersonNotFound(u'No Movies matching the title (%s)' % org_title) search_results = SearchResults() for cur_result in etree.find(u"movies").findall(u"movie"): if cur_result == None: continue cur_movie = self._tmdbDetails(cur_result) search_results.append(cur_movie) if not len(search_results): raise TmdbMovieOrPersonNotFound(u'No Movies matching the title (%s)' % org_title) # Check if no ui has been requested and therefore just return the raw search results. if (self.config['interactive'] == False and self.config['select_first'] == False and self.config['custom_ui'] == None) or not len(search_results): return search_results # Select the first result (most likely match) or invoke user interaction to select the correct movie if self.config['custom_ui'] is not None: self.log.debug("Using custom UI %s" % (repr(self.config['custom_ui']))) ui = self.config['custom_ui'](config = self.config, log = self.log, searchTerm = org_title) else: if not self.config['interactive']: self.log.debug('Auto-selecting first search result using BaseUI') ui = BaseUI(config = self.config, log = self.log, searchTerm = org_title) else: self.log.debug('Interactivily selecting movie using ConsoleUI') ui = ConsoleUI(config = self.config, log = self.log, searchTerm = org_title) return ui.selectMovieOrPerson(search_results)