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:
parent
93086a5305
commit
1a61c7f8b6
@ -12,7 +12,7 @@
|
|||||||
* GNU General Public License for more details.
|
* GNU General Public License for more details.
|
||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package ch.blinkenlights.android.medialibrary;
|
package ch.blinkenlights.android.medialibrary;
|
||||||
@ -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);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user