Search in sources :

Example 1 with TagsReader

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

the class LibraryFilesTableMediator method handleSelection.

/**
 * Handles the selection rows in the library window,
 * enabling or disabling buttons and chat menu items depending on
 * the values in the selected rows.
 *
 * @param row the index of the first row that is selected
 */
public void handleSelection(int row) {
    int[] sel = TABLE.getSelectedRows();
    if (sel.length == 0) {
        handleNoSelection();
        return;
    }
    File selectedFile = getFile(sel[0]);
    // always turn on Launch, Delete, Magnet Lookup, Bitzi Lookup
    LAUNCH_ACTION.setEnabled(true);
    LAUNCH_OS_ACTION.setEnabled(true);
    DELETE_ACTION.setEnabled(true);
    if (selectedFile != null && !selectedFile.getName().endsWith(".torrent")) {
        CREATE_TORRENT_ACTION.setEnabled(sel.length == 1);
    }
    if (selectedFile != null) {
        SEND_TO_FRIEND_ACTION.setEnabled(sel.length == 1);
        if (getMediaType().equals(MediaType.getAnyTypeMediaType())) {
            boolean atLeastOneIsPlayable = false;
            for (int i : sel) {
                File f = getFile(i);
                if (MediaPlayer.isPlayableFile(f) || hasExtension(f.getAbsolutePath(), "mp4")) {
                    atLeastOneIsPlayable = true;
                    break;
                }
            }
            SEND_TO_ITUNES_ACTION.setEnabled(atLeastOneIsPlayable);
        } else {
            SEND_TO_ITUNES_ACTION.setEnabled(getMediaType().equals(MediaType.getAudioMediaType()) || hasExtension(selectedFile.getAbsolutePath(), "mp4"));
        }
    }
    if (sel.length == 1 && selectedFile != null && selectedFile.isFile() && selectedFile.getParentFile() != null) {
        OPEN_IN_FOLDER_ACTION.setEnabled(true);
    } else {
        OPEN_IN_FOLDER_ACTION.setEnabled(false);
    }
    if (sel.length == 1) {
        LibraryMediator.instance().getLibraryCoverArtPanel().setTagsReader(new TagsReader(selectedFile)).asyncRetrieveImage();
    }
}
Also used : TagsReader(com.frostwire.gui.library.tags.TagsReader) File(java.io.File)

Example 2 with TagsReader

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

the class LibraryPlaylistsTableMediator method handleSelection.

/**
 * Handles the selection rows in the library window,
 * enabling or disabling buttons and chat menu items depending on
 * the values in the selected rows.
 *
 * @param row the index of the first row that is selected
 */
public void handleSelection(int row) {
    int[] sel = TABLE.getSelectedRows();
    if (sel.length == 0) {
        handleNoSelection();
        return;
    }
    File selectedFile = getFile(sel[0]);
    // always turn on Launch, Delete, Magnet Lookup, Bitzi Lookup
    LAUNCH_ACTION.setEnabled(true);
    LAUNCH_OS_ACTION.setEnabled(true);
    DELETE_ACTION.setEnabled(true);
    SEND_TO_ITUNES_ACTION.setEnabled(true);
    if (!selectedFile.getName().endsWith(".torrent")) {
        CREATE_TORRENT_ACTION.setEnabled(sel.length == 1);
    }
    SEND_TO_FRIEND_ACTION.setEnabled(sel.length == 1);
    if (sel.length == 1 && selectedFile.isFile() && selectedFile.getParentFile() != null) {
        OPEN_IN_FOLDER_ACTION.setEnabled(true);
    } else {
        OPEN_IN_FOLDER_ACTION.setEnabled(false);
    }
    if (sel.length == 1) {
        TagsReader tagsReader = new TagsReader(selectedFile);
        LibraryMediator.instance().getLibraryCoverArtPanel().setTagsReader(tagsReader).asyncRetrieveImage();
        LibraryUtils.asyncParseLyrics(tagsReader, new LibraryUtils.OnLyricsParsedUICallback() {

            @Override
            public void run() {
                updatePlaylistComponentHeader(getLyrics());
                TABLE.requestFocusInWindow();
            }
        });
    }
    TABLE.requestFocusInWindow();
}
Also used : TagsReader(com.frostwire.gui.library.tags.TagsReader) File(java.io.File)

Example 3 with TagsReader

use of com.frostwire.gui.library.tags.TagsReader 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 4 with TagsReader

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

the class MediaPlayer method loadMedia.

/**
 * Loads a MediaSource into the player to play next
 */
private void loadMedia(MediaSource source, boolean isPreview, boolean playNextSong, Playlist currentPlaylist, List<MediaSource> playlistFilesView) {
    try {
        if (source == null) {
            return;
        }
        if (!isPreview && PlayerSettings.USE_OS_DEFAULT_PLAYER.getValue()) {
            GUIMediator.instance().playInOS(source);
            return;
        }
        currentMedia = source;
        this.playNextMedia = playNextSong;
        this.currentPlaylist = currentPlaylist;
        if (playlistFilesView != null) {
            this.playlistFilesView = playlistFilesView.toArray(new MediaSource[playlistFilesView.size()]);
        } else {
            this.playlistFilesView = null;
        }
        if (currentMedia != null) {
            durationInSeconds = -1;
            if (currentMedia.getFile() != null) {
                TagsReader tagsReader = new TagsReader(currentMedia.getFile());
                LibraryMediator.instance().getLibraryCoverArtPanel().setTagsReader(tagsReader).asyncRetrieveImage();
                calculateDurationInSecs(currentMedia.getFile());
                playMedia();
            } else if (currentMedia.getPlaylistItem() != null && currentMedia.getPlaylistItem().getFilePath() != null) {
                TagsReader tagsReader = new TagsReader(new File(currentMedia.getPlaylistItem().getFilePath()));
                LibraryMediator.instance().getLibraryCoverArtPanel().setTagsReader(tagsReader).asyncRetrieveImage();
                playMedia();
                durationInSeconds = (long) currentMedia.getPlaylistItem().getTrackDurationInSecs();
            } else if (currentMedia instanceof StreamMediaSource) {
                LibraryMediator.instance().getLibraryCoverArtPanel().setDefault();
                playMedia(((StreamMediaSource) currentMedia).showPlayerWindow());
            }
            notifyOpened(source);
        }
    } catch (Throwable e) {
        // NPE from bug report
        e.printStackTrace();
    }
}
Also used : TagsReader(com.frostwire.gui.library.tags.TagsReader) RandomAccessFile(java.io.RandomAccessFile) IsoFile(com.frostwire.mp4.IsoFile) File(java.io.File)

Example 5 with TagsReader

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

Aggregations

TagsReader (com.frostwire.gui.library.tags.TagsReader)8 File (java.io.File)7 TagsData (com.frostwire.gui.library.tags.TagsData)4 PlaylistItem (com.frostwire.alexandria.PlaylistItem)2 IsoFile (com.frostwire.mp4.IsoFile)1 HistoHashMap (com.frostwire.util.HistoHashMap)1 RandomAccessFile (java.io.RandomAccessFile)1 Entry (java.util.Map.Entry)1 MigLayout (net.miginfocom.swing.MigLayout)1