React-player: Bug: canPlay is returning true for all facebook URLs

Created on 1 Feb 2020  路  9Comments  路  Source: cookpete/react-player

Current Behavior

After the new update the canPlay function is returning true for all facebook URLs because of the new matcher. This results in a lot of false positives.

Expected Behavior

canPlay should only return true if it actually can be played.

Most helpful comment

@CookPete I've improved it a bit to not match any facebook pages which include watch or video.

https://regexr.com/4tdur

All 9 comments

If anyone can find or create a regex pattern that matches all playable facebook URLs (and solves https://github.com/CookPete/react-player/issues/778) I'll be happy to use it.

@sapkra @CookPete let's start with this. @sapkra are you aware of any url formats that don't work with it?

 const url = ..................
 const matchFacebookUrl = /facebook\.com\/([^/?].+\/)?video(s|\.php)[/?].*$/
 const isFBVideo = matchFacebookUrl.test(url)
 console.log(isFBVideo)

@paulincai That pattern doesn't match the URL in #778

I'm tempted by this:

^https?://www\.facebook\.com.*/(video|watch).+$

Which just matches any facebook.com url that contains /watch or /video somewhere in it. Quite terse but still covers most use cases:

https://regex101.com/r/VW2BBg/2

@CookPete I've improved it a bit to not match any facebook pages which include watch or video.

https://regexr.com/4tdur

@CookPete I get it.

Not related to the present issue/task, the thing is that I use a scrapper for all web content that lands in my platform and the URL in #778, "https://www.facebook.com/watch/?v=499831560618548" ends up as "https://www.facebook.com/francknicolasofficiel/videos/499831560618548/"
This is the "real" URL that ReactPlayer actually plays because the FB SDK returns this URL not the "watch" url.

And now I remember that I decided to rely on the scrapper for consistency of all URLs having them correctly formatted before saving to DB.

I am for @sapkra 's regex. I think it covers well.

Nice one @sapkra. Updated and published in [email protected]. Cheers all for the help.

ok, here's another one, at least for the reference. There is a video URL format which re-re-directs in Facebook.

This is a video content: https://www.facebook.com/story.php?story_fbid=10156618238668888&id=9328458887

the video URL is https://www.facebook.com/adidasoriginals/videos/10156618238668888/

@paulincai Updated the regex in my link to also match this one if necessary.

Updated regex in [email protected]

Was this page helpful?
0 / 5 - 0 ratings

Related issues

marcuscaum picture marcuscaum  路  3Comments

sedubois picture sedubois  路  6Comments

rpaschoal picture rpaschoal  路  5Comments

intelligence picture intelligence  路  3Comments

MDrooker picture MDrooker  路  6Comments