File size: 2,368 Bytes
e454383
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import re
import json
from urllib.parse import urlencode, quote_plus


def extract_timestamps(transcript, docs) -> list[dict]:
    """
    Extracts timestamps in HH:MM:SS format from the transcript.
    Returns a list of tuples (timestamp_str, session_id, transcript_text).
    """
    pattern = r'(\d{1,2}):(\d{2}):(\d{2})'
    matches = re.finditer(pattern, transcript)
    timestamps = []
    timestamps_list = []

    doc_payloads = [doc["payload"] for doc in docs]

    for match in matches:
        time_str = match.group(0)
        start = match.start()

        # Checking if timestamp is already present in the timestamps_list
        if time_str in timestamps_list:
            continue

        transcript_text = ""
        session_id = None
        # Adding the data for the supporting documents
        for doc in doc_payloads:
            if time_str in doc["timestamp"]:
                transcript_text = f'{doc["speaker"]} @ {time_str}: {doc["text"]}'
                session_id = doc["filename"]  # Get session name from document
                break

        if transcript_text and session_id:
            timestamps.append(
                {
                    "timestamp": time_str,
                    "timestamp_seconds": convert_time_to_seconds(time_str),
                    "transcript_text": transcript_text,
                    "filename": session_id,
                }
            )
        timestamps_list.append(time_str)

    return timestamps


def convert_time_to_seconds(time_str):
    """
    Converts a time string HH:MM:SS to total seconds.
    """
    h, m, s = map(int, time_str.split(':'))
    return h * 3600 + m * 60 + s


def get_embed_url(start_time, uid):
    """
    Constructs the embed URL with the specified start time.
    """
    base_url = "https://ifad.sharepoint.com/sites/IFAD-CLEIFAD11andIFAD12/_layouts/15/embed.aspx"
    params = {
        "UniqueId": uid,
        "nav": json.dumps({
            "playbackOptions": {
                "startTimeInSeconds": start_time
            }
        }),
        "embed": json.dumps({
            "hvm": True,
            "ust": True,
            "hv": "CopyEmbedCode"
        }),
        "referrer": "StreamWebApp",
        "referrerScenario": "EmbedDialog.Create"
    }
    query_string = urlencode(params, quote_via=quote_plus)
    return f"{base_url}?{query_string}"