|
| 1 | +import com.github.philippheuer.credentialmanager.domain.OAuth2Credential; |
| 2 | +import com.github.twitch4j.ITwitchClient; |
| 3 | +import com.github.twitch4j.TwitchClientBuilder; |
| 4 | +import com.github.twitch4j.helix.domain.UserList; |
| 5 | + |
| 6 | +import java.time.LocalDate; |
| 7 | +import java.time.ZoneId; |
| 8 | +import java.util.*; |
| 9 | + |
| 10 | +public class asjordi { |
| 11 | + |
| 12 | + static String clientId = ""; |
| 13 | + static String accessToken = ""; |
| 14 | + |
| 15 | + static ITwitchClient twitchClient = TwitchClientBuilder.builder() |
| 16 | + .withDefaultAuthToken(new OAuth2Credential(clientId, accessToken)) |
| 17 | + .withEnableHelix(true) |
| 18 | + .build(); |
| 19 | + |
| 20 | + public static void main(String[] args) { |
| 21 | + List<Streamer> streamers = getStreamers(); |
| 22 | + |
| 23 | + streamers.forEach(streamer -> streamer.setFollowers(getTotalFollowers(String.valueOf(streamer.getId())))); |
| 24 | + |
| 25 | + // sort by followers |
| 26 | + streamers.sort(Comparator.comparing(Streamer::getFollowers).reversed()); |
| 27 | + System.out.println("Ranking by followers:"); |
| 28 | + streamers.forEach(streamer -> System.out.println(streamer.getDisplayName() + " has " + streamer.getFollowers() + " followers")); |
| 29 | + |
| 30 | + // sort by joined date |
| 31 | + streamers.sort(Comparator.comparing(Streamer::getJoined)); |
| 32 | + System.out.println("Ranking by joined date:"); |
| 33 | + streamers.forEach(streamer -> System.out.println(streamer.getDisplayName() + " joined on " + streamer.getJoined())); |
| 34 | + } |
| 35 | + |
| 36 | + public static List<Streamer> getStreamers() { |
| 37 | + List<String> streamerNames = Arrays.asList( |
| 38 | + "littleragergirl", "ache", "adricontreras4", "agustin51", "alexby11", "ampeterby7", "tvander", "arigameplays", "arigeli_", "auronplay", |
| 39 | + "axozer", "beniju03", "bycalitos", "byviruzz", "carreraaa", "celopan", "srcheeto", "crystalmolly", "darioemehache", "dheylo", |
| 40 | + "djmariio", "doble", "elvisayomastercard", "elyas360", "folagorlives", "thegrefg", "guanyar", "hika", "hiperop", "ibai", |
| 41 | + "ibelky_", "illojuan", "imantado", "irinaisasia", "jesskiu", "jopa", "jordiwild", "kenaivsouza", "mrkeroro10", "thekiddkeo95", |
| 42 | + "kikorivera", "knekro", "a_big_koko", "kronnozomberoficial", "leviathan", "litkillah", "lolalolita", "lolitofdez", "luh", "luzu", |
| 43 | + "mangel", "mayichi", "melo", "missasinfonia", "mixwell", "jaggerprincesa", "nategentile7", "nexxuz", "lakshartnia", "nilojeda", |
| 44 | + "nissaxter", "olliegamerz", "orslok", "outconsumer", "papigavitv", "paracetamor", "patica1999", "paulagonu", "pausenpaii", "perxitaa", |
| 45 | + "nosoyplex", "polispol1", "quackity", "recuerd0p", "reventxz", "rivers_gg", "robertpg", "roier", "rojuu", "rubius", |
| 46 | + "shadoune666", "silithur", "spok_sponha", "elspreen", "spursito", "bystaxx", "suzyroxx", "vicens", "vitu", "werlyb", |
| 47 | + "xavi", "xcry", "elxokas", "thezarcort", "zeling", "zormanworld" |
| 48 | + ); |
| 49 | + |
| 50 | + List<Streamer> streamers = new LinkedList<>(); |
| 51 | + |
| 52 | + UserList resultList = twitchClient.getHelix().getUsers(null, null, streamerNames).execute(); |
| 53 | + resultList.getUsers().forEach(user -> streamers.add(new Streamer(Long.parseLong(user.getId()), user.getLogin(), user.getDisplayName(), user.getCreatedAt().atZone(ZoneId.systemDefault()).toLocalDate()))); |
| 54 | + |
| 55 | + return streamers; |
| 56 | + } |
| 57 | + |
| 58 | + public static int getTotalFollowers(String id) { |
| 59 | + var followers = twitchClient.getHelix().getChannelFollowers(accessToken, id, null, 100, null).execute(); |
| 60 | + return followers.getTotal(); |
| 61 | + } |
| 62 | + |
| 63 | + static class Streamer { |
| 64 | + private long id; |
| 65 | + private String login; |
| 66 | + private String displayName; |
| 67 | + private int followers; |
| 68 | + private LocalDate joined; |
| 69 | + |
| 70 | + public Streamer(long id, String login, String displayName, LocalDate joined) { |
| 71 | + this.id = id; |
| 72 | + this.login = login; |
| 73 | + this.displayName = displayName; |
| 74 | + this.joined = joined; |
| 75 | + } |
| 76 | + |
| 77 | + public long getId() { |
| 78 | + return id; |
| 79 | + } |
| 80 | + |
| 81 | + public String getLogin() { |
| 82 | + return login; |
| 83 | + } |
| 84 | + |
| 85 | + public String getDisplayName() { |
| 86 | + return displayName; |
| 87 | + } |
| 88 | + |
| 89 | + public int getFollowers() { |
| 90 | + return followers; |
| 91 | + } |
| 92 | + |
| 93 | + public LocalDate getJoined() { |
| 94 | + return joined; |
| 95 | + } |
| 96 | + |
| 97 | + public void setFollowers(int followers) { |
| 98 | + this.followers = followers; |
| 99 | + } |
| 100 | + |
| 101 | + @Override |
| 102 | + public String toString() { |
| 103 | + return new StringJoiner(", ", Streamer.class.getSimpleName() + "[", "]") |
| 104 | + .add("id=" + id) |
| 105 | + .add("login='" + login + "'") |
| 106 | + .add("displayName='" + displayName + "'") |
| 107 | + .add("followers=" + followers) |
| 108 | + .add("joined=" + joined) |
| 109 | + .toString(); |
| 110 | + } |
| 111 | + } |
| 112 | +} |
0 commit comments