File size: 1,104 Bytes
2fbb982
db4e125
2d7377d
2fbb982
 
00487e6
2fbb982
3a43614
 
 
00487e6
 
2d7377d
cb2adf3
2d7377d
db4e125
2fbb982
00487e6
 
 
 
 
 
 
 
 
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
import pandas as pd
from Functions.db_connection import default_app
from Resources.localization import get_string


def save_captions_to_db(df, video_id, user):
    try:
        data = df.copy()
        data.columns = ['start_time', 'text', 'end_time']
        df_json = data.to_dict(orient="index")
        default_app.database().child("video_captions").child(video_id).child("captions").set(df_json)
        default_app.database().child("video_captions").child(video_id).child("username").set(user)
        return get_string("save_successful")
    except Exception as e:
        return f"{get_string('save_failed')} {str(e)}"


def request_captions_by_video_id(video_id):
    response = default_app.database().child("video_captions").child(video_id).child("captions").get().val()
    if response is None:
        captions = pd.DataFrame(columns=["end_time", "start_time", "text"])
    else:
        captions = pd.DataFrame(response)
    captions_edit = captions[['start_time', 'text', 'end_time']]
    captions_edit.columns = ["Start", "Text", "End"]
    return captions_edit