Parameterised URL for the Video pane

I have been trying to create a Video pane using a url with parameters so that I can link to videos hosted on AWS S3. An example url would look like this: https://file-examples-com.github.io/uploads/2017/04/file_example_MP4_480_1_5MG.mp4?hello=world. However the isurl method that is called to validate this url expects it to end with ".mp4", which itself is a little strict.

import panel as pn

pn.pane.Video("https://file-examples-com.github.io/uploads/2017/04/file_example_MP4_480_1_5MG.mp4?hello=world")

Should I not be doing this? If this is just an oversight in the method would it be sensible to replace the logic of isurl so that it validates using a proper url library and ignores parameters?

1 Like

Hi @sheldon

Welcome to the community.

The problem is the below validation. Could you create an issue on Github and maybe even a PR to fix it?

Thanks for confirming I already modified locally and it worked. I will put in a PR tomorrow with the fix.

1 Like

I think this has already been fixed by @philippjfr in https://github.com/holoviz/panel/pull/2037.

1 Like

Sorry, @sheldon your contribution would have been greatly appreciated but I’m still trying to release tonight so wanted to get the fix in asap.

1 Like

Thanks for letting me know, saved me wasting time. I was going to suggest a regression test:

def test_isurl():
url_without_parameters = β€œhttps://file-examples-com.github.io/uploads/2017/04/file_example_MP4_480_1_5MG.mp4”
url_with_parameters = β€œhttps://file-examples-com.github.io/uploads/2017/04/file_example_MP4_480_1_5MG.mp4?Expires=1614602942”

assert isurl(url_without_parameters)
assert isurl(url_with_parameters)

but I see you have merged it already.

@Marc @philippjfr I just realised that this does not completely fix my original problem because I had hacked in a fix locally and never tested this one. The second issue for me was that I was using a presigned url to fetch the video and it looks like this: https://some-user.s3.amazonaws.com/media/video/457874dsfsd-dfdsfd-erer-45454-dfdf/original_safeguarded?AWSAccessKeyId=ASDFJDFD34384739784DFD&Signature=SDFSD545345DFGDFG&Expires=162469845984

Essentially the object has no file ending because it is just stored with a uuid on cloud storage. It seems the other issue was that this part of the check
and (formats is None or any(lower_string.endswith('.'+fmt) for fmt in formats))
also fails.

Is there a better way to do the validation for valid formats? I actually don’t know a solution off the top of my head. Happy to do the PR with a little assistance.

Thanks,

Sheldon

1 Like

Hi @sheldon

As I see it there is no general solution for this as the .applies is used guess which panel to apply to an unknown object. Normally you would not use Video on any url.

But you might be able to create a CustomVideo class supporting your use case. Something along the lines of

import panel as pn

class CustomVideo(pn.pane.Video):
    @classmethod
    def applies(cls, obj):
        if isinstance(obj, str) and str.startswith("https://some-user.s3.amazonaws.com/media/video/"):
            return True
        return super(pn.pane.Video, cls).applies(obj)


CustomVideo("https://some-user.s3.amazonaws.com/media/video/457874dsfsd-dfdsfd-erer-45454-dfdf/original_safeguarded?AWSAccessKeyId=ASDFJDFD34384739784DFD&Signature=SDFSD545345DFGDFG&Expires=162469845984")

Let me know if it works.

Thanks for the suggestion @Marc . I can see why the restriction is there. I think your suggestion is nice and pragmatic. I will give it a go and let you know.