diff --git a/fmframework/src/sarsoo/fmframework/music/Album.java b/fmframework/src/sarsoo/fmframework/music/Album.java index a5741cc..85089b2 100644 --- a/fmframework/src/sarsoo/fmframework/music/Album.java +++ b/fmframework/src/sarsoo/fmframework/music/Album.java @@ -2,6 +2,11 @@ package sarsoo.fmframework.music; import java.util.ArrayList; +import org.w3c.dom.Document; + +import sarsoo.fmframework.net.Network; +import sarsoo.fmframework.parser.Parser; + public class Album extends FMObj{ protected Artist artist; protected ArrayList tagList; @@ -22,4 +27,11 @@ public class Album extends FMObj{ } + public static Album getAlbum(String name, String artist, String username) { + String url = Network.getAlbumInfoUrl(name, artist, username); + Document response = Network.getResponse(url); + Album album = Parser.parseAlbum(response); + return album; + } + } diff --git a/fmframework/src/sarsoo/fmframework/music/Artist.java b/fmframework/src/sarsoo/fmframework/music/Artist.java index 70671ea..6b1b38b 100644 --- a/fmframework/src/sarsoo/fmframework/music/Artist.java +++ b/fmframework/src/sarsoo/fmframework/music/Artist.java @@ -2,6 +2,11 @@ package sarsoo.fmframework.music; import java.util.ArrayList; +import org.w3c.dom.Document; + +import sarsoo.fmframework.net.Network; +import sarsoo.fmframework.parser.Parser; + public class Artist extends FMObj{ protected boolean streamable; protected boolean onTour; @@ -14,7 +19,18 @@ public class Artist extends FMObj{ super(name, null, null, 0, 0, 0, null); } + public Artist(String name, String url, String mbid, int listeners, int playCount, int userPlayCount, boolean streamable, boolean onTour, Wiki wiki) { + super(name, url, mbid, listeners, playCount, userPlayCount, wiki); + } + public String toString() { return name; } + + public static Artist getArtist(String name, String username) { + String url = Network.getArtistInfoUrl(name, username); + Document response = Network.getResponse(url); + Artist artist = Parser.parseArtist(response); + return artist; + } } diff --git a/fmframework/src/sarsoo/fmframework/music/Track.java b/fmframework/src/sarsoo/fmframework/music/Track.java index 7138188..12efc13 100644 --- a/fmframework/src/sarsoo/fmframework/music/Track.java +++ b/fmframework/src/sarsoo/fmframework/music/Track.java @@ -2,6 +2,11 @@ package sarsoo.fmframework.music; import java.util.ArrayList; +import org.w3c.dom.Document; + +import sarsoo.fmframework.net.Network; +import sarsoo.fmframework.parser.Parser; + public class Track extends FMObj{ protected Album album; protected Artist artist; @@ -15,4 +20,15 @@ public class Track extends FMObj{ super(name, null, null, 0, 0, 0, null); this.artist = new Artist(artist); } + + public Track(String name, String url, String mbid, int listeners, int playCount, int userPlayCount, Wiki wiki) { + super(name, url, mbid, listeners, playCount, userPlayCount, wiki); + } + + public static Track getTrack(String name, String artist, String username) { + String url = Network.getTrackInfoUrl(name, artist, username); + Document response = Network.getResponse(url); + Track track = Parser.parseTrack(response); + return track; + } } diff --git a/fmframework/src/sarsoo/fmframework/parser/Parser.java b/fmframework/src/sarsoo/fmframework/parser/Parser.java index 7f352e4..33b30b7 100644 --- a/fmframework/src/sarsoo/fmframework/parser/Parser.java +++ b/fmframework/src/sarsoo/fmframework/parser/Parser.java @@ -6,6 +6,7 @@ import org.w3c.dom.NodeList; import sarsoo.fmframework.music.Album; import sarsoo.fmframework.music.Artist; +import sarsoo.fmframework.music.Track; import sarsoo.fmframework.music.Wiki; public class Parser { @@ -19,17 +20,35 @@ public class Parser { 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()); - - + +// Node trackListNode = doc.getElementsByTagName("tracks").item(0); +// NodeList trackNodeList = trackListNode.getChildNodes(); +// if (trackListNode != null) { +// int counter = 0; +// while (trackNodeList.item(counter) != null) { +// Node track = trackNodeList.item(counter); +// //System.out.println(track.getTextContent()); +// String trackName = track.getFirstChild().getTextContent(); +// String trackUrl = track.getFirstChild().getNextSibling().getNextSibling().getTextContent(); +// //String trackDuration = track.getFirstChild().getNextSibling().getNextSibling().getNextSibling().getNextSibling().getTextContent(); +// int trackNumber = Integer.parseInt(track.getAttributes().getNamedItem("rank").getNodeValue()); +// // String trackName = +// // trackListNode.getFirstChild().getFirstChild().getTextContent(); +// // String trackUrl = trackListNode.getNextSibling().getTextContent(); +// System.out.println(trackUrl); +// counter++; +// } +// } + Node wikiNode = doc.getElementsByTagName("wiki").item(0); String published = wikiNode.getFirstChild().getTextContent(); String summary = wikiNode.getFirstChild().getNextSibling().getTextContent(); String content = wikiNode.getFirstChild().getNextSibling().getNextSibling().getTextContent(); - - //System.out.println(published); - //System.out.println(summary); - //System.out.println(content); - + + // System.out.println(published); + // System.out.println(summary); + // System.out.println(content); + Artist artistObj = new Artist(artist); Wiki wiki = new Wiki(); @@ -38,37 +57,38 @@ public class Parser { } - public static Album parseArtist(Document doc) { + public static Artist parseArtist(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(); + String streamable = doc.getElementsByTagName("streamable").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()); + + //System.out.println(listeners); - Artist artistObj = new Artist(artist); - - Album album = new Album(name, url, mbid, artistObj, listeners, playCount, userPlayCount, null); - return album; - + Artist artist = new Artist(name, url, mbid, listeners, playCount, userPlayCount, false, false, null); + return artist; } - public static Album parseTrack(Document doc) { + public static Track parseTrack(Document doc) { String name = doc.getElementsByTagName("name").item(0).getTextContent(); - String artist = doc.getElementsByTagName("artist").item(0).getTextContent(); + String artistName = doc.getElementsByTagName("artist").item(0).getFirstChild().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); + Artist artistObj = new Artist(artistName); + +// System.out.println(userPlayCount); - Album album = new Album(name, url, mbid, artistObj, listeners, playCount, userPlayCount, null); - return album; + Track track = new Track(name, url, mbid, listeners, playCount, userPlayCount, null); + return track; } } diff --git a/fmframework/src/sarsoo/fmframework/test/NetworkTest.java b/fmframework/src/sarsoo/fmframework/test/NetworkTest.java index e494920..826c0d9 100644 --- a/fmframework/src/sarsoo/fmframework/test/NetworkTest.java +++ b/fmframework/src/sarsoo/fmframework/test/NetworkTest.java @@ -8,6 +8,8 @@ import org.junit.jupiter.api.Test; import org.w3c.dom.Document; import sarsoo.fmframework.music.Album; +import sarsoo.fmframework.music.Artist; +import sarsoo.fmframework.music.Track; import sarsoo.fmframework.net.Network; import sarsoo.fmframework.net.TestCall; import sarsoo.fmframework.parser.AlbumParser; @@ -25,7 +27,23 @@ class NetworkTest { String url = Network.getAlbumInfoUrl("The Wall", "Pink Floyd", "Sarsoo"); Document response = Network.getResponse(url); Album album = Parser.parseAlbum(response); - System.out.println(album); + //System.out.println(album); + } + + @Test + void testArtist() { + String url = Network.getArtistInfoUrl("Pink Floyd", "sarsoo"); + Document response = Network.getResponse(url); + Artist artist = Parser.parseArtist(response); + //System.out.println(album); + } + + @Test + void testTrack() { + String url = Network.getTrackInfoUrl("Business", "Eminem", "sarsoo"); + Document response = Network.getResponse(url); + Track track = Parser.parseTrack(response); + //System.out.println(album); } @Test