Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 'filename format basic standards:
- 'News
- '\Title\Season 2017\Title (year) - YYYY-M-D HH MM SS - Episode NN
- 'TV Show
- '\Title\Season 3\Title (Year) - SxxExx - Title
- 'Movie
- '\Title (year)
- 'FOR HELP WITH VBSCRIPT, SEE DEVGURU http://www.devguru.com/content/technologies/vbscript/index.html
- 'This script will handle any file type, but made for common video files.
- 'Turn OFF word wrap!!!
- 'On Windows, get the Notepad++ program for working on files like this. https://notepad-plus-plus.org/ , don't be a chump.
- 'An attempt was made to write the following programming to allow changes to be made easier in any part of the logic (main
- 'code) or function (functions and subs) of the script.
- 'The following was developed using the following hardware:
- '1 Silicon Dust Homerun Prime (3 cable tuner)
- 'Multiprocessor PC for Plex server and MCEB Engine.
- 'Extra PC attached to LAN with a running MCEB engine.
- 'All platforms were Windows 7
- 'Gigabit network.
- 'Note!
- '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
- 'to be an original file from a DVR, otherwise there is no guarantee that it will update correctly. For instance, a remux
- 'or re-encoded copy of any kind is no good. It will use the time of THAT process.
- 'There are currently 2 main functions of this script.
- '1 - To automatically make adjustments to the DVR recording filenames. (USER CONFIGURABLE)
- '2 - Allocate recordings to MCEB engines on the same LAN for processing prior to being added to Plex.
- 'Share the load or dump all encoding to other PCs from the Plex server.
- 'Redistribute pending videos from off-line encoders to maintain the work flow. **in development**
- 'The current logic is as follows.
- 'Get input filename w/ path
- 'Make sure the file is valid.
- 'Set programming variables to likely needed information. This includes:
- 'Tile, SE, Episode, Date/time and if live.
- 'Destination folders
- 'User defined settings
- 'Determine the new filename (Default is no change)
- 'Evaluate MCEB Encoders by status and current queue sizes
- 'Move jobs from off-line encoder folders to dump folder and run a new instance of the script for them.
- 'Evaluate Size of media file.
- 'Determine if a prefered encoder is eligible
- 'Fallback upon available encoders, default to dump folder
- 'Assign task, move and rename file to encoder's shared folder
- 'Delete source folder (if empty)
- 'Log overall status, Upcoming jobs quantity and if any are older than 2 hours which are likely failed recordings.
- '------------------------------------------------------ SO I DO DECLARE-----------------------------------------------------
- 'This is where all global variables are created. Global means that once created, here at the top, any part of the script
- '(main code, functs and subs) can read and write to them. Variables created inside a funct or sub are only valid within
- 'that funct or sub. Variables are used to store any data you process in the script, like the filename you are processing,
- 'or the tile and episode data.
- Dim TotalFiles, BatchMode, IsStockpile, OfflineEncoderlist, NewsFolderName, TVFolderName, MovieFolderName, StockpileName, MediaType, NeedSetup, VideoCatagory
- Dim filesys, WshShell, SettingsDict, NewsDict, EncoderDict, IgnoreDict, ShowDict, MovieDict, CurrentLoadFile
- 'Create objects for global use
- Set filesys = CreateObject("Scripting.FileSystemObject")
- Set WshShell = CreateObject("WScript.Shell")
- NeedSetup = False
- 'Create the dictionaries and set to case-insensitive
- Set SettingsDict = CreateObject ("Scripting.Dictionary")
- SettingsDict.CompareMode = vbTextCompare
- Set EncoderDict = CreateObject ("Scripting.Dictionary")
- EncoderDict.CompareMode = vbTextCompare
- Set NewsDict = CreateObject ("Scripting.Dictionary")
- NewsDict.CompareMode = vbTextCompare
- Set ShowDict = CreateObject ("Scripting.Dictionary")
- ShowDict.CompareMode = vbTextCompare
- Set MovieDict = CreateObject ("Scripting.Dictionary")
- MovieDict.CompareMode = vbTextCompare
- 'Set OtherDict = CreateObject ("Scripting.Dictionary")
- ' OtherDict.CompareMode = vbTextCompare
- 'Load Main config file
- LoadFile "PostProcess.cfg", "load"
- 'Load News Title dictonary
- LoadFile "NewsTitles.cfg", "load"
- 'Load Show Title dictonary
- LoadFile "ShowTitles.cfg", "load"
- 'Load Movie Title dictonary
- LoadFile "MovieTitles.cfg", "load"
- If NeedSetup = True Then
- MakeConfig
- End If
- '---------------------------------------------------------------------------------------------------------------------------
- '---------------------------------------------------------------------------------------------------------------------------
- '----------------------------------------------------- Begin Main Code -----------------------------------------------------
- '---------------------------------------------------------------------------------------------------------------------------
- '---------------------------------------------------------------------------------------------------------------------------
- 'setting the source filename of the file being processed, to a variable. Quitting if null.
- If WScript.Arguments.Count > 0 then
- InputRequest = WScript.Arguments(0)
- Else
- ScriptLog "Empty request. Running setup.", 4, "000000"
- MakeConfig
- End If
- TotalFiles = 0
- 'Determine if it is a folder or a file being processed.
- If filesys.FileExists(InputRequest) Then
- 'If it's just a file, send it through...
- BatchMode = 0
- IsStockpile = False
- 'Determine the video catagory so we know what filename format and folders to use.
- VideoCatagory = VidCat(InputRequest)
- 'Send the file through for processing.
- MainLogic InputRequest
- Elseif filesys.FolderExists(InputRequest) Then
- BatchMode = 1
- If InputRequest = SettingsDict.Item("EncoderStockPile") Then
- IsStockpile = True
- Else
- IsStockpile = False
- End If
- ScriptLog "Batch processing started.", 4, "000000"
- 'If it is a folder then lets enumerate all files within and send them each through...
- RecursiveSearch InputRequest
- End If
- 'Only if a batch of files were processed, report total count.
- If filesys.FolderExists(InputRequest) Then
- ScriptLog "A total of [ " & TotalFiles & " ] files were batch processed.", 4, "000000"
- End If
- Set WshShellExec = Nothing
- Set filesys = Nothing
- WScript.Quit
- 'The end
- '---------------------------------------------------------------------------------------------------------------------------
- '---------------------------------------------------------------------------------------------------------------------------
- '----------------------------------------------- Begin Main Sub Routine ----------------------------------------------------
- '---------------------------------------------------------------------------------------------------------------------------
- '---------------------------------------------------------------------------------------------------------------------------
- Sub MainLogic(SrcFile)
- Dim JobID, DVRGrabSubFolder, DVRGrabFolder, SrcFileName, SrcFileExt, SrcTitle, SrcDateTime, SrcSE, SrcEpTitle, SavedEncoderList, NewFileName
- '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.
- TotalFiles = TotalFiles + 1
- Randomize
- JobID = Int((999999 - 100000 + 1) * Rnd + 100000)
- 'Log the new request.
- ScriptLog "New recording! [" & SrcFile & "]", 0, JobID
- '-------------------------------------------------------------------------------------------------------------------------------------
- '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
- 'then to re-run a function for the same value. So here are a few to use.
- '-------------------------------------------------------------------------------------------------------------------------------------
- 'SrcFile the file being processed, with full path. It's already set, just listing it.
- 'DVRGrabSubFolder is the full path to the RANDOM34AE71CF.... folder that the new recording was born in, inside the .grab folder.
- DVRGrabSubFolder = Left(SrcFile,InStrRev(SrcFile,"\") - 1)
- 'DVRGrabFolder is the full path to the .grab folder of the recording being processed.
- DVRGrabFolder = Left(SrcFile,InStrRev(DVRGrabSubFolder,"\") - 1)
- 'SrcLongNameArray is the entire folder structure and filename in an array.
- SrcLongNameArray = Split(SrcFile, "\")
- 'SrcFileName is the existing filename without subfolders or slashes.
- SrcFileName = SrcLongNameArray(UBound(SrcLongNameArray))
- 'SrcFileArray is the existing filename in an array to separate the name and ext.
- SrcFileArray = Split(SrcFileName, ".")
- 'SrcFileExt is the file extension. (.avi,.mpg,.mp4,.mkv....) NOTE: this includes the dot "."
- SrcFileExt = "." & SrcFileArray(UBound(SrcFileArray))
- 'SrcTitle is the show title.
- SrcTitle = GetTitle(SrcFile, JobID)
- 'SrcEpName is the episode title.
- SrcEpName = GetEpTitle(SrcFile, JobID)
- 'SrcDateTime is the date and time of the recording
- SrcDateTime = GetDateTime(SrcFile)
- 'SrcSE is the SxxExx of the show
- SEArray = Split(GetSE(SrcFile), ",")
- 'SrcSE is the SxxExx of the show
- SrcSE = "S" & SEArray(0) & "E" & SEArray(0)
- 'SrcS is the bare season number
- SrcS = SEArray(0)
- 'SrcE is the bare episode number
- SrcE = SEArray(1)
- 'SrcEpTitle is the Episode number used often as a substitute title when there is no title.
- SrcEpTitle = GetETitle(SrcFile)
- 'SavedEncoderList is a list of all tested and available MCEB engines.
- SavedEncoderList = AvailableEncoderList(JobID) 'this function will return available and offline encoders to their respective array/variables
- 'AvailableEncoderArray is an array of the content of SavedEncoderList
- AvailableEncoderArray = Split(SavedEncoderList, ",")
- 'OfflineEncoderArray is an array of all hosts that are off-line (not including stopped encoders)
- OfflineEncoderArray = Split(OfflineEncoderlist,",")
- '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.
- NewsFolderName = Mid(SettingsDict.Item("NewsLibFolder"),InStrRev(SettingsDict.Item("NewsLibFolder"),"\") + 1 ,Len(SettingsDict.Item("NewsLibFolder"))-InStrrev(SettingsDict.Item("NewsLibFolder"),"\"))
- TVFolderName = Mid(SettingsDict.Item("TVLibFolder"),InStrRev(SettingsDict.Item("TVLibFolder"),"\") + 1 ,Len(SettingsDict.Item("TVLibFolder"))-InStrrev(SettingsDict.Item("TVLibFolder"),"\"))
- MovieFolderName = Mid(SettingsDict.Item("MovieLibFolder"),InStrRev(SettingsDict.Item("MovieLibFolder"),"\") + 1 ,Len(SettingsDict.Item("MovieLibFolder"))-InStrrev(SettingsDict.Item("MovieLibFolder"),"\"))
- OtherFolderName = Mid(SettingsDict.Item("OtherLibFolder"),InStrRev(SettingsDict.Item("OtherLibFolder"),"\") + 1 ,Len(SettingsDict.Item("OtherLibFolder"))-InStrrev(SettingsDict.Item("OtherLibFolder"),"\"))
- StockpileName = Mid(SettingsDict.Item("EncoderStockPile"),InStrRev(SettingsDict.Item("EncoderStockPile"),"\") + 1 ,Len(SettingsDict.Item("EncoderStockPile"))-InStrrev(SettingsDict.Item("EncoderStockPile"),"\"))
- 'Available functions: See actual function below for more information.
- 'FileCreatedOn(filename,x) Values of x:(0=Date 1=Time(24 hr) 2=Both(24 hr) 3=Time(AM/PM))
- 'UpcomingRecordings(URNumber) Values of URNumber:(0=Count of ALL upcoming 1=Count of all older than 2 hrs)
- '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.
- '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)
- 'AvailableEncoderList(JobID)
- 'Qlength(QName) Values of QName:("cpu1") The name of an available encoders, eg. one name like from AEList
- 'EngineStatus(ESName) Values of ESName:("cpu1") The name of an available encoder, eg. one name like from AEList
- 'VidSizeRange(VSRName) Values of VSRName ("c:\full\path\to\file.ts")
- '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
- 'GetSE(GSEName) Values of GSEName:("c:\full\path\to\file.ts" or just "file.ts") This function doesn't require the full path.
- 'GetETitle(GENName) Values of GENName:("c:\full\path\to\file.ts" or just "file.ts") This function doesn't require the full path.
- 'GetIsLive(GILName) Values of GILName:("c:\full\path\to\file.ts" or just "file.ts") This function doesn't require the full path.
- 'GetDateTime(GDTName) Values of GDTName:("c:\full\path\to\file.ts") This function requires the full path.
- 'GetTitle(GTName,JobID) Values of GTName:("c:\full\path\to\file.ts" or just "file.ts") This function doesn't require the full path.
- 'Construct a new filename. (THIS IS WHERE YOU ADJUST FILENAME FORMAT TEMPLATES)
- If VideoCatagory = "news" Then
- NewFileName = SrcTitle & " - " & SrcDateTime & " - " & SrcEpTitle & SrcFileExt
- ElseIf VideoCatagory = "show" Then
- NewFileName = SrcTitle & " - " & SrcSE & " - " & SrcEpName & SrcFileExt
- Elseif VideoCatagory = "movie" Then
- NewFileName = SrcTitle & SrcFileExt
- Elseif VideoCatagory = "other" Then
- NewFileName = SrcTitle & SrcFileExt
- End If
- 'BEGIN LOGIC
- 'Determine list of candidate encoders within group of prefered ones for the given video size
- Select Case VidSizeRange(SrcFile)
- Case "L"
- If Len(SettingsDict.Item("FastEncoderList")) > 1 Then
- PreferedEncoderArray = Split(SettingsDict.Item("FastEncoderList"), ",")
- End If
- Case "M"
- If Len(SettingsDict.Item("MedEncoderList")) > 1 Then
- PreferedEncoderArray = Split(SettingsDict.Item("MedEncoderList"), ",")
- End If
- Case "S"
- If Len(SettingsDict.Item("SlowEncoderList")) > 1 Then
- PreferedEncoderArray = Split(SettingsDict.Item("SlowEncoderList"), ",")
- End If
- End Select
- If IsArray(PreferedEncoderArray) Then
- 'Cross refrence prefered encoders with available ones and return QualifingEncoderArray.
- q = 0
- For Each AvailableEncoder in AvailableEncoderArray
- For each Encoder in PreferedEncoderArray
- If AvailableEncoder = Encoder Then
- ReDim Preserve QualifingEncoderArray(q)
- QualifingEncoderArray(q) = AvailableEncoder
- q = q + 1
- End If
- Next
- Next
- Else
- 'If no encoders are assigned to video size group, use default list of encoders
- QualifingEncoderArray = Split(SavedEncoderList, ",")
- End If
- 'Now, QualifingEncoderArray will contain a pre-final list of candidate encoders.
- 'We just need to determine which is best.
- 'There are 2 methods available for determining the best candidate encoder.
- '1- queue length, simple file count
- '2- queue size (mb), volume comparison weighted by CPU Passmark rating.
- EncoderQueueLength = 100000 'a big fat fake queue size to start with
- Dim ForceQueueSize
- ForceQueueSize = False
- If UBound(QualifingEncoderArray) < 0 Then
- If IsStockpile Then
- ScriptLog "Skipping file, no available encoders to move from stockpile folder.", 4, JobID
- Exit Sub
- Else
- EncoderName = StockpileName
- ScriptLog "Defaulting to StockPile folder, no encoders are available.", 4, JobID
- End If
- Else
- For Each Encoder in QualifingEncoderArray
- 'By queue length
- If SettingsDict.Item("QueueGuage") = "length" Then
- tempnum = Int(Qlength(Encoder))
- If tempnum < 0 then
- ScriptLog "[" & Encoder & "] Unable to get queue length, switching to queue size as alternative", 2, JobID
- ForceQueueSize = True
- ElseIf tempnum >= 0 Then
- ScriptLog "[" & Encoder & "] queue length is " & tempnum, 4, JobID
- End If
- End If
- 'By queue size
- If SettingsDict.Item("QueueGuage") = "size" Or ForceQueueSize Then
- tempnum = Round(filesys.getfolder(SettingsDict.Item("EncoderShares") & "\" & Encoder).Size / 1073741824, 1) 'tempnum is in gb rounded to the nearest 10th decimal
- If EncoderDict.Exists(Encoder) Then
- 'Size-(Size(2(PM/1000))/100) This will take off 2% per 1k passmark
- tempnum = Int(tempnum - (tempnum * (2 *(EncoderDict.Item(Encoder) / 1000))/100))
- End If
- ScriptLog "[" & Encoder & "] queue size is " & tempnum & " Gb", 4, JobID
- End If
- 'Decide if encoder is the one to use
- If Int(tempnum) < EncoderQueueLength Then
- EncoderName = Encoder
- EncoderQueueLength = tempnum
- End If
- If EncoderQueueLength = 0 then
- Exit For
- End If
- Next
- End If
- '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.
- If SettingsDict.Item("AutoReallocate") = 1 And Ubound(OfflineEncoderArray) >= 0 And BatchMode = 0 And Not IsStockpile Then
- ScriptLog "Checking for media in off-line encoder folders." , 4, JobID
- For Each OfflineEncoder in OfflineEncoderArray
- If filesys.FolderExists(SettingsDict.Item("EncoderShares") & "\" & OfflineEncoder) Then
- If filesys.GetFolder(SettingsDict.Item("EncoderShares") & "\" & OfflineEncoder).SubFolders.Count > 0 Then
- filesys.MoveFolder SettingsDict.Item("EncoderShares") & "\" & OfflineEncoder & "\*", SettingsDict.Item("EncoderStockPile")
- ScriptLog "Moved pending files from offline encoder [" & OfflineEncoder & "] to the stockpile folder." , 4, JobID
- End If
- End If
- Next
- End If
- If BatchMode = 0 And Not IsStockpile Then
- If filesys.GetFolder(SettingsDict.Item("EncoderStockPile")).SubFolders.Count > 0 Then
- ScriptLog "Backlog media found, submitting stockpile folder for batch processing." , 4, JobID
- WshShell.Run Wscript.ScriptFullName & " " & SettingsDict.Item("EncoderStockPile")
- Else
- ScriptLog "No backlog media found, moving on." , 4, JobID
- End If
- End If
- 'The engine has been selected for the job, assign it.
- ScriptLog "Assigning " & EncoderName & " with [" & NewFileName & "]", 0, JobID
- 'Create new folder structure based from VideoCatagory and move file. Delete old folder structure.
- If filesys.FileExists(SrcFile) Then
- If VideoCatagory = "news" Then
- NewFolderStruct = MakeFolderStructure(SettingsDict.Item("EncoderShares") & "\" & EncoderName & "\" & NewsFolderName & "\" & SrcTitle & "\Season 2017\")
- ElseIf VideoCatagory = "show" Then
- NewFolderStruct = MakeFolderStructure(SettingsDict.Item("EncoderShares") & "\" & EncoderName & "\" & TVFolderName & "\" & SrcTitle & "\Season " & SrcS & "\")
- Elseif VideoCatagory = "movie" Then
- NewFolderStruct = MakeFolderStructure(SettingsDict.Item("EncoderShares") & "\" & EncoderName & "\" & MovieFolderName & "\")
- Elseif VideoCatagory = "other" Then
- NewFolderStruct = MakeFolderStructure(SettingsDict.Item("EncoderShares") & "\" & EncoderName & "\" & OtherFolderName & "\")
- End If
- If filesys.FileExists(NewFolderStruct & NewFileName) Then
- ScriptLog "Filename [" & NewFolderStruct & NewFileName & "] already exists. Appending time to name.",1, JobID
- filesys.MoveFile SrcFile, NewFolderStruct & Replace(NewFileName,SrcFileExt, FileCreatedOn(SrcFile,3) & SrcFileExt)
- Else
- ScriptLog "Moving file to [" & NewFolderStruct & NewFileName & "]",4, JobID
- filesys.MoveFile SrcFile, NewFolderStruct & NewFileName
- End If
- If BatchMode = 0 Then
- DelFolder = SrcFile
- For FolderDepth = 0 to 3 'Max folder depth removal, but stop when folder is not empty or = special folder name
- FolderDepth = FolderDepth + 1
- DelFolder = Left(SrcFile,InStrRev(DelFolder,"\") - 1)
- Set folder = filesys.GetFolder(DelFolder)
- Select Case folder.Name
- Case ".grab", "Recordings", "Library", NewsFolderName, TVFolderName, MovieFolderName
- ScriptLog "Not deleting folder [" & DelFolder & "], it may be important.",4, JobID
- Exit For
- End Select
- Set SubFolders = folder.SubFolders
- Set FilesWithin = folder.files
- If SubFolders.Count > 0 Or FilesWithin.Count > 0 Then
- ScriptLog "Not deleting folder [" & DelFolder & "], it's not empty yet.",4, JobID
- Exit For
- Elseif Not filesys.FileExists(NewFolderStruct & NewFileName) Then
- ScriptLog "Not deleting [" & DelFolder & "], destination video missing.",2, JobID
- Exit For
- Else
- On Error Resume Next
- filesys.DeleteFolder DelFolder
- If Err.Number <> 0 Then
- ScriptLog "Unable to remove [" & DelFolder & "], error trying, inspect permissions.",2, JobID
- Exit For
- Else
- ScriptLog "Cleaned up folder [" & DelFolder & "]",4, JobID
- End If
- End If
- Next
- Set folder = nothing
- Set SubFolders = nothing
- Set FilesWithin = nothing
- End If
- End If
- If Not EncoderName = StockpileName Then
- 'Execute MCEB engine rescan of folder so it immediately sees the new file.
- ForceFolderUpdate EncoderName, JobID
- End If
- 'LogRank values = 0=SUCCESS 1=ERROR 2=WARNING 4=INFORMATION 8=AUDIT_SUCCESS 16=AUDIT_FAILURE
- If BatchMode = 0 Then
- 'Log upcoming count
- stalefile = UpcomingRecordings(1,DVRGrabFolder)
- newfile = UpcomingRecordings(0,DVRGrabFolder)
- If stalefile > 0 Then
- ScriptLog "There are " & stalefile & " recording(s) older than 2 hours in the grab folder.", 2, JobID
- ScriptLog "There are a total of " & newfile & " new recording(s) pending. See warning log.", 4, JobID
- ElseIf newfile > 0 Then
- ScriptLog "There are " & newfile & " new recording(s) pending.", 4, JobID
- ElseIf newfile = 0 Then
- ScriptLog "There are 0 recordings pending.", 4, JobID
- End If
- End If
- End Sub
- '---------------------------------------------------------------------------------------------------------------------------
- '---------------------------------------------------------------------------------------------------------------------------
- '----------------------------------------- Begin Supporting Functions & Subs -----------------------------------------------
- '---------------------------------------------------------------------------------------------------------------------------
- '---------------------------------------------------------------------------------------------------------------------------
- 'A common routine to load a script based file and execute it.
- Sub LoadFile(auxfile,mode)
- If Not Filesys.FileExists(filesys.GetParentFolderName(WScript.ScriptFullName) & "\" & auxfile) Then
- NeedSetup = True
- Exit Sub
- End If
- If mode = "run" then
- executeGlobal CreateObject("Scripting.FileSystemObject").openTextFile(filesys.GetParentFolderName(WScript.ScriptFullName) & "\" & auxfile).readAll()
- Elseif mode = "load" Then
- Set lfile = filesys.OpenTextFile(filesys.GetParentFolderName(WScript.ScriptFullName) & "\" & auxfile, 1)
- Do Until lfile.AtEndOfStream
- FileString = lfile.ReadLine
- If Instr(FileString, VBTAB) > 0 Then
- SettingArray = Split(FileString, VBTAB)
- If UBound(SettingArray) = 1 Then
- ExecuteString = CurrentLoadFile & ".Add " & Chr(34) & SettingArray(0) & Chr(34) & " , " & Chr(34) & SettingArray(1) & Chr(34)
- executeGlobal ExecuteString
- End If
- ElseIf LCase(Trim(FileString)) = "eof" Then
- Exit Do
- ElseIf Left(FileString,1) = "'" Then
- 'Ignore comment lines
- ElseIf Instr(FileString, " ") > 0 Then
- 'Execute if the string contains a space
- ExecuteString FileString
- Elseif Len(FileString) > 1 Then
- 'Set dictonary name if non-zero length string
- CurrentLoadFile = FileString
- End If
- Loop
- lfile.Close
- End If
- End Sub
- 'A routine to recursively search a folder and ultimately produce all files within it. All files may be processed but
- 'only video files will be accepted by MCEB.
- Sub RecursiveSearch(fldr)
- Set BaseFolder = filesys.GetFolder(fldr)
- For Each MediaFile in BaseFolder.Files
- TotalFiles = TotalFiles + 1
- MainLogic MediaFile
- Next
- 'Ignore .grab folders. We don't want to disturb videos not yet ready.
- For each NestedFolder in BaseFolder.SubFolders
- If Not NestedFolder.Name = ".grab" Then
- RecursiveSearch NestedFolder
- End If
- Next
- End Sub
- 'Returns the quantity of upcoming recordings. Right now only for logging purposes. Only reports the correct number AFTER the
- 'video is moved otherwise it will be +1.
- 'URNumber [0=total,1=old]
- Function UpcomingRecordings(URNumber,GrabFolder)
- If URNumber = 0 Then
- UpcomingRecordings = filesys.GetFolder(GrabFolder).SubFolders.Count
- Elseif URNumber = 1 Then
- UpcomingRecordings = 0
- For Each FolderName In filesys.GetFolder(GrabFolder).SubFolders
- For Each FileName In filesys.GetFolder(FolderName).Files
- Set grabFile = filesys.GetFile(FileName)
- If DateDiff("N", grabFile.DateCreated, now()) > 120 Then 'Older than 2 hours
- UpcomingRecordings = UpcomingRecordings + 1
- End If
- Next
- Next
- End If
- End Function
- 'This sub will build a 2 subfolder deep structure as specified in input PathToMake. Used to create the folders for an assigned
- 'video when moved to the encoders folder.
- 'It returns the full path as the result
- Function MakeFolderStructure(PathToMake)
- MakeFolderStructure = PathToMake
- 'Break apart the path to each folder and filename
- FolderStructureArray = Split(PathToMake, "\")
- WorkingPath = FolderStructureArray(0) & "\"
- 'Start at 1 because 0 is the drive letter
- For w = 1 To Ubound(FolderStructureArray)
- If Not FolderStructureArray(w) = "" Then
- WorkingPath = WorkingPath & FolderStructureArray(w) & "\"
- If Not filesys.FolderExists(WorkingPath) Then
- 'Make the folder one at a time
- newfolder = filesys.CreateFolder(WorkingPath)
- End If
- End If
- Next
- End Function
- 'Sends Logs to the Windows logging service. The following are the log types for classification.
- 'https://msdn.microsoft.com/en-us/library/b4ce6by3
- 'LogRank values = 0=SUCCESS 1=ERROR 2=WARNING 4=INFORMATION 8=AUDIT_SUCCESS 16=AUDIT_FAILURE
- 'See [Event viewer]->[Windows Logs]->[Application]. Logs are marked as from source "WSH".
- 'Filters can be applied to windows logs for a clean operating list of jobs complete or fail.
- Sub ScriptLog(LogData,LogRank,ID)
- WshShell.LogEvent LogRank, Now() & vbcrlf & "ID: " & ID & vbcrlf & LogData
- End Sub
- Sub ForceFolderUpdate(EncoderName, ID)
- strCommand = SettingsDict.Item("UserCLIApp") & " --command=engine --action=rescan --server=" & EncoderName
- Set WshShellExec = WshShell.Exec(strCommand)
- If Instr(WshShellExec.StdOut.ReadAll,"MCEBuddy.UserCLI Successful!!") > 0 Then
- ScriptLog "[" & EncoderName & "] folder rescan command successful.", 4, ID
- Else
- ScriptLog "[" & EncoderName & "] folder rescan command FAILED.", 2, ID
- End If
- End Sub
- 'Returns the result of testing all folder names in the encoders folder as computers on your network for available MCEB engines.
- Function AvailableEncoderList(ID)
- Set FSO = CreateObject("Scripting.FileSystemObject")
- 'Make array from offline.txt
- If filesys.FileExists(SettingsDict.Item("EncoderShares") & "\offline.txt") Then
- Set objTextFile = FSO.OpenTextFile(SettingsDict.Item("EncoderShares") & "\offline.txt", 1)
- 'Need to set it to a var before splitting it to make sue it's not zero length
- If filesys.GetFile(SettingsDict.Item("EncoderShares") & "\offline.txt").Size > 0 Then
- SavedOfflineArray = Split(objTextFile.ReadAll, vbCrLf)
- 'SavedOfflineArray = array of all folder names in the common shared folders that belong to encoders previously marked as offline in offline.txt.
- Else
- ReDim SavedOfflineArray(0)
- End If
- Set objTextFile = Nothing
- Else
- ReDim SavedOfflineArray(0)
- End If
- EncoderArray = EncoderDict.Keys()
- ReDim OutputArray(0)
- ReDim OfflineArray(0)
- For Each EncoderName In EncoderArray
- Select Case EncoderName
- Case ""
- 'Skip blank names
- Continue
- Case StockpileName
- 'Skip dump folder (assumed to be with encoder folders)
- Continue
- End Select
- If Not filesys.FolderExists(SettingsDict.Item("EncoderShares") & "\" & EncoderName) Then
- '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!
- NewEncoderFolder = filesys.CreateFolder(SettingsDict.Item("EncoderShares") & "\" & EncoderName)
- End If
- VisableEncoder = 1
- For j = 0 to Ubound(SavedOfflineArray)
- If SavedOfflineArray(j) = EncoderName Then
- 'If encoder name is in the offline.txt array, ignore it.
- VisableEncoder = 0
- j = Ubound(SavedOfflineArray)
- End If
- Next
- If VisableEncoder = 0 Then
- If Not OfflineArray(UBound(OfflineArray)) = "" Then
- ReDim Preserve OfflineArray(UBound(OfflineArray) + 1)
- End If
- OfflineArray(UBound(OfflineArray)) = EncoderName
- ElseIf VisableEncoder = 1 Then
- EncoderState = EngineStatus(EncoderName)
- If EncoderState = "started" Then
- 'This is where valid hosts are added to the list of output.
- ScriptLog "[" & EncoderName & "] engine is running -idle-", 4, ID
- If Not OutputArray(UBound(OutputArray)) = "" Then
- ReDim Preserve OutputArray(UBound(OutputArray) + 1)
- End If
- OutputArray(UBound(OutputArray)) = EncoderName
- ElseIf EncoderState = "conversion_in_progress" Then
- 'This is where valid hosts are added to the list of output.
- ScriptLog "[" & EncoderName & "] engine is running -working- ", 4, ID
- If Not OutputArray(UBound(OutputArray)) = "" Then
- ReDim Preserve OutputArray(UBound(OutputArray) + 1)
- End If
- OutputArray(UBound(OutputArray)) = EncoderName
- ElseIf EncoderState = "conversion_paused" Then
- ScriptLog "[" & EncoderName & "] engine is -paused-", 4, ID
- If Not OutputArray(UBound(OutputArray)) = "" Then
- ReDim Preserve OutputArray(UBound(OutputArray) + 1)
- End If
- OutputArray(UBound(OutputArray)) = EncoderName
- ElseIf EncoderState = "stopped" Then
- 'This is where valid hosts that are stopped and not added to the list.
- ScriptLog "[" & EncoderName & "] engine is not running -stopped-", 4, ID
- Else
- 'This is where invalid/unavailable hosts are identified.
- ScriptLog "[" & EncoderName & "] is off-line.", 2, JobID
- If Not OfflineArray(UBound(OfflineArray)) = "" Then
- ReDim Preserve OfflineArray(UBound(OfflineArray) + 1)
- End If
- OfflineArray(UBound(OfflineArray)) = EncoderName
- If SettingsDict.Item("AutoDisable") = 1 Then
- ScriptLog "[" & EncoderName & "] has been auto-disabled", 2, ID
- Set objFile = FSO.OpenTextFile(SettingsDict.Item("EncoderShares") & "\offline.txt", 8)
- objFile.Write EncoderName & vbCrLf
- objFile.Close
- End If
- 'Add the folder/encoder name to a offline.txt file and will be ignored on future runs until removed.
- 'Re-run contents of folder for assignment
- End If
- End If
- Next
- AvailableEncoderList = Join(OutputArray,",")
- OfflineEncoderlist = Join(OfflineArray,",")
- ScriptLog "Available encoders: [" & AvailableEncoderList & "]", 4, ID
- End Function
- 'Supplied with an encoders Windows name or IP address, will return the queue length of that MCEB engine.
- Function Qlength(QName)
- strCommand = SettingsDict.Item("UserCLIApp") & " --command=query --action=queuelength --quiet --server=" & QName
- Set WshShellExec = WshShell.Exec(strCommand)
- Qlength = WshShellExec.StdOut.ReadLine
- Set WshShellExec = Nothing
- '-2 means nonresponsive
- End Function
- 'Supplied with an encoder's Windows name or IP address, will return "-2" for offline, "stopped" or "running" engine status
- Function EngineStatus(ESName)
- strCommand = SettingsDict.Item("UserCLIApp") & " --command=query --action=enginestate --quiet --server=" & ESName
- Set WshShellExec = WshShell.Exec(strCommand)
- EngineStatus = WshShellExec.StdOut.ReadLine
- Set WshShellExec = Nothing
- End Function
- 'Crudely determine size category of the video being processed. Used for the fast/med/slow encoders list.
- Function VidSizeRange(VSRName)
- SrcFileSize = filesys.GetFile(VSRName).Size
- Select Case True
- Case SrcFileSize >= CDbl(SettingsDict.Item("ALargeFile") * 1073741824)
- VidSizeRange = "L"
- Case SrcFileSize > CDbl(SettingsDict.Item("AMedFile") * 1073741824) And SrcFileSize < CDbl(SettingsDict.Item("ALargeFile") * 1073741824)
- VidSizeRange = "M"
- Case Else
- VidSizeRange = "S"
- End Select
- End Function
- 'Supplied with a full filename with path will return date, time or date and time of the files creation.
- Function FileCreatedOn(FCOName,FullorPart)
- SET objFSO = CREATEOBJECT("Scripting.FileSystemObject")
- SET objFile = objFSO.GetFile(FCOName)
- FileStamp = objFile.DateCreated
- 'so.. IF, as in it already happened, the file was created at exactly midnight, ONLY the date will be passed because I guess
- 'someone doesn't like zeros...
- 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.
- FileStamp = FileStamp & " 12:00:00 AM" '12 hr equivalent to the 00 00 00 that was removed.
- End If
- FileCreatedArray = Split(FileStamp, " ")
- FileCreatedDateArray = Split(FileCreatedArray(0), "/")
- 'need to translate date format. (MM/DD/YY to YY/MM/DD)
- FileCreatedDate = FileCreatedDateArray(2) & "-" & FileCreatedDateArray(0) & "-" & FileCreatedDateArray(1)
- FileCreatedTimeArray = Split(FileCreatedArray(1), ":")
- 'If 12 hr time is requested, take care of it and pass it along.
- If FullorPart = 3 Then 'Time AM/PM Format
- FileCreatedOn = FileCreatedTimeArray(0) & "." & FileCreatedTimeArray(1) & " " & FileCreatedArray(2)
- Else
- 'Format data for 24 hr format and process other requests
- If FileCreatedArray(2) = "PM" And Not FileCreatedTimeArray(0) = 12 Then
- FileCreatedTimeArray(0) = FileCreatedTimeArray(0) + 12
- End If
- If Len(FileCreatedTimeArray(0)) < 2 Then
- FileCreatedTimeArray(0) = "0" & FileCreatedTimeArray(0)
- End If
- 'Give data requested
- If FullorPart = 0 Then 'Date
- FileCreatedOn = FileCreatedDate
- End If
- If FullorPart = 1 Then 'Time
- FileCreatedOn = Join(FileCreatedTimeArray, " ")
- End If
- If FullorPart = 2 Then 'Date & Time
- FileCreatedOn = FileCreatedDate & " " & Join(FileCreatedTimeArray, " ")
- End If
- End If
- End Function
- Function VidCat(VCFilename)
- If Instr(VCFilename,SettingsDict.Item("NewsDVRFolder")) > 0 Then
- VidCat = "news"
- ElseIf Instr(VCFilename,SettingsDict.Item("ShowDVRFolder")) > 0 Then
- VidCat = "show"
- ElseIf Instr(VCFilename,SettingsDict.Item("MovieDVRFolder")) > 0 Then
- VidCat = "movie"
- Else
- VidCat = "other"
- End If
- End Function
- '-------------------Regex Functions---------------------------------------------------Regex Functions-------------------------
- '----------------------------------------------------Regex Functions----------------------------------------------------------
- '-----------------------------------------------------------------------------------------------------------------------------
- ' The following functions are for extracting file name components for the new filename.
- ' If a date and or time is not included in the supplied filename it will be extracted
- ' from the file creation timestamp and used in its place.
- Function GetSE(GSEName)
- fGSEName = GSEName
- Set objRegEx = CreateObject("VBScript.RegExp")
- objRegEx.Global = True
- GENNameArray = Split(fGSEName, "\")
- fGSEName = GENNameArray(UBound(GENNameArray))
- fGSEName = Replace(fGSEName, " - ", "|")
- 'Find season/Episode in format: Sxx(-)Exx
- objRegEx.Pattern = "[sS]+(\d{1,3})[eE]+(\d{1,3})"
- Set myMatches = objRegEx.Execute(fGSEName)
- For Each myMatch in myMatches
- EpisodeNumArray = Split(Replace(LCase(myMatch.Value),"s",""),"e")
- GetSE = EpisodeNumArray(0) & "," & EpisodeNumArray(1) '<----- OUTPUT IS DETERMINED HERE IF Sxx(-)Exx
- Exit Function
- Next
- 'Find season/Episode in format: Episode xx-xx
- objRegEx.Pattern = "[Ee]pisode[\ \-](\d{1,3})[\ \-](\d{1,3})"
- Set myMatches = objRegEx.Execute(fGSEName)
- For Each myMatch in myMatches
- EpisodeNumArray = Split(Replace(myMatch.Value,"-"," ")," ")
- GetSE = EpisodeNumArray(1) & "," & EpisodeNumArray(2) '<----- OUTPUT IS DETERMINED HERE IF Episode xx-xx
- Exit For
- Next
- End Function
- 'Returns the Episode title, as in "Episode 123", used in news when there is at times no title.
- Function GetETitle(GENName)
- fGENName = GENName
- Set objRegEx = CreateObject("VBScript.RegExp")
- objRegEx.Global = True
- GENNameArray = Split(fGENName, "\")
- fGENName = GENNameArray(UBound(GENNameArray))
- fGENName = Replace(fGENName, " - ", "|")
- 'Find episode in format: SxxExx
- objRegEx.Pattern = "[sS]+(\d{1,3})[eE]+(\d{1,3})"
- Set myMatches = objRegEx.Execute(fGENName)
- For Each myMatch in myMatches
- EpisodeNumArray = Split(Replace(LCase(myMatch.Value),"s",""),"e")
- GetETitle = "Episode " & EpisodeNumArray(1)
- Exit For
- Next
- 'Find episode in format: Episode xx-xx or Episode xxx
- objRegEx.Pattern = "[Ee]pisode[\ \-](\d{1,3})[\ \-]*(\d{0,3})"
- Set myMatches = objRegEx.Execute(fGENName)
- For Each myMatch in myMatches
- EpisodeNumArray = Split(Replace(myMatch.Value,"-"," ")," ")
- 'If the array size is 2, then it's only an episode, 3 would include the season.
- If UBound(EpisodeNumArray) = 1 Then
- GetETitle = "Episode " & EpisodeNumArray(1)
- Elseif UBound(EpisodeNumArray) = 2 Then
- GetETitle = "Episode " & EpisodeNumArray(2)
- Else
- End If
- Exit For
- Next
- End Function
- 'Determines if the episode was live, more useful on Cops shows. It looks for the word "live" anywhere but the title section.
- Function GetIsLive(GILName)
- fGILName = GILName
- Set objRegEx = CreateObject("VBScript.RegExp")
- objRegEx.Global = True
- GILNameArray = Split(fGILName, "\")
- fGILName = GILNameArray(UBound(GILNameArray))
- fGILName = Replace(fGILName, " - ", "|")
- 'Determine if it is live
- GetIsLive = 0
- objRegEx.Pattern = "(\|[a-z A-Z]*[lL]ive[a-z A-Z0-9]*)"
- Set myMatches = objRegEx.Execute(fGILName)
- For Each myMatch in myMatches
- GetIsLive = 1
- Next
- End Function
- 'Returns the Date, time, date & time or time in 12 hr for when a media file was created.
- Function GetDateTime(GDTName)
- fGDTName = GDTName
- Set objRegEx = CreateObject("VBScript.RegExp")
- objRegEx.Global = True
- GDTNameArray = Split(fGDTName, "\")
- NewString = Replace(GDTNameArray(UBound(GDTNameArray)), " - ", "|") 'pipes make great boundaries
- 'date and time in format: YYYY-MM-DD HH MM SS with any ("." or "-" or " ") as delimiters
- objRegEx.Pattern = "(\d{4})[\-\.\ ](\d{2})[\-\.\ ](\d{2}) (\d{2})[\.\-\ ](\d{2})[\.\-\ ](\d{2})"
- Set myMatches = objRegEx.Execute(NewString)
- For Each myMatch in myMatches
- DateArray = Split(Replace(Replace(myMatch.Value,"-"," "),"."," ")," ")
- If Int(DateArray(3)) = 0 And Int(DateArray(4)) = 0 And Int(DateArray(5)) = 0 Then
- GetDateTime = DateArray(0) & "-" & DateArray(1) & "-" & DateArray(2) & " " & FileCreatedOn(fGDTName,1)
- Else
- GetDateTime = DateArray(0) & "-" & DateArray(1) & "-" & DateArray(2) & " " & DateArray(3) & " " & DateArray(4) & " " & DateArray(5)
- End If
- Next
- 'date only in format: MM.DD.YY/YYYY with any ("." or "-" or " ") as delimiters
- If Len(GetDateTime) = 0 Then
- objRegEx.Pattern = "(\d{1,2})[\.\-\ ](\d{1,2})[\.\-\ ](\d{2,4})"
- Set myMatches = objRegEx.Execute(NewString)
- For Each myMatch in myMatches
- DateArray = Split(Replace(Replace(myMatch.Value,"-"," "),".", " ")," ")
- If Len(DateArray(2)) = 2 Then
- DateArray(2) = 2000 + Int(DateArray(2))
- End If
- GetDateTime = DateArray(2) & "-" & DateArray(0) & "-" & DateArray(1) & " " & FileCreatedOn(fGDTName,1)
- Next
- End If
- 'If no date is found, make one from the file attributes
- If Len(GetDateTime) = 0 Then
- GetDateTime = FileCreatedOn(fGDTName,2)
- End If
- End Function
- '------------------------------------------------------------------------------------------------
- 'Returns the show title, assumed to be the first part of the filename.
- Function GetTitle(GTName, ID)
- fGTName = GTName
- Set objRegEx = CreateObject("VBScript.RegExp")
- objRegEx.Global = True
- GTNameArray = Split(fGTName, "\")
- fGTName = GTNameArray(UBound(GTNameArray))
- fGTName = Replace(fGTName, " - ", "|")
- 'Title
- objRegEx.Pattern = "(^[a-zA-Z\ \(\)0-9\-]*)"
- Set myMatches = objRegEx.Execute(fGTName)
- 'If the title can not be determined, log and quit.
- If myMatches.Count = 0 Then
- ScriptLog "Unable to identify title in filename! Ignoring file.",1, ID
- Wscript.Quit
- End If
- GetTitle = myMatches(0)
- 'remove the (year) string for proper matching to dictionary names.
- TitleArray = Split(GetTitle," (")
- GetTitle = TitleArray(0)
- If UBound(TitleArray) > 0 Then
- TitleYear = Replace(TitleArray(1),")","")
- End If
- If VideoCatagory = "news" Then
- If NewsDict.Exists(GetTitle) Then
- GetTitle = NewsDict.Item(GetTitle)
- ScriptLog "Title found in the News dictionary.",4, ID
- Else
- ScriptLog "Unable to locate title in the News dictionary.",2, ID
- End If
- DupTrack = 0
- For Each ShowName In filesys.GetFolder(SettingsDict.Item("NewsLibFolder")).SubFolders
- TitleArray = Split(ShowName.Name," (")
- If TitleArray(0) = GetTitle Then
- DupTrack = DupTrack + 1
- GetTitle = ShowName.Name
- End If
- Next
- If Duptrack > 1 Then
- ScriptLog "More than 1 match was found for this news video.",2, ID
- End If
- 'If all else fails, Create a new title and use it.
- If DupTrack = 0 Then
- ScriptLog "New show detected!",0, ID
- GetTitle = GetTitle & " (" & TitleYear & ")"
- End If
- ElseIf VideoCatagory = "show" Then
- If ShowDict.Exists(GetTitle) Then
- GetTitle = ShowDict.Item(GetTitle)
- ScriptLog "Title found in the TV Show dictionary.",4, ID
- Else
- ScriptLog "Unable to locate title in the TV Show dictionary.",2, ID
- End If
- DupTrack = 0
- For Each ShowName In filesys.GetFolder(SettingsDict.Item("TVLibFolder")).SubFolders
- TitleArray = Split(ShowName.Name," (")
- If TitleArray(0) = GetTitle Then
- DupTrack = DupTrack + 1
- GetTitle = ShowName.Name
- End If
- Next
- If Duptrack > 1 Then
- ScriptLog "More than 1 match was found for this TV show.",2, ID
- End If
- 'If all else fails, Create a new title and use it.
- If DupTrack = 0 Then
- ScriptLog "New show detected!",0, ID
- GetTitle = GetTitle & " (" & TitleYear & ")"
- End If
- Elseif VideoCatagory = "movie" Then
- If MovieDict.Exists(GetTitle) Then
- GetTitle = MovieDict.Item(GetTitle)
- ScriptLog "Title found in the Movie dictionary.",4, ID
- Else
- ScriptLog "Unable to locate title in the Movie dictionary.",2, ID
- End If
- Elseif VideoCatagory = "other" Then
- If OtherDict.Exists(GetTitle) Then
- GetTitle = OtherDict.Item(GetTitle)
- ScriptLog "Title found in the Other dictionary.",4, ID
- Else
- ScriptLog "Unable to locate title in the Other dictionary.",2, ID
- End If
- End If
- End Function
- Function GetEpTitle(SrcFile,JobID)
- GEName = SrcFile
- Set objRegEx = CreateObject("VBScript.RegExp")
- objRegEx.Global = True
- GTNameArray = Split(GEName, "\")
- GEName = GTNameArray(UBound(GTNameArray))
- GTNameArray = Split(GEName, " - ")
- GEName = GTNameArray(Ubound(GTNameArray))
- 'Title
- objRegEx.Pattern = "([a-zA-Z\ \(\)0-9\-\,\?\!\$\%\&\#\@]*)"
- Set myMatches = objRegEx.Execute(GEName)
- 'If the title can not be determined, log and quit.
- If myMatches.Count = 0 Then
- ScriptLog "Unable to identify show title in filename! Ignoring file.",4,JobID
- Wscript.Quit
- End If
- GetEpTitle = myMatches(0)
- End Function
- '------------------------------------------------------------------------------------------------
- '------------------------------------------------------------------------------------------------
- '-------------------------------------SETUP ROUTINES---------------------------------------------
- '------------------------------------------------------------------------------------------------
- '------------------------------------------------------------------------------------------------
- '------------------------------------------------------------------------------------------------
- Sub MakeConfig()
- WorkingFolder = filesys.GetParentFolderName(WScript.ScriptFullName) & "\"
- NewConfigString = "SettingsDict"
- Done = False
- If Not Filesys.FileExists(WorkingFolder & "PostProcess.cfg") Then
- ' ScriptLog "Main config file not found. Creating now.",2, ID
- End If
- 'CLI
- If SettingsDict.Exists("UserCLIApp") Then
- 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
- ThisInput = SettingsDict.Item("UserCLIApp")
- Done = True
- End If
- End If
- Do Until Done
- ThisInput = UserInput("Find Folder", "Select the parent folder of MCEBuddy.UserCLI.exe" ,"",1) & "\MCEBuddy.UserCLI.exe"
- If ThisInput = "" Then
- WayOut
- ElseIf Filesys.FileExists(ThisInput) Then
- Done = true
- Else
- Msgbox "MCEBuddy.UserCLI.exe wasn't found in: " & vbcrlf & ThisInput & vbcrlf & "Please try again."
- End If
- Loop
- NewConfigString = NewConfigString & vbcrlf & "UserCLIApp" & vbtab & ThisInput
- 'NewsLibFolder
- Done = False
- If SettingsDict.Exists("NewsLibFolder") Then
- If MsgBox("Do you want to change the Plex news library location?" & vbcrlf & vbcrlf & SettingsDict.Item("NewsLibFolder"), 4, "Change setting?") = 7 Then
- ThisInput = SettingsDict.Item("NewsLibFolder")
- Done = True
- End If
- End If
- Do Until Done
- ThisInput = UserInput("News Library", "Please select the Plex news library folder." ,"",1)
- If ThisInput = "" Then
- WayOut
- ElseIf Filesys.FolderExists(ThisInput) Then
- Done = true
- Else
- WayOut
- End If
- Loop
- NewConfigString = NewConfigString & vbcrlf & "NewsLibFolder" & vbtab & ThisInput
- 'TVLibFolder
- Done = False
- If SettingsDict.Exists("TVLibFolder") Then
- If MsgBox("Do you want to change the Plex TV show library location?" & vbcrlf & vbcrlf & SettingsDict.Item("TVLibFolder"), 4, "Change setting?") = 7 Then
- ThisInput = SettingsDict.Item("TVLibFolder")
- Done = True
- End If
- End If
- Do Until Done
- ThisInput = UserInput("Show Library", "Please select the Plex TV show library folder." ,"",1)
- If ThisInput = "" Then
- WayOut
- ElseIf Filesys.FolderExists(ThisInput) Then
- Done = true
- Else
- WayOut
- End If
- Loop
- NewConfigString = NewConfigString & vbcrlf & "TVLibFolder" & vbtab & ThisInput
- 'MovieLibFolder
- Done = False
- If SettingsDict.Exists("MovieLibFolder") Then
- If MsgBox("Do you want to change the Plex Movie library location?" & vbcrlf & vbcrlf & SettingsDict.Item("MovieLibFolder"), 4, "Change setting?") = 7 Then
- ThisInput = SettingsDict.Item("MovieLibFolder")
- Done = True
- End If
- End If
- Do Until Done
- ThisInput = UserInput("Movie Library", "Please select the Plex movie library folder." ,"",1)
- If ThisInput = "" Then
- WayOut
- ElseIf Filesys.FolderExists(ThisInput) Then
- Done = true
- Else
- WayOut
- End If
- Loop
- NewConfigString = NewConfigString & vbcrlf & "MovieLibFolder" & vbtab & ThisInput
- 'OtherLibFolder
- Done = False
- If SettingsDict.Exists("OtherLibFolder") Then
- If MsgBox("Do you want to change the Plex Other library location?" & vbcrlf & vbcrlf & SettingsDict.Item("OtherLibFolder"), 4, "Change setting?") = 7 Then
- ThisInput = SettingsDict.Item("OtherLibFolder")
- Done = True
- End If
- End If
- Do Until Done
- ThisInput = UserInput("Other Library", "Please select the Plex OTHER library folder." ,"",1)
- If ThisInput = "" Then
- WayOut
- ElseIf Filesys.FolderExists(ThisInput) Then
- Done = true
- Else
- WayOut
- End If
- Loop
- NewConfigString = NewConfigString & vbcrlf & "OtherLibFolder" & vbtab & ThisInput
- 'Encodershares
- 'NewsDVRFolder
- Done = False
- If SettingsDict.Exists("NewsDVRFolder") Then
- If MsgBox("Do you want to change the Plex News DVR folder?" & vbcrlf & vbcrlf & SettingsDict.Item("NewsDVRFolder"), 4, "Change setting?") = 7 Then
- ThisInput = SettingsDict.Item("NewsDVRFolder")
- Done = True
- End If
- End If
- Do Until Done
- ThisInput = UserInput("News DVR", "Please select the Plex News DVR folder." ,"",1)
- If ThisInput = "" Then
- WayOut
- ElseIf Filesys.FolderExists(ThisInput) Then
- Done = true
- Else
- WayOut
- End If
- Loop
- NewConfigString = NewConfigString & vbcrlf & "NewsDVRFolder" & vbtab & ThisInput
- 'ShowDVRFolder
- Done = False
- If SettingsDict.Exists("ShowDVRFolder") Then
- If MsgBox("Do you want to change the Plex TV Show DVR folder?" & vbcrlf & vbcrlf & SettingsDict.Item("ShowDVRFolder"), 4, "Change setting?") = 7 Then
- ThisInput = SettingsDict.Item("ShowDVRFolder")
- Done = True
- End If
- End If
- Do Until Done
- ThisInput = UserInput("TV Show DVR", "Please select the Plex TV Show DVR folder." ,"",1)
- If ThisInput = "" Then
- WayOut
- ElseIf Filesys.FolderExists(ThisInput) Then
- Done = true
- Else
- WayOut
- End If
- Loop
- NewConfigString = NewConfigString & vbcrlf & "ShowDVRFolder" & vbtab & ThisInput
- 'MovieDVRFolder
- Done = False
- If SettingsDict.Exists("MovieDVRFolder") Then
- If MsgBox("Do you want to change the Plex Movie DVR folder?" & vbcrlf & vbcrlf & SettingsDict.Item("MovieDVRFolder"), 4, "Change setting?") = 7 Then
- ThisInput = SettingsDict.Item("MovieDVRFolder")
- Done = True
- End If
- End If
- Do Until Done
- ThisInput = UserInput("Movie DVR", "Please select the Plex Movie DVR folder." ,"",1)
- If ThisInput = "" Then
- WayOut
- ElseIf Filesys.FolderExists(ThisInput) Then
- Done = true
- Else
- WayOut
- End If
- Loop
- NewConfigString = NewConfigString & vbcrlf & "MovieDVRFolder" & vbtab & ThisInput
- 'OtherDVRFolder
- Done = False
- If SettingsDict.Exists("OtherDVRFolder") Then
- If MsgBox("Do you want to change the Plex Other DVR folder?" & vbcrlf & vbcrlf & SettingsDict.Item("OtherDVRFolder"), 4, "Change setting?") = 7 Then
- ThisInput = SettingsDict.Item("OtherDVRFolder")
- Done = True
- End If
- End If
- Do Until Done
- ThisInput = UserInput("Other DVR", "Please select the Plex Other DVR folder." ,"",1)
- If ThisInput = "" Then
- WayOut
- ElseIf Filesys.FolderExists(ThisInput) Then
- Done = true
- Else
- WayOut
- End If
- Loop
- NewConfigString = NewConfigString & vbcrlf & "OtherDVRFolder" & vbtab & ThisInput
- Done = False
- If SettingsDict.Exists("EncoderShares") Then
- 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
- ThisInput = SettingsDict.Item("EncoderShares")
- Done = True
- End If
- End If
- Do Until Done
- ThisInput = UserInput("Share Root", "Please select the root folder where all shared folders for MCEB engines are located." ,"",1)
- If ThisInput = "" Then
- WayOut
- ElseIf Filesys.FolderExists(ThisInput) Then
- Done = true
- Else
- WayOut
- End If
- Loop
- NewConfigString = NewConfigString & vbcrlf & "EncoderShares" & vbtab & ThisInput
- 'EncoderStockPile
- Done = False
- If SettingsDict.Exists("EncoderStockPile") Then
- 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
- ThisInput = SettingsDict.Item("EncoderStockPile")
- Done = True
- End If
- End If
- Do Until Done
- ThisInput = UserInput("Share Root", "Please select the encoder buffer folder." ,"",1)
- If ThisInput = "" Then
- WayOut
- ElseIf Filesys.FolderExists(ThisInput) Then
- Done = true
- Else
- WayOut
- End If
- Loop
- NewConfigString = NewConfigString & vbcrlf & "EncoderStockPile" & vbtab & ThisInput
- 'AutoDisable
- If SettingsDict.Exists("AutoDisable") Then
- If SettingsDict.Item("AutoDisable") = 1 Then
- SetTo = "Enabled"
- Else
- SetTo = "Disabled"
- End If
- Else
- SetTo = "Enabled"
- End If
- If MsgBox("Do you want to auto disable unresponsive encoders?" & vbcrlf & vbcrlf & "Currently set to: " & SetTo, 4, "Change setting?") = 6 Then
- NewConfigString = NewConfigString & vbcrlf & "AutoDisable" & vbtab & "1"
- Else
- NewConfigString = NewConfigString & vbcrlf & "AutoDisable" & vbtab & "0"
- End If
- 'AutoReallocate
- If SettingsDict.Exists("AutoReallocate") Then
- If SettingsDict.Item("AutoReallocate") = 1 Then
- SetTo = "Enabled"
- Else
- SetTo = "Disabled"
- End If
- Else
- SetTo = "Enabled"
- End If
- 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
- NewConfigString = NewConfigString & vbcrlf & "AutoReallocate" & vbtab & "1"
- Else
- NewConfigString = NewConfigString & vbcrlf & "AutoReallocate" & vbtab & "0"
- End If
- 'FastEncoderList
- Done = False
- If SettingsDict.Exists("FastEncoderList") Then
- 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
- ThisInput = SettingsDict.Item("FastEncoderList")
- Done = True
- End If
- End If
- If Not Done Then
- ThisInput = UserInput("Fast Encoders", "Please make a comma delimited list of which engines involved are to be favored for large files." ,"",0)
- End If
- NewConfigString = NewConfigString & vbcrlf & "FastEncoderList" & vbtab & Replace(ThisInput," ","")
- 'MedEncoderList
- Done = False
- If SettingsDict.Exists("MedEncoderList") Then
- 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
- ThisInput = SettingsDict.Item("MedEncoderList")
- Done = True
- End If
- End If
- If Not Done Then
- ThisInput = UserInput("Medium Speed Encoders", "Please make a comma delimited list of which engines involved are to be favored for medium sized files." ,"",0)
- End If
- NewConfigString = NewConfigString & vbcrlf & "MedEncoderList" & vbtab & Replace(ThisInput," ","")
- 'SlowEncoderList
- Done = False
- If SettingsDict.Exists("SlowEncoderList") Then
- 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
- ThisInput = SettingsDict.Item("SlowEncoderList")
- Done = True
- End If
- End If
- If Not Done Then
- ThisInput = UserInput("Slow Encoders", "Please make a comma delimited list of which engines involved are to be favored for small files." ,"",0)
- End If
- NewConfigString = NewConfigString & vbcrlf & "SlowEncoderList" & vbtab & Replace(ThisInput," ","")
- 'ALargeFile
- Done = False
- If SettingsDict.Exists("ALargeFile") Then
- If SettingsDict.Item("ALargeFile") > 0 Then
- ThisSize = SettingsDict.Item("ALargeFile")
- Else
- ThisSize = 4
- End If
- 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
- ThisSize = SettingsDict.Item("ALargeFile")
- Done = True
- End If
- End If
- Do Until Done
- ThisSize = UserInput("Large media file", "In gb, please specify what is considered a LARGE media file." ,"4",0)
- If ThisSize > 0 Then
- Done = True
- Else
- Msgbox "That is an invalid value, Please try again."
- End If
- Loop
- NewConfigString = NewConfigString & vbcrlf & "ALargeFile" & vbtab & ThisSize
- 'AMedFile
- Done = False
- If SettingsDict.Exists("AMedFile") Then
- If SettingsDict.Item("AMedFile") > 0 Then
- ThisSize = SettingsDict.Item("AMedFile")
- Else
- ThisSize = 2
- End If
- 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
- ThisSize = SettingsDict.Item("AMedFile")
- Done = True
- End If
- End If
- Do Until Done
- ThisSize = UserInput("Medium media file", "In gb, please specify what is considered a MEDIUM sized media file." ,"2",0)
- If ThisSize > 0 Then
- Done = True
- Else
- Msgbox "That is an invalid value, Please try again."
- End If
- Loop
- NewConfigString = NewConfigString & vbcrlf & "AMedFile" & vbtab & ThisSize
- 'QueueGuage
- Done = False
- If SettingsDict.Exists("QueueGuage") Then
- 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
- ThisInput = SettingsDict.Item("QueueGuage")
- Done = True
- End If
- End If
- If Not Done Then
- 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
- ThisInput = "size"
- Else
- ThisInput = "length"
- End If
- End If
- NewConfigString = NewConfigString & vbcrlf & "QueueGuage" & vbtab & ThisInput
- 'EncoderDict
- NewConfigString = NewConfigString & vbcrlf & "EncoderDict"
- For Each EncoderName In EncoderDict.Keys()
- Done = False
- If EncoderDict.Exists(EncoderName) Then
- 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
- NewConfigString = NewConfigString & vbcrlf & EncoderName & vbtab & EncoderDict.Item(EncoderName)
- Done = True
- End If
- End If
- Do Until Done
- ThisInput = UserInput("CPU Passmark", "Please enter the passmark score for " & EncoderName & vbcrlf & vbcrlf & "See http://cpubenchmark.net for lookup.","6000",0)
- If ThisInput > 100 Then
- NewConfigString = NewConfigString & vbcrlf & EncoderName & vbtab & ThisInput
- Done = True
- Else
- Msgbox "That is an invalid value, please try again."
- End If
- Loop
- Next
- NewConfigString = NewConfigString & vbcrlf & "IgnoreDict"
- NewConfigString = NewConfigString & vbcrlf & "'----------------------------------"
- NewConfigString = NewConfigString & vbcrlf & "eof"
- NewConfigString = NewConfigString & vbcrlf & "'----------------------------------"
- NewConfigString = NewConfigString & vbcrlf & "You may write anything you like after the eof tag."
- If MsgBox("Save new configuration to file?", 4, "Save Settings?") = 6 Then
- Set NewConfigFile = filesys.CreateTextFile(WorkingFolder & "PostProcess.cfg", True)
- NewConfigFile.WriteLine NewConfigString
- NewConfigFile.Close
- Else
- Wscript.Quit
- End If
- If Not Filesys.FileExists(WorkingFolder & "NewsTitles.cfg") Then
- Set NewConfigFile = filesys.CreateTextFile(WorkingFolder & "NewsTitles.cfg", True)
- ScriptLog "News title dictionary not found. Creating now.",2, ID
- NewConfigFile.WriteLine "'The title translation dictionary. Used to maintain consistent show titles and to correct/append names."
- NewConfigFile.WriteLine "'This may eventually be discontinued when sources are more uniform in naming."
- NewConfigFile.WriteLine "'FORMAT : a show name<-TAB->The formatted show name"
- NewConfigFile.WriteLine "'The next line sets the dictionary name to load the following entries into."
- NewConfigFile.WriteLine "'----------------------------------"
- NewConfigFile.WriteLine "NewsDict"
- NewConfigFile.WriteLine "'----------------------------------"
- NewConfigFile.WriteLine "'CBS"
- NewConfigFile.WriteLine "cbs 2 news ny at 5pm CBS 2 News NY at 5PM"
- NewConfigFile.WriteLine "'----------------------------------"
- NewConfigFile.WriteLine "eof"
- NewConfigFile.WriteLine "'----------------------------------"
- NewConfigFile.WriteLine "You may write anything you like after the eof tag."
- NewConfigFile.Close
- End If
- If Not Filesys.FileExists(WorkingFolder & "MovieTitles.cfg") Then
- Set NewConfigFile = filesys.CreateTextFile(WorkingFolder & "MovieTitles.cfg", True)
- ScriptLog "Movie title dictionary not found. Creating now.",2, ID
- NewConfigFile.WriteLine "'----------------------------------"
- NewConfigFile.WriteLine "MovieDict"
- NewConfigFile.WriteLine "'----------------------------------"
- NewConfigFile.WriteLine "Mojin- The Lost Legend Mojin- The Lost Legend"
- NewConfigFile.WriteLine "Mojin_ The Lost Legend Mojin- The Lost Legend"
- NewConfigFile.WriteLine "'----------------------------------"
- NewConfigFile.WriteLine "eof"
- NewConfigFile.WriteLine "'----------------------------------"
- NewConfigFile.WriteLine "You may write anything you like after the eof tag."
- NewConfigFile.Close
- End If
- If Not Filesys.FileExists(WorkingFolder & "ShowTitles.cfg") Then
- Set NewConfigFile = filesys.CreateTextFile(WorkingFolder & "ShowTitles.cfg", True)
- ScriptLog "TV Show title dictionary not found. Creating now.",2, ID
- NewConfigFile.WriteLine "'----------------------------------"
- NewConfigFile.WriteLine "ShowDict"
- NewConfigFile.WriteLine "'----------------------------------"
- NewConfigFile.WriteLine "Genius Genius"
- NewConfigFile.WriteLine "National Geographic Presents - Genius Genius"
- NewConfigFile.WriteLine "'----------------------------------"
- NewConfigFile.WriteLine "eof"
- NewConfigFile.WriteLine "'----------------------------------"
- NewConfigFile.WriteLine "You may write anything you like after the eof tag."
- NewConfigFile.Close
- End If
- NeedSetup = False
- End Sub
- 'QType - 0=string 1=folder 2=y/n
- Function UserInput(ITitle,QString,CValue,QType)
- If QType = 0 Then
- UserEnteredString = InputBox(QString, ITitle, CValue)
- If UserEnteredString = "" Then
- Exit Function
- Else
- UserInput = UserEnteredString
- End If
- ElseIf QType = 1 Then
- UserSelectedFolder = SelectFolder("",QString)
- If Filesys.FolderExists(UserSelectedFolder) Then
- UserInput = UserSelectedFolder
- Else
- WayOut
- Exit Function
- End If
- End If
- End Function
- Function SelectFolder( myStartFolder,myPromptString )
- ' This function opens a "Select Folder" dialog and will
- ' return the fully qualified path of the selected folder
- '
- ' Argument:
- ' myStartFolder [string] the root folder where you can start browsing;
- ' if an empty string is used, browsing starts
- ' on the local computer
- '
- ' Returns:
- ' A string containing the fully qualified path of the selected folder
- '
- ' Written by Rob van der Woude
- ' http://www.robvanderwoude.com
- ' Standard housekeeping
- Dim objFolder, objItem, objShell
- ' Custom error handling
- On Error Resume Next
- SelectFolder = vbNull
- ' Create a dialog object
- Set objShell = CreateObject( "Shell.Application" )
- Set objFolder = objShell.BrowseForFolder( 0, myPromptString, 0, myStartFolder )
- ' Return the path of the selected folder
- If IsObject( objfolder ) Then SelectFolder = objFolder.Self.Path
- ' Standard housekeeping
- Set objFolder = Nothing
- Set objshell = Nothing
- On Error Goto 0
- End Function
- Sub WayOut()
- If MsgBox("Are you sure you want to quit setup?", 4, "Quit?") = 6 Then
- Wscript.Quit
- End If
- End Sub
Advertisement
Add Comment
Please, Sign In to add comment