diff options
| author | Pinapelz <donaldshan1@outlook.com> | 2023-04-04 12:11:11 -0700 |
|---|---|---|
| committer | Pinapelz <donaldshan1@outlook.com> | 2023-04-04 12:11:11 -0700 |
| commit | 28550a86f6f9b4dea05e3c19fb89ab7e4f6996ef (patch) | |
| tree | bf88782db8c047ff26fdf8ab4c82002d4e7e8850 | |
Initial Commit
| -rw-r--r-- | .gitignore | 38 | ||||
| -rw-r--r-- | pom.xml | 37 | ||||
| -rw-r--r-- | src/main/java/App.java | 21 | ||||
| -rw-r--r-- | src/main/java/com/pina/Channel.java | 12 | ||||
| -rw-r--r-- | src/main/java/com/pina/Holodex.java | 44 | ||||
| -rw-r--r-- | src/main/java/com/pina/HolodexException.java | 11 | ||||
| -rw-r--r-- | src/main/java/com/pina/HolodexService.java | 16 | ||||
| -rw-r--r-- | src/main/java/com/pina/LiveStream.java | 18 | ||||
| -rw-r--r-- | src/main/java/com/pina/UpcomingStream.java | 10 | ||||
| -rw-r--r-- | src/test/java/org/example/AppTest.java | 38 |
10 files changed, 245 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5ff6309 --- /dev/null +++ b/.gitignore @@ -0,0 +1,38 @@ +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ + +### IntelliJ IDEA ### +.idea/modules.xml +.idea/jarRepositories.xml +.idea/compiler.xml +.idea/libraries/ +*.iws +*.iml +*.ipr + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store
\ No newline at end of file @@ -0,0 +1,37 @@ +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + + <groupId>org.example</groupId> + <artifactId>HldexWrapper</artifactId> + <version>1.0-SNAPSHOT</version> + <packaging>jar</packaging> + + <name>HldexWrapper</name> + <url>http://maven.apache.org</url> + + <properties> + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> + <maven.compiler.source>18</maven.compiler.source> + <maven.compiler.target>18</maven.compiler.target> + </properties> + + <dependencies> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>3.8.1</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>com.squareup.retrofit2</groupId> + <artifactId>retrofit</artifactId> + <version>2.9.0</version> + </dependency> + <dependency> + <groupId>com.squareup.retrofit2</groupId> + <artifactId>converter-jackson</artifactId> + <version>2.9.0</version> + </dependency> + </dependencies> +</project> diff --git a/src/main/java/App.java b/src/main/java/App.java new file mode 100644 index 0000000..73691fb --- /dev/null +++ b/src/main/java/App.java @@ -0,0 +1,21 @@ +import com.pina.Holodex; +import com.pina.HolodexException; +import com.pina.LiveStream; + +import java.util.List; + +public class App +{ + public static void main( String[] args ) + { + Holodex holodex = new Holodex(); + try { + List<LiveStream> liveStreams = holodex.getLiveStreams(); + for (LiveStream stream : liveStreams) { + System.out.println(stream.title + " by " + stream.channel.name); + } + } catch (HolodexException e) { + System.err.println("Failed to get live streams: " + e.getMessage()); + } + } +} diff --git a/src/main/java/com/pina/Channel.java b/src/main/java/com/pina/Channel.java new file mode 100644 index 0000000..36cf499 --- /dev/null +++ b/src/main/java/com/pina/Channel.java @@ -0,0 +1,12 @@ +package com.pina; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; + +@JsonIgnoreProperties(ignoreUnknown = true) +public class Channel { + public String english_name; + public String id; + public String name; + public String photo; + public String type; +} diff --git a/src/main/java/com/pina/Holodex.java b/src/main/java/com/pina/Holodex.java new file mode 100644 index 0000000..38c519a --- /dev/null +++ b/src/main/java/com/pina/Holodex.java @@ -0,0 +1,44 @@ +package com.pina; + +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 final HolodexService service; + + public Holodex(){ + Retrofit retrofit = new Retrofit.Builder() + .baseUrl("https://holodex.net") + .addConverterFactory(JacksonConverterFactory.create()) + .build(); + service = retrofit.create(HolodexService.class); + } + public List<LiveStream> getLiveStreams() throws HolodexException { + Call<List<LiveStream>> call = service.getLiveStreams("channel,clip"); + return executeCall(call); + } + + public List<UpcomingStream> getUpcomingStreams() throws HolodexException { + Call<List<UpcomingStream>> call = service.getUpcomingStreams("channel,clip"); + 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 new file mode 100644 index 0000000..8dc8cbd --- /dev/null +++ b/src/main/java/com/pina/HolodexException.java @@ -0,0 +1,11 @@ +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 new file mode 100644 index 0000000..98351ca --- /dev/null +++ b/src/main/java/com/pina/HolodexService.java @@ -0,0 +1,16 @@ +package com.pina; + +import java.util.List; +import retrofit2.Call; +import retrofit2.http.GET; +import retrofit2.http.Query; + +public interface HolodexService { + @GET("/api/v2/live") + Call<List<LiveStream>> getLiveStreams(@Query("include") String include); + + @GET("/api/v2/upcoming") + Call<List<UpcomingStream>> getUpcomingStreams(@Query("include") String include); + +} + diff --git a/src/main/java/com/pina/LiveStream.java b/src/main/java/com/pina/LiveStream.java new file mode 100644 index 0000000..5e1d7a9 --- /dev/null +++ b/src/main/java/com/pina/LiveStream.java @@ -0,0 +1,18 @@ +package com.pina; + + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; + +@JsonIgnoreProperties(ignoreUnknown = true) +public class LiveStream { + public String id; + public String title; + public String thumbnail; + public String status; + public int viewers; + public Channel channel; +} + + + diff --git a/src/main/java/com/pina/UpcomingStream.java b/src/main/java/com/pina/UpcomingStream.java new file mode 100644 index 0000000..dbdcc9b --- /dev/null +++ b/src/main/java/com/pina/UpcomingStream.java @@ -0,0 +1,10 @@ +package com.pina; + +public class UpcomingStream { + public String id; + public String title; + public String thumbnail; + public String scheduled_start_time; + public String channel_id; + public String channel_name; +} diff --git a/src/test/java/org/example/AppTest.java b/src/test/java/org/example/AppTest.java new file mode 100644 index 0000000..d5f435d --- /dev/null +++ b/src/test/java/org/example/AppTest.java @@ -0,0 +1,38 @@ +package org.example; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +/** + * Unit test for simple App. + */ +public class AppTest + extends TestCase +{ + /** + * Create the test case + * + * @param testName name of the test case + */ + public AppTest( String testName ) + { + super( testName ); + } + + /** + * @return the suite of tests being tested + */ + public static Test suite() + { + return new TestSuite( AppTest.class ); + } + + /** + * Rigourous Test :-) + */ + public void testApp() + { + assertTrue( true ); + } +} |
