def lookup(self, entry, nfo_filename): # If there is already data from a previous parse then we don't need to do anything if entry.get('nfo_id') is not None: log.warning( "Entry %s was already parsed by nfo_lookup and it will be skipped. ", entry.get('title'), ) return # nfo_filename Should not be None at this point assert nfo_filename is not None # Get all values we can from the nfo file. If the nfo file can't be parsed then a warning is logged and we # return without changing the entry try: nfo_reader = NfoReader(nfo_filename) fields = nfo_reader.get_fields_from_nfo_file() except BadXmlFile: log.warning("Invalid '.nfo' file for entry %s", entry.get('title')) return entry.update(fields) # If a valid IMDB id was found in the nfo file, set the imdb_id field of the entry. This will help the # imdb_lookup plugin to get the correct data if it is also used. if 'nfo_id' in fields: if is_valid_imdb_title_id(entry.get('nfo_id', '')): entry.update({'imdb_id': fields['nfo_id']}) else: log.warning( "ID found in nfo file for entry '%s', but it was not a valid IMDB ID", entry.get('title'), )
def parse_react_widget(self, task, config, url, params, headers): page = self.fetch_page(task, url, params, headers) try: json_vars = json.loads( re.search(r'IMDbReactInitialState.push\((.+?)\);\n', page.text).group(1) ) except (TypeError, AttributeError, ValueError) as e: raise plugin.PluginError( 'Unable to get imdb list from imdb react widget.' + ' Either the list is empty or the imdb parser of the imdb_watchlist plugin is broken.' + ' Original error: %s.' % str(e) ) total_item_count = 0 if 'list' in json_vars and 'items' in json_vars['list']: total_item_count = len(json_vars['list']['items']) if not total_item_count: log.verbose('No movies were found in imdb list: %s', config['list']) return imdb_ids = [] for item in json_vars['list']['items']: if is_valid_imdb_title_id(item.get('const')): imdb_ids.append(item['const']) params = {'ids': ','.join(imdb_ids)} url = 'http://www.imdb.com/title/data' try: json_data = self.fetch_page(task, url, params, headers).json() except (ValueError, TypeError) as e: raise plugin.PluginError( 'Unable to get imdb list from imdb JSON API.' + ' Either the list is empty or the imdb parser of the imdb_watchlist plugin is broken.' + ' Original error: %s.' % str(e) ) log.verbose('imdb list contains %d items', len(json_data)) log.debug( 'First entry (imdb id: %s) looks like this: %s', imdb_ids[0], json_data[imdb_ids[0]] ) entries = [] for imdb_id in imdb_ids: entry = Entry() if not ( 'title' in json_data[imdb_id] and 'primary' in json_data[imdb_id]['title'] and 'href' in json_data[imdb_id]['title']['primary'] and 'title' in json_data[imdb_id]['title']['primary'] ): log.debug('no title or link found for item %s, skipping', imdb_id) continue if 'type' in json_data[imdb_id]['title']: entry['imdb_type'] = json_data[imdb_id]['title']['type'] title = json_data[imdb_id]['title']['primary']['title'] entry['title'] = title if 'year' in json_data[imdb_id]['title']['primary']: year = json_data[imdb_id]['title']['primary']['year'][0] entry['title'] += ' (%s)' % year entry['imdb_year'] = year entry['url'] = json_data[imdb_id]['title']['primary']['href'] entry['imdb_id'] = imdb_id entry['imdb_name'] = entry['title'] entries.append(entry) return entries
def parse_react_widget(self, task, config, url, params, headers): page = self.fetch_page(task, url, params, headers) try: json_vars = json.loads( re.search(r'IMDbReactInitialState.push\((.+?)\);\n', page.text).group(1)) except (TypeError, AttributeError, ValueError) as e: raise plugin.PluginError( 'Unable to get imdb list from imdb react widget.' + ' Either the list is empty or the imdb parser of the imdb_watchlist plugin is broken.' + ' Original error: %s.' % str(e)) total_item_count = 0 if 'list' in json_vars and 'items' in json_vars['list']: total_item_count = len(json_vars['list']['items']) if not total_item_count: logger.verbose('No movies were found in imdb list: {}', config['list']) return imdb_ids = [] for item in json_vars['list']['items']: if is_valid_imdb_title_id(item.get('const')): imdb_ids.append(item['const']) params = {'ids': ','.join(imdb_ids)} url = 'http://www.imdb.com/title/data' try: json_data = self.fetch_page(task, url, params, headers).json() except (ValueError, TypeError) as e: raise plugin.PluginError( 'Unable to get imdb list from imdb JSON API.' + ' Either the list is empty or the imdb parser of the imdb_watchlist plugin is broken.' + ' Original error: %s.' % str(e)) logger.verbose('imdb list contains {} items', len(json_data)) logger.debug('First entry (imdb id: {}) looks like this: {}', imdb_ids[0], json_data[imdb_ids[0]]) entries = [] for imdb_id in imdb_ids: entry = Entry() if not ('title' in json_data[imdb_id] and 'primary' in json_data[imdb_id]['title'] and 'href' in json_data[imdb_id]['title']['primary'] and 'title' in json_data[imdb_id]['title']['primary']): logger.debug('no title or link found for item {}, skipping', imdb_id) continue if 'type' in json_data[imdb_id]['title']: entry['imdb_type'] = json_data[imdb_id]['title']['type'] title = json_data[imdb_id]['title']['primary']['title'] entry['title'] = title if 'year' in json_data[imdb_id]['title']['primary']: year = json_data[imdb_id]['title']['primary']['year'][0] entry['title'] += ' (%s)' % year entry['imdb_year'] = year entry['url'] = json_data[imdb_id]['title']['primary']['href'] entry['imdb_id'] = imdb_id entry['imdb_name'] = entry['title'] entries.append(entry) return entries