nicfit / eyeD3

eyeD3 is a Python module and command line program for processing ID3 tags. Information about mp3 files (i.e bit rate, sample frequency, play time, etc.) is also provided. The formats supported are ID3v1 (1.0/1.1) and ID3v2 (2.3/2.4).
http://eyed3.nicfit.net/
GNU General Public License v3.0
532 stars 58 forks source link

mp3 track number #607

Closed Scarlet06 closed 2 months ago

Scarlet06 commented 9 months ago

I'm using it with python 3.11.4 on a windows 11 22H2 version. I have downloaded an mp3 file (version 2.3.0) that already has a track number. If I try to empty this tag, it updates the data, but looking at the properties of the file on windows, it shows the track number is still there. If I set another number instead, windows can show it the same new number, but again setting it to None and looking through windows, shows the initial value instead. Is there something I'm doing wrong?

The code is pretty simple tho, and it worked with other mp3 files:

import eyed3

song:eyed3.AudioFile = eyed3.load(r"path\to\file.mp3")
song.tag.track_num = (None,None)
song.tag.save()

Or is there a procedure I can apply to make sure also the property that windows can look for is being changed?

WhitePeter commented 2 months ago

Even though I am a tad late to the party, let me through in my two cents. Maybe there are id3v1 tags present? If I understand correctly, the default is to only save id3v2, leaving id3v1 alone unless instructed otherwise. I am fairly new to this package and have so far only used the command line interface. This seems to validate my guess, though:

# The default version for eyeD3 tags and save operations.
ID3_DEFAULT_VERSION = ID3_V2_4

(found in __init__ of id3)

Scarlet06 commented 2 months ago

My main program is actually doing this (I'll show a snippet here below), but it doesn't seem to solve this probelm. I can't really understand why it doesn't work.

import eyed3
song_path = "path/to/file.mp3"
mp3 = eyed3.load(song_path)

if mp3.tag is None:
    mp3initTag(eyed3.id3.ID3_V2_4)

elif mp3.tag.version<eyed3.id3.ID3_V2_4:
    mp3.tag.version=eyed3.id3.ID3_V2_4

IDJK why it isn't solving my problem

WhitePeter commented 2 months ago

My point is that there might be id3v1 tags in that file. Some taggers optionally include them for compatibility with legacy apps. What I grasp from your very limited snippet is that your main program only acts on idv2, leaving the v1 tags alone. I guess that Windows then picks up those v1 tags where it can't find a value in v2.

Have you tried checking with the eyeD3 command line program?

eyeD3 --verbose -1 "path\to\file"

That should show you all id3v1 tags. You can clear them with --remove-v1. See what Windows shows after you have done that.

Scarlet06 commented 2 months ago

Uuuh, that's clever. Now I understand what you meant. I was able to write a clunky patch to make my program work as I wanted. I'll write my solution below so that if anyone would ever met the same problem, they can peek it.

I tried my best to add some usefull comments (I'm not very good at it)

import eyed3
from eyed3.id3 import ID3_V1, ID3_V2_4

song_path = r"C:\Users\danie\Desktop\Originale.mp3"

# I load the same song with both ID3 versions
# I'll keep song_v2
song_v1 = eyed3.load(song_path, ID3_V1)
song_v2 = eyed3.load(song_path, ID3_V2_4)

if song_v1.tag is not None:
    # the song has ID3 v1 tags

    if song_v2.tag is None:
        # the song doesn't have ID3 v2 tags

        # specifying the version will convert the metadata
        song_v1.tag.save(version=ID3_V2_4)
        song_v2 = song_v1

    elif song_v2.tag.version<ID3_V2_4:
        # the song has ID3 v2 tags but isn't the latest

        song_v2.tag.save(version=ID3_V2_4)

    # it removes the extra metadata ID3 v1 I don't want to keep
    song_v2.tag.remove(song_path, song_v1.tag.version)

elif song_v2.tag is None:
    # the song doean't have ID3 v1 tags, but doesn't have v2's either

    # it creates a ID3 v2 tag for the song
    song_v2.initTag(ID3_V2_4)

elif song_v2.tag.version<ID3_V2_4:
    # the song has ID3 v2 tags but isn't the latest version

    song_v2.tag.save(version=ID3_V2_4)

mp3 = song_v2