updated to include some additional comments, as well as some of the missing services for naming. This might cause some of the line numbers referenced in the initial post to be off...
v6
[code]/# <>
This script is the initial attempt at making the Flow more generic to use for MOVIES from all services. It relies on StreamFab using a folder for each service (See the naming template below)
REQUIRED: Download MediaInfo CLI from -> https://mediaarea.net/en/MediaInfo/Download/Windows ONE TIME SETUP: unzip it, and add the folder to the Windows Path environment variable, exit and restart Power Automate before running or HDR/DV detection will not work.
This script relies on StreamFab's VIP Services naming template for MOVIES be:
{edition-}
Make sure you set the FolderBase line 4 and 7. The IF statements are there (lines 3-8) in case you have more than one computer.
Folder Base =Top level of StreamFab's Output folder.
#/
DateTime.GetCurrentDateTime.Local DateTimeFormat: DateTime.DateTimeFormat.DateAndTime CurrentDateTime=> DT_Start
**REGION Determine StreamFab's output folder
/# I have a PC and a Laptop. StreamFab's output file is a different path on each. The path is used throughout the flow.
Rather than manually setting an environment variable each time I open the script to run it, the next two IF Folder Exists section determine which PC I'm using, and therefore which StreamFab output folder to look at, and set a veriable called FolderBase which will be used throughout this process
#/
IF (Folder.IfFolderExists.Exists Path: $'''F:\\BluRay-Working\\- DVDFab10\\DVDFab Downloader''') THEN
SET FolderBase TO $'''F:\\BluRay-Working\\- DVDFab10\\DVDFab Downloader'''
END
IF (Folder.IfFolderExists.Exists Path: $'''C:\\DVDFab\\StreamFab\\Download''') THEN
SET FolderBase TO $'''C:\\DVDFab\\StreamFab\\Download'''
END
**ENDREGION
Folder.GetSubfolders Folder: FolderBase FolderFilter: $'''*''' IncludeSubfolders: False FailOnAccessDenied: True SortBy1: Folder.SortBy.NoSort SortDescending1: False SortBy2: Folder.SortBy.NoSort SortDescending2: False SortBy3: Folder.SortBy.NoSort SortDescending3: False Subfolders=> Folders
SET MovieCount TO 0
/# Steps 12-38 set a variable "Service" to the friendly name or abbreviation for the service I want when renaming my files.
For example, Fab calls the Amazon folder amazon, but I want it to be Amz in my files. #/
LOOP FOREACH CurrentItem IN Folders
**REGION Configure Startup Variables
SET FolderPath TO CurrentItem
DISABLE SET FolderPath TO $'''%FolderBase%\\%FolderService%'''
IF CurrentItem.Name = $'''Amazon''' THEN
SET Service TO $'''Amz'''
END
IF CurrentItem.Name = $'''AppleTV+''' THEN
SET Service TO $'''A+'''
END
IF CurrentItem = $'''DiscoveryPlus''' THEN
SET Service TO $'''DiscoveryPlus'''
END
IF CurrentItem.Name = $'''Disney+''' THEN
SET Service TO $'''D+'''
END
IF CurrentItem = $'''DRM MPD''' THEN
SET Service TO $'''DRM MPD'''
END
IF CurrentItem = $'''ESPN+''' THEN
SET Service TO $'''ESPN+'''
END
IF CurrentItem = $'''FOD''' THEN
SET Service TO $'''FOD'''
END
IF CurrentItem = $'''HBOMax''' THEN
SET Service TO $'''HBOMax'''
END
IF CurrentItem.Name = $'''Hulu''' THEN
SET Service TO $'''Hulu'''
END
IF CurrentItem.Name = $'''Max''' THEN
SET Service TO $'''Max'''
END
IF CurrentItem.Name = $'''netflix''' THEN
SET Service TO $'''Netflix'''
END
IF CurrentItem.Name = $'''Paramount+''' THEN
SET Service TO $'''Paramount+'''
END
IF CurrentItem.Name = $'''Peacock''' THEN
SET Service TO $'''Peacock'''
END
IF CurrentItem.Name = $'''PlutoTV''' THEN
SET Service TO $'''PlutoTV'''
END
IF CurrentItem.Name = $'''RakutenTV''' THEN
SET Service TO $'''RakutenTV'''
END
IF CurrentItem.Name = $'''Roku''' THEN
SET Service TO $'''Roku'''
END
IF CurrentItem.Name = $'''Tubi''' THEN
SET Service TO $'''Tubi'''
END
IF CurrentItem.Name = $'''YouTube''' THEN
SET Service TO $'''YT'''
END
IF CurrentItem.Name = $'''YouTube Movies''' THEN
SET Service TO $'''YTM'''
END
IF CurrentItem.Name = $'''YouTube Plus''' THEN
SET Service TO $'''YTP'''
END
**ENDREGION
Folder.GetFiles Folder: FolderPath FileFilter: $'''*.mkv''' IncludeSubfolders: False FailOnAccessDenied: True SortBy1: Folder.SortBy.NoSort SortDescending1: False SortBy2: Folder.SortBy.NoSort SortDescending2: False SortBy3: Folder.SortBy.NoSort SortDescending3: False Files=> FilesMKV
LOOP FOREACH MP4Files IN FilesMKV
SET Is4K TO $'''No'''
File.GetPathPart File: MP4Files Directory=> Directory FileName=> FileName FileNameWithoutExtension=> FileNameNoExtension Extension=> FileExtension
**REGION Get Video info - MediaInfo CLI
# This DOS Command runs MediaInfoCLI to return Frame Width, Frame Height, HDR Format and Video Codec used. Each are then stored in variables for use later.
@@copilotGeneratedAction: 'False'
Scripting.RunDOSCommand.RunDOSCommand DOSCommandOrApplication: $'''mediainfo --Output=Video;%%Width%%x%%Height%%x%%HDR_Format/String%%x%%Format%% \"%Directory%\\%FileNameNoExtension%.mkv\"''' WorkingDirectory: Directory StandardOutput=> CommandOutput2 StandardError=> CommandErrorOutput2 ExitCode=> CommandExitCode2
Text.SplitText.SplitWithDelimiter Text: CommandOutput2 CustomDelimiter: $'''x''' IsRegEx: False Result=> MediaInfoOut
SET varFrameWidth TO MediaInfoOut[0]
SET varFrameHeight TO MediaInfoOut[1]
SET HDR_Format TO MediaInfoOut[2]
SET CodecID TO MediaInfoOut[3]
# This DOS Command runs MediaInfoCLI to return the Audio Format which is stored as a variable for use later
@@copilotGeneratedAction: 'False'
Scripting.RunDOSCommand.RunDOSCommand DOSCommandOrApplication: $'''mediainfo --Output=Audio;%%Format/Info%% \"%Directory%\\%FileNameNoExtension%.mkv\"''' WorkingDirectory: Directory StandardOutput=> AudioFormat StandardError=> CommandErrorOutput3 ExitCode=> CommandExitCode3
**ENDREGION
**REGION Determine Audio Type based on Audio Format string returned from MediaInfo CLI
# This Section evaluates the string returned from MediaInfo CLI for Audio type looking for EAC3, EAC3 JOC, or AAC and sets a variable to optionally be used in file naming later.
SET Audio TO $'''%''%'''
IF Contains(AudioFormat, $'''Enhanced AC-3''', True) THEN
SET Audio TO $''' DD+ E-AC-3'''
END
IF Contains(AudioFormat, $'''Enhanced AC-3 with Joint Object Coding''', True) THEN
SET Audio TO $'''DD+ Atmos'''
END
IF Contains(AudioFormat, $'''Advanced Audio Codec Low Complexity''', True) THEN
SET Audio TO $''' AAC'''
END
**ENDREGION
**REGION Determine video resolution
IF (varFrameHeight = 2160 OR varFrameWidth = 3840) = $'''True''' THEN
SET Resolution TO $'''2160p'''
END
IF (varFrameWidth = 1920 OR varFrameHeight = 1080) = $'''True''' THEN
SET Resolution TO $'''1080p'''
END
IF (varFrameWidth = 1280 OR varFrameHeight = 720) = $'''True''' THEN
SET Resolution TO $'''720p'''
END
**ENDREGION
**REGION Set HDRType based on Mediainfo CLI
IF HDR_Format = $'''SMPTE ST 2086, HDR10 compatible''' THEN
SET HDRType TO $'''HDR10'''
END
IF (Contains(HDR_Format, 'dvhe.08.0', True) OR Contains(HDR_Format, 'dvhe.07.0', True)) = $'''True''' THEN
SET HDRType TO $'''DoVi HDR10'''
END
IF Contains(HDR_Format, $'''dvhe.05.0''', True) THEN
SET HDRType TO $'''DV'''
END
**ENDREGION
IF (Service = 'Peacock') = $'''True''' THEN
# Since SF's template doesn't work with Peacock files, I need to handle the initial splitting its file name differently. this step does that.
DISABLE SET NewVar3 TO MP4Files.NameWithoutExtension
Text.SplitText.SplitWithDelimiter Text: MP4Files.NameWithoutExtension CustomDelimiter: $'''.mkv''' IsRegEx: True Result=> TextList
ELSE
DISABLE SET NewVar3 TO FileName
Text.SplitText.SplitWithDelimiter Text: FileName CustomDelimiter: $'''{e''' IsRegEx: True Result=> TextList
END
# set some additional variables used during the rename process
SET MKVFilesFullname TO $'''%Directory%\\%MP4Files.NameWithoutExtension%.m kv'''
SET MKVFileName TO $'''%MP4Files.NameWithoutExtension%.mkv'''
SET MKVFilesFullname TO $'''%Directory%\\%MP4Files.NameWithoutExtension%.m kv'''
SET MKVFilesFullname1 TO $'''%Directory%\\%MP4Files.NameWithoutExtension%'' '
IF (Service = 'Peacock') = $'''True''' THEN
IF Resolution = $'''2160p''' THEN
File.RenameFiles.RenameAddText Files: MP4Files.FullName TextToAdd: $''' %Resolution% {edition-%Service% DL 4K %HDRType%}''' TextPosition: File.AddTextPosition.AfterName IfFileExists: File.IfExists.Overwrite RenamedFiles=> RenamedFiles
SET NewFolderName1 TO $'''%TextList[0]%- 4K'''
ELSE
File.RenameFiles.RenameAddText Files: MP4Files.FullName TextToAdd: $''' %Resolution% {edition-%Service% DL}''' TextPosition: File.AddTextPosition.AfterName IfFileExists: File.IfExists.DoNothing RenamedFiles=> RenamedFiles
SET NewFolderName1 TO TextList[0]
END
ELSE
IF Resolution = $'''2160p''' THEN
File.RenameFiles.RenameReplaceText Files: MKVFilesFullname TextToReplace: $'''{edition-}''' ReplaceWith: $'''%Resolution% {edition-%Service% DL 4K %HDRType%}''' IfFileExists: File.IfExists.DoNothing RenamedFiles=> RenamedFiles
SET NewFolderName1 TO $'''%TextList[0]%- 4K'''
ELSE
File.RenameFiles.RenameReplaceText Files: MKVFilesFullname TextToReplace: $'''{edition-}''' ReplaceWith: $'''%Resolution% {edition-%Service% DL}''' IfFileExists: File.IfExists.DoNothing RenamedFiles=> RenamedFiles
SET NewFolderName1 TO TextList[0]
END
END
Folder.Create FolderPath: FolderPath FolderName: NewFolderName1 Folder=> NewFolder
SET NewRenamed TO RenamedFiles[0]
DISABLE File.Move Files: NewRenamed.FullName Destination: NewFolder.FullName IfFileExists: File.IfExists.DoNothing MovedFiles=> MovedFiles
# since PAD's File Move/File Copy funtions weren't working, I went with DOS command instead. These next two steps handle that.
SET DOSCommand TO $'''move \"%NewRenamed%\" \"%NewFolder%\"'''
Scripting.RunDOSCommand.RunDOSCommand DOSCommandOrApplication: DOSCommand WorkingDirectory: FolderPath StandardOutput=> CommandOutput StandardError=> CommandErrorOutput ExitCode=> CommandExitCode
Variables.IncreaseVariable Value: MovieCount IncrementValue: 1
END
END
**REGION Calculate run time and files processed
DateTime.GetCurrentDateTime.Local DateTimeFormat: DateTime.DateTimeFormat.DateAndTime CurrentDateTime=> DT_End
DateTime.Subtract FromDate: DT_End SubstractDate: DT_Start TimeUnit: DateTime.DifferenceTimeUnit.Hours TimeDifference=> TimeDifference
Variables.TruncateNumber.GetIntegerPart Number: TimeDifference Result=> Hours
Variables.TruncateNumber.GetDecimalPart Number: TimeDifference Result=> Remainder
SET Minutes TO Remainder * 60
Variables.TruncateNumber.GetDecimalPart Number: Minutes Result=> Remainder
Variables.TruncateNumber.GetIntegerPart Number: Minutes Result=> Minutes
Variables.TruncateNumber.GetIntegerPart Number: Remainder * 60 Result=> Seconds
**ENDREGION
Display.ShowMessageDialog.ShowMessageWithTimeout Title: $'''Complete''' Message: $'''Processed %MovieCount% movies
%Hours%h %Minutes%m %Seconds%s''' Icon: Display.Icon.None Buttons: Display.Buttons.OK DefaultButton: Display.DefaultButton.Button1 IsTopMost: True Timeout: 180 ButtonPressed=> ButtonPressed
[/code]