def add(self, args): _fields = {} if 'link' in args: try: args['title'] = self.TITLE_LINK_REGEX.search( args['link']).group(1) except AttributeError: raise TVShowsTrackerError(( f"Couldn't find {self.TITLE_LINK_REGEX} pattern " f"in {args['link']} string")) for field_name in ['topic URL', 'title', 'air', 'link']: if field_name == 'air': _candidates = ['daily', 'weekly'] ucli.header('Air:') ucli.print_candidates(_candidates) _fields['air'] = ucli.parse_selection(_candidates) continue _field = ucli.get_field( field_name, prefill=args[field_name] if field_name in args else False, necessary=True) if field_name == 'topic URL': _fields['tracker'], _fields['id'] = self.URL_REGEX.search( _field).groups() continue if field_name == 'link': _fields['link'] = manager.get_path(_field) continue _fields[field_name] = _field topic = self.db.topics.insert(**_fields) return self.db.topics[topic]
def search(self, **params): self.media_type = params['type'] search_results = None try: search_results = ucli.gen_to_list( getattr(self, self.media_type)(**params)) ucli.print_candidates(search_results) except MapiNotFoundException: ucli.info('Nothing found') ucli.print_options("[e]dit query, [m]anual, [s]kip, [q]uit") except MapiNetworkException: ucli.drop('Network error: couldn\'t retrieve data') else: ucli.print_options( "[RETURN] default, [e]dit query, [m]anual, [s]kip, [q]uit") finally: return ucli.parse_selection( search_results, { 'e': self.search_again, 'm': self.get_metadata_manual})
def get_metadata_manual(self): _candidates = ['movie', 'episode'] if not self.is_movie: _candidates = _candidates[::-1] ucli.print_candidates(_candidates) ucli.print_options("[RETURN] default, [q]uit") self.media_type = ucli.parse_selection(_candidates) if self.is_movie: metadata = { 'title': ucli.get_field('title', necessary=True)} else: metadata = { 'series': ucli.get_field('title', necessary=True), 'season': ucli.get_field('season', default='1')} metadata['year'] = ucli.get_field('year', default=self.CURRENT_YEAR) return metadata