home *** CD-ROM | disk | FTP | other *** search
/ PC Welt 2004 January / PCWELT_1_2004.ISO / pcwsoft / myHTPC-setup.R24.z.exe / XMLTVAutomate.msi / _50C41A69CD0C42FFBF1009B36E2524C5 < prev    next >
Encoding:
Text File  |  2003-07-07  |  2.6 KB  |  100 lines

  1. '
  2. ' This script will edit the XMLTV file to change the channel format from the 
  3. ' new format back to the old.
  4. '
  5. '
  6. ' Usage: FixListings <Path and filename of XMLTV listings>
  7. '
  8. ' Written by avekevin
  9. ' Released July 4, 2003
  10. ' Version 1.10
  11. '
  12. ' Change Log:
  13. '    v1.01
  14. '    * Script now only pulls first 3 numbers for channel number.  The rest are used
  15. '      for channel call letters
  16. '    
  17. '    v1.00
  18. '    * Initial release
  19. '
  20. '
  21.     
  22. Function ReplaceString (sourceFilename) 
  23.     ' Open XML file
  24.     Set fso = CreateObject("Scripting.FileSystemObject")
  25.     fileExists = fso.FileExists(sourceFilename)
  26.  
  27.     IF NOT fileExists THEN
  28.         set shell = CreateObject("WScript.Shell")
  29.         shell.PopUp "File not found!",0,"XMLTV Format Changer",16
  30.         Exit Function
  31.     END IF
  32.  
  33.     ' Open source file
  34.     set sourceFile = fso.OpenTextFile(sourceFilename,1,False)
  35.  
  36.     ' Path is correct, now open temp file for writing
  37.     tempFilename = fso.GetTempName
  38.  
  39.     ' Open temp file
  40.     set tempFile = fso.OpenTextFile(tempFilename,2,True)
  41.  
  42.     Do Until sourceFile.AtEndOfStream
  43.         ' Read line from source file
  44.         lineContent = sourceFile.ReadLine
  45.  
  46.         ' Replace orig string with new string
  47.         set RegX = NEW RegExp
  48.         RegX.Global = True
  49.         RegX.IgnoreCase = True
  50.         RegX.Pattern = "(id|channel)(="")C([0-9]{1,3})(.*)\.zap2it\.com"
  51.         replaceRegExp = "$1$2$3 $4"
  52.         
  53.         ' Replace string with short version of channel name, if found
  54.         newLineContent = RegX.Replace(lineContent,replaceRegExp)
  55.  
  56.         ' If a change was made above, make channel call letters uppercase
  57.         If StrComp(newLineContent,lineContent,0) Then
  58.             RegX.Pattern = "(id|channel)=""([0-9]{1,3})(.*)"""
  59.             set findMatches = RegX.Execute(newLineContent)
  60.  
  61.             For Each Match in findMatches
  62.                 newLineContent = Replace(newLineContent,Match,UCase(Match))
  63.                 newLineContent = Replace(newLineContent,"ID","id")
  64.                 newLineContent = Replace(newLineContent,"CHANNEL","channel")
  65.             Next
  66.         End IF
  67.  
  68.         'Output result to temp file            
  69.         tempFile.WriteLine(newLineContent)
  70.     Loop
  71.  
  72.     ' Close files
  73.     tempFile.close
  74.     sourceFile.close
  75.     
  76.     ' Delete source file
  77.     fso.DeleteFile sourceFilename,True
  78.     
  79.     ' Rename temp file to source file
  80.     fso.MoveFile tempFilename,sourceFilename
  81. End Function
  82.  
  83. '
  84. ' Main function
  85. '
  86.  
  87. ' Get command line arguments
  88. set commandLineArgs = WScript.Arguments
  89.  
  90. ' If the path is provided, then run otherwise give an error
  91. If commandLineArgs.length Then
  92.     ReplaceString(commandLineArgs(0))
  93. Else
  94.     set shell = CreateObject("WScript.Shell")
  95.     shell.PopUp "Source file name and path not provided!",0,"XMLTV Format Changer",16
  96. End If
  97.  
  98. '
  99. ' End of main function
  100. '