|
| 1 | +package com.github.connyscode.ctils.jTrack; |
| 2 | + |
| 3 | +import com.github.connyscode.ctils.jTrack.backend.GeniusAPI; |
| 4 | +import org.json.simple.JSONArray; |
| 5 | +import org.json.simple.JSONObject; |
| 6 | + |
| 7 | +import java.lang.reflect.Array; |
| 8 | +import java.util.ArrayList; |
| 9 | +import java.util.List; |
| 10 | + |
| 11 | +import static com.github.connyscode.ctils.jTrack.backend.Messaging.error; |
| 12 | + |
| 13 | +public class Artist { |
| 14 | + |
| 15 | + private String artistName = "", artistUrl = "https://genius.com/", artistHeaderImageUrl = "https://genius.com/", artistImageUrl = "https://genius.com/", artistDescription = ""; |
| 16 | + private long artistID = 0, artistFollowers = 0; |
| 17 | + private List<String> alternateNames = new ArrayList<>(); |
| 18 | + private boolean artistVerified = false; |
| 19 | + |
| 20 | + /** |
| 21 | + * Create a Track |
| 22 | + * |
| 23 | + * @param trackObject song response from genius |
| 24 | + * @see Artist |
| 25 | + */ |
| 26 | + public Artist(JSONObject trackObject) { |
| 27 | + try { |
| 28 | + JSONObject artist = trackObject; |
| 29 | + |
| 30 | + // Artist |
| 31 | + artistName = (String) artist.get("name"); |
| 32 | + artistUrl = (String) artist.get("url"); |
| 33 | + artistHeaderImageUrl = (String) artist.get("header_image_url"); |
| 34 | + artistImageUrl = (String) artist.get("image_url"); |
| 35 | + artistID = (long) artist.get("id"); |
| 36 | + artistVerified = (boolean) artist.get("is_verified"); |
| 37 | + if (artist.get("description") != null) |
| 38 | + artistDescription = (String) ((JSONObject) artist.get("description")).get("plain"); |
| 39 | + artistFollowers = (long) artist.get("followers_count"); |
| 40 | + |
| 41 | + JSONArray alts = (JSONArray) artist.get("alternate_names"); |
| 42 | + for(int i = 0; i < alts.size(); i++){ |
| 43 | + alternateNames.add((String) alts.get(i)); |
| 44 | + } |
| 45 | + } catch (Exception e) { |
| 46 | + e.printStackTrace(); |
| 47 | + error("t01", "Could not read complete Track data!"); |
| 48 | + } |
| 49 | + } |
| 50 | + |
| 51 | + /** |
| 52 | + * @return The name of the Artist |
| 53 | + */ |
| 54 | + public String artistName() { |
| 55 | + return this.artistName; |
| 56 | + } |
| 57 | + |
| 58 | + /** |
| 59 | + * @return The artist's Header as an URL<br>(Mostly same as Track.artistImageUrl()) |
| 60 | + */ |
| 61 | + public String artistHeaderImageUrl() { |
| 62 | + return this.artistHeaderImageUrl; |
| 63 | + } |
| 64 | + |
| 65 | + /** |
| 66 | + * @return The artist's Profile Picture as an URL |
| 67 | + */ |
| 68 | + public String artistImageUrl() { |
| 69 | + return this.artistImageUrl; |
| 70 | + } |
| 71 | + |
| 72 | + /** |
| 73 | + * @return The artist's Genius URL |
| 74 | + */ |
| 75 | + public String artistUrl() { |
| 76 | + return this.artistUrl; |
| 77 | + } |
| 78 | + |
| 79 | + /** |
| 80 | + * @return The artist's Description |
| 81 | + */ |
| 82 | + public String artistDescription() { |
| 83 | + return this.artistDescription; |
| 84 | + } |
| 85 | + |
| 86 | + /** |
| 87 | + * @return The artist's follower count |
| 88 | + */ |
| 89 | + public long artistFollowers() { |
| 90 | + return this.artistFollowers; |
| 91 | + } |
| 92 | + |
| 93 | + /** |
| 94 | + * @return The artist's alternate Names |
| 95 | + */ |
| 96 | + public List<String> alternateNames() { |
| 97 | + return this.alternateNames; |
| 98 | + } |
| 99 | + |
| 100 | + /** |
| 101 | + * @return The artist's Genius URL |
| 102 | + */ |
| 103 | + public long artistGID() { |
| 104 | + return this.artistID; |
| 105 | + } |
| 106 | + |
| 107 | + /** |
| 108 | + * @return Is Artist verified |
| 109 | + */ |
| 110 | + public boolean artistVerified() { |
| 111 | + return this.artistVerified; |
| 112 | + } |
| 113 | + ///* MISC */// |
| 114 | + |
| 115 | +} |
0 commit comments