1

I'm working on a python program which organizes a music library. The program will basically help me detect misspelled file or directory names, wrong FLAC tags or unknown/superfluous files. It will also make sure that the FLAC files are named correctly according to their FLAC tags etc.

The structure I though of looks as follows (/ being the root of the music library):

/
 [category]
 [artist]
 [year] - [release]
 [track number] - [title].flac
 [...]
 [artist] - [release].jpg
 [artist] - [release].cue
 [artist] - [release].log
 Various Artists
 [artist_0 [, artist_1 [, ...]]] - [year] - [release]
 [track number] - [title].flac
 [...]
 [artist_0 [, artist_1 [, ...]]] - [release].jpg
 [artist_0 [, artist_1 [, ...]]] - [release].cue
 [artist_0 [, artist_1 [, ...]]] - [release].log
 [...]
 [...]

I started writing some code but pretty soon I noticed that this is actually not a too easy problem to solve. I wrote 4 functions, category, artist, release and file, which are called accordingly while iterating through all the directories. Basically like that (pseudo code):

func category:
 do some checks
 for each file in this directory:
 artist(file)
func artist:
 do some checks
 for each file in this directory:
 release(file)
func release:
 do some checks
 for each file in this directory:
 file(file)
func file:
 do some checks (FLAC tags etc)
for each file in the root directory:
 category(file)

Now I'm wondering, are there any known algorithms or techniques which could be used to solve this problem in an elegant way?

asked Mar 31, 2014 at 19:53
2
  • Another need for the Elegant Pattern. Commented Mar 31, 2014 at 20:01
  • 1
    It seems like you're worried about the code repetition you think you are seeing. But you're operating on different fields, so I don't see how you really have any repetition here. Commented Mar 31, 2014 at 20:39

1 Answer 1

2

There is absolutely nothing wrong with your approach.

Note that if the "do some checks" part was the same in every function, then indeed you could simplify and have a single function that calls itself recursively on sub-folders. Perhaps this is what you had in mind... But this is not the case here as each function is clearly different.

Since you are using Python, you might want to check the os module, esp. os.walk(), which may help traverse the directory structure.

answered Mar 31, 2014 at 21:09
1
  • Thanks for your input. And yes you are right, the "do some checks" is in each function clearly different. Commented Apr 1, 2014 at 6:41

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.