use of com.frostwire.util.HistoHashMap in project frostwire by frostwire.
the class LibraryUtils method suggestPlaylistName.
private static String suggestPlaylistName(File[] mediaFiles) {
HistoHashMap<String> artistNames = new HistoHashMap<>();
HistoHashMap<String> artistsAlbums = new HistoHashMap<>();
HistoHashMap<String> albumNames = new HistoHashMap<>();
HistoHashMap<String> genres = new HistoHashMap<>();
for (File mf : mediaFiles) {
if (MediaPlayer.isPlayableFile(mf)) {
TagsData mt = new TagsReader(mf).parse();
artistNames.update(mt.getArtist());
artistsAlbums.update(mt.getArtist() + " - " + mt.getAlbum());
albumNames.update(mt.getAlbum());
genres.update("(" + mt.getGenre() + ")");
}
}
// TODO: refactor this
List<Entry<String, Integer>> histogramArtistNames = artistNames.histogram();
List<Entry<String, Integer>> histogramArtistsAlbums = artistsAlbums.histogram();
List<Entry<String, Integer>> histogramAlbumNames = albumNames.histogram();
List<Entry<String, Integer>> histogramGenres = genres.histogram();
String topArtistName = histogramArtistNames.get(histogramArtistNames.size() - 1).getKey();
int topArtistNameCount = histogramArtistNames.get(histogramArtistNames.size() - 1).getValue();
String topArtistAlbum = histogramArtistsAlbums.get(histogramArtistsAlbums.size() - 1).getKey();
int topArtistAlbumCount = histogramArtistsAlbums.get(histogramArtistsAlbums.size() - 1).getValue();
String topAlbumName = histogramAlbumNames.get(histogramAlbumNames.size() - 1).getKey();
int topAlbumNameCount = histogramAlbumNames.get(histogramAlbumNames.size() - 1).getValue();
String topGenre = histogramGenres.get(histogramGenres.size() - 1).getKey();
String suggestedPlaylistName = topArtistName;
if (topArtistAlbumCount >= topArtistNameCount) {
suggestedPlaylistName = topArtistAlbum;
} else if (topAlbumNameCount >= topArtistNameCount) {
suggestedPlaylistName = topAlbumName;
if (topArtistNameCount > 3) {
suggestedPlaylistName = topArtistName + " - " + suggestedPlaylistName;
}
}
if (!topGenre.equals("()")) {
suggestedPlaylistName = suggestedPlaylistName + " " + topGenre;
}
return suggestedPlaylistName;
}
Aggregations