Skip to content

Commit 9e42969

Browse files
committed
MediaEmbed: added PeerTube
1 parent 5de379d commit 9e42969

File tree

9 files changed

+175
-90
lines changed

9 files changed

+175
-90
lines changed

docs/Plugins/MediaEmbed/Sites.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,10 @@
333333
<td><code>pastebin</code></td>
334334
<td>https://pastebin.com/9jEf44nc</td>
335335
</tr>
336+
<tr title="PeerTube" id="peertube">
337+
<td><code>peertube</code></td>
338+
<td>https://peertube.tv/w/5JHc2MW1LS4HjDExModcwo</td>
339+
</tr>
336340
<tr title="Pinterest" id="pinterest">
337341
<td><code>pinterest</code></td>
338342
<td>https://www.pinterest.com/pin/99360735500167749/<br/>https://www.pinterest.com/pinterest/official-news/</td>

docs/Plugins/MediaEmbed/Using_default_sites.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ echo count($configurator->MediaEmbed->defaultSites), " sites remaining.\n";
7777
```
7878
Does YouTube exist? yes
7979
What about now? no
80-
136 sites remaining.
80+
137 sites remaining.
8181
0 sites remaining.
8282
```
8383

docs/testdox.txt

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1919,7 +1919,7 @@ Quick (s9e\TextFormatter\Tests\Configurator\RendererGenerators\PHP\Quick)
19191919
[x] Renders plain text
19201920
[x] Renders multi-line text
19211921
[x] Renders rich text
1922-
[x] Ignores locale
1922+
[ ] Ignores locale
19231923
[x] getParameter() returns the default value of a parameter
19241924
[x] getParameter() returns the set value of a parameter
19251925
[x] getParameter() returns an empty string for undefined parameters
@@ -3439,7 +3439,7 @@ Fix Unescaped Curly Braces In Html Attributes (s9e\TextFormatter\Tests\Configura
34393439
[x] Works with data set #20
34403440

34413441
Fold Arithmetic Constants (s9e\TextFormatter\Tests\Configurator\TemplateNormalizations\FoldArithmeticConstants)
3442-
[x] Ignores locale
3442+
[ ] Ignores locale
34433443
[x] Works with data set #0
34443444
[x] Works with data set #1
34453445
[x] Works with data set #2
@@ -3475,7 +3475,7 @@ Fold Arithmetic Constants (s9e\TextFormatter\Tests\Configurator\TemplateNormaliz
34753475
[x] Works with data set #32
34763476

34773477
Fold Constant XPath Expressions (s9e\TextFormatter\Tests\Configurator\TemplateNormalizations\FoldConstantXPathExpressions)
3478-
[x] Ignores locale
3478+
[ ] Ignores locale
34793479
[x] Works with data set #0
34803480
[x] Works with data set #1
34813481
[x] Works with data set #2
@@ -6908,6 +6908,9 @@ Parser (s9e\TextFormatter\Tests\Plugins\MediaEmbed\Parser)
69086908
[x] Scraping tests with data set #61
69096909
[x] Scraping tests with data set #62
69106910
[x] Scraping tests with data set #63
6911+
[x] Scraping tests with data set #64
6912+
[x] Scraping tests with data set #65
6913+
[x] Scraping tests with data set #66
69116914
[x] Scraping+rendering tests with data set #0
69126915
[x] Scraping+rendering tests with data set #1
69136916
[x] Scraping+rendering tests with data set #2
@@ -7934,7 +7937,7 @@ PHP (s9e\TextFormatter\Tests\Renderers\PHP)
79347937
[x] Renders plain text
79357938
[x] Renders multi-line text
79367939
[x] Renders rich text
7937-
[x] Ignores locale
7940+
[ ] Ignores locale
79387941
[x] getParameter() returns the default value of a parameter
79397942
[x] getParameter() returns the set value of a parameter
79407943
[x] getParameter() returns an empty string for undefined parameters
@@ -7974,7 +7977,7 @@ XSLT (s9e\TextFormatter\Tests\Renderers\XSLT)
79747977
[x] Renders plain text
79757978
[x] Renders multi-line text
79767979
[x] Renders rich text
7977-
[x] Ignores locale
7980+
[ ] Ignores locale
79787981
[x] getParameter() returns the default value of a parameter
79797982
[x] getParameter() returns the set value of a parameter
79807983
[x] getParameter() returns an empty string for undefined parameters
@@ -8083,7 +8086,7 @@ XPath (s9e\TextFormatter\Utils\XPath)
80838086
[x] export('"\'') returns concat('"',"'")
80848087
[x] export(123) returns 123
80858088
[x] export(123.45) returns 123.45
8086-
[x] export(123.45) returns 123.45 regardless of locale
8089+
[ ] export(123.45) returns 123.45 regardless of locale
80878090
[x] export(new stdClass) throws an exception
80888091
[x] export(false) returns 'false()'
80898092
[x] export(true) returns 'true()'

src/Bundles/MediaPack.php

Lines changed: 81 additions & 80 deletions
Large diffs are not rendered by default.

src/Bundles/MediaPack/Renderer.php

Lines changed: 3 additions & 3 deletions
Large diffs are not rendered by default.

src/Plugins/MediaEmbed/Configurator/Collections/CachedDefinitionCollection.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ class CachedDefinitionCollection extends SiteDefinitionCollection
9393
'on3'=>['attributes'=>[],'example'=>['https://www.on3.com/rivals/darion-jones-240802/','https://www.on3.com/db/christian-jones-150372/industry-comparison/'],'extract'=>['!/db/(?:[-\\w]*-)?(?\'id\'[0-9]+)/industry-comparison/!','!/rivals/(?:[-\\w]*-)?(?\'id\'[0-9]+)/!'],'homepage'=>'https://www.on3.com/db/','host'=>['on3.com'],'iframe'=>['data-s9e-livepreview-ignore-attrs'=>'style','height'=>476,'onload'=>'let b=this.contentWindow;window.addEventListener(\'message\',a=>{{a.source===b&&a.data.height&&(this.style.height=+a.data.height+20+\'px\')}});b.postMessage(\'\',\'*\')','src'=>'https://embed.on3.com/db/{@id}/industry-comparison/','width'=>600],'name'=>'On3 DB','scrape'=>[],'tags'=>['sports']],
9494
'orfium'=>['attributes'=>[],'example'=>['https://www.orfium.com/album/24371/everybody-loves-kanye-totom/','https://www.orfium.com/live-set/614763/foof-no-lights-5-foof/','https://www.orfium.com/playlist/511651/electronic-live-sessions-creamtronic/','https://www.orfium.com/track/625367/the-ambience-of-the-goss-vistas/'],'extract'=>['@album/(?\'album_id\'\\d+)@','@playlist/(?\'playlist_id\'\\d+)@','@live-set/(?\'set_id\'\\d+)@','@track/(?\'track_id\'\\d+)@'],'homepage'=>'https://www.orfium.com/','host'=>['orfium.com'],'iframe'=>['height'=>'<xsl:choose><xsl:when test="@album_id">550</xsl:when><xsl:otherwise>275</xsl:otherwise></xsl:choose>','max-width'=>900,'src'=>'https://www.orfium.com/embedded/<xsl:choose><xsl:when test="@album_id">album/<xsl:value-of select="@album_id"/></xsl:when><xsl:when test="@playlist_id">playlist/<xsl:value-of select="@playlist_id"/></xsl:when><xsl:when test="@set_id">live-set/<xsl:value-of select="@set_id"/></xsl:when><xsl:otherwise>track/<xsl:value-of select="@track_id"/></xsl:otherwise></xsl:choose>','width'=>'100%'],'name'=>'Orfium','scrape'=>[],'tags'=>['music']],
9595
'pastebin'=>['attributes'=>[],'example'=>'https://pastebin.com/9jEf44nc','extract'=>['@pastebin\\.com/(?!u/)(?:\\w+(?:\\.php\\?i=|/))?(?\'id\'\\w+)@'],'homepage'=>'https://pastebin.com/','host'=>['pastebin.com'],'iframe'=>['height'=>300,'scrolling'=>'','src'=>'//pastebin.com/embed_iframe/{@id}','style'=>['resize'=>'vertical'],'width'=>'100%'],'name'=>'Pastebin','scrape'=>[]],
96+
'peertube'=>['attributes'=>['host'=>['required'=>true],'id'=>['filterChain'=>['#identifier'],'required'=>true],'start'=>['filterChain'=>['#timestamp'],'required'=>false]],'example'=>'https://peertube.tv/w/5JHc2MW1LS4HjDExModcwo','extract'=>['!^https://(?\'host\'[-.\\w]+)/(?:videos/embed|w)/(?\'id\'[-\\w]+)(?:\\?start=(?\'start\'\\d[\\dhms]*))?!'],'homepage'=>'https://joinpeertube.org/','host'=>['peertube.tv'],'iframe'=>['src'=>'https://<xsl:value-of select="@host"/>/videos/embed/<xsl:value-of select="@id"/><xsl:if test="@start">?start=<xsl:value-of select="@start"/></xsl:if>'],'name'=>'PeerTube','scrape'=>[['extract'=>['!https://(?\'host\'[-.\\w]+)/videos/embed/(?\'id\'[-\\w]+)(?:\\?start=(?\'start\'\\d[\\dhms]*))?!'],'match'=>['!^https://(?\'host\'[-.\\w]+)/w/(?\'id\'\\w+)!'],'url'=>'https://{@host}/services/oembed?url=https%3A%2F%2F{@host}%2Fw%2F%2F{@id}']],'tags'=>['videos']],
9697
'pinterest'=>['amp'=>['custom-element'=>'amp-pinterest','src'=>'https://cdn.ampproject.org/v0/amp-pinterest-0.1.js','template'=>'<amp-pinterest width="245" height="330" data-do="embedPin" data-url="https://www.pinterest.com/pin/{@id}/"/>'],'attributes'=>[],'example'=>['https://www.pinterest.com/pin/99360735500167749/','https://www.pinterest.com/pinterest/official-news/'],'extract'=>['@pinterest.com/pin/(?\'id\'\\d+)@','@pinterest.com/(?!_/|discover/|explore/|news_hub/|pin/|search/)(?\'id\'[-\\w]+/[-\\w]+)@'],'homepage'=>'https://www.pinterest.com/','host'=>['pinterest.com'],'iframe'=>['data-s9e-livepreview-ignore-attrs'=>'style','height'=>360,'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/pinterest.min.html#{@id}','width'=>'<xsl:choose><xsl:when test="contains(@id,\'/\')">730</xsl:when><xsl:otherwise>345</xsl:otherwise></xsl:choose>'],'name'=>'Pinterest','scrape'=>[],'source'=>'https://developers.pinterest.com/tools/widget-builder/','tags'=>['social']],
9798
'podbean'=>['attributes'=>[],'example'=>['https://dialhforheroclix.podbean.com/e/dial-h-for-heroclix-episode-46-all-ya-need-is-love/','https://www.podbean.com/ew/pb-gmyyz-d6e065'],'extract'=>['!podbean\\.com/(?:[-\\w]+/)*(?:player[-\\w]*/|\\w+/pb-)(?\'id\'[-\\w]+)!'],'homepage'=>'https://www.podbean.com/','host'=>['podbean.com'],'iframe'=>['height'=>150,'max-width'=>900,'src'=>'https://www.podbean.com/player-v2/?i={@id}','width'=>'100%'],'name'=>'Podbean','scrape'=>[['extract'=>['!podbean\\.com/player[^/]*/\\?i=(?\'id\'[-\\w]+)!'],'header'=>'User-agent: PHP (not Mozilla)','match'=>['@podbean\\.com/(?:media/shar)?e/(?!pb-)@']]],'tags'=>['podcasts']],
9899
'prezi'=>['attributes'=>[],'example'=>'https://prezi.com/5ye8po_hmikp/10-most-common-rookie-presentation-mistakes/','extract'=>['#//prezi\\.com/(?!(?:a(?:bout|mbassadors)|c(?:o(?:llaborate|mmunity|ntact)|reate)|exp(?:erts|lore)|ip(?:ad|hone)|jobs|l(?:ear|ogi)n|m(?:ac|obility)|pr(?:es(?:s|ent)|icing)|recommend|support|user|windows|your)/)(?\'id\'\\w+)/#'],'homepage'=>'https://prezi.com/','host'=>['prezi.com'],'iframe'=>['height'=>400,'src'=>'//prezi.com/embed/{@id}/','width'=>550],'name'=>'Prezi','scrape'=>[],'tags'=>['presentations']],
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php declare(strict_types=1);
2+
3+
/**
4+
* @package s9e\TextFormatter
5+
* @copyright Copyright (c) The s9e authors
6+
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
7+
*/
8+
namespace s9e\TextFormatter\Plugins\MediaEmbed\Configurator;
9+
10+
class PeerTubeHelper extends AbstractConfigurableHostHelper
11+
{
12+
protected function getSiteId(): string
13+
{
14+
return 'peertube';
15+
}
16+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<site name="PeerTube" homepage="https://joinpeertube.org/">
2+
<example>https://peertube.tv/w/5JHc2MW1LS4HjDExModcwo</example>
3+
4+
<tags><tag>videos</tag></tags>
5+
6+
<attributes>
7+
<host required="true" />
8+
<id required="true" filterChain="#identifier"/>
9+
<start required="false" filterChain="#timestamp" />
10+
</attributes>
11+
12+
<host>peertube.tv</host>
13+
<extract>!^https://(?'host'[-.\w]+)/(?:videos/embed|w)/(?'id'[-\w]+)(?:\?start=(?'start'\d[\dhms]*))?!</extract>
14+
<scrape url="https://{@host}/services/oembed?url=https%3A%2F%2F{@host}%2Fw%2F%2F{@id}">
15+
<match>!^https://(?'host'[-.\w]+)/w/(?'id'\w+)!</match>
16+
<extract>!https://(?'host'[-.\w]+)/videos/embed/(?'id'[-\w]+)(?:\?start=(?'start'\d[\dhms]*))?!</extract>
17+
</scrape>
18+
<iframe>
19+
<src><![CDATA[
20+
<xsl:text>https://</xsl:text>
21+
<xsl:value-of select="@host"/>
22+
<xsl:text>/videos/embed/</xsl:text>
23+
<xsl:value-of select="@id"/>
24+
<xsl:if test="@start">?start=<xsl:value-of select="@start"/></xsl:if>
25+
]]></src>
26+
</iframe>
27+
</site>

tests/Plugins/MediaEmbed/ParserTest.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use s9e\TextFormatter\Configurator;
66
use s9e\TextFormatter\Parser\Tag;
7+
use s9e\TextFormatter\Plugins\MediaEmbed\Configurator\PeerTubeHelper;
78
use s9e\TextFormatter\Plugins\MediaEmbed\Configurator\XenForoHelper;
89
use s9e\TextFormatter\Plugins\MediaEmbed\Parser;
910
use s9e\TextFormatter\Tests\Plugins\ParsingTestsRunner;
@@ -971,6 +972,38 @@ function ($configurator)
971972
$configurator->MediaEmbed->add('odysee');
972973
}
973974
],
975+
[
976+
'https://peertube.tv/w/5JHc2MW1LS4HjDExModcwo',
977+
'<r><PEERTUBE host="peertube.tv" id="265b2d65-d5d4-4721-b340-0c1fa932c38e">https://peertube.tv/w/5JHc2MW1LS4HjDExModcwo</PEERTUBE></r>',
978+
[],
979+
function ($configurator)
980+
{
981+
$configurator->registeredVars['cacheDir'] = __DIR__ . '/../../.cache';
982+
$configurator->MediaEmbed->add('peertube');
983+
}
984+
],
985+
[
986+
'https://peertube.tv/w/5JHc2MW1LS4HjDExModcwo?start=5s',
987+
'<r><PEERTUBE host="peertube.tv" id="265b2d65-d5d4-4721-b340-0c1fa932c38e" start="5">https://peertube.tv/w/5JHc2MW1LS4HjDExModcwo?start=5s</PEERTUBE></r>',
988+
[],
989+
function ($configurator)
990+
{
991+
$configurator->registeredVars['cacheDir'] = __DIR__ . '/../../.cache';
992+
$configurator->MediaEmbed->add('peertube');
993+
}
994+
],
995+
[
996+
'https://neat.tube/w/3PWC7CoQnqfZ4AkupAcVGB?start=4s',
997+
'<r><PEERTUBE host="neat.tube" id="3PWC7CoQnqfZ4AkupAcVGB" start="4">https://neat.tube/w/3PWC7CoQnqfZ4AkupAcVGB?start=4s</PEERTUBE></r>',
998+
[],
999+
function ($configurator)
1000+
{
1001+
$configurator->registeredVars['cacheDir'] = __DIR__ . '/../../.cache';
1002+
1003+
$peertubeHelper = new PeerTubeHelper($configurator);
1004+
$peertubeHelper->addHost('neat.tube');
1005+
}
1006+
],
9741007
[
9751008
'https://howtofail.podbean.com/e/how-to-fail-m-gawdat-c19/',
9761009
'<r><PODBEAN id="gmyyz-d6e065">https://howtofail.podbean.com/e/how-to-fail-m-gawdat-c19/</PODBEAN></r>',

0 commit comments

Comments
 (0)