aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/main/java/App.java9
-rw-r--r--src/main/java/com/pina/Holodex.java26
-rw-r--r--src/main/java/com/pina/query/ChannelQueryBuilder.java3
-rw-r--r--src/main/java/com/pina/query/VideoMetadataQueryBuilder.java40
-rw-r--r--src/main/java/com/pina/query/VideoQueryBuilder.java149
-rw-r--r--src/main/java/com/pina/query/VideosByChannelIDQueryBuilder.java (renamed from src/main/java/com/pina/query/VideosByChannelIDQuery.java)19
6 files changed, 211 insertions, 35 deletions
diff --git a/src/main/java/App.java b/src/main/java/App.java
index 05f4856..f526bd2 100644
--- a/src/main/java/App.java
+++ b/src/main/java/App.java
@@ -3,8 +3,8 @@ import com.pina.HolodexException;
import com.pina.datatypes.Channel;
import com.pina.datatypes.Video;
import com.pina.query.ChannelQueryBuilder;
-import com.pina.query.LiveVideoQueryBuilder;
import com.pina.query.VideoQueryBuilder;
+import com.pina.query.VideoMetadataQueryBuilder;
import java.util.List;
@@ -17,7 +17,7 @@ public class App
Channel channel = holodex.getChannel("UC4WvIIAo89_AzGUh1AZ6Dkg");
System.out.println(channel.name + " is a member of " + channel.org + " and has " + channel.suborg + " as a suborg");
- LiveVideoQueryBuilder liveVideoQuery = new LiveVideoQueryBuilder().setStatus("live").setOrg("Hololive");
+ VideoQueryBuilder liveVideoQuery = new VideoQueryBuilder().setStatus("live").setOrg("Hololive");
List<Video> currentlyLiveVideos = holodex.getLiveVideos(liveVideoQuery);
System.out.println("Currently there are " + currentlyLiveVideos.size() + " livestreams on going in Hololive");
for (Video video : currentlyLiveVideos) {
@@ -28,10 +28,11 @@ public class App
channelQuery.setOrg("Nijisanji");
channelQuery.setLimit(75);
List<Channel> nijisanjiMembers = holodex.getChannels(channelQuery);
+ // Gets the first 75 members of Nijisanji
- VideoQueryBuilder vidoeQuery = new VideoQueryBuilder();
+ VideoMetadataQueryBuilder vidoeQuery = new VideoMetadataQueryBuilder();
vidoeQuery.setVideoId("9-O_IWM3184");
- Video anotherVideo = holodex.getVideo(new VideoQueryBuilder().setVideoId("9-O_IWM3184").setLang("en"));
+ Video anotherVideo = holodex.getVideo(new VideoMetadataQueryBuilder().setVideoId("9-O_IWM3184").setLang("en"));
System.out.println(anotherVideo.channel.name + " uploaded a video titled " + anotherVideo.title + " on " + anotherVideo.published_at);
}
diff --git a/src/main/java/com/pina/Holodex.java b/src/main/java/com/pina/Holodex.java
index 5253f2b..58a11c0 100644
--- a/src/main/java/com/pina/Holodex.java
+++ b/src/main/java/com/pina/Holodex.java
@@ -3,9 +3,9 @@ package com.pina;
import com.pina.datatypes.Channel;
import com.pina.datatypes.Video;
import com.pina.query.ChannelQueryBuilder;
-import com.pina.query.LiveVideoQueryBuilder;
import com.pina.query.VideoQueryBuilder;
-import com.pina.query.VideosByChannelIDQuery;
+import com.pina.query.VideoMetadataQueryBuilder;
+import com.pina.query.VideosByChannelIDQueryBuilder;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import retrofit2.Call;
@@ -17,9 +17,18 @@ import java.io.IOException;
import java.util.List;
public class Holodex {
- private final HolodexService service;
+ 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();
@@ -30,15 +39,14 @@ public class Holodex {
return chain.proceed(request);
});
Retrofit retrofit = new Retrofit.Builder()
- .baseUrl("https://holodex.net")
+ .baseUrl(baseUrl)
.addConverterFactory(JacksonConverterFactory.create())
.client(httpClient.build())
.build();
service = retrofit.create(HolodexService.class);
}
-
- public List<Video> getLiveVideos(LiveVideoQueryBuilder queryBuilder) throws HolodexException {
+ public List<Video> getLiveVideos(VideoQueryBuilder queryBuilder) throws HolodexException {
Call<List<Video>> call = service.getLiveVideos(queryBuilder.getChannelId(), queryBuilder.getId(),
queryBuilder.getInclude(), queryBuilder.getLang(),
queryBuilder.getLimit(), queryBuilder.getMaxUpcomingHours(),
@@ -50,7 +58,7 @@ public class Holodex {
return executeCall(call);
}
- public List<Video> getVideos(LiveVideoQueryBuilder queryBuilder) throws HolodexException {
+ 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(),
@@ -67,7 +75,7 @@ public class Holodex {
return executeCall(call);
}
- public List<Video> getVideosByChannelId(VideosByChannelIDQuery query) throws HolodexException {
+ 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);
@@ -80,7 +88,7 @@ public class Holodex {
return executeCall(call);
}
- public Video getVideo(VideoQueryBuilder query) throws HolodexException {
+ public Video getVideo(VideoMetadataQueryBuilder query) throws HolodexException {
Call<Video> call = service.getVideo(query.getVideoId(), query.getLang(), query.getC());
return executeCall(call);
}
diff --git a/src/main/java/com/pina/query/ChannelQueryBuilder.java b/src/main/java/com/pina/query/ChannelQueryBuilder.java
index 13fd387..1c51d68 100644
--- a/src/main/java/com/pina/query/ChannelQueryBuilder.java
+++ b/src/main/java/com/pina/query/ChannelQueryBuilder.java
@@ -1,6 +1,9 @@
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;
diff --git a/src/main/java/com/pina/query/VideoMetadataQueryBuilder.java b/src/main/java/com/pina/query/VideoMetadataQueryBuilder.java
new file mode 100644
index 0000000..bccad79
--- /dev/null
+++ b/src/main/java/com/pina/query/VideoMetadataQueryBuilder.java
@@ -0,0 +1,40 @@
+package com.pina.query;
+
+
+public class VideoMetadataQueryBuilder {
+ /***
+ * 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 VideoMetadataQueryBuilder setVideoId(String videoId) {
+ this.videoId = videoId;
+ return this;
+ }
+
+ public String getLang() {
+ return lang;
+ }
+
+ public VideoMetadataQueryBuilder setLang(String lang) {
+ this.lang = lang;
+ return this;
+ }
+
+ public String getC() {
+ return c;
+ }
+
+ public VideoMetadataQueryBuilder 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
index bd6d1b0..67acd1b 100644
--- a/src/main/java/com/pina/query/VideoQueryBuilder.java
+++ b/src/main/java/com/pina/query/VideoQueryBuilder.java
@@ -1,22 +1,39 @@
package com.pina.query;
-
public class VideoQueryBuilder {
- private String videoId;
+ /***
+ * 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 String c;
+ 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 String getVideoId() {
- return videoId;
+ public VideoQueryBuilder setChannelId(String channelId) {
+ this.channelId = channelId;
+ return this;
}
- public VideoQueryBuilder setVideoId(String videoId) {
- this.videoId = videoId;
+ public VideoQueryBuilder setId(String id) {
+ this.id = id;
return this;
}
- public String getLang() {
- return lang;
+ public VideoQueryBuilder setInclude(String include) {
+ this.include = include;
+ return this;
}
public VideoQueryBuilder setLang(String lang) {
@@ -24,14 +41,118 @@ public class VideoQueryBuilder {
return this;
}
- public String getC() {
- return c;
+ 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 setC(String c) {
- this.c = c;
+ 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/VideosByChannelIDQuery.java b/src/main/java/com/pina/query/VideosByChannelIDQueryBuilder.java
index 73999f0..0ba9963 100644
--- a/src/main/java/com/pina/query/VideosByChannelIDQuery.java
+++ b/src/main/java/com/pina/query/VideosByChannelIDQueryBuilder.java
@@ -1,6 +1,9 @@
package com.pina.query;
-public class VideosByChannelIDQuery {
+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;
@@ -9,37 +12,37 @@ public class VideosByChannelIDQuery {
private Integer offset;
private String paginated;
- public VideosByChannelIDQuery setChannelId(String channelId) {
+ public VideosByChannelIDQueryBuilder setChannelId(String channelId) {
this.channelId = channelId;
return this;
}
- public VideosByChannelIDQuery setType(String type) {
+ public VideosByChannelIDQueryBuilder setType(String type) {
this.type = type;
return this;
}
- public VideosByChannelIDQuery setInclude(String include) {
+ public VideosByChannelIDQueryBuilder setInclude(String include) {
this.include = include;
return this;
}
- public VideosByChannelIDQuery setLang(String lang) {
+ public VideosByChannelIDQueryBuilder setLang(String lang) {
this.lang = lang;
return this;
}
- public VideosByChannelIDQuery setLimit(Integer limit) {
+ public VideosByChannelIDQueryBuilder setLimit(Integer limit) {
this.limit = limit;
return this;
}
- public VideosByChannelIDQuery setOffset(Integer offset) {
+ public VideosByChannelIDQueryBuilder setOffset(Integer offset) {
this.offset = offset;
return this;
}
- public VideosByChannelIDQuery setPaginated(String paginated) {
+ public VideosByChannelIDQueryBuilder setPaginated(String paginated) {
this.paginated = paginated;
return this;
}
send patches to the email below
yukais@pinapelz.com
include the subject [PATCH repo_name]
pinapelz.com
homepage