Octorock

Plex PPS daily snapshot

May 22nd, 2017
751
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VBScript 62.03 KB | None | 0 0
  1.  
  2.  
  3. 'filename format basic standards:
  4. 'News
  5.         '\Title\Season 2017\Title (year) - YYYY-M-D HH MM SS - Episode NN
  6. 'TV Show
  7.         '\Title\Season 3\Title (Year) - SxxExx - Title
  8. 'Movie
  9.         '\Title (year)
  10.  
  11. 'FOR HELP WITH VBSCRIPT, SEE DEVGURU http://www.devguru.com/content/technologies/vbscript/index.html
  12.    
  13. 'This script will handle any file type, but made for common video files.
  14. 'Turn OFF word wrap!!!
  15. 'On Windows, get the Notepad++ program for working on files like this. https://notepad-plus-plus.org/ , don't be a chump.
  16.  
  17. 'An attempt was made to write the following programming to allow changes to be made easier in any part of the logic (main
  18. 'code) or function (functions and subs) of the script.
  19.  
  20. 'The following was developed using the following hardware:
  21.     '1 Silicon Dust Homerun Prime (3 cable tuner)
  22.     'Multiprocessor PC for Plex server and MCEB Engine.
  23.     'Extra PC attached to LAN with a running MCEB engine.
  24.     'All platforms were Windows 7
  25.     'Gigabit network.
  26.  
  27. 'Note!
  28. 'If the time in the filename is 00 00 00, it will use the file created attribute of the file. This means, the file needs
  29. 'to be an original file from a DVR, otherwise there is no guarantee that it will update correctly. For instance, a remux
  30. 'or re-encoded copy of any kind is no good. It will use the time of THAT process.
  31.  
  32. 'There are currently 2 main functions of this script.
  33.     '1 - To automatically make adjustments to the DVR recording filenames. (USER CONFIGURABLE)
  34.     '2 - Allocate recordings to MCEB engines on the same LAN for processing prior to being added to Plex.
  35.         'Share the load or dump all encoding to other PCs from the Plex server.
  36.         'Redistribute pending videos from off-line encoders to maintain the work flow. **in development**
  37.  
  38. 'The current logic is as follows.
  39.     'Get input filename w/ path
  40.     'Make sure the file is valid.
  41.     'Set programming variables to likely needed information. This includes:
  42.         'Tile, SE, Episode, Date/time and if live.
  43.         'Destination folders
  44.         'User defined settings
  45.     'Determine the new filename (Default is no change)
  46.     'Evaluate MCEB Encoders by status and current queue sizes
  47.     'Move jobs from off-line encoder folders to dump folder and run a new instance of the script for them.
  48.     'Evaluate Size of media file.
  49.     'Determine if a prefered encoder is eligible
  50.     'Fallback upon available encoders, default to dump folder
  51.     'Assign task, move and rename file to encoder's shared folder
  52.     'Delete source folder (if empty)
  53.     'Log overall status, Upcoming jobs quantity and if any are older than 2 hours which are likely failed recordings.
  54.  
  55. '------------------------------------------------------ SO I DO DECLARE-----------------------------------------------------
  56. 'This is where all global variables are created. Global means that once created, here at the top, any part of the script
  57. '(main code, functs and subs) can read and write to them. Variables created inside a funct or sub are only valid within
  58. 'that funct or sub. Variables are used to store any data you process in the script, like the filename you are processing,
  59. 'or the tile and episode data.
  60.  
  61. Dim TotalFiles, BatchMode, IsStockpile, OfflineEncoderlist, NewsFolderName, TVFolderName, MovieFolderName, StockpileName, MediaType, NeedSetup, VideoCatagory
  62. Dim filesys, WshShell, SettingsDict, NewsDict, EncoderDict, IgnoreDict, ShowDict, MovieDict, CurrentLoadFile
  63. 'Create objects for global use
  64. Set filesys = CreateObject("Scripting.FileSystemObject")
  65. Set WshShell = CreateObject("WScript.Shell")
  66. NeedSetup = False
  67.  
  68. 'Create the dictionaries and set to case-insensitive
  69. Set SettingsDict = CreateObject ("Scripting.Dictionary")
  70.     SettingsDict.CompareMode = vbTextCompare
  71. Set EncoderDict = CreateObject ("Scripting.Dictionary")
  72.     EncoderDict.CompareMode = vbTextCompare
  73. Set NewsDict = CreateObject ("Scripting.Dictionary")
  74.     NewsDict.CompareMode = vbTextCompare
  75. Set ShowDict = CreateObject ("Scripting.Dictionary")
  76.     ShowDict.CompareMode = vbTextCompare
  77. Set MovieDict = CreateObject ("Scripting.Dictionary")
  78.     MovieDict.CompareMode = vbTextCompare
  79. 'Set OtherDict = CreateObject ("Scripting.Dictionary")
  80. '   OtherDict.CompareMode = vbTextCompare
  81.    
  82. 'Load Main config file
  83. LoadFile "PostProcess.cfg", "load"
  84. 'Load News Title dictonary
  85. LoadFile "NewsTitles.cfg", "load"
  86. 'Load Show Title dictonary
  87. LoadFile "ShowTitles.cfg", "load"
  88. 'Load Movie Title dictonary
  89. LoadFile "MovieTitles.cfg", "load"
  90. If NeedSetup  = True Then
  91.     MakeConfig
  92. End If
  93.  
  94. '---------------------------------------------------------------------------------------------------------------------------
  95. '---------------------------------------------------------------------------------------------------------------------------
  96. '----------------------------------------------------- Begin Main Code -----------------------------------------------------
  97. '---------------------------------------------------------------------------------------------------------------------------
  98. '---------------------------------------------------------------------------------------------------------------------------
  99. 'setting the source filename of the file being processed, to a variable. Quitting if null.
  100. If WScript.Arguments.Count > 0 then
  101.     InputRequest = WScript.Arguments(0)
  102. Else
  103.     ScriptLog "Empty request. Running setup.", 4, "000000"
  104.     MakeConfig
  105. End If
  106. TotalFiles = 0
  107. 'Determine if it is a folder or a file being processed.
  108. If filesys.FileExists(InputRequest) Then
  109.     'If it's just a file, send it through...
  110.     BatchMode = 0
  111.     IsStockpile = False
  112.     'Determine the video catagory so we know what filename format and folders to use.
  113.     VideoCatagory = VidCat(InputRequest)
  114.     'Send the file through for processing.
  115.     MainLogic InputRequest
  116. Elseif filesys.FolderExists(InputRequest) Then
  117.     BatchMode = 1
  118.     If InputRequest = SettingsDict.Item("EncoderStockPile") Then
  119.         IsStockpile = True
  120.     Else
  121.         IsStockpile = False
  122.     End If
  123.     ScriptLog "Batch processing started.", 4, "000000"
  124.     'If it is a folder then lets enumerate all files within and send them each through...
  125.     RecursiveSearch InputRequest
  126. End If
  127. 'Only if a batch of files were processed, report total count.
  128. If filesys.FolderExists(InputRequest) Then
  129.     ScriptLog "A total of [ " & TotalFiles & " ] files were batch processed.", 4, "000000"
  130. End If
  131. Set WshShellExec = Nothing
  132. Set filesys = Nothing
  133. WScript.Quit
  134. 'The end
  135.  
  136.  
  137. '---------------------------------------------------------------------------------------------------------------------------
  138. '---------------------------------------------------------------------------------------------------------------------------
  139. '----------------------------------------------- Begin Main Sub Routine ----------------------------------------------------
  140. '---------------------------------------------------------------------------------------------------------------------------
  141. '---------------------------------------------------------------------------------------------------------------------------
  142. Sub MainLogic(SrcFile)
  143.     Dim JobID, DVRGrabSubFolder, DVRGrabFolder, SrcFileName, SrcFileExt, SrcTitle, SrcDateTime, SrcSE, SrcEpTitle, SavedEncoderList, NewFileName
  144.     'Generate a sorta unique ID in the event more than 1 PPS is triggered at the same time. The logs are mixed and this will help identify one job from another.
  145.     TotalFiles = TotalFiles + 1
  146.     Randomize
  147.     JobID = Int((999999 - 100000 + 1) * Rnd + 100000)
  148.  
  149.     'Log the new request.
  150.     ScriptLog "New recording! [" & SrcFile & "]", 0, JobID
  151.  
  152.     '-------------------------------------------------------------------------------------------------------------------------------------
  153.     'Set the global variables for the scriptor to use anywhere in the script. It is better to use data from an already set variable below
  154.     'then to re-run a function for the same value. So here are a few to use.
  155.     '-------------------------------------------------------------------------------------------------------------------------------------
  156.         'SrcFile the file being processed, with full path. It's already set,  just listing it.
  157.         'DVRGrabSubFolder is the full path to the RANDOM34AE71CF.... folder that the new recording was born in, inside the .grab folder.
  158.     DVRGrabSubFolder = Left(SrcFile,InStrRev(SrcFile,"\") - 1)
  159.         'DVRGrabFolder is the full path to the .grab folder of the recording being processed.
  160.     DVRGrabFolder = Left(SrcFile,InStrRev(DVRGrabSubFolder,"\") - 1)
  161.         'SrcLongNameArray is the entire folder structure and filename in an array.
  162.     SrcLongNameArray = Split(SrcFile, "\")
  163.         'SrcFileName is the existing filename without subfolders or slashes.
  164.     SrcFileName = SrcLongNameArray(UBound(SrcLongNameArray))
  165.         'SrcFileArray is the existing filename in an array to separate the name and ext.
  166.     SrcFileArray = Split(SrcFileName, ".")
  167.         'SrcFileExt is the file extension. (.avi,.mpg,.mp4,.mkv....) NOTE: this includes the dot "."
  168.     SrcFileExt = "." & SrcFileArray(UBound(SrcFileArray))
  169.         'SrcTitle is the show title.
  170.     SrcTitle = GetTitle(SrcFile, JobID)
  171.         'SrcEpName is the episode title.
  172.     SrcEpName = GetEpTitle(SrcFile, JobID)
  173.         'SrcDateTime is the date and time of the recording
  174.     SrcDateTime = GetDateTime(SrcFile)
  175.         'SrcSE is the SxxExx of the show
  176.     SEArray = Split(GetSE(SrcFile), ",")
  177.     'SrcSE is the SxxExx of the show
  178.     SrcSE = "S" & SEArray(0) & "E" & SEArray(0)
  179.     'SrcS is the bare season number
  180.     SrcS = SEArray(0)
  181.     'SrcE is the bare episode number
  182.     SrcE = SEArray(1)
  183.         'SrcEpTitle is the Episode number used often as a substitute title when there is no title.
  184.     SrcEpTitle = GetETitle(SrcFile)
  185.         'SavedEncoderList is a list of all tested and available MCEB engines.
  186.     SavedEncoderList = AvailableEncoderList(JobID) 'this function will return available and offline encoders to their respective array/variables
  187.         'AvailableEncoderArray is an array of the content of SavedEncoderList
  188.     AvailableEncoderArray = Split(SavedEncoderList, ",")
  189.         'OfflineEncoderArray is an array of all hosts that are off-line (not including stopped encoders)
  190.     OfflineEncoderArray = Split(OfflineEncoderlist,",")
  191.         'Strip out the folder names for the various main libraries. This is used in avoiding deleting such folder names and makes referencing them easier in future programming.
  192.     NewsFolderName = Mid(SettingsDict.Item("NewsLibFolder"),InStrRev(SettingsDict.Item("NewsLibFolder"),"\") + 1 ,Len(SettingsDict.Item("NewsLibFolder"))-InStrrev(SettingsDict.Item("NewsLibFolder"),"\"))
  193.     TVFolderName = Mid(SettingsDict.Item("TVLibFolder"),InStrRev(SettingsDict.Item("TVLibFolder"),"\") + 1 ,Len(SettingsDict.Item("TVLibFolder"))-InStrrev(SettingsDict.Item("TVLibFolder"),"\"))
  194.     MovieFolderName = Mid(SettingsDict.Item("MovieLibFolder"),InStrRev(SettingsDict.Item("MovieLibFolder"),"\") + 1 ,Len(SettingsDict.Item("MovieLibFolder"))-InStrrev(SettingsDict.Item("MovieLibFolder"),"\"))
  195.     OtherFolderName = Mid(SettingsDict.Item("OtherLibFolder"),InStrRev(SettingsDict.Item("OtherLibFolder"),"\") + 1 ,Len(SettingsDict.Item("OtherLibFolder"))-InStrrev(SettingsDict.Item("OtherLibFolder"),"\"))
  196.     StockpileName = Mid(SettingsDict.Item("EncoderStockPile"),InStrRev(SettingsDict.Item("EncoderStockPile"),"\") + 1 ,Len(SettingsDict.Item("EncoderStockPile"))-InStrrev(SettingsDict.Item("EncoderStockPile"),"\"))
  197.     'Available functions: See actual function below for more information.
  198.         'FileCreatedOn(filename,x) Values of x:(0=Date 1=Time(24 hr) 2=Both(24 hr) 3=Time(AM/PM))
  199.         'UpcomingRecordings(URNumber) Values of URNumber:(0=Count of ALL upcoming 1=Count of all older than 2 hrs)
  200.         'MakeFolderStructure(PathToMake) Values of PathToMake:("c:\any\structure\you\want"), then returns the path as a string in the event you want it for a variable.
  201.         'ScriptLog(LogData,LogRank,JobID) Values of LogData:("Anything you want") LogRank: (0=SUCCESS 1=ERROR 2=WARNING 4=INFORMATION 8=AUDIT_SUCCESS 16=AUDIT_FAILURE)
  202.         'AvailableEncoderList(JobID)
  203.         'Qlength(QName) Values of QName:("cpu1") The name of an available encoders, eg. one name like from AEList
  204.         'EngineStatus(ESName) Values of ESName:("cpu1") The name of an available encoder, eg. one name like from AEList
  205.         'VidSizeRange(VSRName) Values of VSRName ("c:\full\path\to\file.ts")
  206.         'FileCreatedOn(FCOName,FullorPart) Values of FCOName:("c:\full\path\to\file.ts") FullorPart:(0,1,2 or 3) 0=Date 1=Time 2=Date&Time 3=Time12hr
  207.         'GetSE(GSEName) Values of GSEName:("c:\full\path\to\file.ts" or just "file.ts") This function doesn't require the full path.
  208.         'GetETitle(GENName) Values of GENName:("c:\full\path\to\file.ts" or just "file.ts") This function doesn't require the full path.
  209.         'GetIsLive(GILName) Values of GILName:("c:\full\path\to\file.ts" or just "file.ts") This function doesn't require the full path.
  210.         'GetDateTime(GDTName) Values of GDTName:("c:\full\path\to\file.ts") This function requires the full path.
  211.         'GetTitle(GTName,JobID) Values of GTName:("c:\full\path\to\file.ts" or just "file.ts") This function doesn't require the full path.
  212.  
  213.     'Construct a new filename. (THIS IS WHERE YOU ADJUST FILENAME FORMAT TEMPLATES)
  214.     If VideoCatagory = "news" Then
  215.         NewFileName = SrcTitle & " - " & SrcDateTime & " - " & SrcEpTitle & SrcFileExt
  216.     ElseIf VideoCatagory = "show" Then
  217.         NewFileName = SrcTitle & " - " & SrcSE & " - " & SrcEpName & SrcFileExt
  218.     Elseif VideoCatagory = "movie" Then
  219.         NewFileName = SrcTitle & SrcFileExt
  220.     Elseif VideoCatagory = "other" Then
  221.         NewFileName = SrcTitle & SrcFileExt
  222.     End If
  223.    
  224.    
  225.     'BEGIN LOGIC
  226.     'Determine list of candidate encoders within group of prefered ones for the given video size
  227.     Select Case VidSizeRange(SrcFile)
  228.         Case "L"
  229.             If Len(SettingsDict.Item("FastEncoderList")) > 1 Then
  230.                 PreferedEncoderArray = Split(SettingsDict.Item("FastEncoderList"), ",")
  231.             End If
  232.         Case "M"
  233.             If Len(SettingsDict.Item("MedEncoderList")) > 1 Then
  234.                 PreferedEncoderArray = Split(SettingsDict.Item("MedEncoderList"), ",")
  235.             End If
  236.         Case "S"
  237.             If Len(SettingsDict.Item("SlowEncoderList")) > 1 Then
  238.                 PreferedEncoderArray = Split(SettingsDict.Item("SlowEncoderList"), ",")
  239.             End If
  240.     End Select
  241.     If IsArray(PreferedEncoderArray) Then
  242.         'Cross refrence prefered encoders with available ones and return QualifingEncoderArray.
  243.         q = 0
  244.         For Each AvailableEncoder in AvailableEncoderArray
  245.             For each Encoder in PreferedEncoderArray
  246.                 If AvailableEncoder = Encoder Then
  247.                     ReDim Preserve QualifingEncoderArray(q)
  248.                     QualifingEncoderArray(q) = AvailableEncoder
  249.                     q = q + 1
  250.                 End If
  251.             Next
  252.         Next
  253.     Else
  254.         'If no encoders are assigned to video size group, use default list of encoders
  255.         QualifingEncoderArray = Split(SavedEncoderList, ",")
  256.     End If
  257.  
  258.     'Now, QualifingEncoderArray will contain a pre-final list of candidate encoders.
  259.     'We just need to determine which is best.
  260.     'There are 2 methods available for determining the best candidate encoder.
  261.         '1- queue length, simple file count
  262.         '2- queue size (mb), volume comparison weighted by CPU Passmark rating.
  263.     EncoderQueueLength = 100000 'a big fat fake queue size to start with
  264.     Dim ForceQueueSize
  265.     ForceQueueSize = False
  266.     If UBound(QualifingEncoderArray) < 0 Then
  267.         If IsStockpile Then
  268.             ScriptLog "Skipping file, no available encoders to move from stockpile folder.", 4, JobID
  269.             Exit Sub
  270.         Else
  271.             EncoderName = StockpileName
  272.             ScriptLog "Defaulting to StockPile folder, no encoders are available.", 4, JobID
  273.         End If
  274.     Else
  275.         For Each Encoder in QualifingEncoderArray
  276.         'By queue length
  277.             If SettingsDict.Item("QueueGuage") = "length" Then
  278.                 tempnum = Int(Qlength(Encoder))
  279.                 If tempnum < 0 then
  280.                     ScriptLog "[" & Encoder & "] Unable to get queue length, switching to queue size as alternative", 2, JobID
  281.                     ForceQueueSize = True
  282.                 ElseIf tempnum >= 0 Then
  283.                     ScriptLog "[" & Encoder & "] queue length is " & tempnum, 4, JobID
  284.                 End If
  285.             End If
  286.         'By queue size
  287.             If SettingsDict.Item("QueueGuage") = "size" Or ForceQueueSize Then
  288.                 tempnum = Round(filesys.getfolder(SettingsDict.Item("EncoderShares") & "\" & Encoder).Size / 1073741824, 1) 'tempnum is in gb rounded to the nearest 10th decimal
  289.                 If EncoderDict.Exists(Encoder) Then
  290.                     'Size-(Size(2(PM/1000))/100) This will take off 2% per 1k passmark
  291.                     tempnum = Int(tempnum - (tempnum * (2 *(EncoderDict.Item(Encoder) / 1000))/100))
  292.                 End If
  293.                 ScriptLog "[" & Encoder & "] queue size is " & tempnum & " Gb", 4, JobID
  294.             End If
  295.         'Decide if encoder is the one to use
  296.             If Int(tempnum) < EncoderQueueLength Then
  297.                 EncoderName = Encoder
  298.                 EncoderQueueLength = tempnum
  299.             End If
  300.             If EncoderQueueLength = 0 then
  301.                 Exit For
  302.             End If
  303.         Next
  304.     End If
  305.     'Before we continue, if AutoReallocate is active and if there are offline encoders found, move the jobs to the stockpile folder and submit for reprocessing.
  306.     If SettingsDict.Item("AutoReallocate") = 1 And Ubound(OfflineEncoderArray) >= 0 And BatchMode = 0 And Not IsStockpile Then
  307.         ScriptLog "Checking for media in off-line encoder folders." , 4, JobID
  308.         For Each OfflineEncoder in OfflineEncoderArray
  309.             If filesys.FolderExists(SettingsDict.Item("EncoderShares") & "\" & OfflineEncoder) Then
  310.                 If filesys.GetFolder(SettingsDict.Item("EncoderShares") & "\" & OfflineEncoder).SubFolders.Count > 0 Then
  311.                     filesys.MoveFolder SettingsDict.Item("EncoderShares") & "\" & OfflineEncoder & "\*", SettingsDict.Item("EncoderStockPile")
  312.                     ScriptLog "Moved pending files from offline encoder [" & OfflineEncoder & "] to the stockpile folder." , 4, JobID
  313.                 End If
  314.             End If
  315.         Next
  316.     End If
  317.     If BatchMode = 0 And Not IsStockpile Then
  318.         If filesys.GetFolder(SettingsDict.Item("EncoderStockPile")).SubFolders.Count > 0 Then
  319.             ScriptLog "Backlog media found, submitting stockpile folder for batch processing." , 4, JobID
  320.             WshShell.Run Wscript.ScriptFullName & " " & SettingsDict.Item("EncoderStockPile")
  321.         Else
  322.             ScriptLog "No backlog media found, moving on." , 4, JobID
  323.         End If
  324.     End If
  325.     'The engine has been selected for the job, assign it.
  326.     ScriptLog "Assigning " & EncoderName & " with [" & NewFileName & "]", 0, JobID
  327.  
  328.     'Create new folder structure based from VideoCatagory and move file. Delete old folder structure.
  329.     If filesys.FileExists(SrcFile) Then
  330.         If VideoCatagory = "news" Then
  331.             NewFolderStruct = MakeFolderStructure(SettingsDict.Item("EncoderShares") & "\" & EncoderName & "\" & NewsFolderName & "\" & SrcTitle & "\Season 2017\")
  332.         ElseIf VideoCatagory = "show" Then
  333.             NewFolderStruct = MakeFolderStructure(SettingsDict.Item("EncoderShares") & "\" & EncoderName & "\" & TVFolderName & "\" & SrcTitle & "\Season " & SrcS & "\")
  334.         Elseif VideoCatagory = "movie" Then
  335.             NewFolderStruct = MakeFolderStructure(SettingsDict.Item("EncoderShares") & "\" & EncoderName & "\" & MovieFolderName & "\")
  336.         Elseif VideoCatagory = "other" Then
  337.             NewFolderStruct = MakeFolderStructure(SettingsDict.Item("EncoderShares") & "\" & EncoderName & "\" & OtherFolderName & "\")
  338.         End If
  339.         If filesys.FileExists(NewFolderStruct & NewFileName) Then
  340.             ScriptLog "Filename [" & NewFolderStruct & NewFileName & "] already exists. Appending time to name.",1, JobID
  341.             filesys.MoveFile SrcFile, NewFolderStruct & Replace(NewFileName,SrcFileExt, FileCreatedOn(SrcFile,3) & SrcFileExt)
  342.         Else
  343.             ScriptLog "Moving file to [" & NewFolderStruct & NewFileName & "]",4, JobID
  344.             filesys.MoveFile SrcFile, NewFolderStruct & NewFileName
  345.         End If
  346.         If BatchMode = 0 Then
  347.             DelFolder = SrcFile
  348.             For FolderDepth = 0 to 3 'Max folder depth removal, but stop when folder is not empty or = special folder name
  349.                 FolderDepth = FolderDepth + 1
  350.                 DelFolder = Left(SrcFile,InStrRev(DelFolder,"\") - 1)
  351.                 Set folder = filesys.GetFolder(DelFolder)
  352.                 Select Case folder.Name
  353.                     Case ".grab", "Recordings", "Library", NewsFolderName, TVFolderName, MovieFolderName
  354.                         ScriptLog "Not deleting folder [" & DelFolder & "], it may be important.",4, JobID
  355.                         Exit For
  356.                 End Select
  357.                 Set SubFolders = folder.SubFolders
  358.                 Set FilesWithin = folder.files
  359.                 If SubFolders.Count > 0 Or FilesWithin.Count > 0 Then
  360.                     ScriptLog "Not deleting folder [" & DelFolder & "], it's not empty yet.",4, JobID
  361.                     Exit For
  362.                 Elseif Not filesys.FileExists(NewFolderStruct & NewFileName) Then
  363.                     ScriptLog "Not deleting [" & DelFolder & "], destination video missing.",2, JobID
  364.                     Exit For
  365.                 Else
  366.                     On Error Resume Next
  367.                     filesys.DeleteFolder DelFolder
  368.                     If Err.Number <> 0 Then
  369.                         ScriptLog "Unable to remove [" & DelFolder & "], error trying, inspect permissions.",2, JobID
  370.                         Exit For
  371.                     Else
  372.                         ScriptLog "Cleaned up folder [" & DelFolder & "]",4, JobID
  373.                     End If
  374.                 End If
  375.             Next
  376.             Set folder = nothing
  377.             Set SubFolders = nothing
  378.             Set FilesWithin = nothing
  379.         End If
  380.     End If
  381.     If Not EncoderName = StockpileName Then
  382.         'Execute MCEB engine rescan of folder so it immediately sees the new file.
  383.         ForceFolderUpdate EncoderName, JobID
  384.     End If
  385.     'LogRank values = 0=SUCCESS   1=ERROR   2=WARNING   4=INFORMATION   8=AUDIT_SUCCESS   16=AUDIT_FAILURE
  386.     If BatchMode = 0 Then
  387.         'Log upcoming count
  388.         stalefile = UpcomingRecordings(1,DVRGrabFolder)
  389.         newfile = UpcomingRecordings(0,DVRGrabFolder)
  390.         If stalefile > 0 Then
  391.             ScriptLog "There are " & stalefile & " recording(s) older than 2 hours in the grab folder.", 2, JobID
  392.             ScriptLog "There are a total of " & newfile & " new recording(s) pending. See warning log.", 4, JobID
  393.         ElseIf newfile > 0 Then
  394.             ScriptLog "There are " & newfile & " new recording(s) pending.", 4, JobID
  395.         ElseIf newfile = 0 Then
  396.             ScriptLog "There are 0 recordings pending.", 4, JobID
  397.         End If
  398.     End If
  399. End Sub
  400.  
  401. '---------------------------------------------------------------------------------------------------------------------------
  402. '---------------------------------------------------------------------------------------------------------------------------
  403. '----------------------------------------- Begin Supporting Functions & Subs -----------------------------------------------
  404. '---------------------------------------------------------------------------------------------------------------------------
  405. '---------------------------------------------------------------------------------------------------------------------------
  406. 'A common routine to load a script based file and execute it.
  407. Sub LoadFile(auxfile,mode)
  408.     If Not Filesys.FileExists(filesys.GetParentFolderName(WScript.ScriptFullName) & "\" & auxfile) Then
  409.         NeedSetup = True
  410.         Exit Sub
  411.     End If
  412.     If mode = "run" then
  413.         executeGlobal CreateObject("Scripting.FileSystemObject").openTextFile(filesys.GetParentFolderName(WScript.ScriptFullName) & "\" & auxfile).readAll()
  414.     Elseif mode = "load" Then
  415.         Set lfile = filesys.OpenTextFile(filesys.GetParentFolderName(WScript.ScriptFullName) & "\" & auxfile, 1)
  416.         Do Until lfile.AtEndOfStream
  417.             FileString = lfile.ReadLine
  418.             If Instr(FileString, VBTAB) > 0 Then
  419.                 SettingArray = Split(FileString, VBTAB)
  420.                 If UBound(SettingArray) = 1 Then
  421.                     ExecuteString = CurrentLoadFile & ".Add " & Chr(34) & SettingArray(0) & Chr(34) & " , " & Chr(34) & SettingArray(1) & Chr(34)
  422.                     executeGlobal ExecuteString
  423.                 End If
  424.             ElseIf LCase(Trim(FileString)) = "eof" Then
  425.                 Exit Do
  426.             ElseIf Left(FileString,1) = "'" Then
  427.                 'Ignore comment lines
  428.             ElseIf Instr(FileString, " ") > 0 Then
  429.                 'Execute if the string contains a space
  430.                 ExecuteString FileString
  431.             Elseif Len(FileString) > 1 Then
  432.                 'Set dictonary name if non-zero length string
  433.                 CurrentLoadFile = FileString
  434.             End If
  435.         Loop
  436.         lfile.Close
  437.     End If
  438. End Sub
  439. 'A routine to recursively search a folder and ultimately produce all files within it. All files may be processed but
  440. 'only video files will be accepted by MCEB.
  441. Sub RecursiveSearch(fldr)
  442.     Set BaseFolder = filesys.GetFolder(fldr)
  443.     For Each MediaFile in BaseFolder.Files
  444.         TotalFiles = TotalFiles + 1
  445.         MainLogic MediaFile
  446.     Next
  447.     'Ignore .grab folders. We don't want to disturb videos not yet ready.
  448.    For each NestedFolder in BaseFolder.SubFolders
  449.         If Not NestedFolder.Name = ".grab" Then
  450.             RecursiveSearch NestedFolder
  451.         End If
  452.     Next
  453. End Sub
  454. 'Returns the quantity of upcoming recordings. Right now only for logging purposes. Only reports the correct number AFTER the
  455. 'video is moved otherwise it will be +1.
  456. 'URNumber [0=total,1=old]
  457. Function UpcomingRecordings(URNumber,GrabFolder)
  458.     If URNumber = 0 Then
  459.         UpcomingRecordings = filesys.GetFolder(GrabFolder).SubFolders.Count
  460.     Elseif URNumber = 1 Then
  461.         UpcomingRecordings = 0
  462.         For Each FolderName In filesys.GetFolder(GrabFolder).SubFolders
  463.             For Each FileName In filesys.GetFolder(FolderName).Files
  464.                 Set grabFile = filesys.GetFile(FileName)
  465.                 If DateDiff("N", grabFile.DateCreated, now()) > 120 Then 'Older than 2 hours
  466.                     UpcomingRecordings = UpcomingRecordings + 1
  467.                 End If
  468.             Next
  469.         Next
  470.     End If
  471. End Function
  472. 'This sub will build a 2 subfolder deep structure as specified in input PathToMake. Used to create the folders for an assigned
  473. 'video when moved to the encoders folder.
  474. 'It returns the full path as the result
  475. Function MakeFolderStructure(PathToMake)
  476.     MakeFolderStructure = PathToMake
  477.     'Break apart the path to each folder and filename
  478.     FolderStructureArray = Split(PathToMake, "\")
  479.     WorkingPath = FolderStructureArray(0) & "\"
  480.     'Start at 1 because 0 is the drive letter
  481.     For w = 1 To Ubound(FolderStructureArray)
  482.         If Not FolderStructureArray(w) = "" Then
  483.             WorkingPath = WorkingPath & FolderStructureArray(w) & "\"
  484.             If Not filesys.FolderExists(WorkingPath) Then
  485.                 'Make the folder one at a time
  486.                 newfolder = filesys.CreateFolder(WorkingPath)
  487.             End If
  488.         End If
  489.     Next
  490. End Function
  491. 'Sends Logs to the Windows logging service. The following are the log types for classification.
  492. 'https://msdn.microsoft.com/en-us/library/b4ce6by3
  493. 'LogRank values = 0=SUCCESS   1=ERROR   2=WARNING   4=INFORMATION   8=AUDIT_SUCCESS   16=AUDIT_FAILURE
  494. 'See [Event viewer]->[Windows Logs]->[Application]. Logs are marked as from source "WSH".
  495. 'Filters can be applied to windows logs for a clean operating list of jobs complete or fail.
  496. Sub ScriptLog(LogData,LogRank,ID)
  497.     WshShell.LogEvent LogRank, Now() & vbcrlf & "ID: " & ID & vbcrlf & LogData
  498. End Sub
  499. Sub ForceFolderUpdate(EncoderName, ID)
  500.     strCommand = SettingsDict.Item("UserCLIApp") & " --command=engine  --action=rescan --server=" & EncoderName
  501.     Set WshShellExec = WshShell.Exec(strCommand)
  502.     If Instr(WshShellExec.StdOut.ReadAll,"MCEBuddy.UserCLI Successful!!") > 0 Then
  503.         ScriptLog "[" & EncoderName & "] folder rescan command successful.", 4, ID
  504.     Else
  505.         ScriptLog "[" & EncoderName & "] folder rescan command FAILED.", 2, ID
  506.     End If
  507. End Sub
  508. 'Returns the result of testing all folder names in the encoders folder as computers on your network for available MCEB engines.
  509. Function AvailableEncoderList(ID)
  510.     Set FSO = CreateObject("Scripting.FileSystemObject")
  511.     'Make array from offline.txt
  512.     If filesys.FileExists(SettingsDict.Item("EncoderShares") & "\offline.txt") Then
  513.         Set objTextFile = FSO.OpenTextFile(SettingsDict.Item("EncoderShares") & "\offline.txt", 1)
  514.         'Need to set it to a var before splitting it to make sue it's not zero length
  515.         If filesys.GetFile(SettingsDict.Item("EncoderShares") & "\offline.txt").Size > 0 Then
  516.             SavedOfflineArray = Split(objTextFile.ReadAll, vbCrLf)
  517.             'SavedOfflineArray = array of all folder names in the common shared folders that belong to encoders previously marked as offline in offline.txt.
  518.         Else
  519.             ReDim SavedOfflineArray(0)
  520.         End If
  521.         Set objTextFile = Nothing
  522.     Else
  523.         ReDim SavedOfflineArray(0)
  524.     End If
  525.     EncoderArray = EncoderDict.Keys()
  526.     ReDim OutputArray(0)
  527.     ReDim OfflineArray(0)
  528.     For Each EncoderName In EncoderArray
  529.         Select Case EncoderName
  530.             Case ""
  531.                 'Skip blank names
  532.                 Continue
  533.             Case StockpileName
  534.                 'Skip dump folder (assumed to be with encoder folders)
  535.                 Continue
  536.         End Select
  537.         If Not filesys.FolderExists(SettingsDict.Item("EncoderShares") & "\" & EncoderName) Then
  538.             'Needed if in the event of encoder folder being deleted, likely by MCEB when no files remain. All encoders MUST be listed in EncoderList setting!
  539.             NewEncoderFolder = filesys.CreateFolder(SettingsDict.Item("EncoderShares") & "\" & EncoderName)
  540.         End If
  541.         VisableEncoder = 1
  542.         For j = 0 to Ubound(SavedOfflineArray)
  543.             If SavedOfflineArray(j) = EncoderName Then
  544.                 'If encoder name is in the offline.txt array, ignore it.
  545.                 VisableEncoder = 0
  546.                 j = Ubound(SavedOfflineArray)
  547.             End If
  548.         Next
  549.         If VisableEncoder = 0 Then
  550.             If Not OfflineArray(UBound(OfflineArray)) = "" Then
  551.                 ReDim Preserve OfflineArray(UBound(OfflineArray) + 1)
  552.             End If
  553.             OfflineArray(UBound(OfflineArray)) = EncoderName
  554.         ElseIf VisableEncoder = 1 Then
  555.             EncoderState = EngineStatus(EncoderName)
  556.             If EncoderState = "started" Then
  557.                 'This is where valid hosts are added to the list of output.
  558.                 ScriptLog "[" & EncoderName & "] engine is running -idle-", 4, ID
  559.                 If Not OutputArray(UBound(OutputArray)) = "" Then
  560.                     ReDim Preserve OutputArray(UBound(OutputArray) + 1)
  561.                 End If
  562.                 OutputArray(UBound(OutputArray)) = EncoderName
  563.             ElseIf EncoderState = "conversion_in_progress" Then
  564.                 'This is where valid hosts are added to the list of output.
  565.                 ScriptLog "[" & EncoderName & "] engine is running -working- ", 4, ID
  566.                 If Not OutputArray(UBound(OutputArray)) = "" Then
  567.                     ReDim Preserve OutputArray(UBound(OutputArray) + 1)
  568.                 End If
  569.                 OutputArray(UBound(OutputArray)) = EncoderName
  570.             ElseIf EncoderState = "conversion_paused" Then
  571.                 ScriptLog "[" & EncoderName & "] engine is -paused-", 4, ID
  572.                 If Not OutputArray(UBound(OutputArray)) = "" Then
  573.                     ReDim Preserve OutputArray(UBound(OutputArray) + 1)
  574.                 End If
  575.                 OutputArray(UBound(OutputArray)) = EncoderName
  576.             ElseIf EncoderState = "stopped" Then
  577.                 'This is where valid hosts that are stopped and not added to the list.
  578.                 ScriptLog "[" & EncoderName & "] engine is not running -stopped-", 4, ID
  579.             Else
  580.                 'This is where invalid/unavailable hosts are identified.
  581.                 ScriptLog "[" & EncoderName & "] is off-line.", 2, JobID
  582.                 If Not OfflineArray(UBound(OfflineArray)) = "" Then
  583.                     ReDim Preserve OfflineArray(UBound(OfflineArray) + 1)
  584.                 End If
  585.                 OfflineArray(UBound(OfflineArray)) = EncoderName
  586.                 If SettingsDict.Item("AutoDisable") = 1 Then
  587.                     ScriptLog "[" & EncoderName & "] has been auto-disabled", 2, ID
  588.                     Set objFile = FSO.OpenTextFile(SettingsDict.Item("EncoderShares") & "\offline.txt", 8)
  589.                     objFile.Write EncoderName & vbCrLf
  590.                     objFile.Close
  591.                 End If
  592.                 'Add the folder/encoder name to a offline.txt file and will be ignored on future runs until removed.
  593.                 'Re-run contents of folder for assignment
  594.             End If
  595.         End If
  596.     Next
  597.     AvailableEncoderList = Join(OutputArray,",")
  598.     OfflineEncoderlist = Join(OfflineArray,",")
  599.     ScriptLog "Available encoders: [" & AvailableEncoderList & "]", 4, ID
  600. End Function
  601. 'Supplied with an encoders Windows name or IP address, will return the queue length of that MCEB engine.
  602. Function Qlength(QName)
  603.     strCommand = SettingsDict.Item("UserCLIApp") & " --command=query --action=queuelength --quiet --server=" & QName
  604.     Set WshShellExec = WshShell.Exec(strCommand)
  605.     Qlength = WshShellExec.StdOut.ReadLine
  606.     Set WshShellExec = Nothing
  607.     '-2 means nonresponsive
  608. End Function
  609. 'Supplied with an encoder's Windows name or IP address, will return "-2" for offline, "stopped" or "running" engine status
  610. Function EngineStatus(ESName)
  611.     strCommand = SettingsDict.Item("UserCLIApp") & " --command=query --action=enginestate --quiet --server=" & ESName
  612.     Set WshShellExec = WshShell.Exec(strCommand)
  613.     EngineStatus = WshShellExec.StdOut.ReadLine
  614.     Set WshShellExec = Nothing
  615. End Function
  616. 'Crudely determine size category of the video being processed. Used for the fast/med/slow encoders list.
  617. Function VidSizeRange(VSRName)
  618.     SrcFileSize = filesys.GetFile(VSRName).Size
  619.     Select Case True
  620.         Case SrcFileSize >= CDbl(SettingsDict.Item("ALargeFile") * 1073741824)
  621.             VidSizeRange = "L"
  622.         Case SrcFileSize > CDbl(SettingsDict.Item("AMedFile") * 1073741824) And SrcFileSize < CDbl(SettingsDict.Item("ALargeFile") * 1073741824)
  623.             VidSizeRange = "M"
  624.         Case Else
  625.             VidSizeRange = "S"
  626.     End Select
  627. End Function
  628. 'Supplied with a full filename with path will return date, time or date and time of the files creation.
  629. Function FileCreatedOn(FCOName,FullorPart)
  630.     SET objFSO = CREATEOBJECT("Scripting.FileSystemObject")
  631.     SET objFile = objFSO.GetFile(FCOName)
  632.     FileStamp = objFile.DateCreated
  633. 'so.. IF, as in it already happened, the file was created at exactly midnight, ONLY the date will be passed because I guess
  634. 'someone doesn't like zeros...
  635.     If Instr(FileStamp,":") < 1 Then 'For whatever reason when it is midnight, something squares it off by removing all the 0's and only the date is given.
  636.         FileStamp = FileStamp & " 12:00:00 AM" '12 hr equivalent to the 00 00 00 that was removed.
  637.     End If
  638.     FileCreatedArray = Split(FileStamp, " ")
  639.     FileCreatedDateArray = Split(FileCreatedArray(0), "/")
  640.     'need to translate date format. (MM/DD/YY to YY/MM/DD)
  641.     FileCreatedDate = FileCreatedDateArray(2) & "-" & FileCreatedDateArray(0) & "-" & FileCreatedDateArray(1)
  642.     FileCreatedTimeArray = Split(FileCreatedArray(1), ":")
  643.     'If 12 hr time is requested, take care of it and pass it along.
  644.     If FullorPart = 3 Then 'Time AM/PM Format
  645.         FileCreatedOn = FileCreatedTimeArray(0) & "." & FileCreatedTimeArray(1) & " " & FileCreatedArray(2)
  646.     Else
  647.         'Format data for 24 hr format and process other requests
  648.         If FileCreatedArray(2) = "PM"  And Not FileCreatedTimeArray(0) = 12 Then
  649.             FileCreatedTimeArray(0) = FileCreatedTimeArray(0) + 12
  650.         End If
  651.         If Len(FileCreatedTimeArray(0)) < 2 Then
  652.             FileCreatedTimeArray(0) = "0" & FileCreatedTimeArray(0)
  653.         End If
  654.         'Give data requested
  655.         If FullorPart = 0 Then 'Date
  656.             FileCreatedOn = FileCreatedDate
  657.         End If
  658.         If FullorPart = 1 Then 'Time
  659.             FileCreatedOn = Join(FileCreatedTimeArray, " ")
  660.         End If
  661.         If FullorPart = 2 Then 'Date & Time
  662.             FileCreatedOn = FileCreatedDate & " " & Join(FileCreatedTimeArray, " ")
  663.         End If
  664.     End If
  665. End Function
  666. Function VidCat(VCFilename)
  667.     If Instr(VCFilename,SettingsDict.Item("NewsDVRFolder")) > 0 Then
  668.         VidCat = "news"
  669.     ElseIf Instr(VCFilename,SettingsDict.Item("ShowDVRFolder")) > 0 Then
  670.         VidCat = "show"
  671.     ElseIf Instr(VCFilename,SettingsDict.Item("MovieDVRFolder")) > 0 Then
  672.         VidCat = "movie"
  673.     Else
  674.         VidCat = "other"
  675.     End If
  676. End Function
  677. '-------------------Regex Functions---------------------------------------------------Regex Functions-------------------------
  678. '----------------------------------------------------Regex Functions----------------------------------------------------------
  679. '-----------------------------------------------------------------------------------------------------------------------------
  680.  
  681. ' The following functions are for extracting file name components for the new filename.
  682. ' If a date and or time is not included in the supplied filename it will be extracted
  683. ' from the file creation timestamp and used in its place.
  684. Function GetSE(GSEName)
  685.     fGSEName = GSEName
  686.     Set objRegEx = CreateObject("VBScript.RegExp")
  687.     objRegEx.Global = True
  688.     GENNameArray = Split(fGSEName, "\")
  689.     fGSEName = GENNameArray(UBound(GENNameArray))
  690.     fGSEName = Replace(fGSEName, " - ", "|")
  691. 'Find season/Episode in format: Sxx(-)Exx
  692.     objRegEx.Pattern = "[sS]+(\d{1,3})[eE]+(\d{1,3})"
  693.     Set myMatches = objRegEx.Execute(fGSEName)
  694.     For Each myMatch in myMatches
  695.         EpisodeNumArray = Split(Replace(LCase(myMatch.Value),"s",""),"e")
  696.         GetSE = EpisodeNumArray(0) & "," & EpisodeNumArray(1)       '<----- OUTPUT IS DETERMINED HERE IF Sxx(-)Exx
  697.         Exit Function
  698.     Next
  699. 'Find season/Episode in format: Episode xx-xx
  700.     objRegEx.Pattern = "[Ee]pisode[\ \-](\d{1,3})[\ \-](\d{1,3})"
  701.     Set myMatches = objRegEx.Execute(fGSEName)
  702.     For Each myMatch in myMatches
  703.         EpisodeNumArray = Split(Replace(myMatch.Value,"-"," ")," ")
  704.         GetSE = EpisodeNumArray(1) & "," & EpisodeNumArray(2)       '<----- OUTPUT IS DETERMINED HERE IF Episode xx-xx
  705.         Exit For
  706.     Next
  707. End Function
  708. 'Returns the Episode title, as in "Episode 123", used in news when there is at times no title.
  709. Function GetETitle(GENName)
  710.     fGENName = GENName
  711.     Set objRegEx = CreateObject("VBScript.RegExp")
  712.     objRegEx.Global = True
  713.     GENNameArray = Split(fGENName, "\")
  714.     fGENName = GENNameArray(UBound(GENNameArray))
  715.     fGENName = Replace(fGENName, " - ", "|")
  716. 'Find episode in format: SxxExx
  717.     objRegEx.Pattern = "[sS]+(\d{1,3})[eE]+(\d{1,3})"
  718.     Set myMatches = objRegEx.Execute(fGENName)
  719.     For Each myMatch in myMatches
  720.         EpisodeNumArray = Split(Replace(LCase(myMatch.Value),"s",""),"e")
  721.         GetETitle = "Episode " & EpisodeNumArray(1)
  722.         Exit For
  723.     Next
  724. 'Find episode in format: Episode xx-xx or Episode xxx
  725.     objRegEx.Pattern = "[Ee]pisode[\ \-](\d{1,3})[\ \-]*(\d{0,3})"
  726.     Set myMatches = objRegEx.Execute(fGENName)
  727.     For Each myMatch in myMatches
  728.         EpisodeNumArray = Split(Replace(myMatch.Value,"-"," ")," ")
  729.         'If the array size is 2, then it's only an episode, 3 would include the season.
  730.         If UBound(EpisodeNumArray) = 1 Then
  731.             GetETitle = "Episode " & EpisodeNumArray(1)
  732.         Elseif UBound(EpisodeNumArray) = 2 Then
  733.             GetETitle = "Episode " & EpisodeNumArray(2)
  734.         Else
  735.         End If
  736.         Exit For
  737.     Next
  738. End Function
  739. 'Determines if the episode was live, more useful on Cops shows. It looks for the word "live" anywhere but the title section.
  740. Function GetIsLive(GILName)
  741.     fGILName = GILName
  742.     Set objRegEx = CreateObject("VBScript.RegExp")
  743.     objRegEx.Global = True
  744.     GILNameArray = Split(fGILName, "\")
  745.     fGILName = GILNameArray(UBound(GILNameArray))
  746.     fGILName = Replace(fGILName, " - ", "|")
  747. 'Determine if it is live
  748.     GetIsLive = 0
  749.     objRegEx.Pattern = "(\|[a-z A-Z]*[lL]ive[a-z A-Z0-9]*)"
  750.     Set myMatches = objRegEx.Execute(fGILName)
  751.     For Each myMatch in myMatches
  752.         GetIsLive = 1
  753.     Next
  754. End Function
  755. 'Returns the Date, time, date & time or time in 12 hr for when a media file was created.
  756. Function GetDateTime(GDTName)
  757.     fGDTName = GDTName
  758.     Set objRegEx = CreateObject("VBScript.RegExp")
  759.     objRegEx.Global = True
  760.     GDTNameArray = Split(fGDTName, "\")
  761.     NewString = Replace(GDTNameArray(UBound(GDTNameArray)), " - ", "|") 'pipes make great boundaries
  762. 'date and time in format: YYYY-MM-DD HH MM SS with any ("." or "-" or " ") as delimiters
  763.     objRegEx.Pattern = "(\d{4})[\-\.\ ](\d{2})[\-\.\ ](\d{2}) (\d{2})[\.\-\ ](\d{2})[\.\-\ ](\d{2})"
  764.     Set myMatches = objRegEx.Execute(NewString)
  765.     For Each myMatch in myMatches
  766.         DateArray = Split(Replace(Replace(myMatch.Value,"-"," "),"."," ")," ")
  767.         If Int(DateArray(3)) = 0 And Int(DateArray(4)) = 0 And Int(DateArray(5)) = 0 Then
  768.             GetDateTime = DateArray(0) & "-" & DateArray(1) & "-" & DateArray(2) & " " & FileCreatedOn(fGDTName,1)
  769.         Else
  770.             GetDateTime = DateArray(0) & "-" & DateArray(1) & "-" & DateArray(2) & " " & DateArray(3) & " " & DateArray(4) & " " & DateArray(5)
  771.         End If
  772.     Next
  773. 'date only in format: MM.DD.YY/YYYY with any ("." or "-" or " ") as delimiters
  774.     If Len(GetDateTime) = 0 Then
  775.         objRegEx.Pattern = "(\d{1,2})[\.\-\ ](\d{1,2})[\.\-\ ](\d{2,4})"
  776.         Set myMatches = objRegEx.Execute(NewString)
  777.         For Each myMatch in myMatches
  778.             DateArray = Split(Replace(Replace(myMatch.Value,"-"," "),".", " ")," ")
  779.             If Len(DateArray(2)) = 2 Then
  780.                 DateArray(2) = 2000 + Int(DateArray(2))
  781.             End If
  782.             GetDateTime = DateArray(2) & "-" & DateArray(0) & "-" & DateArray(1) & " " & FileCreatedOn(fGDTName,1)
  783.         Next
  784.     End If
  785. 'If no date is found, make one from the file attributes
  786.     If Len(GetDateTime) = 0 Then
  787.         GetDateTime = FileCreatedOn(fGDTName,2)
  788.     End If
  789. End Function
  790. '------------------------------------------------------------------------------------------------
  791. 'Returns the show title, assumed to be the first part of the filename.
  792. Function GetTitle(GTName, ID)
  793.     fGTName = GTName
  794.     Set objRegEx = CreateObject("VBScript.RegExp")
  795.     objRegEx.Global = True
  796.     GTNameArray = Split(fGTName, "\")
  797.     fGTName = GTNameArray(UBound(GTNameArray))
  798.     fGTName = Replace(fGTName, " - ", "|")
  799. 'Title
  800.     objRegEx.Pattern = "(^[a-zA-Z\ \(\)0-9\-]*)"
  801.     Set myMatches = objRegEx.Execute(fGTName)
  802. 'If the title can not be determined, log and quit.
  803.     If myMatches.Count = 0 Then
  804.         ScriptLog "Unable to identify title in filename! Ignoring file.",1, ID
  805.         Wscript.Quit
  806.     End If
  807.     GetTitle = myMatches(0)
  808.     'remove the (year) string for proper matching to dictionary names.
  809.     TitleArray = Split(GetTitle," (")
  810.     GetTitle = TitleArray(0)
  811.     If UBound(TitleArray) > 0 Then
  812.         TitleYear = Replace(TitleArray(1),")","")
  813.     End If
  814.  
  815.     If VideoCatagory = "news" Then
  816.         If NewsDict.Exists(GetTitle) Then
  817.             GetTitle = NewsDict.Item(GetTitle)
  818.             ScriptLog "Title found in the News dictionary.",4, ID
  819.         Else
  820.             ScriptLog "Unable to locate title in the News dictionary.",2, ID
  821.         End If
  822.         DupTrack = 0
  823.         For Each ShowName In filesys.GetFolder(SettingsDict.Item("NewsLibFolder")).SubFolders
  824.             TitleArray = Split(ShowName.Name," (")
  825.             If TitleArray(0) = GetTitle Then
  826.                 DupTrack = DupTrack + 1
  827.                 GetTitle = ShowName.Name
  828.             End If
  829.         Next
  830.         If Duptrack > 1 Then
  831.             ScriptLog "More than 1 match was found for this news video.",2, ID
  832.         End If
  833.     'If all else fails, Create a new title and use it.
  834.         If DupTrack = 0 Then
  835.             ScriptLog "New show detected!",0, ID
  836.             GetTitle = GetTitle & " (" & TitleYear & ")"
  837.         End If
  838.     ElseIf VideoCatagory = "show" Then
  839.         If ShowDict.Exists(GetTitle) Then
  840.             GetTitle = ShowDict.Item(GetTitle)
  841.             ScriptLog "Title found in the TV Show dictionary.",4, ID
  842.         Else
  843.             ScriptLog "Unable to locate title in the TV Show dictionary.",2, ID
  844.         End If
  845.         DupTrack = 0
  846.         For Each ShowName In filesys.GetFolder(SettingsDict.Item("TVLibFolder")).SubFolders
  847.             TitleArray = Split(ShowName.Name," (")
  848.             If TitleArray(0) = GetTitle Then
  849.                 DupTrack = DupTrack + 1
  850.                 GetTitle = ShowName.Name
  851.             End If
  852.         Next
  853.         If Duptrack > 1 Then
  854.             ScriptLog "More than 1 match was found for this TV show.",2, ID
  855.         End If
  856.     'If all else fails, Create a new title and use it.
  857.         If DupTrack = 0 Then
  858.             ScriptLog "New show detected!",0, ID
  859.             GetTitle = GetTitle & " (" & TitleYear & ")"
  860.         End If
  861.     Elseif VideoCatagory = "movie" Then
  862.         If MovieDict.Exists(GetTitle) Then
  863.             GetTitle = MovieDict.Item(GetTitle)
  864.             ScriptLog "Title found in the Movie dictionary.",4, ID
  865.         Else
  866.             ScriptLog "Unable to locate title in the Movie dictionary.",2, ID
  867.         End If
  868.     Elseif VideoCatagory = "other" Then
  869.         If OtherDict.Exists(GetTitle) Then
  870.             GetTitle = OtherDict.Item(GetTitle)
  871.             ScriptLog "Title found in the Other dictionary.",4, ID
  872.         Else
  873.             ScriptLog "Unable to locate title in the Other dictionary.",2, ID
  874.         End If
  875.     End If
  876. End Function
  877. Function GetEpTitle(SrcFile,JobID)
  878.     GEName = SrcFile
  879.     Set objRegEx = CreateObject("VBScript.RegExp")
  880.     objRegEx.Global = True
  881.     GTNameArray = Split(GEName, "\")
  882.     GEName = GTNameArray(UBound(GTNameArray))
  883.     GTNameArray = Split(GEName, " - ")
  884.     GEName = GTNameArray(Ubound(GTNameArray))
  885. 'Title
  886.     objRegEx.Pattern = "([a-zA-Z\ \(\)0-9\-\,\?\!\$\%\&\#\@]*)"
  887.     Set myMatches = objRegEx.Execute(GEName)
  888. 'If the title can not be determined, log and quit.
  889.     If myMatches.Count = 0 Then
  890.         ScriptLog "Unable to identify show title in filename! Ignoring file.",4,JobID
  891.         Wscript.Quit
  892.     End If
  893.     GetEpTitle = myMatches(0)
  894. End Function
  895. '------------------------------------------------------------------------------------------------
  896. '------------------------------------------------------------------------------------------------
  897. '-------------------------------------SETUP ROUTINES---------------------------------------------
  898. '------------------------------------------------------------------------------------------------
  899. '------------------------------------------------------------------------------------------------
  900. '------------------------------------------------------------------------------------------------
  901. Sub MakeConfig()
  902.     WorkingFolder = filesys.GetParentFolderName(WScript.ScriptFullName) & "\"
  903.     NewConfigString =  "SettingsDict"
  904.     Done = False
  905.     If Not Filesys.FileExists(WorkingFolder & "PostProcess.cfg") Then
  906. '       ScriptLog "Main config file not found. Creating now.",2, ID
  907.     End If
  908. 'CLI
  909.     If SettingsDict.Exists("UserCLIApp") Then
  910.         If MsgBox("Do you want to change the location of MCEBuddy.UserCLI.exe from the following?" & vbcrlf & vbcrlf & SettingsDict.Item("UserCLIApp"), 4, "Change setting?")  = 7 Then
  911.             ThisInput = SettingsDict.Item("UserCLIApp")
  912.             Done = True
  913.         End If
  914.     End If
  915.     Do Until Done
  916.         ThisInput = UserInput("Find Folder", "Select the parent folder of MCEBuddy.UserCLI.exe" ,"",1) & "\MCEBuddy.UserCLI.exe"
  917.         If ThisInput = "" Then
  918.             WayOut
  919.         ElseIf Filesys.FileExists(ThisInput) Then
  920.             Done = true
  921.         Else
  922.             Msgbox "MCEBuddy.UserCLI.exe wasn't found in: " & vbcrlf & ThisInput & vbcrlf & "Please try again."
  923.         End If
  924.     Loop
  925.     NewConfigString =  NewConfigString & vbcrlf &  "UserCLIApp" & vbtab & ThisInput
  926. 'NewsLibFolder
  927.     Done = False
  928.     If SettingsDict.Exists("NewsLibFolder") Then
  929.         If MsgBox("Do you want to change the Plex news library location?" & vbcrlf & vbcrlf & SettingsDict.Item("NewsLibFolder"), 4, "Change setting?")  = 7 Then
  930.             ThisInput = SettingsDict.Item("NewsLibFolder")
  931.             Done = True
  932.         End If
  933.     End If
  934.     Do Until Done
  935.         ThisInput = UserInput("News Library", "Please select the Plex news library folder." ,"",1)
  936.         If ThisInput = "" Then
  937.             WayOut
  938.         ElseIf Filesys.FolderExists(ThisInput) Then
  939.             Done = true
  940.         Else
  941.             WayOut
  942.         End If
  943.     Loop
  944.     NewConfigString =  NewConfigString & vbcrlf &  "NewsLibFolder" & vbtab & ThisInput
  945. 'TVLibFolder
  946.     Done = False
  947.     If SettingsDict.Exists("TVLibFolder") Then
  948.         If MsgBox("Do you want to change the Plex TV show library location?" & vbcrlf & vbcrlf & SettingsDict.Item("TVLibFolder"), 4, "Change setting?")  = 7 Then
  949.             ThisInput = SettingsDict.Item("TVLibFolder")
  950.             Done = True
  951.         End If
  952.     End If
  953.     Do Until Done
  954.         ThisInput = UserInput("Show Library", "Please select the Plex TV show library folder." ,"",1)
  955.         If ThisInput = "" Then
  956.             WayOut
  957.         ElseIf Filesys.FolderExists(ThisInput) Then
  958.             Done = true
  959.         Else
  960.             WayOut
  961.         End If
  962.     Loop
  963.     NewConfigString =  NewConfigString & vbcrlf &  "TVLibFolder" & vbtab & ThisInput
  964. 'MovieLibFolder
  965.     Done = False
  966.     If SettingsDict.Exists("MovieLibFolder") Then
  967.         If MsgBox("Do you want to change the Plex Movie library location?" & vbcrlf & vbcrlf & SettingsDict.Item("MovieLibFolder"), 4, "Change setting?")  = 7 Then
  968.             ThisInput = SettingsDict.Item("MovieLibFolder")
  969.             Done = True
  970.         End If
  971.     End If
  972.     Do Until Done
  973.         ThisInput = UserInput("Movie Library", "Please select the Plex movie library folder." ,"",1)
  974.         If ThisInput = "" Then
  975.             WayOut
  976.         ElseIf Filesys.FolderExists(ThisInput) Then
  977.             Done = true
  978.         Else
  979.             WayOut
  980.         End If
  981.     Loop
  982.     NewConfigString =  NewConfigString & vbcrlf &  "MovieLibFolder" & vbtab & ThisInput
  983. 'OtherLibFolder
  984.     Done = False
  985.     If SettingsDict.Exists("OtherLibFolder") Then
  986.         If MsgBox("Do you want to change the Plex Other library location?" & vbcrlf & vbcrlf & SettingsDict.Item("OtherLibFolder"), 4, "Change setting?")  = 7 Then
  987.             ThisInput = SettingsDict.Item("OtherLibFolder")
  988.             Done = True
  989.         End If
  990.     End If
  991.     Do Until Done
  992.         ThisInput = UserInput("Other Library", "Please select the Plex OTHER library folder." ,"",1)
  993.         If ThisInput = "" Then
  994.             WayOut
  995.         ElseIf Filesys.FolderExists(ThisInput) Then
  996.             Done = true
  997.         Else
  998.             WayOut
  999.         End If
  1000.     Loop
  1001.     NewConfigString =  NewConfigString & vbcrlf &  "OtherLibFolder" & vbtab & ThisInput
  1002. 'Encodershares
  1003. 'NewsDVRFolder
  1004.     Done = False
  1005.     If SettingsDict.Exists("NewsDVRFolder") Then
  1006.         If MsgBox("Do you want to change the Plex News DVR folder?" & vbcrlf & vbcrlf & SettingsDict.Item("NewsDVRFolder"), 4, "Change setting?")  = 7 Then
  1007.             ThisInput = SettingsDict.Item("NewsDVRFolder")
  1008.             Done = True
  1009.         End If
  1010.     End If
  1011.     Do Until Done
  1012.         ThisInput = UserInput("News DVR", "Please select the Plex News DVR folder." ,"",1)
  1013.         If ThisInput = "" Then
  1014.             WayOut
  1015.         ElseIf Filesys.FolderExists(ThisInput) Then
  1016.             Done = true
  1017.         Else
  1018.             WayOut
  1019.         End If
  1020.     Loop
  1021.     NewConfigString =  NewConfigString & vbcrlf &  "NewsDVRFolder" & vbtab & ThisInput
  1022. 'ShowDVRFolder
  1023.     Done = False
  1024.     If SettingsDict.Exists("ShowDVRFolder") Then
  1025.         If MsgBox("Do you want to change the Plex TV Show DVR folder?" & vbcrlf & vbcrlf & SettingsDict.Item("ShowDVRFolder"), 4, "Change setting?")  = 7 Then
  1026.             ThisInput = SettingsDict.Item("ShowDVRFolder")
  1027.             Done = True
  1028.         End If
  1029.     End If
  1030.     Do Until Done
  1031.         ThisInput = UserInput("TV Show DVR", "Please select the Plex TV Show DVR folder." ,"",1)
  1032.         If ThisInput = "" Then
  1033.             WayOut
  1034.         ElseIf Filesys.FolderExists(ThisInput) Then
  1035.             Done = true
  1036.         Else
  1037.             WayOut
  1038.         End If
  1039.     Loop
  1040.     NewConfigString =  NewConfigString & vbcrlf &  "ShowDVRFolder" & vbtab & ThisInput
  1041. 'MovieDVRFolder
  1042.     Done = False
  1043.     If SettingsDict.Exists("MovieDVRFolder") Then
  1044.         If MsgBox("Do you want to change the Plex Movie DVR folder?" & vbcrlf & vbcrlf & SettingsDict.Item("MovieDVRFolder"), 4, "Change setting?")  = 7 Then
  1045.             ThisInput = SettingsDict.Item("MovieDVRFolder")
  1046.             Done = True
  1047.         End If
  1048.     End If
  1049.     Do Until Done
  1050.         ThisInput = UserInput("Movie DVR", "Please select the Plex Movie DVR folder." ,"",1)
  1051.         If ThisInput = "" Then
  1052.             WayOut
  1053.         ElseIf Filesys.FolderExists(ThisInput) Then
  1054.             Done = true
  1055.         Else
  1056.             WayOut
  1057.         End If
  1058.     Loop
  1059.     NewConfigString =  NewConfigString & vbcrlf &  "MovieDVRFolder" & vbtab & ThisInput
  1060. 'OtherDVRFolder
  1061.     Done = False
  1062.     If SettingsDict.Exists("OtherDVRFolder") Then
  1063.         If MsgBox("Do you want to change the Plex Other DVR folder?" & vbcrlf & vbcrlf & SettingsDict.Item("OtherDVRFolder"), 4, "Change setting?")  = 7 Then
  1064.             ThisInput = SettingsDict.Item("OtherDVRFolder")
  1065.             Done = True
  1066.         End If
  1067.     End If
  1068.     Do Until Done
  1069.         ThisInput = UserInput("Other DVR", "Please select the Plex Other DVR folder." ,"",1)
  1070.         If ThisInput = "" Then
  1071.             WayOut
  1072.         ElseIf Filesys.FolderExists(ThisInput) Then
  1073.             Done = true
  1074.         Else
  1075.             WayOut
  1076.         End If
  1077.     Loop
  1078.     NewConfigString =  NewConfigString & vbcrlf &  "OtherDVRFolder" & vbtab & ThisInput
  1079.     Done = False
  1080.     If SettingsDict.Exists("EncoderShares") Then
  1081.         If MsgBox("Do you want to change the folder where all network shares for MCEB engines are located?" & vbcrlf & vbcrlf & SettingsDict.Item("EncoderShares"), 4, "Change setting?")  = 7 Then
  1082.             ThisInput = SettingsDict.Item("EncoderShares")
  1083.             Done = True
  1084.         End If
  1085.     End If
  1086.     Do Until Done
  1087.         ThisInput = UserInput("Share Root", "Please select the root folder where all shared folders for MCEB engines are located." ,"",1)
  1088.         If ThisInput = "" Then
  1089.             WayOut
  1090.         ElseIf Filesys.FolderExists(ThisInput) Then
  1091.             Done = true
  1092.         Else
  1093.             WayOut
  1094.         End If
  1095.     Loop
  1096.     NewConfigString =  NewConfigString & vbcrlf &  "EncoderShares" & vbtab & ThisInput
  1097. 'EncoderStockPile
  1098.     Done = False
  1099.     If SettingsDict.Exists("EncoderStockPile") Then
  1100.         If MsgBox("Do you want to change the temporary media storage folder? It is suggested to be on the same drive as the DVR." & vbcrlf & vbcrlf & SettingsDict.Item("EncoderStockPile"), 4, "Change setting?")  = 7 Then
  1101.             ThisInput = SettingsDict.Item("EncoderStockPile")
  1102.             Done = True
  1103.         End If
  1104.     End If
  1105.     Do Until Done
  1106.         ThisInput = UserInput("Share Root", "Please select the encoder buffer folder." ,"",1)
  1107.         If ThisInput = "" Then
  1108.             WayOut
  1109.         ElseIf Filesys.FolderExists(ThisInput) Then
  1110.             Done = true
  1111.         Else
  1112.             WayOut
  1113.         End If
  1114.     Loop
  1115.     NewConfigString =  NewConfigString & vbcrlf &  "EncoderStockPile" & vbtab & ThisInput
  1116. 'AutoDisable
  1117.     If SettingsDict.Exists("AutoDisable") Then
  1118.         If SettingsDict.Item("AutoDisable") = 1 Then
  1119.             SetTo = "Enabled"
  1120.         Else
  1121.             SetTo = "Disabled"
  1122.         End If
  1123.     Else
  1124.         SetTo = "Enabled"
  1125.     End If
  1126.     If MsgBox("Do you want to auto disable unresponsive encoders?" & vbcrlf & vbcrlf & "Currently set to: " & SetTo, 4, "Change setting?")  = 6 Then
  1127.         NewConfigString =  NewConfigString & vbcrlf &  "AutoDisable" & vbtab & "1"
  1128.     Else
  1129.         NewConfigString =  NewConfigString & vbcrlf &  "AutoDisable" & vbtab & "0"
  1130.     End If
  1131. 'AutoReallocate
  1132.     If SettingsDict.Exists("AutoReallocate") Then
  1133.         If SettingsDict.Item("AutoReallocate") = 1 Then
  1134.             SetTo = "Enabled"
  1135.         Else
  1136.             SetTo = "Disabled"
  1137.         End If
  1138.     Else
  1139.         SetTo = "Enabled"
  1140.     End If
  1141.     If MsgBox("Do you want media to be automatically reassigned when an unresponsive encoder if found?" & vbcrlf & vbcrlf & "Currently set to: " & SetTo, 4, "Change setting?")  = 6 Then
  1142.         NewConfigString =  NewConfigString & vbcrlf &  "AutoReallocate" & vbtab & "1"
  1143.     Else
  1144.         NewConfigString =  NewConfigString & vbcrlf &  "AutoReallocate" & vbtab & "0"
  1145.     End If
  1146. 'FastEncoderList
  1147.     Done = False
  1148.     If SettingsDict.Exists("FastEncoderList") Then
  1149.         If Not MsgBox("Do you want to classify any of the MCEB engines as fast? These will tend to have larger jobs assigned." & vbcrlf & vbcrlf & "Currently included: " & SettingsDict.Item("FastEncoderList"), 4, "Change setting?")  = 6 Then
  1150.             ThisInput = SettingsDict.Item("FastEncoderList")
  1151.             Done = True
  1152.         End If
  1153.     End If
  1154.     If Not Done Then
  1155.         ThisInput = UserInput("Fast Encoders", "Please make a comma delimited list of which engines involved are to be favored for large files." ,"",0)
  1156.     End If
  1157.     NewConfigString =  NewConfigString & vbcrlf &  "FastEncoderList" & vbtab & Replace(ThisInput," ","")
  1158. 'MedEncoderList
  1159.     Done = False
  1160.     If SettingsDict.Exists("MedEncoderList") Then
  1161.         If Not MsgBox("Do you want to classify any of the MCEB engines as average speed? These will tend to have medium sized jobs assigned." & vbcrlf & vbcrlf & "Currently included: " & SettingsDict.Item("MedEncoderList"), 4, "Change setting?")  = 6 Then
  1162.             ThisInput = SettingsDict.Item("MedEncoderList")
  1163.             Done = True
  1164.         End If
  1165.     End If
  1166.     If Not Done Then
  1167.         ThisInput = UserInput("Medium Speed Encoders", "Please make a comma delimited list of which engines involved are to be favored for medium sized files." ,"",0)
  1168.     End If
  1169.     NewConfigString =  NewConfigString & vbcrlf &  "MedEncoderList" & vbtab & Replace(ThisInput," ","")
  1170. 'SlowEncoderList
  1171.     Done = False
  1172.     If SettingsDict.Exists("SlowEncoderList") Then
  1173.         If Not MsgBox("Do you want to classify any of the MCEB engines as slow? These will tend to have small sized jobs assigned." & vbcrlf & vbcrlf & SettingsDict.Item("SlowEncoderList"), 4, "Change setting?")  = 6 Then
  1174.             ThisInput = SettingsDict.Item("SlowEncoderList")
  1175.             Done = True
  1176.         End If
  1177.     End If
  1178.     If Not Done Then
  1179.         ThisInput = UserInput("Slow Encoders", "Please make a comma delimited list of which engines involved are to be favored for small files." ,"",0)
  1180.     End If
  1181.     NewConfigString =  NewConfigString & vbcrlf &  "SlowEncoderList" & vbtab & Replace(ThisInput," ","")
  1182. 'ALargeFile
  1183.     Done = False
  1184.     If SettingsDict.Exists("ALargeFile") Then
  1185.         If SettingsDict.Item("ALargeFile") > 0 Then
  1186.             ThisSize = SettingsDict.Item("ALargeFile")
  1187.         Else
  1188.             ThisSize = 4
  1189.         End If
  1190.         If MsgBox("Do you want to change what is considered a LARGE media file?" & vbcrlf & vbcrlf & "Currently set to: " & ThisSize & " gb", 4, "Change setting?")  = 7 Then
  1191.             ThisSize = SettingsDict.Item("ALargeFile")
  1192.             Done = True
  1193.         End If
  1194.     End If
  1195.     Do Until Done
  1196.         ThisSize = UserInput("Large media file", "In gb, please specify what is considered a LARGE media file." ,"4",0)
  1197.         If ThisSize > 0 Then
  1198.             Done = True
  1199.         Else
  1200.             Msgbox "That is an invalid value, Please try again."
  1201.         End If
  1202.     Loop
  1203.     NewConfigString =  NewConfigString & vbcrlf &  "ALargeFile" & vbtab & ThisSize
  1204. 'AMedFile
  1205.     Done = False
  1206.     If SettingsDict.Exists("AMedFile") Then
  1207.         If SettingsDict.Item("AMedFile") > 0 Then
  1208.             ThisSize = SettingsDict.Item("AMedFile")
  1209.         Else
  1210.             ThisSize = 2
  1211.         End If
  1212.         If MsgBox("Do you want to change what is considered a MEDIUM sized media file?" & vbcrlf & vbcrlf & "Currently set to: " & ThisSize & " gb", 4, "Change setting?")  = 7 Then
  1213.             ThisSize = SettingsDict.Item("AMedFile")
  1214.             Done = True
  1215.         End If
  1216.     End If
  1217.     Do Until Done
  1218.         ThisSize = UserInput("Medium media file", "In gb, please specify what is considered a MEDIUM sized media file." ,"2",0)
  1219.         If ThisSize > 0 Then
  1220.             Done = True
  1221.         Else
  1222.             Msgbox "That is an invalid value, Please try again."
  1223.         End If
  1224.     Loop
  1225.     NewConfigString =  NewConfigString & vbcrlf &  "AMedFile" & vbtab & ThisSize
  1226. 'QueueGuage
  1227.     Done = False
  1228.     If SettingsDict.Exists("QueueGuage") Then
  1229.         If MsgBox("Do you want to change what is used to determine an encoders queue size?" & vbcrlf & vbcrlf & "Currently set to: " & SettingsDict.Item("QueueGuage"), 4, "Change setting?")  = 7 Then
  1230.             ThisInput = SettingsDict.Item("QueueGuage")
  1231.             Done = True
  1232.         End If
  1233.     End If
  1234.     If Not Done Then
  1235.         If MsgBox("Use total file size of the queue to determine an encoders queue size, otherwise file count will be used.", 4, "Change setting?")  = 6 Then
  1236.             ThisInput = "size"
  1237.         Else
  1238.             ThisInput = "length"
  1239.         End If
  1240.     End If
  1241.     NewConfigString =  NewConfigString & vbcrlf &  "QueueGuage" & vbtab & ThisInput
  1242. 'EncoderDict
  1243.     NewConfigString =  NewConfigString & vbcrlf &  "EncoderDict"
  1244.     For Each EncoderName In EncoderDict.Keys()
  1245.         Done = False
  1246.         If EncoderDict.Exists(EncoderName) Then
  1247.             If MsgBox("Do you want to change the passmark score for " & EncoderName & "." & vbcrlf & vbcrlf & "Currently set to: " & EncoderDict.Item(EncoderName), 4, "Change setting?")  = 7 Then
  1248.                 NewConfigString =  NewConfigString & vbcrlf &  EncoderName & vbtab & EncoderDict.Item(EncoderName)
  1249.                 Done = True
  1250.             End If
  1251.         End If
  1252.         Do Until Done
  1253.             ThisInput = UserInput("CPU Passmark", "Please enter the passmark score for " & EncoderName & vbcrlf & vbcrlf & "See http://cpubenchmark.net for lookup.","6000",0)
  1254.             If ThisInput > 100 Then
  1255.                 NewConfigString =  NewConfigString & vbcrlf &  EncoderName & vbtab & ThisInput
  1256.                 Done = True
  1257.             Else
  1258.                 Msgbox "That is an invalid value, please try again."
  1259.             End If
  1260.         Loop
  1261.     Next   
  1262.     NewConfigString =  NewConfigString & vbcrlf &  "IgnoreDict"
  1263.     NewConfigString =  NewConfigString & vbcrlf &  "'----------------------------------"
  1264.     NewConfigString =  NewConfigString & vbcrlf &  "eof"
  1265.     NewConfigString =  NewConfigString & vbcrlf &  "'----------------------------------"
  1266.     NewConfigString =  NewConfigString & vbcrlf &  "You may write anything you like after the eof tag."
  1267.     If MsgBox("Save new configuration to file?", 4, "Save Settings?")  = 6 Then
  1268.         Set NewConfigFile = filesys.CreateTextFile(WorkingFolder & "PostProcess.cfg", True)
  1269.         NewConfigFile.WriteLine NewConfigString
  1270.         NewConfigFile.Close
  1271.     Else
  1272.         Wscript.Quit
  1273.     End If
  1274.     If Not Filesys.FileExists(WorkingFolder & "NewsTitles.cfg") Then
  1275.         Set NewConfigFile = filesys.CreateTextFile(WorkingFolder & "NewsTitles.cfg", True)
  1276.         ScriptLog "News title dictionary not found. Creating now.",2, ID
  1277.         NewConfigFile.WriteLine "'The title translation dictionary. Used to maintain consistent show titles and to correct/append names."
  1278.         NewConfigFile.WriteLine "'This may eventually be discontinued when sources are more uniform in naming."
  1279.         NewConfigFile.WriteLine "'FORMAT : a show name<-TAB->The formatted show name"
  1280.         NewConfigFile.WriteLine "'The next line sets the dictionary name to load the following entries into."
  1281.         NewConfigFile.WriteLine "'----------------------------------"
  1282.         NewConfigFile.WriteLine "NewsDict"
  1283.         NewConfigFile.WriteLine "'----------------------------------"
  1284.         NewConfigFile.WriteLine "'CBS"
  1285.         NewConfigFile.WriteLine "cbs 2 news ny at 5pm   CBS 2 News NY at 5PM"
  1286.         NewConfigFile.WriteLine "'----------------------------------"
  1287.         NewConfigFile.WriteLine "eof"
  1288.         NewConfigFile.WriteLine "'----------------------------------"
  1289.         NewConfigFile.WriteLine "You may write anything you like after the eof tag."
  1290.         NewConfigFile.Close
  1291.     End If
  1292.     If Not Filesys.FileExists(WorkingFolder & "MovieTitles.cfg") Then
  1293.         Set NewConfigFile = filesys.CreateTextFile(WorkingFolder & "MovieTitles.cfg", True)
  1294.         ScriptLog "Movie title dictionary not found. Creating now.",2, ID
  1295.         NewConfigFile.WriteLine "'----------------------------------"
  1296.         NewConfigFile.WriteLine "MovieDict"
  1297.         NewConfigFile.WriteLine "'----------------------------------"
  1298.         NewConfigFile.WriteLine "Mojin- The Lost Legend Mojin- The Lost Legend"
  1299.         NewConfigFile.WriteLine "Mojin_ The Lost Legend Mojin- The Lost Legend"
  1300.         NewConfigFile.WriteLine "'----------------------------------"
  1301.         NewConfigFile.WriteLine "eof"
  1302.         NewConfigFile.WriteLine "'----------------------------------"
  1303.         NewConfigFile.WriteLine "You may write anything you like after the eof tag."
  1304.         NewConfigFile.Close
  1305.     End If
  1306.     If Not Filesys.FileExists(WorkingFolder & "ShowTitles.cfg") Then
  1307.         Set NewConfigFile = filesys.CreateTextFile(WorkingFolder & "ShowTitles.cfg", True)
  1308.         ScriptLog "TV Show title dictionary not found. Creating now.",2, ID
  1309.         NewConfigFile.WriteLine "'----------------------------------"
  1310.         NewConfigFile.WriteLine "ShowDict"
  1311.         NewConfigFile.WriteLine "'----------------------------------"
  1312.         NewConfigFile.WriteLine "Genius Genius"
  1313.         NewConfigFile.WriteLine "National Geographic Presents - Genius  Genius"
  1314.         NewConfigFile.WriteLine "'----------------------------------"
  1315.         NewConfigFile.WriteLine "eof"
  1316.         NewConfigFile.WriteLine "'----------------------------------"
  1317.         NewConfigFile.WriteLine "You may write anything you like after the eof tag."
  1318.         NewConfigFile.Close
  1319.     End If
  1320.     NeedSetup = False
  1321. End Sub
  1322. 'QType - 0=string 1=folder 2=y/n
  1323. Function UserInput(ITitle,QString,CValue,QType)
  1324.     If QType = 0 Then
  1325.         UserEnteredString = InputBox(QString, ITitle, CValue)
  1326.         If UserEnteredString = "" Then
  1327.             Exit Function
  1328.         Else
  1329.             UserInput = UserEnteredString
  1330.         End If
  1331.     ElseIf QType = 1 Then
  1332.         UserSelectedFolder = SelectFolder("",QString)
  1333.         If Filesys.FolderExists(UserSelectedFolder) Then
  1334.             UserInput = UserSelectedFolder
  1335.         Else
  1336.             WayOut
  1337.             Exit Function
  1338.         End If
  1339.     End If
  1340.  
  1341. End Function
  1342. Function SelectFolder( myStartFolder,myPromptString )
  1343. ' This function opens a "Select Folder" dialog and will
  1344. ' return the fully qualified path of the selected folder
  1345. '
  1346. ' Argument:
  1347. '     myStartFolder    [string]    the root folder where you can start browsing;
  1348. '                                  if an empty string is used, browsing starts
  1349. '                                  on the local computer
  1350. '
  1351. ' Returns:
  1352. ' A string containing the fully qualified path of the selected folder
  1353. '
  1354. ' Written by Rob van der Woude
  1355. ' http://www.robvanderwoude.com
  1356.  
  1357.     ' Standard housekeeping
  1358.    Dim objFolder, objItem, objShell
  1359.    
  1360.     ' Custom error handling
  1361.    On Error Resume Next
  1362.     SelectFolder = vbNull
  1363.  
  1364.     ' Create a dialog object
  1365.    Set objShell  = CreateObject( "Shell.Application" )
  1366.     Set objFolder = objShell.BrowseForFolder( 0, myPromptString, 0, myStartFolder )
  1367.  
  1368.     ' Return the path of the selected folder
  1369.    If IsObject( objfolder ) Then SelectFolder = objFolder.Self.Path
  1370.  
  1371.     ' Standard housekeeping
  1372.    Set objFolder = Nothing
  1373.     Set objshell  = Nothing
  1374.     On Error Goto 0
  1375. End Function
  1376. Sub WayOut()
  1377.     If MsgBox("Are you sure you want to quit setup?", 4, "Quit?") = 6 Then
  1378.         Wscript.Quit
  1379.     End If
  1380. End Sub
Advertisement
Add Comment
Please, Sign In to add comment