/classes/Video.php

https://github.com/fracmak/mythweb · PHP · 188 lines · 174 code · 10 blank · 4 comment · 12 complexity · 9cf141fbc3039d1e1280fc1539849997 MD5 · raw file

  1. <?php
  2. class Video {
  3. var $intid;
  4. var $plot;
  5. var $category;
  6. var $rating;
  7. var $title;
  8. var $subtitle;
  9. var $season;
  10. var $episode;
  11. var $director;
  12. var $inetref;
  13. var $year;
  14. var $userrating;
  15. var $length;
  16. var $showlevel;
  17. var $filename;
  18. var $cover_file;
  19. var $cover_url;
  20. var $cover_scaled_width = video_img_width;
  21. var $cover_scaled_height = video_img_height;
  22. var $childid;
  23. var $url;
  24. var $browse;
  25. var $genres;
  26. function Video($intid) {
  27. $this->__construct($intid);
  28. }
  29. function __construct($intid) {
  30. global $db;
  31. global $mythvideo_dir;
  32. // Video storage directories
  33. $video_dirs = $db->query_list('
  34. SELECT dirname
  35. FROM storagegroup
  36. WHERE groupname="Coverart"
  37. ');
  38. $video = $db->query_assoc('
  39. SELECT *
  40. FROM videometadata
  41. WHERE intid = ?',
  42. $intid);
  43. $this->intid = $intid;
  44. $this->plot = $video['plot'];
  45. $this->category = $video['category'];
  46. $this->rating = $video['rating'];
  47. $this->title = $video['title'];
  48. $this->subtitle = $video['subtitle'];
  49. $this->season = $video['season'];
  50. $this->episode = $video['episode'];
  51. $this->director = $video['director'];
  52. $this->inetref = $video['inetref'];
  53. $this->year = $video['year'] ? $video['year'] : t('Unknown');
  54. $this->userrating = $video['userrating'] ? $video['userrating'] : t('Unknown');
  55. $this->length = $video['length'];
  56. $this->showlevel = $video['showlevel'];
  57. $this->filename = $video['filename'];
  58. $this->cover_file = $video['coverfile'];
  59. $this->browse = $video['browse'];
  60. // And the artwork URL
  61. $this->cover_url = '';
  62. if ($this->cover_file && $this->cover_file != 'No Cover') {
  63. $exists = false;
  64. foreach ($video_dirs as $dir) {
  65. $path = preg_replace('#/+#', '/', "$dir/$this->cover_file");
  66. if (file_exists($path) && is_executable(dirname($path))) {
  67. $exists = true;
  68. break;
  69. }
  70. }
  71. if ($exists) {
  72. $this->cover_url = 'pl/coverart/'.$this->cover_file;
  73. $this->cover_file = $path;
  74. list($width, $height) = @getimagesize($this->cover_file);
  75. if ($width > 0 && $height > 0) {
  76. $wscale = video_img_width / $width;
  77. $hscale = video_img_height / $height;
  78. $scale = $wscale < $hscale ? $wscale : $hscale;
  79. $this->cover_scaled_width = floor($width * $scale);
  80. $this->cover_scaled_height = floor($height * $scale);
  81. }
  82. }
  83. }
  84. $this->childid = $video['childid'];
  85. // Figure out the URL
  86. $this->url = '#';
  87. if (file_exists('data/video/'))
  88. $this->url = implode('/', array_map('rawurlencode',
  89. array_map('utf8tolocal',
  90. explode('/',
  91. 'data/video/' . preg_replace('#^'.$mythvideo_dir.'/?#', '', $this->filename)
  92. ))));
  93. $genre = $db->query('SELECT idgenre
  94. FROM videometadatagenre
  95. WHERE idvideo = ?',
  96. $this->intid
  97. );
  98. while( $id = $genre->fetch_col()) {
  99. $this->genres[] = $id;
  100. }
  101. $genre->finish();
  102. }
  103. // This function returns metadata preped for 'ajax' requests to update
  104. function metadata() {
  105. global $Category_String;
  106. return array( 'intid' => $this->intid,
  107. 'img' => '<img width="'.$this->cover_scaled_width.'" height="'.$this->cover_scaled_height.'" alt="'.t('Missing Cover').'"'
  108. .(($_SESSION["show_video_covers"] && file_exists($this->cover_url)) ? ' src="data/video_covers/'.basename($this->cover_file).'"' : '')
  109. .'>',
  110. 'title' => '<a href="'.$this->url.'">'.$this->title.'</a>',
  111. 'subtitle' => $this->subtitle,
  112. 'season' => $this->season,
  113. 'episode' => $this->episode,
  114. 'playtime' => nice_length($this->length * 60),
  115. 'category' => strlen($Category_String[$this->category]) ? $Category_String[$this->category] : t('Uncategorized'),
  116. 'imdb' => ($this->inetref != '00000000') ? '<a href="http://www.imdb.com/Title?'.$this->inetref.'">'.$this->inetref.'</a>' : '',
  117. 'plot' => $this->plot,
  118. 'rating' => $this->rating,
  119. 'director' => $this->director,
  120. 'inetref' => $this->inetref,
  121. 'year' => $this->year,
  122. 'userrating' => $this->userrating,
  123. 'length' => $this->length,
  124. 'showlevel' => $this->showlevel
  125. );
  126. }
  127. function save() {
  128. global $db;
  129. $db->query('UPDATE videometadata
  130. SET videometadata.plot = ?,
  131. videometadata.category = ?,
  132. videometadata.rating = ?,
  133. videometadata.title = ?,
  134. videometadata.subtitle = ?,
  135. videometadata.season = ?,
  136. videometadata.episode = ?,
  137. videometadata.director = ?,
  138. videometadata.inetref = ?,
  139. videometadata.year = ?,
  140. videometadata.userrating = ?,
  141. videometadata.length = ?,
  142. videometadata.showlevel = ?,
  143. videometadata.filename = ?,
  144. videometadata.coverfile = ?,
  145. videometadata.browse = ?
  146. WHERE videometadata.intid = ?',
  147. $this->plot,
  148. $this->category,
  149. $this->rating,
  150. $this->title,
  151. $this->subtitle,
  152. $this->season,
  153. $this->episode,
  154. $this->director,
  155. $this->inetref,
  156. $this->year,
  157. $this->userrating,
  158. $this->length,
  159. $this->showlevel,
  160. $this->filename,
  161. ( @filesize($this->cover_file) > 0 ? $this->cover_file : 'No Cover' ),
  162. $this->browse,
  163. $this->intid
  164. );
  165. $db->query('DELETE FROM videometadatagenre
  166. WHERE videometadatagenre.idvideo = ?',
  167. $this->intid
  168. );
  169. if (count($this->genres) > 0)
  170. foreach ($this->genres as $genre)
  171. $db->query('INSERT INTO videometadatagenre ( idvideo, idgenre )
  172. VALUES ( ?, ? )',
  173. $this->intid,
  174. $genre
  175. );
  176. }
  177. }
  178. ?>