Search in sources :

Example 1 with TagsData

use of com.frostwire.gui.library.tags.TagsData in project frostwire by frostwire.

the class LibraryUtils method addPlaylistItem.

private static void addPlaylistItem(Playlist playlist, File file, boolean starred, int index) {
    try {
        LibraryMediator.instance().getLibrarySearch().pushStatus(I18n.tr("Importing") + " " + file.getName());
        TagsData mt = new TagsReader(file).parse();
        PlaylistItem item = playlist.newItem(file.getAbsolutePath(), file.getName(), file.length(), FilenameUtils.getExtension(file.getName()), mt.getTitle(), mt.getDuration(), mt.getArtist(), mt.getAlbum(), // TODO: cover art path
        "", mt.getBitrate(), mt.getComment(), mt.getGenre(), mt.getTrack(), mt.getYear(), starred || playlist.isStarred());
        List<PlaylistItem> items = playlist.getItems();
        if (index != -1 && index < items.size()) {
            // insert item
            items.add(index, item);
            // update all sort indexes from insertion point onwards
            for (int i = index; i < items.size(); i++) {
                PlaylistItem curItem = items.get(i);
                curItem.setSortIndexByTrackNumber(i + 1);
                curItem.save();
            }
        } else {
            items.add(item);
            // fall back index would be it being the last track.
            item.setSortIndexByTrackNumber(items.size());
            item.save(item.isStarred());
        }
        if (isPlaylistSelected(playlist)) {
            // refresh UI
            LibraryMediator.instance().getLibraryPlaylists().refreshSelection();
        }
    } finally {
        LibraryMediator.instance().getLibrarySearch().revertStatus();
    }
}
Also used : TagsData(com.frostwire.gui.library.tags.TagsData) TagsReader(com.frostwire.gui.library.tags.TagsReader) PlaylistItem(com.frostwire.alexandria.PlaylistItem)

Example 2 with TagsData

use of com.frostwire.gui.library.tags.TagsData in project frostwire by frostwire.

the class MediaPlayerComponent method getCommentFromMP3.

private String getCommentFromMP3(MediaSource currentMedia) {
    String comment = "";
    File fileToParse = currentMedia.getFile();
    if (fileToParse != null && fileToParse.isFile() && fileToParse.exists() && fileToParse.getAbsolutePath().toLowerCase().endsWith(".mp3")) {
        TagsReader reader = new TagsReader(fileToParse);
        TagsData tagData = reader.parse();
        if (tagData != null && !StringUtils.isNullOrEmpty(tagData.getComment())) {
            comment = tagData.getComment();
        }
    }
    return comment;
}
Also used : TagsData(com.frostwire.gui.library.tags.TagsData) TagsReader(com.frostwire.gui.library.tags.TagsReader) File(java.io.File)

Example 3 with TagsData

use of com.frostwire.gui.library.tags.TagsData in project frostwire by frostwire.

the class LibraryUtils method asyncParseLyrics.

static void asyncParseLyrics(final TagsReader tagsReader, final OnLyricsParsedUICallback uiCallback) {
    File audioFile = tagsReader.getFile();
    if (audioFile == null || !audioFile.isFile() || !audioFile.canRead() || uiCallback == null) {
        if (uiCallback != null) {
            uiCallback.setLyrics("");
            GUIMediator.safeInvokeLater(uiCallback);
        }
        return;
    }
    executor.submit(new Runnable() {

        @Override
        public void run() {
            TagsData tagsData = tagsReader.parse();
            if (tagsData != null) {
                // can't be null, only ""
                uiCallback.setLyrics(tagsData.getLyrics());
                GUIMediator.safeInvokeLater(uiCallback);
            }
        }
    });
}
Also used : TagsData(com.frostwire.gui.library.tags.TagsData) File(java.io.File)

Example 4 with TagsData

use of com.frostwire.gui.library.tags.TagsData 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)

Example 5 with TagsData

use of com.frostwire.gui.library.tags.TagsData in project frostwire by frostwire.

the class MediaPlayerComponent method getArtistFromMP3.

private String getArtistFromMP3(MediaSource currentMedia) {
    String artist = "";
    if (currentMedia.getFile() != null) {
        File fileToParse = currentMedia.getFile();
        if (fileToParse.isFile() && fileToParse.exists() && fileToParse.getAbsolutePath().toLowerCase().endsWith(".mp3")) {
            TagsReader reader = new TagsReader(fileToParse);
            TagsData tagData = reader.parse();
            if (tagData != null && !StringUtils.isNullOrEmpty(tagData.getComment())) {
                artist = tagData.getArtist();
            }
        }
    } else if (currentMedia.getPlaylistItem() != null && !StringUtils.isNullOrEmpty(currentMedia.getPlaylistItem().getTrackArtist())) {
        artist = currentMedia.getPlaylistItem().getTrackArtist();
    }
    return artist;
}
Also used : 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)5 TagsReader (com.frostwire.gui.library.tags.TagsReader)4 File (java.io.File)4 PlaylistItem (com.frostwire.alexandria.PlaylistItem)1 HistoHashMap (com.frostwire.util.HistoHashMap)1 Entry (java.util.Map.Entry)1