A better /nowplaying/index.html

Discussion in 'TiVo Home Media Features & TiVoToGo' started by gman622, Mar 28, 2005.

  1. Apr 2, 2005 #21 of 168
    Kriston

    Kriston New Member

    6
    0
    Feb 10, 2005
    Just wanted to let you know.

    It does NOT work in konqueror.

    Loaded FireFox and it worked fine.

    Would NEVER try Internet Extorter, so I would not know about it.
     
  2. Apr 2, 2005 #22 of 168
    AnteL0pe

    AnteL0pe the anti-haX0r

    373
    0
    Oct 1, 2004
    Washington...
    Thats odd, it works fine in Safari.
     
  3. Apr 2, 2005 #23 of 168
    Kriston

    Kriston New Member

    6
    0
    Feb 10, 2005
    It is odd. I guess that it might be some of the new security features. When (if) I get some time I will dig a little deeper into it. I am running SuSE 9.2 on AMD 64 Athlon 3000+. It might be a 64 bit issue.
     
  4. Apr 2, 2005 #24 of 168
    AnteL0pe

    AnteL0pe the anti-haX0r

    373
    0
    Oct 1, 2004
    Washington...
    I'll try it from a linux box as well...
     
  5. Apr 2, 2005 #25 of 168
    jhhyde

    jhhyde Member

    69
    11
    Dec 31, 2001
    Sammamish, WA
    When I tried this in Firefox nothing happened.

    The JavaScript Console says line 7 has a syntax error.

    That would be the line that has this:

    <![CDATA[

    I'm not a Java guy, can anyone tell me what is going on, I just downloaded this and made my tivo ip and mak changes. I also downloaded another copy just to make sure I didn't change line 7.
     
  6. Apr 3, 2005 #26 of 168
    Kriston

    Kriston New Member

    6
    0
    Feb 10, 2005
    I just tried the 32 bit version (on a different computer). Same thing. I get the skeleton of the format, but no data is filled in. Mozilla and FireFox both work properly.

    Konqueror never displays certificate or cookie info dialog like the others. It may be rejecting something before I see it.
     
  7. Apr 3, 2005 #27 of 168
    Kriston

    Kriston New Member

    6
    0
    Feb 10, 2005
    I just enabled javascript debug and error checking. I gate a Parse Error at line 8.
    This is the line that sets the tivo_ip variable.

    Still investigating.
     
  8. Apr 3, 2005 #28 of 168
    morac

    morac Cat God

    12,398
    1,212
    Mar 14, 2003
    NJ
    This is very cool, but it suffers from the same bug that every other program that grabs all the shows at once from a TiVo does.

    The TiVo will only return a maximum of 128 shows at one time. This means that your script will only show a maximum of (that's right) 128 shows. My TiVo contains 202 shows so the last 74 aren't picked up.

    A simple fix for this is to grab a lower number of shows at once using the "AnchorOffset" and "ItemCount" parameters. For example by adding the following to the end of the URL it will grab 50 shows starting at index 100: "&ItemCount=50&AnchorOffest=100". If the number of shows left is less that the amount listed in ItemCount, than only the number of shows left will be returned. If the AnchorOffset is greater than the total number of shows, than no shows will be returned (the ItemCount XML variable will be 0).

    I'm not sure exactly how this could be done easily in your code since it requires making multiple requests to the TiVo and parsing out the data for each request and your code doesn't look like it was designed to do this.


    Also you do a blocking call which means the browser can't be used while the show listing is being downloaded. I once wrote a script to parse through a number of web pages using XMLHttpRequest and there is a way to write it so it does so in the background. Set the third parameter in the open() call to true and use the "onreadystatechange" variable to have it call a function when the server response comes in.
     
  9. Apr 4, 2005 #29 of 168
    gman622

    gman622 New Member

    111
    0
    Feb 17, 2005
    I've updated this so that the shows are now sortable.
    By clicking on the table header titles you can sort by:
    SourceStation, Title, CaptureDate, SourceSize, and Recording Quality.

    You can still get it at:
    http://home.ripway.com/2005-2/266393/nowPlaying.xhtml

    *still only guaranteed to work with FireFox
     
  10. Apr 4, 2005 #30 of 168
    jhhyde

    jhhyde Member

    69
    11
    Dec 31, 2001
    Sammamish, WA
    All fine and very good, but can anyone explain why I get syntax error on line 7 when I try it in Firefox?

    That would be the line that has this:

    <![CDATA[

    So far, the Firefox guarantee is not valid.
     
  11. Apr 4, 2005 #31 of 168
    morac

    morac Cat God

    12,398
    1,212
    Mar 14, 2003
    NJ
    You should be able to use Sarissa to make it compatible with Internet Explorer. Sarissa is a bunch of javascripts that emulate Mozilla's XSLT functions for IE.
     
  12. Apr 7, 2005 #32 of 168
    GCymbala

    GCymbala New Member

    25
    0
    Jan 22, 2005
    Hope you don't mind ... I made some changes to a copy of your "better now playing list" for my own needs. I've got two TiVos, and I didn't want to maintain two copies of the file, so I added a <select> with the my list of TiVos. Also removed some spaces between the quotes around EpisodeTitles -- they just bugged me. I also defaulted to sorting by Title, by adding
    Code:
    <xsl:sort select="t:Details/t:Title"/>
    to the for-each Item loop.

    You can see it at: cymbala[dot]com/Greg/nowPlaying.zip

    I appreciate the work you've put into this -- would have taken me too long to ever get around to doing it myself

    -Greg

     
  13. Apr 8, 2005 #33 of 168
    gman622

    gman622 New Member

    111
    0
    Feb 17, 2005
    I don't mind at all; sorry to inflict my code upon you. This was my first foray into xsl (and CSS and Javascript and XHTML for that matter) and it definitely turned into "the 'hack-iest' thing that could possibly work."

    that a good idea; although it might be better for me to generalize it (maybe an array of IP's) so that any number of tivo's will work.

    that brings up a bug that I should fix, currently when you sort by title it doesn't take into account ones that start with "The" or "A" (are there others that i'm forgetting?). I don't think that can work with xsl:sort but it's an easy fix in the sortTable function.

    There's also a couple of enhancements I was thinking of making including a SVG Pie Chart and making it possible to sort by Expiration Date. If anyone has any suggestions feel free to chime in.

    One problem I am having is trying to make an async xml request. It seems to retrieve the xml document ok but choke with an uncaught exception when I try to transform it. If anyone can help:
    Code:
            var xsltProcessor = new XSLTProcessor();
            var xmlDoc;
            xsltProcessor.importStylesheet(xsltSheet);
            var myXMLHTTPRequest = new XMLHttpRequest();
            netscape.security.PrivilegeManager.enablePrivilege('UniversalBrowserRead');
            myXMLHTTPRequest.open("GET", 'np.xml', true,'tivo',mak);
    
            myXMLHTTPRequest.onreadystatechange=function() {
                if (myXMLHTTPRequest.readyState==4) {
                    xmlDoc = myXMLHTTPRequest.responseXML;
               }
            }
    
            myXMLHTTPRequest.send(null);
            var fragment = xsltProcessor.transformToFragment(xmlDoc, document);
    
     
  14. Apr 9, 2005 #34 of 168
    GCymbala

    GCymbala New Member

    25
    0
    Jan 22, 2005
    Sheesh! Hold on ... one more post and maybe I'll stop getting all these stupid "Your Post contains one or more URL..." messages...
     
  15. Apr 9, 2005 #35 of 168
    GCymbala

    GCymbala New Member

    25
    0
    Jan 22, 2005
    Yep, I was thinking the same thing, but being lazy, couldn't be bothered to write a function to create the <select> list dynamically from an array. Plus, I wanted to use their names, not just IP addresses, so it'd have to be a 2-dimensional array, which is a little ugly in JavaScript.

    I realized this too, but it didn't bother me too much.

    Sounds cool. The only SVG I've ever touched, though was inside Paint Shop Pro, and glancing at the source once or twice.

    I tried to get this working, but had trouble too. I ended up making the myXMLHTTPRequest in global scope. That seemed to solve something, but created others because the code continued to try to parse the response after the send. I ended up having to move a bunch of code into the onreadystate function, since that's where you need to fire things from.

    At the top, right after
    Code:
    var totalGB = 29.252;
    
    I've got:

    Code:
    var xsltSheet = document.getElementsByTagNameNS('[XSL Namespace]', 'stylesheet')[1];
    var myXMLHTTPRequest = new XMLHttpRequest();
    
    function CheckXMLHTTPReadyState() {
    	if (myXMLHTTPRequest.readyState==4) {
    
    		netscape.security.PrivilegeManager.enablePrivilege('UniversalBrowserRead');
    		var xsltNS = '[XSL Namespace]';
    		var xsltSheet = document.getElementsByTagNameNS(xsltNS, 'stylesheet')[0];
    
    		var xsltProcessor = new XSLTProcessor();
    		xsltProcessor.importStylesheet(xsltSheet);
    		var xmlDoc;
    		xmlDoc = myXMLHTTPRequest.responseXML;
    		var fragment = xsltProcessor.transformToFragment(xmlDoc, document);
    		document.getElementById("divContent").appendChild(fragment);
    		convertDates();
    		calcTimeLeft();
    	}
    }
    And in the appendTransformation I've got this:

    Code:
    netscape.security.PrivilegeManager.enablePrivilege('UniversalBrowserRead');
    		myXMLHTTPRequest = new XMLHttpRequest();
    		myXMLHTTPRequest.onreadystatechange=CheckXMLHTTPReadyState;
            
    		myXMLHTTPRequest.open("GET", '[now playing url]', true,'tivo',mak);
            
    
    		myXMLHTTPRequest.send(null);
    
    I don't know if I need all those enablePrivilege's, but I'm not familiar with what they do and it didn't work unless I put 'em in there.
     
  16. Apr 9, 2005 #36 of 168
    morac

    morac Cat God

    12,398
    1,212
    Mar 14, 2003
    NJ
    I was getting the same error with my version. Based on your code I put the following line in my reponse handling routine and all the sudden it worked.
    I was under the wrong impression that you only need to enable UniversalBrowserRead once per page, but according to the documentation, you need to call it per function.

    Anyway, the code I have is a bit more simplistic (it only uses one global variable). I broke out the sending and handling of the request because I want to be able to send multiple requests to the TiVo in case it doesn't download all the listings on the first request. I also threw in some try, catch code to give the user some feedback in case of error. In addition I put a check in to see if the page returned from the TiVo is valid before trying to parse it.

    Code:
    var myXMLHTTPRequest;
    
    function sendRequest() {
        try {
           myXMLHTTPRequest = new XMLHttpRequest();
           netscape.security.PrivilegeManager.enablePrivilege('UniversalBrowserRead');
           myXMLHTTPRequest.onreadystatechange = handleResponse;
           myXMLHTTPRequest.open("GET", 'https://'+tivo_ip+
                  '/TiVoConnect?Command=QueryContainer&Container=%2FNowPlaying&Recurse=Yes'
                  , true,'tivo',mak);
           myXMLHTTPRequest.send(null);
        }
        catch (e) { 
           alert("Error occurred sending request: " + e);
        }
    }
    
    function handleResponse()
    {
        try {
          // if finished fetching page and no errors occurred
          if ((myXMLHTTPRequest.readyState == 4) && 
              (myXMLHTTPRequest.status < 300) && 
              (myXMLHTTPRequest.responseText!="")) {
             netscape.security.PrivilegeManager.enablePrivilege('UniversalBrowserRead');
             var xsltNS = 'http://www.w3.org/1999/XSL/Transform';
             var xsltSheet = document.getElementsByTagNameNS(xsltNS, 'stylesheet')[0];
             appendTransformation(xsltSheet);
             convertDates();
             calcTimeLeft();
          }
        }
        catch (e) { 
           alert("Error occurred handling response: " + e);
        }
    }
    
    function appendTransformation (xsltSheet) {
        var divContent = document.getElementById("divContent");
        var oForm = document.getElementById("frmSelTiVo");
        while (divContent.hasChildNodes())
    	{
    		divContent.removeChild(divContent.childNodes[0]);
    	}
        if (typeof XSLTProcessor != 'undefined') {
            var xsltProcessor = new XSLTProcessor();
            xsltProcessor.importStylesheet(xsltSheet);
            var xmlDoc = myXMLHTTPRequest.responseXML;
            var fragment = xsltProcessor.transformToFragment(xmlDoc, document);
            document.getElementById("divContent").appendChild(fragment);
        }
    }
    
    window.onload = initPage;
    function initPage()
    {
    	var tivo_list = document.getElementById("selTiVos");
    	tivo_ip = tivo_list.options[tivo_list.selectedIndex].value;
    	sendRequest();
    }
    
     
  17. Apr 9, 2005 #37 of 168
    morac

    morac Cat God

    12,398
    1,212
    Mar 14, 2003
    NJ
    I threw something together which will download all the shows on the TiVo with multiple requests. Unfortunately there are a number of bugs that don't look very easy to fix, but perhaps someone familiar with XSLT might be able to.

    Depending on how I coded either:

    1. All the shows are broken out into multiple tables (one for each tivo request)

    Or all the shows are shown in the same table, but:

    1. The Now Playing header at the top lists the the wrong info data (only shows as of the first request)
    2. If a suggestion is being recorded the table gets screwed up
    3. Suggestions aren't put into the tab correctly.


    I want to try to download all the data and combine it into one big XML file before it is translated, but I don't know if that is possible and since each table will contain the TiVo Detail tag I'm not sure it will work anyway.

    If you want to see the code as it is currently (the part that makes multiple request), you can grab it at:

    removed - see post below for final version

    The zip file contains each method.
     
  18. Apr 9, 2005 #38 of 168
    morac

    morac Cat God

    12,398
    1,212
    Mar 14, 2003
    NJ
    Okay, I got it working. You can grab it from:

    http://anonymous123.home.comcast.net/nowPlaying.xhtml

    Just change the MAK and IP and you're all set.

    There is an option to change how many shows will be grabbed per request. The lower the number the less shows grabbed at once, but the more often the page is updated. The higher the number the less often the page is updated. The total amount of time it takes shouldn't differ that much whatever the number is.

    Edit: I made one minor update because the code I had was filling in the combined XML table from the last show to the first. Now the XML table will be filled in order.

    By the way, even though I did not do so, it might be a good idea to remove the automatic title sorting that was added with the line
    Code:
    <xsl:sort select="t:Details/t:Title"/>
    (delete the line) because it slows down the rebuilding of the list as each new response comes in.
     
  19. Apr 10, 2005 #39 of 168
    gman622

    gman622 New Member

    111
    0
    Feb 17, 2005
    another update.....

    1. another (sortable) column was added: Expires. now you can see which show will be deleted first, second, third and so on. (finally a use for the keep until date!)

    2. multiple tivos are supported (though i'm not sure how well... i only have one)

    3. requests are asynchronous, so the browser will not hang on lengthy GETs
    (the tab/title will let you know when it's done loading)

    4. now recording info will tell you if it's a planned or suggested recording.

    here 'tis:
    http://home.ripway.com/2005-2/266393/nowPlaying.xhtml
     
  20. Apr 10, 2005 #40 of 168
    smithrl

    smithrl Member

    96
    0
    Sep 23, 2002
    Ann Arbor, MI

    I get the exact same error with Firefox - both with the original script and with Morac's version
     

Share This Page