From 1982b0f969c3c47c2cfde0d7ae728d1d3d9c00bd Mon Sep 17 00:00:00 2001 From: Adrian Ulrich Date: Sat, 21 Jan 2017 12:27:16 +0100 Subject: [PATCH] convert legacy ID3v1 numeric-only genres into strings --- .../medialibrary/MediaMetadataExtractor.java | 183 +++++++++++++++++- 1 file changed, 182 insertions(+), 1 deletion(-) diff --git a/src/ch/blinkenlights/android/medialibrary/MediaMetadataExtractor.java b/src/ch/blinkenlights/android/medialibrary/MediaMetadataExtractor.java index 1ee2206a..9a61d05a 100644 --- a/src/ch/blinkenlights/android/medialibrary/MediaMetadataExtractor.java +++ b/src/ch/blinkenlights/android/medialibrary/MediaMetadataExtractor.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2016 Adrian Ulrich + * Copyright (C) 2016 - 2017 Adrian Ulrich * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -53,6 +53,161 @@ public class MediaMetadataExtractor extends HashMap> { * Regexp matching anything */ private static final Pattern sFilterAny = Pattern.compile("^(.*)$"); + /** + * Genres as defined by androids own MediaScanner.java + */ + private static final String[] ID3_GENRES = { + "Blues", + "Classic Rock", + "Country", + "Dance", + "Disco", + "Funk", + "Grunge", + "Hip-Hop", + "Jazz", + "Metal", + "New Age", + "Oldies", + "Other", + "Pop", + "R&B", + "Rap", + "Reggae", + "Rock", + "Techno", + "Industrial", + "Alternative", + "Ska", + "Death Metal", + "Pranks", + "Soundtrack", + "Euro-Techno", + "Ambient", + "Trip-Hop", + "Vocal", + "Jazz+Funk", + "Fusion", + "Trance", + "Classical", + "Instrumental", + "Acid", + "House", + "Game", + "Sound Clip", + "Gospel", + "Noise", + "AlternRock", + "Bass", + "Soul", + "Punk", + "Space", + "Meditative", + "Instrumental Pop", + "Instrumental Rock", + "Ethnic", + "Gothic", + "Darkwave", + "Techno-Industrial", + "Electronic", + "Pop-Folk", + "Eurodance", + "Dream", + "Southern Rock", + "Comedy", + "Cult", + "Gangsta", + "Top 40", + "Christian Rap", + "Pop/Funk", + "Jungle", + "Native American", + "Cabaret", + "New Wave", + "Psychadelic", + "Rave", + "Showtunes", + "Trailer", + "Lo-Fi", + "Tribal", + "Acid Punk", + "Acid Jazz", + "Polka", + "Retro", + "Musical", + "Rock & Roll", + "Hard Rock", + // The following genres are Winamp extensions + "Folk", + "Folk-Rock", + "National Folk", + "Swing", + "Fast Fusion", + "Bebob", + "Latin", + "Revival", + "Celtic", + "Bluegrass", + "Avantgarde", + "Gothic Rock", + "Progressive Rock", + "Psychedelic Rock", + "Symphonic Rock", + "Slow Rock", + "Big Band", + "Chorus", + "Easy Listening", + "Acoustic", + "Humour", + "Speech", + "Chanson", + "Opera", + "Chamber Music", + "Sonata", + "Symphony", + "Booty Bass", + "Primus", + "Porn Groove", + "Satire", + "Slow Jam", + "Club", + "Tango", + "Samba", + "Folklore", + "Ballad", + "Power Ballad", + "Rhythmic Soul", + "Freestyle", + "Duet", + "Punk Rock", + "Drum Solo", + "A capella", + "Euro-House", + "Dance Hall", + "Goa", + "Drum & Bass", + "Club-House", + "Hardcore", + "Terror", + "Indie", + "Britpop", + "Negerpunk", + "Polsk Punk", + "Beat", + "Christian Gangsta", + "Heavy Metal", + "Black Metal", + "Crossover", + "Contemporary Christian", + "Christian Rock", + "Merengue", + "Salsa", + "Thrash Metal", + "Anime", + "JPop", + "Synthpop", + // 148 goes here, Winamp 5.6 would have 148 -> 191 these ¯\_(ツ)_/¯ + }; /** * Constructor for MediaMetadataExtractor @@ -132,6 +287,7 @@ public class MediaMetadataExtractor extends HashMap> { break; default: populateSelf(mediaTags); + convertNumericGenre(); } mediaTags.release(); @@ -214,4 +370,29 @@ public class MediaMetadataExtractor extends HashMap> { put(key, list); } + /** + * Detects legacy numeric-genre definitions and + * replaces them with one of ID3_GENRES[] + */ + private void convertNumericGenre() { + int genreIdx = -1; + String rawGenre = getFirst(GENRE); + + if (rawGenre == null) + return; // no genre, nothing to do + + try { + genreIdx = Integer.parseInt(rawGenre); + } catch (NumberFormatException exception) { /* genre not set or not a number */ } + + if (genreIdx >= 0 && genreIdx < ID3_GENRES.length) { + ArrayList data = new ArrayList(1); + data.add(ID3_GENRES[genreIdx]); + + remove(GENRE); + addFiltered(sFilterAny, GENRE, data); + } + + } + }