0

I'm not knowledgeable about scripting, so I'll be upfront about that. I've been doing management with Doug's Scripts for over a decade, but the one that would be most useful (Append to Selected Tag) doesn't offer the correct fields to adjust the information I want to change.

I would like to prepend the season number and the (padded 2 digit) episode number to the beginning of episode names in my library (not the file name!), so I get something like 101 Pilot, 102 Deep Throat, 103 Squeeze, etc., in my smart playlists for using on AppleTV (because the newer AppleTVs running tvOS do not show that additional information in the playlist view, and it's easy to lose your place in long running series).

I have used Subler and iFlicks, and both can handle prepending the information and adding to iTunes going forward, but if I drop my older library files to those apps, some of my comments, groupings, etc., get erased using their update metadata options (in iFlicks 2, the artwork also gets changed, and I have to handle each season separately to change it back), and neither handle extended episodes or DVD vs Aired orderings well when starting from a clean slate.

I'm looking for a script that I can use to select entire playlists or shows and only changes the one tag (the episode name) using info from other tags that I already have populated (the original episode name, season number, and episode number) and that can pad the episode number 0-9 to 2 digits. Can someone point me in the right direction?

  • AFAIK, iTunes adds the metadata to the file directly and also stores it in the library xml. When I open the files from my media folders in other apps (such as Quicktime 7 and Subler) than iTunes, they show the metadata. To more directly answer the question, I want both. That is--I want to have the metadata embedded into the file. – blackbox Apr 21 '20 at 6:08
0

I think this will do it for you:

use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions
--
-- Start by selecting the shows in a playlist. 
-- Don't select the playlist. Select the Shows.

tell application "iTunes"
    set theShowList to the selection
    repeat with aShow in theShowList
        -- get the information we need
        set theSeasonNumber to season number of aShow
        set theEpisodeNumber to episode number of aShow
        set theName to name of aShow
        --
        -- pad the episode number to two digits
        set thePaddedEpisodeNumber to "0" & theEpisodeNumber as string
        set theTwoDigitEpisodeNumber to characters -2 thru -1 of thePaddedEpisodeNumber as string
        --
        -- assemble the new name
        set theNewName to theSeasonNumber & theTwoDigitEpisodeNumber & " " & theName as string
        --
        -- set the new name
        set the name of aShow to theNewName
    end repeat
end tell

The script could be cleaned up and made more efficient but I wrote it this way so it was easier to follow.

Be sure to select the shows, not the playlist. It doesn't work otherwise.

While experimenting with this I noticed that some TV shows have episode numbers that are three digits already. That would be a problem for this script. FYI.

This was done with iTunes 12.9.5.5, macOS Mojave 10.14.6.

Here are before and after pictures. You're going to have to zoom in.Before-- and note the shows are selected!

enter image description here

  • This worked nicely! Thanks for taking the time to work this script up for us. – blackbox Apr 24 '20 at 1:53
  • Awesome. You're welcome. – Christian Boyce Apr 24 '20 at 15:59
-1

I have a Python script called "tag_tv" that does all of this work, outside of iTunes, but fully compatible with all of the Apple products. Beyond the basic string manipulations (season, episode, title), the key is calling a piece of SW found here: https://github.com/TechSmith/mp4v2

Unfortunately, I haven't seen any binaries for this, so you need to build it yourself. I've you've ever done ANY building of open-source SW (configure, make, gcc, etc.) this one should be easy.

This is from my Python script, but you can see what you're able to set with that mp4 SW:

cmd = "mp4tags -i \"tvshow\" -S \"" + show + "\" -n " + seasonNumber + " -M " + episodeNumber + " -o " + episodeID + " -s \"" + title + "\" -y " + date + " -m \"" + desc + "\" -P " + artwork + " " + file

If you could compile this SW, you could easily script this in Shell, Python, AppleScript, etc. This is more efficient for me than trying to use one of the GUI tools you mentioned for doing the tagging.

-1

This uses ffmpeg so if you don't have that open the terminal application and download the homebrew package installer by entering this:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"

Then enter brew install ffmpeg

Set the terminal current working directory to the folder you'd like to output to by entering cd then drag and drop the folder from a finder window on top of the terminal window and it will automatically enter the path with any necessary escape characters so you can press enter.

After that copy this into a text file (change the input folder to be correct and save it):

path_to_episodes_folder="/Users/Family/Desktop/Folder With Spaces In The Name"
output_episodes_folder="/Users/Family/Desktop/Output"
output_extension=".mp3"

# For every file in the input folder:
for episode_path in "$path_to_episodes_folder/"*
do

# Get the metadata from the input file.
original_episode_title="$(ffprobe "$episode_path" -v quiet -show_entries format_tags="title" -of default=nw=1:nk=1)"
season_number="$(ffprobe "$episode_path" -v quiet -show_entries format_tags="season" -of default=nw=1:nk=1)"
episode_number="$(ffprobe "$episode_path" -v quiet -show_entries format_tags="episode" -of default=nw=1:nk=1)"

# If the episode is one digit in length (such as "1") add a leading zero. Otherwise use the default value (which is two digits long "01").
if [ ${#episode_number} == 1 ]
then
    formatted_episode_number="0${episode_number}"
else
    formatted_episode_number=$episode_number
fi

# Formatted output metadata title ("101 Title").
full_output_title="${season_number}${formatted_episode_number} ${original_episode_title}"

# The command for ffmpeg to modify the "title" metadata property on the output.
ffmpeg -i "$episode_path" -map 0 -c copy -hide_banner -metadata title="$full_output_title" "${original_episode_title}${output_extension}"
done

Then enter sh space, then drag and drop the path to the text file you just created on top of the window and press enter.

I wasn't quite sure what you were asking for in you title formatting, but the main thing is that this command will only return the "specified_value" which can then be used to change the metadata title for the output.

ffprobe "path/to/file/input.ext" -v quiet -show_entries format_tags="specified_value" -of default=nw=1:nk=1

To see all the metadata from the input for a file run this command. ffprobe -hide_banner path/to/file/basename.ext NOTE: I'm not sure if all the metadata command keywords are correct since I don't have access to the source file so use the above command to find the right keyword if it doesn't work right away.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .