home *** CD-ROM | disk | FTP | other *** search
/ PC Welt 2004 January / PCWELT_1_2004.ISO / pcwsoft / myHTPC-setup.R24.z.exe / myHTPC_EpgTVPIPlugin.wsc next >
Encoding:
Extensible Markup Language  |  2003-10-21  |  11.5 KB  |  377 lines

  1. <?XML version="1.0"?>
  2. <component>
  3.  
  4. <registration
  5.     description="EpgTVPIPlugin"
  6.     progid="myHTPC.EpgTVPIPlugin"
  7.     version="1.00"
  8.     classid="{2494bddc-7c9a-4c0d-a3eb-c0f9dc42f472}"
  9. >
  10. </registration>
  11.  
  12. <implements id="Automation" type="Automation">
  13.     <method name="Watch"></method>
  14.     <method name="Record"></method>
  15.     <method name="LiveTV"></method>
  16.     <method name="Cancel"></method>
  17. </implements>
  18.  
  19. <script language="JScript">
  20.  
  21. <![CDATA[
  22.  
  23. //------------------------------------------------------------------------------
  24. //
  25. //  This plug-in is used by myHTPC to generate TVVI and TVPI files for viewing
  26. //  and recording TV. It could just as easily be replaced with a different plug-in
  27. //  with a more direct approach.
  28. //
  29. //------------------------------------------------------------------------------
  30. // Watch and Record are the two public functions of the component, and they are called directly
  31. // by myHTPC. Since they are so similar in this case, they both use a couple of
  32. // helper functions listed below.
  33. // The Cancel function is new to R21 and has the same parameters.
  34. //
  35. // The parameters for both functions are the same, as follows:
  36. //
  37. //  channelID : string
  38. //
  39. //              contains the value of the channel attribute for the progamme element
  40. //
  41. //  channelDisplayNames : VB array of strings
  42. //
  43. //              contains a string for each display-name found for the channel
  44. //              for example, tv_grab_uk puts two display names for each channel,
  45. //              where the first one is the channel name and the second one is the
  46. //              channel number.
  47. //
  48. //              Using one of the two, you should be able to get the true channel
  49. //              number for use in the TVVI file. See the comments below.
  50. //
  51. //  programTitle  : string (self explanatory)
  52. //
  53. //  programDesc   : string (self explanatory)
  54. //
  55. //  startDate     : string
  56. //
  57. //              This is in the format YYYYMMDD. All dates and times are in GMT.
  58. //
  59. //  startTime     : string
  60. //
  61. //              This is in the format HH:MM. All dates and times are in GMT.
  62. //
  63. //  endDate       : string (same as startDate)
  64. //
  65. //  endTime       : string (same as startTime)
  66. //
  67. //  duration      : string
  68. //
  69. //              This is in the format HH:MM.
  70. //
  71. //  channelNumber    : string
  72. //              This comes from the channels.ini number= tag
  73. //
  74. //  subtitle            : string
  75. //                        The program's sub-title
  76. //
  77. //------------------------------------------------------------------------------
  78.  
  79. function Watch( channelID , channelDisplayNames , programTitle , programDesc , startDate , startTime , endDate , endTime , duration , channelNumber , subtitle)
  80. {
  81.   return CreateFile( "tvvi" , "tv-viewer-info" , channelNumber , channelID, channelDisplayNames , programTitle , programDesc , startDate , startTime , endDate , endTime , duration )
  82. }
  83.  
  84. //------------------------------------------------------------------------------
  85.  
  86. function Record( channelID , channelDisplayNames , programTitle , programDesc , startDate , startTime , endDate , endTime , duration , channelNumber , subtitle )
  87. {
  88.   return CreateFile( "tvpi" , "tv-program-info" , channelNumber , channelID, channelDisplayNames , programTitle , programDesc , startDate , startTime , endDate , endTime , duration )
  89. }
  90.  
  91. function Cancel( channelID , channelDisplayNames , programTitle , programDesc , startDate , startTime , endDate , endTime , duration , channelNumber , subtitle )
  92. {
  93.     var tv = null; 
  94.     var tvHelper = null; 
  95.  
  96.     try { 
  97.         tvHelper = new ActiveXObject ("myHTPC_WTV.Helper"); // Get Helper Object 
  98.         if (tvHelper != null) 
  99.             tv = tvHelper.GetTV(); // See if TV Plugin is running 
  100.     } 
  101.     catch (e) {} 
  102.  
  103.     if (tv != null) 
  104.     { 
  105.             tvHelper = null;
  106.         tv.autCancelEvent(channelNumber, startDate, startTime, endDate, endTime);
  107.     } 
  108.     return ""; 
  109. }
  110.  
  111. //------------------------------------------------------------------------------
  112. // In addition, LiveTV should just bring up the TV system in a default state
  113. // Currently, it does nothing.
  114.  
  115. function LiveTV( )
  116. {
  117.   var shell = new ActiveXObject( "WScript.Shell" );
  118.   var tv = null, tvHelper = null;
  119.  
  120.   try {
  121.       tvHelper = new ActiveXObject("myHTPC_WTV.Helper");
  122.       if (tvHelper != null)
  123.           tv = tvHelper.GetTV();
  124.     }
  125.     catch (e) { }
  126.  
  127.     if (tv == null)
  128.     {
  129.       shell.Run('"C:\\Program Files\\myHTPC\\myHTPC_Runner.exe" -x=280 -y=40 -w=-40 -h=-40 -pvrmode=2');
  130.     }        
  131.     else
  132.     {
  133.        tvHelper = null;
  134.               
  135.        if (tv.autRecorderMode)
  136.        {
  137.           tv.autSetRecorderMode(0); 
  138.     }
  139.        tv.autShowWindow(280, 40, -40, -40);    
  140.        tv.autSetPVRMode(2);
  141.        tv.autShowWindow(0, 0, 0, 0);    
  142.     }
  143.   
  144.   return "";
  145. }
  146.  
  147. //------------------------------------------------------------------------------
  148. // CreateDocument takes all the parameters and creates an XML document with all
  149. // the pieces inside it. It is also responsible for finding the true RF-CHANNEL
  150. // from the information given.
  151.  
  152. function CreateDocument( rootName , channelNumber, channelID , channelDisplayNames , programTitle , programDesc , startDate , startTime , endDate , endTime , duration )
  153. {
  154.   // Declare the necessary variables
  155.  
  156.     var doc , root, program , element;
  157.  
  158.   //----------------------------------------------------------------------------
  159.   // For tv_grab_na, the channel id is of the form <number><space><station>
  160.   // For example :  "2 KPRC"
  161.   // So, we have have to parse it to split the station and the number for use
  162.   // in the TVVI file.
  163.  
  164.   // This will search for the first space in the file. There is only a single
  165.   // space between the slashes in the regular expression
  166.  
  167.   //----------------------------------------------------------------------------
  168.   // For tv_grab_uk, each channel has a number of display names, it seems that the
  169.   // first one is the station name and the second is the channel number.
  170.   // If you are using this grabber, comment out the previous section and use this
  171.   // one instead. It may need better error handling in cases where the channel
  172.   // has less than 2 display names.
  173.  
  174.   //----------------------------------------------------------------------------
  175.   // Create a new XML document
  176.  
  177.     doc = new ActiveXObject( "Msxml2.DOMDocument.4.0" );
  178.  
  179.   // Create the root element for the document and set the version attribute
  180.  
  181.     root = doc.createElement( rootName );
  182.   root.setAttribute( "version" , "1.0" );
  183.  
  184.   // Tell the document that this is the root element
  185.  
  186.     doc.documentElement = root;
  187.  
  188.   // create the program element
  189.  
  190.   program = doc.createElement( "program" );
  191.  
  192.   // Now create, populate and add the other elements
  193.  
  194.   // station
  195.  
  196.   var namesVB = new VBArray( channelDisplayNames );
  197.   var names   = namesVB.toArray();
  198.  
  199.  
  200.   element = doc.createElement( "station" );
  201.   element.text = names[0] ;
  202.   program.appendChild( element );
  203.  
  204.   // tv-mode
  205.   // not sure what effect this has or how to determine the correct value,
  206.   // so it is hard-coded to "cable"
  207.  
  208.   element = doc.createElement( "tv-mode" );
  209.   element.text = "cable";
  210.   program.appendChild( element );
  211.  
  212.   // program-title
  213.  
  214.   element = doc.createElement( "program-title" );
  215.   element.text = programTitle;
  216.   program.appendChild( element );
  217.  
  218.   // program-description
  219.  
  220.   element = doc.createElement( "program-description" );
  221.   element.text = programDesc;
  222.   program.appendChild( element );
  223.  
  224.   // start-date
  225.  
  226.   element = doc.createElement( "start-date" );
  227.   element.text = startDate;
  228.   program.appendChild( element );
  229.  
  230.   // start-time
  231.  
  232.   element = doc.createElement( "start-time" );
  233.   element.text = startTime;
  234.   program.appendChild( element );
  235.  
  236.   // end-date
  237.  
  238.   element = doc.createElement( "end-date" );
  239.   element.text = endDate;
  240.   program.appendChild( element );
  241.  
  242.   // end-time
  243.  
  244.   element = doc.createElement( "end-time" );
  245.   element.text = endTime;
  246.   program.appendChild( element );
  247.  
  248.   // duration
  249.  
  250.   element = doc.createElement( "duration" );
  251.   element.text = duration;
  252.   program.appendChild( element );
  253.  
  254.   // rf-channel
  255.  
  256.   element = doc.createElement( "rf-channel" );
  257.   element.text = channelNumber.toString();
  258.   program.appendChild( element );
  259.  
  260.   element = doc.createElement( "id-channel" );
  261.   element.text = channelID.toString();
  262.   program.appendChild( element );
  263.  
  264.  
  265.   // add the program element to the root
  266.  
  267.   root.appendChild( program );
  268.  
  269.   return doc;
  270. }
  271.  
  272. //------------------------------------------------------------------------------
  273.  
  274. function CreateFile( fileExt , rootName , channelNumber, channelID, channelDisplayNames , programTitle , programDesc , startDate , startTime , endDate , endTime , duration )
  275. {
  276.   var doc = CreateDocument( rootName, channelNumber, channelID , channelDisplayNames , programTitle , programDesc , startDate , startTime , endDate , endTime , duration );
  277.  
  278.   //----------------------------------------------------------------------------
  279.   // This is used to 'pretty-print' the document so that each element is on its own line
  280.  
  281.   var reader = new ActiveXObject( "Msxml2.SAXXMLReader.4.0" );
  282.  
  283.   var writer = new ActiveXObject( "Msxml2.MXXMLWriter.4.0" );
  284.  
  285.   reader.contentHandler = writer;
  286.  
  287.   writer.indent = true;
  288.   writer.standalone = true;
  289.   writer.omitXMLDeclaration = true;
  290.  
  291.   reader.parse( doc.xml );
  292.  
  293.   writer.flush();
  294.  
  295.   //----------------------------------------------------------------------------
  296.   // Now, s contains the whole document formatted nicely
  297.  
  298.   var s = writer.output;
  299.  
  300.   //----------------------------------------------------------------------------
  301.   // Get rid of all tabs in s
  302.  
  303.   s = s.replace( /\t/g , "" );
  304.  
  305.   //----------------------------------------------------------------------------
  306.   // Find the system's temp folder, create a text file there and save s
  307.   // to the text file
  308.  
  309.   var fso = new ActiveXObject("Scripting.FileSystemObject");
  310.  
  311.   var temp_folder = fso.GetSpecialFolder( 2 );
  312.  
  313.   var file_name = temp_folder.path + "\\myHTPC." + fileExt;
  314.  
  315.   var file = fso.CreateTextFile( file_name , true );
  316.  
  317.   file.Write( s );
  318.  
  319.   file.Close();
  320.  
  321.   //----------------------------------------------------------------------------
  322.   // Now run the file
  323.  
  324.   var bUseRecorderMode = true;
  325.  
  326.   var shell = new ActiveXObject( "WScript.Shell" );
  327.   var tv = null, tvHelper = null;
  328.  
  329.     try {
  330.       tvHelper = new ActiveXObject("myHTPC_WTV.Helper");
  331.       if (tvHelper != null)
  332.           tv = tvHelper.GetTV();
  333.     }
  334.     catch (e) { }
  335.  
  336.     var bUseSilentMode = false;
  337.         
  338.     // Check if silent mode is needed - when recording in the future.
  339.     if (bUseRecorderMode && fileExt == "tvpi")
  340.         bUseSilentMode = true;
  341.  
  342.     if (tv == null)
  343.     {
  344.         if (bUseSilentMode)
  345.             shell.Run('"C:\\Program Files\\myHTPC\\myHTPC_Runner.exe" -recordermode=2 -x=300 -y=320 -w=460 -h=250  -commandfile="' + file_name + '"');
  346.         else 
  347.             shell.Run('"C:\\Program Files\\myHTPC\\myHTPC_Runner.exe" -x=300 -y=320 -w=460 -h=250  -commandfile="' + file_name + '" -fullscreen=1');
  348.     }
  349.     else
  350.     {
  351.        tvHelper = null;
  352.        if (bUseSilentMode)
  353.            tv.autSetRecorderMode(2);
  354.        else 
  355.        {
  356.            if (tv.autRecorderMode)
  357.        {
  358.                tv.autSetRecorderMode(0); 
  359.                tv.autShowWindow(300, 320, 460, 250);
  360.            }                
  361.            tv.autShowWindow(0, 0, 0, 0);
  362.            tv.autFullScreen();
  363.        }
  364.        tv.autSetCommandFile(file_name);  
  365.     }
  366.  
  367.     return "";
  368. }
  369.  
  370. //------------------------------------------------------------------------------
  371.  
  372. ]]>
  373. </script>
  374.  
  375. </component>
  376.  
  377.