def get_timelines(input_file: str) -> list: res = [] file_rows = FileManager.get_file_rows(input_file) for i, file_row in enumerate(file_rows): if Subtitle.is_timeline(file_row): res.append(file_row) return res
def get_subtitles(file_rows: list) -> list: result = [] timeline_raw = '' subtitle_raw = '' for i, file_row in enumerate(file_rows): if Subtitle.is_timeline(file_row): timeline_raw = file_row if Subtitle.is_subtitle_string(file_row): subtitle_raw = file_row if timeline_raw != '' and subtitle_raw != '': result.append(Subtitle(SubtitleString(subtitle_raw), TimeLine(timeline_raw))) timeline_raw = '' subtitle_raw = '' return result
def fix(self): caption_rows = FileManager.get_file_rows(self.input_filename) for i, caption_row in enumerate(caption_rows): if Subtitle.is_timeline(caption_row): if i + 3 < len(caption_rows): timeline_splitted = caption_row.split(',') timeline_splitted_next = caption_rows[i + 3].split(',') HandleFunctions.save_str_to_file( self.output_filename, timeline_splitted[0] + ',' + timeline_splitted_next[0] + '\n') else: HandleFunctions.save_str_to_file(self.output_filename, caption_row) else: HandleFunctions.save_str_to_file(self.output_filename, caption_row)
def remove_timelines(input_file: str, output_file: str): file_rows = FileManager.get_file_rows(input_file) for i, file_row in enumerate(file_rows): if not Subtitle.is_timeline(file_row): HandleFunctions.save_str_to_file(output_file, file_row)