Change YouTube Transcript Timestamps Into Links Using KM With Regex

I several text transcripts from YouTube videos that have timestamps every-other line.

I want to change those timestamps into links and calculate the total seconds so the link can skip to that point in the video and resave the rich text.

For example here is a video: https://www.youtube.com/watch?v=KzvaDZVSk3c

Here's part of the transcript:

00:00
today we're going to talk about
00:01
self-persuasion but we're going to speak
00:03
about it from the perspective of
00:05
nlp frame control
00:08
in our last video we spoke about the
00:11
topic of frame control
00:13
i brought it up a few times and the

I want to replace each timestamp line to be a link to the YouTube url with the total seconds added so it links directly to that point in the video, for example if the transcript had a line that was 30:42 it would replace it to make it a link like this:

<a href="https://www.youtube.com/watch?v=KzvaDZVSk3c&t=1842">30:42</a>

To get the to total seconds I was thinking to cycle through each line of the text transcript and run an if else statement to see if the line contains ':', and calculate from minutes into seconds by splitting the line at the ':' then multiply the first split by 60, and then add add to the second split to get the total seconds.

Does anybody have a suggestion for the best way to approach this? Maybe with regex?

Thanks in advance

See if this gets you started.

image

The "Search Variable" action has "Notify Aborts Macro" and "Notify on Failure" turned off. The "If" checking %ActionResult% tells whether the search found anything or not:

image

Hope this helps.

1 Like

Thanks Dan!

I made some progress per your suggestions. The issue I'm having now is I'm not sure what syntax needs to be used to export a RTF file with formatted links. I tried to use both html and RTF format but they don't parse when saving the new file. Do you know how I export my transcript with the links in RTF format? In the example below you will see i have 3 different actions for "set variables timestamp to text", these were the 3 different syntax i tried but none of them export the rtf with the formatted link. Any suggestions would be really appreciated.

Heres what I have so far:

No I don't. I couldn't create PDFs with hyperlinks either, when I tried a while back.

I have two thoughts. The first is to format it in HTML and save it as an HTML file. If you're going to email the results, this might actually work well. The second is that depending on what app is used to open the file, often-times you can right-click and there's an option to "Open URL" or something like that.

Other than that, I don't have any ideas.

@ccstone Hey Chris - do you have any idea how to save a document (of any type, really) so that URLs are clickable hyperlinks? Thanks.

I'm obviously not Chris, but here are some ideas that have worked for me:

  1. Print web page to PDF
  2. Save Word file as PDF
  3. Save Excel as PDF

I haven't tried it, but I'd expect the same if you save a TextEdit RTF file, or a Pages file, to PDF.

Thanks, Jim.

Printing to PDF and saving Word as PDF doesn't create clickable links, at least not in my experience, and I tried them extensively a could of years ago. I'd love to be proven wrong, though.

@DanThomas, just try it. Works for me.

Well, that's interesting! I have a PDF I made in October of 2018, and the links weren't clickable then, but they are now. So since the PDF didn't change, something in the OS must have. Or else I'm just crazy, which isn't outside the realm of possibility.

Thanks for double-checking!

1 Like

Hey everyone thanks so much for your help!

I'm not sure if my question was clear... what I meant to ask was how to I export text that is inside a KM variable... how do I export out of KM to a file that has the links formatted correctly. What I want is this:

30:42

but what i get when i export rtf I get this:

[30:42](https://www.youtube.com/watch=KzvaDZVSk3c?t=1842)

How do I format the text inside KM so that when it exports it formats correctly? I hope this makes sense.

Thanks in advance!

In order to create a hyperlink that is clickable, you need to create the HTML code and then save as a .html file. Then open that file in any web browser.

See:

EDIT: I forgot that you could also create the links using Markdown, save to a .md file, and then open with any Markdown viewer/editor.