0

I've written a little script to move all my .flac files from dap to artist subfolders so it can easily be accessed from computer. I used python3 on Ubuntu with libs such as eyed3 and os. And it worked fine with almost 30 songs (2 artists). So here is the code:

    import os
    import eyed3

    os.chdir("/home/user/Music")
    cwd = os.getcwd()

    # print the current directory
    print("Current working directory is:", cwd)

    listOfFiles = os.listdir()
    artists = []

    # print(listOfFiles)

    try:
        for file in listOfFiles:
            aFile = eyed3.load(file)
            artist = aFile.tag.artist
            if artist not in a:
                artists.append(artist)
                os.mkdir(artist)
            os.rename(cwd + '/' + file, cwd + '/' + artist + '/' + file)
    except:
        print("not a file")

    print(artists)

It created 2 folders as it has to. But when I tried to run this script on my Windows PC it trows an exception and prints "not a file". Here is console output without try/except:

Traceback (most recent call last):
  File "D:\GitHub\Song-Sorter\main.py", line 21, in <module>
    artist = aFile.tag.artist
AttributeError: 'NoneType' object has no attribute 'tag'

So I tried this (next line after artist = aFile.tag.artist):

print(type(artist))

and its output is:

<class 'NoneType'>

What is the problem? Can't figure out

Pavel Bredelev
  • 1,301
  • 2
  • 12
  • 12
  • always put full error message (starting at word "Traceback") in question (not comment) as text (not screenshot). There are other useful information. – furas Oct 15 '19 at 08:49
  • maybe some file doesn't have information about `artist` - you should check this file in other program. – furas Oct 15 '19 at 08:50

1 Answers1

0

Found a solution. I tested this script on my mp3 part of library and it worked fine. Then I tried on flac part and it did not work because eyed3 works only with mp3. So I recomend using Mutagen library

Pavel Bredelev
  • 1,301
  • 2
  • 12
  • 12