video_player.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360
  1. <?php
  2. function ppvm_player($ppub, $path, $video) {
  3. $metadata = $ppub->metadata;
  4. $short_title = $metadata["title"];
  5. // if(strlen($short_title) > 30) {
  6. // $short_title = substr($short_title, 0, 30);
  7. // $short_title .= "…";
  8. // }
  9. ?>
  10. <!DOCTYPE html>
  11. <html lang="<?php echo($metadata["language"] ?? SITE_LANGUAGE);?>">
  12. <head>
  13. <meta charset="utf-8">
  14. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  15. <title><?php echo(htmlentities($metadata["title"]));?> - <?php echo(SITE_NAME);?></title>
  16. <meta name="description" content="<?php echo(htmlentities($metadata["description"]));?>">
  17. <meta name="author" content="<?php echo(htmlentities($metadata["author"]));?>">
  18. <link rel="alternate" type="application/x-ppub" title="<?php echo(htmlentities($metadata["title"]));?> (as PPUB)" href="?download=true" />
  19. <script type="text/javascript" src="<?php echo(SITE_URL);?>/ppvm_player.js"></script>
  20. <style type="text/css">
  21. body {
  22. margin: 0px;
  23. background-color: #000;
  24. }
  25. video {
  26. display: block;
  27. height: auto;
  28. width: 100vw;
  29. height: 100vh;
  30. }
  31. .additional-contols {
  32. background: rgba(45, 45, 45, 0.8);
  33. padding: 6px;
  34. color: #ffffff;
  35. position: absolute;
  36. top: -36px;
  37. left: 0;
  38. right: 0;
  39. opacity: 0;
  40. transition: 0.2s all;
  41. padding-top: 0px;
  42. padding-bottom: 0px;
  43. font-size: 14px;
  44. }
  45. body:hover .additional-contols.javascript, .paused.javascript, .noscript {
  46. top: 0px;
  47. opacity: 1;
  48. }
  49. .noscript-text {
  50. white-space: nowrap;
  51. margin-right: 10px;
  52. margin-left: 30px;
  53. }
  54. body, input {
  55. font: 1rem -apple-system,BlinkMacSystemFont,"Segoe UI",Roboto, Helvetica,Arial,sans-serif,"Apple Color Emoji","Segoe UI Emoji", "Segoe UI Symbol";
  56. }
  57. dialog {
  58. background: rgba(45, 45, 45, 1);
  59. color: #ffffff;
  60. border: 1px solid aliceblue;
  61. max-width: 75%;
  62. }
  63. dialog p{
  64. margin-top: 2px;
  65. }
  66. dialog::backdrop {
  67. background: rgba(45, 45, 45, 0.8);
  68. }
  69. dialog .contents {
  70. margin: -15px;
  71. margin-bottom: 0px;
  72. padding: 15px;
  73. padding-bottom: 0px;
  74. max-height: calc(75vh - 55px);
  75. overflow-y: auto;
  76. }
  77. dialog .controls {
  78. border-top: 1px solid dimgrey;
  79. padding-top: 10px;
  80. }
  81. a {
  82. color: skyblue;
  83. }
  84. a:visited {
  85. color: aquamarine;
  86. }
  87. .additional-contols a {
  88. color: #ffffff;
  89. overflow: hidden;
  90. text-overflow: ellipsis;
  91. white-space: nowrap;
  92. flex-shrink: 2;
  93. }
  94. .additional-control {
  95. display: flex;
  96. flex-wrap: nowrap;
  97. align-items: baseline;
  98. justify-content: start;
  99. }
  100. .filler {
  101. flex: 1;
  102. }
  103. .site a {
  104. text-decoration: none;
  105. color: #ffffff;
  106. margin: 8px;
  107. }
  108. .site a:hover {
  109. color: skyblue;
  110. text-decoration: underline;
  111. }
  112. .additional-control button, .additional-control select {
  113. background: rgba(45, 45, 45, 0);
  114. border: 1px solid rgba(45, 45, 45, 0);
  115. color: #ffffff;
  116. cursor: pointer;
  117. text-decoration: underline;
  118. text-align: right;
  119. margin-top: 0px;
  120. margin-bottom: 2px;
  121. margin-left: 2px;
  122. margin-right: 2px;
  123. padding-left: 6px;
  124. padding-right: 6px;
  125. padding-bottom: 3px;
  126. padding-top: 1px;
  127. height: 23px;
  128. -webkit-appearance: none;
  129. }
  130. .additional-control select {
  131. margin-left: auto;
  132. }
  133. .additional-control button:hover, .additional-control select:hover {
  134. color: skyblue;
  135. }
  136. .additional-control button:focus, .additional-control select:focus {
  137. color: skyblue;
  138. }
  139. .additional-control select option {
  140. color: #000000;
  141. }
  142. summary {
  143. cursor: pointer;
  144. }
  145. #share-modal textarea, pre {
  146. width: 500px;
  147. background: rgb(30, 30, 30);
  148. color: #fff;
  149. border: none;
  150. padding: 8px;
  151. margin-top: 8px;
  152. margin-bottom: 18px;
  153. border-radius: 4px;
  154. overflow: scroll;
  155. white-space: pre;
  156. }
  157. #download-modal li {
  158. margin-bottom: 8px;
  159. }
  160. </style>
  161. </head>
  162. <body>
  163. <video controls id="player" poster="<?php echo($video->metadata["poster"]);?>" preload="metadata" src="<?php echo($video->metadata["master"]);?>">
  164. </video>
  165. <div id="no-script" class="additional-contols noscript">
  166. <div class="additional-control site">
  167. <a href="<?php echo(SITE_URL);?>/<?php echo($_GET["ppub"]);?>/<?php echo($_GET["asset"]);?>" target="_blank" title="<?php echo(htmlentities($metadata["title"]));?>"><strong><?php echo(htmlentities($short_title));?></strong></a>
  168. <span class="noscript-text">For the best experience, please enable JavaScript.</span>
  169. </div>
  170. </div>
  171. <div id="controls" class="additional-contols paused">
  172. <div class="additional-control site">
  173. <a href="<?php echo(SITE_URL);?>/<?php echo($_GET["ppub"]);?>/<?php echo($_GET["asset"]);?>" target="_blank" title="<?php echo(htmlentities($metadata["title"]));?>"><strong><?php echo(htmlentities($short_title));?></strong></a>
  174. <button onclick="showInfo()">Info</button>
  175. <button onclick="shareVideo()">Share</button>
  176. <button onclick="downloadVideo()">Download</button>
  177. <select name="quality" id="quality-selector" onchange="qualitySelected()">
  178. </select>
  179. </div>
  180. </div>
  181. <dialog id="download-modal">
  182. <form method="dialog">
  183. <div class="contents">
  184. <p><strong>Download video</strong><br/>
  185. <a href="<?php echo($video->metadata["master"]); ?>" download>Download the full quality version of this video</a> or select a different version to suit your needs below.
  186. </p>
  187. <details>
  188. <summary>Other formats and versions</summary>
  189. <ul>
  190. <?php
  191. foreach ($video->entries as $entry) {
  192. $entry_asset = $ppub->asset_index[$entry->filename];
  193. echo(" <li><a href=\"" . $entry->filename . "\" download>" . htmlentities($entry->label) . "</a><br/>\n");
  194. echo(" <small>" . round(($entry_asset->end_location - $entry_asset->start_location) / 1000000, 2) . "MB, " . $entry_asset->mimetype . "</small></li>\n");
  195. }
  196. ?>
  197. </ul>
  198. </details>
  199. <p>
  200. <?php if ($ppub->metadata["copyright"] != null) { ?>
  201. <br/>
  202. <?php echo($ppub->metadata["copyright"]);?>
  203. <?php } if ($ppub->metadata["licence"] != null) { ?>
  204. <br/>
  205. <a href="<?php echo($ppub->metadata["licence"]);?>" target="_blank">See Licence</a>
  206. <?php } ?></p>
  207. </div>
  208. <div class="controls">
  209. <button value="cancel">Close</button>
  210. </div>
  211. </form>
  212. </dialog>
  213. <dialog id="info-modal">
  214. <form method="dialog">
  215. <div class="contents">
  216. <p><strong><?php echo(htmlentities($ppub->metadata["title"]));?></strong>
  217. <?php if($ppub->metadata["author"] != null) {
  218. preg_match("/^([^<]*(?= *<|$))<*([^>]*)>*/", $ppub->metadata["author"], $author);
  219. ?>
  220. <br/>By <?php
  221. if(isset($author[2]) && $author[2] != '') {
  222. echo("<a href=\"mailto:".$author[2]."\">");
  223. echo(htmlentities(trim($author[1])));
  224. echo("</a>");
  225. } else {
  226. echo(htmlentities($ppub->metadata["author"]));
  227. }
  228. ?>.
  229. <?php } if ($ppub->metadata["tags"] != null and USE_PPIX) { ?>
  230. <br/>Tagged with:
  231. <?php
  232. foreach(explode(" ", $ppub->metadata["tags"]) as $tag) {
  233. ?>
  234. <a href="<?php echo(SITE_URL);?>/?tag=<?php echo(urlencode($tag));?>" target="_blank"><?php echo(htmlentities($tag));?></a>
  235. <?php
  236. }
  237. ?>
  238. <?php } if ($ppub->metadata["date"] != null) { ?>
  239. <br/>Last updated on <?php echo(htmlentities((new DateTime($ppub->metadata["date"]))->format(DATE_FORMAT)));?>.
  240. <br/><?php } if ($ppub->metadata["copyright"] != null) { ?>
  241. <?php echo($ppub->metadata["copyright"]);?>
  242. <?php } if ($ppub->metadata["licence"] != null) { ?>
  243. <a href="<?php echo($ppub->metadata["licence"]);?>" target="_blank">See Licence</a>
  244. <?php } ?></p>
  245. <br/><small>Powered by <a href="https://github.com/Tilo15/php-ppub" target="_blank">php-ppub</a></small></p>
  246. </div>
  247. <div class="controls">
  248. <button value="cancel">Close</button>
  249. </div>
  250. </form>
  251. </dialog>
  252. <dialog id="share-modal">
  253. <form method="dialog">
  254. <div class="contents">
  255. <p><strong>Share this video</strong><br/>
  256. With your friends, colleagues, distant family, or strangers on the internet.
  257. </p>
  258. <div>
  259. <label>Link:</label>
  260. <pre><?php echo(SITE_URL);?>/<?php echo($_GET["ppub"]);?>/<?php echo($_GET["asset"]);?></pre>
  261. </div>
  262. <div>
  263. <label>Embed:</label><br/>
  264. <textarea readonly rows="3"><?php generate_embed($path, $video);?></textarea>
  265. </div>
  266. </div>
  267. <div class="controls">
  268. <button value="cancel" autofocus>Close</button>
  269. </div>
  270. </form>
  271. </dialog>
  272. <dialog id="unplayable-modal">
  273. <form method="dialog">
  274. <div class="contents">
  275. <p><strong>Unable to playback content</strong><br/>
  276. Your browser does not appear to support any of the available codecs.
  277. </p>
  278. </div>
  279. <div class="controls">
  280. <button value="cancel">Close</button>
  281. </div>
  282. </form>
  283. </dialog>
  284. <script type="text/javascript">
  285. setup_playback({
  286. entries: [
  287. <?php
  288. foreach ($video->entries as $entry) {
  289. $entry_asset = $ppub->asset_index[$entry->filename];
  290. $size = ($entry_asset->end_location - $entry_asset->start_location);
  291. echo(" { type: \"" . $entry->type . "\", mimetype: \"" . $entry_asset->mimetype . "\", path: \"" . $entry->filename . "\", label: \"" . $entry->label . "\", byterate: " . $size / (float)$video->metadata["duration"] . ", filesize: " . $size . ", metadata: { ");
  292. foreach ($entry->metadata as $key => $val) {
  293. echo(str_replace("-", "_", $key) . ": \"" . $val . "\", ");
  294. }
  295. echo("}},\n");
  296. }
  297. ?>
  298. ]
  299. });
  300. </script>
  301. </body>
  302. </html>
  303. <?php
  304. }
  305. function generate_embed($path, $video) {
  306. $percent = 56.25;
  307. if(isset($video->metadata["ratio"])) {
  308. $ratio = explode(":", $video->metadata["ratio"]);
  309. $percent = (min($ratio[0], $ratio[1]) / max($ratio[0], $ratio[1])) * 100;
  310. }
  311. ?>
  312. <div class="ppvm-player" style="position: relative; height:0; background: #2d2d2d; padding-bottom: <?php echo($percent);?>%">
  313. <iframe src="<?php echo(SITE_URL);?>/<?php echo($_GET["ppub"]);?>/<?php echo($_GET["asset"]);?>?embed=true/" style="position: absolute; top: 0; left: 0; width: 100%; height: 100%;" allowfullscreen></iframe>
  314. </div><?php
  315. }
  316. ?>