-
Notifications
You must be signed in to change notification settings - Fork 0
/
FeaturedSave.java
47 lines (41 loc) · 1.39 KB
/
FeaturedSave.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package advisor;
import com.google.gson.JsonObject;
import java.util.ArrayList;
import static advisor.View.printPage;
public class FeaturedSave implements SaveMusic {
private final String title;
protected String out;
private static int countNew;
FeaturedSave() {
title = "Category: Featured Songs";
out = "";
}
@Override
public String writeToText(JsonObject json) {
StringBuilder output = new StringBuilder();
if (countNew > 0){
output.append(title).append(" ").append(countNew).append("\n").append("\n");
}
else{
output.append(title).append("\n").append("\n");
}
var playlists = json.get("playlists").getAsJsonObject();
playlists.get("items").getAsJsonArray().forEach(item -> {
var playlist = item.getAsJsonObject();
var name = playlist.get("name").getAsString();
var url = playlist.get("external_urls").getAsJsonObject().get("spotify").getAsString();
output.append(name).append("\n");
output.append(url).append("\n").append("\n");
});
out = output.toString();
return output.toString();
}
@Override
public String returnOutput() {
return out;
}
@Override
public void accept(Visitor visit) {
visit.visit(this);
}
}