您的播放列表可在此处获得:https ://www.c895.org/playlist/
我认为页面的解析比使用私有 API 更好。为此,您可以使用JSOUP。
本站示例:
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));
在哪里TrackInfo
:
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;
}
}
因此,您可以找到在任何时间间隔播放的歌曲。