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
*/
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
*/
@ -441,18 +445,19 @@ public class MediaMetadataExtractor extends HashMap<String, ArrayList<String>> {
if (rawGenre == null)
return; // no genre, nothing to do
Matcher matcher = sFilterGenre.matcher(rawGenre);
if (matcher.matches()) {
try {
genreIdx = Integer.parseInt(rawGenre);
} catch (NumberFormatException exception) { /* genre not set or not a number */ }
genreIdx = Integer.parseInt(matcher.group(1));
} catch (NumberFormatException e) {} // ignored
}
if (genreIdx >= 0 && genreIdx < ID3_GENRES.length) {
ArrayList<String> data = new ArrayList<String>(1);
data.add(ID3_GENRES[genreIdx]);
remove(GENRE);
addFiltered(sFilterAny, GENRE, data);
}
}
}