use of com.frostwire.gui.library.tags.TagsReader in project frostwire by frostwire.
the class LibraryPlaylistsTableMediator method updatePlaylistComponentHeader.
private void updatePlaylistComponentHeader(String lyrics) {
JPanel playlistHeaderRow = new JPanel(new MigLayout("insets 10, fillx", "[][grow][]"));
LibraryCoverArtPanel artWorkLabel = new LibraryCoverArtPanel();
if (currentPlaylist == null) {
return;
}
if (!currentPlaylist.isStarred()) {
PlaylistItem playlistItem = currentPlaylist.getItems().get(0);
if (playlistItem != null) {
TagsReader tagsReader = new TagsReader(new File(playlistItem.getFilePath()));
artWorkLabel.setTagsReader(tagsReader).asyncRetrieveImage();
}
}
// left
Dimension artDimensions = new Dimension(210, 210);
artWorkLabel.setPreferredSize(artDimensions);
artWorkLabel.setMinimumSize(artDimensions);
artWorkLabel.setMaximumSize(artDimensions);
playlistHeaderRow.add(artWorkLabel);
// center
JPanel centerContainer = new JPanel(new MigLayout("fillx, wrap 1"));
JLabel playlistSectionTitle = new JLabel(I18n.tr("Playlist"));
// Replace this for a text edit or show a dialog to rename it
JLabel playlistTitle = new JLabel(currentPlaylist.getName());
Font font = new Font("Helvetica", Font.BOLD, 30);
playlistTitle.setFont(font);
JLabel duration = new JLabel(LibraryUtils.getPlaylistDurationInDDHHMMSS(currentPlaylist) + ", " + currentPlaylist.getItems().size() + " " + I18n.tr("tracks"));
centerContainer.add(playlistSectionTitle, "wrap");
centerContainer.add(playlistTitle, "wrap");
centerContainer.add(duration);
playlistHeaderRow.add(centerContainer, "alignx left, aligny top, growx, pushx");
if (lyrics != null && !lyrics.isEmpty()) {
JPanel lyricsPanel = createLyricsPanel(lyrics);
playlistHeaderRow.add(lyricsPanel, "aligny top");
}
mainContainer.removeAll();
mainContainer.add(playlistHeaderRow, "wrap, growx");
mainContainer.add(super.getComponent(), "grow");
mainContainer.invalidate();
mainContainer.repaint();
mainContainer.updateUI();
}
use of com.frostwire.gui.library.tags.TagsReader 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;
}
use of com.frostwire.gui.library.tags.TagsReader 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;
}
Aggregations