Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*****************************************************************************************\
- | This GetTVscript is written by kael |
- | modified by Hölger |
- | V.2 - expanded by Droideka |
- | V.2.1 - modified by Rimion |
- | omtv.se made some minor changes on the site. |
- | V.2.2 - modified by Rimion (080917) |
- | omtv.se har gjort om sin sida. |
- | La till funktionerna GetTV(channel, ahead) och GetBar(channel). I Samurize |
- | Config Editor kan du nu med hjälp av parametrar ange vilken kanal som ska |
- | användas (ex. SVT1, TV8, TV3, SVT_HD) och vilket program som ska visas. |
- | 0 = det som sänds nu, 1 = nästa program, 2 =... |
- | V.2.3 - modified by Whiskey (20120406) |
- | 1: Fixat så åäö funkar, vet inte om de är korrekt sätt men funkar iaf |
- | 2: Ser ut som omtv.se gjort om sin sida igen lagt till så den parsar rätt men |
- | program som har <h5 class="icon movie">Title</h5> och inte bara <h5>Title</h5> |
- | 3: Find out that showTime / timeDelimiter / timeProgressSeparator is broken |
- \*****************************************************************************************/
- var showTime = true ;// Option to show the time in the output (true or false)
- var timeDelimiter = ":" ;// Option what to separate hours and minutes with(":" "." or what you want)
- var timeProgramSeparator = " " ;// Option what to separate time and program with
- var noProgramYet = "Inget program" ;// The text showing when there are no program yet
- var noProgramNow = "Sändningsuppehåll" ;// The text showing when there are no program right now
- var noProgramEnd = "Sändningsslut" ;// The text showing when there are no program any more
- /*
- 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...
- 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/
- example:
- to add "Canal+ Sport" you would notice the end of the link to be "Canal+_Sport"
- http://www.omtv.se/tabla/Canal+_Sport/
- so the fuction would look like this:
- function GetCanalPlusSport() { return GetTV_("Canal+_Sport", 0); }
- */
- function GetTV(channel, ahead) {return GetTV_(channel, parseInt(ahead)); }
- function GetBar(channel) {return GetBar_(channel); }
- function GetSVT1() { return GetTV_("SVT1", 0); }
- function GetBarSVT1() { return GetBar_("SVT1"); }
- function GetNextSVT1() { return GetTV_("SVT1", 1); }
- function GetSVT2() { return GetTV_("SVT2", 0); }
- function GetBarSVT2() { return GetBar_("SVT2"); }
- function GetNextSVT2() { return GetTV_("SVT2", 1); }
- function GetTV3() { return GetTV_("TV3", 0); }
- function GetBarTV3() { return GetBar_("TV3"); }
- function GetNextTV3() { return GetTV_("TV3", 1); }
- function GetTV4() { return GetTV_("TV4", 0); }
- function GetBarTV4() { return GetBar_("TV4"); }
- function GetNextTV4() { return GetTV_("TV4", 1); }
- function GetKanal5() { return GetTV_("Kanal_5", 0); }
- function GetBarKanal5() { return GetBar_("Kanal_5"); }
- function GetNextKanal5() { return GetTV_("Kanal_5", 1); }
- function Get6an() { return GetTV_("TV6", 0); }
- function GetBar6an() { return GetBar_("TV6"); }
- function GetNext6an() { return GetTV_("TV6", 1); }
- function GetSjuan() { return GetTV_("Sjuan", 0); }
- function GetBarSjuan() { return GetBar_("Sjuan"); }
- function GetNextSjuan() { return GetTV_("Sjuan", 1); }
- function GetDiscovery_Channel() { return GetTV_("Discovery_Channel", 0); }
- function GetBarDiscovery_Channel() { return GetBar_("Discovery_Channel"); }
- function GetNextDiscovery_Channel() { return GetTV_("Discovery_Channel", 1); }
- function GetTV_(channel, count)
- {
- var txt = GetPage_(channel);
- if(txt.substr(0,5)=="Error") return txt;
- try
- {
- var now = -1;
- var offset = -2;
- var lines = txt.split("\r\n");
- // Check if the last program = noProgramEnd
- // omtv.se sometimes repeats the next day first program as the current day last progam
- // we then have to set the offset to -3 to skip the last program in the saved file
- if (lines[lines.length-2].indexOf(noProgramEnd) < 0) offset = -3;
- for(var i=lines.length+offset;i>=0;i--)
- {
- var time = lines[i].substring(0,5);
- _time = new Date();
- 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);
- 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);
- _now = new Date();
- if(_now.getHours()<6) _now.setHours(_now.getHours()+18);
- else _now.setHours(_now.getHours()-6);
- if(_time<_now)
- {
- now = i;
- break;
- }
- }
- if((now+count>=0) && (now+count<=lines.length-2))
- return convertUTF8_(lines[now+count]);
- else
- return noProgramYet;
- }
- catch(e)
- {
- return "Error parsing file";
- }
- }
- function GetBar_(channel)
- {
- var txt = GetPage_(channel);
- if(txt.substr(0,5)=="Error") return txt;
- try
- {
- var now = -1;
- var lines = txt.split("\r\n");
- var offset = -2;
- // Check if the last program = noProgramEnd
- // omtv.se somtimes repeats the next day first program as the current day last progam
- // we then have to set the offset to -3 to skip the last program in the saved file
- if (lines[lines.length-2].indexOf(noProgramEnd) < 0) offset = -3;
- for(var i=lines.length+offset;i>=0;i--)
- {
- var time = lines[i].substring(0,5);
- _time = new Date();
- 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);
- 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);
- _now = new Date();
- if(_now.getHours()<6) _now.setHours(_now.getHours()+18);
- else _now.setHours(_now.getHours()-6);
- if(_time<_now)
- {
- now = i;
- break;
- }
- }
- if(now<0 || now>=(lines.length-2))
- return 0;
- var time1 = lines[now].substring(0,5);
- var time1h = time1.substring(0,2);
- var time1m = time1.substring(3,5);
- var time2 = lines[now+1].substring(0,5);
- var time2h = time2.substring(0,2);
- var time2m = time2.substring(3,5);
- if(time1h<6) time1h=time1h*1+18; else time1h-=6;
- if(time2h<6) time2h=time2h*1+18; else time2h-=6;
- var totalmins = (time2h-time1h)*60+(time2m-time1m);
- var runningminutes = (_now.getHours()-time1h)*60+(_now.getMinutes()-time1m);
- return runningminutes/totalmins*100;
- }
- catch(e)
- {
- return "Error parsing file";
- }
- }
- function GetPage_(channel)
- {
- try
- {
- var fs = new ActiveXObject("Scripting.FileSystemObject");
- try{var ADODBS=new ActiveXObject("ADODB.Stream");}catch(er){var ADODBS=false;}
- try
- {
- var file=fs.GetSpecialFolder(2)+"\\"+channel+".tv";
- if(fs.FileExists(file))
- {
- var f=fs.GetFile(file);
- var filetime = new Date(f.DateLastModified);
- var now = new Date();
- var timeToDownload = new Date();
- timeToDownload.setHours(6,15,0);
- if(timeToDownload>now || filetime>timeToDownload)
- {
- var filen = f.OpenAsTextStream(1);
- var txt = filen.ReadAll();
- filen.Close();
- return txt;
- }
- }
- }
- catch(e)
- {
- return "Error reading from file";
- }
- finally
- {
- delete filetime;
- delete now;
- delete timeToDownload;
- }
- try
- {
- var adress = "http://www.omtv.se/tabla/"+channel+"/";
- var http = new ActiveXObject("Microsoft.XMLHTTP");
- http.Open("GET",adress ,false);
- http.send();
- var html = "Error";
- if (http.Status==200)
- {
- if(ADODBS){
- try{
- ADODBS.Open();
- ADODBS.Type=1; // Binary
- ADODBS.Write(http.responseBody); // Write the response as a byte stream.
- ADODBS.Position=0; // Move back to the start of the stream to be able to change type and charset.
- ADODBS.Type=2; // Text
- ADODBS.Charset="ISO-8859-1"; // Default to Latin 1 Western, West European.
- html=ADODBS.ReadText();
- ADODBS.Close();
- }
- catch(er){
- html=http.responseText; // Something failed, default back to responseText, UTF-8 is forced.
- }
- }
- }
- html = fixHTMLcodes_(html);
- }
- catch(e)
- {
- return "Error downloading page";
- }
- finally
- {
- delete http;
- }
- try
- {
- html = between(html, "<tbody>", "</tbody>");
- var txt="";
- var lines = html.split("</tr>");
- var endtime="";
- // Had to change to 'lines.length-1' for some reason
- for(var i=0;i<lines.length-1;i++)
- {
- var time = lines[i].substr(lines[i].indexOf("</td>")-5,5);
- var program = between(lines[i], "<h5>", "</h5>");
- var desc = between(lines[i], "<p>", "<");
- if(program.indexOf("\r\n")!=-1)
- program = program.substr(0,program.indexOf("\r\n"));
- if(endtime!="")
- {
- var _endtime = new Date();
- _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);
- var _time = new Date();
- _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);
- if(_endtime<_time)
- {
- if(showTime)
- txt+=endtime.substring(0,2)+timeDelimiter+endtime.substring(3,5)+timeProgramSeparator;
- txt+=noProgramNow+"\r\n";
- }
- }
- endtime = lines[i].substr(lines[i].indexOf("(")+9,5);
- if(endtime.substr(2,1)!=".")
- endtime = "";
- if(showTime)
- txt+=time.substring(0,2)+timeDelimiter+time.substring(3,5)+timeProgramSeparator;
- //added
- txt+=program+"%tt"+desc+"\r\n";
- //added
- }
- if(endtime!="")
- {
- var _endtime = new Date();
- _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);
- var _time = new Date();
- _time.setHours(5,59,0);
- if(_endtime<_time)
- {
- if(showTime)
- txt+=endtime.substring(0,2)+timeDelimiter+endtime.substring(3,5)+timeProgramSeparator;
- txt+=noProgramEnd+"\r\n";
- }
- }
- }
- catch(e)
- {
- return "Error parsing page";
- }
- try
- {
- var file=fs.CreateTextFile(file,true);
- file.Write(txt);
- }
- catch(e)
- {
- return "Error writing to file";
- }
- finally
- {
- file.Close();
- }
- }
- catch(e)
- {
- return "Error creating FileSystemObject";
- }
- finally
- {
- delete fs;
- }
- return txt;
- }
- function between(str, start, stop)
- {
- str = str.substr(str.indexOf(start)+start.length);
- str = str.substr(0,str.indexOf(stop));
- return str;
- }
- function convertUTF8_(string){
- var convertedString="";
- try{
- var Stream = new ActiveXObject("ADODB.Stream");
- Stream.Open();
- Stream.Type = 2; // Text
- Stream.Charset="ISO-8859-1";
- Stream.WriteText(string);
- Stream.Position=0;
- Stream.Charset="UTF-8";
- convertedString = Stream.ReadText(string.length);
- Stream.Close();
- }
- catch(er)
- {
- convertedString = string;
- }
- return convertedString;
- }
- function fixHTMLcodes_(str)
- {
- str = str.replace(/å/g, "å");
- str = str.replace(/ä/g, "ä");
- str = str.replace(/ö/g, "ö");
- str = str.replace(/Å/g, "Å");
- str = str.replace(/Ä/g, "Ä");
- str = str.replace(/Ö/g, "Ö");
- str = str.replace(/&/g, "&");
- str = str.replace(/"/g, "\"");
- str = str.replace(/‚/g, ",");
- str = str.replace(/ƒ/g, "f");
- // str = str.replace(/„/g, """);
- str = str.replace(/…/g, ".");
- str = str.replace(/†/g, "?");
- str = str.replace(/‡/g, "?");
- str = str.replace(/ˆ/g, "^");
- str = str.replace(/‰/g, "?");
- str = str.replace(/Š/g, "S");
- str = str.replace(/‹/g, "<");
- str = str.replace(/Œ/g, "O");
- str = str.replace(/‘/g, "'");
- str = str.replace(/’/g, "'");
- // str = str.replace(/“/g, """);
- // str = str.replace(/”/g, """);
- str = str.replace(/•/g, ".");
- str = str.replace(/–/g, "-");
- str = str.replace(/—/g, "-");
- str = str.replace(/˜/g, "~");
- str = str.replace(/™/g, "T");
- str = str.replace(/š/g, "s");
- str = str.replace(/›/g, ">");
- str = str.replace(/œ/g, "o");
- str = str.replace(/Ÿ/g, "Y");
- str = str.replace(/ /g, " ");
- str = str.replace(/¡/g, "¡");
- str = str.replace(/¢/g, "¢");
- str = str.replace(/£/g, "£");
- str = str.replace(/¤/g, "¤");
- str = str.replace(/¥/g, "¥");
- str = str.replace(/¦/g, "¦");
- str = str.replace(/§/g, "§");
- str = str.replace(/¨/g, "¨");
- str = str.replace(/©/g, "©");
- str = str.replace(/ª/g, "ª");
- str = str.replace(/«/g, "«");
- str = str.replace(/¬/g, "¬");
- str = str.replace(/­/g, "");
- str = str.replace(/®/g, "®");
- str = str.replace(/¯/g, "¯");
- str = str.replace(/°/g, "°");
- str = str.replace(/±/g, "±");
- str = str.replace(/²/g, "²");
- str = str.replace(/³/g, "³");
- str = str.replace(/´/g, "´");
- str = str.replace(/µ/g, "µ");
- str = str.replace(/¶/g, "¶");
- str = str.replace(/·/g, "·");
- str = str.replace(/¸/g, "¸");
- str = str.replace(/¹/g, "¹");
- str = str.replace(/º/g, "º");
- str = str.replace(/»/g, "»");
- str = str.replace(/¼/g, "¼");
- str = str.replace(/½/g, "½");
- str = str.replace(/¾/g, "¾");
- str = str.replace(/¿/g, "¿");
- str = str.replace(/À/g, "À");
- str = str.replace(/Á/g, "Á");
- str = str.replace(/Â/g, "Â");
- str = str.replace(/Ã/g, "Ã");
- str = str.replace(/Ä/g, "Ä");
- str = str.replace(/Å/g, "Å");
- str = str.replace(/Æ/g, "Æ");
- str = str.replace(/Ç/g, "Ç");
- str = str.replace(/È/g, "È");
- str = str.replace(/É/g, "É");
- str = str.replace(/Ê/g, "Ê");
- str = str.replace(/Ë/g, "Ë");
- str = str.replace(/Ì/g, "Ì");
- str = str.replace(/Í/g, "Í");
- str = str.replace(/Î/g, "Î");
- str = str.replace(/Ï/g, "Ï");
- str = str.replace(/Ð/g, "Ð");
- str = str.replace(/Ñ/g, "Ñ");
- str = str.replace(/Ò/g, "Ò");
- str = str.replace(/Ó/g, "Ó");
- str = str.replace(/Ô/g, "Ô");
- str = str.replace(/Õ/g, "Õ");
- str = str.replace(/Ö/g, "Ö");
- str = str.replace(/×/g, "×");
- str = str.replace(/Ø/g, "Ø");
- str = str.replace(/Ù/g, "Ù");
- str = str.replace(/Ú/g, "Ú");
- str = str.replace(/Û/g, "Û");
- str = str.replace(/Ü/g, "Ü");
- str = str.replace(/Ý/g, "Ý");
- str = str.replace(/Þ/g, "Þ");
- str = str.replace(/ß/g, "ß");
- str = str.replace(/à/g, "à");
- str = str.replace(/á/g, "á");
- str = str.replace(/â/g, "â");
- str = str.replace(/ã/g, "ã");
- str = str.replace(/ä/g, "ä");
- str = str.replace(/å/g, "å");
- str = str.replace(/æ/g, "æ");
- str = str.replace(/ç/g, "ç");
- str = str.replace(/è/g, "è");
- str = str.replace(/é/g, "é");
- str = str.replace(/ê/g, "ê");
- str = str.replace(/ë/g, "ë");
- str = str.replace(/ì/g, "ì");
- str = str.replace(/í/g, "í");
- str = str.replace(/î/g, "î");
- str = str.replace(/ï/g, "ï");
- str = str.replace(/ð/g, "ð");
- str = str.replace(/ñ/g, "ñ");
- str = str.replace(/ò/g, "ò");
- str = str.replace(/ó/g, "ó");
- str = str.replace(/ô/g, "ô");
- str = str.replace(/õ/g, "õ");
- str = str.replace(/ö/g, "ö");
- str = str.replace(/÷/g, "÷");
- str = str.replace(/ø/g, "ø");
- str = str.replace(/ù/g, "ù");
- str = str.replace(/ú/g, "ú");
- str = str.replace(/û/g, "û");
- str = str.replace(/ü/g, "ü");
- str = str.replace(/ý/g, "ý");
- str = str.replace(/þ/g, "þ");
- str = str.replace(/ÿ/g, "ÿ");
- return str;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement