def find_and_write_episode_ids(): import argparse parser = argparse.ArgumentParser( description='TV Series Tools: Find IMDB IDs for all episodes of ' + 'passed TV series') parser.add_argument('--input', '-i', dest='inputfile', required=True, help='TV series list file -- one series title per' ' line, empty lines and lines starting with the hash' ' sign are ignored') parser.add_argument('--output', '-o', dest='outputfile', required=True, help='output file -- episode IMDB IDs will be written' ' one ID per line, if the file exists it will not be' ' overwritte, but IMDB IDs not already included in the' ' file will be added') args = parser.parse_args() listio.write_map( args.outputfile, find_episode_ids(listio.read_list(args.inputfile), IMDb())) sys.exit()
def find_and_write_episode_ids(): import argparse parser = argparse.ArgumentParser( description='TV Series Tools: Find IMDB IDs for all episodes of ' + 'passed TV series' ) parser.add_argument('--input', '-i', dest='inputfile', required=True, help='TV series list file -- one series title per' ' line, empty lines and lines starting with the hash' ' sign are ignored') parser.add_argument('--output', '-o', dest='outputfile', required=True, help='output file -- episode IMDB IDs will be written' ' one ID per line, if the file exists it will not be' ' overwritte, but IMDB IDs not already included in the' ' file will be added') args = parser.parse_args() listio.write_map( args.outputfile, find_episode_ids( listio.read_list(args.inputfile), IMDb() ) ) sys.exit()
def search_subs_and_save_matches(): import argparse parser = argparse.ArgumentParser( description='TV Series Tools: Search subtitles' ) parser.add_argument('--input', '-i', dest='inputdir', required=True, help='path to a directory with the subtitle SRT files') parser.add_argument('--output', '-o', dest='outputfile', required=True, help='path to a file in which the matches will be' ' stored') parser.add_argument('--patterns', '-p', dest='patterns', required=True, help='path to a file with search patterns') args = parser.parse_args() excl = [ common.convert_list_to_match(match) for match in listio.read_map(args.outputfile) ] regex_list = [ compile_regex(pattern) for pattern in listio.read_list(args.patterns) ] paths = iter_subs_files(args.inputdir) subs = read_subs(paths) matches = search_subs(subs, excl, regex_list) matches_list = ( common.convert_match_to_list(match) for match in matches ) listio.write_map(args.outputfile, matches_list) sys.exit()
def test_write_map(self): TMP_FILE_PATH = '_tmp_map.txt' listio.write_map(TMP_FILE_PATH, [ ['First column', 'second column', '3'], ['next;item,', 'foo', 'bar'], ]) with open(TMP_FILE_PATH, 'r') as f: self.assertEqual( f.read(), 'First column;second column;3\n' '"next;item,";foo;bar\n') os.remove(TMP_FILE_PATH)
def test_write_map_custom_format(self): TMP_FILE_PATH = '_tmp_map.txt' listio.write_map(TMP_FILE_PATH, [ ['First column', 'second column', '3'], ['next;item,', 'foo', 'bar'], ], delimiter=u',', lineterminator=u'\r\n') with open(TMP_FILE_PATH, 'rb') as f: self.assertEqual( f.read(), b'First column,second column,3\r\n' b'"next;item,",foo,bar\r\n') os.remove(TMP_FILE_PATH)
def check_positive_answers(): import argparse parser = argparse.ArgumentParser( description='TV Series Tools: Check again positive answers') parser.add_argument( '--input', '-i', dest='inputfile', required=True, help='path to a file with the answers', ) parser.add_argument( '--output', '-o', dest='outputfile', required=True, help='path to a file in which the new answers will be' ' stored', ) parser.add_argument( '--totals', '-t', dest='totals', action='store_true', help='show total number of answers to check,' ' this will cause that if there are a lot of answers' ' it will take quite a lot of time before the first' ' question shows up', ) args = parser.parse_args() answers = listio.read_map(args.inputfile) answers_positive = filter_positive_answers(answers) matches_positive = (convert_answer_to_match(answer) for answer in answers_positive) answers_checked = listio.read_map(args.outputfile) # Using list instead of generator so that we can read it several times. new_matches_answered = [ convert_answer_to_match(answer) for answer in answers_checked ] matches_not_checked = filter_matches(matches_positive, new_matches_answered) matches_with_context = add_subs_context_to_matches(matches_not_checked, 3) new_answers_checked = approve_matches(matches_with_context, totals=args.totals) listio.write_map(args.outputfile, new_answers_checked) sys.exit()
def search_subs_and_save_matches(): import argparse parser = argparse.ArgumentParser( description='TV Series Tools: Search subtitles') parser.add_argument( '--input', '-i', dest='inputdir', required=True, help='path to a directory with the subtitle SRT files', ) parser.add_argument( '--output', '-o', dest='outputfile', required=True, help='path to a file in which the matches will be' ' stored', ) parser.add_argument( '--patterns', '-p', dest='patterns', required=True, help='path to a file with search patterns', ) args = parser.parse_args() if os.path.isfile(args.outputfile): excl = [ common.convert_list_to_match(match) for match in listio.read_map(args.outputfile) ] else: excl = [] regex_list = [ compile_regex(pattern) for pattern in listio.read_list(args.patterns) ] paths = iter_subs_files(args.inputdir) subs = read_subs(paths) matches = search_subs(subs, excl, regex_list) matches_list = (common.convert_match_to_list(match) for match in itertools.chain(excl, matches)) listio.write_map(args.outputfile, matches_list) sys.exit()
def test_write_map(self): TMP_FILE_PATH = '_tmp_map.txt' listio.write_map( TMP_FILE_PATH, [ ['First column', 'second column', '3'], ['next;item,', 'foo', 'bar'], ] ) with open(TMP_FILE_PATH, 'r') as f: self.assertEqual( f.read(), 'First column;second column;3\n' '"next;item,";foo;bar\n' ) os.remove(TMP_FILE_PATH)
def approve_matches_and_save_answers(): import argparse parser = argparse.ArgumentParser( description='TV Series Tools: Check matches and save answers') parser.add_argument( '--input', '-i', dest='inputfile', required=True, help='path to a file with the matches', ) parser.add_argument( '--output', '-o', dest='outputfile', required=True, help='path to a file in which the answers will be' ' stored', ) parser.add_argument( '--totals', '-t', dest='totals', action='store_true', help='show total number of matches to answer,' ' this will cause that if there are a lot of matches' ' it will take quite a lot of time before the first' ' question shows up', ) args = parser.parse_args() matches_list = listio.read_map(args.inputfile) matches = (common.convert_list_to_match(l) for l in matches_list) answers_old = listio.read_map(args.outputfile) # Using list instead of generator so that we can read it several times. matches_answered = [ convert_answer_to_match(answer) for answer in answers_old ] matches_not_answered = filter_matches(matches, matches_answered) matches_with_context = add_subs_context_to_matches(matches_not_answered, 2) answers_new = approve_matches(matches_with_context, totals=args.totals) answers = itertools.chain(answers_old, answers_new) listio.write_map(args.outputfile, answers) sys.exit()
def migrate_custom_map_to_csv(): import argparse parser = argparse.ArgumentParser( description='TV Series Tools: Migrate custom map to CSV' ) parser.add_argument('--input', '-i', dest='inputfile', required=True, help='input custom map file path') parser.add_argument('--output', '-o', dest='outputfile', required=True, help='output csv file path') args = parser.parse_args() listio.write_map( args.outputfile, [line.split(' :: ') for line in listio.read_lines(args.inputfile)] ) sys.exit()
def test_write_map_custom_format(self): TMP_FILE_PATH = '_tmp_map.txt' listio.write_map( TMP_FILE_PATH, [ ['First column', 'second column', '3'], ['next;item,', 'foo', 'bar'], ], delimiter=u',', lineterminator=u'\r\n' ) with open(TMP_FILE_PATH, 'rb') as f: self.assertEqual( f.read(), b'First column,second column,3\r\n' b'"next;item,",foo,bar\r\n' ) os.remove(TMP_FILE_PATH)
def check_positive_answers(): import argparse parser = argparse.ArgumentParser( description='TV Series Tools: Check again positive answers' ) parser.add_argument('--input', '-i', dest='inputfile', required=True, help='path to a file with the answers') parser.add_argument('--output', '-o', dest='outputfile', required=True, help='path to a file in which the new answers will be' ' stored') parser.add_argument('--totals', '-t', dest='totals', action='store_true', help='show total number of answers to check,' ' this will cause that if there are a lot of answers' ' it will take quite a lot of time before the first' ' question shows up') args = parser.parse_args() answers = listio.read_map(args.inputfile) answers_positive = filter_positive_answers(answers) matches_positive = ( convert_answer_to_match(answer) for answer in answers_positive ) answers_checked = listio.read_map(args.outputfile) # Using list instead of generator so that we can read it several times. new_matches_answered = [ convert_answer_to_match(answer) for answer in answers_checked ] matches_not_checked = filter_matches( matches_positive, new_matches_answered ) matches_with_context = add_subs_context_to_matches(matches_not_checked, 3) new_answers_checked = approve_matches( matches_with_context, totals=args.totals ) listio.write_map(args.outputfile, new_answers_checked) sys.exit()
def migrate_custom_map_to_csv(): import argparse parser = argparse.ArgumentParser( description='TV Series Tools: Migrate custom map to CSV') parser.add_argument('--input', '-i', dest='inputfile', required=True, help='input custom map file path') parser.add_argument('--output', '-o', dest='outputfile', required=True, help='output csv file path') args = parser.parse_args() listio.write_map( args.outputfile, [line.split(' :: ') for line in listio.read_lines(args.inputfile)]) sys.exit()
def write_result(file_path_success, file_path_failed, results): for id, sub_file_name, error in results: if error is None: listio.write_map(file_path_success, [(id, sub_file_name)]) else: listio.write_map(file_path_failed, [(id, error)])
def write_result(file_path_success, file_path_failed, results): for id, sub_file_name, error in results: if error is None: listio.write_map(file_path_success, [(id, sub_file_name)]) else: listio.write_map(file_path_failed, [(id, error)])