Summarising an episode of APEX Instant Tips

Summarising an episode of APEX Instant Tips

100% free of charge solution using Microsoft Edge browser and the Copilot's AI capabilities

TL;DR

In this blog post:

  • How to get and convert YouTube subtitles to SRT: This blog post shows how to use Microsoft Edge and Copilot to get the auto-generated subtitles from a YouTube video in JSON format and convert them to SRT format using a Python script.

  • How to get a summary of a video using subtitles: The document shows how to use Copilot to generate a summary of a video based on the SRT subtitles. It also compares the results of different prompts and shows how to customize the summary.

💡
This TL;DR is AI-generated too, but it describes the content quite well. Keep reading to see how you can take advantage of Microsoft's Edge Browser Copilot for free and do some amazing things in a matter of minutes.

Get the auto-generated subtitles from the YouTube video

  1. Open a video on YouTube (on pause, CC off)

  2. Open the Network Tab

  3. Filter the network tab to "Fetch/XHR"

  4. Click the "CC" button to enable closed captioning.

  5. Look at a new entry on the network tab for an endpoint, "timedtext"

  6. Save the file as instant_tips.json

"events": [ {
    "tStartMs": 1040,
    "dDurationMs": 3210,
    "segs": [ {
      "utf8": "Thank you,"
    } ]
  }, {
    "tStartMs": 4250,
    "dDurationMs": 2440,
    "segs": [ {
      "utf8": "hello and welcome"
    } ]
  }, {
    "tStartMs": 6690,
    "dDurationMs": 1730,
    "segs": [ {
      "utf8": " to this episode of"
    } ]
  }
]

Turn it into SRT format for better readability

  1. Open Microsoft Edge

  2. Drag your instant_tips.json file to the browser window

  3. Click on the Copilot icon in the top right corner of the browser

  4. Enter the following or similar prompt in the chat:
    Can you turn these subtitles into SRT?

You will get something like this:

Creating your own procedure to convert YouTube JSON subtitles to SRT

As seen in the screenshot above, Copilot didn't do the conversion but instead suggested some sources where I could find more information on the SRT file format. Well, that's OK, but I need to have my JSON file converted because it will be easier to get a summary of the episode if there's just the dialogue and nothing else.

I'll look nowhere, but the AI again to help me write a Python procedure that does that. I got there in no more than 5 minutes, and I was even guided on how to run the code on my specific OS and tools. Here's part of my prompt and the output code, generated by the LLM* (if not mentioned earlier, LLM means Large Language Model - the thing that understands language and semantics and powers Copilot's conversational capabilities).

Write me a code which converts JSON subtitles from a YouTube video to SRT. The code should be in Python. After that tell me how to run it on a MacBook, as it should grab a file with the JSON subtitles in it. Output the result in a file, saved in the same directory as the input JSON file. I need to enter the subtitle's JSON filename when running the Python file.

So after a couple of iterations, I got the final version of the Python code and instructions on how to run it on my Macbook.

To run this code on your MacBook, you can follow these steps:

  1. Open a text editor such as Sublime Text or Visual Studio Code.

  2. Copy the above code and paste it into a new file.

  3. Save the file with a .py extension, for example, subtitle_converter.py.

  4. Place the JSON file containing the subtitles in the same directory as the Python file.

  5. Open the Terminal app on your MacBook.

  6. Navigate to the directory containing the Python and JSON files using the cd command.

  7. Run the Python script by typing python subtitle_converter.py youtube_subtitles.json in the Terminal and press Enter.

  8. The converted SRT file will be created in the same directory as the Python and JSON files.

I hope this helps! Let me know if you have any other questions.

and the Python code:

import json
import sys
from datetime import timedelta

def convert_to_srt(subtitles):
    srt_content = ""
    subtitle_number = 1

    for subtitle in subtitles:
        start_time = timedelta(milliseconds=subtitle["tStartMs"])
        end_time = start_time + timedelta(milliseconds=subtitle.get("dDurationMs", 0))

        srt_content += f"{subtitle_number}\n"
        srt_content += f"{start_time.total_seconds():.3f} --> {end_time.total_seconds():.3f}\n"

        for seg in subtitle.get("segs", []):
            srt_content += seg["utf8"]

        srt_content += "\n\n"
        subtitle_number += 1

    return srt_content.strip()

def convert_json_to_srt(json_filename, output_filename):
    with open(json_filename, 'r', encoding='utf-8') as json_file:
        data = json.load(json_file)

    subtitles = data.get("events", [])
    srt_content = convert_to_srt(subtitles)

    with open(output_filename, 'w', encoding='utf-8') as output_file:
        output_file.write(srt_content)

if __name__ == "__main__":
    if len(sys.argv) != 2:
        print("Usage: python convert_subtitles.py <input_json_filename>")
        sys.exit(1)

    input_filename = sys.argv[1]
    output_filename = input_filename.replace(".json", ".srt")

    convert_json_to_srt(input_filename, output_filename)
    print(f"SRT file saved as: {output_filename}")

After running the Python script, I got a new file - youtube_subtitles.srt in the same folder as the JSON file (just like I asked in my prompt). Here is the result - just what I needed:

1
0.000 --> 774.900

2
3.680 --> 9.879
[Music]

3
11.169 --> 11.169

4
11.179 --> 17.940
thank you hello and welcome once again

5
15.049 --> 17.940

6
15.059 --> 19.980
to Apex instant tips episode 120 brought

7
17.930 --> 19.980

8
17.940 --> 22.439
to you every Friday at 1205 eastern time
💡
It is very interesting to note that I haven't provided any sample of the input JSON file to Copilot to learn from. It just knew what a usual YouTube subtitles JSON file looks like and parsed it correctly. And that's because this type of files are publicly available and the model was trained on them. If you like to do it with a file that follows your own structure - JSON, YAML, you name it- you can upload it and ask the LLM to examine it and use it for any tasks that you want to give it further.

Getting a summary of the episode

We repeat the steps from the second chapter:

  1. Open Microsoft Edge

  2. Drag your instant_tips.srt file to the browser window

  3. Click on the Copilot icon in the top right corner of the browser

  4. Enter your prompt in the chat:

So I got some answers ... using similar prompts (the first time I just wanted a summary of my file), I got two slightly different replies:

💡
The first one - using a simple prompt, that asks for just a summary of my file.

📃 Summary v1

  • How to create a template component in APEX: The video shows how to copy and paste some HTML code into a plugin and turn it into a reusable template component. It also demonstrates how to use a template directive to conditionally display the component based on a field value.

  • How to call different template components in the same column: The video shows how to use a case expression to dynamically choose which template component to use based on another column value. It also shows how the template components can have different parameters and functionality.

  • How to write PL/SQL packages with examples: The video shares a tip on how to provide an example code for every procedure in a package specification. It explains how this can help with testing, documentation, and code reuse. It also shows how to use the Apex SQL Workshop to create and edit packages.

💡
The second one was generated using the following prompt:

"Based on the subtitles you see, give me a summary of it. When doing the summary, start with some sentences about APEX Instant Tips, then add the summary information from the episode as bullet points."

... and the result is:

📃 Summary v2

  • APEX Instant Tips is a series of short videos that provide tips and tricks for using Oracle Application Express (APEX). The videos are hosted by Anton Nielsen and Hayden Hudson, who are experts in APEX development and consulting.

  • In this episode, they demonstrate how to use template components in APEX, which are reusable HTML fragments that can be inserted into different regions or columns.

  • Some of the benefits of using template components are:

    • They can simplify and protect your code from accidental changes or deletions.

    • They can use template directives to conditionally display or hide content based on data values or logic.

    • They can be called from different template components using a case expression, which allows for more flexibility and customization.

    • They can provide examples and documentation for each procedure in your package, which makes it easier to test and reuse your code.

Terms

  • LLM: Large Language Model (LLM) is a type of language model that can understand and generate human-like language by processing massive amounts of data.

  • SRT format: SRT format is a subtitle file format that stores text which can be displayed along with video in a media player.

  • TL;DR: TLDR stands for “Too Long; Didn’t Read” and is used to express that a text is too long, identify a short summary of a long text, or ask for a summary of a long text.

Follow me

Did you like this blog post?
Do you want to hear more about APEX and AI?
Follow me! 🔔