[mythtv] [Patch] MythWeb MythVideo Info Edit

Bob Cottingham bob at bobnvic.com
Fri Aug 20 17:09:07 EDT 2004


The attached files add the following functionality to the MythWeb
MythVideo Info Edit:

1. Ability to view and choose video cover art from the MythVideo cover art
directory.
2. Pull information and cover art from IMDB using the same imdb.pl script
used by MythVideo.

Included is a patch to mythweb/video_edit.php and a new file
mythweb/video_edit_covers.php.  I also took the opportunity to make the
indenting consistent (4 spaces) in the video_edit.php file.

In addition, a symlink is required in the mythweb root directory to the
MythVideo cover art directory (default cover art directory is
~/.mythtv/MythVideo), and this should be reflected in conf.php for
video.img.path (all of this is already required to show the cover art). 
In order for apache to write files to the cover art directory, each
directory level to the cover art directory must be accessible to apache. 
For example, if the cover art directory is /home/myth/.mythtv/MythVideo,
then the user must do a chmod a+x /home /home/myth /home/myth/.mythtv
/home/myth/.mythtv/MythVideo.

Although the code is completely functional and, I think, useful, my
inexperience in coding is evident and I would appreciate any constructive
feedback.  There are at least two possible concerns that I am aware of. 
First, I do not separate the logic from the display.  I may attempt this
next as I gain experience with how the rest of mythweb is laid out. 
Secondly, this functionality does require javascript, as does the existing
Video Info Edit code.  I understand this may be an issue with some people.
 I can rewrite the patch to use the same window instead of opening new
windows - this would actually simplify the code some, however it didn't
achieve the effect I wanted at the time and I hadn't heard of any concerns
with the use of javascript in the existing code.  Of course, it may simply
be that few, if any, are actually using this functionality and therefore
didn't notice.  Before completely rewriting my patch, I'd like to hear if
this is an issue and about any other needed changes.

Please provide feedback, and if acceptable, commit to CVS.

Thanks,
Bob Cottingham
-------------- next part --------------
? mythweb.patch
? video_edit_covers.php
Index: video_edit.php
===================================================================
RCS file: /var/lib/mythcvs/mythweb/video_edit.php,v
retrieving revision 1.1
diff -u -d -r1.1 video_edit.php
--- video_edit.php	22 May 2004 07:09:23 -0000	1.1
+++ video_edit.php	20 Aug 2004 21:06:01 -0000
@@ -1,14 +1,12 @@
 <?php
 /***                                                                        ***\
-    video_edit.php                  Last Updated: 2004.05.21 (bobcottingham)
+    video_edit.php                  Last Updated: 2004.08.16 (bobcottingham)
 
     edit video info
 \***                                                                        ***/
 
-
 // Initialize the script, database, etc.
     require_once "includes/init.php";
-
 ?>
 <script language="JavaScript">
 <!--
@@ -23,19 +21,128 @@
 //-->
 </script>
 <?php
+$action = $HTTP_GET_VARS['action'];
+
 //check to see if the form has been submitted
 if (isset($_POST['submit'])) {
 
-      //insert data into database
-      mysql_query("UPDATE videometadata SET title='{$_POST['title']}',director='{$_POST['director']}',plot='{$_POST['plot']}',rating='{$_POST['rating']}',inetref='{$_POST['inetref']}',year='{$_POST['year']}',userrating='{$_POST['userrating']}',length='{$_POST['length']}' WHERE intid='{$_POST['intid']}'");
-      //close window and refresh parent
-      ?><body onLoad="refreshParent()"</body><?php
+    //insert data into database
+    $title = addslashes($_POST['title']);
+    $plot = addslashes($_POST['plot']);
+    $coverfile=$_POST['coverdir']."/".$_POST['coverfile']; 
+    mysql_query("UPDATE videometadata SET title='{$title}',director='{$_POST['director']}',plot='{$plot}',rating='{$_POST['rating']}',inetref='{$_POST['inetref']}',year='{$_POST['year']}',userrating='{$_POST['userrating']}',length='{$_POST['length']}',coverfile='{$coverfile}' WHERE intid='{$_POST['intid']}'")
+        or trigger_error('SQL Error: '.mysql_error(), FATAL);
+    //close window and refresh parent
+    ?><body onLoad="refreshParent()"</body><?php
+}
+
+// save post data while browsing cover images
+if (isset($_POST['cover'])) {
+    $_SESSION['title']=$_POST['title'];
+    $_SESSION['director']=$_POST['director'];
+    $_SESSION['plot']=$_POST['plot'];
+    $_SESSION['rating']=$_POST['rating'];
+    $_SESSION['inetref']=$_POST['inetref'];
+    $_SESSION['year']=$_POST['year'];
+    $_SESSION['userrating']=$_POST['userrating'];
+    $_SESSION['length']=$_POST['length'];
+    $_SESSION['coverdir']=$_POST['coverdir'];
+    $_SESSION['coverfile']=$_POST['coverfile'];
+    $title=$_SESSION['title'];
+    $director=$_SESSION['director'];
+    $plot=$_SESSION['plot'];
+    $rating=$_SESSION['rating'];
+    $inetref=$_SESSION['inetref'];
+    $year=$_SESSION['year'];
+    $userrating=$_SESSION['userrating'];
+    $length=$_SESSION['length'];
+    $coverfile=$_SESSION['coverfile'];
+    $coverdir=$_SESSION['coverdir'];
+} 
+
+//reset session data if cover images browsed
+elseif ($action == "covers") {
+
+    $title=$_SESSION['title'];
+    $director=$_SESSION['director'];
+    $plot=$_SESSION['plot'];
+    $rating=$_SESSION['rating'];
+    $inetref=$_SESSION['inetref'];
+    $year=$_SESSION['year'];
+    $userrating=$_SESSION['userrating'];
+    $length=$_SESSION['length'];
+    $coverfile=$_SESSION['coverfile'];
+    $coverdir=$_SESSION['coverdir'];
+}
+
+// Lookup movie in IMDB 
+elseif (isset($_POST['imdb'])) {
+    $title=$_POST['title'];
+    echo "Search on: ".$title;
+    $imdbmovies = "/usr/local/share/mythtv/mythvideo/scripts/imdb.pl -M $title ";	
+    exec ($imdbmovies, $resultArray);
+    ?> <br /> <body bgcolor="#002650" text="#DEDEDE" link="#E0E0FF" alink="#990033" vlink="#E0E0FF" onclick="hide()"> 
+    Choose from the following results:<br /><?
+    for ($x=0; $resultArray[$x];$x++) {
+        $movieid=substr($resultArray[$x],0,strpos($resultArray[$x],":"));
+        $title=substr($resultArray[$x],strpos($resultArray[$x],":")+1);
+        ?>
+        <a href="video_edit.php?movieid=<?=$movieid?>&intid=<?=$_REQUEST['intid']?>"><?=$title?><br /></a>
+        <?
+    }
+    ?><br />Or submit the IMDB Number Here:<br/>
+    <form name="form1" method="post" action="<?=$_SERVER['PHP_SELF']?>">
+    <table width="302" border="0" cellspacing="0" cellpadding="3">
+    <tr>
+        <td width="99">IMDB Number:</td>
+        <td width="301"><input name="movieid" type="text" size=20 value=""></td>
+    </tr><tr>
+        <td><input type="hidden" name="intid" value="<?if (isset($_REQUEST['intid'])) print $_REQUEST['intid']?>">
+        <input type="submit" name="movieidsubmit" value="submit"></td>
+    </tr>
+    </table>
+    </form><?
+    exit;
 }
 
+// Pull data from IMDB for specified movie
+elseif (isset($_REQUEST['movieid'])) {
+    $movieid=$_REQUEST['movieid'];
+    $imdbdata = "/usr/local/share/mythtv/mythvideo/scripts/imdb.pl -D $movieid ";
+    exec ($imdbdata, $resultArray); 
+    $title=substr($resultArray[0],strpos($resultArray[0],":")+1);
+    $year=substr($resultArray[1],strpos($resultArray[1],":")+1);
+    $director=substr($resultArray[2],strpos($resultArray[2],":")+1);
+    $plot=substr($resultArray[3],strpos($resultArray[3],":")+1);
+    $userrating=substr($resultArray[4],strpos($resultArray[4],":")+1);
+    $rating=substr($resultArray[5],strpos($resultArray[5],":")+1);
+    $inetref=$movieid;
+    $length=substr($resultArray[6],strpos($resultArray[6],":")+1);
+    $imdbcover="/usr/local/share/mythtv/mythvideo/scripts/imdb.pl -P $movieid ";
+    exec ($imdbcover, $coverArray); 
+    $cfile = fopen($coverArray[0],"rb"); 
+    while(!feof($cfile)) 
+    { 
+        $cont.= fread($cfile,1024); 
+    } 
+    fclose($cfile); 
+    $covername=video_img_path.basename($coverArray[0]);
+    $cfile2 = fopen($covername,"w"); 
+    fwrite($cfile2,$cont); 
+    fclose($cfile2); 
+    $coverfile=basename($coverArray[0]);
+} else {
+
 //get data to prefill form if we're editing an existing entry
-   $edit_result = mysql_query("SELECT intid,title,director,plot,rating,inetref,year,userrating,length FROM videometadata WHERE intid=' {$_REQUEST['intid']}'")
+    $cover_result = mysql_query("SELECT data FROM settings WHERE value='VideoArtworkDir'")
           or trigger_error('SQL Error: '.mysql_error(), FATAL);
-     list($intid,$title,$director,$plot,$rating,$inetref,$year,$userrating,$length)=mysql_fetch_array($edit_result);
+    $edit_result = mysql_query("SELECT intid,title,director,plot,rating,inetref,year,userrating,length,coverfile FROM videometadata WHERE intid=' {$_REQUEST['intid']}'")
+          or trigger_error('SQL Error: '.mysql_error(), FATAL);
+    list($coverdir) = mysql_fetch_array($cover_result);
+    list($intid,$title,$director,$plot,$rating,$inetref,$year,$userrating,$length,$coverfile)=mysql_fetch_array($edit_result);
+    $coverfile=basename($coverfile);
+}
+
 //output html form
 ?>
 
@@ -54,14 +161,11 @@
 </style>
 </head>
 
-<body bgcolor="#003060" text="#DEDEDE" link="#3181B4" alink="#CC0000" vlink="#3181B4" onclick="hide()">
+<body bgcolor="#002650" text="#DEDEDE" link="#E0E0FF" alink="#990033" vlink="#E0E0FF" onclick="hide()">
 
 <p align="center">
 <font size="+1">Edit Video Info</font>
 </p>
-
-<br>
-
 <form method="post" action="<?=$_SERVER['PHP_SELF']?>">
 <table width="302" border="0" cellspacing="0" cellpadding="3">
 <tr>
@@ -72,10 +176,10 @@
     <td><input name="director" type="text" value="<?if (isset($director)) print $director; ?>"></td>
 </tr><tr>
     <td>Plot:</td>
-    <td><textarea name="plot" rows="5" cols="30" wrap="VIRTUAL"><?if (isset($plot)) print $plot; ?></textarea></td>
+    <td><textarea name="plot" rows="5" cols="35" wrap="VIRTUAL"><?if (isset($plot)) print $plot; ?></textarea></td>
 </tr><tr>
     <td>Rating:</td>
-    <td><input name="rating" type="text" value="<?if (isset($rating)) print $rating; ?>"></td>
+    <td><textarea name="rating" rows="2" cols="35" wrap="VIRTUAL"><?if (isset($rating)) print $rating; ?></textarea></td>
 </tr><tr>
     <td>IMDB:</td>
     <td><input name="inetref" type="text" value="<?if (isset($inetref)) print $inetref; ?>"></td>
@@ -83,15 +187,19 @@
     <td>Year:</td>
     <td><input name="year" type="text" size=4 value="<?if (isset($year)) print $year; ?>"></td>
 </tr><tr>
-    <td>Userrating:</td>
+    <td>User Rating:</td>
     <td><input name="userrating" type="text" size=3 value="<?if (isset($userrating)) print $userrating; ?>"></td>
 </tr><tr>
     <td>Length:</td>
     <td><input name="length" type="text" size=3 value="<?if (isset($length)) print $length; ?>"> in minutes</td>
 </tr><tr>
+    <td>Cover Art:</td>
+    <td><input name="coverfile" type="text" value="<?if(isset($coverfile)) print $coverfile; ?>"><input type="hidden" name="coverdir" value="<? print $coverdir ?>"><INPUT TYPE="submit" NAME="cover" VALUE="Select Image" onclick="window.open('video_edit_covers.php?intid=<?=$_REQUEST['intid']?>','_blank')">    
+</tr><tr>
     <td></td>
     <td><input type="hidden" name="intid" value="<?if (isset($_REQUEST['intid'])) print $_REQUEST['intid']?>">
-       <input type="submit" name="submit" value="submit"></td>
+        <input type="submit" name="imdb" value="Pull from IMDB">            
+        <input type="submit" name="submit" value="Submit"></td>
 </tr>
 </table>
-------------- next part --------------
<?php
/***                                                                        ***\
    video_edit_covers.php                  Last Updated: 2004.08.16 (bobcottingham)

    select video coverfile

    based on image browser by  shakib at http://www.mediumart.co.uk
\***                                                                        ***/

// Initialize the script, database, etc.
    require_once "includes/init.php";
    global $coverfile;

/* CONFIG */

// maximum width and height of scaled images
$maxw = 100;
$maxh = 75;
// number of columns in table
$cols = 4;
// number of rows in table
$rows = 4;
// default sorting method ["date","size","name"]
$df_sortby = "name";
// default ordering (ascending or descending) ["ASC","DESC"]
$df_ascdsc = "ASC";
// coverfile directory under the mythweb web directory - should be set to covers in config/conf.php
$imgdir= video_img_path;
#$imgdir= "covers/";
echo video_img_path;
echo $imgdir;
// allowed image types
$sfxs = array(".jpg",".jpeg",".png");

/* INITIALIZATION */

$coverfile=$HTTP_GET_VARS['coverfile'];
$action = $HTTP_GET_VARS['action'];
$intid = $HTTP_GET_VARS['intid'];

// useful shortcut
$url = $_SERVER["PHP_SELF"]."?&intid=".$intid;

if ($action == 'covers') {
    leavePage ();
}

// start point and ordering
$start = ( isset($_GET["start"]) ) ? $_GET["start"] : 0;
$sortby = ( isset($_GET["sortby"]) ) ? $_GET["sortby"] : $df_sortby;
$ascdsc = ( isset($_GET["ascdsc"]) ) ? $_GET["ascdsc"] : $df_ascdsc;

?>
<script language="JavaScript">
<!--
function refreshParent() {
  window.opener.location.href = 'video_edit.php?action=covers&intid=<?=$intid?>';

  if (window.opener.progressWindow) {
    window.opener.progressWindow.close()
  }
  window.close();
}
//-->
</script>

<?
/* READ DIRECTORY */
// create array to hold filenames and information
// $images[n][0] = name
// $images[n][1] = date
// $images[n][2] = size
$images = array();

@ $handle = opendir($imgdir);
if ( !$handle ) {
    error("could not open directory!");
    exit;
}

#while ( $file = readdir($handle) ) {    original code
while (false !== ($file = readdir($handle) ) ) {
    if ( isValid($file,$sfxs) ) {
        $tmp = array();
        $tmp[0] = $file;
        $tmp[1] = filemtime($imgdir.$file);
        $tmp[2] = filesize($imgdir.$file);
        array_push($images,$tmp);
    }
}

// now sort the dir:
usort($images,"sortme");

?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>
    <title>MythVideo Cover Images</title>
    <style>
               body, td, input, select {
                         font-family: Verdana, Arial, Helvetica, sans-serif;
                         font-size: 0.8em;
               }
               a {
                          font-weight: bold;
                }
                .img {
                            font-size: 0.7em;
                            border: 1px solid #666666;
                            text-align: center;
                             vertical-align: bottom;
                             padding: 5px 2px 5px 2px;
    </style>
</head>
<body>
<h3 align="center">MythVideo Cover Images</h3>
<?
    /* CREATE TABLE */
    $k = $start;
    $n = count($images);
    $ord = "&sortby=".$sortby."&ascdsc=".$ascdsc;
    if ( $start > 0 ) {
        $pn = $start - $rows*$cols;
        $prev = '<a href="'.$url.$ord.'&start='.$pn.'">prev</a>';
    } else {
        $prev = "prev";
    }
    if ( $start + $rows*$cols < $n) {
        $nn = $start + $rows*$cols;
        $next = '<a href="'.$url.$ord.'&start='.$nn.'">next</a>';
    } else {
        $next = "next";
    }
    if ( $n-$k < $rows*$cols ) {
        $rows = ceil(($n-$k)/$cols);
    }
?>

<table border="0" align="center" width="<?=$cols*$maxw*1.4?>">
    <tr>
        <td colspan="<?=$cols?>" align="center">
            <form name="f" action="<?=$_SERVER["PHP_SELF"]?>" method="GET">
            <input name="start" type="hidden" value="<?=$start?>">
            sort by
            <select name="sortby">
            <option value="-1">-- sort by --</option>
            <option value="date"<? if ($sortby=="date") echo " SELECTED"?>>date</option>
            <option value="size"<? if ($sortby=="size") echo " SELECTED"?>>size</option>
            <option value="name"<? if ($sortby=="name") echo " SELECTED"?>>name</option>
            </select>
            <input name="ascdsc" value="ASC" type="radio"<? if ($ascdsc=="ASC") echo " CHECKED"?>>ascending
            <input name="ascdsc" value="DESC" type="radio"<? if ($ascdsc=="DESC") echo " CHECKED"?>>descending
            <input type="submit" value="re-sort">
            </form>
        </td>
    </tr>
    <tr>
        <td colspan="<?=$cols?>"><hr></td>
    </tr>
    <tr>
        <td colspan="<?=$cols?>">
            <table width="100%">
                <tr>
                    <td><?=$prev?></td>
                    <td align="right"><?=$next?></td>
                </tr>
            </table>
        </td>
    </tr>
<?
    for ( $i=0; $i<$rows; $i++ ) {
?>
    <tr>
<?
        for ( $j=0; $j<$cols; $j++ ) {
?>
        <td class="img">
<?
            if ( $k < $n ) {
?>
            <a href="<?=$imgdir.$images[$k][0]?>" target="blank">
                <img src="<?=$imgdir.$images[$k][0]?>" height="<?=$maxh ?>" border="0">
            </a><br />
            <a href="video_edit_covers.php?action=covers&coverfile=<?=$images[$k][0]?>&intid=<?=$intid?>"><?=$images[$k][0]?>
            </a><br />
            <?=round($images[$k][2]/1024)?>Kb, <?=date("d-m-y",$images[$k][1])?>
<?
            } else {
?>
            &nbsp;
<?
            }
?>
        </td>
<?
            $k++;
        }
?>
    </tr>
<?
    }
?>
    <tr>
        <td colspan="<?=$cols?>"><hr></td>
    </tr>
    <tr>
        <td colspan="<?=$cols?>" align="center">
        Click on the image to enlarge to full size.<br />
        Click on the title to select image for cover.
        </td>
    </tr>
</table>

</body>
</html>

<?
    /*
        USEFUL FUNCTIONS
    */

    function isValid($f,$a) {
        $t = getSuffix($f);
        return ( in_array($t,$a) ) ? true : false;
    }

    function getSuffix($f) {
        $n = strrpos($f,".");
        return substr($f,$n,strlen($f)-$n);
    }

    function sortme($a,$b) {
        // setup
        global $sortby, $ascdsc;
        if ( $sortby == "name" ) {
            $n = 0;
        } elseif ( $sortby == "date" ) {
            $n = 1;
        } elseif ( $sortby == "size" ) {
            $n = 2;
        }
        $m = ( $ascdsc == "ASC" ) ? 1 : -1;
        if ( $a[$n] == $b[$n] ) return 0;
        return ($a[$n] > $b[$n]) ? $m : -1*$m;
    }

    function leavePage () {
        global $coverfile,$intid;
        session_name("mythweb_id");
        session_start();
        $_SESSION['coverfile']=$coverfile;
            ?><body onLoad="refreshParent()"</body><?php
    }

    function error($str) {
        echo '<div style="background-color:#ffffff;color:#660000;font-weight:bold">'.$str.'</div>';
    }

?>


More information about the mythtv-dev mailing list