Skip to content

Commit

Permalink
MediaEmbed: updated Facebook
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshyPHP committed Aug 18, 2024
1 parent 9e72cf7 commit bc9958e
Show file tree
Hide file tree
Showing 7 changed files with 99 additions and 83 deletions.
1 change: 1 addition & 0 deletions docs/testdox.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6894,6 +6894,7 @@ Parser (s9e\TextFormatter\Tests\Plugins\MediaEmbed\Parser)
[x] Scraping tests with data set #53
[x] Scraping tests with data set #54
[x] Scraping tests with data set #55
[x] Scraping tests with data set #56
[x] Scraping+rendering tests with data set #0
[x] Scraping+rendering tests with data set #1
[x] Scraping+rendering tests with data set #2
Expand Down
48 changes: 24 additions & 24 deletions src/Bundles/Fatdown.php

Large diffs are not rendered by default.

40 changes: 20 additions & 20 deletions src/Bundles/Forum.php

Large diffs are not rendered by default.

76 changes: 38 additions & 38 deletions src/Bundles/MediaPack.php

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class CachedDefinitionCollection extends SiteDefinitionCollection
'dumpert'=>['attributes'=>[],'example'=>'https://www.dumpert.nl/item/6622577_4652b140','extract'=>['!dumpert\\.nl/(?:item|mediabase)/(?\'id\'\\d+[/_]\\w+)!'],'homepage'=>'https://www.dumpert.nl/','host'=>['dumpert.nl'],'iframe'=>['src'=>'//www.dumpert.nl/embed/{translate(@id,\'/\',\'_\')}'],'name'=>'dumpert','scrape'=>[],'tags'=>['.nl','entertainment']],
'eighttracks'=>['attributes'=>[],'example'=>['https://8tracks.com/lovinq/headphones-in-world-out','https://8tracks.com/lovinq/4982023'],'extract'=>['!8tracks\\.com/[-\\w]+/(?\'id\'\\d+)(?=#|$)!'],'homepage'=>'https://8tracks.com/','host'=>['8tracks.com'],'iframe'=>['height'=>400,'src'=>'//8tracks.com/mixes/{@id}/player_v3_universal','width'=>400],'name'=>'8tracks','scrape'=>[['extract'=>['!eighttracks://mix/(?\'id\'\\d+)!'],'match'=>['!8tracks\\.com/[-\\w]+/\\D!']]],'tags'=>['music']],
'espn'=>['attributes'=>[],'example'=>['https://www.espn.com/video/clip?id=17474659','https://www.espn.com/espnw/video/13887284/kyrgios-angry-code-violation-almost-hitting-ref','https://broadband.espn.go.com/video/clip?id=17481969'],'extract'=>['#video/(?:clip(?:\\?id=|/_/id/))?(?\'id\'\\d+)#'],'homepage'=>'https://www.espn.com/','host'=>['espn.com','espn.go.com'],'iframe'=>['src'=>'//www.espn.com/core/video/iframe?id={@id}'],'name'=>'ESPN','scrape'=>[],'tags'=>['sports']],
'facebook'=>['amp'=>['custom-element'=>'amp-facebook','src'=>'https://cdn.ampproject.org/v0/amp-facebook-0.1.js','template'=>'<amp-facebook layout="responsive" width="640" height="360"><xsl:if test="starts-with(@type,\'v\')"><xsl:attribute name="data-embed-as">video</xsl:attribute></xsl:if><xsl:attribute name="data-href">https://www.facebook.com/<xsl:choose><xsl:when test="@user"><xsl:value-of select="@user"/></xsl:when><xsl:otherwise>user</xsl:otherwise></xsl:choose>/<xsl:choose><xsl:when test="starts-with(@type,\'v\')">video</xsl:when><xsl:otherwise>post</xsl:otherwise></xsl:choose>s/<xsl:value-of select="@id"/></xsl:attribute></amp-facebook>'],'attributes'=>[],'example'=>['https://www.facebook.com/MetaforDevelopers/posts/451016937058647','https://www.facebook.com/watch/?v=224353158889229','https://fb.watch/3zYsXdnxjf/','https://www.facebook.com/reel/873906321076441'],'extract'=>['@facebook\\.com/.*?(?:fbid=|/permalink/|\\?v=)(?\'id\'\\d+)@','@facebook\\.com/(?\'user\'[.\\w]+)/(?\'type\'[pv])(?:ost|ideo)s?/(?\'id\'\\d+)@','@facebook\\.com/video/(?=post|video)(?\'type\'[pv])@','@facebook\\.com/events/(?\'id\'\\d+)\\b(?!/permalink)@','@facebook\\.com/watch/\\?(?\'type\'[pv])=@','@facebook.com/groups/[^/]*/(?\'type\'p)osts/(?\'id\'\\d+)@','@facebook\\.com/(?\'user\'[.\\w]+)/posts/pfbid(?\'pfbid\'\\w+)@','@facebook\\.com/permalink\\.php\\?story_fbid=(?:(?\'id\'\\d+)|pfbid(?\'pfbid\'\\w+))&id=(?\'page_id\'\\d+)@','@facebook\\.com/(?\'user\'[.\\w]+)/(?\'type\'v)ideos/[^/]+/(?\'id\'\\d+)/@','@facebook\\.com/(?\'type\'r)eel/(?\'id\'\\d+)@'],'homepage'=>'https://www.facebook.com/','host'=>['facebook.com','fb.watch'],'iframe'=>['data-s9e-livepreview-ignore-attrs'=>'style','onload'=>'let c=new MessageChannel;c.port1.onmessage=e=>this.style.height=e.data+\'px\';this.contentWindow.postMessage(\'s9e:init\',\'*\',[c.port2])','src'=>'https://s9e.github.io/iframe/2/facebook.min.html#<xsl:choose><xsl:when test="@user"><xsl:value-of select="@user"/>/<xsl:choose><xsl:when test="@type=\'r\'or@type=\'v\'">video</xsl:when><xsl:otherwise>post</xsl:otherwise></xsl:choose>s/<xsl:choose><xsl:when test="@id"><xsl:value-of select="@id"/></xsl:when><xsl:otherwise>pfbid<xsl:value-of select="@pfbid"/></xsl:otherwise></xsl:choose></xsl:when><xsl:when test="@id"><xsl:value-of select="@type"/><xsl:value-of select="@id"/></xsl:when><xsl:otherwise>pfbid<xsl:value-of select="@pfbid"/></xsl:otherwise></xsl:choose>'],'name'=>'Facebook','scrape'=>[['extract'=>['@facebook\\.com/(?\'user\'[.\\w]+)/(?\'type\'[pv])\\w+/(?\'id\'\\d+)(?!\\w)@'],'header'=>'User-agent: PHP (not Mozilla)','match'=>['@facebook\\.com/[.\\w]+/posts/pfbid@'],'url'=>'https://www.facebook.com/plugins/post.php?href=https%3A%2F%2Fwww.facebook.com%2F{@user}%2Fposts%2Fpfbid{@pfbid}'],['extract'=>['@story_fbid=(?\'id\'\\d+)@'],'header'=>'User-agent: PHP (not Mozilla)','match'=>['@facebook\\.com/permalink\\.php\\?story_fbid=pfbid(?\'pfbid\'\\w+)&id=(?\'page_id\'\\d+)@'],'url'=>'https://www.facebook.com/plugins/post.php?href=https%3A%2F%2Fwww.facebook.com%2Fpermalink.php%3Fstory_fbid%3Dpfbid{@pfbid}%26id%3D{@page_id}'],['extract'=>['@facebook\\.com/watch/\\?(?\'type\'v)=(?\'id\'\\d+)@','@facebook\\.com/(?\'user\'[.\\w]+)/(?\'type\'v)ideos/(?\'id\'\\d+)@'],'header'=>'User-agent: PHP (not Mozilla)','match'=>['@fb\\.watch/.@']]],'tags'=>['social'],'tracking_policy'=>'https://www.facebook.com/help/1896641480634370'],
'facebook'=>['amp'=>['custom-element'=>'amp-facebook','src'=>'https://cdn.ampproject.org/v0/amp-facebook-0.1.js','template'=>'<amp-facebook layout="responsive" width="640" height="360"><xsl:if test="starts-with(@type,\'v\')"><xsl:attribute name="data-embed-as">video</xsl:attribute></xsl:if><xsl:attribute name="data-href">https://www.facebook.com/<xsl:choose><xsl:when test="@user"><xsl:value-of select="@user"/></xsl:when><xsl:otherwise>user</xsl:otherwise></xsl:choose>/<xsl:choose><xsl:when test="starts-with(@type,\'v\')">video</xsl:when><xsl:otherwise>post</xsl:otherwise></xsl:choose>s/<xsl:value-of select="@id"/></xsl:attribute></amp-facebook>'],'attributes'=>[],'example'=>['https://www.facebook.com/MetaforDevelopers/posts/451016937058647','https://www.facebook.com/watch/?v=224353158889229','https://fb.watch/3zYsXdnxjf/','https://www.facebook.com/reel/873906321076441'],'extract'=>['@facebook\\.com/.*?(?:fbid=|/permalink/|\\?v=)(?\'id\'\\d+)@','@facebook\\.com/(?\'user\'[.\\w]+)/(?\'type\'[pv])(?:ost|ideo)s?/(?\'id\'\\d+)@','@facebook\\.com/video/(?=post|video)(?\'type\'[pv])@','@facebook\\.com/events/(?\'id\'\\d+)\\b(?!/permalink)@','@facebook\\.com/watch/\\?(?\'type\'[pv])=@','@facebook.com/groups/[^/]*/(?\'type\'p)osts/(?\'id\'\\d+)@','@facebook\\.com/(?\'user\'[.\\w]+)/posts/pfbid(?\'pfbid\'\\w+)@','@facebook\\.com/permalink\\.php\\?story_fbid=(?:(?\'id\'\\d+)|pfbid(?\'pfbid\'\\w+))&id=(?\'page_id\'\\d+)@','@facebook\\.com/(?\'user\'[.\\w]+)/(?\'type\'v)ideos/[^/]+/(?\'id\'\\d+)/@','@facebook\\.com/(?\'type\'r)eel/(?\'id\'\\d+)@'],'homepage'=>'https://www.facebook.com/','host'=>['facebook.com','fb.watch'],'iframe'=>['data-s9e-livepreview-ignore-attrs'=>'style','onload'=>'let c=new MessageChannel;c.port1.onmessage=e=>this.style.height=e.data+\'px\';this.contentWindow.postMessage(\'s9e:init\',\'*\',[c.port2])','src'=>'https://s9e.github.io/iframe/2/facebook.min.html#<xsl:choose><xsl:when test="@user"><xsl:value-of select="@user"/>/<xsl:choose><xsl:when test="@type=\'r\'or@type=\'v\'">video</xsl:when><xsl:otherwise>post</xsl:otherwise></xsl:choose>s/<xsl:choose><xsl:when test="@id"><xsl:value-of select="@id"/></xsl:when><xsl:otherwise>pfbid<xsl:value-of select="@pfbid"/></xsl:otherwise></xsl:choose></xsl:when><xsl:when test="@id"><xsl:value-of select="@type"/><xsl:value-of select="@id"/></xsl:when><xsl:otherwise>pfbid<xsl:value-of select="@pfbid"/></xsl:otherwise></xsl:choose>'],'name'=>'Facebook','scrape'=>[['extract'=>['@facebook\\.com/(?\'user\'[.\\w]+)/(?\'type\'[pv])\\w+/(?\'id\'\\d+)(?!\\w)@'],'header'=>'User-agent: PHP (not Mozilla)','match'=>['@facebook\\.com/[.\\w]+/posts/pfbid@'],'url'=>'https://www.facebook.com/plugins/post.php?href=https%3A%2F%2Fwww.facebook.com%2F{@user}%2Fposts%2Fpfbid{@pfbid}'],['extract'=>['@story_fbid=(?\'id\'\\d+)@'],'header'=>'User-agent: PHP (not Mozilla)','match'=>['@facebook\\.com/permalink\\.php\\?story_fbid=pfbid(?\'pfbid\'\\w+)&id=(?\'page_id\'\\d+)@'],'url'=>'https://www.facebook.com/plugins/post.php?href=https%3A%2F%2Fwww.facebook.com%2Fpermalink.php%3Fstory_fbid%3Dpfbid{@pfbid}%26id%3D{@page_id}'],['extract'=>['@facebook\\.com/watch/\\?(?\'type\'v)=(?\'id\'\\d+)@','@facebook\\.com/(?\'user\'[.\\w]+)/(?\'type\'v)ideos/(?\'id\'\\d+)@'],'header'=>'User-agent: PHP (not Mozilla)','match'=>['@fb\\.watch/.@']],['extract'=>['@facebook\\.com/\\w+/(?\'user\'[.\\w]+)/permalink/(?\'id\'\\d+)(?!\\w)@'],'header'=>'User-agent: PHP (not Mozilla)','match'=>['@facebook\\.com/share/[pv]/\\w@']]],'tags'=>['social'],'tracking_policy'=>'https://www.facebook.com/help/1896641480634370'],
'falstad'=>['attributes'=>[],'example'=>'https://www.falstad.com/circuit/circuitjs.html?cct=$+1+0.000005+10.20027730826997+50+5+43+v+176+272+256+144+0+0+40+5+0+0+0.5+w+176+272+336+272+0+r+336+272+256+144+0+1000','extract'=>['!falstad\\.com/circuit/circuitjs\\.html\\?c(?:ct=(?\'cct\'[^&]+)|tz=(?\'ctz\'[-+=\\w]+))!'],'homepage'=>'https://www.falstad.com/circuit/circuitjs.html','host'=>['falstad.com'],'iframe'=>['height'=>500,'src'=>'https://www.falstad.com/circuit/circuitjs.html?running=false&amp;c<xsl:choose><xsl:when test="@cct">ct=<xsl:value-of select="@cct"/></xsl:when><xsl:otherwise>tz=<xsl:value-of select="@ctz"/></xsl:otherwise></xsl:choose>','style'=>['max-height'=>'90vh'],'width'=>'100%'],'name'=>'Falstad Circuit Simulator','scrape'=>[]],
'flickr'=>['attributes'=>[],'example'=>['https://www.flickr.com/photos/8757881@N04/2971804544/lightbox/','https://flic.kr/8757881@N04/2971804544','https://flic.kr/p/5wBgXo'],'extract'=>['@flickr\\.com/photos/[^/]+/(?\'id\'\\d+)@','@flic\\.kr/(?!p/)[^/]+/(?\'id\'\\d+)@'],'homepage'=>'https://www.flickr.com/','host'=>['flic.kr','flickr.com'],'iframe'=>['height'=>500,'src'=>'https://www.flickr.com/photos/_/{@id}/player/','width'=>500],'name'=>'Flickr','scrape'=>[['extract'=>['@flickr\\.com/photos/[^/]+/(?\'id\'\\d+)@'],'match'=>['@flic\\.kr/p/(?\'short\'\\w+)@'],'url'=>'https://www.flickr.com/photo.gne?rb=1&short={@short}']],'tags'=>['images']],
'foxnews'=>['attributes'=>[],'example'=>'https://video.foxnews.com/v/3592758613001/reddit-helps-fund-homemade-hot-sauce-venture/','extract'=>['!video\\.foxnews\\.com/v/(?\'id\'\\d+)!'],'homepage'=>'https://www.foxnews.com/','host'=>['video.foxnews.com'],'iframe'=>['src'=>'//video.foxnews.com/v/video-embed.html?video_id={@id}'],'name'=>'Fox News','scrape'=>[],'tags'=>['news']],
Expand Down
5 changes: 5 additions & 0 deletions src/Plugins/MediaEmbed/Configurator/sites/facebook.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@
<extract>@facebook\.com/watch/\?(?'type'v)=(?'id'\d+)@</extract>
<extract>@facebook\.com/(?'user'[.\w]+)/(?'type'v)ideos/(?'id'\d+)@</extract>
</scrape>
<scrape>
<header>User-agent: PHP (not Mozilla)</header>
<match>@facebook\.com/share/[pv]/\w@</match>
<extract>@facebook\.com/\w+/(?'user'[.\w]+)/permalink/(?'id'\d+)(?!\w)@</extract>
</scrape>

<iframe onload="let c=new MessageChannel;c.port1.onmessage=e=>this.style.height=e.data+'px';this.contentWindow.postMessage('s9e:init','*',[c.port2])" data-s9e-livepreview-ignore-attrs="style">
<src><![CDATA[
Expand Down
10 changes: 10 additions & 0 deletions tests/Plugins/MediaEmbed/ParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,16 @@ function ($configurator)
$configurator->MediaEmbed->add('facebook');
}
],
[
'https://www.facebook.com/share/p/EMMeAHj1cLMNWAER/',
'<r><FACEBOOK id="2603488166519287" user="francepermaculture">https://www.facebook.com/share/p/EMMeAHj1cLMNWAER/</FACEBOOK></r>',
[],
function ($configurator)
{
$configurator->registeredVars['cacheDir'] = __DIR__ . '/../../.cache';
$configurator->MediaEmbed->add('facebook');
}
],
[
'https://flic.kr/p/5wBgXo',
'<r><FLICKR id="2971804544">https://flic.kr/p/5wBgXo</FLICKR></r>',
Expand Down

0 comments on commit bc9958e

Please sign in to comment.