[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 =StreamFab's Output folder.
#/
DateTime.GetCurrentDateTime.Local DateTimeFormat: DateTime.DateTimeFormat.DateAndTime CurrentDateTime=> DT_Start
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
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
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.Name = $'''Disney+''' THEN
SET Service TO $'''D+'''
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 = $'''Peacock''' THEN
SET Service TO $'''Peacock'''
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 returns 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 $''' E-AC-3'''
END
IF Contains(AudioFormat, $'''Enhanced AC-3 with Joint Object Coding''', True) THEN
SET Audio TO $''' 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 - Mediainfo CLI
IF HDR_Format = $'''SMPTE ST 2086, HDR10 compatible''' THEN
SET HDRType TO $'''HDR10'''
END
IF (Contains(HDR_Format, 'dvhe.08.06', True) OR Contains(HDR_Format, 'dvhe.07.06', True)) = $'''True''' THEN
SET HDRType TO $'''DoVi HDR10'''
END
IF Contains(HDR_Format, $'''dvhe.05.06''', True) THEN
SET HDRType TO $'''DV'''
END
**ENDREGION
DISABLE GOTO 'End'
IF (Service = 'Peacock') = $'''True''' THEN
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 MKVFilesFullname TO $'''%Directory%\\%MP4Files.NameWithoutExtension%.mkv'''
SET MKVFileName TO $'''%MP4Files.NameWithoutExtension%.mkv'''
SET MKVFilesFullname TO $'''%Directory%\\%MP4Files.NameWithoutExtension%.mkv'''
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
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
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]