0

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!

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
beastlyCoder
  • 2,349
  • 4
  • 25
  • 52
  • hmm https://www.c895.org/playlist/ ? – Peter Samokhin Mar 10 '19 at 18:46
  • yes, i understand that is where the playlist is held, but I'm not sure how I should go about implementing that in my application. Should i try and find where it is being loaded in the backend, or just load the data from that page – beastlyCoder Mar 10 '19 at 18:47
  • I think that using a private API that you can find with Google Developer Tools is not a good idea. You can simply parse this page — and this would be OK, I think. – Peter Samokhin Mar 10 '19 at 18:49
  • Alright sounds good, do you have any links you could direct me in doing this? If not, I'll just search it myself :) thank you – beastlyCoder Mar 10 '19 at 18:49

1 Answers1

1

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.

Peter Samokhin
  • 864
  • 1
  • 9
  • 19