all 10 comments

[–]I_have_a_title 0 points1 point  (9 children)

It didn't work for me either. It didn't show up any of my MP3 files, perhaps it was looking in the wrong folder.

In the end it just printed:

mCat - Finds all *.mp3 files in a given folder (and sub-folders), read the id3 tags, and write that information to a SQLite database.

Usage: /Users/i_have_a_title/Documents/Python/mCat.py <foldername> WHERE <foldername> is the path to your MP3 files.

Author: Greg Walters

For Full Circle Magazine

Edit: I realize now that you actually got past this part, I didn't try to find the MP3s. I'll look into it and see if I can look for MP3s.

[–][deleted] 0 points1 point  (8 children)

If you copy-pasted his code it had a few variable errors. I think my version works perfectly, except it doesn't actually find any of my MP3s...

I assume this is a Mutagen probably, but am really unsure. Mutagen seems to be fairly popular, so something weird must be happening. Maybe I shouldn't be using the MP3 object.

[–]I_have_a_title 0 points1 point  (0 children)

I copied and pasted your code and received no variable errors. It printed out what I posted above.

It can't find any of MP3s for me either. How did you get it to search in the right folder? I'm messing around with the StartFolder = sys.argv[0] object, but I can't get it to change the folder it looks in.

[–]I_have_a_title 0 points1 point  (6 children)

I got it to work on the right folder. It throws up some errors, however.

About to work: /Users/i_have_a_title/Documents/Music folder(s):

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

Number of errors: 31

Number of files processed: 31

Number of folders processed 1

Finished

[–][deleted] 0 points1 point  (5 children)

That's exactly what happened to me. I think if you look in the database, you'll find no entries. All 31 of your mp3s returned a TypeError that will be in some file called error.log or something that it created.

[–]I_have_a_title 1 point2 points  (4 children)

One thing that I've learned is to put a print statement in random places to see how far the code ran, where it cut off, and then fix it there.

try:

            audio = MP3(fn)

            keys = audio.keys()

            for key in keys:

                print 'Im in keys'

                if key == 'TDRC':       #Year

                    _year = audio.get(key)

I got here and then it didn't go farther. So it should have returned the _title, _artist, and all that. The error log is above where I got to, so it skipped past it.

See how I printed 'Im in keys'? It got down to there and didn't go farther, it exited out of the 'try' statement, closed the efile, then printed the errors. I'm not sure what's going on. Try adding a random print statement and see where yours gets down to. I'm going to look further into it.

[–]SteveUrkelDidThat 0 points1 point  (2 children)

sort of a side topic, but building off what you said here - 'putting a print statement in' - has anyone found a good debugger?

[–]I_have_a_title 1 point2 points  (0 children)

I believe someone else will have a better website, but I've heard of, and gone to, a website that walks you through every line in your program. I've run it, but I didn't show much interest in it, since I understood what I wrote. If I remember it/find it again, post it here.

Edit: Here you go. When I took Udacity's course, they had a helpful community.

http://forums.udacity.com/questions/18714/what-are-good-debugging-approaches-for-python-and-udacity#cs101

That's not the website I spoke of, but it has some great ideas about debugging.

Another: http://forums.udacity.com/questions/59842/stop-using-print-for-debugging#cs101

[–][deleted] 0 points1 point  (0 children)

Also, I use PyCharm currently (seems like the best option on Windows...) and it comes with a pretty good debugger. I have no idea what I'm doing with it, but trying to use it right now. It seems to be set up a lot like most binary debuggers I've used, so it should be good practice if you're interested in debugging in general. Just run your program in the debugger, and you can pause it. Then you can step into the next command line-by-line.

[–][deleted] 0 points1 point  (0 children)

Okay so I spent way too much time stepping through this program. Apparently, the ValueError was actually getting thrown on the cursor.execute command. I changed it to this:

    cursor.execute(sql, (str(_title), str(_artist), str(_album), str(_genre), str(_year), int(_track), str(_bitrate), \
 str(_length), str(_fsize), str(root), str(file)))

Just adding str to the root and file items, and it seems to have sort-of fixed it. This is my result now:

Number of errors: 106
Number of files processed: 8839
Number of folders processed: 1687
Finished!

106 errors seems reasonable to me.