Ticket #1322: transcode.2.diff

File transcode.2.diff, 13.3 KB (added by penguin@…, 18 years ago)
  • mythweb/themes/default/tv/transcode.php

     
     1<?php
     2// Add transcode job to jobqueue.
     3// By Penguin Frozen <penguin@frozendesert.net>
     4
     5
     6//Get stage
     7$stage = $_POST["stage"];
     8
     9//This keeps us from altering the database
     10    $Live=true;
     11//This show how much info to show
     12//0 - Off
     13//1 - Debug
     14    $verbose=0;
     15
     16// Set the desired page title
     17    $page_title = 'MythWeb - Transcode';
     18    $headers[0] = "<link rel=\"stylesheet\" href=\"" . skin_url . "/transcode.css\">";
     19    if ($stage==3 && $verbose==0) {
     20        $headers[1] = "<meta http-equiv=\"refresh\" content=\"1;/mythweb/\">";
     21    }
     22   
     23
     24// Print the page header
     25    require_once theme_dir.'/header.php';
     26
     27
     28?>
     29<br>
     30<?php
     31if (!isset($_POST["stage"]))
     32{
     33//Entry page
     34    echo ("
     35    <form action=\"transcode\" method=\"POST\">
     36    <input type=hidden name=\"stage\" value=\"2\">
     37    <table align=center border=1>
     38    <!-- <tr><td><select name=\"select_video\"> -->
     39    ");
     40    $query = "SELECT title,subtitle,chanid,starttime,description,filesize FROM recorded ORDER BY title,starttime DESC";
     41    $result = mysql_query($query);
     42
     43    $rows = mysql_numrows($result);
     44    $i = 0;
     45    $j = 0;
     46    while ($i<$rows)
     47    {
     48        $title = mysql_result($result,$i,"title");
     49        $subtitle = mysql_result($result,$i,"subtitle");
     50        $chanid = mysql_result($result,$i,"chanid");
     51        $starttime = mysql_result($result,$i,"starttime");
     52        $description = mysql_result($result,$i,"description");
     53        $vid_info = transcode_encode_vidlink($chanid,$starttime);
     54        $filesize = mysql_result($result,$i,"filesize");
     55        $filesize = (int)($filesize/(1024*1024));
     56        //Only show the file if it has commercial cutpoints and is not already queued
     57        if (transcode_has_cutpoints($vid_info) && !transcode_is_queued($vid_info))
     58        {
     59            echo ("<tr>");
     60            echo ("<td><input type=checkbox name=\"$i\" value=\"$vid_info\"></td>");
     61            echo ("<td>$title");
     62            if ($subtitle != "")
     63              echo (": $subtitle");
     64            echo ("</td>");
     65            echo ("<td width=400>$description</td>");
     66            echo ("<td>$starttime</td>");
     67            echo ("<td>$filesize MB</td>");
     68            echo ("</tr>");
     69        }
     70
     71        $i++;
     72    }
     73    echo ("
     74    </table>
     75    <br><center><input type=submit value=\"Review Selections\"></center>
     76    </form>
     77    ");
     78}
     79?>
     80<div id="vidinfo">
     81</div>
     82<?php
     83if ( $stage == 2 )
     84{
     85//Show confirmation page
     86    echo ("
     87    <div id=\"vidinfo\">
     88    <form action=\"transcode\" method=\"POST\">
     89    <input type=hidden name=\"stage\" value=\"3\">
     90    <br>Will transcode the following videos:
     91    ");
     92    foreach ($_POST as $post_key => $post_value)
     93    {
     94        if ($post_key !== "stage")
     95        {
     96            echo ("<input type=hidden name=\"$post_key\" value=\"$post_value\">\n");
     97            $video_info = transcode_get_vidinfo($post_value);
     98            echo ("<br> ");
     99            echo ("<a id=\"program_" . $post_key . "\" href=\"#\" onmouseover =\"popup('program_" . $post_key . "', '');return true\">");
     100            echo ($video_info["title"]);
     101            if ($video_info["subtitle"] != "")
     102              echo (": " . $video_info["subtitle"]);
     103            echo ("</a>\n");
     104        }
     105    }
     106    echo ("
     107    <br>
     108    <br><input type=submit value=\"Queue\">
     109    </form>
     110    </div>
     111    ");
     112    foreach ($_POST as $post_key => $post_value)
     113    {
     114        if ($post_key !== "stage")
     115        {
     116            $video_info = transcode_get_vidinfo($post_value);
     117            echo ("<div id=\"program_" . $post_key . "_popup\" class=\"popup\"><dl class=\"details_list\">\n");
     118            echo ("<dt>Title:</dt><dd>" . $video_info["title"]);
     119            if ($video_info["subtitle"] != "")
     120              echo (": " . $video_info["subtitle"]);
     121            echo ("</dd>\n");
     122            echo ("<dt>Start time:</dt><dd>" . $video_info["starttime"] . "</dd>\n");
     123            echo ("<dt>End time:</dt><dd>" . $video_info["endtime"] . "</dd>\n");
     124            echo ("<dt>Chanid:</dt><dd>" . $video_info["chanid"] . "</dd>\n");
     125            echo ("<dt>Host:</dt><dd>" . $video_info["hostname"] . "</dd>\n");
     126            echo ("<dt>Filesize:</dt><dd>" . $video_info["filesize"] . "MB</dd>\n");
     127            echo ("<dt>Description:</dt><dd>" . $video_info["description"] . "</dd>\n");
     128            echo ("</div>\n");
     129        }
     130    }
     131}
     132else if ( $stage == 3 )
     133{
     134//Database modification process
     135    if ($verbose>0)
     136        echo ("<div id=\"vidinfo\">");
     137    if (!$Live && $verbose>0)
     138      echo ("<font color=\"red\"><b>Notice</b>: Database Safe-mode Activated</font>");
     139    foreach ($_POST as $post_key  => $post_value)
     140    {
     141        if ($post_key !== "stage")
     142        {
     143            if ($verbose>0)
     144                echo ("<br><br>Got $post_key : $post_value");
     145            $video_parms = transcode_decode_vidlink($post_value);
     146            $insert_time = date("Y-m-d H:i:s");
     147            $query = "SELECT mark,type FROM recordedmarkup WHERE chanid=\"$video_parms[0]\" AND starttime=\"$video_parms[1]\" AND type BETWEEN 4 AND 5";
     148            if ($verbose>0)
     149                echo ("<br>Query: $query");
     150            $result = mysql_query($query);
     151            $i = 0;
     152            $cutpoint = 0;
     153            $rows = mysql_numrows($result);
     154            if ($verbose>0)
     155                echo ("<br>Rows: $rows");
     156            $cutlist = array();
     157            $query = "UPDATE recorded SET cutlist=\"";
     158            while ($i<$rows)
     159            {
     160                $type = mysql_result($result,$i,"type");
     161                $mark = mysql_result($result,$i,"mark");
     162                if ($type == 4)
     163                    $cutlist[$cutpoint] = $mark;
     164                if ($type == 5) {
     165                    $cutlist[$cutpoint] = $cutlist[$cutpoint]." - $mark";
     166                    $query = $query."$cutlist[$cutpoint]\n";
     167                    if ($verbose>0)
     168                        echo ("<br>Cutpoint created: $cutlist[$cutpoint]");
     169                    $cutpoint++;
     170                }
     171                $i++;
     172            }
     173            if ($verbose>0)
     174                echo ("<br>Cutpoints created: $cutpoint");
     175            $query = $query."\" WHERE chanid=\"$video_parms[0]\" AND starttime=\"$video_parms[1]\"";
     176            if ($Live)
     177              mysql_query($query);
     178            if ($verbose>0)
     179                echo ("<br>Query: $query");
     180            $query = "INSERT INTO jobqueue VALUES ('','$video_parms[0]','$video_parms[1]','$insert_time',1,0,1,1,'','','','')";
     181            if ($Live)
     182              mysql_query($query);
     183            if ($verbose>0)
     184                echo ("<br>Query: $query");
     185        }
     186    }
     187    if ($verbose>0)
     188    {
     189        echo ("<br><br><a href=\"transcode\">Transcode</a>");
     190        echo ("</div");
     191    }
     192}
     193
     194
     195
     196
     197// Print the page footer
     198    require_once theme_dir.'/footer.php';
     199
     200
  • mythweb/themes/default/header.php

     
    176176                    &nbsp; | &nbsp;
    177177                    <a href="<?php echo root ?>backend_log"><?php echo t('Backend Logs') ?></a>
    178178<?php } ?>
     179                    &nbsp; | &nbsp;
     180                    <a href="<?php echo root ?>tv/transcode"><?php echo t('Transcode') ?></a>
    179181                </div></td>
    180182        </tr>
    181183        </table></td>
  • mythweb/skins/default/transcode.css

     
     1#vidinfo {
     2    position: relative;
     3    left: 120pt;
     4    width: 600px;
     5}
     6
     7#vid_warn {
     8    font-size: 12px;
     9    color: #FF0000;
     10}
     11 No newline at end of file
  • mythweb/languages/English.php

    Property changes on: mythweb/skins/default/transcode.css
    ___________________________________________________________________
    Name: svn:executable
       + *
    
     
    9696    'The requested recording schedule has been deleted.' => '',
    9797    'Thursday'                                           => '',
    9898    'Title'                                              => '',
     99    'Transcode'                                          => '',
    99100    'Transcoder'                                         => '',
    100101    'Tuesday'                                            => '',
    101102    'Type'                                               => '',
  • mythweb/modules/tv/transcode.php

     
     1<?php
     2// Add jobqueue entries
     3// By Penguin Frozen <penguin@frozendesert.net>
     4
     5/*
     6
     7Mythjobqueue Types, Commands, Flags, And Status
     8
     9Types
     100 - None
     111 - Transcode
     122 - Commflag
     13
     14Commands
     150 - Run
     161 - Pause
     172 - Resume
     184 - Stop
     198 - Restart
     20
     21Flags
     220 - Reg Flags
     231 - Use cutlist
     242 - Live Recording
     25
     26Status
     270 - Unknown
     281 - Queued
     292 - Pending
     303 - Starting
     314 - Running
     325 - Stopping
     336 - Paused
     347 - Retry
     358 - Erroring
     369 - Aborting
     37100 - Done
     38110 - Finished
     39120 - Aborted
     40130 - Erroreds
     41140 - Cancelled
     42
     43*/
     44function transcode_encode_vidlink($chanid,$starttime)
     45{
     46//Creates encoded string
     47    return implode("~",array($chanid,$starttime));
     48}
     49
     50function transcode_decode_vidlink($vidlink)
     51{
     52//Decodes string
     53    return explode("~",$vidlink);
     54}
     55
     56function transcode_get_vidinfo($vidlink)
     57{
     58//Retrieves video info, uses encoded string
     59    $video_search_info=transcode_decode_vidlink($vidlink);
     60    $query="SELECT title,subtitle,description,hostname,filesize,endtime FROM recorded WHERE chanid=\"$video_search_info[0]\" AND starttime=\"$video_search_info[1]\"";
     61    $result=mysql_query($query);
     62    $rows=mysql_numrows($result);
     63    $i=0;
     64    $video_info=array();
     65    while ($i<$rows)
     66    {
     67        $video_info["title"]=mysql_result($result,$i,"title");
     68        $video_info["subtitle"]=mysql_result($result,$i,"subtitle");
     69        $video_info["description"]=mysql_result($result,$i,"description");
     70        $video_info["hostname"]=mysql_result($result,$i,"hostname");
     71        $video_info["filesize"]=mysql_result($result,$i,"filesize");
     72        $video_info["filesize"]=(int)($video_info["filesize"]/(1024*1024));
     73        $video_info["endtime"]=mysql_result($result,$i,"endtime");
     74        $video_info["chanid"]=$video_search_info[0];
     75        $video_info["starttime"]=$video_search_info[1];
     76        $i++;
     77    }
     78    return $video_info;
     79}
     80
     81function transcode_has_cutpoints($vidlink)
     82{
     83//Determines if a video has commercial cutpoints, uses encoded string
     84    $video_cutpoint_info=transcode_decode_vidlink($vidlink);
     85    $query="SELECT mark FROM recordedmarkup WHERE chanid=\"$video_cutpoint_info[0]\" AND starttime=\"$video_cutpoint_info[1]\" AND type BETWEEN 4 AND 5";
     86    $result=mysql_query($query);
     87    $rows=mysql_numrows($result);
     88    if ($rows>0)
     89        return true;
     90    return false;
     91}
     92
     93function transcode_is_queued($vidlink)
     94{
     95//Checks to see if video is already queued to be transcoded
     96//We wouldn't want to transcode twice :D
     97    $video_queue_info=transcode_decode_vidlink($vidlink);
     98    $query="SELECT id FROM jobqueue WHERE chanid=\"$video_queue_info[0]\" AND starttime=\"$video_queue_info[1]\" AND type=1";
     99    $result=mysql_query($query);
     100    $rows=mysql_numrows($result);
     101    if ($rows>0)
     102        return true;
     103    return false;
     104}
     105
     106// Load the class for this page
     107    require_once theme_dir.'tv/transcode.php';
     108
     109// Exit
     110    exit;
     111
  • mythweb/modules/tv/init.php

    Property changes on: mythweb/modules/tv/transcode.php
    ___________________________________________________________________
    Name: svn:executable
       + *
    
     
    2323                                                  'schedules/manual' => t('Schedule Manually'),
    2424                                                  'schedules/custom' => t('Custom Schedule'),
    2525                                                  'recorded'         => t('Recorded Programs'),
     26                                                  'transcode'        => t('Transcode'),
    2627                                                 ),
    2728                          );
    2829
  • mythweb/.htaccess

     
    108108# or if this is a /css/, /js/ or /cache/ directory request.
    109109    RewriteRule    ^(css|data|images|js|themes|skins|[a-z_]+\.php)(/|$)     -     [L]
    110110
    111 # Redirect most of the remaining URL requests to the main mythweb script.
     111# Redirect most of the remaining URL requests to the main cooktools script.
    112112# It will then handle any requests given to it.
    113113    RewriteRule     ^(.+)$                  mythweb.php/$1              [QSA,L]
    114114