-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(MediaInfo): support get media info
- Loading branch information
1 parent
fe41844
commit 23249f1
Showing
6 changed files
with
99 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 11 additions & 2 deletions
13
...configure/controller/VideoController.java → ...ler/MediaStreamingReactiveController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,37 @@ | ||
package com.github.johnnymillergh.boot.mediastreamingspringbootautoconfigure.controller; | ||
|
||
import com.drew.metadata.Directory; | ||
import com.github.johnnymillergh.boot.mediastreamingspringbootautoconfigure.model.Video; | ||
import com.github.johnnymillergh.boot.mediastreamingspringbootautoconfigure.services.MediaInfoService; | ||
import com.github.johnnymillergh.boot.mediastreamingspringbootautoconfigure.services.VideoService; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.RestController; | ||
import reactor.core.publisher.Flux; | ||
|
||
import java.time.Duration; | ||
import java.util.List; | ||
|
||
/** | ||
* Description: VideoController, change description here. | ||
* Description: MediaStreamingReactiveController, change description here. | ||
* | ||
* @author Johnny Miller (锺俊), email: [email protected], date: 10/26/2020 4:17 PM | ||
**/ | ||
@RestController | ||
@RequiredArgsConstructor | ||
public class VideoController { | ||
public class MediaStreamingReactiveController { | ||
private final VideoService videoService; | ||
private final MediaInfoService mediaInfoService; | ||
|
||
@GetMapping(value = "/video-annotation", produces = MediaType.APPLICATION_STREAM_JSON_VALUE) | ||
public Flux<List<Video>> getVideo() { | ||
return Flux.interval(Duration.ofSeconds(2)).map(aLong -> videoService.getAllVideoList()); | ||
} | ||
|
||
@GetMapping(value = "/media-info/{name}") | ||
public Flux<Directory> mediaInfo(@PathVariable String name) { | ||
return mediaInfoService.getMediaInfo(name); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
.../johnnymillergh/boot/mediastreamingspringbootautoconfigure/services/MediaInfoService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.github.johnnymillergh.boot.mediastreamingspringbootautoconfigure.services; | ||
|
||
import com.drew.metadata.Directory; | ||
import reactor.core.publisher.Flux; | ||
|
||
/** | ||
* Description: MediaInfoService, change description here. | ||
* | ||
* @author Johnny Miller (锺俊), email: [email protected], date: 10/27/2020 2:46 PM | ||
**/ | ||
public interface MediaInfoService { | ||
Flux<Directory> getMediaInfo(String name); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
...llergh/boot/mediastreamingspringbootautoconfigure/services/impl/MediaInfoServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package com.github.johnnymillergh.boot.mediastreamingspringbootautoconfigure.services.impl; | ||
|
||
import com.drew.imaging.ImageMetadataReader; | ||
import com.drew.imaging.ImageProcessingException; | ||
import com.drew.metadata.Directory; | ||
import com.drew.metadata.Metadata; | ||
import com.github.johnnymillergh.boot.mediastreamingspringbootautoconfigure.services.FileService; | ||
import com.github.johnnymillergh.boot.mediastreamingspringbootautoconfigure.services.MediaInfoService; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import lombok.val; | ||
import reactor.core.publisher.Flux; | ||
import reactor.core.publisher.Mono; | ||
|
||
import java.io.IOException; | ||
|
||
/** | ||
* Description: MediaInfoServiceImpl, change description here. | ||
* | ||
* @author Johnny Miller (锺俊), email: [email protected], date: 10/27/2020 2:47 PM | ||
**/ | ||
@Slf4j | ||
@RequiredArgsConstructor | ||
public class MediaInfoServiceImpl implements MediaInfoService { | ||
private final FileService fileService; | ||
|
||
@Override | ||
public Flux<Directory> getMediaInfo(String name) { | ||
val fileByFileName = fileService.getFileByFileName(name); | ||
Mono<Iterable<Directory>> iterableMono = fileByFileName.map(path -> { | ||
Iterable<Directory> directories = null; | ||
try { | ||
Metadata metadata = ImageMetadataReader.readMetadata(path.toFile()); | ||
directories = metadata.getDirectories(); | ||
} catch (ImageProcessingException | IOException e) { | ||
log.error("Cannot read file metadata!", e); | ||
} | ||
return directories; | ||
}); | ||
return iterableMono.flatMapMany(Flux::fromIterable); | ||
} | ||
} |