1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Now Playing (more PHP code) - Part II

Discussion in 'TiVo Home Media Features & TiVoToGo' started by windracer, Oct 26, 2007.

  1. clam729

    clam729 Member

    205
    2
    Nov 27, 2004
    Very nice. I have some of those added already - this is how I am doing it (from index.php)
    PHP:
    $tivoarray[$i]['content'] = str_replace("amp;"""$tivoarray[$i]['content']);
    $tivoarray[$i]['title'] = str_replace("amp;"""$tivoarray[$i]['title']);
    $tivoarray[$i]['episodetitle'] = str_replace("amp;"""$tivoarray[$i]['episodetitle']);
    $tivoarray[$i]['description'] = str_replace("Copyright Tribune Media Services, Inc."""$tivoarray[$i]['description']);
    I'll try and work on it a little tonight.
     
  2. HomeUser

    HomeUser Active Member

    2,376
    1
    Jan 12, 2003
    A2 Michigan
    I added some updates to the version in the link that windracer pointed to.

    Some of the changes I made

    - The collapse cookies now work if you have more than one DVR.

    - I added a Summery page useful if you have more than one TiVo DVR.

    - Free space is also displayed as a percent with color warnings when the FS gets below a set level.

    - Modified the code to continue on to the next DVR instead of trapping out if one of the DVR's is off-line.

    - Changed to use GB's instead of MB.

    I only tested the code with Linux and did nothing with the RSS.

    [​IMG]

    Code refresh attached
     

    Attached Files:

  3. windracer

    windracer joined the 10k club

    11,580
    3
    Jan 3, 2003
    St. Pete, FL
    Very cool ... thanks for the updates! :up::up: I had written a custom shell script wrapper to try and check for "offline" TiVos but it never worked reliably and inevitably wget would get hung up somewhere. Your new solution is a lot nicer, and works! ;)

    Just a few things I wanted to point out:

    - you misspelled "Available" in index.php (line 14, for the summary page)
    - you should add your new .pgid, .srid, .epnum class elements to line 9 of tivo.css so the text is formatted in a similar manner to the other elements there

    Thanks again!
     
  4. windracer

    windracer joined the 10k club

    11,580
    3
    Jan 3, 2003
    St. Pete, FL
    Note to others who may upgrade to HomeUser's new version: if you use the check_tivo plugin for Nagios to monitor free space, you'll need to update the plugin code to look for GB instead of MB in the regular expression and also account for the decimal place in the free space number. To do this, I changed the following line:

    Code:
    if (!preg_match("/Available Space \(including Suggestions\)\: (\d+) MB/",$response, $matches)) {
    to:

    Code:
    if (!preg_match("/Available Space \(including Suggestions\)\: (\d+.\d+) GB\s.*/",$response, $matches)) {
     
  5. HomeUser

    HomeUser Active Member

    2,376
    1
    Jan 12, 2003
    A2 Michigan
    I used Percent Free instead of the free space for the Nagios check_tivo_freespace script.

    Code:
    if (!preg_match("/Available Space \(including Suggestions\)\: \d+.\d+\sGB\s\((\d+.\d+).\)*/",
                    $response, $matches)) {
    Changed the output messages to reflect Percent also
    Code:
    if (!preg_match("/Available Space \(including Suggestions\)\: \d+.\d+\sGB\s\((\d+.\d+).\)*/",
                    $response, $matches)) {
      echo "CRITICAL - Unable to find match in $url\n";
      exit(2);
    }
    
    $freespace = intval($matches[1]);
    if ($freespace < $critical) {
      echo "CRITICAL - $freespace% is less than $critical% Free\n";
      exit(2);
    } else if ($freespace < $warning) {
      echo "WARNING - $freespace% is less than $warning% Free\n";
      exit(1);
    } else {
      echo "OK - $freespace% is at least $warning% Free\n";
      exit(0);
    }
    
     
  6. HomeUser

    HomeUser Active Member

    2,376
    1
    Jan 12, 2003
    A2 Michigan
    Good catch, When I started I knew nothing and now know very little about CSS.
    I tried to get ProgramId and SeriesId on the same line like Size and Duration. I think one or both of the ID parameters could be used to organize the programs into folders. Not sure if they are really any use in the output.


    Made you're suggestions and re-uploaded the tivo_now_playing.zip file in the previous message
    Just the two updated files are attached in the zip file this message
     

    Attached Files:

  7. windracer

    windracer joined the 10k club

    11,580
    3
    Jan 3, 2003
    St. Pete, FL
    Ah, I like that idea! I made your changes to the plugin, but the regex doesn't seem to work if the percentage is a whole number (ex. 38% instead of 37.8%).
     
  8. HomeUser

    HomeUser Active Member

    2,376
    1
    Jan 12, 2003
    A2 Michigan
    I just discovered that problem also. Change the second "\d+" one or more of to "\d*" zero or more of.
    Code:
    f (!preg_match("/Available Space \(including Suggestions\)\: \d+.\d*\sGB\s\((\d+.\d*).\)*/",
                    $response, $matches)) {
     
  9. windracer

    windracer joined the 10k club

    11,580
    3
    Jan 3, 2003
    St. Pete, FL
  10. gonzotek

    gonzotek tivo_xml developer

    2,404
    3
    Sep 24, 2004
    Outside...
    Cool, glad to see that people are still using and improving this! The first version (which clam729, et al, then improved upon) was written over a long weekend the month TTG was released, while sick and feverish, so I apologize if the code is ugly :).
     
  11. windracer

    windracer joined the 10k club

    11,580
    3
    Jan 3, 2003
    St. Pete, FL
    I wonder if clam729 ever finished those other cool mods he was working on back in 2008? ;)
     
  12. HomeUser

    HomeUser Active Member

    2,376
    1
    Jan 12, 2003
    A2 Michigan
    If you have Nagios sending e-mail alerts I found that "In Progress Recordings" cause the free space warning to send out false alerts. The "In Progress Recording" suggestions are not counted as suggestions and are being calculated as part of the used space then freeing up space when they become suggestions after recording has completed.

    This free space flapping is especially annoying if you have the Elite with 4 tuners recording suggestions.

    I don't see any indicator that shows a in progress recording is a suggestion so I came up with this hack.

    Code:
    [COLOR="Silver"]foreach($tivos as $tivo) {
    	unset($tivoarray, $totalsize, $totallength, $customicon, $sc, $totalitems, $freespace, $rssheader, $rsscontent, $rssfooter, $header, $content, $footer, $fp1, $fp2, $totalsuggestions, $percent_free, $fpt, $auto_size_gb[/COLOR] , $recording_suggestion);
    
    	[COLOR="Blue"]// both requested and suggestions show now_recording when in progress. Any in progress
    	// recordings before the first non suggestion should be counted as used space.[/COLOR]
    	$recording_suggestion = false;
    
    
    At the start of the TiVo loop I added a new boolean $recording_suggestion and set it to false I also included it in the unset list JIC.

    Code:
    [COLOR="Silver"]		// # compute suggestions added 10/28/2011 
    		if($customicon[3] == "suggestion-recording") {
    			$totalsuggestions += $tivoarray[$i]['sourcesize'];
    		}[/COLOR]
    
    [COLOR="Blue"]		// Fix Nagios free space flapping 04/11/12 VW>
    		// Requested in progress recordings are listed first[/COLOR]
    		if($customicon[3] != "in-progress-recording"){
    			[COLOR="Blue"]//All in progress recordings should now be suggestions[/COLOR]
    			$recording_suggestion = true;
    		}
    		if($recording_suggestion == true){
    			if($customicon[3] == "in-progress-recording"){
    				$totalsuggestions += $tivoarray[$i]['sourcesize'];
    			}
     		}
    
    Added new code that checks for any non in progress recording I added it just after the space used by suggestions is computed $customicon[3] == "suggestion-recording". The new code sets the new Boolean true.
    Next add any additional "In Progress Recordings" to the space used by suggestions.
     
  13. bshrock

    bshrock New Member

    263
    0
    Jan 6, 2012
    Thanks works great.
    Maybe a little more efficient coding?

    Code:
    	[COLOR="Blue"]// Fix Nagios free space flapping 04/11/12 VW>[/COLOR]
    	[COLOR="Blue"]// Requested in progress recordings are listed first
    [/COLOR]
    	if($recording_suggestion == true){
    		if($customicon[3] == "in-progress-recording"){
    			$totalsuggestions += $tivoarray[$i]['sourcesize'];
    		}
    	} else {
    		if($customicon[3] != "in-progress-recording"){
    			[COLOR="Blue"]//All in progress recordings should now be suggestions[/COLOR]
    			$recording_suggestion = true;
    		}
     	}
    
     
  14. bshrock

    bshrock New Member

    263
    0
    Jan 6, 2012
    Is there an easy way to get the data sorted into folders?
     
  15. windracer

    windracer joined the 10k club

    11,580
    3
    Jan 3, 2003
    St. Pete, FL
    So ... I upgraded my Linux server to Ubuntu 12.10 (Quantal Quetzal) on Friday night and today noticed that this script wasn't working anymore. I have it set via cron to run hourly and the last time it ran successfully was Friday before the upgrade.

    I'm thinking it has something to do with PHP 5.4, as I see other folks on the Ubuntu forums mentioning PHP problems. I'm not certain I want to rollback to 5.3 yet since other stuff (like WordPress) is working fine.

    If I manually run 'php index.php' it just does nothing. No errors, no output, even with error_reporting set to -1.

    Anyone have any ideas?

    edit: ahh, fixed it! I found a tivo_errors.txt file that contained this:

    Code:
    [22-Oct-2012 20:57:01 UTC] PHP Notice:  Undefined index: OS in /usr/local/tivo/now_playing/tivo_settings.php on line 8
    [22-Oct-2012 20:57:01 UTC] PHP Fatal error:  Call-time pass-by-reference has been removed in /usr/local/tivo/now_playing/class_tivo_xml.php on line 111
    
    I commented out the check for $_ENV["OS"] in tivo_settings.php to get past the first error (I'm on Linux so I don't need to check for Windows to set the delimiter), but the second one was a little different. After a little Google searching, I determined that line 111 in class_tivo_xml.php needed to be changed from this:

    Code:
     xml_set_object($this->parser, &$this);
    to this:

    Code:
     xml_set_object($this->parser, $this);
    Basically, remove the ampersand (&) before $this.

    That fixed it, the script is working again! :up:
     
  16. gonzotek

    gonzotek tivo_xml developer

    2,404
    3
    Sep 24, 2004
    Outside...
    :) Just as an amusing point of historical fact: That ampersand bug goes all the way back to my first release of the script... and exists because I lifted the xml parsing routine from comments in the php documentation without fully understanding what it did (at the time) :eek:. Thanks for fixing it!
     
  17. HomeUser

    HomeUser Active Member

    2,376
    1
    Jan 12, 2003
    A2 Michigan
    Any one still using or made any updates?
     
  18. gonzotek

    gonzotek tivo_xml developer

    2,404
    3
    Sep 24, 2004
    Outside...
    Anything you're looking for specifically? Other than windracer's fix last year, there hasn't been much interest in this in a quite a while.
     
  19. windracer

    windracer joined the 10k club

    11,580
    3
    Jan 3, 2003
    St. Pete, FL
  20. HomeUser

    HomeUser Active Member

    2,376
    1
    Jan 12, 2003
    A2 Michigan
    Looking to see if there is any interest or any important changes b4 cleaning up and posting new code.

    Over the past year I have made many changes.
    When I thought the DVR was deleting programs early I modified the program to save a history of the playlists. Click on the number of suggestions in the summery table to bring up a table linking to the play lists of that DVR for the current month.

    When I was searching the DVR's for a BBCA program that did not record (was set to record only new) and hoping that the program was recorded as a suggestion I added a combined play list to make searching all of the DVRs easy.

    Changes that I recall
    • Auto size adjustment for drives.
    • Archiving "now playing" lists.
    • Sorting of summery table.
    • Added field deleted to summery table (space not used by programs or suggestions).
    • Combined now playing for all DVR's.
    • URL path allowing generation when HTML files are not published on local computer some guru probably can find a better solution to this.
    • Other changes that I have forgot about.
      - I added something to the program information like series ID.
      - Toggle all button.

    Almost live webpage with the modifications See HomeUser's Now Playing List

    Notes:
    • The archive history is saved only when the program is run during the first 15 minutes of each hour it may take an hour before the history pages are generated.
    • For sorting the tables I used sortable.js table code from http://www.kryogenix.org/code/browser/sorttable/
    • My updated files attached. I moved all the js and php files except index.php to a bin directory and made lots of changes to tivo_settings.php and will not %100 compatible with the previous tivo_settings.php.
     

    Attached Files:

Share This Page