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