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