File size: 1,760 Bytes
59e1d08
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
from tool.file_name import *
from ui.ui_component import *
import gradio as gr
import os


def write_simple_transcribe_file(simple_transcribe_txt_list: list):
    with open(dir_simple_transcribe_file, "w", encoding="utf-8") as file:
        file.writelines(simple_transcribe_txt_list)


def read_simple_transcribe_file():
    with open(dir_simple_transcribe_file, "r", encoding="utf-8") as file:
        simple_transcribe_txt_list = file.readlines()
    return simple_transcribe_txt_list


def write_transcribe_subtitle_file(transcribe_txt_list: list, subtitle_txt_list: list, write_adjusted_file: bool):
    transcribe = dir_base_transcribe_file
    subtitle = dir_base_subtitle_file
    if write_adjusted_file:
        transcribe = dir_adjusted_transcribe_file
        subtitle = dir_adjusted_subtitle_file

    with open(transcribe, "w", encoding="utf-8") as file:
        file.writelines(transcribe_txt_list)
    with open(subtitle, "w", encoding="utf-8") as file:
        file.writelines(subtitle_txt_list)


def read_transcribe_subtitle_file(read_adjusted_file: bool):
    transcribe = dir_base_transcribe_file
    subtitle = dir_base_subtitle_file
    if read_adjusted_file:
        transcribe = dir_adjusted_transcribe_file
        subtitle = dir_adjusted_subtitle_file

    if not os.path.exists(transcribe):
        raise gr.Error(current_ui_lang["file_not_exist"] + ": Transcribe")
    if not os.path.exists(subtitle):
        raise gr.Error(current_ui_lang["file_not_exist"] + ": Subtitle")

    with open(transcribe, "r", encoding="utf-8") as file:
        transcribe_txt_list = file.readlines()
    with open(subtitle, "r", encoding="utf-8") as file:
        subtitle_txt_list = file.readlines()
    return transcribe_txt_list, subtitle_txt_list