diff -crN --exclude=.svn -x data /usr/src/myth/trunk/mythplugins/mythweb/classes/Video.php ./classes/Video.php
*** /usr/src/myth/trunk/mythplugins/mythweb/classes/Video.php 2010-01-13 14:37:23.000000000 +0000
--- ./classes/Video.php 2010-01-20 09:16:45.000000000 +0000
***************
*** 33,38 ****
--- 33,46 ----
function __construct($intid) {
global $db;
global $mythvideo_dir;
+
+ // Video storage directories
+ $video_dirs = $db->query_list('
+ SELECT dirname
+ FROM storagegroup
+ WHERE groupname="Coverart"
+ ');
+
$video = $db->query_assoc('
SELECT *
FROM videometadata
***************
*** 56,71 ****
$this->cover_file = $video['coverfile'];
$this->browse = $video['browse'];
// And the artwork URL
! if ($this->cover_file != 'No Cover' && file_exists($this->cover_file) ) {
! $this->cover_url = 'data/video_covers/'.substr($this->cover_file, strlen(setting('VideoArtworkDir', hostname)));
! list($width, $height) = @getimagesize($this->cover_file);
! if ($width > 0 && $height > 0) {
! $wscale = video_img_width / $width;
! $hscale = video_img_height / $height;
! $scale = $wscale < $hscale ? $wscale : $hscale;
! $this->cover_scaled_width = floor($width * $scale);
! $this->cover_scaled_height = floor($height * $scale);
}
}
$this->childid = $video['childid'];
// Figure out the URL
--- 64,90 ----
$this->cover_file = $video['coverfile'];
$this->browse = $video['browse'];
// And the artwork URL
! $this->cover_url = '';
! if ($this->cover_file != 'No Cover') {
! $exists = false;
! foreach ($video_dirs as $dir) {
! $path = preg_replace('#/+#', '/', "$dir/$this->cover_file");
! if (file_exists($path) && is_executable(dirname($path))) {
! $exists = true;
! break;
! }
}
+ if ($exists) {
+ $this->cover_url = 'pl/coverart/'.$this->cover_file;
+ $this->cover_file = path;
+ list($width, $height) = @getimagesize($this->cover_file);
+ if ($width > 0 && $height > 0) {
+ $wscale = video_img_width / $width;
+ $hscale = video_img_height / $height;
+ $scale = $wscale < $hscale ? $wscale : $hscale;
+ $this->cover_scaled_width = floor($width * $scale);
+ $this->cover_scaled_height = floor($height * $scale);
+ }
}
$this->childid = $video['childid'];
// Figure out the URL
***************
*** 165,167 ****
--- 184,187 ----
}
}
+ ?>
diff -crN --exclude=.svn -x data /usr/src/myth/trunk/mythplugins/mythweb/modules/coverart/handler.pl ./modules/coverart/handler.pl
*** /usr/src/myth/trunk/mythplugins/mythweb/modules/coverart/handler.pl 1970-01-01 01:00:00.000000000 +0100
--- ./modules/coverart/handler.pl 2010-01-20 09:13:09.000000000 +0000
***************
*** 0 ****
--- 1,163 ----
+ #!/usr/bin/perl
+ #
+ # MythWeb Coverart/Download module
+ #
+ # @url $URL$
+ # @date $Date$
+ # @version $Revision$
+ # @author $Author$
+ #
+
+ # Necessary constants for sysopen
+ use Fcntl;
+
+ # Other includes
+ use Sys::Hostname;
+ use HTTP::Date;
+
+ # Attempt to use the perl bindings to prevent the backend from shutting down during streaming
+ eval 'use MythTV;';
+
+ if (!$@) {
+ our $mythbackend = new MythTV();
+ $mythbackend->backend_command('ANN Playback '.hostname);
+ }
+
+ # Which cover are we displaying
+ our $cover = url_param('cover');
+ if ($Path[1]) {
+ $cover = $Path[1];
+ }
+
+ # No match?
+ unless ($cover =~ /\w/) {
+ print header(),
+ "Unknown cover requested.\n";
+ exit;
+ }
+
+ # Find the local file
+ our $filename;
+ $sh = $dbh->prepare('SELECT dirname FROM storagegroup WHERE groupname = "Coverart"');
+ $sh->execute();
+ while (my ($coverart_dir) = $sh->fetchrow_array()) {
+ next unless (-e "$coverart_dir/$cover");
+ $filename = "$coverart_dir/$cover";
+ last;
+ }
+ $sh->finish;
+
+ 1;
+
+ unless ($filename) {
+ print header(),
+ "$cover does not exist in any recognized storage group directories for this host.";
+ exit;
+ }
+
+ # File size
+ my $size = -s $filename;
+
+ # Zero bytes?
+ if ($size < 1) {
+ print header(),
+ "$cover is an empty file.";
+ exit;
+ }
+
+ # File type
+ my $type = 'text/html';
+ my $suffix = '';
+ if ($cover =~ /\.jpg$/) {
+ $type = 'image/jpeg';
+ $suffix = '.jpg';
+ }
+ else {
+ print header(),
+ "Unknown image type requested: $cover\n";
+ exit;
+ }
+
+ # Open the file for reading
+ unless (sysopen DATA, $filename, O_RDONLY) {
+ print header(),
+ "Can't read $cover: $!";
+ exit;
+ }
+
+ # Binmode, in case someone is running this from Windows.
+ binmode DATA;
+
+ my $start = 0;
+ my $end = $size;
+ my $total_size = $size;
+ my $read_size = 1024;
+ my $mtime = (stat($filename))[9];
+
+ # Handle cache hits/misses
+ if ( $ENV{'HTTP_IF_MODIFIED_SINCE'}) {
+ my $check_time = str2time($ENV{'HTTP_IF_MODIFIED_SINCE'});
+ if ($mtime <= $check_time) {
+ print header(-Content_type => $type,
+ -status => "304 Not Modified"
+ );
+ exit;
+ }
+ }
+
+ # Requested a range?
+ if ($ENV{'HTTP_RANGE'}) {
+ # Figure out the size of the requested chunk
+ ($start, $end) = $ENV{'HTTP_RANGE'} =~ /bytes\W+(\d*)-(\d*)\W*$/;
+ if ($end < 1 || $end > $size) {
+ $end = $size;
+ }
+ $size = $end - $start+1;
+ if ($read_size > $size) {
+ $read_size = $size;
+ }
+ print header(-status => "206 Partial Content",
+ -type => $type,
+ -Content_length => $size,
+ -Accept_Ranges => 'bytes',
+ -Content_Range => "bytes $start-$end/$total_size",
+ -Last_Modified => time2str($mtime),
+ -Content_disposition => " attachment; filename=\"$cover\""
+ );
+ }
+ else {
+ print header(-type => $type,
+ -Content_length => $size,
+ -Accept_Ranges => 'bytes',
+ -Last_Modified => time2str($mtime),
+ -Content_disposition => " attachment; filename=\"$cover\""
+ );
+ }
+
+ # Seek to the requested position
+ sysseek DATA, $start, 0;
+
+ # Print the content to the browser
+ my $buffer;
+ while (sysread DATA, $buffer, $read_size ) {
+ print $buffer;
+ $size -= $read_size;
+ if ($size == 0) {
+ last;
+ }
+ if ($size < $read_size) {
+ $read_size = $size;
+ }
+ }
+ close DATA;
+
+ # Escape a parameter for safe use in a commandline call
+ sub shell_escape {
+ $str = shift;
+ $str =~ s/'/'\\''/sg;
+ return "'$str'";
+ }
+
+ # Return true
+ 1;
+
diff -crN --exclude=.svn -x data /usr/src/myth/trunk/mythplugins/mythweb/modules/coverart/init.php ./modules/coverart/init.php
*** /usr/src/myth/trunk/mythplugins/mythweb/modules/coverart/init.php 1970-01-01 01:00:00.000000000 +0100
--- ./modules/coverart/init.php 2010-01-20 09:17:04.000000000 +0000
***************
*** 0 ****
--- 1,15 ----
+
diff -crN --exclude=.svn -x data /usr/src/myth/trunk/mythplugins/mythweb/modules/video/tmpl/default/video.php ./modules/video/tmpl/default/video.php
*** /usr/src/myth/trunk/mythplugins/mythweb/modules/video/tmpl/default/video.php 2010-01-13 14:37:22.000000000 +0000
--- ./modules/video/tmpl/default/video.php 2010-01-19 15:43:20.000000000 +0000
***************
*** 318,324 ****
if (strlen($video->subtitle) > 0)
echo '
' . html_entities($video->subtitle);
?>
!