stripping deprecated code
This commit is contained in:
parent
27b26c5eda
commit
729a1e14c2
@ -1,19 +1,15 @@
|
||||
package sarsoo.fmframework.fx.controller;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.text.NumberFormat;
|
||||
import java.util.Locale;
|
||||
|
||||
import javafx.event.ActionEvent;
|
||||
import javafx.fxml.FXML;
|
||||
import sarsoo.fmframework.fm.FmUserNetwork;
|
||||
import sarsoo.fmframework.fx.FmFramework;
|
||||
import sarsoo.fmframework.fx.tab.FMObjListTab;
|
||||
import sarsoo.fmframework.music.Artist;
|
||||
import sarsoo.fmframework.music.Wiki;
|
||||
import sarsoo.fmframework.net.Key;
|
||||
import sarsoo.fmframework.net.Network;
|
||||
import sarsoo.fmframework.util.Getter;
|
||||
import sarsoo.fmframework.util.Maths;
|
||||
import sarsoo.fmframework.util.Reference;
|
||||
import javafx.scene.control.*;
|
||||
@ -98,11 +94,7 @@ public class ArtistPaneController {
|
||||
@FXML
|
||||
protected void handleViewTracks(ActionEvent event) {
|
||||
|
||||
try {
|
||||
FmFramework.getController().addTab(new FMObjListTab(Getter.getArtistTracks(artist.getName(), Reference.getUserName())));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void refresh() {
|
||||
|
@ -30,7 +30,6 @@ import sarsoo.fmframework.fx.tab.ScrobbleChartTab;
|
||||
import sarsoo.fmframework.fx.tab.TrackTab;
|
||||
import sarsoo.fmframework.log.Log;
|
||||
import sarsoo.fmframework.log.Logger;
|
||||
import sarsoo.fmframework.log.console.ConsoleHandler;
|
||||
import sarsoo.fmframework.fx.FmFramework;
|
||||
import sarsoo.fmframework.music.Album;
|
||||
import sarsoo.fmframework.music.Artist;
|
||||
|
@ -1,188 +0,0 @@
|
||||
package sarsoo.fmframework.jframe;
|
||||
|
||||
import java.awt.FlowLayout;
|
||||
import java.awt.Font;
|
||||
import java.awt.GridLayout;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.text.NumberFormat;
|
||||
import java.util.Locale;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.SwingConstants;
|
||||
|
||||
import sarsoo.fmframework.music.Album;
|
||||
import sarsoo.fmframework.net.Network;
|
||||
import sarsoo.fmframework.util.Maths;
|
||||
import sarsoo.fmframework.util.Reference;
|
||||
|
||||
public class AlbumView extends JFrame {
|
||||
JPanel buttons = new JPanel();
|
||||
JPanel buttons2 = new JPanel();
|
||||
JPanel trackListPanel = new JPanel();
|
||||
|
||||
JLabel name = new JLabel();
|
||||
JLabel artist = new JLabel();
|
||||
JLabel listeners = new JLabel();
|
||||
JLabel playCount = new JLabel();
|
||||
JLabel userPlayCount = new JLabel();
|
||||
JLabel timePlayRatio = new JLabel();
|
||||
|
||||
JButton open = new JButton("View Online");
|
||||
JButton viewArtist = new JButton("View Artist");
|
||||
JButton viewWiki = new JButton("View Wiki");
|
||||
JButton musicBrainz = new JButton("Open MusicBrainz");
|
||||
JButton rym = new JButton("Open RYM");
|
||||
|
||||
public AlbumView(Album album) {
|
||||
super(album.getName());
|
||||
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
|
||||
setLayout(new GridLayout(7, 1));
|
||||
setSize(300, 300);
|
||||
setResizable(false);
|
||||
|
||||
buttons.setLayout(new FlowLayout());
|
||||
buttons2.setLayout(new FlowLayout());
|
||||
// System.out.println(album.getName());
|
||||
// if (album.getTrackList() != null)
|
||||
// buttons2.setLayout(new GridLayout(album.getTrackList().size(), 1));
|
||||
|
||||
buttons.add(open);
|
||||
// buttons2.add(viewArtist);
|
||||
|
||||
if (album.getWiki() != null)
|
||||
buttons.add(viewWiki);
|
||||
if (album.getMbid() != null)
|
||||
buttons.add(musicBrainz);
|
||||
buttons.add(rym);
|
||||
|
||||
NumberFormat numberFormat = NumberFormat.getNumberInstance(Locale.US);
|
||||
Font title = new Font("Arial", Font.BOLD, 24);
|
||||
Font sub = new Font("Arial", Font.PLAIN, 20);
|
||||
|
||||
name.setText(album.getName());
|
||||
name.setHorizontalAlignment(SwingConstants.CENTER);
|
||||
name.setFont(title);
|
||||
|
||||
artist.setText(album.getArtist().getName());
|
||||
artist.setHorizontalAlignment(SwingConstants.CENTER);
|
||||
artist.setFont(sub);
|
||||
|
||||
listeners.setText(numberFormat.format(album.getListeners()) + " Listeners");
|
||||
listeners.setHorizontalAlignment(SwingConstants.CENTER);
|
||||
playCount.setText(numberFormat.format(album.getPlayCount()) + " Total Scrobbles");
|
||||
playCount.setHorizontalAlignment(SwingConstants.CENTER);
|
||||
|
||||
userPlayCount.setText(numberFormat.format(album.getUserPlayCount())
|
||||
+ String.format(" Scrobbles (%.2f%%)", Maths.getPercentListening(album, Reference.getUserName())));
|
||||
userPlayCount.setHorizontalAlignment(SwingConstants.CENTER);
|
||||
userPlayCount.setFont(sub);
|
||||
|
||||
double ratio = album.getTimeListenRatio();
|
||||
|
||||
// int ratioRound = (int) Math.round(ratio);
|
||||
// int oneOverRatioRound = (int) Math.round(1/ratio);
|
||||
if (ratio > 1) {
|
||||
timePlayRatio.setText(String.format("listen every %.2f days", ratio));
|
||||
} else if (ratio == 1) {
|
||||
timePlayRatio.setText("listen every day");
|
||||
} else {
|
||||
timePlayRatio.setText(String.format("%.2f times a day", 1/ratio));
|
||||
}
|
||||
timePlayRatio.setHorizontalAlignment(SwingConstants.CENTER);
|
||||
timePlayRatio.setFont(sub);
|
||||
|
||||
artist.addMouseListener(new MouseAdapter() {
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
album.getArtist().view();
|
||||
}
|
||||
});
|
||||
|
||||
open.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent arg0) {
|
||||
Network.openURL(album.getUrl());
|
||||
}
|
||||
});
|
||||
viewArtist.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent arg0) {
|
||||
album.getArtist().view();
|
||||
}
|
||||
});
|
||||
viewWiki.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent arg0) {
|
||||
album.getWiki().view(album.getName());
|
||||
}
|
||||
});
|
||||
musicBrainz.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent arg0) {
|
||||
Network.openURL(album.getMusicBrainzURL());
|
||||
;
|
||||
}
|
||||
});
|
||||
rym.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent arg0) {
|
||||
Network.openURL(album.getRymURL());
|
||||
;
|
||||
}
|
||||
});
|
||||
|
||||
// if (album.getTrackList() != null) {
|
||||
// int counter;
|
||||
// ArrayList<Track> trackList = album.getTrackList();
|
||||
// for (counter = 0; counter < trackList.size(); counter++) {
|
||||
// Track track = trackList.get(counter);
|
||||
// JLabel name = new JLabel(track.getName());
|
||||
//
|
||||
// int playCountString = track.getUserPlayCount();
|
||||
//
|
||||
// JLabel userPlays;
|
||||
// if (playCountString == 0)
|
||||
// userPlays = new JLabel("0");
|
||||
// else
|
||||
// userPlays = new JLabel(Integer.toString(track.getUserPlayCount()));
|
||||
//
|
||||
// JLabel plays = new JLabel(numberFormat.format(track.getPlayCount()));
|
||||
// JButton openExternal = new JButton("Open Online");
|
||||
// openExternal.addActionListener(new ActionListener() {
|
||||
// public void actionPerformed(ActionEvent arg0) {
|
||||
// Network.openURL(track.getUrl());
|
||||
// }
|
||||
// });
|
||||
// JButton openInternal = new JButton("Open " +
|
||||
// track.getClass().getSimpleName());
|
||||
// openInternal.addActionListener(new ActionListener() {
|
||||
// public void actionPerformed(ActionEvent arg0) {
|
||||
// track.view();
|
||||
// }
|
||||
// });
|
||||
// JPanel panel = new JPanel();
|
||||
// panel.setLayout(new GridLayout(1, 5));
|
||||
// panel.add(name);
|
||||
// panel.add(userPlays);
|
||||
// panel.add(plays);
|
||||
// panel.add(openInternal);
|
||||
// panel.add(openExternal);
|
||||
//
|
||||
// trackListPanel.add(panel);
|
||||
// }
|
||||
// }
|
||||
|
||||
add(name);
|
||||
add(artist);
|
||||
add(userPlayCount);
|
||||
add(timePlayRatio);
|
||||
add(listeners);
|
||||
add(playCount);
|
||||
|
||||
// add(trackListPanel);
|
||||
add(buttons);
|
||||
// add(buttons2);
|
||||
pack();
|
||||
}
|
||||
}
|
@ -1,21 +0,0 @@
|
||||
package sarsoo.fmframework.jframe;
|
||||
|
||||
import sarsoo.fmframework.util.Reference;
|
||||
|
||||
public class Driver {
|
||||
|
||||
public static void main(String[] args) {
|
||||
// String username = JOptionPane.showInputDialog(null, "Enter User-Name");
|
||||
// System.out.println(username);
|
||||
// if (username != null) {
|
||||
Reference.setUserName("sarsoo");
|
||||
// Reference.setUserName(username);
|
||||
|
||||
// System.out.println(Getter.getScrobbles(Reference.getUserName()));
|
||||
|
||||
MainMenu main = new MainMenu();
|
||||
main.setVisible(true);
|
||||
// }
|
||||
}
|
||||
|
||||
}
|
@ -1,188 +0,0 @@
|
||||
package sarsoo.fmframework.jframe;
|
||||
|
||||
import java.awt.Font;
|
||||
import java.awt.GridLayout;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.text.NumberFormat;
|
||||
import java.util.Collections;
|
||||
import java.util.Locale;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JMenu;
|
||||
import javax.swing.JMenuBar;
|
||||
import javax.swing.JMenuItem;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.SwingConstants;
|
||||
|
||||
import sarsoo.fmframework.music.Album;
|
||||
import sarsoo.fmframework.music.FMObj;
|
||||
import sarsoo.fmframework.net.Network;
|
||||
import sarsoo.fmframework.util.FMObjList;
|
||||
import sarsoo.fmframework.util.Maths;
|
||||
import sarsoo.fmframework.util.Reference;
|
||||
|
||||
public class FMObjListView extends JFrame {
|
||||
|
||||
public FMObjListView(FMObjList objects, String title) {
|
||||
super(title);
|
||||
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
|
||||
// setLayout(new GridLayout(objects.size() + 2, 0));
|
||||
// setResizable(false);
|
||||
// createMenu();
|
||||
|
||||
int limit = 20;
|
||||
|
||||
if(objects.size() > limit) {
|
||||
setSize(600, 800);
|
||||
}
|
||||
|
||||
JPanel container = new JPanel();
|
||||
container.setLayout(new GridLayout(objects.size() + 2, 0));
|
||||
|
||||
NumberFormat numberFormat = NumberFormat.getNumberInstance(Locale.US);
|
||||
Font font = new Font("Arial", Font.PLAIN, 20);
|
||||
Font header = new Font("Arial", Font.BOLD, 16);
|
||||
|
||||
JPanel headerLabels = new JPanel();
|
||||
// headerLabels.setFont(header);
|
||||
headerLabels.setLayout(new GridLayout(1, 4));
|
||||
|
||||
|
||||
JLabel headerName = new JLabel("name");
|
||||
headerName.setHorizontalAlignment(SwingConstants.CENTER);
|
||||
headerName.setFont(header);
|
||||
|
||||
JLabel headerUser = new JLabel("user");
|
||||
headerUser.setHorizontalAlignment(SwingConstants.CENTER);
|
||||
headerUser.setFont(header);
|
||||
|
||||
JLabel headerTotal = new JLabel("total");
|
||||
headerTotal.setHorizontalAlignment(SwingConstants.CENTER);
|
||||
headerTotal.setFont(header);
|
||||
|
||||
headerLabels.add(headerName);
|
||||
headerLabels.add(headerUser);
|
||||
headerLabels.add(headerTotal);
|
||||
headerLabels.add(new JLabel(""));
|
||||
// headerLabels.add(new JLabel(""));
|
||||
|
||||
container.add(headerLabels);
|
||||
|
||||
Collections.sort(objects);
|
||||
Collections.reverse(objects);
|
||||
|
||||
int counter;
|
||||
for (counter = 0; counter < objects.size(); counter++) {
|
||||
FMObj fmObj = objects.get(counter);
|
||||
JLabel artistName = new JLabel(fmObj.getName());
|
||||
artistName.setHorizontalAlignment(SwingConstants.CENTER);
|
||||
artistName.addMouseListener(new MouseAdapter() {
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
fmObj.view();
|
||||
}
|
||||
});
|
||||
|
||||
int playCountString = fmObj.getUserPlayCount();
|
||||
|
||||
JLabel userPlays;
|
||||
if (playCountString == 0)
|
||||
userPlays = new JLabel("0");
|
||||
else
|
||||
userPlays = new JLabel(Integer.toString(fmObj.getUserPlayCount()));
|
||||
userPlays.setHorizontalAlignment(SwingConstants.CENTER);
|
||||
|
||||
JLabel plays = new JLabel(numberFormat.format(fmObj.getPlayCount()));
|
||||
plays.setHorizontalAlignment(SwingConstants.CENTER);
|
||||
|
||||
JButton openExternal = new JButton("Open Online");
|
||||
openExternal.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent arg0) {
|
||||
Network.openURL(fmObj.getUrl());
|
||||
}
|
||||
});
|
||||
// JButton openInternal = new JButton("Open " + fmObj.getClass().getSimpleName());
|
||||
// openInternal.addActionListener(new ActionListener() {
|
||||
// public void actionPerformed(ActionEvent arg0) {
|
||||
// fmObj.view();
|
||||
// }
|
||||
// });
|
||||
JPanel panel = new JPanel();
|
||||
panel.setLayout(new GridLayout(1, 4));
|
||||
panel.add(artistName);
|
||||
panel.add(userPlays);
|
||||
panel.add(plays);
|
||||
// panel.add(openInternal);
|
||||
panel.add(openExternal);
|
||||
|
||||
container.add(panel);
|
||||
}
|
||||
|
||||
JPanel info = new JPanel();
|
||||
info.setLayout(new GridLayout(1, 2));
|
||||
|
||||
JLabel totalScrobbles = new JLabel(numberFormat.format(objects.getTotalUserScrobbles()) + " total plays");
|
||||
totalScrobbles.setHorizontalAlignment(SwingConstants.CENTER);
|
||||
totalScrobbles.setFont(font);
|
||||
info.add(totalScrobbles);
|
||||
|
||||
double percent = Maths.getPercentListening(objects, Reference.getUserName());
|
||||
// if (percent > 1) {
|
||||
JLabel percentLabel = new JLabel();
|
||||
percentLabel.setHorizontalAlignment(SwingConstants.CENTER);
|
||||
percentLabel.setText(String.format("%.2f%%", percent));
|
||||
percentLabel.setFont(font);
|
||||
info.add(percentLabel);
|
||||
|
||||
// }
|
||||
|
||||
container.add(info);
|
||||
|
||||
JScrollPane scroll = new JScrollPane(container);
|
||||
add(scroll);
|
||||
|
||||
if(objects.size() <= limit) {
|
||||
pack();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void createMenu() {
|
||||
JMenuBar menuBar = new JMenuBar();
|
||||
|
||||
JMenu editMenu = new JMenu("Edit");
|
||||
|
||||
JMenu addMenu = new JMenu("Add");
|
||||
|
||||
// create menu items
|
||||
JMenuItem addAlbum = new JMenuItem("Album");
|
||||
addAlbum.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent arg0) {
|
||||
Album album = sarsoo.fmframework.jframe.Getter.getAlbum();
|
||||
if (album != null) {
|
||||
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
JMenuItem addTrack = new JMenuItem("Track");
|
||||
|
||||
JMenuItem addArtist = new JMenuItem("Artist");
|
||||
|
||||
addMenu.add(addAlbum);
|
||||
addMenu.add(addTrack);
|
||||
addMenu.add(addArtist);
|
||||
|
||||
editMenu.add(addMenu);
|
||||
menuBar.add(editMenu);
|
||||
|
||||
setJMenuBar(menuBar);
|
||||
}
|
||||
}
|
@ -1,108 +0,0 @@
|
||||
package sarsoo.fmframework.jframe;
|
||||
|
||||
import java.awt.FlowLayout;
|
||||
import java.awt.Font;
|
||||
import java.awt.GridLayout;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.text.NumberFormat;
|
||||
import java.util.Locale;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.SwingConstants;
|
||||
|
||||
import sarsoo.fmframework.music.FMObj;
|
||||
import sarsoo.fmframework.net.Network;
|
||||
import sarsoo.fmframework.util.Maths;
|
||||
import sarsoo.fmframework.util.Reference;
|
||||
|
||||
public class FMObjView extends JFrame {
|
||||
JPanel buttons = new JPanel();
|
||||
|
||||
JLabel name = new JLabel();
|
||||
JLabel listeners = new JLabel();
|
||||
JLabel playCount = new JLabel();
|
||||
JLabel userPlayCount = new JLabel();
|
||||
JLabel timePlayRatio = new JLabel();
|
||||
|
||||
JButton viewWiki = new JButton("View Wiki");
|
||||
JButton open = new JButton("View Online");
|
||||
JButton musicBrainz = new JButton("Open MusicBrainz");
|
||||
|
||||
public FMObjView(FMObj obj) {
|
||||
super(obj.toString());
|
||||
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
|
||||
setLayout(new GridLayout(6, 1));
|
||||
setSize(300, 300);
|
||||
// setResizable(false);
|
||||
|
||||
buttons.setLayout(new FlowLayout());
|
||||
|
||||
buttons.add(open);
|
||||
if (obj.getWiki() != null)
|
||||
buttons.add(viewWiki);
|
||||
if (obj.getMbid() != null)
|
||||
buttons.add(musicBrainz);
|
||||
|
||||
NumberFormat numberFormat = NumberFormat.getNumberInstance(Locale.US);
|
||||
Font title = new Font("Arial", Font.BOLD, 24);
|
||||
Font sub = new Font("Arial", Font.PLAIN, 20);
|
||||
|
||||
name.setText(obj.getName());
|
||||
name.setHorizontalAlignment(SwingConstants.CENTER);
|
||||
name.setFont(title);
|
||||
|
||||
listeners.setText(numberFormat.format(obj.getListeners()) + " Listeners");
|
||||
listeners.setHorizontalAlignment(SwingConstants.CENTER);
|
||||
playCount.setText(numberFormat.format(obj.getPlayCount()) + " Total Scrobbles");
|
||||
playCount.setHorizontalAlignment(SwingConstants.CENTER);
|
||||
userPlayCount.setText(numberFormat.format(obj.getUserPlayCount())
|
||||
+ String.format(" Scrobbles (%.2f%%)", Maths.getPercentListening(obj, Reference.getUserName())));
|
||||
userPlayCount.setHorizontalAlignment(SwingConstants.CENTER);
|
||||
userPlayCount.setFont(sub);
|
||||
|
||||
double ratio = obj.getTimeListenRatio();
|
||||
|
||||
// int ratioRound = (int) Math.round(ratio);
|
||||
// int oneOverRatioRound = (int) Math.round(1/ratio);
|
||||
if (ratio > 1) {
|
||||
timePlayRatio.setText(String.format("listen every %.2f days", ratio));
|
||||
} else if (ratio == 1) {
|
||||
timePlayRatio.setText("listen every day");
|
||||
} else {
|
||||
timePlayRatio.setText(String.format("%.2f times a day", 1 / ratio));
|
||||
}
|
||||
timePlayRatio.setHorizontalAlignment(SwingConstants.CENTER);
|
||||
timePlayRatio.setFont(sub);
|
||||
|
||||
viewWiki.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent arg0) {
|
||||
obj.getWiki().view(obj.getName());
|
||||
}
|
||||
});
|
||||
open.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent arg0) {
|
||||
Network.openURL(obj.getUrl());
|
||||
}
|
||||
});
|
||||
musicBrainz.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent arg0) {
|
||||
Network.openURL(obj.getMusicBrainzURL());
|
||||
;
|
||||
}
|
||||
});
|
||||
add(name);
|
||||
add(userPlayCount);
|
||||
add(timePlayRatio);
|
||||
add(listeners);
|
||||
add(playCount);
|
||||
// add(info);
|
||||
add(buttons);
|
||||
|
||||
pack();
|
||||
}
|
||||
|
||||
}
|
@ -2,47 +2,53 @@ package sarsoo.fmframework.jframe;
|
||||
|
||||
import javax.swing.JOptionPane;
|
||||
|
||||
import sarsoo.fmframework.fm.FmUserNetwork;
|
||||
import sarsoo.fmframework.music.Album;
|
||||
import sarsoo.fmframework.music.Artist;
|
||||
import sarsoo.fmframework.music.Track;
|
||||
import sarsoo.fmframework.net.Key;
|
||||
import sarsoo.fmframework.util.Reference;
|
||||
|
||||
public class Getter {
|
||||
|
||||
public static Album getAlbum() {
|
||||
FmUserNetwork net = new FmUserNetwork(Key.getKey(), Reference.getUserName());
|
||||
String albumName = JOptionPane.showInputDialog(null, "Enter Album Name");
|
||||
if (albumName != null) {
|
||||
String artistName = JOptionPane.showInputDialog(null, "Enter Artist Name");
|
||||
if (artistName != null) {
|
||||
return Album.getAlbum(albumName, artistName, Reference.getUserName());
|
||||
return net.getAlbum(albumName, artistName);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Artist getArtist() {
|
||||
FmUserNetwork net = new FmUserNetwork(Key.getKey(), Reference.getUserName());
|
||||
String artistName = JOptionPane.showInputDialog(null, "Enter Artist Name");
|
||||
if (artistName != null) {
|
||||
return Artist.getArtist(artistName, Reference.getUserName());
|
||||
return net.getArtist(artistName);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Track getTrack() {
|
||||
FmUserNetwork net = new FmUserNetwork(Key.getKey(), Reference.getUserName());
|
||||
String trackName = JOptionPane.showInputDialog(null, "Enter Track Name");
|
||||
if (trackName != null) {
|
||||
String artistName = JOptionPane.showInputDialog(null, "Enter Artist Name");
|
||||
if (artistName != null) {
|
||||
return Track.getTrack(artistName, trackName, Reference.getUserName());
|
||||
return net.getTrack(trackName, artistName);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Track getTrack(Album album) {
|
||||
FmUserNetwork net = new FmUserNetwork(Key.getKey(), Reference.getUserName());
|
||||
String trackName = JOptionPane.showInputDialog(null, "Enter Track Name");
|
||||
if (trackName != null) {
|
||||
Track track = Track.getTrack(album.getArtist().getName(), trackName, Reference.getUserName());
|
||||
Track track = net.getTrack(trackName, album.getArtist().getName());
|
||||
track.setAlbum(album);
|
||||
return track;
|
||||
}
|
||||
|
@ -1,91 +0,0 @@
|
||||
package sarsoo.fmframework.jframe;
|
||||
|
||||
import java.awt.GridLayout;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JOptionPane;
|
||||
|
||||
import sarsoo.fmframework.music.Album;
|
||||
import sarsoo.fmframework.music.Artist;
|
||||
import sarsoo.fmframework.music.Track;
|
||||
import sarsoo.fmframework.net.Network;
|
||||
import sarsoo.fmframework.util.Getter;
|
||||
import sarsoo.fmframework.util.Reference;
|
||||
|
||||
public class MainMenu extends JFrame {
|
||||
|
||||
JButton getAlbum = new JButton("Get Album");
|
||||
JButton getArtist = new JButton("Get Artist");
|
||||
JButton viewLastTrack = new JButton("View Last Track");
|
||||
JButton viewList = new JButton("View List");
|
||||
JButton viewTag = new JButton("View Tags");
|
||||
JButton today = new JButton();
|
||||
|
||||
public MainMenu() {
|
||||
super("fmframework - " + Reference.getUserName());
|
||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
setLayout(new GridLayout(3, 2));
|
||||
setSize(300, 300);
|
||||
setResizable(false);
|
||||
|
||||
getAlbum.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent arg0) {
|
||||
Album album = sarsoo.fmframework.jframe.Getter.getAlbum();
|
||||
if (album != null) {
|
||||
album.view();
|
||||
} else {
|
||||
JOptionPane.showMessageDialog(null, "No Album Found", "Album Error", JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
}
|
||||
});
|
||||
getArtist.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent arg0) {
|
||||
Artist artist = sarsoo.fmframework.jframe.Getter.getArtist();
|
||||
if (artist != null) {
|
||||
artist.view();
|
||||
} else {
|
||||
JOptionPane.showMessageDialog(null, "No Artist Found", "Artist Error", JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
}
|
||||
});
|
||||
viewLastTrack.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent arg0) {
|
||||
Track track = Getter.getLastTrack();
|
||||
if (track != null) {
|
||||
track.view();
|
||||
} else {
|
||||
JOptionPane.showMessageDialog(null, "No Track Found", "Track Error", JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
}
|
||||
});
|
||||
viewList.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent arg0) {
|
||||
RefListsView view = new RefListsView();
|
||||
view.setVisible(true);
|
||||
}
|
||||
});
|
||||
viewTag.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent arg0) {
|
||||
TagMenuView view = new TagMenuView();
|
||||
view.setVisible(true);
|
||||
}
|
||||
});
|
||||
today.setText("Today: " + Integer.toString(Getter.getScrobblesToday(Reference.getUserName())));
|
||||
today.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent arg0) {
|
||||
Network.openURL(String.format("https://www.last.fm/user/%s/library?date_preset=LAST_30_DAYS", Reference.getUserName()));
|
||||
today.setText("Today: " + Integer.toString(Getter.getScrobblesToday(Reference.getUserName())));
|
||||
}
|
||||
});
|
||||
add(viewLastTrack);
|
||||
add(today);
|
||||
add(viewTag);
|
||||
add(viewList);
|
||||
add(getArtist);
|
||||
add(getAlbum);
|
||||
|
||||
}
|
||||
}
|
@ -1,105 +0,0 @@
|
||||
package sarsoo.fmframework.jframe;
|
||||
|
||||
import java.awt.GridLayout;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JFrame;
|
||||
import sarsoo.fmframework.util.Reference;
|
||||
|
||||
public class RefListsView extends JFrame {
|
||||
|
||||
public RefListsView() {
|
||||
super("fmframework");
|
||||
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
|
||||
setLayout(new GridLayout(3, 2));
|
||||
setSize(300, 300);
|
||||
setResizable(false);
|
||||
|
||||
|
||||
// Reference.initGroupsList();
|
||||
// ArrayList<FMObjList> groups = Reference.getGroups();
|
||||
// int counter;
|
||||
// for (counter = 0; counter < groups.size(); counter++) {
|
||||
// FMObjList group = groups.get(counter);
|
||||
// JButton view = new JButton("View " + group.getGroupName());
|
||||
// view.addActionListener(new ActionListener() {
|
||||
// public void actionPerformed(ActionEvent arg0) {
|
||||
// group.view();
|
||||
// }
|
||||
// });
|
||||
// add(view);
|
||||
// }
|
||||
|
||||
// JButton viewTDE = new JButton("TDE");
|
||||
// viewTDE.addActionListener(new ActionListener() {
|
||||
// public void actionPerformed(ActionEvent arg0) {
|
||||
// Reference.getTDE().view();
|
||||
// }
|
||||
// });
|
||||
// add(viewTDE);
|
||||
|
||||
JButton viewBPHQ = new JButton("BPHQ");
|
||||
viewBPHQ.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent arg0) {
|
||||
Reference.getBB().view();
|
||||
}
|
||||
});
|
||||
add(viewBPHQ);
|
||||
|
||||
JButton viewDre = new JButton("Dre");
|
||||
viewDre.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent arg0) {
|
||||
Reference.getDre().view();
|
||||
}
|
||||
});
|
||||
add(viewDre);
|
||||
JButton viewWu = new JButton("Wu");
|
||||
viewWu.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent arg0) {
|
||||
Reference.getWu().view();
|
||||
}
|
||||
});
|
||||
add(viewWu);
|
||||
JButton viewHopeless = new JButton("Hopeless");
|
||||
viewHopeless.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent arg0) {
|
||||
Reference.getHopeless().view();
|
||||
}
|
||||
});
|
||||
add(viewHopeless);
|
||||
JButton viewSaturation = new JButton("Saturation");
|
||||
viewSaturation.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent arg0) {
|
||||
Reference.getSaturation().view();
|
||||
}
|
||||
});
|
||||
add(viewSaturation);
|
||||
|
||||
JButton viewEmoTrio = new JButton("Emo Trio");
|
||||
viewEmoTrio.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent arg0) {
|
||||
Reference.getEmoTrio().view();
|
||||
}
|
||||
});
|
||||
// add(viewEmoTrio);
|
||||
//
|
||||
// JButton viewRockTag = new JButton("Rock Tag");
|
||||
// viewRockTag.addActionListener(new ActionListener() {
|
||||
// public void actionPerformed(ActionEvent arg0) {
|
||||
// FMObjList list = Getter.getUserTag(Reference.getUserName(), "rock");
|
||||
// list.view();
|
||||
// }
|
||||
// });
|
||||
// add(viewRockTag);
|
||||
//
|
||||
// JButton viewRapTag = new JButton("Rap Tag");
|
||||
// viewRapTag.addActionListener(new ActionListener() {
|
||||
// public void actionPerformed(ActionEvent arg0) {
|
||||
// FMObjList list = Getter.getUserTag(Reference.getUserName(), "rap");
|
||||
// list.view();
|
||||
// }
|
||||
// });
|
||||
// add(viewRapTag);
|
||||
}
|
||||
}
|
@ -1,43 +0,0 @@
|
||||
package sarsoo.fmframework.jframe;
|
||||
|
||||
import java.awt.GridLayout;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JFrame;
|
||||
|
||||
import sarsoo.fmframework.music.Tag;
|
||||
import sarsoo.fmframework.util.FMObjList;
|
||||
import sarsoo.fmframework.util.Getter;
|
||||
import sarsoo.fmframework.util.Reference;
|
||||
|
||||
public class TagMenuView extends JFrame {
|
||||
|
||||
public TagMenuView() {
|
||||
super("View Tags");
|
||||
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
|
||||
|
||||
ArrayList<Tag> tags = Getter.getUserTags(Reference.getUserName());
|
||||
|
||||
setLayout(new GridLayout(4, 4));
|
||||
setSize(700, 700);
|
||||
setResizable(false);
|
||||
|
||||
int counter;
|
||||
for(counter = 0; counter < tags.size(); counter++) {
|
||||
Tag tag = tags.get(counter);
|
||||
|
||||
JButton view = new JButton(tag.getName());
|
||||
view.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent arg0) {
|
||||
|
||||
FMObjList list = Getter.getUserTag(Reference.getUserName(), tag.getName());
|
||||
list.view();
|
||||
}
|
||||
});
|
||||
add(view);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,192 +0,0 @@
|
||||
package sarsoo.fmframework.jframe;
|
||||
|
||||
import java.awt.FlowLayout;
|
||||
import java.awt.Font;
|
||||
import java.awt.GridLayout;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.text.NumberFormat;
|
||||
import java.util.Locale;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.SwingConstants;
|
||||
|
||||
import sarsoo.fmframework.music.Track;
|
||||
import sarsoo.fmframework.net.Network;
|
||||
import sarsoo.fmframework.util.Maths;
|
||||
import sarsoo.fmframework.util.Reference;
|
||||
|
||||
public class TrackView extends JFrame {
|
||||
// JPanel info = new JPanel();
|
||||
// JPanel nameInfo = new JPanel();
|
||||
// JPanel scrobbleInfo = new JPanel();
|
||||
JPanel buttons = new JPanel();
|
||||
JPanel buttons2 = new JPanel();
|
||||
|
||||
JLabel name = new JLabel();
|
||||
JLabel album = new JLabel();
|
||||
JLabel artist = new JLabel();
|
||||
JLabel listeners = new JLabel();
|
||||
JLabel playCount = new JLabel();
|
||||
JLabel userPlayCount = new JLabel();
|
||||
JLabel timePlayRatio = new JLabel();
|
||||
|
||||
JButton open = new JButton("View Online");
|
||||
JButton viewArtist = new JButton("View Artist");
|
||||
JButton viewAlbum = new JButton("View Album");
|
||||
JButton viewWiki = new JButton("View Wiki");
|
||||
JButton musicBrainz = new JButton("Open MusicBrainz");
|
||||
JButton genius = new JButton("Open Genius");
|
||||
|
||||
public TrackView(Track track) {
|
||||
super(track.getName());
|
||||
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
|
||||
if (track.getAlbum() != null) {
|
||||
setLayout(new GridLayout(8, 1));
|
||||
} else {
|
||||
setLayout(new GridLayout(7, 1));
|
||||
}
|
||||
// setSize(300, 300);
|
||||
setResizable(false);
|
||||
|
||||
// info.setLayout(new GridLayout(6,1));
|
||||
// nameInfo.setLayout(new GridLayout(3,1));
|
||||
// scrobbleInfo.setLayout(new GridLayout(3,1));
|
||||
buttons.setLayout(new FlowLayout());
|
||||
buttons2.setLayout(new FlowLayout());
|
||||
|
||||
buttons.add(open);
|
||||
if (track.getMbid() != null)
|
||||
buttons.add(musicBrainz);
|
||||
|
||||
buttons2.add(viewArtist);
|
||||
if (track.getAlbum() != null)
|
||||
buttons2.add(viewAlbum);
|
||||
if (track.getWiki() != null)
|
||||
buttons2.add(viewWiki);
|
||||
// if (track.getArtist() != null)
|
||||
buttons.add(genius);
|
||||
|
||||
NumberFormat numberFormat = NumberFormat.getNumberInstance(Locale.US);
|
||||
Font title = new Font("Arial", Font.BOLD, 24);
|
||||
Font sub = new Font("Arial", Font.PLAIN, 20);
|
||||
Font subSub = new Font("Arial", Font.PLAIN, 16);
|
||||
|
||||
name.setText(track.getName());
|
||||
name.setHorizontalAlignment(SwingConstants.CENTER);
|
||||
name.setFont(title);
|
||||
|
||||
if (track.getAlbum() != null) {
|
||||
album.setText(track.getAlbum().getName());
|
||||
album.addMouseListener(new MouseAdapter() {
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
track.getAlbum().view();
|
||||
}
|
||||
});
|
||||
}
|
||||
album.setHorizontalAlignment(SwingConstants.CENTER);
|
||||
album.setFont(sub);
|
||||
|
||||
artist.setText(track.getArtist().getName());
|
||||
artist.setHorizontalAlignment(SwingConstants.CENTER);
|
||||
artist.setFont(sub);
|
||||
|
||||
double ratio = track.getTimeListenRatio();
|
||||
|
||||
// int ratioRound = (int) Math.round(ratio);
|
||||
// int oneOverRatioRound = (int) Math.round(1/ratio);
|
||||
if (ratio > 1) {
|
||||
timePlayRatio.setText(String.format("listen every %.2f days", ratio));
|
||||
} else if (ratio == 1) {
|
||||
timePlayRatio.setText("listen every day");
|
||||
} else {
|
||||
timePlayRatio.setText(String.format("%.2f times a day", 1 / ratio));
|
||||
}
|
||||
timePlayRatio.setHorizontalAlignment(SwingConstants.CENTER);
|
||||
timePlayRatio.setFont(subSub);
|
||||
|
||||
listeners.setText(numberFormat.format(track.getListeners()) + " Listeners");
|
||||
listeners.setHorizontalAlignment(SwingConstants.CENTER);
|
||||
playCount.setText(numberFormat.format(track.getPlayCount()) + " Total Scrobbles");
|
||||
playCount.setHorizontalAlignment(SwingConstants.CENTER);
|
||||
userPlayCount.setText(numberFormat.format(track.getUserPlayCount())
|
||||
+ String.format(" Scrobbles (%.3f%%)", Maths.getPercentListening(track, Reference.getUserName())));
|
||||
userPlayCount.setHorizontalAlignment(SwingConstants.CENTER);
|
||||
userPlayCount.setFont(sub);
|
||||
|
||||
open.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent arg0) {
|
||||
Network.openURL(track.getUrl());
|
||||
}
|
||||
});
|
||||
viewWiki.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent arg0) {
|
||||
track.getWiki().view(track.getName());
|
||||
}
|
||||
});
|
||||
|
||||
if (track.getUserPlayCount() > 0) {
|
||||
userPlayCount.addMouseListener(new MouseAdapter() {
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
String namePlus = track.getName().replaceAll(" ", "+");
|
||||
String artistPlus = track.getArtist().getName().replaceAll(" ", "+");
|
||||
String url = String.format("https://www.last.fm/user/%s/library/music/%s/_/%s",
|
||||
Reference.getUserName(), artistPlus, namePlus);
|
||||
Network.openURL(url);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
artist.addMouseListener(new MouseAdapter() {
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
track.getArtist().view();
|
||||
}
|
||||
});
|
||||
|
||||
viewArtist.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent arg0) {
|
||||
track.getArtist().view();
|
||||
}
|
||||
});
|
||||
musicBrainz.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent arg0) {
|
||||
Network.openURL(track.getMusicBrainzURL());
|
||||
}
|
||||
});
|
||||
viewAlbum.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent arg0) {
|
||||
track.getAlbum().view();
|
||||
}
|
||||
});
|
||||
genius.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent arg0) {
|
||||
Network.openURL(track.getLyricsURL());
|
||||
}
|
||||
});
|
||||
|
||||
add(name);
|
||||
if (track.getAlbum() != null)
|
||||
add(album);
|
||||
add(artist);
|
||||
add(userPlayCount);
|
||||
add(timePlayRatio);
|
||||
add(listeners);
|
||||
add(playCount);
|
||||
|
||||
// info.add(nameInfo);
|
||||
// info.add(scrobbleInfo);
|
||||
|
||||
// add(info);
|
||||
add(buttons);
|
||||
// add(buttons2);
|
||||
pack();
|
||||
}
|
||||
}
|
@ -1,29 +0,0 @@
|
||||
package sarsoo.fmframework.jframe;
|
||||
|
||||
import java.awt.GridLayout;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.JTextArea;
|
||||
|
||||
import sarsoo.fmframework.music.Wiki;
|
||||
|
||||
public class WikiView extends JFrame {
|
||||
JTextArea contentLabel = new JTextArea();
|
||||
|
||||
public WikiView(Wiki wiki, String name) {
|
||||
super(name);
|
||||
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
|
||||
setLayout(new GridLayout(1,1));
|
||||
setSize(500, 700);
|
||||
contentLabel.setText(wiki.getContent()+ "\n\n" + wiki.getDate());
|
||||
|
||||
contentLabel.setLineWrap(true);
|
||||
// contentLabel.setText("<html>" + wiki.getContent() + "<br><br>" + wiki.getDate() + "</html>");
|
||||
|
||||
JScrollPane scroll = new JScrollPane(contentLabel);
|
||||
add(scroll);
|
||||
|
||||
// add(contentLabel);
|
||||
// pack();
|
||||
}
|
||||
}
|
@ -3,14 +3,6 @@ package sarsoo.fmframework.music;
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.w3c.dom.Document;
|
||||
|
||||
import sarsoo.fmframework.jframe.AlbumView;
|
||||
import sarsoo.fmframework.net.Network;
|
||||
import sarsoo.fmframework.net.URLBuilder;
|
||||
import sarsoo.fmframework.parser.Parser;
|
||||
import sarsoo.fmframework.util.Reference;
|
||||
|
||||
public class Album extends FMObj implements Serializable{
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
@ -18,19 +10,6 @@ public class Album extends FMObj implements Serializable{
|
||||
protected ArrayList<Tag> tagList;
|
||||
protected ArrayList<Track> trackList;
|
||||
|
||||
@Deprecated
|
||||
public Album(String name, String artist) {
|
||||
super(name, null, null, 0, 0, 0, null);
|
||||
this.artist = Artist.getArtist(artist, Reference.getUserName());
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public Album(String name, String url, String mbid, Artist artist, int listeners, int playCount, int userPlayCount,
|
||||
Wiki wiki) {
|
||||
super(name, url, mbid, listeners, playCount, userPlayCount, wiki);
|
||||
this.artist = artist;
|
||||
}
|
||||
|
||||
private Album(AlbumBuilder builder) {
|
||||
this.name = builder.name;
|
||||
this.artist = builder.artist;
|
||||
@ -55,29 +34,6 @@ public class Album extends FMObj implements Serializable{
|
||||
return artist;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static Album getAlbum(String name, String artist, String username) {
|
||||
String url = URLBuilder.getAlbumInfoUrl(name, artist, username);
|
||||
Document response = Network.getResponse(url);
|
||||
if (response != null) {
|
||||
Album album = Parser.parseAlbum(response);
|
||||
return album;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// public Track getTrack(int track) {
|
||||
// return trackList.get(track);
|
||||
// }
|
||||
//
|
||||
// public ArrayList<Track> getTrackList(){
|
||||
// return trackList;
|
||||
// }
|
||||
//
|
||||
// public void addTrack(Track track) {
|
||||
// trackList.add(track);
|
||||
// }
|
||||
//
|
||||
public ArrayList<Tag> getTags() {
|
||||
return tagList;
|
||||
}
|
||||
@ -93,13 +49,6 @@ public class Album extends FMObj implements Serializable{
|
||||
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
@Override
|
||||
public void view() {
|
||||
AlbumView view = new AlbumView(this);
|
||||
view.setVisible(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj.getClass() != this.getClass())
|
||||
@ -118,19 +67,6 @@ public class Album extends FMObj implements Serializable{
|
||||
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
@Override
|
||||
public void refresh() {
|
||||
Album album = Album.getAlbum(name, artist.getName(), Reference.getUserName());
|
||||
|
||||
this.listeners = album.listeners;
|
||||
this.userPlayCount = album.userPlayCount;
|
||||
this.playCount = album.playCount;
|
||||
this.wiki = album.wiki;
|
||||
this.mbid = album.mbid;
|
||||
|
||||
}
|
||||
|
||||
public static class AlbumBuilder{
|
||||
|
||||
protected String name;
|
||||
|
@ -3,14 +3,6 @@ package sarsoo.fmframework.music;
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.w3c.dom.Document;
|
||||
|
||||
import sarsoo.fmframework.net.Network;
|
||||
import sarsoo.fmframework.net.URLBuilder;
|
||||
//import sarsoo.fmframework.net.TestCall;
|
||||
import sarsoo.fmframework.parser.Parser;
|
||||
import sarsoo.fmframework.util.Reference;
|
||||
|
||||
public class Artist extends FMObj implements Serializable{
|
||||
|
||||
/**
|
||||
@ -23,16 +15,6 @@ public class Artist extends FMObj implements Serializable{
|
||||
protected ArrayList<Artist> similarArtists;
|
||||
protected ArrayList<Tag> tagList;
|
||||
|
||||
@Deprecated
|
||||
public Artist(String name) {
|
||||
super(name, null, null, 0, 0, 0, null);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public Artist(String name, String url, String mbid, int listeners, int playCount, int userPlayCount, Wiki wiki) {
|
||||
super(name, url, mbid, listeners, playCount, userPlayCount, wiki);
|
||||
}
|
||||
|
||||
private Artist(ArtistBuilder builder) {
|
||||
this.name = builder.name;
|
||||
|
||||
@ -53,26 +35,6 @@ public class Artist extends FMObj implements Serializable{
|
||||
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static Artist getArtist(String name, String username) {
|
||||
String url = URLBuilder.getArtistInfoUrl(name, username);
|
||||
// TestCall.test(url);
|
||||
Document response = Network.getResponse(url);
|
||||
if (response != null) {
|
||||
Artist artist = Parser.parseArtist(response);
|
||||
return artist;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static Artist getArtistByMbid(String mbid, String username) {
|
||||
String url = URLBuilder.getArtistInfoMbidUrl(mbid, username);
|
||||
Document response = Network.getResponse(url);
|
||||
Artist artist = Parser.parseArtist(response);
|
||||
return artist;
|
||||
}
|
||||
|
||||
public ArrayList<Album> getAlbum() {
|
||||
return albums;
|
||||
}
|
||||
@ -110,19 +72,6 @@ public class Artist extends FMObj implements Serializable{
|
||||
return "Artist: " + name;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
@Override
|
||||
public void refresh() {
|
||||
Artist artist = Artist.getArtist(name, Reference.getUserName());
|
||||
|
||||
this.listeners = artist.listeners;
|
||||
this.userPlayCount = artist.userPlayCount;
|
||||
this.playCount = artist.playCount;
|
||||
this.wiki = artist.wiki;
|
||||
this.mbid = artist.mbid;
|
||||
|
||||
|
||||
}
|
||||
|
||||
public static class ArtistBuilder{
|
||||
|
||||
|
@ -2,8 +2,8 @@ package sarsoo.fmframework.music;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import sarsoo.fmframework.jframe.FMObjView;
|
||||
import sarsoo.fmframework.util.Getter;
|
||||
import sarsoo.fmframework.fm.FmUserNetwork;
|
||||
import sarsoo.fmframework.net.Key;
|
||||
import sarsoo.fmframework.util.Maths;
|
||||
import sarsoo.fmframework.util.Reference;
|
||||
|
||||
@ -27,29 +27,6 @@ public abstract class FMObj implements Comparable<FMObj>, Serializable{
|
||||
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public FMObj(String name, String url, String mbid, int listeners, int playCount, int userPlayCount, Wiki wiki) {
|
||||
this.name = name;
|
||||
this.url = url;
|
||||
this.mbid = mbid;
|
||||
this.listeners = listeners;
|
||||
this.playCount = playCount;
|
||||
this.userPlayCount = userPlayCount;
|
||||
this.wiki = wiki;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public abstract void refresh();
|
||||
|
||||
@Deprecated
|
||||
public void view() {
|
||||
FMObjView view = new FMObjView(this);
|
||||
view.setVisible(true);
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(FMObj obj) {
|
||||
@ -86,7 +63,8 @@ public abstract class FMObj implements Comparable<FMObj>, Serializable{
|
||||
}
|
||||
|
||||
public double getPercent() {
|
||||
return ((double)userPlayCount*100)/(double) Getter.getScrobbles(Reference.getUserName());
|
||||
FmUserNetwork net = new FmUserNetwork(Key.getKey(), Reference.getUserName());
|
||||
return ((double)userPlayCount*100)/(double) net.getUser().getScrobbleCount();
|
||||
}
|
||||
|
||||
public Wiki getWiki() {
|
||||
|
@ -19,12 +19,6 @@ public class Tag implements Comparable<Tag>, Serializable{
|
||||
this.count = count;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public Tag(String name, String url) {
|
||||
this.setName(name);
|
||||
this.setUrl(url);
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
@ -5,11 +5,7 @@ import java.util.ArrayList;
|
||||
|
||||
import org.w3c.dom.Document;
|
||||
|
||||
import sarsoo.fmframework.jframe.TrackView;
|
||||
import sarsoo.fmframework.net.Network;
|
||||
import sarsoo.fmframework.net.URLBuilder;
|
||||
//import sarsoo.fmframework.net.TestCall;
|
||||
import sarsoo.fmframework.parser.Parser;
|
||||
import sarsoo.fmframework.util.Reference;
|
||||
|
||||
public class Track extends FMObj implements Serializable {
|
||||
@ -27,19 +23,6 @@ public class Track extends FMObj implements Serializable {
|
||||
|
||||
private int utsFirstListen;
|
||||
|
||||
@Deprecated
|
||||
public Track(String name, String artist) {
|
||||
super(name, null, null, 0, 0, 0, null);
|
||||
this.artist = new Artist(artist);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public Track(String name, String url, String mbid, Artist artist, int listeners, int playCount, int userPlayCount,
|
||||
Wiki wiki) {
|
||||
super(name, url, mbid, listeners, playCount, userPlayCount, wiki);
|
||||
this.artist = artist;
|
||||
}
|
||||
|
||||
private Track(TrackBuilder builder) {
|
||||
|
||||
this.name = builder.name;
|
||||
@ -63,20 +46,6 @@ public class Track extends FMObj implements Serializable {
|
||||
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static Track getTrack(String name, String artist, String username) {
|
||||
// System.out.println("Artist " + artist);
|
||||
// System.out.println("track " + name);
|
||||
String url = URLBuilder.getTrackInfoUrl(name, artist, username);
|
||||
// TestCall.test(url);
|
||||
Document response = Network.getResponse(url);
|
||||
if (response != null) {
|
||||
Track track = Parser.parseTrack(response);
|
||||
return track;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public Artist getArtist() {
|
||||
return artist;
|
||||
}
|
||||
@ -95,7 +64,10 @@ public class Track extends FMObj implements Serializable {
|
||||
}
|
||||
|
||||
public String getLyricsURL() {
|
||||
return URLBuilder.getLyricsUrl(name, artist.getName());
|
||||
String trackName = name.replaceAll(" ", "-");
|
||||
String artistName = artist.getName().replaceAll(" ", "-");
|
||||
String urlString = String.format("http://genius.com/%s-%s-lyrics", artistName, trackName);
|
||||
return urlString;
|
||||
}
|
||||
|
||||
public Album getAlbum() {
|
||||
@ -115,12 +87,6 @@ public class Track extends FMObj implements Serializable {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
@Override
|
||||
public void view() {
|
||||
TrackView view = new TrackView(this);
|
||||
view.setVisible(true);
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
if (album != null)
|
||||
@ -129,20 +95,6 @@ public class Track extends FMObj implements Serializable {
|
||||
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
@Override
|
||||
public void refresh() {
|
||||
Track track = Track.getTrack(name, artist.getName(), Reference.getUserName());
|
||||
|
||||
this.listeners = track.listeners;
|
||||
this.userPlayCount = track.userPlayCount;
|
||||
this.playCount = track.playCount;
|
||||
this.wiki = track.wiki;
|
||||
this.mbid = track.mbid;
|
||||
this.isLoved = track.isLoved;
|
||||
|
||||
}
|
||||
|
||||
public int getUtsFirstListen() {
|
||||
return utsFirstListen;
|
||||
}
|
||||
|
@ -2,8 +2,6 @@ package sarsoo.fmframework.music;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import sarsoo.fmframework.jframe.WikiView;
|
||||
|
||||
public class Wiki implements Serializable{
|
||||
|
||||
/**
|
||||
@ -20,11 +18,6 @@ public class Wiki implements Serializable{
|
||||
this.setContent(content);
|
||||
}
|
||||
|
||||
public void view(String name) {
|
||||
WikiView view = new WikiView(this, name);
|
||||
view.setVisible(true);
|
||||
}
|
||||
|
||||
public String getDate() {
|
||||
return date;
|
||||
}
|
||||
|
@ -1,57 +0,0 @@
|
||||
package sarsoo.fmframework.net;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.Reader;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@Deprecated
|
||||
public class Authenticator {
|
||||
public String write() {
|
||||
URL url;
|
||||
try {
|
||||
url = new URL("http://ws.audioscrobbler.com/2.0/");
|
||||
|
||||
Map<String, Object> params = new LinkedHashMap<>();
|
||||
params.put("name", "Freddie the Fish");
|
||||
params.put("email", "fishie@seamail.example.com");
|
||||
params.put("reply_to_thread", 10394);
|
||||
params.put("message",
|
||||
"Shark attacks in Botany Bay have gotten out of control. We need more defensive dolphins to protect the schools here, but Mayor Porpoise is too busy stuffing his snout with lobsters. He's so shellfish.");
|
||||
|
||||
StringBuilder postData = new StringBuilder();
|
||||
for (Map.Entry<String, Object> param : params.entrySet()) {
|
||||
if (postData.length() != 0)
|
||||
postData.append('&');
|
||||
postData.append(URLEncoder.encode(param.getKey(), "UTF-8"));
|
||||
postData.append('=');
|
||||
postData.append(URLEncoder.encode(String.valueOf(param.getValue()), "UTF-8"));
|
||||
}
|
||||
byte[] postDataBytes = postData.toString().getBytes("UTF-8");
|
||||
|
||||
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
|
||||
conn.setRequestMethod("POST");
|
||||
conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
|
||||
conn.setRequestProperty("Content-Length", String.valueOf(postDataBytes.length));
|
||||
conn.setDoOutput(true);
|
||||
conn.getOutputStream().write(postDataBytes);
|
||||
|
||||
Reader in = new BufferedReader(new InputStreamReader(conn.getInputStream(), "UTF-8"));
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int c; (c = in.read()) >= 0;)
|
||||
sb.append((char)c);
|
||||
String response = sb.toString();
|
||||
|
||||
return response.toString();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
|
||||
}
|
||||
}
|
@ -16,96 +16,8 @@ import org.xml.sax.SAXException;
|
||||
|
||||
import sarsoo.fmframework.error.ApiCallException;
|
||||
|
||||
@Deprecated
|
||||
public class Network {
|
||||
|
||||
public static Document getResponse(String urlString) {
|
||||
try {
|
||||
URL url = new URL(urlString);
|
||||
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
|
||||
conn.setRequestMethod("GET");
|
||||
conn.setRequestProperty("Accept", "application/xml");
|
||||
conn.setRequestProperty("User-Agent", "fmframework/1.0");
|
||||
|
||||
if (conn.getResponseCode() != 200) {
|
||||
throw new ApiCallException(conn.getResponseCode());
|
||||
}
|
||||
|
||||
InputStream input = conn.getInputStream();
|
||||
|
||||
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
|
||||
DocumentBuilder dBuilder;
|
||||
try {
|
||||
dBuilder = dbFactory.newDocumentBuilder();
|
||||
try {
|
||||
Document doc = dBuilder.parse(input);
|
||||
conn.disconnect();
|
||||
doc.getDocumentElement().normalize();
|
||||
|
||||
return doc;
|
||||
|
||||
} catch (SAXException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} catch (ParserConfigurationException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} catch (MalformedURLException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} catch (ApiCallException e) {
|
||||
System.err.println(e.getFailureCode() + " " + e.getError());
|
||||
}
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
public static Document write(byte[] postDataBytes) {
|
||||
|
||||
URL url;
|
||||
try {
|
||||
url = new URL("http://ws.audioscrobbler.com/2.0/");
|
||||
|
||||
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
|
||||
conn.setRequestMethod("POST");
|
||||
conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
|
||||
conn.setRequestProperty("Content-Length", String.valueOf(postDataBytes.length));
|
||||
conn.setDoOutput(true);
|
||||
conn.getOutputStream().write(postDataBytes);
|
||||
|
||||
InputStream input = conn.getInputStream();
|
||||
|
||||
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
|
||||
DocumentBuilder dBuilder;
|
||||
try {
|
||||
dBuilder = dbFactory.newDocumentBuilder();
|
||||
try {
|
||||
Document doc = dBuilder.parse(input);
|
||||
conn.disconnect();
|
||||
doc.getDocumentElement().normalize();
|
||||
|
||||
return doc;
|
||||
|
||||
} catch (SAXException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} catch (ParserConfigurationException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void openURL(String url) {
|
||||
try {
|
||||
Desktop desktop = java.awt.Desktop.getDesktop();
|
||||
|
@ -1,44 +0,0 @@
|
||||
package sarsoo.fmframework.net;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
|
||||
@Deprecated
|
||||
public class TestCall {
|
||||
|
||||
public static void test(String urlString) {
|
||||
try {
|
||||
URL url = new URL(urlString);
|
||||
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
|
||||
conn.setRequestMethod("GET");
|
||||
conn.setRequestProperty("Accept", "application/json");
|
||||
|
||||
if (conn.getResponseCode() != 200) {
|
||||
throw new RuntimeException("Failed : HTTP error code : " + conn.getResponseCode());
|
||||
}
|
||||
|
||||
BufferedReader br = new BufferedReader(new InputStreamReader((conn.getInputStream())));
|
||||
|
||||
String output;
|
||||
while ((output = br.readLine()) != null) {
|
||||
System.out.println(output);
|
||||
}
|
||||
|
||||
conn.disconnect();
|
||||
|
||||
} catch (MalformedURLException e) {
|
||||
|
||||
e.printStackTrace();
|
||||
|
||||
} catch (IOException e) {
|
||||
|
||||
e.printStackTrace();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,230 +0,0 @@
|
||||
package sarsoo.fmframework.net;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLEncoder;
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
import sarsoo.fmframework.music.Track;
|
||||
|
||||
@Deprecated
|
||||
public class URLBuilder {
|
||||
|
||||
public enum FMObjType{
|
||||
ARTIST,
|
||||
ALBUM,
|
||||
TRACK
|
||||
}
|
||||
|
||||
public static String getArtistInfoUrl(String artist, String username) {
|
||||
String urlString;
|
||||
try {
|
||||
urlString = String.format(
|
||||
"http://ws.audioscrobbler.com/2.0/?method=artist.getInfo&artist=%s&autocorrect=0&username=%s&api_key=%s",
|
||||
URLEncoder.encode(artist, "UTF-8"), URLEncoder.encode(username, "UTF-8"),
|
||||
URLEncoder.encode(Key.getKey(), "UTF-8"));
|
||||
return urlString;
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
public static String getArtistInfoMbidUrl(String mbid, String username) {
|
||||
String urlString;
|
||||
try {
|
||||
urlString = String.format(
|
||||
"http://ws.audioscrobbler.com/2.0/?method=artist.getInfo&mbid=%s&autocorrect=0&username=%s&api_key=%s",
|
||||
URLEncoder.encode(mbid, "UTF-8"), URLEncoder.encode(username, "UTF-8"),
|
||||
URLEncoder.encode(Key.getKey(), "UTF-8"));
|
||||
return urlString;
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
public static String getArtistTracks(String artist, int page, String username) {
|
||||
String urlString;
|
||||
try {
|
||||
urlString = String.format(
|
||||
"http://ws.audioscrobbler.com/2.0/?method=user.getartisttracks&user=%s&artist=%s&page=%d&api_key=%s",
|
||||
URLEncoder.encode(username, "UTF-8"),
|
||||
URLEncoder.encode(artist, "UTF-8"),
|
||||
page,
|
||||
URLEncoder.encode(Key.getKey(), "UTF-8"));
|
||||
return urlString;
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
public static String getAlbumInfoUrl(String album, String artist, String username) {
|
||||
String urlString;
|
||||
try {
|
||||
urlString = String.format(
|
||||
"http://ws.audioscrobbler.com/2.0/?method=album.getInfo&album=%s&artist=%s&autocorrect=0&username=%s&api_key=%s",
|
||||
URLEncoder.encode(album, "UTF-8"), URLEncoder.encode(artist, "UTF-8"),
|
||||
URLEncoder.encode(username, "UTF-8"), URLEncoder.encode(Key.getKey(), "UTF-8"));
|
||||
return urlString;
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static String getTrackInfoUrl(String name, String artist, String username) {
|
||||
String urlString;
|
||||
try {
|
||||
urlString = String.format(
|
||||
"http://ws.audioscrobbler.com/2.0/?method=track.getInfo&track=%s&artist=%s&autocorrect=0&username=%s&api_key=%s",
|
||||
URLEncoder.encode(name, "UTF-8"),
|
||||
URLEncoder.encode(artist, "UTF-8"),
|
||||
URLEncoder.encode(username, "UTF-8"),
|
||||
URLEncoder.encode(Key.getKey(), "UTF-8"));
|
||||
return urlString;
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static String getLastTrackUrl(String username) {
|
||||
String urlString;
|
||||
try {
|
||||
urlString = String.format(
|
||||
"http://ws.audioscrobbler.com/2.0/?method=user.getrecenttracks&user=%s&limit=1&api_key=%s",
|
||||
URLEncoder.encode(username, "UTF-8"), URLEncoder.encode(Key.getKey(), "UTF-8"));
|
||||
return urlString;
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
// System.out.println(urlString);
|
||||
return null;
|
||||
}
|
||||
|
||||
public static String getUserInfoUrl(String username) {
|
||||
String urlString;
|
||||
try {
|
||||
urlString = String.format("http://ws.audioscrobbler.com/2.0/?method=user.getinfo&user=%s&api_key=%s",
|
||||
URLEncoder.encode(username, "UTF-8"), URLEncoder.encode(Key.getKey(), "UTF-8"));
|
||||
return urlString;
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
// System.out.println(urlString);
|
||||
return null;
|
||||
}
|
||||
|
||||
public static String getLyricsUrl(String trackName, String artistName) {
|
||||
String track = trackName.replaceAll(" ", "-");
|
||||
// track = track.replaceAll("[^a-zA-Z ]", "").toLowerCase();
|
||||
String artist = artistName.replaceAll(" ", "-");
|
||||
// artist = artist.replaceAll("[^a-zA-Z ]", "").toLowerCase();
|
||||
String urlString = String.format("http://genius.com/%s-%s-lyrics", artist, track);
|
||||
return urlString;
|
||||
}
|
||||
|
||||
public static String getUserPersonalTags(String username, String tag) {
|
||||
String urlString;
|
||||
try {
|
||||
urlString = String.format("http://ws.audioscrobbler.com/2.0/?method=user.getpersonaltags&user=%s&tag=%s&taggingtype=artist&api_key=%s",
|
||||
URLEncoder.encode(username, "UTF-8"),
|
||||
URLEncoder.encode(tag, "UTF-8"),
|
||||
// URLEncoder.encode(taggingType.toString().toLowerCase(), "UTF-8"),
|
||||
URLEncoder.encode(Key.getKey(), "UTF-8"));
|
||||
return urlString;
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
// System.out.println(urlString);
|
||||
return null;
|
||||
}
|
||||
|
||||
public static String getUserPersonalTags(String username, String tag, int page) {
|
||||
String urlString;
|
||||
try {
|
||||
urlString = String.format("http://ws.audioscrobbler.com/2.0/?method=user.getpersonaltags&user=%s&tag=%s&page=%d&taggingtype=artist&api_key=%s",
|
||||
URLEncoder.encode(username, "UTF-8"),
|
||||
URLEncoder.encode(tag, "UTF-8"),
|
||||
page,
|
||||
// URLEncoder.encode(taggingType.toString().toLowerCase(), "UTF-8"),
|
||||
URLEncoder.encode(Key.getKey(), "UTF-8"));
|
||||
return urlString;
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
// System.out.println(urlString);
|
||||
return null;
|
||||
}
|
||||
|
||||
public static String getUserTopTags(String username) {
|
||||
String urlString;
|
||||
try {
|
||||
urlString = String.format("http://ws.audioscrobbler.com/2.0/?method=user.gettoptags&user=%s&api_key=%s",
|
||||
URLEncoder.encode(username, "UTF-8"),
|
||||
URLEncoder.encode(Key.getKey(), "UTF-8"));
|
||||
return urlString;
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
// System.out.println(urlString);
|
||||
return null;
|
||||
}
|
||||
|
||||
public static String getTodayScrobbles(String username) {
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
|
||||
String month;
|
||||
if(now.getMonthValue() < 10) {
|
||||
month = "0" + now.getMonthValue();
|
||||
}else {
|
||||
month = Integer.toString(now.getMonthValue());
|
||||
}
|
||||
|
||||
String day;
|
||||
if(now.getDayOfMonth() < 10) {
|
||||
day = "0" + now.getDayOfMonth();
|
||||
}else {
|
||||
day = Integer.toString(now.getDayOfMonth());
|
||||
}
|
||||
|
||||
String date = String.format("%d-%s-%sT00:00:00.00Z", now.getYear(), month, day);
|
||||
// System.out.println(date);
|
||||
// long midnight = Instant.parse("2018-04-05T07:00:00.00Z").getEpochSecond();
|
||||
long midnight = Instant.parse(date).getEpochSecond();
|
||||
|
||||
String urlString;
|
||||
try {
|
||||
urlString = String.format("http://ws.audioscrobbler.com/2.0/?method=user.getrecenttracks&user=%s&limit=200&from=%s&api_key=%s",
|
||||
URLEncoder.encode(username, "UTF-8"),
|
||||
URLEncoder.encode(Long.toString(midnight), "UTF-8"),
|
||||
URLEncoder.encode(Key.getKey(), "UTF-8"));
|
||||
return urlString;
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
// System.out.println(urlString);
|
||||
return null;
|
||||
}
|
||||
|
||||
public static String getScrobble(Track track, String username) {
|
||||
String urlString;
|
||||
try {
|
||||
urlString = String.format("http://ws.audioscrobbler.com/2.0/?method=user.gettoptags&user=%s&api_key=%s",
|
||||
URLEncoder.encode(username, "UTF-8"),
|
||||
URLEncoder.encode(Key.getKey(), "UTF-8"));
|
||||
return urlString;
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
// System.out.println(urlString);
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -1,178 +0,0 @@
|
||||
package sarsoo.fmframework.net;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.NamedNodeMap;
|
||||
import org.w3c.dom.Node;
|
||||
|
||||
import sarsoo.fmframework.music.Tag;
|
||||
import sarsoo.fmframework.music.Track;
|
||||
import sarsoo.fmframework.parser.Parser;
|
||||
import sarsoo.fmframework.util.FMObjList;
|
||||
import sarsoo.fmframework.util.Reference;
|
||||
|
||||
@Deprecated
|
||||
public class User {
|
||||
|
||||
protected String userName;
|
||||
|
||||
public User(String userName) {
|
||||
this.userName = userName;
|
||||
}
|
||||
|
||||
public String getUserName() {
|
||||
return userName;
|
||||
}
|
||||
|
||||
public Track getLastTrack() {
|
||||
if(Reference.isVerbose())
|
||||
Reference.getConsole().write(">>getLastTrack");
|
||||
|
||||
String url = URLBuilder.getLastTrackUrl(userName);
|
||||
// TestCall.test(url);
|
||||
Document doc = Network.getResponse(url);
|
||||
|
||||
// System.out.println(doc.getDocumentElement().getAttribute("status"));
|
||||
if (doc != null) {
|
||||
// System.out.println(doc.getDocumentElement().getAttribute("status"));
|
||||
Parser.stripSpace(doc.getDocumentElement());
|
||||
Track track = Parser.parseLastTrack(doc);
|
||||
// if(Reference.isVerbose())
|
||||
// System.out.println(track);
|
||||
// return null;
|
||||
return track;
|
||||
}
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
public int getScrobbles() {
|
||||
if(Reference.isVerbose())
|
||||
Reference.getConsole().write(">>getScrobbles");
|
||||
|
||||
String url = URLBuilder.getUserInfoUrl(userName);
|
||||
Document doc = Network.getResponse(url);
|
||||
if (doc.getDocumentElement().getAttribute("status").equals("ok")) {
|
||||
String scrobbles = doc.getElementsByTagName("playcount").item(0).getTextContent();
|
||||
if (scrobbles != null)
|
||||
if(Reference.isVerbose())
|
||||
Reference.getConsole().write("total scrobbles: " + scrobbles);
|
||||
return Integer.parseInt(scrobbles);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public int getScrobblesToday() {
|
||||
if(Reference.isVerbose())
|
||||
Reference.getConsole().write(">>getScrobblesToday");
|
||||
|
||||
String url = URLBuilder.getTodayScrobbles(userName);
|
||||
Document doc = Network.getResponse(url);
|
||||
if (doc.getDocumentElement().getAttribute("status").equals("ok")) {
|
||||
Node node = doc.getChildNodes().item(0).getFirstChild();
|
||||
NamedNodeMap var = node.getAttributes();
|
||||
// System.out.println(var.getNamedItem("total").getNodeValue());
|
||||
// if (scrobbles != null)
|
||||
if(Reference.isVerbose())
|
||||
Reference.getConsole().write("scrobbles today: " + var.getNamedItem("total").getNodeValue());
|
||||
return Integer.parseInt(var.getNamedItem("total").getNodeValue());
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public FMObjList getUserTag(String tag) {
|
||||
if(Reference.isVerbose())
|
||||
Reference.getConsole().write(">>getUserTag");
|
||||
|
||||
String url = URLBuilder.getUserPersonalTags(userName, tag);
|
||||
Document doc = Network.getResponse(url);
|
||||
|
||||
if (doc != null) {
|
||||
int pages = Integer.valueOf(
|
||||
doc.getFirstChild().getFirstChild().getAttributes().getNamedItem("totalPages").getNodeValue());
|
||||
if(Reference.isVerbose())
|
||||
Reference.getConsole().write("tag pages: " + pages);
|
||||
|
||||
FMObjList list = Parser.parseUserTagList(doc);
|
||||
list.setGroupName(tag);
|
||||
|
||||
if(Reference.isVerbose())
|
||||
Reference.getConsole().write("tag: " + tag);
|
||||
|
||||
if (pages > 1) {
|
||||
int counter;
|
||||
for (counter = 2; counter <= pages; counter++) {
|
||||
String urlNew = URLBuilder.getUserPersonalTags(userName, tag, counter);
|
||||
Document docNew = Network.getResponse(urlNew);
|
||||
|
||||
if (docNew != null) {
|
||||
list.addAll(Parser.parseUserTagList(docNew));
|
||||
// return Parser.parseUserTagList(docNew);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public FMObjList getArtistTracks(String artist) {
|
||||
|
||||
// String url = URLBuilder.getArtistTracks(artist, 1, username);
|
||||
// Document doc = Network.getResponse(url);
|
||||
|
||||
// if (doc != null) {
|
||||
// int pages = Integer.valueOf(
|
||||
// doc.getFirstChild().getFirstChild().getAttributes().getNamedItem("totalPages").getNodeValue());
|
||||
//
|
||||
// FMObjList list = Parser.parseArtistTracks(doc);
|
||||
//// list.setGroupName(artist + " tracks");
|
||||
//
|
||||
// System.out.println(pages);
|
||||
//
|
||||
//
|
||||
// return list;
|
||||
// }
|
||||
|
||||
if(Reference.isVerbose())
|
||||
Reference.getConsole().write(">>getArtistTracks");
|
||||
|
||||
FMObjList totalList = new FMObjList();
|
||||
FMObjList list = new FMObjList();
|
||||
|
||||
int counter = 1;
|
||||
do {
|
||||
String url = URLBuilder.getArtistTracks(artist, counter, userName);
|
||||
Document doc = Network.getResponse(url);
|
||||
|
||||
list = Parser.parseArtistTracks(doc);
|
||||
|
||||
totalList.addAll(list);
|
||||
counter++;
|
||||
|
||||
}while(list.size() > 0);
|
||||
|
||||
return totalList;
|
||||
|
||||
|
||||
}
|
||||
|
||||
public ArrayList<Tag> getUserTags() {
|
||||
if(Reference.isVerbose())
|
||||
Reference.getConsole().write(">>getUserTags");
|
||||
|
||||
String url = URLBuilder.getUserTopTags(userName);
|
||||
Document doc = Network.getResponse(url);
|
||||
if (doc != null) {
|
||||
return Parser.parseUserTags(doc);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
@ -1,28 +0,0 @@
|
||||
package sarsoo.fmframework.parser;
|
||||
|
||||
import sarsoo.fmframework.music.Album;
|
||||
import sarsoo.fmframework.music.Artist;
|
||||
|
||||
import org.w3c.dom.Document;
|
||||
|
||||
@Deprecated
|
||||
public class AlbumParser {
|
||||
|
||||
public static Album parseAlbum(Document doc){
|
||||
|
||||
String name = doc.getElementsByTagName("name").item(0).getTextContent();
|
||||
String artist = doc.getElementsByTagName("artist").item(0).getTextContent();
|
||||
String mbid = doc.getElementsByTagName("mbid").item(0).getTextContent();
|
||||
String url = doc.getElementsByTagName("url").item(0).getTextContent();
|
||||
int listeners = Integer.parseInt(doc.getElementsByTagName("listeners").item(0).getTextContent());
|
||||
int playCount = Integer.parseInt(doc.getElementsByTagName("playcount").item(0).getTextContent());
|
||||
int userPlayCount = Integer.parseInt(doc.getElementsByTagName("userplaycount").item(0).getTextContent());
|
||||
|
||||
Artist artistObj = new Artist(artist);
|
||||
|
||||
Album album = new Album(name, url, mbid, artistObj, listeners, playCount, userPlayCount, null);
|
||||
return album;
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -1,483 +0,0 @@
|
||||
package sarsoo.fmframework.parser;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import javax.xml.transform.OutputKeys;
|
||||
import javax.xml.transform.Transformer;
|
||||
import javax.xml.transform.TransformerException;
|
||||
import javax.xml.transform.TransformerFactory;
|
||||
import javax.xml.transform.dom.DOMSource;
|
||||
import javax.xml.transform.stream.StreamResult;
|
||||
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.NamedNodeMap;
|
||||
import org.w3c.dom.Node;
|
||||
import org.w3c.dom.NodeList;
|
||||
|
||||
import sarsoo.fmframework.fx.TextAreaConsole;
|
||||
import sarsoo.fmframework.music.Album;
|
||||
import sarsoo.fmframework.music.Artist;
|
||||
import sarsoo.fmframework.music.Tag;
|
||||
import sarsoo.fmframework.music.Track;
|
||||
import sarsoo.fmframework.music.Wiki;
|
||||
import sarsoo.fmframework.util.FMObjList;
|
||||
import sarsoo.fmframework.util.Reference;
|
||||
|
||||
@Deprecated
|
||||
public class Parser {
|
||||
|
||||
public static Album parseAlbum(Document doc) {
|
||||
if(Reference.isVerbose())
|
||||
Reference.getConsole().write(">parseAlbum");
|
||||
|
||||
if (doc.getDocumentElement().getAttribute("status").equals("ok")) {
|
||||
String name = doc.getElementsByTagName("name").item(0).getTextContent();
|
||||
String artist = doc.getElementsByTagName("artist").item(0).getTextContent();
|
||||
|
||||
String mbid = null;
|
||||
NodeList mbidNodeList = doc.getElementsByTagName("mbid");
|
||||
if (mbidNodeList.item(0) != null) {
|
||||
mbid = doc.getElementsByTagName("mbid").item(0).getTextContent();
|
||||
}
|
||||
|
||||
String url = doc.getElementsByTagName("url").item(0).getTextContent();
|
||||
int listeners = Integer.parseInt(doc.getElementsByTagName("listeners").item(0).getTextContent());
|
||||
int playCount = Integer.parseInt(doc.getElementsByTagName("playcount").item(0).getTextContent());
|
||||
|
||||
int userPlayCount = 0;
|
||||
NodeList userPlayCountNodeList = doc.getElementsByTagName("userplaycount");
|
||||
if (userPlayCountNodeList.item(0) != null) {
|
||||
userPlayCount = Integer.parseInt(userPlayCountNodeList.item(0).getTextContent());
|
||||
}
|
||||
|
||||
Artist artistObj = Artist.getArtist(artist, Reference.getUserName());
|
||||
|
||||
Wiki wiki = null;
|
||||
NodeList wikiNodeList = doc.getElementsByTagName("wiki");
|
||||
if (wikiNodeList.getLength() != 0) {
|
||||
Node wikiNode = wikiNodeList.item(0);
|
||||
NodeList wikiContents = wikiNode.getChildNodes();
|
||||
|
||||
String date = null;
|
||||
String content = null;
|
||||
|
||||
int counter;
|
||||
Node node;
|
||||
for (counter = 0; counter < wikiContents.getLength(); counter++) {
|
||||
node = wikiContents.item(counter);
|
||||
|
||||
if (node.getNodeName().equals("published")) {
|
||||
date = node.getTextContent();
|
||||
}
|
||||
if (node.getNodeName().equals("content")) {
|
||||
content = node.getTextContent();
|
||||
}
|
||||
}
|
||||
|
||||
if (date != null && content != null)
|
||||
wiki = new Wiki(date, null, content);
|
||||
}
|
||||
|
||||
Album album = new Album(name, url, mbid, artistObj, listeners, playCount, userPlayCount, wiki);
|
||||
|
||||
if(Reference.isVerbose())
|
||||
Reference.getConsole().write(album.toString());
|
||||
|
||||
return album;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Artist parseArtist(Document doc) {
|
||||
if(Reference.isVerbose())
|
||||
TextAreaConsole.getInstance().write(">parseArtist");
|
||||
|
||||
if (doc.getDocumentElement().getAttribute("status").equals("ok")) {
|
||||
String name = doc.getElementsByTagName("name").item(0).getTextContent();
|
||||
String mbid = null;
|
||||
|
||||
NodeList mbidNodeList = doc.getElementsByTagName("mbid");
|
||||
if (mbidNodeList.item(0) != null) {
|
||||
mbid = doc.getElementsByTagName("mbid").item(0).getTextContent();
|
||||
}
|
||||
|
||||
String url = doc.getElementsByTagName("url").item(0).getTextContent();
|
||||
|
||||
int listeners = Integer.parseInt(doc.getElementsByTagName("listeners").item(0).getTextContent());
|
||||
int playCount = Integer.parseInt(doc.getElementsByTagName("playcount").item(0).getTextContent());
|
||||
|
||||
int userPlayCount = 0;
|
||||
NodeList userPlayCountNodeList = doc.getElementsByTagName("userplaycount");
|
||||
if (userPlayCountNodeList.item(0) != null) {
|
||||
userPlayCount = Integer.parseInt(userPlayCountNodeList.item(0).getTextContent());
|
||||
}
|
||||
|
||||
Wiki wiki = null;
|
||||
NodeList wikiNodeList = doc.getElementsByTagName("bio");
|
||||
if (wikiNodeList.getLength() != 0) {
|
||||
Node wikiNode = wikiNodeList.item(0);
|
||||
NodeList wikiContents = wikiNode.getChildNodes();
|
||||
|
||||
String date = null;
|
||||
String summary = null;
|
||||
String content = null;
|
||||
|
||||
int counter;
|
||||
Node node;
|
||||
for (counter = 0; counter < wikiContents.getLength(); counter++) {
|
||||
node = wikiContents.item(counter);
|
||||
|
||||
if (node.getNodeName().equals("published")) {
|
||||
// System.out.println(node.getNodeName() + node.getTextContent());
|
||||
date = node.getTextContent();
|
||||
}
|
||||
if (node.getNodeName().equals("summary")) {
|
||||
// System.out.println(node.getNodeName() + node.getTextContent());
|
||||
summary = node.getTextContent();
|
||||
}
|
||||
if (node.getNodeName().equals("content")) {
|
||||
// System.out.println(node.getNodeName() + node.getTextContent());
|
||||
content = node.getTextContent();
|
||||
}
|
||||
}
|
||||
|
||||
if (date != null && content != null)
|
||||
// System.out.println("wiki init");
|
||||
wiki = new Wiki(date, summary, content);
|
||||
// if (wikiNodeList.item(0) != null) {
|
||||
// String date = wikiNodeList.item(0).getFirstChild().getTextContent();
|
||||
//
|
||||
// Node summaryNode = wikiNodeList.item(0).getFirstChild().getNextSibling();
|
||||
// while (!(summaryNode instanceof Element) && summaryNode != null) {
|
||||
// summaryNode = summaryNode.getNextSibling();
|
||||
// }
|
||||
// String summary = summaryNode.getTextContent();
|
||||
// // System.out.println(summary);
|
||||
//
|
||||
// Node contentNode = summaryNode.getNextSibling();
|
||||
// while (!(contentNode instanceof Element) && contentNode != null) {
|
||||
// contentNode = contentNode.getNextSibling();
|
||||
// }
|
||||
// String content = contentNode.getTextContent();
|
||||
// // System.out.println(content);
|
||||
//
|
||||
// wiki = new Wiki(date, summary, content);
|
||||
// }
|
||||
}
|
||||
|
||||
Artist artist = new Artist(name, url, mbid, listeners, playCount, userPlayCount, wiki);
|
||||
|
||||
if(Reference.isVerbose())
|
||||
Reference.getConsole().write(artist.toString());
|
||||
|
||||
return artist;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Track parseTrack(Document doc) {
|
||||
if(Reference.isVerbose())
|
||||
// System.out.println("-parseTrack");
|
||||
TextAreaConsole.getInstance().write(">parseTrack");
|
||||
|
||||
if (doc.getDocumentElement().getAttribute("status").equals("ok")) {
|
||||
String name = " ";
|
||||
try {
|
||||
name = doc.getElementsByTagName("name").item(0).getTextContent();
|
||||
} catch (NullPointerException e) {
|
||||
System.err.println("Could Not Parse Track Name");
|
||||
return null;
|
||||
}
|
||||
String artistName = " ";
|
||||
try {
|
||||
artistName = doc.getElementsByTagName("artist").item(0).getFirstChild().getTextContent();
|
||||
} catch (NullPointerException e) {
|
||||
System.err.println("Could Not Parse Artist Name for " + name);
|
||||
return null;
|
||||
}
|
||||
String mbid = null;
|
||||
|
||||
NodeList mbidNodeList = doc.getElementsByTagName("mbid");
|
||||
if (mbidNodeList.item(0) != null) {
|
||||
mbid = doc.getElementsByTagName("mbid").item(0).getTextContent();
|
||||
}
|
||||
|
||||
String url = null;
|
||||
|
||||
url = doc.getElementsByTagName("url").item(0).getTextContent();
|
||||
|
||||
int listeners = Integer.parseInt(doc.getElementsByTagName("listeners").item(0).getTextContent());
|
||||
int playCount = Integer.parseInt(doc.getElementsByTagName("playcount").item(0).getTextContent());
|
||||
|
||||
int userPlayCount = 0;
|
||||
|
||||
NodeList userPlayCountNodeList = doc.getElementsByTagName("userplaycount");
|
||||
if (userPlayCountNodeList.item(0) != null) {
|
||||
userPlayCount = Integer.parseInt(userPlayCountNodeList.item(0).getTextContent());
|
||||
}
|
||||
|
||||
Artist artistObj = Artist.getArtist(artistName, Reference.getUserName());
|
||||
|
||||
Wiki wiki = null;
|
||||
NodeList wikiNodeList = doc.getElementsByTagName("wiki");
|
||||
if (wikiNodeList.getLength() != 0) {
|
||||
Node wikiNode = wikiNodeList.item(0);
|
||||
NodeList wikiContents = wikiNode.getChildNodes();
|
||||
|
||||
String date = null;
|
||||
// String summary = null;
|
||||
String content = null;
|
||||
|
||||
int counter;
|
||||
Node node;
|
||||
for (counter = 0; counter < wikiContents.getLength(); counter++) {
|
||||
node = wikiContents.item(counter);
|
||||
|
||||
if (node.getNodeName().equals("published")) {
|
||||
// System.out.println(node.getNodeName() + node.getTextContent());
|
||||
date = node.getTextContent();
|
||||
}
|
||||
// if (node.getNodeName().equals("summary")) {
|
||||
// System.out.println(node.getNodeName() + node.getTextContent());
|
||||
// summary = node.getTextContent();
|
||||
// }
|
||||
if (node.getNodeName().equals("content")) {
|
||||
// System.out.println(node.getNodeName() + node.getTextContent());
|
||||
content = node.getTextContent();
|
||||
}
|
||||
}
|
||||
|
||||
if (date != null && content != null)
|
||||
// System.out.println("wiki init");
|
||||
wiki = new Wiki(date, null, content);
|
||||
}
|
||||
|
||||
Track track = new Track(name, url, mbid, artistObj, listeners, playCount, userPlayCount, wiki);
|
||||
|
||||
if(Reference.isVerbose())
|
||||
Reference.getConsole().write(track.toString());
|
||||
|
||||
return track;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static Track parseLastTrack(Document doc) {
|
||||
if(Reference.isVerbose())
|
||||
// System.out.println("-parseLastTrack");
|
||||
TextAreaConsole.getInstance().write(">parseLastTrack");
|
||||
|
||||
if (doc.getDocumentElement().getAttribute("status").equals("ok")) {
|
||||
String name = doc.getElementsByTagName("name").item(0).getTextContent();
|
||||
// System.out.println(name);
|
||||
String artistName = doc.getElementsByTagName("artist").item(0).getTextContent();
|
||||
|
||||
String albumName = doc.getElementsByTagName("album").item(0).getTextContent();
|
||||
|
||||
Track track = Track.getTrack(name, artistName, Reference.getUserName());
|
||||
|
||||
Album album = Album.getAlbum(albumName, artistName, Reference.getUserName());
|
||||
|
||||
track.setAlbum(album);
|
||||
|
||||
if(Reference.isVerbose())
|
||||
System.out.println(track);
|
||||
|
||||
return track;
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
public static ArrayList<Tag> parseUserTags(Document doc) {
|
||||
if(Reference.isVerbose())
|
||||
Reference.getConsole().write(">parseUserTags");
|
||||
|
||||
if (doc.getDocumentElement().getAttribute("status").equals("ok")) {
|
||||
NodeList objList = doc.getElementsByTagName("tag");
|
||||
|
||||
// Node obj = objList.item(0);
|
||||
ArrayList<Tag> list = new ArrayList<Tag>();
|
||||
// String name = obj.getFirstChild().getTextContent();
|
||||
// System.out.println(name);
|
||||
//
|
||||
// Artist artist = Artist.getArtist(name, Reference.getUserName());
|
||||
//
|
||||
// System.out.println(artist);
|
||||
|
||||
int counter;
|
||||
for (counter = 0; counter < objList.getLength(); counter++) {
|
||||
NodeList obj = objList.item(counter).getChildNodes();
|
||||
|
||||
String name = obj.item(0).getTextContent();
|
||||
String url = obj.item(4).getTextContent();
|
||||
// System.out.println(obj.getTextContent());
|
||||
|
||||
Tag tag = new Tag(name, url);
|
||||
|
||||
if(Reference.isVerbose())
|
||||
Reference.getConsole().write(tag.toString());
|
||||
|
||||
// System.out.println(name + " " + url);
|
||||
list.add(tag);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
public static FMObjList parseUserTagList(Document doc) {
|
||||
if(Reference.isVerbose())
|
||||
Reference.getConsole().write(">parseUserTagList");
|
||||
// Console.getInstance().write("-parseUserTagList");
|
||||
|
||||
if (doc.getDocumentElement().getAttribute("status").equals("ok")) {
|
||||
NodeList objList = doc.getElementsByTagName("artist");
|
||||
|
||||
// Node obj = objList.item(0);
|
||||
FMObjList list = new FMObjList();
|
||||
// String name = obj.getFirstChild().getTextContent();
|
||||
// System.out.println(name);
|
||||
//
|
||||
// Artist artist = Artist.getArtist(name, Reference.getUserName());
|
||||
//
|
||||
// System.out.println(artist);
|
||||
|
||||
int counter;
|
||||
for (counter = 0; counter < objList.getLength(); counter++) {
|
||||
Node obj = objList.item(counter);
|
||||
|
||||
String name = obj.getFirstChild().getTextContent();
|
||||
// System.out.println(name + ".");
|
||||
// System.out.println(obj.getTextContent());
|
||||
Artist artist = Artist.getArtist(name, Reference.getUserName());
|
||||
|
||||
// if(Reference.isVerbose())
|
||||
// Reference.getConsole().write(artist.toString());
|
||||
|
||||
// System.out.println(artist);
|
||||
list.add(artist);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
public static FMObjList parseArtistTracks(Document doc) {
|
||||
if(Reference.isVerbose())
|
||||
Reference.getConsole().write(">parseArtistTracks");
|
||||
|
||||
if (doc.getDocumentElement().getAttribute("status").equals("ok")) {
|
||||
NodeList objList = doc.getElementsByTagName("track");
|
||||
|
||||
// Node obj = objList.item(0);
|
||||
FMObjList list = new FMObjList();
|
||||
// String name = obj.getFirstChild().getTextContent();
|
||||
// System.out.println(name);
|
||||
//
|
||||
// Artist artist = Artist.getArtist(name, Reference.getUserName());
|
||||
//
|
||||
// System.out.println(artist);
|
||||
|
||||
int counter;
|
||||
for (counter = 0; counter < objList.getLength(); counter++) {
|
||||
Node obj = objList.item(counter);
|
||||
|
||||
NodeList objNodes = obj.getChildNodes();
|
||||
|
||||
String artist = objNodes.item(0).getTextContent();
|
||||
// System.out.println(artist);
|
||||
String name = objNodes.item(2).getTextContent();
|
||||
// System.out.println(name);
|
||||
// System.out.println(name + ".");
|
||||
// System.out.println(obj.getTextContent());
|
||||
// System.out.println(counter);
|
||||
// System.out.println(artist);
|
||||
Track track = Track.getTrack(name, artist, Reference.getUserName());
|
||||
|
||||
if(Reference.isVerbose())
|
||||
Reference.getConsole().write(track.toString());
|
||||
|
||||
list.add(track);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
public static void printDocument(Document doc, OutputStream out) throws IOException, TransformerException {
|
||||
TransformerFactory tf = TransformerFactory.newInstance();
|
||||
Transformer transformer = tf.newTransformer();
|
||||
transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "no");
|
||||
transformer.setOutputProperty(OutputKeys.METHOD, "xml");
|
||||
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
|
||||
transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
|
||||
transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4");
|
||||
|
||||
transformer.transform(new DOMSource(doc), new StreamResult(new OutputStreamWriter(out, "UTF-8")));
|
||||
}
|
||||
|
||||
public static void stripSpace(Node node) {
|
||||
Node child = node.getFirstChild();
|
||||
while (child != null) {
|
||||
// save the sibling of the node that will
|
||||
// perhaps be removed and set to null
|
||||
Node c = child.getNextSibling();
|
||||
if ((child.getNodeType() == Node.TEXT_NODE && child.getNodeValue().trim().length() == 0)
|
||||
|| ((child.getNodeType() != Node.TEXT_NODE) && (child.getNodeType() != Node.ELEMENT_NODE)))
|
||||
node.removeChild(child);
|
||||
else // process children recursively
|
||||
stripSpace(child);
|
||||
child = c;
|
||||
}
|
||||
}
|
||||
|
||||
public static void compact(Node node, String indent) {
|
||||
if (node == null)
|
||||
return;
|
||||
switch (node.getNodeType()) {
|
||||
case Node.ELEMENT_NODE: {
|
||||
System.out.print(node.getNodeName() + '[');
|
||||
indent += blanks(node.getNodeName().length() + 1);
|
||||
NamedNodeMap attrs = node.getAttributes();
|
||||
boolean first = true;
|
||||
for (int i = 0; i < attrs.getLength(); i++) {
|
||||
if (!first)
|
||||
System.out.print('\n' + indent);
|
||||
System.out.print('@' + attrs.item(i).getNodeName() + '[' + attrs.item(i).getNodeValue() + ']');
|
||||
first = false;
|
||||
}
|
||||
for (Node child = node.getFirstChild(); child != null; child = child.getNextSibling()) {
|
||||
if (!first)
|
||||
System.out.print('\n' + indent);
|
||||
compact(child, indent);
|
||||
first = false;
|
||||
}
|
||||
System.out.print(']');
|
||||
break;
|
||||
}
|
||||
case Node.TEXT_NODE: {
|
||||
System.out.print(node.getNodeValue().trim());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// production of string of spaces with a lazy StringBuffer
|
||||
private static StringBuffer blanks = new StringBuffer();
|
||||
|
||||
private static String blanks(int n) {
|
||||
for (int i = blanks.length(); i < n; i++)
|
||||
blanks.append(' ');
|
||||
return blanks.substring(0, n);
|
||||
}
|
||||
}
|
@ -3,11 +3,12 @@ package sarsoo.fmframework.util;
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import sarsoo.fmframework.jframe.FMObjListView;
|
||||
import sarsoo.fmframework.fm.FmUserNetwork;
|
||||
import sarsoo.fmframework.music.Album;
|
||||
import sarsoo.fmframework.music.Artist;
|
||||
import sarsoo.fmframework.music.FMObj;
|
||||
import sarsoo.fmframework.music.Track;
|
||||
import sarsoo.fmframework.net.Key;
|
||||
|
||||
public class FMObjList extends ArrayList<FMObj> implements Comparable<FMObjList>, Serializable {
|
||||
|
||||
@ -71,21 +72,6 @@ public class FMObjList extends ArrayList<FMObj> implements Comparable<FMObjList>
|
||||
return totalScrobbles;
|
||||
}
|
||||
|
||||
public void view(String title) {
|
||||
FMObjListView view = new FMObjListView(this, title);
|
||||
view.setVisible(true);
|
||||
}
|
||||
|
||||
public void view() {
|
||||
if (groupName != null) {
|
||||
FMObjListView view = new FMObjListView(this, getGroupName());
|
||||
view.setVisible(true);
|
||||
} else {
|
||||
FMObjListView view = new FMObjListView(this, "List View");
|
||||
view.setVisible(true);
|
||||
}
|
||||
}
|
||||
|
||||
public String getGroupName() {
|
||||
return groupName;
|
||||
}
|
||||
@ -100,6 +86,7 @@ public class FMObjList extends ArrayList<FMObj> implements Comparable<FMObjList>
|
||||
}
|
||||
|
||||
public void refresh() {
|
||||
stream().forEach(FMObj::refresh);
|
||||
FmUserNetwork net = new FmUserNetwork(Key.getKey(), Reference.getUserName());
|
||||
stream().forEach(item->net.refresh(item));
|
||||
}
|
||||
}
|
||||
|
@ -1,166 +0,0 @@
|
||||
package sarsoo.fmframework.util;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.NamedNodeMap;
|
||||
import org.w3c.dom.Node;
|
||||
|
||||
import sarsoo.fmframework.music.Tag;
|
||||
import sarsoo.fmframework.music.Track;
|
||||
import sarsoo.fmframework.net.Network;
|
||||
import sarsoo.fmframework.net.URLBuilder;
|
||||
import sarsoo.fmframework.parser.Parser;
|
||||
|
||||
@Deprecated
|
||||
public class Getter {
|
||||
public static Track getLastTrack() {
|
||||
if(Reference.isVerbose())
|
||||
Reference.getConsole().write(">>getLastTrack");
|
||||
|
||||
String url = URLBuilder.getLastTrackUrl(Reference.getUserName());
|
||||
// TestCall.test(url);
|
||||
Document doc = Network.getResponse(url);
|
||||
|
||||
// System.out.println(doc.getDocumentElement().getAttribute("status"));
|
||||
if (doc != null) {
|
||||
// System.out.println(doc.getDocumentElement().getAttribute("status"));
|
||||
Parser.stripSpace(doc.getDocumentElement());
|
||||
Track track = Parser.parseLastTrack(doc);
|
||||
// if(Reference.isVerbose())
|
||||
// System.out.println(track);
|
||||
// return null;
|
||||
return track;
|
||||
}
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
public static int getScrobbles(String username) {
|
||||
if(Reference.isVerbose())
|
||||
Reference.getConsole().write(">>getScrobbles");
|
||||
|
||||
String url = URLBuilder.getUserInfoUrl(username);
|
||||
Document doc = Network.getResponse(url);
|
||||
if (doc.getDocumentElement().getAttribute("status").equals("ok")) {
|
||||
String scrobbles = doc.getElementsByTagName("playcount").item(0).getTextContent();
|
||||
if (scrobbles != null)
|
||||
if(Reference.isVerbose())
|
||||
Reference.getConsole().write("total scrobbles: " + scrobbles);
|
||||
return Integer.parseInt(scrobbles);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static int getScrobblesToday(String username) {
|
||||
if(Reference.isVerbose())
|
||||
Reference.getConsole().write(">>getScrobblesToday");
|
||||
|
||||
String url = URLBuilder.getTodayScrobbles(username);
|
||||
Document doc = Network.getResponse(url);
|
||||
if (doc.getDocumentElement().getAttribute("status").equals("ok")) {
|
||||
Node node = doc.getChildNodes().item(0).getFirstChild();
|
||||
NamedNodeMap var = node.getAttributes();
|
||||
// System.out.println(var.getNamedItem("total").getNodeValue());
|
||||
// if (scrobbles != null)
|
||||
if(Reference.isVerbose())
|
||||
Reference.getConsole().write("scrobbles today: " + var.getNamedItem("total").getNodeValue());
|
||||
return Integer.parseInt(var.getNamedItem("total").getNodeValue());
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static FMObjList getUserTag(String username, String tag) {
|
||||
if(Reference.isVerbose())
|
||||
Reference.getConsole().write(">>getUserTag");
|
||||
|
||||
String url = URLBuilder.getUserPersonalTags(username, tag);
|
||||
Document doc = Network.getResponse(url);
|
||||
|
||||
if (doc != null) {
|
||||
int pages = Integer.valueOf(
|
||||
doc.getFirstChild().getFirstChild().getAttributes().getNamedItem("totalPages").getNodeValue());
|
||||
if(Reference.isVerbose())
|
||||
Reference.getConsole().write("tag pages: " + pages);
|
||||
|
||||
FMObjList list = Parser.parseUserTagList(doc);
|
||||
list.setGroupName(tag);
|
||||
|
||||
if(Reference.isVerbose())
|
||||
Reference.getConsole().write("tag: " + tag);
|
||||
|
||||
if (pages > 1) {
|
||||
int counter;
|
||||
for (counter = 2; counter <= pages; counter++) {
|
||||
String urlNew = URLBuilder.getUserPersonalTags(username, tag, counter);
|
||||
Document docNew = Network.getResponse(urlNew);
|
||||
|
||||
if (docNew != null) {
|
||||
list.addAll(Parser.parseUserTagList(docNew));
|
||||
// return Parser.parseUserTagList(docNew);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static FMObjList getArtistTracks(String artist, String username) {
|
||||
|
||||
// String url = URLBuilder.getArtistTracks(artist, 1, username);
|
||||
// Document doc = Network.getResponse(url);
|
||||
|
||||
// if (doc != null) {
|
||||
// int pages = Integer.valueOf(
|
||||
// doc.getFirstChild().getFirstChild().getAttributes().getNamedItem("totalPages").getNodeValue());
|
||||
//
|
||||
// FMObjList list = Parser.parseArtistTracks(doc);
|
||||
//// list.setGroupName(artist + " tracks");
|
||||
//
|
||||
// System.out.println(pages);
|
||||
//
|
||||
//
|
||||
// return list;
|
||||
// }
|
||||
|
||||
if(Reference.isVerbose())
|
||||
Reference.getConsole().write(">>getArtistTracks");
|
||||
|
||||
FMObjList totalList = new FMObjList();
|
||||
FMObjList list = new FMObjList();
|
||||
|
||||
int counter = 1;
|
||||
do {
|
||||
String url = URLBuilder.getArtistTracks(artist, counter, username);
|
||||
Document doc = Network.getResponse(url);
|
||||
|
||||
list = Parser.parseArtistTracks(doc);
|
||||
|
||||
totalList.addAll(list);
|
||||
counter++;
|
||||
|
||||
}while(list.size() > 0);
|
||||
|
||||
return totalList;
|
||||
|
||||
|
||||
}
|
||||
|
||||
public static ArrayList<Tag> getUserTags(String username) {
|
||||
if(Reference.isVerbose())
|
||||
Reference.getConsole().write(">>getUserTags");
|
||||
|
||||
String url = URLBuilder.getUserTopTags(username);
|
||||
Document doc = Network.getResponse(url);
|
||||
if (doc != null) {
|
||||
return Parser.parseUserTags(doc);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
@ -45,114 +45,4 @@ public class Reference {
|
||||
console = consoleIn;
|
||||
}
|
||||
|
||||
private static ArrayList<FMObjList> groups = new ArrayList<FMObjList>();
|
||||
|
||||
// public static void initGroupsList() {
|
||||
// groups.add(getTDE());
|
||||
// groups.add(getBPHQ());
|
||||
// groups.add(getDre());
|
||||
// groups.add(getWu());
|
||||
// groups.add(getHopeless());
|
||||
// groups.add(getSaturation());
|
||||
// }
|
||||
|
||||
public static FMObjList getSaturation() {
|
||||
FMObjList saturation = new FMObjList("Saturation");
|
||||
|
||||
saturation.add(Album.getAlbum("Saturation", "Brockhampton", Reference.getUserName()));
|
||||
saturation.add(Album.getAlbum("Saturation II", "Brockhampton", Reference.getUserName()));
|
||||
saturation.add(Album.getAlbum("Saturation III", "Brockhampton", Reference.getUserName()));
|
||||
|
||||
return saturation;
|
||||
}
|
||||
|
||||
// public static ArrayList<FMObjList> getGroups() {
|
||||
// return groups;
|
||||
// }
|
||||
|
||||
public static FMObjList getHopeless() {
|
||||
FMObjList hopeless = new FMObjList("Hopless");
|
||||
|
||||
hopeless.add(Artist.getArtist("Circa Survive", Reference.getUserName()));
|
||||
hopeless.add(Artist.getArtist("Enter Shikari", Reference.getUserName()));
|
||||
hopeless.add(Artist.getArtist("Have Mercy", Reference.getUserName()));
|
||||
hopeless.add(Artist.getArtist("Moose Blood", Reference.getUserName()));
|
||||
// hopeless.add(Artist.getArtist("New Found Glory", Reference.getUserName()));
|
||||
hopeless.add(Artist.getArtist("Neck Deep", Reference.getUserName()));
|
||||
hopeless.add(Artist.getArtist("Sum 41", Reference.getUserName()));
|
||||
// hopeless.add(Artist.getArtist("Taking Back Saturday", Reference.getUserName()));
|
||||
hopeless.add(Artist.getArtist("Tonight Alive", Reference.getUserName()));
|
||||
hopeless.add(Artist.getArtist("Trash Boat", Reference.getUserName()));
|
||||
hopeless.add(Artist.getArtist("The Wonder Years", Reference.getUserName()));
|
||||
hopeless.add(Artist.getArtist("With Confidence", Reference.getUserName()));
|
||||
hopeless.add(Artist.getArtist("Trophy Eyes", Reference.getUserName()));
|
||||
hopeless.add(Artist.getArtist("Dryjacket", Reference.getUserName()));
|
||||
hopeless.add(Artist.getArtist("Yellowcard", Reference.getUserName()));
|
||||
|
||||
return hopeless;
|
||||
}
|
||||
|
||||
public static FMObjList getTDE() {
|
||||
FMObjList tde = new FMObjList("TDE");
|
||||
|
||||
tde.add(Artist.getArtist("Kendrick Lamar", Reference.getUserName()));
|
||||
tde.add(Artist.getArtist("Jay Rock", Reference.getUserName()));
|
||||
tde.add(Artist.getArtist("ScHoolboy Q", Reference.getUserName()));
|
||||
tde.add(Artist.getArtist("Ab-Soul", Reference.getUserName()));
|
||||
tde.add(Artist.getArtist("Black Hippy", Reference.getUserName()));
|
||||
tde.add(Artist.getArtist("Isaiah Rashad", Reference.getUserName()));
|
||||
tde.add(Artist.getArtist("SZA", Reference.getUserName()));
|
||||
tde.add(Artist.getArtist("Sir", Reference.getUserName()));
|
||||
|
||||
return tde;
|
||||
}
|
||||
|
||||
public static FMObjList getBB() {
|
||||
FMObjList bphq = new FMObjList("British Rock");
|
||||
|
||||
bphq.add(Artist.getArtist("Deaf Havana", Reference.getUserName()));
|
||||
bphq.add(Artist.getArtist("Lower Than Atlantis", Reference.getUserName()));
|
||||
bphq.add(Artist.getArtist("Mallory Knox", Reference.getUserName()));
|
||||
bphq.add(Artist.getArtist("Don Broco", Reference.getUserName()));
|
||||
bphq.add(Artist.getArtist("Moose Blood", Reference.getUserName()));
|
||||
bphq.add(Artist.getArtist("Young Guns", Reference.getUserName()));
|
||||
|
||||
return bphq;
|
||||
}
|
||||
|
||||
public static FMObjList getDre() {
|
||||
FMObjList dre = new FMObjList("Dre");
|
||||
|
||||
dre.add(Artist.getArtist("N.W.A", Reference.getUserName()));
|
||||
// dre.add(Album.getAlbum("Straight Outta Compton", "N.W.A", Reference.getUserName()));
|
||||
// dre.add(Album.getAlbum("Doggystyle", "Snoop Dogg", Reference.getUserName()));
|
||||
dre.add(Artist.getArtist("Dr. Dre", Reference.getUserName()));
|
||||
dre.add(Artist.getArtist("Snoop Dogg", Reference.getUserName()));
|
||||
dre.add(Artist.getArtist("Eminem", Reference.getUserName()));
|
||||
|
||||
return dre;
|
||||
}
|
||||
|
||||
public static FMObjList getWu() {
|
||||
FMObjList wu = new FMObjList("Wu-Tang Clan");
|
||||
|
||||
wu.add(Artist.getArtist("Wu-Tang Clan", Reference.getUserName()));
|
||||
wu.add(Artist.getArtist("GZA/Genius", Reference.getUserName()));
|
||||
wu.add(Artist.getArtist("Ol' Dirty Bastard", Reference.getUserName()));
|
||||
wu.add(Artist.getArtist("Ghostface Killah", Reference.getUserName()));
|
||||
wu.add(Artist.getArtist("Method Man", Reference.getUserName()));
|
||||
wu.add(Artist.getArtist("Raekwon", Reference.getUserName()));
|
||||
|
||||
return wu;
|
||||
}
|
||||
|
||||
public static FMObjList getEmoTrio() {
|
||||
FMObjList emoTrio = new FMObjList("Classic Emo Trio");
|
||||
|
||||
emoTrio.add(Artist.getArtist("My Chemical Romance", Reference.getUserName()));
|
||||
emoTrio.add(Artist.getArtist("Fall Out Boy", Reference.getUserName()));
|
||||
emoTrio.add(Artist.getArtist("Panic! at the Disco", Reference.getUserName()));
|
||||
|
||||
return emoTrio;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user