Skip to content
This repository has been archived by the owner on Apr 11, 2019. It is now read-only.

Commit

Permalink
Merge pull request #104 from HydraWiki/v.2.7.4
Browse files Browse the repository at this point in the history
Adding support for playlist to the evlplayer using youtube video list
  • Loading branch information
applehat authored Jul 18, 2018
2 parents 018ab85 + 233f0ff commit 49f23db
Show file tree
Hide file tree
Showing 6 changed files with 125 additions and 31 deletions.
6 changes: 6 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
## Patch Notes
### v2.7.4
* Added support for playlist to evlplayer
* Added support for youtube video list
* Updated Documentation for evlplayer
* Added missing dependency for evlplayer in extension.json

### v2.7.3
* Default Twitch VOD to autoplay=false by default
* Allow videos to be sized in 1:1 aspect ratios for special use cases.
Expand Down
53 changes: 43 additions & 10 deletions EmbedVideo.hooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -200,22 +200,36 @@ static public function parseServiceTag( $service, $input, array $args, Parser $p
static public function parseEVL( Parser &$parser ) {
$args = func_get_args();
array_shift( $args );

// handle comma separated video id list
$ids = explode(',', $args[0]);
$id = isset($args[2]) && is_numeric($args[2]) ? $args[2] - 1 : false;
$video = $id !== false && isset($ids[$id]) ? $ids[$id] : array_shift($ids);

// standardise first 2 arguments into strings that parse_str can handle.
$args[0] = "id=".$args[0];
$args[1] = "linktitle=".$args[1];
// standardize first 2 arguments into strings that parse_str can handle.
$args[0] = "id=" . $video;
$args[1] = "linktitle=" . $args[1];

$options = [];
parse_str( implode( "&", $args ), $options );

// default service to youtube for compatibility with vlink
$options['service'] = isset( $options['service'] ) ? $options['service'] : "youtube";

// force to youtubevidelink or youtube if video list is provided
if (count($ids) > 0) {
if ($options['service'] != 'youtube' || $options['service'] != 'youtbuevideolist') {
$options['notice'] = "The video list feature only works with the youtube service. Your service is being overridden.";
}
$options['service'] = count($ids) > 0 && $id === false ? "youtubevideolist" : "youtube";
}

$options = array_merge( self::$validArguments, $options );

// fix for youtube ids that VideoLink would have handled.
if ($options['service'] == 'youtube' && strpos($options['id'], ';') !== false) {
// transform input like Oh8KRy2WV0o;C5rePhJktn0 into Oh8KRy2WV0o
$options['notice'] = "Use of simi-colon delimited video lists is depricated. Only the first video in this list will play.";
$options['notice'] = "Use of semicolon delimited video lists is deprecated. Only the first video in this list will play.";
$options['id'] = strstr($options['id'], ';', true);
}

Expand All @@ -239,6 +253,21 @@ static public function parseEVL( Parser &$parser ) {
}
}

// handle adding playlist for video links for a play all link
if ($options['service'] == 'youtubevideolist' && count($ids) > 0) {
$playlist = implode(',', $ids);
if (!isset($options['urlargs']) || empty($options['urlargs'])) {
// just set the url args to the playlist
$options['urlargs'] = "playlist={$playlist}";
} else {
// break down the url args and inject the playlist.
$urlargs = [];
parse_str($options['urlargs'], $urlargs);
$urlargs['playlist'] = $playlist;
$options['urlargs'] = http_build_query($urlargs);
}
}

$json = json_encode($options);

$link = Xml::element('a', [
Expand Down Expand Up @@ -274,12 +303,15 @@ static public function parseEVLPlayer($input, array $args, Parser $parser, PPFra
$input = "DEFAULT PLAYER REPLACEMENT";
}

$div = Html::element('div', array(
// Parse internal content
$content = $parser->recursiveTagParse($input, $frame);

$div = Html::rawElement('div', array(
'id' => 'vplayerbox-'.$pid,
'class' => 'embedvideo-evlbox vplayerbox'.$class,
'data-size' => $w.'x'.$h,
'style' => $style,
), $input);
), $content);

if ($args['defaultid'] && $args['service']) {
$new = self::parseEV(
Expand All @@ -294,11 +326,12 @@ static public function parseEVLPlayer($input, array $args, Parser $parser, PPFra
$args['autoresize'],
$args['valignment']
)[0];

// replace the default content with the new content
$div = str_replace( $input, $new, $div );
$div = str_replace( $content, $new, $div );
}

return [ $div, 'noParse'=> true, 'isHTML'=> true ];
return [ $div, 'noparse'=> true, 'isHTML'=> true ];
}

/**
Expand All @@ -322,7 +355,7 @@ static public function parseEVU( $parser, $url = null ) {

if (isset($map[$host])) {
if (!is_array($map[$host])) {
// only one possible anser. Set it.
// only one possible answer. Set it.
$service = $map[$host];
} else {
// map by array.
Expand All @@ -332,7 +365,7 @@ static public function parseEVU( $parser, $url = null ) {
$test = $evs->parseVideoID($url);

if ($test !== false && $test !== $url) {
// sucessful parse - safe assumption that this is correct.
// successful parse - safe assumption that this is correct.
$service = $possibleService;
break;
}
Expand Down
36 changes: 27 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,14 +123,14 @@ Alternativly, you can also use the service id as the tag (assuming another exten
| Attribute | Required | Default | Description |
|---------------------------------------------|----------|---------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `service="(See Supported Services below.)"` | yes | | The video service to call. |
| `id="[id|url]"` | yes | | The raw ID of the video or URL from the player page. |
| `dimensions="[WIDTH|WIDTHxHEIGHT|xHEIGHT]"` | no | 640 | Dimensions in pixels to size the embed container. The standard format is width x height where either can be omitted, but the `x` must proceed height to indicate it as the height.<br/>Examples: `480`, `480x320`, `x320`. If the height is not provided it will be calculated automatically from the width and service default ratio.<br/>Some services such as *Gfycat* do not have standard heights and should be specified for each embed. `$wgEmbedVideoDefaultWidth` can be set in `LocalSettings.php` to override the default width. |
| `alignment="[left|center|right|inline]"` | no | none | Align the placement of the video either to the left, centered, or to the right. Inline will allow multiple videos to display side by side without forced line breaks. |
| `id="[id\|url]"` | yes | | The raw ID of the video or URL from the player page. |
| `dimensions="[WIDTH\|WIDTHxHEIGHT\|xHEIGHT]"` | no | 640 | Dimensions in pixels to size the embed container. The standard format is width x height where either can be omitted, but the `x` must proceed height to indicate it as the height.<br/>Examples: `480`, `480x320`, `x320`. If the height is not provided it will be calculated automatically from the width and service default ratio.<br/>Some services such as *Gfycat* do not have standard heights and should be specified for each embed. `$wgEmbedVideoDefaultWidth` can be set in `LocalSettings.php` to override the default width. |
| `alignment="[left\|center\|right\|inline]"` | no | none | Align the placement of the video either to the left, centered, or to the right. Inline will allow multiple videos to display side by side without forced line breaks. |
| `description="[wiki text]"` | no | none | Display a description under the embed container. |
| `container="[frame]"` | no | none | Specifies the container type to use for the embed.<br/>`frame`: Wrap the video player in a Mediawiki thumbnail box. |
| `urlargs="modestbranding=1&version=3"` | no | none | Allows extra URL arguments to be appended to the generated embed URL. This is useful for obscure options only supported on one service. |
| `autoresize="false"` | no | true | Automatically resize videos when their size will cause them to break outside of their container element |
| `valignment="[top|middle|bottom|baseline]"` | no | none | Align the vertical placement of the video either to the top, middle, bottom, or baseline of the parent element. Using this parameter forces the alignment parameter to be inline. |
| `valignment="[top\|middle\|bottom\|baseline]"` | no | none | Align the vertical placement of the video either to the top, middle, bottom, or baseline of the parent element. Using this parameter forces the alignment parameter to be inline. |

## Examples

Expand All @@ -156,6 +156,12 @@ For YouTube to have the video start at a specific time code utilize the urlargs(

{{#ev:youtube|https://www.youtube.com/watch?v=pSsYTj9kCHE|||||start=76}}

### Example #3

Creating a video list for Youtube. This allows you to queue a set of video in a temporary playlist. Use the 'youtubevideolist` service selector:

{{#ev:youtubevideolist|-D--GWwca0g|||||playlist=afpRzcAAZVM,gMEHZPZTAVc,lom_plwy9iA,BSWYMQEQhEo,EREaWhXj4_Q}}

# Support for VideoLink Tags

Support for the unmaintained VideoLink extension's tags has been added since version 2.5.
Expand Down Expand Up @@ -196,18 +202,28 @@ An important caveat to make note of, is that the `w` and `h` attributes only eff
_Note that the use of the `{{#vlink}}` parser function is also acceptable here for backwards compatibility._


{{#evl:<video id>|<Link text>|service=youtube|player=<player id>}}
{{#evl:<video id>|<Link text>|<video to play>|service=youtube|player=<player id>}}

In addition to all of the attributes supported by the `#evt` tag, these specific attributes apply to the `#evl` (and `#vlink`) tags. To maintain backwards compatibility, if you do not define a `service` then `youtube` is assumed.
In addition to all of the attributes supported by the `#evt` tag, these specific attributes apply to the `#evl` (and `#vlink`) tags. To maintain backwards compatibility, if you do not define a `service` then `youtube` is assumed. Passing a comma separated list of video ids is only supported for the `youtube` service.

| Attributes | Required | Default | Description |
|---------------|--------------|-----------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| video id | yes | none | The ID of the video you would like to play. _Please note that the use of multiple video IDs separated by a semicolon is now deprecated. Please use the proper service for playlists if you would like play multiple videos from a single link_ |
| video id | yes | none | The ID of the video you would like to play or a comma separated list of videos to play. _Please note that the use of multiple video IDs separated by a semicolon is now deprecated._ |
| link text | yes | none | The text to display inside the link |
| video to play | no | none | The number that represents the video to play from video id if its is a comma separated list of ids.
| player | no | 'default' | Player container to load video in. _Note that the ID 'default' will only exist if you've defined a player with no ID._ |
| initial video | _deprecated_ | | In the original VideoLink, this would define what video to play first if multiple videos were define. Please see notes about in `video id` and `start`. |
| start | _deprecated_ | 0:00 | In the original VideoLink, this defined the start time of a video. Since we support multiple video services, this feature can now be replicated with the `urlargs` parameter. For backwards compatibility, this attribute will be respect on videos with the service `youtube`. |

### Video Link Playlist example:

Creating a video list allows video links to create a playlist on the fly using the _youtube_ and _youtubevideolist_ service. _Note: even if you define a service the system will use youtube if a list of videos is provided._

<evlplayer style="position:relative; width: 800px; margin: 0.5em 0" id="example-player">default content</evlplayer>
{{#evl:pSsYTj9kCHE,pSsYTj9kCHE,pSsYTj9kCHE|Play All|player=example-player}}
{{#evl:pSsYTj9kCHE,pSsYTj9kCHE,pSsYTj9kCHE|Let eet Go|1|player=example-player}}
{{#evl:pSsYTj9kCHE,pSsYTj9kCHE,pSsYTj9kCHE|Let eet Go|2|player=example-player}}
{{#evl:pSsYTj9kCHE,pSsYTj9kCHE,pSsYTj9kCHE|Let eet Go|3|player=example-player}}

## Supported Services

Expand Down Expand Up @@ -235,7 +251,7 @@ As of version 2.x, EmbedVideo supports embedding video content from the followin
| [Metacafe](http://www.metacafe.com/) | `metacafe` | 11404579 | http://www.metacafe.com/watch/11404579/lan\_party\_far\_cry\_4/ |
| [Nico Nico Video](http://www.nicovideo.jp/) | `nico` | sm24394325 | http://www.nicovideo.jp/watch/sm24394325 |
| [RuTube](http://rutube.ru/) | `rutube` | b698163ccb67498db74d50cb0f22e556 | http://rutube.ru/video/b698163ccb67498db74d50cb0f22e556/ |
| [SoundCloud](http://soundcloud.com/) | `soundcloud` | | https://soundcloud.com/skrillex/skrillex-rick-ross-purple-lamborghini |
| [SoundCloud](http://soundcloud.com/) | `soundcloud` | | https://soundcloud.com/skrillex/skrillex-rick-ross-purple-lamborghini |
| [TeacherTube](http://teachertube.com) | `teachertube` | 370511 | http://www.teachertube.com/video/thats-a-noun-sing-along-hd-version-370511 |
| [TED Talks](http://www.ted.com/talks/browse/) | `ted` | bruce\_aylward\_humanity\_vs\_ebola\_the\_winning\_strategies\_in\_a\_terrifying\_war | http://www.ted.com/talks/bruce\_aylward\_humanity\_vs\_ebola\_the\_winning\_strategies\_in\_a\_terrifying\_war |
| [Tubi TV](http://tubitv.com) | `tubitv` | 318409 | http://tubitv.com/video/318409 |
Expand All @@ -245,7 +261,9 @@ As of version 2.x, EmbedVideo supports embedding video content from the followin
| [Vimeo](http://www.vimeo.com) | `vimeo` | 105035718 | http://vimeo.com/105035718 |
| [Vine](http://vine.co) | `vine` | h2B7WMtuX2t | https://vine.co/v/h2B7WMtuX2t |
| [Yahoo Screen](http://screen.yahoo.com/) | `yahoo` | katy-perry-dances-sharks-2015-024409668 | https://screen.yahoo.com/videos-for-you/katy-perry-dances-sharks-2015-024409668.html |
| [YouTube](http://www.youtube.com/) | `youtube` - Single Videos | `youtubeplaylist` - Playlists | pSsYTj9kCHE |
| [YouTube](http://www.youtube.com/) | `youtube` - Single Videos | pSsYTj9kCHE | https://www.youtube.com/watch?v=pSsYTj9kCHE |
| [YouTube](http://www.youtube.com/) | `youtubeplaylist` - Playlists | PLY0KbDiiFYeNgQkjujixr7qD-FS8qecoP | https://www.youtube.com/embed/?listType=playlist&list=PLY0KbDiiFYeNgQkjujixr7qD-FS8qecoP |
| [YouTube](http://www.youtube.com/) | `youtubevideolist` - Video List | pSsYTj9kCHE - urlargs=playlist=pSsYTj9kCHE,pSsYTj9kCHE | https://www.youtube.com/embed/pSsYTj9kCHE?playlist=pSsYTj9kCHE,pSsYTj9kCHE |
| [Youku](http://www.youku.com/) | `youku` | XODc3NDgzMTY4 | http://v.youku.com/v\_show/id\_XODc3NDgzMTY4.html |

# Configuration Settings
Expand Down
Loading

0 comments on commit 49f23db

Please sign in to comment.