3

Every other tag seems to work e.g. title, cover art, artist but I encounter an error for the track number tag [trkn] every time

import mutagen
from mutagen import MP4, MP4Cover

filePath = 'LoadFiles/UserUpload/test.mp4'
mp4_meta = MP4(filePath)

print("Enter the following")
title = input("Title: ")
mp4_meta['\xa9nam'] = title #works

trackno = input("Track No.: ")
mp4_meta['trkn'] = trackno #nope

mp4_meta.save()

In the mutagen documentation it states:

Tuples of ints (multiple values per key are supported):

‘trkn’ – track number, total tracks

What's the fix to this?

yst0
  • 31
  • 3

2 Answers2

3

You need to provide a tuple for this field, including the total number of tracks.

Try the following:

trackno = input("Track No: ")
totaltracks = input("Total No of Tracks: ")
mp4_meta['trkn'] = [(trackno, totaltracks)]
lys
  • 949
  • 2
  • 9
  • 33
  • 1
    As @user19702899 mentioned in their response, you must wrap the tuple in a list to avoid a ```ValueError```. This is not well defined in the [docs](https://mutagen.readthedocs.io/en/latest/api/mp4.html#mutagen.mp4.MP4Tags). I think this should be the accepted answer, but @lys I would recommend editing it to match the other user's change for the last line: ```mp4_meta['trkn'] = [(trackno, totaltracks)]```. Thank you! – Robert Silver Jul 22 '23 at 21:25
1

You actually need to provide an iterable of tuples. Same as lys' answer except for the last line (where a list containing a single tuple of 2 ints is set as the trkn value):

trackno = input("Track No: ")
totaltracks = input("Total No of Tracks: ")
mp4_meta['trkn'] = [(trackno, totaltracks)]