Originally Posted by
prem1er
I am working on creating my first 'useful' piece of software for my own personal use. I am not completely new to Java, but I am definitely still learning. I am writing a small program to help keep my music organized on my file system and since I have most of the functionality working I figured I would share it here for you to take a look at and let me know what you think, or if anyone needs it for their own use.
My program is set to watch a specific directory for new folders being added. In my case, it watches my music directory for newly ripped or downloaded albums. It copies the files to a new location and renames them based on artist, album, and release year. This way I don't have to manually move/rename all the files and I can remove them from my download directory once I am finished seeding.
I'm using a java package called Jaudiotagger to read ID3 tags.
I haven't set up a logger yet, so excuse all the sys-outs.
Some random comments:
- Most of your print statements are pointless. There is nothing that enforces that what your print is really what you use. For instance:
Code:
File albumDirectory = new File(OUTPUT_DIR + "/" + artist + "/" + year + " - " + album);
....
System.out.println("Creating album directory: " + OUTPUT_DIR + "/" + artist + "/" + year + " - " + album);
should better be:
Code:
File albumDirectory = new File(OUTPUT_DIR + "/" + artist + "/" + year + " - " + album);
....
System.out.println("Creating album directory: " + albumDirectory.getCanonicalPath());
- Replace the hardcoded file/directory by MessageFormat string, and be ready to get these MessageFormat strings from a properties file (this wil likely be the first request by users if you make the code public):
Code:
static String albumFormat="{0}/{1}/{4}-{2}";
albumDirName=MessageFormat.format(albumFormat,[OUTPUT_DIR,artist,album,cdpart,year);
- Your file copy performance can be improved: you can use significantly larger buffers, and maybe have a look at the java.nio package which AFAIK is meant for high performance I/O.
- To test for a file extension use String.endsWith(). You may also want to use another "properties" item for the supported file extensions (to handle .ogg, .flac)...
- WATCH_DIR & OUTPUT_DIR should be a mix of properties and user home directory (maybe recognize "~" and replace by System.getProperty("user.home")
- Your test for "newFolder.lastModified()" won't work if an old directory is moved in WATCH_DIR. What really counts is the inode modification date (the thing you get with "ls -c").
- IRL your program is is going to cause you a lot of grief as a "watcher" because it will try to copy/move things that are not complete (it takes more than 2 seconds to rip/download a MP3).
- I'm not convinced your program will do the right thing when it starts if your forgot to empty WATCH_DIR (It think it will copy everything again). IMHO it should copy/move the files to their target directory and keep WATCH_DIR empty. If you keep the source files on the side it means you don't trust your own code (and if you don't, don't expect others to do so). Of course during development and testing you may lose a couple of files but once this is done you should display some self-confidence.
I know these comments may hurt a bit but "c'est le métier qui rentre" (*) as we say in my country. Not that bad for a first shot actually.
(*) it's the job experience that settles in
Bookmarks