Template:VideoGallery/sandbox: Difference between revisions

From Dolphin Emulator Wiki
Jump to navigation Jump to search
mNo edit summary
mNo edit summary
Line 3: Line 3:
Parameterless mode begins
Parameterless mode begins


-->{{#vardefine:tl_vg_videocount|{{#vardefineecho:tl_vg_currentvideo|{{#expr:0{{#regex:{{{1|}}}|/(.+)/|+1}}}}}}}}<!--
-->{{#vardefine:tl_vg_videocount|{{#vardefineecho:tl_vg_currentvideo|{{#expr:0{{#regex:{{{1|}}}|/(.+)/|+1}}}}}}}}{{#while:|{{#ifexpr:{{#var:tl_vg_currentvideo}}>0|true}}|{{#vardefine:server{{#var:tl_vg_currentvideo}}|{{#regex:videolist
 
  Counting completed, max video count is duplicated to two variables: tl_vg_videocount and tl_vg_currentvideo, their values will change later.
 
-->{{#while:|{{#ifexpr:{{#var:tl_vg_currentvideo}}>0|true}}|{{#vardefine:server{{#var:tl_vg_currentvideo}}|{{#regex:videolist


{{{1|}}}|/videolist(\n.*){1,{{#var:tl_vg_currentvideo}}}\n(((?!\s).)+(\/{{!}}=))([\s\S]*)/|$2}}}}
{{{1|}}}|/videolist(\n.*){1,{{#var:tl_vg_currentvideo}}}\n(((?!\s).)+(\/{{!}}=))([\s\S]*)/|$2}}}}
Line 15: Line 11:
{{#vardefine:caption{{#var:tl_vg_currentvideo}}|{{#regex:videolist
{{#vardefine:caption{{#var:tl_vg_currentvideo}}|{{#regex:videolist


{{{1|}}}|/videolist(\n.*){1,{{#var:tl_vg_currentvideo}}}\n(((?!\s).)+(\/{{!}}=))(.......(?!\s)....{{!}}.......)(.*)([\s\S]*)/|{{#vardefine:tl_vg_currentvideo|{{#expr:{{#var:tl_vg_currentvideo}}-1}}}}$6}}}}}}<!--
{{{1|}}}|/videolist(\n.*){1,{{#var:tl_vg_currentvideo}}}\n(((?!\s).)+(\/{{!}}=))(.......(?!\s)....{{!}}.......)(.*)([\s\S]*)/|{{#vardefine:tl_vg_currentvideo|{{#expr:{{#var:tl_vg_currentvideo}}-1}}}}$6}}}}}}{{#vardefine:tl_vg_videocount|{{#expr:{{#var:tl_vg_videocount}}+1}}}}<div id="VideoGallery">{{#while:|{{#ifexpr:{{#var:tl_vg_videocount}}>0|true}}|{{#if:{{#var:video{{#vardefineecho:tl_vg_videocount|{{#expr:{{#var:tl_vg_videocount}}-1}}}}}}|{{#if:{{#vardefineecho:embed|{{#switch:{{#var:server{{#var:tl_vg_videocount}}}}|{{#vardefineecho:watchonyt|https://www.youtube.com/watch?v=}}=https://www.youtube.com/embed/|https://www.dailymotion.com/video/=https://www.dailymotion.com/embed/video/|}}}}|{{#tag:ul|{{#tag:li|<div data-src="{{#var:embed}}{{#var:video{{#var:tl_vg_videocount}}}}" data-style="width:302px;">[{{#var:server{{#var:tl_vg_videocount}}}}{{#var:video{{#var:tl_vg_videocount}}}}{{#tag:nowiki|{{#var:caption{{#var:tl_vg_videocount}}}}}}]</div>}}}}|[[Category:Pages with invalid video links]]}}|}}}}</div><!--
 
  Segregating strings to variables completed, variables are with self-explanatory names: server, video, and caption. The ultimate trick of picking value from each variables index-like is by having the increasing (decreasing in this case) number appended to variable names and then use the while-loop with number increasing/decreasing to iterate values from numbered variable names or call a numbered variable name index-like for its value. I'll learn from this for [[Template:Config required]] and some other templates.
 
-->
{{#vardefine:tl_vg_embedslots|{{#ifexpr:{{#var:tl_vg_videocount}}<3|{{#var:tl_vg_videocount}}|3}}}}<!--
 
  Max embed slots to a variable: tl_vg_embedslots, value will be subtracted each time a featuring video is selected for embedding. Next part is while-loop with our silly randomizer logic.
 
-->
{{#while:|{{#ifexpr:{{#var:tl_vg_embedslots}}>0|true}}|{{#vardefine:tl_vg_featuredvideo|{{#expr:{{Mod|{{#time:U}}+{{#vardefineecho:tl_vg_embedslots|{{#expr:{{#var:tl_vg_embedslots}}-1}}}}+{{#switch:{{#var:tl_vg_embedslots}}|0={{REVISIONSIZE}}|1={{NUMBEROFPAGES:R}}|2={{CurrentRevision}}}}|{{#var:tl_vg_videocount}}}}+1}}}}{{#while:|{{#if:{{#var:video{{#var:tl_vg_featuredvideo}}}}||used}}|{{#vardefine:tl_vg_featuredvideo|{{#expr:{{#var:tl_vg_featuredvideo}}{{#ifexpr:{{#var:tl_vg_featuredvideo}}-1=0|+2|-1}}}}}}}}<!--
 
  The key part where the video is being turned into an embed video. Notice the #ev used here.
 
--><div style="float:left; margin: .5em 0 1.3em 1.4em;">{{#ev:{{#regex:{{#var:server{{#var:tl_vg_featuredvideo}}}}|/.*(youtube{{!}}dailymotion).*/|$1}}|{{#var:video{{#var:tl_vg_featuredvideo}}}}|302||<span style="text-overflow: ellipsis; display: inline-block; width: 275px; white-space: nowrap; overflow: hidden; vertical-align: top;" title="{{#var:caption{{#var:tl_vg_featuredvideo}}}}">[{{#var:server{{#var:tl_vg_featuredvideo}}}}{{#var:video{{#var:tl_vg_featuredvideo}}}} {{#tag:nowiki|{{#var:caption{{#var:tl_vg_featuredvideo}}}}}}]</span>|frame}}</div><!--
 
 
 
-->{{#vardefine:video{{#var:tl_vg_featuredvideo}}|}}}}<!--
 
  While-loop completed. Ready to render the remaining non-featured videos to the page.
 
-->
<div style="clear:left"></div>
{{#vardefine:tl_vg_videocount|{{#expr:{{#var:tl_vg_videocount}}+1}}}}
{{#while:|{{#ifexpr:{{#var:tl_vg_videocount}}>0|true}}|{{#if:{{#var:video{{#vardefineecho:tl_vg_videocount|{{#expr:{{#var:tl_vg_videocount}}-1}}}}}}|{{#tag:ul|{{#tag:li|[{{#var:server{{#var:tl_vg_videocount}}}}{{#var:video{{#var:tl_vg_videocount}}}}{{#tag:nowiki|{{#var:caption{{#var:tl_vg_videocount}}}}}}]}}}}|}}}}<!--


Parameterless mode ends
Parameterless mode ends

Revision as of 11:35, 5 February 2022

[edit] [purge] Template documentation
{{VideoGallery|{{#vardefineecho:videogallery|
https://www.youtube.com/watch?v=wjzv0KtDXOA Xenoblade JP 1 (Dolphin Emulator @ 720p)
https://www.youtube.com/watch?v=tJtCp8rPXWg Xenoblade PAL 1 [Dolphin Emulator @ 1080p]
https://www.dailymotion.com/video/x1k9hnl Cocoto Platform Jumper HD on Dolphin Emulator (Widescreen Hack) part1
https://www.youtube.com/watch?v=_VLNa9PKT0Y Xenoblade PAL 2 (Dolphin Emulator @ 720p)
https://www.youtube.com/watch?v=dp3QnvFn_Hc Xenoblade PAL 3 (Dolphin Emulator @ 720p)
}}}}

Compare below and #Legacy compatibility! True randomization is our key feature. Requires JavaScript which I have provided a working sample in the talk page. Without JavaScript this will just display as hyperlinked list in reverse order. Another benefit is reducing editing required. Just copy/paste the video link and write caption!


Legacy compatibility

Videos like below still use the old template parameters, they will work fine.

{{VideoGallery/sandbox
|vid1=wjzv0KtDXOA|cap1=Xenoblade JP 1 (Dolphin Emulator @ 720p)
|vid2=tJtCp8rPXWg|cap2=Xenoblade PAL 1 [Dolphin Emulator @ 1080p]
|srv3=dailymotion|vid3=x1k9hnl|cap3=Cocoto Platform Jumper HD on Dolphin Emulator (Widescreen Hack) part1
|vid4=_VLNa9PKT0Y|cap4=Xenoblade PAL 2 (Dolphin Emulator @ 720p)
|vid5=dp3QnvFn_Hc|cap5=Xenoblade PAL 3 (Dolphin Emulator @ 720p)
}}

Other rationale

  • Requires {{#vardefineecho:videogallery|}} to avoid issues with equal sign ("=") in template. If {{Problems}} is doing it then why not this?
  • Parameterless to prevent parameter typo or tampering. This has happened before. Can't remember where is our old discussion at, there was a delusional anonymous tampering the parameter number in attempt of having his video first on the list - in assumption of only the first three videos will embed on the page. This won't be the case when parameters weren't there. They can paste their url anywhere in the list, doesn't matter. Also with JS they wouldn't be thinking about the edit save grinding.
  • Quality categories added: checks if the video url is accepted for embedding and checks for the missing caption.