Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f826b24a authored by Daniel Martí's avatar Daniel Martí Committed by Steve Kondik
Browse files

Add basic support for VorbisComment DATE tags

Since Android doesn't support DATE tag itself, just use it to extract
the year from the ISO date (if the YEAR tag isn't present) and fill
media database with it.

Require: http://review.cyanogenmod.org/#/c/104193/

Change-Id: I30f86bb05cc8ab158ca538f899a124a4bf8eb9f0
parent e54a9e2d
Loading
Loading
Loading
Loading
+14 −0
Original line number Diff line number Diff line
@@ -61,6 +61,8 @@ import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Locale;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * Internal service helper that no-one should use directly.
@@ -351,6 +353,11 @@ public class MediaScanner

    private final BitmapFactory.Options mBitmapOptions = new BitmapFactory.Options();

    // For basic VorbisComment DATE tag support. It can take two forms, YYYY
    // or YYYY-MM. This pattern is used to extract the year for compatibility
    // with the ID3 YEAR tag.
    private static final Pattern DATE_YEAR_DETECT_PATTERN = Pattern.compile("^(\\d{4})(-\\d{2})?$");

    private static class FileEntry {
        long mRowId;
        String mPath;
@@ -615,6 +622,13 @@ public class MediaScanner
                mGenre = getGenreName(value);
            } else if (name.equalsIgnoreCase("year") || name.startsWith("year;")) {
                mYear = parseSubstring(value, 0, 0);
            } else if (mYear == 0 && name.equalsIgnoreCase("date") || name.startsWith("date;")) {
                // Since Android doesn't support DATE tag itself, just use it to extract
                // the year, if the YEAR tag isn't present.
                Matcher m = DATE_YEAR_DETECT_PATTERN.matcher(value);
                if (m.find()) {
                    mYear = parseSubstring(m.group(1), 0, 0);
                }
            } else if (name.equalsIgnoreCase("tracknumber") || name.startsWith("tracknumber;")) {
                // track number might be of the form "2/12"
                // we just read the number before the slash