Renaming Tatort video files with Hazel

0
Tatort
Tatort

I’m not a fan of linear TV watching. Therefore, I try to automatically download TV content that I want to watch either as Podcasts to my smartphone or as video files to my computer. The famous German TV show ‘Tatort’ is an example of the later category. How to automatically download ‘Tatort’ media files to your computer will be a topic for a separate post. This blog post however is about automatically renaming ‘Tatort’ media files with the help of ‘Hazel‘ and ‘AppleScript’.

The challenge

When downloading the latest ‘Tatort’ episode they normally only have the episode title in the file name, such as ‘Tatort-Taxi nach Leipzig.mp4. Other ‘Tatort’ files that I came across either had the episode ID such as ‘1000.mp4’ or the the season/episode number such as ‘S2016E32.mp4’ in the file name.

However, as a ‘KODI‘ and ‘Plex‘ user I would need structured file names that contain the relevant episode information in order that the two media systems are able to identify the correct ‘Tatort’ episodes. Furthermore, I personally want to have the investigator name in the file name as well. Therefore, my preferred naming scheme would be:

  • Scheme: Tatort – S<season:yyyy>E<episode:[e]e> – <id:iiii> – <title:text> – <investigator:text>.mp4
  • Example: Tatort – S2016E32 – 1000 – Taxi nach Leipzig – Lindholm.mp4

So far, I had to open a website, looking up the missing data and manually update the file name of the downloaded MP4 file. As this was too much (manual) work every week I decided to write an AppleScript for ‘Hazel‘ that would rename the MP4 files for me.

The solution

My new workflow now is:

  • I check if the file name of my ‘Tatort’ media file is formatted according to one of the following three options:
    1) episode title, e.g. ‘Taxi nach Leipzip.mp4’
    2) episode ID, e.g. ‘1000.mp4’
    3) season/episode numbering, e.g. ‘S2016E32.mp4’
    If the file name does not match any of the the above mentioned options I start watching/scrolling the beginning of the ‘Tatort’ episode. Luckily with macOS’ built-in ‘QuickView’ this can be done with little effort. I just have to hit the space bar when the media file is selected in ‘macOS Finder’.
  • At this point my ‘Hazel Tatort Workflow’ kicks in. The workflow reads the file name of the MP4 file and hands it over to the the AppleScript. The AppleScript downloads a XML file from the internet and looks up the relevant episode information. This information is then handed back to the ‘Hazel’ workflow which saves the final file name of the the MP4 file und uploads the file to the correct folder on my ‘NAS’.

The following image gallery shows how to to setup such a workflow in Hazel.

[masterslider id=”2″]

 

Additional comments for each individual step:

  • Step 1: Create a new ‘Hazel’ workflow for the folder where your new ‘Tatort’ media files are coming in. The matching condition can be set to files of the kind ‘Movie’. Then add the first rule action of the type ‘Run AppleScript’ to the workflow. Copy & paste the whole code that is listed below to this rule action as embedded code.
  • Step 2: Define the import and export values of the rule action ‘Run AppleScript’. The only import value required by the AppleScript is the file name. The export values can be defined by the user. In total there are nine export values to choose from. Please read the comments in the code for further details. It’s important that all export values with a ‘true’ value in the code show up in exactly the same sequence in Hazel’s ‘Script export’ box as in the code. If you have no idea what the instructions in this step mean, then just copy the same setup as shown in the image of ‘Step 2’.
  • Step 3: Create your preferred naming scheme for your ‘Tatort’ media files. Note that the available elements may depend on your settings in ‘Step 2’.
  • Step 4: Define the subfolder(s) where your ‘Tatort’ media files shall be copied. This step is optional.
  • Step 5: Move your ‘Tatort’ media files to your preferred storage device (internal or external hard disk, NAS, etc.). This step is optional.

Note that there can be a significant lag between the moment you copy the ‘Tatort’ media file to the watched folder and the moment Hazel is actually renaming the file. On the one hand this is due to the fact that ‘Hazel’ itself has some built-in delays until a ‘Hazel’ rule is executed. On the other hand it is also because of the poor performance of ‘AppleScript’ execution on ‘macOS’.

If you want you can also download a standalone script file that can be executed within ‘Apple Script Editor’. Read the comments within the script (especially the ‘Note’ section) to learn about the differences of the ‘Hazel script’ and the ‘Standalone script’.

Tatort AppleScript v9.2 (26.3 KB)

LEAVE A REPLY

Please enter your comment!
Please enter your name here