iTunes specific tags


#1

Hello,

I use Mp3tag to tag my whole iTunes-library (m4a-files).

I want the media to look exactly like iTunes purchased m4a-files.

But there are three fields I couldn't handle:

Apple Store Country ('sfID')
Album Title ID ('atID')
Genre ID ('geID')

How can I set those?

Best regards,
Felix


#2

Done with mutagen:

from mutagen.mp4 import MP4

audio = MP4("test.m4a")
audio["geID"] = [12345]
audio["atID"] = [12345]
audio["sfID"] = [12345]
audio.pprint()
audio.save()

#3

Wrote a little dirty script to tag after tagged with jonaaa20's tool.

Feel free to optimize it.

import requests
import json
import re
import os
import mutagen

from mutagen.mp4 import MP4

source_dir = r"C:\Lossless"

for i, name in enumerate(os.listdir(source_dir), start=0):  # iterate over all files/directories in source_dir
	if name[-4:].lower() != ".m4a":  # ignore non-mp3 files
		continue
	path = os.path.join(source_dir, name)  # build the whole file path
	# you can also check with os.path.isfile(path) to make sure it's a file you're processing
	# etc. (your mutagen update logic)
	audio = MP4(path)
	if i == 0:
		lookupid = audio["cnID"]
		lookupid = lookupid[0]
		break

# lookupid = int(input("AppleStoreCatalogID: "))

print(lookupid)

a = ('https://itunes.apple.com/lookup?country=US&entity=song&limit=200&id=%i' % lookupid)
b = requests.get(a).json()

geID = b['results'][0]['primaryGenreName']
geID = re.sub("Blues", '2', geID)
geID = re.sub("Comedy", '3', geID)
geID = re.sub("Children's Music", '4', geID)
geID = re.sub("Classical", '5', geID)
geID = re.sub("Country", '6', geID)
geID = re.sub("Electronic", '7', geID)
geID = re.sub("Holiday", '8', geID)
geID = re.sub("Classical|Opera", '9', geID)
geID = re.sub("Singer/Songwriter", '10', geID)
geID = re.sub("Jazz", '11', geID)
geID = re.sub("Latino", '12', geID)
geID = re.sub("New Age", '13', geID)
geID = re.sub("Pop", '14', geID)
geID = re.sub("R&B/Soul", '15', geID)
geID = re.sub("Soundtrack", '16', geID)
geID = re.sub("Dance", '17', geID)
geID = re.sub("Hip-Hop/Rap", '18', geID)
geID = re.sub("World", '19', geID)
geID = re.sub("Alternative", '20', geID)
geID = re.sub("Rock", '21', geID)
geID = re.sub("Christian & Gospel", '22', geID)
geID = re.sub("Vocal", '23', geID)
geID = re.sub("Reggae", '24', geID)
geID = re.sub("Easy Listening", '25', geID)
geID = re.sub("J-Pop", '27', geID)
geID = re.sub("Enka", '28', geID)
geID = re.sub("Anime", '29', geID)
geID = re.sub("Kayokyoku", '30', geID)
geID = int(geID)
geID = [geID]
print(geID)

atID = b['results'][0]['artistId']
atID = [atID]
print(atID)

sfID = b['results'][0]['country']
sfID = re.sub("ENG", '143441', sfID)
sfID = re.sub("DEU", '143443', sfID)
sfID = re.sub("CAN", '143455', sfID)
sfID = int(sfID)
sfID = [sfID]
print(sfID)

plID = b['results'][0]['collectionId']
plID = [plID]
print(plID)



for name in os.listdir(source_dir):  # iterate over all files/directories in source_dir
	if name[-4:].lower() != ".m4a":  # ignore non-mp3 files
		continue
	path = os.path.join(source_dir, name)  # build the whole file path
	# you can also check with os.path.isfile(path) to make sure it's a file you're processing
	# etc. (your mutagen update logic)
	audio = MP4(path)
	audio["geID"] = geID
	audio["atID"] = atID
	audio["sfID"] = sfID
	audio["plID"] = plID
	audio["pgap"] = False
	audio["cpil"] = False
	audio.pprint()
	audio.save()