Skip to content

Instantly share code, notes, and snippets.

@axeldelafosse
Created February 8, 2023 23:31
Show Gist options
  • Save axeldelafosse/e2f21eaff6b6392790352cabd42430bd to your computer and use it in GitHub Desktop.
Save axeldelafosse/e2f21eaff6b6392790352cabd42430bd to your computer and use it in GitHub Desktop.
Write the ID3v2.4 tag `TXXX:STYLE` to `TCON`
import sys
import mutagen
def write_style_to_genre(input_path):
# Open the file
file = mutagen.File(input_path)
print(file.tags.pprint())
# Check if the file has a STYLE tag
if "TXXX:STYLE" in file:
# Extract the style
style = file["TXXX:STYLE"].text[0]
# Print the style
print(style)
# Set the genre
file["TCON"] = mutagen.id3.TCON(encoding=3, text=style)
# Save the file
file.save()
else:
print("Error: The file does not have a STYLE tag.")
# Read the input path from the command line arguments
input_path = sys.argv[1]
# Write style to genre
write_style_to_genre(input_path)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment