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
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?
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.
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.
Thanks for letting me know, saved me wasting time. I was going to suggest a regression test:
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”
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:
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))
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.
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
def applies(cls, obj):
if isinstance(obj, str) and str.startswith("https://some-user.s3.amazonaws.com/media/video/"):
return super(pn.pane.Video, cls).applies(obj)
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.