Search code examples
pythonpython-3.xitunesmp4mutagen

iTunes MP4 Tags / Metadata with Python3 and Mutagen


I'm currently using the Mutagen module for Python to prepare the MP4 Tags of a video-file for iTunes. It works fine, but I miss one really important tag, it's called "stik" and stands for the iTunes media type.

This is my current code:

mp4_video_tags = MP4(mp4_file)

mp4_video_tags['\xa9nam'] = 'Video Name'
mp4_video_tags['\xa9alb'] = 'DVD-Name'
mp4_video_tags['\xa9gen'] = 'Video-Training'
mp4_video_tags['\xa9day'] = '2015'
mp4_video_tags['\xa9ART'] = 'Company'
mp4_video_tags['aART'] = 'Company'
mp4_video_tags['\xa9wrt'] = 'Company'
mp4_video_tags['cprt'] = 'Copyright (c) Company'
mp4_video_tags['desc'] = 'description'
mp4_video_tags['tvsh'] = 'DVD-Name'
mp4_video_tags['trkn'] = [(1, 18)]
mp4_video_tags['disk'] = [(1, 1)]
mp4_video_tags['stik'] = 10

mp4_video_tags.save()

That code works really fine, but it crashes at "mp4_video_tags['stik'] = 10", because the value of this tag can't be an integer. But according to this list: https://code.google.com/p/mp4v2/wiki/iTunesMetadata#Media_Type_%28stik%29

it must be an integer with the value of 10 for a TV Show.

I've noticed that Mutagen does not show the "stik" tag in their tag list / docs, maybe it's not supported by default: https://mutagen.readthedocs.org/en/latest/api/mp4.html

Could anyone explain me how I can set the MP4 Tag "stik" to 10 for TV Shows with Mutagen?


Solution

  • I know I'm a little late to the party, but I have a gift:

    mp4_tags['stik'] = str(unichr(10))
    

    I haven't tried it but I think you can also use mp4_tags['stik'] = '\n' as well as the newline character is represented by the binary number 10.

    The problem is iTunes reads the field as a binary number, you can save more or less anything you want to it. for example I tried setting mp4_tags['tvsn'] = '2' and I loaded the file into iTunes it was displayed as Season 50 which if you look on a ASCII table is how the character 2 is represented.

    Seems to be a bug in the library.