Errors with Python and eyed3

231 views Asked by At
import os
import eyed3


def files(path):
    for file in os.listdir(path):
        if os.path.isfile(os.path.join(path, file)):
            yield file


def title_alteration(music_artist_string):
    music_artist_string = music_artist_string.replace(';', ' feat. ', 1)
    semicolon_count = music_artist_string.count(';')
    music_artist_string = music_artist_string.replace(';', ', ', semicolon_count-1)
    music_artist_string = music_artist_string.replace(';', ' & ')
    return music_artist_string


def main():
    audio_files = eyed3.load(files('D:\\iTunes Music\\iTunes\\iTunes Media\\Music'))
    title_alteration(audio_files.tag.artist)


if __name__ == '__main__':
    main()

Can I get some help debugging this, I got it down to three distinct functions with some help from my last post, now I just need to know why is this getting errors when I attempt to run it on this directory on my pc.

I'm getting these errors (TLDR; It doesnt like Line 20 [the audio_files line]):

Traceback (most recent call last):
  File "D:/Pycharm Projects/Music Alterations v2.py", line 25, in <module>
    main()
  File "D:/Pycharm Projects/Music Alterations v2.py", line 20, in main
    audio_files = eyed3.load(files('D:\\iTunes Music\\iTunes\\iTunes Media\\Music'))
  File "C:\Users\cLappy\AppData\Local\Programs\Python\Python38\lib\site-packages\eyed3\core.py", line 74, in load
    path = pathlib.Path(path)
  File "C:\Users\cLappy\AppData\Local\Programs\Python\Python38\lib\pathlib.py", line 1038, in __new__
    self = cls._from_parts(args, init=False)
  File "C:\Users\cLappy\AppData\Local\Programs\Python\Python38\lib\pathlib.py", line 679, in _from_parts
    drv, root, parts = self._parse_args(args)
  File "C:\Users\cLappy\AppData\Local\Programs\Python\Python38\lib\pathlib.py", line 663, in _parse_args
    a = os.fspath(a)
TypeError: expected str, bytes or os.PathLike object, not generator

Process finished with exit code 1
1

There are 1 answers

0
Dennis Sparrow On

Your files function is a generator, to be used like an iterator. The eyed3.load function doesn't want a generator or an iterator. It wants a pathname or something like one. Passing a generator where a pathname is expected does not magically cause iteration over all the values the generator would generate. It would work better just to make a list of all the pathnames of interest and then iterate over that list, calling eyed3.load for each pathname.