Announcement

Collapse
No announcement yet.

Naming Template - Using Power Automate Desktop to rename files

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    StreamFab for Windows Naming Template - Using Power Automate Desktop to rename files

    Initially this was a separate topic, but got merged into another thread, so I'm recreating this as stand alone so its not buried.

    While StreamFab has a Template for file names and such, it doesn't allow for all the options I want, and sometimes gets the resolution wrong. This Power Automate Desktop script uses MediaInfo CLI to capture the parameters of the file and sets variables that will be used in the file renaming process.

    For my Plex library I like to use the Edition tags, and capture what service the file was downloaded from, if its 4K and if it has HDR or not. I also use abbreviations for the services, rather than the full name.

    This flow meets my needs, and works, I've been using this for a long time, so I thought I'd share. I know there are other renamers out there, but I use Power Automate (cloud) for work so thought I'd play with Power Automate Desktop.

    The script evaluates for video resolution of 2160, 1080, 720. It assumes progressive scan as everything I've downloaded since using StreamFab (formerly DVDFab Downlaoder) since version 2.0.x.x has been progressive. It also evaluates HDR types of HDR10, DV, or DoVi HDR10 (which is DV with fall back to HDR10 included). Audio is evaluated for EAC3, EAC3 JOC, and AAC. However, I only use Resolution and HDR Type when naming files.


    This script relies on StreamFab's VIP Services naming template for MOVIES to be:
    <moviename> (<year>) {edition-}

    Note: Peacock doesn't use StreamFab's name template currently, so I have separate rename steps for those files. Fandango At Home doesn't get the date in the file name, so I have steps to remove the parentheses from the file name.


    While this script recurses the service provider folders in the main StreamFab Output folder, it only looks at the top level of the Service Provider folder, it does not recurse those subfolders. In other words, It does not touch already processed movies or touch TV shows as they would be in subfolders.

    I have StreamFab set to download as MKV, so this script is set to work only on MKV files. If you download as MP4, you would need to make a few changes in the flow, where MKV is specifically called out.

    What to expect:

    non-4K movie Source file:
    StreamFabOut\Amazon\MovieName (year) {edition-}.mkv

    For Fandanog at home it would be: StreamFabOut\Amazon\MovieName () {edition-}.mkv


    Output file:
    StreamFabOut\Amazon\MovieName (year)\MovieName (year) 1080p {edition-Amz DL}.mkv

    For Fandanog at home it would be: StreamFabOut\Amazon\MovieName\MovieName 1080p {edition-Vudu DL}.mkv
    ​​

    4K Movie source file (downloaded from Max as 4K only HDR10):
    StreamFabOut\Max\MovieName (year) {edition-}.mkv

    Output file:
    StreamFabOut\Max\MovieName (year)\MovieName (year) 2160p {edition-Max DL 4K HDR10}.mkv


    When copied to your Plex movie folder, they will show as the movie name, and the edition tag will be respected.

    When running from the My Flows list, it runs much much much faster than running from inside the Editor.

    I mainly use Amazon, Disney+, Hulu, Max, Paramount+, Peacock, Fandango at Home, I may not have fully tested other services, so If you find a bug, please let me know.



    REQUIRED:
    • Power Automate Desktop -> https://learn.microsoft.com/en-us/po...-flows/install
    • MediaInfo CLI from -> https://mediaarea.net/en/MediaInfo/Download/Windows
      • ONE TIME SETUP: With Power Automate Desktop Closed, download MediaInfo CLI, then unzip it, (move the folder if you need to) and add the folder to the Windows Path environment variable. To add to Path... Windows Settings -> System -> About -> Advanced System Settings -> Environment Variables. In the SYSTEM variables section, select Path, click the Edit Button, and add the folder where you unzipped MediaInfo CLI.
    • Select the entire script in Post #2 of this thread, copy to the clipboard. Open Power Automate Desktop, Create a New Flow, name it, click Create. In the Main section (middle of screen), right click and paste. The flow steps will be created there. (if copy/paste of the "code" doesn't work, please see the attached text file, to copy/paste from)
    • Make sure you set the FolderBase variable (lines 3-8 of the flow) in the Flow to match the top level if your StreamFab output folder. (also see personalization note below)

    Personalization notes:
    • I have both a laptop and desktop, the location of the download folders are different on each computer. Therefore I have a two sets of IF statements (rows 3 through 8) to evaluate if the folder exists and sets FolderBase = to the correct StreamFab output folder for the computer I'm working on.
    • While I do have MediaInfo CLI capture video and audio details to variables, I only use the video info when renaming. You can adjust rows 99-115 to include the Audio variable if you wish.
    • Lines 15-34 set the custom Service names or abbreviations used when renaming the files. So if you don't like Amz for Amazon, edit line 16 for example.
    • You can tweak the output file name string and variables on rows 99-115. ​ For example: you don't need to have the edition tag in the final file name, you can remove it.
    Other Items:
    • As I share new/updated versions of this code, the line numbers referenced in Post 1 can/will change. I'll do my best to provide mention of that in each new cost posting.
    • As new Downloader modules are released, code needs to be added to this script. For example: Fandango At Home was recently added, and I had to add lines to account for the file names, no year being provided, and folder names.
    Last edited by KidJoe; 01-30-2025, 05:04 PM.

    #2
    Code:
    /# <<Expand and read this entire comment!!>>
    
    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:
    <moviename> <year> {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
    ​
    ​
    Attached Files

    Comment


      #3
      Version 8 - Updated for Fandago at Home.

      I use Vudu as the "nick name"

      Code:
      /# <<Expand and read this entire comment!!>>
      
      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:
      <moviename> <year> {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
      LOOP FOREACH CurrentItem IN Folders
      **REGION Configure Startup Variables
      SET FolderPath TO CurrentItem
      /# Steps 19-81 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. Disney+ is the default folder name, but I want D+ when renaming my files, etc. #/
      IF CurrentItem.Name = $'''Amazon''' THEN
      SET Service TO $'''Amz'''
      END
      IF CurrentItem.Name = $'''AppleTV+''' THEN
      SET Service TO $'''A+'''
      END
      IF CurrentItem.Name = $'''DiscoveryPlus''' THEN
      SET Service TO $'''DiscoveryPlus'''
      END
      IF CurrentItem.Name = $'''Disney+''' THEN
      SET Service TO $'''D+'''
      END
      IF CurrentItem.Name = $'''DRM MPD''' THEN
      SET Service TO $'''DRM MPD'''
      END
      IF CurrentItem.Name = $'''Fandango at Home''' THEN
      SET Service TO $'''Vudu'''
      END
      IF CurrentItem.Name = $'''ESPN+''' THEN
      SET Service TO $'''ESPN+'''
      END
      IF CurrentItem.Name = $'''FOD''' THEN
      SET Service TO $'''FOD'''
      END
      IF CurrentItem.Name = $'''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.
      Text.SplitText.SplitWithDelimiter Text: MP4Files.NameWithoutExtension CustomDelimiter: $'''.mkv''' IsRegEx: True Result=> TextList
      END
      IF (Service = 'Vudu') = $'''True''' THEN
      # Since SF's Fandango At Home module doesn't include the Year, I need to handle the initial splitting its file name differently. these steps do that.
      DISABLE SET VuduDelimit TO $'''%%(%%'''
      SET Datalength TO MP4Files.NameWithoutExtension
      SET VuduLength TO TextAsNumber
      Text.ToNumber Text: Datalength.Length Number=> TextAsNumber
      Text.GetSubtext.GetSubtext Text: MP4Files.NameWithoutExtension CharacterPosition: 0 NumberOfChars: Datalength.Length - 14 Subtext=> TextList
      Text.GetSubtext.GetSubtext Text: MP4Files.NameWithoutExtension CharacterPosition: 0 NumberOfChars: Datalength.Length - 14 Subtext=> VuduNewFolderName2
      END
      IF (Contains(Service, 'Peacock', True) OR Contains(Service, 'Vudu', True)) <> $'''True''' THEN
      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'''
      SET NewFolderName2 TO NewFolderName1
      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]
      SET NewFolderName2 TO NewFolderName1
      END
      END
      IF (Service = 'Vudu') = $'''True''' THEN
      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'''
      SET NewFolderName2 TO NewFolderName1
      ELSE
      File.RenameFiles.RenameReplaceText Files: MKVFilesFullname TextToReplace: $'''() {edition-}''' ReplaceWith: $'''%Resolution% {edition-%Service% DL}''' IfFileExists: File.IfExists.DoNothing RenamedFiles=> RenamedFiles
      SET NewFolderName1 TO VuduNewFolderName2
      SET NewFolderName2 TO NewFolderName1
      END
      END
      IF (Contains(Service, 'Peacock', True) OR Contains(Service, 'Vudu', True)) <> $'''True''' THEN
      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'''
      SET NewFolderName2 TO NewFolderName1
      ELSE
      File.RenameFiles.RenameReplaceText Files: MKVFilesFullname TextToReplace: $'''{edition-}''' ReplaceWith: $'''%Resolution% {edition-%Service% DL}''' IfFileExists: File.IfExists.DoNothing RenamedFiles=> RenamedFiles
      SET NewFolderName1 TO TextList[0]
      SET NewFolderName2 TO NewFolderName1
      Text.SplitText.SplitWithDelimiter Text: FileName CustomDelimiter: $'''{e''' IsRegEx: True Result=> TextList
      END
      END
      Folder.Create FolderPath: FolderPath FolderName: NewFolderName2 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
      ​
      Attached Files

      Comment

      Working...
      X