' SageFeeds.vbs MH 02/23/10 ' Input file format: ' LongName, ShortName (optional), Feed URL, Thumbnail URL Option Explicit ' User modifiable constants ' Category name to file feeds under. Const DEF_GRP_LONG = "Favorites" Const DEF_GRP_SHORT = "Fav" ' Open output files when finished? Const DONE_OPEN = True ' Constants Const FILEOUT_UITEXT = "CustomOnlineVideoUIText.properties" Const FILEOUT_LINKS = "CustomOnlineVideoLinks.properties" Const FOR_WRITE = 2, FOR_APPEND = 8 Const COM_FLAG = "#", REP_CHAR = "~", SPLIT_CHAR = "," Const LONGNAME = 0, SHORTNAME = 1, FEEDURL = 2, THUMBURL = 3 Const PREF_XPOD = "xPodcast" Const UITEXT_SRC_LONG = "Source/~/LongName=" Const UITEXT_SRC_SHORT = "Source/~/ShortName=" Const UITEXT_THUMB = "Category/~/ThumbURL=" Const UITEXT_LONG = "Category/~/LongName=" Const UITEXT_SHORT = "Category/~/ShortName=" Const DEF_LINKS_SRC = "Sources=xPodcastNews,xPodcastComedy,xPodcastSports,xPodcastScienceTech,xPodcastEntertainment,xPodcastHD,xPodcastFamily,xPodcastHomeGarden" Const LINKS_SRC = "CustomSources=" Const LINKS_FEED = "xFeedPodcastCustom/~=~,xFlagTitleNone;" ' Main Dim oFS: Set oFS = CreateObject( "Scripting.FileSystemObject") Dim oArgs: Set oArgs = WScript.Arguments Dim iContinue If oArgs.Count <> 1 Then MsgBox "Need input file to parse into SageTV video feeds.", _ vbExclamation, "Error" WScript.Quit ElseIf Not oFS.FileExists( oArgs( 0)) Then MsgBox "Input file not found.", vbExclamation, "Error" WScript.Quit End If Dim oInputFile: Set oInputFile = oFS.OpenTextFile( oArgs( 0)) Dim sCategory, sOutUIText, sOutLinks, sLine, sLabel, sShortName Dim aInputVals, iCnt, sSavePath Dim bUIText_Exists, bLinks_Exists ' Determine if UIText and Links files already exist. sSavePath = oFS.GetParentFolderName( _ oFS.GetFile( oArgs( 0)).Path) & "\" bUIText_Exists = oFS.FileExists( sSavePath & FILEOUT_UITEXT) bLinks_Exists = oFS.FileExists( sSavePath & FILEOUT_LINKS) ' Initial output file values. sCategory = PREF_XPOD & DEF_GRP_LONG If Not bUIText_Exists Then _ sOutUIText = _ Replace( UITEXT_SRC_LONG, REP_CHAR, sCategory) & DEF_GRP_LONG & _ vbCRLF & _ Replace( UITEXT_SRC_SHORT, REP_CHAR, sCategory) & DEF_GRP_SHORT & _ vbCRLF & vbCRLF sOutLinks = Iif( bLinks_Exists, vbCRLF, DEF_LINKS_SRC & vbCRLF & _ LINKS_SRC & sCategory & vbCRLF & vbCRLF) ' Get lines from input file. Do While Not oInputFile.AtEndOfStream sLine = Trim( oInputFile.ReadLine) ' Ignore blank and comment lines. If sLine <> "" And Left( sLine, 1) <> COM_FLAG Then aInputVals = Split( sLine, SPLIT_CHAR) ' Generate feed label. Incrementing counter will cause ' feeds to be sorted the same as ordered in input file. iCnt = iCnt + 1 sLabel = Pad_0( iCnt, 2) & _ Replace( aInputVals( LONGNAME), " ", "") ' Check for optional shortname. sShortName = Iif( Trim( aInputVals( SHORTNAME)) <> "", _ Trim( aInputVals( SHORTNAME)), _ Trim( aInputVals( LONGNAME))) ' Create UIText values & append to UIText file string. sOutUIText = sOutUIText & _ Replace( UITEXT_THUMB, REP_CHAR, sLabel) & _ Trim( aInputVals( THUMBURL)) & vbCRLF & _ Replace( UITEXT_LONG, REP_CHAR, sLabel) & _ Trim( aInputVals( LONGNAME)) & vbCRLF & _ Replace( UITEXT_SHORT, REP_CHAR, sLabel) & _ sShortName & vbCRLF & vbCRLF ' Create Links values & append to links file string. sOutLinks = sOutLinks & Replace( _ Replace( LINKS_FEED, REP_CHAR, sLabel, 1, 1), _ REP_CHAR, sCategory) & _ Trim( aInputVals( FEEDURL)) & vbCRLF End If Loop ' Open existing or create new output files. Dim oOutUIText, oOutLinks Set oOutUIText = oFS.OpenTextFile( sSavePath & FILEOUT_UITEXT, _ Iif( bUIText_Exists, FOR_APPEND, FOR_WRITE), True) Set oOutLinks = oFS.OpenTextFile( sSavePath & FILEOUT_LINKS, _ Iif( bLinks_Exists, FOR_APPEND, FOR_WRITE), True) ' Write generated feed/ui info. oOutUIText.Write sOutUIText oOutLinks.Write sOutLinks ' Close all files. oOutUIText.Close oOutLinks.Close oInputFile.Close Function Iif( Condition, TrueResult, FalseResult) If Condition Then Iif = TrueResult Else Iif = FalseResult End Function Function Pad_0( sTarget, iCount) Pad_0 = Right( String( iCount, "0") & sTarget, iCount) End Function