I am trying to implement a radio app for the following website: http://www.c895.org/mp3/
The website uses the SGPlayer to display the artist, and song names. I am able to retrieve that information, but I am unable to find where I can access the previously played tracks.
I've gone through with Google Developer tools in Chrome to try and find API links, or JSON data, but I was unable to find where that playlist information was held.
Should I keep looking for the data, or instead implement in my Android Application a way to feed in the data based on what is being displayed on the website?
I thought about using AsyncTasks to efficiently load the data through the backend.
Any ideas, thoughts, and opinions are of great help!
Your playlists are available there: https://www.c895.org/playlist/
I think the parsing of the page is better than using private APIs. For this, you can use JSOUP.
Example for this site:
String url = "https://www.c895.org/playlist/";
Document document = Jsoup.connect(url).get();
Element playlist = document.select("#playlist").first();
List<TrackInfo> tracks = new ArrayList<>();
for (Element track : playlist.children()) {
long time = Long.parseLong(track.dataset().get("ts"));
String title = track.select(".title").first().text();
String artist = track.select(".artist").first().text();
// `time * 1000` because `java.util.Date` requires milliseconds
// but `time` (`data-ts`) is a count of seconds
tracks.add(new TrackInfo(new Date(time * 1000), title, artist));
}
// example output:
// TrackInfo{date=Sun Mar 10 22:06:58 MSK 2019, title='Grapevine', artist='Tiësto'}
System.out.println(tracks.get(0));
Where TrackInfo
is:
class TrackInfo {
private Date date;
private String title, artist;
public TrackInfo(Date date, String title, String artist) {
this.date = date;
this.title = title;
this.artist = artist;
}
@Override
public String toString() {
return "TrackInfo{" +
"date=" + date +
", title='" + title + '\'' +
", artist='" + artist + '\'' +
'}';
}
public Date getDate() {
return date;
}
public void setDate(Date date) {
this.date = date;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getArtist() {
return artist;
}
public void setArtist(String artist) {
this.artist = artist;
}
}
So you can find a song that played at any time interval.