diff options
| -rw-r--r-- | src/main/java/App.java | 43 | ||||
| -rw-r--r-- | src/main/java/com/pina/Holodex.java | 118 | ||||
| -rw-r--r-- | src/main/java/com/pina/HolodexException.java | 11 | ||||
| -rw-r--r-- | src/main/java/com/pina/HolodexService.java | 92 | ||||
| -rw-r--r-- | src/main/java/com/pina/datatypes/Channel.java | 18 | ||||
| -rw-r--r-- | src/main/java/com/pina/datatypes/Comment.java | 7 | ||||
| -rw-r--r-- | src/main/java/com/pina/datatypes/SimpleChannel.java | 13 | ||||
| -rw-r--r-- | src/main/java/com/pina/datatypes/SimpleVideo.java | 23 | ||||
| -rw-r--r-- | src/main/java/com/pina/datatypes/Video.java | 21 | ||||
| -rw-r--r-- | src/main/java/com/pina/query/ChannelQueryBuilder.java | 79 | ||||
| -rw-r--r-- | src/main/java/com/pina/query/VideoByVideoIdQueryBuilder.java | 40 | ||||
| -rw-r--r-- | src/main/java/com/pina/query/VideoQueryBuilder.java | 158 | ||||
| -rw-r--r-- | src/main/java/com/pina/query/VideosByChannelIDQueryBuilder.java | 78 |
13 files changed, 0 insertions, 701 deletions
diff --git a/src/main/java/App.java b/src/main/java/App.java deleted file mode 100644 index 383d9b5..0000000 --- a/src/main/java/App.java +++ /dev/null @@ -1,43 +0,0 @@ -import com.pina.Holodex; -import com.pina.HolodexException; -import com.pina.datatypes.Channel; -import com.pina.datatypes.SimpleVideo; -import com.pina.datatypes.Video; -import com.pina.query.ChannelQueryBuilder; -import com.pina.query.VideoByVideoIdQueryBuilder; -import com.pina.query.VideoQueryBuilder; - -import java.util.List; - -public class App -{ - public static void main( String[] args ) - { - try { - Holodex holodex = new Holodex("YOUR_API_KEY_HERE"); - Channel channel = holodex.getChannel("UC4WvIIAo89_AzGUh1AZ6Dkg"); - System.out.println(channel.name + " is a member of " + channel.org + " and has " + channel.suborg + " as a suborg"); - - VideoQueryBuilder liveVideoQuery = new VideoQueryBuilder().setStatus("live").setOrg("Hololive"); - List<SimpleVideo> currentlyLiveVideos = holodex.getLiveAndUpcomingVideos(liveVideoQuery); - System.out.println("Currently there are " + currentlyLiveVideos.size() + " livestreams on going in Hololive"); - - for (SimpleVideo video : currentlyLiveVideos) { - System.out.println(video.channel.name + " is currently live with " + video.live_viewers + " views"); - } - - ChannelQueryBuilder channelQuery = new ChannelQueryBuilder(); - channelQuery.setOrg("Nijisanji"); - channelQuery.setLimit(75); - List<Channel> nijisanjiMembers = holodex.getChannels(channelQuery); - - Video anotherVideo = holodex.getVideo(new VideoByVideoIdQueryBuilder().setVideoId("9-O_IWM3184").setLang("en")); - System.out.println(anotherVideo.channel.name + " uploaded a video titled " + anotherVideo.title + - " on " + anotherVideo.published_at); - } catch (HolodexException ex) { - throw new RuntimeException(ex); - } - - } - -} diff --git a/src/main/java/com/pina/Holodex.java b/src/main/java/com/pina/Holodex.java deleted file mode 100644 index 931021f..0000000 --- a/src/main/java/com/pina/Holodex.java +++ /dev/null @@ -1,118 +0,0 @@ -package com.pina; - -import com.pina.datatypes.Channel; -import com.pina.datatypes.SimpleVideo; -import com.pina.datatypes.Video; -import com.pina.query.ChannelQueryBuilder; -import com.pina.query.VideoByVideoIdQueryBuilder; -import com.pina.query.VideoQueryBuilder; -import com.pina.query.VideosByChannelIDQueryBuilder; -import okhttp3.OkHttpClient; -import okhttp3.Request; -import retrofit2.Call; -import retrofit2.Response; -import retrofit2.Retrofit; -import retrofit2.converter.jackson.JacksonConverterFactory; - -import java.io.IOException; -import java.util.List; - -public class Holodex { - private HolodexService service; - - public Holodex(String apiKey) { - initializeHolodexService(apiKey, "https://holodex.net"); - } - - public Holodex(String apiKey, String baseUrl) { - // purely for unit testing - initializeHolodexService(apiKey, baseUrl); - } - - private void initializeHolodexService(String apiKey, String baseUrl){ - OkHttpClient.Builder httpClient = new OkHttpClient.Builder(); - httpClient.addInterceptor(chain -> { - Request original = chain.request(); - Request request = original.newBuilder() - .header("X-APIKEY", apiKey) - .method(original.method(), original.body()) - .build(); - return chain.proceed(request); - }); - Retrofit retrofit = new Retrofit.Builder() - .baseUrl(baseUrl) - .addConverterFactory(JacksonConverterFactory.create()) - .client(httpClient.build()) - .build(); - service = retrofit.create(HolodexService.class); - } - - public List<SimpleVideo> getLiveAndUpcomingVideos(VideoQueryBuilder queryBuilder) throws HolodexException { - Call<List<SimpleVideo>> call = service.getLiveVideos(queryBuilder.getChannelId(), queryBuilder.getId(), - queryBuilder.getInclude(), queryBuilder.getLang(), - queryBuilder.getLimit(), queryBuilder.getMaxUpcomingHours(), - queryBuilder.getMentionedChannelId(), queryBuilder.getOffset(), - queryBuilder.getOrder(), queryBuilder.getOrg(), - queryBuilder.getPaginated(), queryBuilder.getSort(), - queryBuilder.getStatus(), queryBuilder.getTopic(), - queryBuilder.getType()); - return executeCall(call); - } - - public List<Video> getVideos(VideoQueryBuilder queryBuilder) throws HolodexException { - Call<List<Video>> call = service.getVideos(queryBuilder.getChannelId(), queryBuilder.getId(), - queryBuilder.getInclude(), queryBuilder.getLang(), - queryBuilder.getLimit(), queryBuilder.getMaxUpcomingHours(), - queryBuilder.getMentionedChannelId(), queryBuilder.getOffset(), - queryBuilder.getOrder(), queryBuilder.getOrg(), - queryBuilder.getPaginated(), queryBuilder.getSort(), - queryBuilder.getStatus(), queryBuilder.getTopic(), - queryBuilder.getType()); - return executeCall(call); - } - - public Channel getChannel(String channelId) throws HolodexException { - Call<Channel> call = service.getChannel(channelId); - return executeCall(call); - } - - public List<Video> getVideosByChannelId(VideosByChannelIDQueryBuilder query) throws HolodexException { - Call<List<Video>> call = service.getVideosByChannelId(query.getChannelId(), query.getType(), query.getInclude(), - query.getLang(), query.getLimit(), query.getOffset(), query.getPaginated()); - return executeCall(call); - - } - - public List<Video> getVideosFromChannels(String[] channels) throws HolodexException{ - String channelsString = String.join(",", channels); - Call<List<Video>> call = service.getVideosFromChannels(channelsString); - return executeCall(call); - } - - public Video getVideo(VideoByVideoIdQueryBuilder query) throws HolodexException { - Call<Video> call = service.getVideo(query.getVideoId(), query.getLang(), query.getC()); - return executeCall(call); - } - - public List<Channel> getChannels(ChannelQueryBuilder query) throws HolodexException{ - Call<List<Channel>> call = service.getChannels(query.getLimit(), query.getOffset(), query.getType(), - query.getLang(), query.getOrder(), query.getOrg(), query.getSort() - ); - return executeCall(call); - } - - - private <T> T executeCall(Call<T> call) throws HolodexException { - try { - Response<T> response = call.execute(); - if (response.isSuccessful()) { - return response.body(); - } else { - throw new HolodexException("API returned error: " + response.code()); - } - } catch (IOException e) { - System.out.println(e); - throw new HolodexException("Failed to execute API call", e); - } - } -} diff --git a/src/main/java/com/pina/HolodexException.java b/src/main/java/com/pina/HolodexException.java deleted file mode 100644 index 8dc8cbd..0000000 --- a/src/main/java/com/pina/HolodexException.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.pina; - -public class HolodexException extends Exception{ - public HolodexException(String message) { - super(message); - } - - public HolodexException(String message, Throwable cause) { - super(message, cause); - } -} diff --git a/src/main/java/com/pina/HolodexService.java b/src/main/java/com/pina/HolodexService.java deleted file mode 100644 index fa2af85..0000000 --- a/src/main/java/com/pina/HolodexService.java +++ /dev/null @@ -1,92 +0,0 @@ -package com.pina; - -import com.pina.datatypes.Channel; -import com.pina.datatypes.SimpleVideo; -import com.pina.datatypes.Video; -import retrofit2.Call; -import retrofit2.http.GET; -import retrofit2.http.Path; -import retrofit2.http.Query; - -import java.util.List; - -public interface HolodexService { - @GET("/api/v2/live") - Call<List<SimpleVideo>> getLiveVideos( - @Query("channel_id") String channel_id, - @Query("id") String id, - @Query("include") String include, - @Query("lang") String lang, - @Query("limit") Integer limit, - @Query("maxUpcomingHours") Integer maxUpcomingHours, - @Query("mentioned_channel_id") String mentioned_channel_id, - @Query("offset") Integer offset, - @Query("order") String order, - @Query("org") String org, - @Query("paginated") String paginated, - @Query("sort") String sort, - @Query("status") String status, - @Query("topic") String topic, - @Query("type") String type - ); - - @GET("/api/v2/videos") - Call<List<Video>> getVideos( - @Query("channel_id") String channel_id, - @Query("id") String id, - @Query("include") String include, - @Query("lang") String lang, - @Query("limit") Integer limit, - @Query("max_upcoming_hours") Integer max_upcoming_hours, - @Query("mentioned_channel_id") String mentioned_channel_id, - @Query("offset") Integer offset, - @Query("order") String order, - @Query("org") String org, - @Query("paginated") String paginated, - @Query("sort") String sort, - @Query("status") String status, - @Query("topic") String topic, - @Query("type") String type - ); - - @GET("/api/v2/channels/{channelID}") - Call<Channel> getChannel( - @Path("channelID") String channelID - ); - - @GET("/api/v2/channels/{channelID}/{type}") - Call<List<Video>> getVideosByChannelId( - @Path("channelID") String channelID, - @Path("type") String type, - @Query("include") String include, - @Query("lang") String lang, - @Query("limit") Integer limit, - @Query("offset") Integer offset, - @Query("paginated") String paginated - ); - - @GET("/api/v2/users/live") - Call<List<Video>> getVideosFromChannels( - @Query("channels") String channels - ); - - @GET("/api/v2/videos/{videoID}") - Call<Video> getVideo( - @Path("videoID") String videoID, - @Query("lang") String lang, - @Query("c") String c - ); - - @GET("/api/v2/channels") - Call<List<Channel>> getChannels( - @Query("limit") Integer limit, - @Query("offset") Integer offset, - @Query("type") String type, - @Query("lang") String lang, - @Query("order") String order, - @Query("org") String org, - @Query("sort") String sort - ); - -} - diff --git a/src/main/java/com/pina/datatypes/Channel.java b/src/main/java/com/pina/datatypes/Channel.java deleted file mode 100644 index cadfbc9..0000000 --- a/src/main/java/com/pina/datatypes/Channel.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.pina.datatypes; - -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; - -@JsonIgnoreProperties(ignoreUnknown = true) -public class Channel extends SimpleChannel{ - public String suborg; - public String banner; - public String twitter; - public String video_count; - public String subscriber_count; - public String view_count; - public String clip_count; - public String lang; - public String published_at; - public boolean inactive; - public String description; -} diff --git a/src/main/java/com/pina/datatypes/Comment.java b/src/main/java/com/pina/datatypes/Comment.java deleted file mode 100644 index cf52a1f..0000000 --- a/src/main/java/com/pina/datatypes/Comment.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.pina.datatypes; - -public class Comment { - public String comment_key; - public String video_id; - public String message; -} diff --git a/src/main/java/com/pina/datatypes/SimpleChannel.java b/src/main/java/com/pina/datatypes/SimpleChannel.java deleted file mode 100644 index c70a0be..0000000 --- a/src/main/java/com/pina/datatypes/SimpleChannel.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.pina.datatypes; - -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; - -@JsonIgnoreProperties(ignoreUnknown = true) -public class SimpleChannel { - public String id; - public String name; - public String english_name; - public String type; - public String photo; - public String org; -} diff --git a/src/main/java/com/pina/datatypes/SimpleVideo.java b/src/main/java/com/pina/datatypes/SimpleVideo.java deleted file mode 100644 index 1d30748..0000000 --- a/src/main/java/com/pina/datatypes/SimpleVideo.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.pina.datatypes; - -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; - -@JsonIgnoreProperties (ignoreUnknown = true) -public class SimpleVideo { - public String id; - public String title; - public String type; - public String topic_id; - public String published_at; - public String available_at; - public int duration; - public String status; - public String start_scheduled; - public String start_actual; - public String end_actual; - public int live_viewers; - public String description; - public int songcount; - public String channel_id; - public Channel channel; -} diff --git a/src/main/java/com/pina/datatypes/Video.java b/src/main/java/com/pina/datatypes/Video.java deleted file mode 100644 index 850dfb9..0000000 --- a/src/main/java/com/pina/datatypes/Video.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.pina.datatypes; - - -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; - -import java.util.List; - -@JsonIgnoreProperties(ignoreUnknown = true) -public class Video extends SimpleVideo { - public List<Video> clips; - public List<Video> sources; - public List<Video> refers; - public List<Video> simulcasts; - public List<SimpleChannel> mentions; - public String thumbnail; - public List<Video> reccomendations; - public List<Comment> comments; -} - - - diff --git a/src/main/java/com/pina/query/ChannelQueryBuilder.java b/src/main/java/com/pina/query/ChannelQueryBuilder.java deleted file mode 100644 index 1c51d68..0000000 --- a/src/main/java/com/pina/query/ChannelQueryBuilder.java +++ /dev/null @@ -1,79 +0,0 @@ -package com.pina.query; - -public class ChannelQueryBuilder { - /*** - * Used to get a set of channels matching the given parameters - */ - private Integer limit; - private Integer offset; - private String type; - private String lang; - private String order; - private String org; - private String sort; - - public Integer getLimit() { - return limit; - } - - public ChannelQueryBuilder setLimit(Integer limit) { - this.limit = limit; - return this; - } - - public Integer getOffset() { - return offset; - } - - public ChannelQueryBuilder setOffset(Integer offset) { - this.offset = offset; - return this; - } - - public String getType() { - return type; - } - - public ChannelQueryBuilder setType(String type) { - this.type = type; - return this; - } - - public String getLang() { - return lang; - } - - public ChannelQueryBuilder setLang(String lang) { - this.lang = lang; - return this; - } - - public String getOrder() { - return order; - } - - public ChannelQueryBuilder setOrder(String order) { - this.order = order; - return this; - } - - public String getOrg() { - return org; - } - - public ChannelQueryBuilder setOrg(String org) { - this.org = org; - return this; - } - - public String getSort() { - return sort; - } - - public ChannelQueryBuilder setSort(String sort) { - this.sort = sort; - return this; - } - - -} diff --git a/src/main/java/com/pina/query/VideoByVideoIdQueryBuilder.java b/src/main/java/com/pina/query/VideoByVideoIdQueryBuilder.java deleted file mode 100644 index b996028..0000000 --- a/src/main/java/com/pina/query/VideoByVideoIdQueryBuilder.java +++ /dev/null @@ -1,40 +0,0 @@ -package com.pina.query; - - -public class VideoByVideoIdQueryBuilder { - /*** - * Used to get the metadata of a single video when given the video ID - */ - private String videoId; - private String lang; - private String c; - - public String getVideoId() { - return videoId; - } - - public VideoByVideoIdQueryBuilder setVideoId(String videoId) { - this.videoId = videoId; - return this; - } - - public String getLang() { - return lang; - } - - public VideoByVideoIdQueryBuilder setLang(String lang) { - this.lang = lang; - return this; - } - - public String getC() { - return c; - } - - public VideoByVideoIdQueryBuilder setC(String c) { - this.c = c; - return this; - } - - -} diff --git a/src/main/java/com/pina/query/VideoQueryBuilder.java b/src/main/java/com/pina/query/VideoQueryBuilder.java deleted file mode 100644 index 67acd1b..0000000 --- a/src/main/java/com/pina/query/VideoQueryBuilder.java +++ /dev/null @@ -1,158 +0,0 @@ -package com.pina.query; - -public class VideoQueryBuilder { - /*** - * Query parameters for /api/v2/live and /api/v2/videos - * Query Live and Upcoming Videos - */ - private String channelId; - private String id; - private String include; - private String lang; - private Integer limit; - private Integer maxUpcomingHours; - private String mentionedChannelId; - private Integer offset; - private String order; - private String org; - private String paginated; - private String sort; - private String status; - private String topic; - private String type; - - public VideoQueryBuilder setChannelId(String channelId) { - this.channelId = channelId; - return this; - } - - public VideoQueryBuilder setId(String id) { - this.id = id; - return this; - } - - public VideoQueryBuilder setInclude(String include) { - this.include = include; - return this; - } - - public VideoQueryBuilder setLang(String lang) { - this.lang = lang; - return this; - } - - public VideoQueryBuilder setLimit(Integer limit) { - this.limit = limit; - return this; - } - - public VideoQueryBuilder setMaxUpcomingHours(Integer maxUpcomingHours) { - this.maxUpcomingHours = maxUpcomingHours; - return this; - } - - public VideoQueryBuilder setMentionedChannelId(String mentionedChannelId) { - this.mentionedChannelId = mentionedChannelId; - return this; - } - - public VideoQueryBuilder setOffset(Integer offset) { - this.offset = offset; - return this; - } - - public VideoQueryBuilder setOrder(String order) { - this.order = order; - return this; - } - - public VideoQueryBuilder setOrg(String org) { - this.org = org; - return this; - } - - public VideoQueryBuilder setPaginated(String paginated) { - this.paginated = paginated; - return this; - } - - public VideoQueryBuilder setSort(String sort) { - this.sort = sort; - return this; - } - - public VideoQueryBuilder setStatus(String status) { - this.status = status; - return this; - } - - public VideoQueryBuilder setTopic(String topic) { - this.topic = topic; - return this; - } - - public VideoQueryBuilder setType(String type) { - this.type = type; - return this; - } - - public String getChannelId() { - return channelId; - } - - public String getId() { - return id; - } - - public String getInclude() { - return include; - } - - public String getLang() { - return lang; - } - - public Integer getLimit() { - return limit; - } - - public Integer getMaxUpcomingHours() { - return maxUpcomingHours; - } - - public String getMentionedChannelId() { - return mentionedChannelId; - } - - public Integer getOffset() { - return offset; - } - - public String getOrder() { - return order; - } - - public String getOrg() { - return org; - } - - public String getPaginated() { - return paginated; - } - - public String getSort() { - return sort; - } - - public String getStatus() { - return status; - } - - public String getTopic() { - return topic; - } - - public String getType() { - return type; - } -}
\ No newline at end of file diff --git a/src/main/java/com/pina/query/VideosByChannelIDQueryBuilder.java b/src/main/java/com/pina/query/VideosByChannelIDQueryBuilder.java deleted file mode 100644 index 0ba9963..0000000 --- a/src/main/java/com/pina/query/VideosByChannelIDQueryBuilder.java +++ /dev/null @@ -1,78 +0,0 @@ -package com.pina.query; - -public class VideosByChannelIDQueryBuilder { - /*** - * Used to get the videos of a single channel when given the channel ID - */ - private String channelId; - private String type; - private String include; - private String lang; - private Integer limit; - private Integer offset; - private String paginated; - - public VideosByChannelIDQueryBuilder setChannelId(String channelId) { - this.channelId = channelId; - return this; - } - - public VideosByChannelIDQueryBuilder setType(String type) { - this.type = type; - return this; - } - - public VideosByChannelIDQueryBuilder setInclude(String include) { - this.include = include; - return this; - } - - public VideosByChannelIDQueryBuilder setLang(String lang) { - this.lang = lang; - return this; - } - - public VideosByChannelIDQueryBuilder setLimit(Integer limit) { - this.limit = limit; - return this; - } - - public VideosByChannelIDQueryBuilder setOffset(Integer offset) { - this.offset = offset; - return this; - } - - public VideosByChannelIDQueryBuilder setPaginated(String paginated) { - this.paginated = paginated; - return this; - } - - public String getChannelId() { - return channelId; - } - - public String getType() { - return type; - } - - public String getInclude() { - return include; - } - - public String getLang() { - return lang; - } - - public Integer getLimit() { - return limit; - } - - public Integer getOffset() { - return offset; - } - - public String getPaginated() { - return paginated; - } - -} |
