home *** CD-ROM | disk | FTP | other *** search
- <?XML version="1.0"?>
- <component>
-
- <registration
- description="EpgTVPIPlugin"
- progid="myHTPC.EpgTVPIPlugin"
- version="1.00"
- classid="{2494bddc-7c9a-4c0d-a3eb-c0f9dc42f472}"
- >
- </registration>
-
- <implements id="Automation" type="Automation">
- <method name="Watch"></method>
- <method name="Record"></method>
- <method name="LiveTV"></method>
- <method name="Cancel"></method>
- </implements>
-
- <script language="JScript">
-
- <![CDATA[
-
- //------------------------------------------------------------------------------
- //
- // This plug-in is used by myHTPC to generate TVVI and TVPI files for viewing
- // and recording TV. It could just as easily be replaced with a different plug-in
- // with a more direct approach.
- //
- //------------------------------------------------------------------------------
- // Watch and Record are the two public functions of the component, and they are called directly
- // by myHTPC. Since they are so similar in this case, they both use a couple of
- // helper functions listed below.
- // The Cancel function is new to R21 and has the same parameters.
- //
- // The parameters for both functions are the same, as follows:
- //
- // channelID : string
- //
- // contains the value of the channel attribute for the progamme element
- //
- // channelDisplayNames : VB array of strings
- //
- // contains a string for each display-name found for the channel
- // for example, tv_grab_uk puts two display names for each channel,
- // where the first one is the channel name and the second one is the
- // channel number.
- //
- // Using one of the two, you should be able to get the true channel
- // number for use in the TVVI file. See the comments below.
- //
- // programTitle : string (self explanatory)
- //
- // programDesc : string (self explanatory)
- //
- // startDate : string
- //
- // This is in the format YYYYMMDD. All dates and times are in GMT.
- //
- // startTime : string
- //
- // This is in the format HH:MM. All dates and times are in GMT.
- //
- // endDate : string (same as startDate)
- //
- // endTime : string (same as startTime)
- //
- // duration : string
- //
- // This is in the format HH:MM.
- //
- // channelNumber : string
- // This comes from the channels.ini number= tag
- //
- // subtitle : string
- // The program's sub-title
- //
- //------------------------------------------------------------------------------
-
- function Watch( channelID , channelDisplayNames , programTitle , programDesc , startDate , startTime , endDate , endTime , duration , channelNumber , subtitle)
- {
- return CreateFile( "tvvi" , "tv-viewer-info" , channelNumber , channelID, channelDisplayNames , programTitle , programDesc , startDate , startTime , endDate , endTime , duration )
- }
-
- //------------------------------------------------------------------------------
-
- function Record( channelID , channelDisplayNames , programTitle , programDesc , startDate , startTime , endDate , endTime , duration , channelNumber , subtitle )
- {
- return CreateFile( "tvpi" , "tv-program-info" , channelNumber , channelID, channelDisplayNames , programTitle , programDesc , startDate , startTime , endDate , endTime , duration )
- }
-
- function Cancel( channelID , channelDisplayNames , programTitle , programDesc , startDate , startTime , endDate , endTime , duration , channelNumber , subtitle )
- {
- var tv = null;
- var tvHelper = null;
-
- try {
- tvHelper = new ActiveXObject ("myHTPC_WTV.Helper"); // Get Helper Object
- if (tvHelper != null)
- tv = tvHelper.GetTV(); // See if TV Plugin is running
- }
- catch (e) {}
-
- if (tv != null)
- {
- tvHelper = null;
- tv.autCancelEvent(channelNumber, startDate, startTime, endDate, endTime);
- }
- return "";
- }
-
- //------------------------------------------------------------------------------
- // In addition, LiveTV should just bring up the TV system in a default state
- // Currently, it does nothing.
-
- function LiveTV( )
- {
- var shell = new ActiveXObject( "WScript.Shell" );
- var tv = null, tvHelper = null;
-
- try {
- tvHelper = new ActiveXObject("myHTPC_WTV.Helper");
- if (tvHelper != null)
- tv = tvHelper.GetTV();
- }
- catch (e) { }
-
- if (tv == null)
- {
- shell.Run('"C:\\Program Files\\myHTPC\\myHTPC_Runner.exe" -x=280 -y=40 -w=-40 -h=-40 -pvrmode=2');
- }
- else
- {
- tvHelper = null;
-
- if (tv.autRecorderMode)
- {
- tv.autSetRecorderMode(0);
- }
- tv.autShowWindow(280, 40, -40, -40);
- tv.autSetPVRMode(2);
- tv.autShowWindow(0, 0, 0, 0);
- }
-
- return "";
- }
-
- //------------------------------------------------------------------------------
- // CreateDocument takes all the parameters and creates an XML document with all
- // the pieces inside it. It is also responsible for finding the true RF-CHANNEL
- // from the information given.
-
- function CreateDocument( rootName , channelNumber, channelID , channelDisplayNames , programTitle , programDesc , startDate , startTime , endDate , endTime , duration )
- {
- // Declare the necessary variables
-
- var doc , root, program , element;
-
- //----------------------------------------------------------------------------
- // For tv_grab_na, the channel id is of the form <number><space><station>
- // For example : "2 KPRC"
- // So, we have have to parse it to split the station and the number for use
- // in the TVVI file.
-
- // This will search for the first space in the file. There is only a single
- // space between the slashes in the regular expression
-
- //----------------------------------------------------------------------------
- // For tv_grab_uk, each channel has a number of display names, it seems that the
- // first one is the station name and the second is the channel number.
- // If you are using this grabber, comment out the previous section and use this
- // one instead. It may need better error handling in cases where the channel
- // has less than 2 display names.
-
- //----------------------------------------------------------------------------
- // Create a new XML document
-
- doc = new ActiveXObject( "Msxml2.DOMDocument.4.0" );
-
- // Create the root element for the document and set the version attribute
-
- root = doc.createElement( rootName );
- root.setAttribute( "version" , "1.0" );
-
- // Tell the document that this is the root element
-
- doc.documentElement = root;
-
- // create the program element
-
- program = doc.createElement( "program" );
-
- // Now create, populate and add the other elements
-
- // station
-
- var namesVB = new VBArray( channelDisplayNames );
- var names = namesVB.toArray();
-
-
- element = doc.createElement( "station" );
- element.text = names[0] ;
- program.appendChild( element );
-
- // tv-mode
- // not sure what effect this has or how to determine the correct value,
- // so it is hard-coded to "cable"
-
- element = doc.createElement( "tv-mode" );
- element.text = "cable";
- program.appendChild( element );
-
- // program-title
-
- element = doc.createElement( "program-title" );
- element.text = programTitle;
- program.appendChild( element );
-
- // program-description
-
- element = doc.createElement( "program-description" );
- element.text = programDesc;
- program.appendChild( element );
-
- // start-date
-
- element = doc.createElement( "start-date" );
- element.text = startDate;
- program.appendChild( element );
-
- // start-time
-
- element = doc.createElement( "start-time" );
- element.text = startTime;
- program.appendChild( element );
-
- // end-date
-
- element = doc.createElement( "end-date" );
- element.text = endDate;
- program.appendChild( element );
-
- // end-time
-
- element = doc.createElement( "end-time" );
- element.text = endTime;
- program.appendChild( element );
-
- // duration
-
- element = doc.createElement( "duration" );
- element.text = duration;
- program.appendChild( element );
-
- // rf-channel
-
- element = doc.createElement( "rf-channel" );
- element.text = channelNumber.toString();
- program.appendChild( element );
-
- element = doc.createElement( "id-channel" );
- element.text = channelID.toString();
- program.appendChild( element );
-
-
- // add the program element to the root
-
- root.appendChild( program );
-
- return doc;
- }
-
- //------------------------------------------------------------------------------
-
- function CreateFile( fileExt , rootName , channelNumber, channelID, channelDisplayNames , programTitle , programDesc , startDate , startTime , endDate , endTime , duration )
- {
- var doc = CreateDocument( rootName, channelNumber, channelID , channelDisplayNames , programTitle , programDesc , startDate , startTime , endDate , endTime , duration );
-
- //----------------------------------------------------------------------------
- // This is used to 'pretty-print' the document so that each element is on its own line
-
- var reader = new ActiveXObject( "Msxml2.SAXXMLReader.4.0" );
-
- var writer = new ActiveXObject( "Msxml2.MXXMLWriter.4.0" );
-
- reader.contentHandler = writer;
-
- writer.indent = true;
- writer.standalone = true;
- writer.omitXMLDeclaration = true;
-
- reader.parse( doc.xml );
-
- writer.flush();
-
- //----------------------------------------------------------------------------
- // Now, s contains the whole document formatted nicely
-
- var s = writer.output;
-
- //----------------------------------------------------------------------------
- // Get rid of all tabs in s
-
- s = s.replace( /\t/g , "" );
-
- //----------------------------------------------------------------------------
- // Find the system's temp folder, create a text file there and save s
- // to the text file
-
- var fso = new ActiveXObject("Scripting.FileSystemObject");
-
- var temp_folder = fso.GetSpecialFolder( 2 );
-
- var file_name = temp_folder.path + "\\myHTPC." + fileExt;
-
- var file = fso.CreateTextFile( file_name , true );
-
- file.Write( s );
-
- file.Close();
-
- //----------------------------------------------------------------------------
- // Now run the file
-
- var bUseRecorderMode = true;
-
- var shell = new ActiveXObject( "WScript.Shell" );
- var tv = null, tvHelper = null;
-
- try {
- tvHelper = new ActiveXObject("myHTPC_WTV.Helper");
- if (tvHelper != null)
- tv = tvHelper.GetTV();
- }
- catch (e) { }
-
- var bUseSilentMode = false;
-
- // Check if silent mode is needed - when recording in the future.
- if (bUseRecorderMode && fileExt == "tvpi")
- bUseSilentMode = true;
-
- if (tv == null)
- {
- if (bUseSilentMode)
- shell.Run('"C:\\Program Files\\myHTPC\\myHTPC_Runner.exe" -recordermode=2 -x=300 -y=320 -w=460 -h=250 -commandfile="' + file_name + '"');
- else
- shell.Run('"C:\\Program Files\\myHTPC\\myHTPC_Runner.exe" -x=300 -y=320 -w=460 -h=250 -commandfile="' + file_name + '" -fullscreen=1');
- }
- else
- {
- tvHelper = null;
- if (bUseSilentMode)
- tv.autSetRecorderMode(2);
- else
- {
- if (tv.autRecorderMode)
- {
- tv.autSetRecorderMode(0);
- tv.autShowWindow(300, 320, 460, 250);
- }
- tv.autShowWindow(0, 0, 0, 0);
- tv.autFullScreen();
- }
- tv.autSetCommandFile(file_name);
- }
-
- return "";
- }
-
- //------------------------------------------------------------------------------
-
- ]]>
- </script>
-
- </component>
-
-