Advertisement
Guest User

Untitled

a guest
Apr 6th, 2012
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*****************************************************************************************\
  2. |                           This GetTVscript is written by kael                           |
  3. |                                    modified by Hölger                                   |
  4. | V.2   - expanded by Droideka                                                            |
  5. | V.2.1 - modified by Rimion                                                              |
  6. |         omtv.se made some minor changes on the site.                                    |
  7. | V.2.2 - modified by Rimion (080917)                                                     |
  8. |         omtv.se har gjort om sin sida.                                                  |
  9. |         La till funktionerna GetTV(channel, ahead) och GetBar(channel). I Samurize      |
  10. |         Config Editor kan du nu med hjälp av parametrar ange vilken kanal som ska       |
  11. |         användas (ex. SVT1, TV8, TV3, SVT_HD) och vilket program som ska visas.         |
  12. |         0 = det som sänds nu, 1 = nästa program, 2 =...                                 |
  13. | V.2.3 - modified by Whiskey (20120406)                                                  |
  14. |         1: Fixat så åäö funkar, vet inte om de är korrekt sätt men funkar iaf           |
  15. |         2: Ser ut som omtv.se gjort om sin sida igen lagt till så den parsar rätt men   |
  16. |     program som har <h5 class="icon movie">Title</h5> och inte bara <h5>Title</h5>      |
  17. |         3: Find out that showTime / timeDelimiter / timeProgressSeparator is broken     |
  18. \*****************************************************************************************/
  19. var showTime = true                     ;// Option to show the time in the output (true or false)
  20. var timeDelimiter = ":"                 ;// Option what to separate hours and minutes with(":" "." or what you want)
  21. var timeProgramSeparator = " "          ;// Option what to separate time and program with
  22. var noProgramYet = "Inget program"      ;// The text showing when there are no program yet
  23. var noProgramNow = "Sändningsuppehåll"  ;// The text showing when there are no program right now
  24. var noProgramEnd = "Sändningsslut"      ;// The text showing when there are no program any more
  25.  
  26. /*
  27. To add your other channels just copy one of the sets of channels and change the function name to something unique and change the string-parameter to the apropriate name...
  28. It has to be the right link name, you can check the link name by hovering over the channel icon at: http://www.omtv.se/kanaler/
  29.  
  30. example:
  31. to add "Canal+ Sport" you would notice the end of the link to be "Canal+_Sport"
  32. http://www.omtv.se/tabla/Canal+_Sport/
  33. so the fuction would look like this:
  34. function GetCanalPlusSport() { return GetTV_("Canal+_Sport", 0); }
  35. */
  36.  
  37. function GetTV(channel, ahead) {return GetTV_(channel, parseInt(ahead)); }
  38. function GetBar(channel) {return GetBar_(channel); }
  39.  
  40. function GetSVT1() { return GetTV_("SVT1", 0); }
  41. function GetBarSVT1() { return GetBar_("SVT1"); }
  42. function GetNextSVT1() { return GetTV_("SVT1", 1); }
  43.  
  44. function GetSVT2() { return GetTV_("SVT2", 0); }
  45. function GetBarSVT2() { return GetBar_("SVT2"); }
  46. function GetNextSVT2() { return GetTV_("SVT2", 1); }
  47.  
  48. function GetTV3() { return GetTV_("TV3", 0); }
  49. function GetBarTV3() { return GetBar_("TV3"); }
  50. function GetNextTV3() { return GetTV_("TV3", 1); }
  51.  
  52. function GetTV4() { return GetTV_("TV4", 0); }
  53. function GetBarTV4() { return GetBar_("TV4"); }
  54. function GetNextTV4() { return GetTV_("TV4", 1); }
  55.  
  56. function GetKanal5() { return GetTV_("Kanal_5", 0); }
  57. function GetBarKanal5() { return GetBar_("Kanal_5"); }
  58. function GetNextKanal5() { return GetTV_("Kanal_5", 1); }
  59.  
  60. function Get6an() { return GetTV_("TV6", 0); }
  61. function GetBar6an() { return GetBar_("TV6"); }
  62. function GetNext6an() { return GetTV_("TV6", 1); }
  63.  
  64. function GetSjuan() { return GetTV_("Sjuan", 0); }
  65. function GetBarSjuan() { return GetBar_("Sjuan"); }
  66. function GetNextSjuan() { return GetTV_("Sjuan", 1); }
  67.  
  68. function GetDiscovery_Channel() { return GetTV_("Discovery_Channel", 0); }
  69. function GetBarDiscovery_Channel() { return GetBar_("Discovery_Channel"); }
  70. function GetNextDiscovery_Channel() { return GetTV_("Discovery_Channel", 1); }
  71.  
  72. function GetTV_(channel, count)
  73. {
  74.     var txt = GetPage_(channel);
  75.    
  76.     if(txt.substr(0,5)=="Error") return txt;
  77.    
  78.     try
  79.     {
  80.         var now = -1;
  81.         var offset = -2;
  82.         var lines = txt.split("\r\n");
  83.        
  84.         // Check if the last program = noProgramEnd
  85.         // omtv.se sometimes repeats the next day first program as the current day last progam
  86.         // we then have to set the offset to -3 to skip the last program in the saved file
  87.         if (lines[lines.length-2].indexOf(noProgramEnd) < 0) offset = -3;
  88.        
  89.         for(var i=lines.length+offset;i>=0;i--)
  90.         {
  91.             var time = lines[i].substring(0,5);
  92.            
  93.             _time = new Date();
  94.  
  95.             if((parseInt(time.substring(0,1))*10 + parseInt(time.substring(1,2)))<6) _time.setHours(parseInt(time.substring(0,1))*10 + parseInt(time.substring(1,2))+18,parseInt(time.substring(3,4))*10 + parseInt(time.substring(4,5)),0,0);
  96.             else _time.setHours(parseInt(time.substring(0,1))*10 + parseInt(time.substring(1,2))-6,parseInt(time.substring(3,4))*10 + parseInt(time.substring(4,5)),0,0);
  97.            
  98.             _now = new Date();
  99.             if(_now.getHours()<6) _now.setHours(_now.getHours()+18);
  100.             else _now.setHours(_now.getHours()-6);
  101.  
  102.             if(_time<_now)
  103.             {
  104.                 now = i;
  105.                 break;
  106.             }
  107.         }
  108.  
  109.         if((now+count>=0) && (now+count<=lines.length-2))
  110.             return convertUTF8_(lines[now+count]);
  111.         else
  112.             return noProgramYet;
  113.     }
  114.     catch(e)
  115.     {
  116.         return "Error parsing file";
  117.     }
  118. }
  119.  
  120. function GetBar_(channel)
  121. {
  122.     var txt = GetPage_(channel);
  123.     if(txt.substr(0,5)=="Error") return txt;
  124.  
  125.     try
  126.     {
  127.  
  128.         var now = -1;
  129.         var lines = txt.split("\r\n");
  130.         var offset = -2;
  131.        
  132.         // Check if the last program = noProgramEnd
  133.         // omtv.se somtimes repeats the next day first program as the current day last progam
  134.         // we then have to set the offset to -3 to skip the last program in the saved file
  135.         if (lines[lines.length-2].indexOf(noProgramEnd) < 0) offset = -3;
  136.        
  137.         for(var i=lines.length+offset;i>=0;i--)
  138.         {
  139.             var time = lines[i].substring(0,5);
  140.             _time = new Date();
  141.  
  142.             if((parseInt(time.substring(0,1))*10 + parseInt(time.substring(1,2)))<6) _time.setHours(parseInt(time.substring(0,1))*10 + parseInt(time.substring(1,2))+18,parseInt(time.substring(3,4))*10 + parseInt(time.substring(4,5)),0,0);
  143.             else _time.setHours(parseInt(time.substring(0,1))*10 + parseInt(time.substring(1,2))-6,parseInt(time.substring(3,4))*10 + parseInt(time.substring(4,5)),0,0);
  144.  
  145.             _now = new Date();
  146.             if(_now.getHours()<6) _now.setHours(_now.getHours()+18);
  147.             else _now.setHours(_now.getHours()-6);
  148.  
  149.             if(_time<_now)
  150.             {
  151.                 now = i;
  152.                 break;
  153.             }
  154.         }
  155.  
  156.         if(now<0 || now>=(lines.length-2))
  157.             return 0;
  158.  
  159.         var time1 = lines[now].substring(0,5);
  160.         var time1h = time1.substring(0,2);
  161.         var time1m = time1.substring(3,5);
  162.         var time2 = lines[now+1].substring(0,5);
  163.         var time2h = time2.substring(0,2);
  164.         var time2m = time2.substring(3,5);
  165.         if(time1h<6) time1h=time1h*1+18; else time1h-=6;
  166.         if(time2h<6) time2h=time2h*1+18; else time2h-=6;
  167.  
  168.        
  169.         var totalmins = (time2h-time1h)*60+(time2m-time1m);
  170.         var runningminutes = (_now.getHours()-time1h)*60+(_now.getMinutes()-time1m);
  171.         return runningminutes/totalmins*100;
  172.     }
  173.     catch(e)
  174.     {
  175.         return "Error parsing file";
  176.     }
  177. }
  178.  
  179. function GetPage_(channel)
  180. {
  181.     try
  182.     {
  183.         var fs = new ActiveXObject("Scripting.FileSystemObject");
  184.         try{var ADODBS=new ActiveXObject("ADODB.Stream");}catch(er){var ADODBS=false;}
  185.        
  186.         try
  187.         {
  188.             var file=fs.GetSpecialFolder(2)+"\\"+channel+".tv";
  189.            
  190.             if(fs.FileExists(file))
  191.             {
  192.                 var f=fs.GetFile(file);
  193.                 var filetime = new Date(f.DateLastModified);
  194.                 var now = new Date();
  195.                 var timeToDownload = new Date();
  196.                 timeToDownload.setHours(6,15,0);
  197.                 if(timeToDownload>now || filetime>timeToDownload)
  198.                 {
  199.                         var filen = f.OpenAsTextStream(1);
  200.                         var txt = filen.ReadAll();
  201.                         filen.Close();
  202.                         return txt;
  203.                 }
  204.             }
  205.         }
  206.         catch(e)
  207.         {
  208.             return "Error reading from file";
  209.         }
  210.         finally
  211.         {
  212.             delete filetime;
  213.             delete now;
  214.             delete timeToDownload;
  215.         }
  216.    
  217.         try
  218.         {
  219.             var adress = "http://www.omtv.se/tabla/"+channel+"/";
  220.            
  221.             var http = new ActiveXObject("Microsoft.XMLHTTP");
  222.             http.Open("GET",adress ,false);
  223.             http.send();
  224.             var html = "Error";
  225.             if (http.Status==200)
  226.             {
  227.                 if(ADODBS){
  228.                     try{
  229.                         ADODBS.Open();
  230.                         ADODBS.Type=1;    // Binary
  231.                         ADODBS.Write(http.responseBody);  // Write the response as a byte stream.
  232.                         ADODBS.Position=0;   // Move back to the start of the stream to be able to change type and charset.
  233.                         ADODBS.Type=2;  // Text
  234.                         ADODBS.Charset="ISO-8859-1"; // Default to Latin 1 Western, West European.
  235.                         html=ADODBS.ReadText();
  236.                         ADODBS.Close();
  237.                     }
  238.                     catch(er){
  239.                         html=http.responseText;  // Something failed, default back to responseText, UTF-8 is forced.
  240.                     }
  241.                 }
  242.             }
  243.             html = fixHTMLcodes_(html);
  244.         }
  245.         catch(e)
  246.         {
  247.             return "Error downloading page";
  248.         }
  249.         finally
  250.         {
  251.             delete http;
  252.         }
  253.    
  254.         try
  255.         {
  256.             html = between(html, "<tbody>", "</tbody>");
  257.            
  258.             var txt="";
  259.             var lines = html.split("</tr>");
  260.             var endtime="";
  261.  
  262.             // Had to change to 'lines.length-1' for some reason
  263.             for(var i=0;i<lines.length-1;i++)
  264.             {
  265.                 var time = lines[i].substr(lines[i].indexOf("</td>")-5,5);
  266.                 var program = between(lines[i], "<h5>", "</h5>");
  267.                 var desc = between(lines[i], "<p>", "<");
  268.                
  269.                     if(program.indexOf("\r\n")!=-1)
  270.                     program = program.substr(0,program.indexOf("\r\n"));
  271.                
  272.                 if(endtime!="")
  273.                 {
  274.                     var _endtime = new Date();
  275.                     _endtime.setHours(parseInt(endtime.substring(0,1))*10 + parseInt(endtime.substring(1,2)),parseInt(endtime.substring(3,4))*10 + parseInt(endtime.substring(4,5)),0,0);
  276.                     var _time = new Date();
  277.                     _time.setHours(parseInt(time.substring(0,1))*10 + parseInt(time.substring(1,2)),parseInt(time.substring(3,4))*10 + parseInt(time.substring(4,5)),0,0);
  278.                     if(_endtime<_time)
  279.                     {
  280.                         if(showTime)
  281.                             txt+=endtime.substring(0,2)+timeDelimiter+endtime.substring(3,5)+timeProgramSeparator;
  282.                         txt+=noProgramNow+"\r\n";
  283.                     }
  284.                 }
  285.                
  286.                 endtime = lines[i].substr(lines[i].indexOf("(")+9,5);
  287.                
  288.                 if(endtime.substr(2,1)!=".")
  289.                     endtime = "";
  290.                
  291.                 if(showTime)
  292.                     txt+=time.substring(0,2)+timeDelimiter+time.substring(3,5)+timeProgramSeparator;
  293.                 //added
  294.                 txt+=program+"%tt"+desc+"\r\n";
  295.                 //added
  296.             }
  297.            
  298.             if(endtime!="")
  299.             {
  300.                
  301.                 var _endtime = new Date();
  302.                
  303.                 _endtime.setHours(parseInt(endtime.substring(0,1))*10 + parseInt(endtime.substring(1,2)),parseInt(endtime.substring(3,4))*10 + parseInt(endtime.substring(4,5)),0,0);
  304.                 var _time = new Date();
  305.                 _time.setHours(5,59,0);
  306.                 if(_endtime<_time)
  307.                 {
  308.                     if(showTime)
  309.                         txt+=endtime.substring(0,2)+timeDelimiter+endtime.substring(3,5)+timeProgramSeparator;
  310.                     txt+=noProgramEnd+"\r\n";
  311.                 }
  312.             }
  313.         }
  314.         catch(e)
  315.         {
  316.             return "Error parsing page";
  317.         }
  318.        
  319.         try
  320.         {
  321.             var file=fs.CreateTextFile(file,true);
  322.             file.Write(txt);
  323.         }  
  324.         catch(e)
  325.         {
  326.             return "Error writing to file";
  327.         }
  328.         finally
  329.         {
  330.             file.Close();
  331.         }
  332.     }
  333.     catch(e)
  334.     {
  335.         return "Error creating FileSystemObject";
  336.     }
  337.     finally
  338.     {
  339.         delete fs;
  340.     }
  341.     return txt;
  342.  
  343. }
  344.  
  345. function between(str, start, stop)
  346. {
  347.     str = str.substr(str.indexOf(start)+start.length);
  348.     str = str.substr(0,str.indexOf(stop));
  349.     return str;
  350. }
  351.  
  352. function convertUTF8_(string){
  353.     var convertedString="";
  354.     try{
  355.         var Stream = new ActiveXObject("ADODB.Stream");
  356.         Stream.Open();
  357.         Stream.Type = 2; // Text
  358.         Stream.Charset="ISO-8859-1";
  359.         Stream.WriteText(string);
  360.         Stream.Position=0;
  361.         Stream.Charset="UTF-8";
  362.         convertedString = Stream.ReadText(string.length);
  363.         Stream.Close();
  364.     }
  365.     catch(er)
  366.     {
  367.         convertedString = string;
  368.     }
  369.     return convertedString;
  370. }
  371.  
  372. function fixHTMLcodes_(str)
  373. {
  374.     str = str.replace(/&aring;/g, "å");
  375.     str = str.replace(/&auml;/g, "ä");
  376.     str = str.replace(/&ouml;/g, "ö");
  377.     str = str.replace(/&Aring;/g, "Å");
  378.     str = str.replace(/&Auml;/g, "Ä");
  379.     str = str.replace(/&Ouml;/g, "Ö");
  380.     str = str.replace(/&amp;/g, "&");
  381.     str = str.replace(/&quot;/g, "\"");
  382.     str = str.replace(/&#130;/g, ",");
  383.     str = str.replace(/&#131;/g, "f");
  384. //  str = str.replace(/&#132;/g, """);
  385.     str = str.replace(/&#133;/g, ".");
  386.     str = str.replace(/&#134;/g, "?");
  387.     str = str.replace(/&#135;/g, "?");
  388.     str = str.replace(/&#136;/g, "^");
  389.     str = str.replace(/&#137;/g, "?");
  390.     str = str.replace(/&#138;/g, "S");
  391.     str = str.replace(/&#139;/g, "<");
  392.     str = str.replace(/&#140;/g, "O");
  393.     str = str.replace(/&#145;/g, "'");
  394.     str = str.replace(/&#146;/g, "'");
  395. //  str = str.replace(/&#147;/g, """);
  396. //  str = str.replace(/&#148;/g, """);
  397.     str = str.replace(/&#149;/g, ".");
  398.     str = str.replace(/&#150;/g, "-");
  399.     str = str.replace(/&#151;/g, "-");
  400.     str = str.replace(/&#152;/g, "~");
  401.     str = str.replace(/&#153;/g, "T");
  402.     str = str.replace(/&#154;/g, "s");
  403.     str = str.replace(/&#155;/g, ">");
  404.     str = str.replace(/&#156;/g, "o");
  405.     str = str.replace(/&#159;/g, "Y");
  406.     str = str.replace(/&#160;/g, " ");
  407.     str = str.replace(/&#161;/g, "¡");
  408.     str = str.replace(/&#162;/g, "¢");
  409.     str = str.replace(/&#163;/g, "£");
  410.     str = str.replace(/&#164;/g, "¤");
  411.     str = str.replace(/&#165;/g, "¥");
  412.     str = str.replace(/&#166;/g, "¦");
  413.     str = str.replace(/&#167;/g, "§");
  414.     str = str.replace(/&#168;/g, "¨");
  415.     str = str.replace(/&#169;/g, "©");
  416.     str = str.replace(/&#170;/g, "ª");
  417.     str = str.replace(/&#171;/g, "«");
  418.     str = str.replace(/&#172;/g, "¬");
  419.     str = str.replace(/&#173;/g, "­");
  420.     str = str.replace(/&#174;/g, "®");
  421.     str = str.replace(/&#175;/g, "¯");
  422.     str = str.replace(/&#176;/g, "°");
  423.     str = str.replace(/&#177;/g, "±");
  424.     str = str.replace(/&#178;/g, "²");
  425.     str = str.replace(/&#179;/g, "³");
  426.     str = str.replace(/&#180;/g, "´");
  427.     str = str.replace(/&#181;/g, "µ");
  428.     str = str.replace(/&#182;/g, "¶");
  429.     str = str.replace(/&#183;/g, "·");
  430.     str = str.replace(/&#184;/g, "¸");
  431.     str = str.replace(/&#185;/g, "¹");
  432.     str = str.replace(/&#186;/g, "º");
  433.     str = str.replace(/&#187;/g, "»");
  434.     str = str.replace(/&#188;/g, "¼");
  435.     str = str.replace(/&#189;/g, "½");
  436.     str = str.replace(/&#190;/g, "¾");
  437.     str = str.replace(/&#191;/g, "¿");
  438.     str = str.replace(/&#192;/g, "À");
  439.     str = str.replace(/&#193;/g, "Á");
  440.     str = str.replace(/&#194;/g, "Â");
  441.     str = str.replace(/&#195;/g, "Ã");
  442.     str = str.replace(/&#196;/g, "Ä");
  443.     str = str.replace(/&#197;/g, "Å");
  444.     str = str.replace(/&#198;/g, "Æ");
  445.     str = str.replace(/&#199;/g, "Ç");
  446.     str = str.replace(/&#200;/g, "È");
  447.     str = str.replace(/&#201;/g, "É");
  448.     str = str.replace(/&#202;/g, "Ê");
  449.     str = str.replace(/&#203;/g, "Ë");
  450.     str = str.replace(/&#204;/g, "Ì");
  451.     str = str.replace(/&#205;/g, "Í");
  452.     str = str.replace(/&#206;/g, "Î");
  453.     str = str.replace(/&#207;/g, "Ï");
  454.     str = str.replace(/&#208;/g, "Ð");
  455.     str = str.replace(/&#209;/g, "Ñ");
  456.     str = str.replace(/&#210;/g, "Ò");
  457.     str = str.replace(/&#211;/g, "Ó");
  458.     str = str.replace(/&#212;/g, "Ô");
  459.     str = str.replace(/&#213;/g, "Õ");
  460.     str = str.replace(/&#214;/g, "Ö");
  461.     str = str.replace(/&#215;/g, "×");
  462.     str = str.replace(/&#216;/g, "Ø");
  463.     str = str.replace(/&#217;/g, "Ù");
  464.     str = str.replace(/&#218;/g, "Ú");
  465.     str = str.replace(/&#219;/g, "Û");
  466.     str = str.replace(/&#220;/g, "Ü");
  467.     str = str.replace(/&#221;/g, "Ý");
  468.     str = str.replace(/&#222;/g, "Þ");
  469.     str = str.replace(/&#223;/g, "ß");
  470.     str = str.replace(/&#224;/g, "à");
  471.     str = str.replace(/&#225;/g, "á");
  472.     str = str.replace(/&#226;/g, "â");
  473.     str = str.replace(/&#227;/g, "ã");
  474.     str = str.replace(/&#228;/g, "ä");
  475.     str = str.replace(/&#229;/g, "å");
  476.     str = str.replace(/&#230;/g, "æ");
  477.     str = str.replace(/&#231;/g, "ç");
  478.     str = str.replace(/&#232;/g, "è");
  479.     str = str.replace(/&#233;/g, "é");
  480.     str = str.replace(/&#234;/g, "ê");
  481.     str = str.replace(/&#235;/g, "ë");
  482.     str = str.replace(/&#236;/g, "ì");
  483.     str = str.replace(/&#237;/g, "í");
  484.     str = str.replace(/&#238;/g, "î");
  485.     str = str.replace(/&#239;/g, "ï");
  486.     str = str.replace(/&#240;/g, "ð");
  487.     str = str.replace(/&#241;/g, "ñ");
  488.     str = str.replace(/&#242;/g, "ò");
  489.     str = str.replace(/&#243;/g, "ó");
  490.     str = str.replace(/&#244;/g, "ô");
  491.     str = str.replace(/&#245;/g, "õ");
  492.     str = str.replace(/&#246;/g, "ö");
  493.     str = str.replace(/&#247;/g, "÷");
  494.     str = str.replace(/&#248;/g, "ø");
  495.     str = str.replace(/&#249;/g, "ù");
  496.     str = str.replace(/&#250;/g, "ú");
  497.     str = str.replace(/&#251;/g, "û");
  498.     str = str.replace(/&#252;/g, "ü");
  499.     str = str.replace(/&#253;/g, "ý");
  500.     str = str.replace(/&#254;/g, "þ");
  501.     str = str.replace(/&#255;/g, "ÿ");
  502.  
  503.     return str;
  504. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement