1<?php
2
3class 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                if ($width > 0 && $height > 0) {
82                    $wscale = video_img_width / $width;
83                    $hscale = video_img_height / $height;
84                    $scale = $wscale < $hscale ? $wscale : $hscale;
85                    $this->cover_scaled_width  = floor($width * $scale);
86                    $this->cover_scaled_height = floor($height * $scale);
87                }
88            }
89        }
90        $this->childid = $video['childid'];
91    // Figure out the URL
92        $this->url = '#';
93    //// all junk, replacing
94//        if (file_exists('data/video/'))
95//            $this->url = implode('/', array_map('rawurlencode',
96//                                             array_map('utf8tolocal',
97//                                             explode('/',
98//                                             'data/video/' . preg_replace('#^'.$mythvideo_dir.'/?#', '', $this->filename)
99//                                       ))));
100        $this->url = 'video/stream?Id=' . $this->intid;
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_url)) ? ' 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    }
136
137    function save() {
138        global $db;
139        $db->query('UPDATE videometadata
140                       SET videometadata.plot         = ?,
141                           videometadata.category     = ?,
142                           videometadata.rating       = ?,
143                           videometadata.title        = ?,
144                           videometadata.subtitle     = ?,
145                           videometadata.season       = ?,
146                           videometadata.episode      = ?,
147                           videometadata.director     = ?,
148                           videometadata.inetref      = ?,
149                           videometadata.year         = ?,
150                           videometadata.userrating   = ?,
151                           videometadata.length       = ?,
152                           videometadata.showlevel    = ?,
153                           videometadata.filename     = ?,
154                           videometadata.coverfile    = ?,
155                           videometadata.browse       = ?
156                     WHERE videometadata.intid        = ?',
157                    $this->plot,
158                    $this->category,
159                    $this->rating,
160                    $this->title,
161                    $this->subtitle,
162                    $this->season,
163                    $this->episode,
164                    $this->director,
165                    $this->inetref,
166                    $this->year,
167                    $this->userrating,
168                    $this->length,
169                    $this->showlevel,
170                    $this->filename,
171                    ( @filesize($this->cover_file) > 0 ? $this->cover_file : 'No Cover' ),
172                    $this->browse,
173                    $this->intid
174                    );
175
176        $db->query('DELETE FROM videometadatagenre
177                          WHERE videometadatagenre.idvideo = ?',
178                    $this->intid
179                    );
180        if (count($this->genres) > 0)
181            foreach ($this->genres as $genre)
182                $db->query('INSERT INTO videometadatagenre ( idvideo, idgenre )
183                                                    VALUES (       ?,       ? )',
184                           $this->intid,
185                           $genre
186                           );
187
188    }
189}
190?>
191