Search in sources :

Example 1 with HistoHashMap

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;
}
Also used : Entry(java.util.Map.Entry) HistoHashMap(com.frostwire.util.HistoHashMap) TagsData(com.frostwire.gui.library.tags.TagsData) TagsReader(com.frostwire.gui.library.tags.TagsReader) File(java.io.File)

Aggregations

TagsData (com.frostwire.gui.library.tags.TagsData)1 TagsReader (com.frostwire.gui.library.tags.TagsReader)1 HistoHashMap (com.frostwire.util.HistoHashMap)1 File (java.io.File)1 Entry (java.util.Map.Entry)1