Need a regexp to extract embedded videos with html tag

Here is a regexp given by Mark and Saq which I use to extract embedded images in [img].filename.png] format

\define spotlight-actions()
<$vars
	myCur=<<currentTiddler>>
	sp=""" """
	img1="\[img\["
	img2=".jpg\]\]"
>
<$action-spotlight
	$images={{{[<myCur>get[text]search-replace:gi:regexp[\n],<sp>search-replace:gi:regexp<img1>,[@1@@]split[@1]prefix[@@]search-replace:gi:regexp<img2>,[.jpg@@]split[@@]regexp[(\.jpg$)]] :and[format:titlelist[]join[ ]]}}}
/>
</$vars>
\end

<$button actions=<<spotlight-actions>> > {{$:/images/dripicons/photo-group}}</$button>

Now I need such a regexp to extract all embedded videos in a tiddler which are displayed in the format given below

<video width='80%' controls preload='metadata'> <source src='relative_path.mp4' type='video/mp4'>  </video>

Can anyone help ?

1 Like

@arunnbabu81 thanks for sharing, I notice you use <$action-spotlight without providing any information about it.

Check this tiddler and press the image beneath the title of the tiddler. A sidetabs with images in spotlight mode opens on the right side of the tiddler body

I am using this to hide the images from the tiddler body and show them in the sidetabs on the right side to reduce the visual clutter while reading the tiddler text field and also to scroll and see the images on the right sidetabs while I am reading the tiddler text.

I now need to replicate this function with videos. But for that I need a regexp to extract the videos with html video tags.

Bacxk to your original Question, is this a batchg process you want to do once, or will it always need to happen? will you remove the existing snippit?

What information do you want from your snippit, ie just relative_path.mp4

<video width='80%' controls preload='metadata'> 
<source src='relative_path.mp4' type='video/mp4'> </video>

Regex is not a strong point of mine, but I have other ways. But this sounds like paret of a bigger question, which may have other answers.

If this is part of your spot light tool, you could transclude the video both in the sidebar and the story river but with a condition in each case.

I need to extract and list all emebedded html videos together so that I can see them in the sidetabs on the right side separately (while hiding the videos in the tiddler body).
For this I need to extract the whole snippet including the html video tags I suppose

<video width='80%' controls preload='metadata'> 
<source src='relative_path.mp4' type='video/mp4'> </video>

But what is the snipit in? a text field? Is it on its own line?

It’s in the text field. Or should I use separate tiddlers for videos and embed them in the parent tiddler. I didn’t want to use seperate tiddlers for each videos since I have many such videos mostly local files

If your cloning a new button couldn’t you just adjust the start and end.

img1="\<video"
img2="\<\/video>"

or if you want one button for both maybe

img1="(\[img\[|\<video)"
img2="(.jpg\]\]|\</video>)"
2 Likes

Thank you @john.edw_gmail.com for helping out

I tried like this

<$vars
    myCur=<<currentTiddler>>
    sp=""" """
    vid1="\<video"
    vid2="\<\/video>"
    delink="\[\[.*?\]\]"
>

{{{[<myCur>get[text]search-replace:gi:regexp[\n],<sp>search-replace:gi:regexp<delink>,[]search-replace:gi:regexp<vid1>,[@1@@]split[@1]prefix[@@]search-replace:gi:regexp<vid2>,[.mp4@@]split[@@]regexp[(\.mp4$)]] :and[format:titlelist[]join[ ]]}}}

This is the result

How to remove the [[ and ]] at the beginning & end and replace it with <video & </video> respectively

1 Like

Try this:

<$let
  myCur=<<currentTiddler>>
  sp=""" """
  vid1="\<video"
  vid2="\<\/video>"
  vid3="\<\/video>$"
  delink="\[\[.*?\]\]"
>

{{{[<myCur>get[text]search-replace:gi:regexp[\n],<sp>search-replace:gi:regexp<delink>,[]search-replace:gi:regexp<vid1>,[@1@@<video]split[@1]prefix[@@]search-replace:gi:regexp<vid2>,[</video>@@]split[@@]regexp<vid3>] :and[join[ ]]}}}  

Fred

1 Like

@tw-FRed Thank you. It almost works. The regexp correctly extracts the video, but they are displayed as links. How to modify the code to display them as video itself.

https://arsheth-ui.tiddlyhost.com/

Here is the code tiddler and this is the video tiddler demo of what I am doing

2 Likes

triple brackets return a list of title titles, so you get a single (missing) tiddler title

try

<$list filter="[<myCur>get[text]search-replace:gi:regexp[\n],<sp>search-replace:gi:regexp<delink>,[]search-replace:gi:regexp<vid1>,[@1@@<video]split[@1]prefix[@@]search-replace:gi:regexp<vid2>,[</video>@@]split[@@]regexp<vid3>]">
<<currentTiddler>>
</$list>
2 Likes

thank you @buggyj it works perfectly now. Many thanks to @tw-FRed also.