diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs
index af4d398..7fe881d 100644
--- a/.settings/org.eclipse.jdt.core.prefs
+++ b/.settings/org.eclipse.jdt.core.prefs
@@ -19,6 +19,7 @@ org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.problem.nullAnnotationInferenceConflict=warning
org.eclipse.jdt.core.compiler.problem.nullReference=warning
org.eclipse.jdt.core.compiler.problem.nullSpecViolation=warning
+org.eclipse.jdt.core.compiler.problem.nullUncheckedConversion=ignore
org.eclipse.jdt.core.compiler.problem.potentialNullReference=warning
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
org.eclipse.jdt.core.compiler.problem.syntacticNullAnalysisForFields=enabled
diff --git a/pom.xml b/pom.xml
index 3d67642..8a8ad7e 100644
--- a/pom.xml
+++ b/pom.xml
@@ -4,7 +4,7 @@
4.0.0
cc
wordview
- 0.0.1-SNAPSHOT
+ 0.0.3-SNAPSHOT
WordViewAPI
diff --git a/src/main/java/cc/wordview/api/Application.java b/src/main/java/cc/wordview/api/Application.java
index 603199d..2829c47 100644
--- a/src/main/java/cc/wordview/api/Application.java
+++ b/src/main/java/cc/wordview/api/Application.java
@@ -22,28 +22,38 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
+import cc.wordview.api.config.WordViewConfig;
+
@SpringBootApplication
@ComponentScan(basePackages = { "cc.wordview.api" })
public class Application implements ApplicationRunner {
private static final Logger logger = LoggerFactory.getLogger(Application.class);
+ @Autowired
+ private WordViewConfig config;
+
public static void main(String... args) throws Exception {
SpringApplication.run(Application.class, args);
}
@Override
public void run(ApplicationArguments args) throws Exception {
- if (args.containsOption("production")) {
+ config.setProduction(args.containsOption("production"));
+
+ if (config.isProduction()) {
if (CORS_ORIGIN == CORS_ORIGIN_ALL) {
logger.warn("CORS_ORIGIN is set to all.");
}
+ } else {
+ logger.info("All requests to YouTube's API are being mocked");
}
}
}
diff --git a/src/main/java/cc/wordview/api/config/WordViewConfig.java b/src/main/java/cc/wordview/api/config/WordViewConfig.java
new file mode 100644
index 0000000..9fb3e02
--- /dev/null
+++ b/src/main/java/cc/wordview/api/config/WordViewConfig.java
@@ -0,0 +1,16 @@
+package cc.wordview.api.config;
+
+import org.springframework.stereotype.Component;
+
+@Component
+public class WordViewConfig {
+ private boolean production;
+
+ public boolean isProduction() {
+ return production;
+ }
+
+ public void setProduction(boolean production) {
+ this.production = production;
+ }
+}
diff --git a/src/main/java/cc/wordview/api/controller/MusicController.java b/src/main/java/cc/wordview/api/controller/MusicController.java
index cfd7e09..c212e0e 100644
--- a/src/main/java/cc/wordview/api/controller/MusicController.java
+++ b/src/main/java/cc/wordview/api/controller/MusicController.java
@@ -12,6 +12,7 @@
import javax.servlet.http.HttpServletResponse;
+import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.ContentDisposition;
import org.springframework.http.HttpHeaders;
@@ -27,6 +28,7 @@
import com.sapher.youtubedl.YoutubeDLResponse;
import cc.wordview.api.Constants;
+import cc.wordview.api.config.WordViewConfig;
import cc.wordview.api.util.FileReader;
import cc.wordview.api.util.StringUtil;
import cc.wordview.ytm.YoutubeApi;
@@ -46,21 +48,30 @@ public class MusicController {
@Value("${wordview.ytm.api-key}")
private String API_KEY;
+ @Autowired
+ private WordViewConfig config;
+
// History is just being a placeholder here it does not provide the inteded
// functionality yet
@GetMapping("/history")
public ResponseEntity> history() {
return response(() -> {
- ytapi.setApiKey(API_KEY);
-
- SearchResult result = ytapi.search("ano-yume-wo-nazotte", 1).get(0);
-
Video video = new Video();
- video.setId(result.getId().getVideoId());
- video.setTitle(result.getSnippet().getTitle());
- video.setArtist(result.getSnippet().getChannelTitle());
- video.setCover(result.getSnippet().getThumbnails().getHigh().getUrl());
+ if (config.isProduction()) {
+ ytapi.setApiKey(API_KEY);
+ SearchResult result = ytapi.search("ano-yume-wo-nazotte", 1).get(0);
+
+ video.setId(result.getId().getVideoId());
+ video.setTitle(result.getSnippet().getTitle());
+ video.setArtist(result.getSnippet().getChannelTitle());
+ video.setCover(result.getSnippet().getThumbnails().getHigh().getUrl());
+ } else {
+ video.setId("sAuEeM_6zpk");
+ video.setTitle("YOASOBI「あの夢をなぞって」 Official Music Video");
+ video.setArtist("YOASOBI");
+ video.setCover("https://img.youtube.com/vi/sAuEeM_6zpk/0.jpg");
+ }
return ok(video);
});