diff --git a/src/main/java/play/pluv/config/RestClientConfig.java b/src/main/java/play/pluv/config/RestClientConfig.java index 719a73a..86510c7 100644 --- a/src/main/java/play/pluv/config/RestClientConfig.java +++ b/src/main/java/play/pluv/config/RestClientConfig.java @@ -12,6 +12,7 @@ import play.pluv.oauth.apple.AppleApiClient; import play.pluv.oauth.google.GoogleApiClient; import play.pluv.oauth.spotify.SpotifyApiClient; +import play.pluv.playlist.infra.OcrApiClient; @Configuration public class RestClientConfig { @@ -42,6 +43,11 @@ public GoogleApiClient googleApiClient() { return createHttpInterface(GoogleApiClient.class); } + @Bean + public OcrApiClient ocrApiClient() { + return createHttpInterface(OcrApiClient.class); + } + private T createHttpInterface(final Class clazz) { Builder builder = RestClient.builder(); if (logActive) { diff --git a/src/main/java/play/pluv/playlist/application/PlayListService.java b/src/main/java/play/pluv/playlist/application/PlayListService.java index 43f2217..5775fb6 100644 --- a/src/main/java/play/pluv/playlist/application/PlayListService.java +++ b/src/main/java/play/pluv/playlist/application/PlayListService.java @@ -6,12 +6,14 @@ import play.pluv.playlist.domain.MusicStreaming; import play.pluv.playlist.domain.PlayList; import play.pluv.playlist.domain.PlayListMusic; +import play.pluv.playlist.infra.OcrReader; @Service @RequiredArgsConstructor public class PlayListService { private final PlayListConnectorComposite playListConnectorComposite; + private final OcrReader ocrReader; public List getPlayLists(final String accessToken, final MusicStreaming source) { return playListConnectorComposite.getPlayList(source, accessToken); @@ -24,15 +26,6 @@ public List getPlayListMusics( } public List getOcrPlayListMusics(final List base64EncodedImages) { - return List.of( - new PlayListMusic( - "좋은 날", List.of("아이유"), null, - "https://i.scdn.co/image/ab67616d00001e0215cf3110f19687b1a24943d1" - ), - new PlayListMusic( - "ㅈㅣㅂ", List.of("한로로"), null, - "https://i.scdn.co/image/ab67616d00001e0215cf3110f19687b1a22314" - ) - ); + return ocrReader.ocrImages(base64EncodedImages); } } diff --git a/src/main/java/play/pluv/playlist/infra/OcrApiClient.java b/src/main/java/play/pluv/playlist/infra/OcrApiClient.java new file mode 100644 index 0000000..b9b0e75 --- /dev/null +++ b/src/main/java/play/pluv/playlist/infra/OcrApiClient.java @@ -0,0 +1,13 @@ +package play.pluv.playlist.infra; + +import java.util.List; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.service.annotation.PostExchange; +import play.pluv.playlist.infra.dto.OcrMusicRequest; +import play.pluv.playlist.infra.dto.OcrMusicResponse; + +public interface OcrApiClient { + + @PostExchange("http://192.168.0.22:8000/ocr") + List ocrPlayListImage(@RequestBody final OcrMusicRequest request); +} diff --git a/src/main/java/play/pluv/playlist/infra/OcrReader.java b/src/main/java/play/pluv/playlist/infra/OcrReader.java new file mode 100644 index 0000000..6c012df --- /dev/null +++ b/src/main/java/play/pluv/playlist/infra/OcrReader.java @@ -0,0 +1,22 @@ +package play.pluv.playlist.infra; + +import java.util.List; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Component; +import play.pluv.playlist.domain.PlayListMusic; +import play.pluv.playlist.infra.dto.OcrMusicRequest; +import play.pluv.playlist.infra.dto.OcrMusicResponse; + +@Component +@RequiredArgsConstructor +public class OcrReader { + + private final OcrApiClient ocrApiClient; + + public List ocrImages(final List base64EncodedImages) { + final OcrMusicRequest request = OcrMusicRequest.from(base64EncodedImages); + return ocrApiClient.ocrPlayListImage(request).stream() + .map(OcrMusicResponse::toPlayListMusic) + .toList(); + } +} diff --git a/src/main/java/play/pluv/playlist/infra/dto/OcrMusicRequest.java b/src/main/java/play/pluv/playlist/infra/dto/OcrMusicRequest.java new file mode 100644 index 0000000..3875511 --- /dev/null +++ b/src/main/java/play/pluv/playlist/infra/dto/OcrMusicRequest.java @@ -0,0 +1,20 @@ +package play.pluv.playlist.infra.dto; + +import java.util.List; + +public record OcrMusicRequest( + List images +) { + + public static OcrMusicRequest from(final List base64EncodedImages) { + return new OcrMusicRequest( + base64EncodedImages.stream() + .map(Base64EncodedImage::new) + .toList() + ); + } + + private record Base64EncodedImage(String base64EncodedImage) { + + } +} diff --git a/src/main/java/play/pluv/playlist/infra/dto/OcrMusicResponse.java b/src/main/java/play/pluv/playlist/infra/dto/OcrMusicResponse.java new file mode 100644 index 0000000..4a6b647 --- /dev/null +++ b/src/main/java/play/pluv/playlist/infra/dto/OcrMusicResponse.java @@ -0,0 +1,13 @@ +package play.pluv.playlist.infra.dto; + +import java.util.List; +import play.pluv.playlist.domain.PlayListMusic; + +public record OcrMusicResponse( + String artistNames, String songTitle +) { + + public PlayListMusic toPlayListMusic() { + return new PlayListMusic(songTitle, List.of(artistNames), null, ""); + } +}