relex genre parsing

Allow genre tags with whitespaces (or enclosed in brackets) to be picked up by the genre translator.
This commit is contained in:
Adrian Ulrich 2018-02-18 10:59:57 +01:00
parent 93086a5305
commit 1a61c7f8b6

View File

@ -57,6 +57,10 @@ public class MediaMetadataExtractor extends HashMap<String, ArrayList<String>> {
* Regexp matching anything * Regexp matching anything
*/ */
private static final Pattern sFilterAny = Pattern.compile("^([\\s\\S]*)$"); private static final Pattern sFilterAny = Pattern.compile("^([\\s\\S]*)$");
/**
* Regexp matching possible genres
*/
private static final Pattern sFilterGenre = Pattern.compile("^\\s*\\(?(\\d+)\\)?\\s*$");
/** /**
* Genres as defined by androids own MediaScanner.java * Genres as defined by androids own MediaScanner.java
*/ */
@ -441,18 +445,19 @@ public class MediaMetadataExtractor extends HashMap<String, ArrayList<String>> {
if (rawGenre == null) if (rawGenre == null)
return; // no genre, nothing to do return; // no genre, nothing to do
try { Matcher matcher = sFilterGenre.matcher(rawGenre);
genreIdx = Integer.parseInt(rawGenre); if (matcher.matches()) {
} catch (NumberFormatException exception) { /* genre not set or not a number */ } try {
genreIdx = Integer.parseInt(matcher.group(1));
} catch (NumberFormatException e) {} // ignored
}
if (genreIdx >= 0 && genreIdx < ID3_GENRES.length) { if (genreIdx >= 0 && genreIdx < ID3_GENRES.length) {
ArrayList<String> data = new ArrayList<String>(1); ArrayList<String> data = new ArrayList<String>(1);
data.add(ID3_GENRES[genreIdx]); data.add(ID3_GENRES[genreIdx]);
remove(GENRE); remove(GENRE);
addFiltered(sFilterAny, GENRE, data); addFiltered(sFilterAny, GENRE, data);
} }
} }
} }