Play images and video from Synology PhotoStation server

embed.php 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?
  2. require_once('albumutil.php');
  3. require_once('photoutil.php');
  4. $id_str = $_GET['id'];
  5. $id_arr = explode('_', $id_str);
  6. if (3 !== count($id_arr) || ('photo' !== $id_arr[0] && 'video' !== $id_arr[0])) {
  7. $error = true;
  8. }
  9. $albumName = @pack('H*', $id_arr[1]);
  10. $fileName = @pack('H*', $id_arr[2]);
  11. $path = SYNOPHOTO_SERVICE_REAL_DIR . "/" . ("/" === $albumName ? "" : $albumName . "/") . $fileName;
  12. $item = checkVideoAvailable($albumName, $path, $id_arr[0]);
  13. if ($item) {
  14. $quality = findQualityObject($item['additional']['video_quality'], $_GET['quality']);
  15. $quality_id = $quality['id'];
  16. $videoType = $quality['container'];
  17. $videoProfile = $quality['profile_name'];
  18. $video = SYNOPHOTO_URL_PREFIX . "/photo/webapi/download.php/1.mp4?api=SYNO.PhotoStation.Download&method=getvideo&version=1&id=$id_str&quality_id=$quality_id";
  19. $image = SYNOPHOTO_URL_PREFIX . "/photo/webapi/thumb.php?api=SYNO.PhotoStation.Thumb&method=get&version=1&id=$id_str&size=large";
  20. $title = $item['info']['title'].' - '. __(photo_str_ap_name_6);
  21. } else {
  22. $title = __(photo_str_ap_name_6);
  23. }
  24. function findQualityObject ($videoQuality, $qualityProfileName)
  25. {
  26. if (!$videoQuality) {
  27. return null;
  28. }
  29. foreach ($videoQuality as $i) {
  30. if ($qualityProfileName == $i['profile_name']) {
  31. return $i;
  32. }
  33. }
  34. usort($videoQuality, function($a, $b) {
  35. $profileOrder = Array('high'=>0, 'medium'=>1, 'low'=>2, 'orig_h264'=>3, 'mobile'=>4, 'flv'=>5);
  36. return $profileOrder[$a['profile_name']] > $profileOrder[$b['profile_name']] ? 1 : -1;
  37. });
  38. return $videoQuality[0];
  39. }
  40. function checkVideoAvailable ($albumName, $path, $type)
  41. {
  42. if (!csSynoPhotoMisc::CheckPathValid($path)) {
  43. return false;
  44. }
  45. csSYNOPhotoDB::GetDBInstance()->SetSessionCache();
  46. if (!csSYNOPhotoMisc::CheckAlbumAccessible($albumName)) {
  47. return false;
  48. }
  49. if (@file_exists($path)) {
  50. if (!($item = PhotoAPIUtil::getItemByPath($path, array('video_quality'), $type, false))) {
  51. return false;
  52. }
  53. }
  54. return $item;
  55. }
  56. ?>
  57. <!DOCTYPE html>
  58. <html><head><title><?= $title ?></title>
  59. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  60. <meta http-equiv="X-UA-Compatible" content="IE=11" />
  61. <script type="text/javascript" src="../jwplayer/jwplayer.js"></script>
  62. <script type="text/javascript" src="../photo_new/syno_embed.js"></script>
  63. <link rel="shortcut icon" href="../favicon.ico">
  64. </head><body>
  65. <? if ($error) {?>
  66. <div style=text-align:center;margin-top:100px><?=__(photo_str_video_unavailable)?></div>
  67. <? } else {?>
  68. <div id='player'></div>
  69. <script>
  70. var video = "<?= $video?>",
  71. image = "<?= $image?>",
  72. videoType = "<?= $videoType?>";
  73. videoProfile = "<?= $videoProfile?>";
  74. </script>
  75. <?}?>
  76. </body></html>