Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

eyed3.load creating string rather than an eyed3 object? #643

Open
JohnBrandonOlsen opened this issue Jan 17, 2025 · 2 comments
Open

eyed3.load creating string rather than an eyed3 object? #643

JohnBrandonOlsen opened this issue Jan 17, 2025 · 2 comments

Comments

@JohnBrandonOlsen
Copy link

JohnBrandonOlsen commented Jan 17, 2025

Calling eyed3.load for an mp3 file is creating string variables rather than eyed3 objects.

Python 3.10.12 (main, Nov 6 2024, 20:22:13) [GCC 11.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.

import eyed3
audiofile = eyed3.load("{filename}.mp3")
print(audiofile)
{filename}.mp3
print(audiofile.tag.artist)
Traceback (most recent call last):
File "", line 1, in
AttributeError: 'NoneType' object has no attribute 'artist'

Any idea what might cause this?

@ferdnyc
Copy link

ferdnyc commented Jan 17, 2025

@JohnBrandonOlsen

Well, reading the current code for eyed3.load(), it's impossible. There's no code path that leads to it returning a string:

eyeD3/eyed3/core.py

Lines 422 to 456 in 2cdef0d

def load(path, tag_version=None) -> Optional[AudioFile]:
"""Loads the file identified by ``path`` and returns a concrete type of
:class:`eyed3.core.AudioFile`. If ``path`` is not a file an ``IOError`` is
raised. ``None`` is returned when the file type (i.e. mime-type) is not
recognized.
The following AudioFile types are supported:
* :class:`eyed3.mp3.Mp3AudioFile` - For mp3 audio files.
* :class:`eyed3.id3.TagFile` - For raw ID3 data files.
If ``tag_version`` is not None (the default) only a specific version of
metadata is loaded. This value must be a version constant specific to the
eventual format of the metadata.
"""
from . import mimetype, mp3, id3
if not isinstance(path, pathlib.Path):
path = pathlib.Path(path)
log.debug(f"Loading file: {path}")
if path.exists():
if not path.is_file():
raise IOError(f"not a file: {path}")
else:
raise IOError(f"file not found: {path}")
mtype = mimetype.guessMimetype(path)
log.debug(f"File mime-type: {mtype}")
if mtype in mp3.MIME_TYPES:
return mp3.Mp3AudioFile(path, tag_version)
elif mtype == id3.ID3_MIME_TYPE:
return id3.TagFile(path, tag_version)
else:
return None

But since you're testing in Python 3.10.12, I'm guessing you're on an LTS distro, which means you may not be running the most current eyed3 version, either. What's the value of eyed3.version?

@JohnBrandonOlsen
Copy link
Author

I only just installed eyed3 yesterday, the version is 0.9.7

I've played with it more since last night and have got it working somewhat, but it is still a real hassle of a workaround. Hopefully it is still something I am doing wrong or missing.

The errors are being thrown when files do not have an ID3 profile.

`Time: 15:53 MPEG1, Layer III [ 128 kb/s @ 44100 Hz - Joint stereo ]

No ID3 v1.x/v2.x tag found!
audiofile.tag.artist = "[Artist Name]"
AttributeError: 'NoneType' object has no attribute 'artist'
`

I have been opening each mp3 file in VLC and adding a title to the ID3 information. Once that is done everything was working as expected.

Thanks for responding, in replying to you here I discovered the initTag function and that has solved my issue!

https://stackoverflow.com/questions/31326789/create-new-id3-tag-using-python-and-eyed3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants