Page 1 of 1

Better track year handling

PostPosted: Wed Dec 12, 2012 2:01 am
by baaldemon
So back in a previous version (forget the number but it was back in May of 2010), a lot of us were seeing stack traces for invalid years in our logs. That was because subsonic couldnt handle dates in the id3 tag, even though most taggers now seem to use full dates rather than just a 4 character year. Jump ahead to the current version and the same kind of issue is present, though it doesn't dump stack traces into the logs. What I see is on the sorted albums some have years next to them and others dont even for Albums I know have files that contain tags with the date in them. So looking through the code it appears that this is down to essentially the same issue as before in that the parser can only handle 4 digit years in the tag.

I would like to request that more robust tag handling be added to give the ability for it to properly identify the year off of files which have a date stamp in the tag rather than just the year. As a quick fix for simple plug into the existing JaudioTaggerParser class I added a couple private methods, as seen below, and then modified the call for setting the year from:
metaData.setYear(parseInteger(getTagField(tag, FieldKey.YEAR)));
To:
metaData.setYear(parseInteger(dateToYear(getTagField(tag, FieldKey.YEAR))));

If this were to be put in place I would recommend that on the version released that a util be run on initial install to rerun tags and update the year field for existing entries (I haven't coded that up yet as I just decided to clear out and recreate that part of the database).

Code: Select all
        /**
         * Try and retrieve a valid year from a date tag, since most taggers put full release date
         * Will only try to grab a different date if the length of the string is > 4
         */
        private String dateToYear(String date) {
                String yr = date;
                if (date.length() > 4) {
                        try {
                                if (date.matches("^\\d{4}.*")) {
                                        int i = Integer.parseInt(date.substring(0,4));
                                        if (isValidYear(i)) {
                                                yr = date.substring(0,4);
                                        }
                                }
                                if (date.matches(".*\\d{4}$") && yr.equals(date)){
                                        int i = Integer.parseInt(date.substring(date.length()-4));
                                        if (isValidYear(i)) {
                                                yr = date.substring(date.length()-4);
                                        }
                                }
                        }
                        catch (NumberFormatException nfe) {
//                              Ignore NFEs
//                              nfe.printStackTrace();
                        }
                }
                return yr;
        }

        /**
         * Return true if integer appears to be a valid year
         */
        private boolean isValidYear(Integer i) {
                boolean val = false;
                if (i>1900 && i<2100) {
                        val = true;
                }
                return val;
        }

Re: Better track year handling

PostPosted: Wed Dec 12, 2012 6:47 am
by hakko
Just curious - have you ever encountered dates on form dd-MM-yyyy etc in tags?

Re: Better track year handling

PostPosted: Wed Dec 12, 2012 11:58 am
by baaldemon
Can't say that I have, but I figured I would add in support in case there are some out there. I figure why not try to be a bit more thorough so it can handle a wide range of date formats.

Its just bothered me that since the year showed up that alot of my albums weren't displaying it. Im rather anal about making sure my library is properlyy tagged. I forgot to get stats of a before and after run on my music. But from cursory reviews I went from maybe %30 of albums showing a date to probably 90%. I may setup a test case to get the raw number of tracks tagged by this versus the original code.

Sent from my DROID3 using Tapatalk 2

Re: Better track year handling

PostPosted: Thu Dec 13, 2012 2:51 am
by baaldemon
So I setup a vm to run some tests in. Here are my results:

For the test I used a total 61,515 Files (mix of flac, mp3 with a spattering of audio books thrown in).

Below are the queries I ran after completing a scan of all the files. The column for fix is with my year logic applied where as base refers to the stock 4.7 war file without the year logic.
Code: Select all
select count(*) from media_file where year is not null and type = 'MUSIC';
|======================|
|    fix   |   base    |
|======================|
|  59141   |   24581   |
|======================|


select count(*) from media_file where year is null and type = 'MUSIC';
|======================|
|    fix   |   base    |
|======================|
|   2374   |   36934   |
|======================|


Like I said I am fairly anal about tagging my files, so the results of the dates associated with the albums was killing me.

Re: Better track year handling

PostPosted: Sun Mar 17, 2013 8:11 pm
by DGMayor
I actually came here to bring up the year in the id3 tag being the full date of "2003-02-04", which is the default date style when using Musicbrainz as your source. Unfortunately, Subsonic doesn't show any date when it's in this format.

(I'm also anal about my tagging lol)