def select(self, choices): if not choices: raise Error("Internal error: no choices!") if len(choices) == 1 or self.batch: result = 1 else: just = len(str(len(choices))) index = 1 for choice in choices: echo(str(index).rjust(just), ':', choice) index += 1 while True: answer = input('[1] > ') if not answer: result = 1 else: try: result = int(answer) except ValueError: result = None if result and 1 <= result <= len(choices): break else: echo("Bad response") result = choices[result - 1] echo(result) return result
def launch_file(self, filename): args = self.args query, release = file_to_query(filename) if args.query: query = args.query if args.release: release = string_set(args.release) if args.verbose: echo('Using query "{query}" and release "{release}"'.format( release=' '.join(release), query=query)) search_results = search(query) if not search_results: echo('No result') return if self.args.batch and len(search_results) > 1: raise Error('More than one result, aborting') episode = self.select(search_results) return episode and self.episode(episode, args.language, release)
def __call__(self, query): if self.status_code >= 300: raise Error("HTTP request to '{}' has failed with status {}" .format(self.url, self.status_code)) if not self._query: self._query = PyQuery(self.content) return self._query(query)
def login(user, password): result = session.post('/dologin.php', data={ 'username': user, 'password': password, 'remember': 'true' }) if get_current_user(result): return session.cookies['PHPSESSID'] raise Error(result('center p[align="center"]').text())
def select(self, choices): if not choices: raise Error("Internal error: no choices!") chosen_index = None skipping = False if len(choices) == 1 or self.batch: chosen_index = 1 else: just = len(str(len(choices))) index = 1 for choice in choices: echo(" {} : {}".format(str(index).rjust(just), choice)) index += 1 echo(" S : Skip") while True: answer = input('[1] > ') if not answer: chosen_index = 1 elif answer.lower() == "s": skipping = True else: try: chosen_index = int(answer) except ValueError: pass if skipping or (chosen_index and 1 <= chosen_index <= len(choices)): break else: echo("Bad response") if skipping: echo("Skipping") return None result = choices[chosen_index - 1] echo("{}".format(result)) return result
def launch_file(self, filename): echo('-' * 30) args = self.args filename = remove_extension(filename) + '.srt' echo('Target SRT file:', filename) ignore = False if os.path.isfile(filename): echo('File exists.', end=' ') if args.ignore or (not args.overwrite and not self.confirm('Overwrite?', True)): echo('Ignoring.') ignore = True else: echo('Overwriting.') if not ignore: query, release = file_to_query(filename) if args.query: query = args.query if args.release: release = string_set(args.release) if args.verbose: echo('Using query "{query}" and release "{release}"'.format( release=' '.join(release), query=query)) search_results = search(query) if search_results: if self.args.batch and len(search_results) > 1: raise Error('More than one result, aborting') episode = self.select(search_results) todownload = self.episode(episode, args.language, release) todownload.download(filename) else: echo('No result') echo()