I really don’t do a lot of coding and I really don’t know JavaScript that well and with that what I’m trying to do is create a shortcut that grabs all relevant info from a YouTube video such as video title, date uploaded (medium format), date I created the note(medium format), Channel Name, URL with TimeStamp, duration of video, video description, a section for my own notes, and lastly the transcript down below if I could figure that out.
I have everything working via RegEx except for the Transcript.
Currently this is all done in shortcuts as a share sheet action. The issue I’m having is no matter what I try the only way with my knowledge and understanding that I’ve been able to access the transcript is to open the transcript on the YouTube page then go to share and run my shortcut which will run JavaScript on webpage just to get the xml / html (essentially one line of code).
This works as I can then copy and paste into notes the raw input and see the transcript is there. Transcripts don’t show up without a JavaScript call unless I am overlooking something.
I came up with a RegEx (tested and worked at regex101.com) that for the most part grabs the transcript text only HOWEVER when I try to run the it all at once within a shortcut on a long video (1 hr) it times out.
Ex:
Run JavaScript on webpage with shortcut input
var result = [];
// Get all links from the page
completion(new XMLSerializer().serializeToString(document));
// Call completion to finish
completion(result);
Match (?s)(?<=start-offset=\"\d{4,7}\">)(.*?)(?=<\/div>\s.*<dom-repeat class=\"style-scope ytd-transcript-body-renderer\">)
QuickLook
This times out. For testing I’m just running a shortcut with just this and nothing else.
I found this 3 year old forum post which seemed like it would do the same as what I was attempting to do which is cycle through all parts of a transcript and return the results but I’m having issues doing it either within shortcuts as a run JavaScript on webpage or pasting into scriptable and using the run script command from shortcuts usually with an error about the document. Also I’m unsure I’m doing the variables correctly for the transcript so I wanted to see what this would look like correctly written within shortcuts as a run JavaScript on webpage action or as a script within scriptable so I’ll at least know my focus should be on parsing the correct class.
Example Script I’m trying to using is the full script from the link above. This is my first post and it told me I exceeded the number of links I can include.
I’m not sure posting anything I’ve tried would be useful as it’s wrong and I figured posting what my intent is maybe someone might find a more elegant solution.