This commit is contained in:
1 parent
2904e59e71
commit
31d449916f
11 files changed
+201
-12
No files matched your search
@@ -181,6 +181,9 @@ app.register.max-per-device-per-day
|
|||||||
| GET | `/app/dramas/{id}` | 详情(含剧集列表,免费集带**已签名**播放地址) |
|
| GET | `/app/dramas/{id}` | 详情(含剧集列表,免费集带**已签名**播放地址) |
|
||||||
| GET | `/app/search?keyword=&pageIndex=&pageSize=` | **匿名**。搜索已上线短剧:按标题/简介模糊匹配,分页返回卡片列表 |
|
| GET | `/app/search?keyword=&pageIndex=&pageSize=` | **匿名**。搜索已上线短剧:按标题/简介模糊匹配,分页返回卡片列表 |
|
||||||
|
|
||||||
|
首页、发现页和推荐流的卡片 `preview.posterUrl` 与详情的 `episodes[].posterUrl` 同源,
|
||||||
|
有 READY 高清 poster 时返回签名地址;没有时为 `null`,客户端回退雪碧图。
|
||||||
|
|
||||||
`POST /app/dramas/page` 请求体:
|
`POST /app/dramas/page` 请求体:
|
||||||
|
|
||||||
```json
|
```json
|
||||||
@@ -289,6 +292,7 @@ app.register.max-per-device-per-day
|
|||||||
"likeCount": "45",
|
"likeCount": "45",
|
||||||
"commentCount": "8",
|
"commentCount": "8",
|
||||||
"playUrl": "/files/episode/202610/xxx.mp4?e=1760000000&s=9f2c...",
|
"playUrl": "/files/episode/202610/xxx.mp4?e=1760000000&s=9f2c...",
|
||||||
|
"posterUrl": "/files/transcoded/88/poster.jpg?e=1760000000&s=7b1e...",
|
||||||
"thumbnailsUrl": "/files/transcoded/88/thumbnails/thumbnails.vtt?e=1760000000&s=8a1d..."
|
"thumbnailsUrl": "/files/transcoded/88/thumbnails/thumbnails.vtt?e=1760000000&s=8a1d..."
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
@@ -306,6 +310,7 @@ app.register.max-per-device-per-day
|
|||||||
| `viewCount` | Long(JSON 字符串) | 取 `drama.view_count`,累计播放量,既有字段语义不变 |
|
| `viewCount` | Long(JSON 字符串) | 取 `drama.view_count`,累计播放量,既有字段语义不变 |
|
||||||
| `episodes[].likeCount` | Long(JSON 字符串) | 本集点赞数,取 `drama_episode.like_count` |
|
| `episodes[].likeCount` | Long(JSON 字符串) | 本集点赞数,取 `drama_episode.like_count` |
|
||||||
| `episodes[].commentCount` | Long(JSON 字符串) | 本集未删除评论数,按 `episode_id` 统计 |
|
| `episodes[].commentCount` | Long(JSON 字符串) | 本集未删除评论数,按 `episode_id` 统计 |
|
||||||
|
| `episodes[].posterUrl` | String / null | 本集高清首帧 poster 签名地址;没有 READY 媒资时为 `null`,用于播放首帧占位 |
|
||||||
| `episodes[].thumbnailsUrl` | String / null | 本集雪碧图 WebVTT 时间轴签名地址;没有 READY 产物时为 `null` |
|
| `episodes[].thumbnailsUrl` | String / null | 本集雪碧图 WebVTT 时间轴签名地址;没有 READY 产物时为 `null` |
|
||||||
|
|
||||||
计数是只读快照:互动操作完成后客户端重新拉取详情即可刷新;`Long` 字段一律按字符串下发,
|
计数是只读快照:互动操作完成后客户端重新拉取详情即可刷新;`Long` 字段一律按字符串下发,
|
||||||
@@ -326,6 +331,7 @@ app.register.max-per-device-per-day
|
|||||||
"accessible": true,
|
"accessible": true,
|
||||||
"accessType": "FREE",
|
"accessType": "FREE",
|
||||||
"playUrl": "/files/episode/202610/xxx.mp4?e=1760000000&s=9f2c...",
|
"playUrl": "/files/episode/202610/xxx.mp4?e=1760000000&s=9f2c...",
|
||||||
|
"posterUrl": "/files/transcoded/88/poster.jpg?e=1760000000&s=7b1e...",
|
||||||
"qualities": ["AUTO", "720p", "1080p"],
|
"qualities": ["AUTO", "720p", "1080p"],
|
||||||
"tracks": [
|
"tracks": [
|
||||||
{"quality": "AUTO", "playUrl": "/files/transcoded/88/master.m3u8?e=1760000000&s=9f2c..."},
|
{"quality": "AUTO", "playUrl": "/files/transcoded/88/master.m3u8?e=1760000000&s=9f2c..."},
|
||||||
@@ -352,6 +358,9 @@ app.register.max-per-device-per-day
|
|||||||
`sprite_XXX.jpg#xywh=x,y,w,h`。有 READY `media_thumbnail` 时返回签名地址,
|
`sprite_XXX.jpg#xywh=x,y,w,h`。有 READY `media_thumbnail` 时返回签名地址,
|
||||||
无产物时为 `null`;该字段不影响 `playUrl`、`qualities` 和 HLS/原文件回落。
|
无产物时为 `null`;该字段不影响 `playUrl`、`qualities` 和 HLS/原文件回落。
|
||||||
|
|
||||||
|
`posterUrl` 是转码产出的高清首帧 poster 签名地址;有 READY 媒资但没有 poster 时为
|
||||||
|
`null`。客户端应优先用它作为视频纹理就绪前的占位,雪碧图仅作为回退和拖动预览使用。
|
||||||
|
|
||||||
**`GET /app/episodes/{id}/stats`(播放页计数刷新)**
|
**`GET /app/episodes/{id}/stats`(播放页计数刷新)**
|
||||||
|
|
||||||
只读返回本集点赞数、本集未删除评论数、所属剧收藏数,以及当前用户对
|
只读返回本集点赞数、本集未删除评论数、所属剧收藏数,以及当前用户对
|
||||||
|
|||||||
+16
-5
@@ -27,6 +27,7 @@ import com.fruitshorts.content.service.DramaService;
|
|||||||
import com.fruitshorts.content.service.EpisodeService;
|
import com.fruitshorts.content.service.EpisodeService;
|
||||||
import com.fruitshorts.interaction.service.CommentService;
|
import com.fruitshorts.interaction.service.CommentService;
|
||||||
import com.fruitshorts.media.service.PlaybackSigner;
|
import com.fruitshorts.media.service.PlaybackSigner;
|
||||||
|
import com.fruitshorts.media.service.PosterUrlResolver;
|
||||||
import com.fruitshorts.media.service.ThumbnailUrlResolver;
|
import com.fruitshorts.media.service.ThumbnailUrlResolver;
|
||||||
import com.fruitshorts.content.vo.DramaCategoryRespVO;
|
import com.fruitshorts.content.vo.DramaCategoryRespVO;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
@@ -67,6 +68,7 @@ public class AppCatalogService {
|
|||||||
private final PlaybackSigner playbackSigner;
|
private final PlaybackSigner playbackSigner;
|
||||||
private final CommentService commentService;
|
private final CommentService commentService;
|
||||||
private final ThumbnailUrlResolver thumbnailUrlResolver;
|
private final ThumbnailUrlResolver thumbnailUrlResolver;
|
||||||
|
private final PosterUrlResolver posterUrlResolver;
|
||||||
|
|
||||||
public AppFeedVO homeFeed() {
|
public AppFeedVO homeFeed() {
|
||||||
Map<Long, Map<String, String>> categoryLocales = categoryLocaleMap();
|
Map<Long, Map<String, String>> categoryLocales = categoryLocaleMap();
|
||||||
@@ -200,6 +202,9 @@ public class AppCatalogService {
|
|||||||
episodes.stream().map(DramaEpisode::getId).sorted().toList());
|
episodes.stream().map(DramaEpisode::getId).sorted().toList());
|
||||||
Map<Long, String> thumbnailUrls = thumbnailUrlResolver.resolveAll(
|
Map<Long, String> thumbnailUrls = thumbnailUrlResolver.resolveAll(
|
||||||
episodes.stream().map(DramaEpisode::getId).sorted().toList());
|
episodes.stream().map(DramaEpisode::getId).sorted().toList());
|
||||||
|
Map<Long, String> posterUrls = posterUrlResolver.resolveAll(
|
||||||
|
episodes.stream().map(DramaEpisode::getVideoAssetId)
|
||||||
|
.filter(id -> id != null && id > 0L).distinct().toList());
|
||||||
List<Map<String, String>> types = dramaCategoryService.localesForDrama(drama, categoryLocaleMap());
|
List<Map<String, String>> types = dramaCategoryService.localesForDrama(drama, categoryLocaleMap());
|
||||||
|
|
||||||
AppDramaDetailVO detail = new AppDramaDetailVO();
|
AppDramaDetailVO detail = new AppDramaDetailVO();
|
||||||
@@ -222,7 +227,7 @@ public class AppCatalogService {
|
|||||||
detail.setFavoriteCount(drama.getFavoriteCount());
|
detail.setFavoriteCount(drama.getFavoriteCount());
|
||||||
detail.setCommentCount(commentService.countByDrama(dramaId));
|
detail.setCommentCount(commentService.countByDrama(dramaId));
|
||||||
detail.setEpisodes(episodes.stream()
|
detail.setEpisodes(episodes.stream()
|
||||||
.map(episode -> toEpisode(episode, episodeCommentCounts, thumbnailUrls))
|
.map(episode -> toEpisode(episode, episodeCommentCounts, thumbnailUrls, posterUrls))
|
||||||
.toList());
|
.toList());
|
||||||
return detail;
|
return detail;
|
||||||
}
|
}
|
||||||
@@ -333,18 +338,21 @@ public class AppCatalogService {
|
|||||||
previews.values().stream().map(DramaEpisode::getId).sorted().toList());
|
previews.values().stream().map(DramaEpisode::getId).sorted().toList());
|
||||||
Map<Long, String> thumbnailUrls = thumbnailUrlResolver.resolveAll(
|
Map<Long, String> thumbnailUrls = thumbnailUrlResolver.resolveAll(
|
||||||
previews.values().stream().map(DramaEpisode::getId).sorted().toList());
|
previews.values().stream().map(DramaEpisode::getId).sorted().toList());
|
||||||
|
Map<Long, String> posterUrls = posterUrlResolver.resolveAll(
|
||||||
|
previews.values().stream().map(DramaEpisode::getVideoAssetId)
|
||||||
|
.filter(id -> id != null && id > 0L).distinct().toList());
|
||||||
Map<Long, ContentTag> tags = loadTags(dramas);
|
Map<Long, ContentTag> tags = loadTags(dramas);
|
||||||
return dramas.stream()
|
return dramas.stream()
|
||||||
.map(drama -> toCard(
|
.map(drama -> toCard(
|
||||||
drama, categoryLocales, tags, previews.get(drama.getId()), commentCounts,
|
drama, categoryLocales, tags, previews.get(drama.getId()), commentCounts,
|
||||||
thumbnailUrls))
|
thumbnailUrls, posterUrls))
|
||||||
.toList();
|
.toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
private AppDramaCardVO toCard(Drama drama, Map<Long, Map<String, String>> categoryLocales,
|
private AppDramaCardVO toCard(Drama drama, Map<Long, Map<String, String>> categoryLocales,
|
||||||
Map<Long, ContentTag> tags,
|
Map<Long, ContentTag> tags,
|
||||||
DramaEpisode preview, Map<Long, Long> commentCounts,
|
DramaEpisode preview, Map<Long, Long> commentCounts,
|
||||||
Map<Long, String> thumbnailUrls) {
|
Map<Long, String> thumbnailUrls, Map<Long, String> posterUrls) {
|
||||||
List<Map<String, String>> types = dramaCategoryService.localesForDrama(drama, categoryLocales);
|
List<Map<String, String>> types = dramaCategoryService.localesForDrama(drama, categoryLocales);
|
||||||
AppDramaCardVO card = new AppDramaCardVO();
|
AppDramaCardVO card = new AppDramaCardVO();
|
||||||
card.setId(drama.getId());
|
card.setId(drama.getId());
|
||||||
@@ -368,12 +376,12 @@ public class AppCatalogService {
|
|||||||
card.setLanguage(drama.getLanguage());
|
card.setLanguage(drama.getLanguage());
|
||||||
card.setDramaType(drama.getDramaType());
|
card.setDramaType(drama.getDramaType());
|
||||||
card.setPreview(preview == null
|
card.setPreview(preview == null
|
||||||
? null : toEpisode(preview, commentCounts, thumbnailUrls));
|
? null : toEpisode(preview, commentCounts, thumbnailUrls, posterUrls));
|
||||||
return card;
|
return card;
|
||||||
}
|
}
|
||||||
|
|
||||||
private AppEpisodeVO toEpisode(DramaEpisode episode, Map<Long, Long> commentCounts,
|
private AppEpisodeVO toEpisode(DramaEpisode episode, Map<Long, Long> commentCounts,
|
||||||
Map<Long, String> thumbnailUrls) {
|
Map<Long, String> thumbnailUrls, Map<Long, String> posterUrls) {
|
||||||
AppEpisodeVO vo = new AppEpisodeVO();
|
AppEpisodeVO vo = new AppEpisodeVO();
|
||||||
vo.setId(episode.getId());
|
vo.setId(episode.getId());
|
||||||
vo.setNumber(episode.getEpNo());
|
vo.setNumber(episode.getEpNo());
|
||||||
@@ -388,6 +396,9 @@ public class AppCatalogService {
|
|||||||
vo.setLikeCount(episode.getLikeCount() == null ? 0L : episode.getLikeCount());
|
vo.setLikeCount(episode.getLikeCount() == null ? 0L : episode.getLikeCount());
|
||||||
vo.setCommentCount(commentCounts.getOrDefault(episode.getId(), 0L));
|
vo.setCommentCount(commentCounts.getOrDefault(episode.getId(), 0L));
|
||||||
vo.setThumbnailsUrl(thumbnailUrls.get(episode.getId()));
|
vo.setThumbnailsUrl(thumbnailUrls.get(episode.getId()));
|
||||||
|
if (episode.getVideoAssetId() != null) {
|
||||||
|
vo.setPosterUrl(posterUrls.get(episode.getVideoAssetId()));
|
||||||
|
}
|
||||||
if (free) {
|
if (free) {
|
||||||
// 播放地址统一在这里签名:客户端拿不到可长期复用的裸地址
|
// 播放地址统一在这里签名:客户端拿不到可长期复用的裸地址
|
||||||
vo.setPlayUrl(playbackSigner.sign(playableSource(episode)));
|
vo.setPlayUrl(playbackSigner.sign(playableSource(episode)));
|
||||||
|
|||||||
@@ -24,6 +24,8 @@ public class AppEpisodeVO {
|
|||||||
* 详情页拿到就能直接播,不必按集再请求一次播放票据。
|
* 详情页拿到就能直接播,不必按集再请求一次播放票据。
|
||||||
*/
|
*/
|
||||||
private String playUrl;
|
private String playUrl;
|
||||||
|
/** 高清首帧 poster 地址;没有 READY 媒资时为 null */
|
||||||
|
private String posterUrl;
|
||||||
/** 雪碧图 WebVTT 时间轴地址;没有产物时为 null */
|
/** 雪碧图 WebVTT 时间轴地址;没有产物时为 null */
|
||||||
private String thumbnailsUrl;
|
private String thumbnailsUrl;
|
||||||
}
|
}
|
||||||
+8
-1
@@ -9,6 +9,7 @@ import com.fruitshorts.app.vo.AppBannerVO;
|
|||||||
import com.fruitshorts.app.vo.AppCategoryVO;
|
import com.fruitshorts.app.vo.AppCategoryVO;
|
||||||
import com.fruitshorts.app.vo.AppDramaCardVO;
|
import com.fruitshorts.app.vo.AppDramaCardVO;
|
||||||
import com.fruitshorts.app.vo.AppDramaDetailVO;
|
import com.fruitshorts.app.vo.AppDramaDetailVO;
|
||||||
|
import com.fruitshorts.app.vo.AppEpisodeVO;
|
||||||
import com.fruitshorts.app.vo.AppFeedVO;
|
import com.fruitshorts.app.vo.AppFeedVO;
|
||||||
import com.fruitshorts.app.vo.AppSectionVO;
|
import com.fruitshorts.app.vo.AppSectionVO;
|
||||||
import com.fruitshorts.app.vo.AppRankingEntryVO;
|
import com.fruitshorts.app.vo.AppRankingEntryVO;
|
||||||
@@ -75,6 +76,10 @@ class AppCatalogControllerContractTest {
|
|||||||
card.setLikeCount(3200L);
|
card.setLikeCount(3200L);
|
||||||
card.setFavoriteCount(1800L);
|
card.setFavoriteCount(1800L);
|
||||||
card.setCommentCount(96L);
|
card.setCommentCount(96L);
|
||||||
|
AppEpisodeVO preview = new AppEpisodeVO();
|
||||||
|
preview.setId(21L);
|
||||||
|
preview.setPosterUrl("/files/transcoded/21/poster.jpg?e=1&s=sig");
|
||||||
|
card.setPreview(preview);
|
||||||
AppSectionVO section = new AppSectionVO("hot", "热门推荐", List.of(card));
|
AppSectionVO section = new AppSectionVO("hot", "热门推荐", List.of(card));
|
||||||
AppFeedVO feed = new AppFeedVO(List.of(banner), List.of(section));
|
AppFeedVO feed = new AppFeedVO(List.of(banner), List.of(section));
|
||||||
given(catalogService.homeFeed()).willReturn(feed);
|
given(catalogService.homeFeed()).willReturn(feed);
|
||||||
@@ -88,7 +93,9 @@ class AppCatalogControllerContractTest {
|
|||||||
.andExpect(jsonPath("$.data.sections[0].dramas[0].viewCount").value("12400"))
|
.andExpect(jsonPath("$.data.sections[0].dramas[0].viewCount").value("12400"))
|
||||||
.andExpect(jsonPath("$.data.sections[0].dramas[0].likeCount").value("3200"))
|
.andExpect(jsonPath("$.data.sections[0].dramas[0].likeCount").value("3200"))
|
||||||
.andExpect(jsonPath("$.data.sections[0].dramas[0].favoriteCount").value("1800"))
|
.andExpect(jsonPath("$.data.sections[0].dramas[0].favoriteCount").value("1800"))
|
||||||
.andExpect(jsonPath("$.data.sections[0].dramas[0].commentCount").value("96"));
|
.andExpect(jsonPath("$.data.sections[0].dramas[0].commentCount").value("96"))
|
||||||
|
.andExpect(jsonPath("$.data.sections[0].dramas[0].preview.posterUrl")
|
||||||
|
.value("/files/transcoded/21/poster.jpg?e=1&s=sig"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
+6
-4
@@ -60,10 +60,10 @@ class AppPlaybackContractTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void should_return_free_access_when_episode_is_free() throws Exception {
|
void should_return_free_access_when_episode_is_free() throws Exception {
|
||||||
given(playbackService.play(isNull(), eq(11L), any(), any()))
|
PlayRespVO free = ticket(11L, true, PlaybackService.ACCESS_FREE,
|
||||||
.willReturn(ticket(11L, true, PlaybackService.ACCESS_FREE,
|
"/files/ep.mp4?s=1", "/files/transcoded/11/thumbnails/thumbnails.vtt?e=1&s=sig");
|
||||||
"/files/ep.mp4?s=1",
|
free.setPosterUrl("/files/transcoded/11/poster.jpg?e=1&s=sig");
|
||||||
"/files/transcoded/11/thumbnails/thumbnails.vtt?e=1&s=sig"));
|
given(playbackService.play(isNull(), eq(11L), any(), any())).willReturn(free);
|
||||||
|
|
||||||
mockMvc.perform(get("/app/episodes/11/play").header("X-Device-Id", "device-9"))
|
mockMvc.perform(get("/app/episodes/11/play").header("X-Device-Id", "device-9"))
|
||||||
.andExpect(status().isOk())
|
.andExpect(status().isOk())
|
||||||
@@ -74,6 +74,8 @@ class AppPlaybackContractTest {
|
|||||||
.andExpect(jsonPath("$.data.accessible").value(true))
|
.andExpect(jsonPath("$.data.accessible").value(true))
|
||||||
.andExpect(jsonPath("$.data.accessType").value(PlaybackService.ACCESS_FREE))
|
.andExpect(jsonPath("$.data.accessType").value(PlaybackService.ACCESS_FREE))
|
||||||
.andExpect(jsonPath("$.data.playUrl").value("/files/ep.mp4?s=1"))
|
.andExpect(jsonPath("$.data.playUrl").value("/files/ep.mp4?s=1"))
|
||||||
|
.andExpect(jsonPath("$.data.posterUrl")
|
||||||
|
.value("/files/transcoded/11/poster.jpg?e=1&s=sig"))
|
||||||
.andExpect(jsonPath("$.data.thumbnailsUrl")
|
.andExpect(jsonPath("$.data.thumbnailsUrl")
|
||||||
.value("/files/transcoded/11/thumbnails/thumbnails.vtt?e=1&s=sig"))
|
.value("/files/transcoded/11/thumbnails/thumbnails.vtt?e=1&s=sig"))
|
||||||
.andExpect(jsonPath("$.data.likeCount").value("88"))
|
.andExpect(jsonPath("$.data.likeCount").value("88"))
|
||||||
|
|||||||
+18
-1
@@ -15,6 +15,7 @@ import com.fruitshorts.content.service.DramaService;
|
|||||||
import com.fruitshorts.content.service.EpisodeService;
|
import com.fruitshorts.content.service.EpisodeService;
|
||||||
import com.fruitshorts.interaction.service.CommentService;
|
import com.fruitshorts.interaction.service.CommentService;
|
||||||
import com.fruitshorts.media.service.PlaybackSigner;
|
import com.fruitshorts.media.service.PlaybackSigner;
|
||||||
|
import com.fruitshorts.media.service.PosterUrlResolver;
|
||||||
import com.fruitshorts.media.service.ThumbnailUrlResolver;
|
import com.fruitshorts.media.service.ThumbnailUrlResolver;
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
@@ -40,6 +41,7 @@ class AppCatalogServiceTest {
|
|||||||
private DramaCategoryService dramaCategoryService;
|
private DramaCategoryService dramaCategoryService;
|
||||||
private CommentService commentService;
|
private CommentService commentService;
|
||||||
private ThumbnailUrlResolver thumbnailUrlResolver;
|
private ThumbnailUrlResolver thumbnailUrlResolver;
|
||||||
|
private PosterUrlResolver posterUrlResolver;
|
||||||
private AppCatalogService catalogService;
|
private AppCatalogService catalogService;
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
@@ -53,10 +55,12 @@ class AppCatalogServiceTest {
|
|||||||
PlaybackSigner playbackSigner = mock(PlaybackSigner.class);
|
PlaybackSigner playbackSigner = mock(PlaybackSigner.class);
|
||||||
thumbnailUrlResolver = mock(ThumbnailUrlResolver.class);
|
thumbnailUrlResolver = mock(ThumbnailUrlResolver.class);
|
||||||
given(thumbnailUrlResolver.resolveAll(any())).willReturn(Map.of());
|
given(thumbnailUrlResolver.resolveAll(any())).willReturn(Map.of());
|
||||||
|
posterUrlResolver = mock(PosterUrlResolver.class);
|
||||||
|
given(posterUrlResolver.resolveAll(any())).willReturn(Map.of());
|
||||||
commentService = mock(CommentService.class);
|
commentService = mock(CommentService.class);
|
||||||
catalogService = new AppCatalogService(dramaService, episodeService, bannerService,
|
catalogService = new AppCatalogService(dramaService, episodeService, bannerService,
|
||||||
dramaCategoryService, mock(ContentTagService.class), dramaClassificationService, dramaPlaylistCategoryService,
|
dramaCategoryService, mock(ContentTagService.class), dramaClassificationService, dramaPlaylistCategoryService,
|
||||||
playbackSigner, commentService, thumbnailUrlResolver);
|
playbackSigner, commentService, thumbnailUrlResolver, posterUrlResolver);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -78,6 +82,10 @@ class AppCatalogServiceTest {
|
|||||||
.willReturn(Map.of(11L, 2L, 22L, 4L));
|
.willReturn(Map.of(11L, 2L, 22L, 4L));
|
||||||
given(thumbnailUrlResolver.resolveAll(List.of(11L, 22L)))
|
given(thumbnailUrlResolver.resolveAll(List.of(11L, 22L)))
|
||||||
.willReturn(Map.of(22L, "/files/transcoded/22/thumbnails/thumbnails.vtt"));
|
.willReturn(Map.of(22L, "/files/transcoded/22/thumbnails/thumbnails.vtt"));
|
||||||
|
firstEpisode.setVideoAssetId(101L);
|
||||||
|
secondEpisode.setVideoAssetId(202L);
|
||||||
|
given(posterUrlResolver.resolveAll(List.of(202L, 101L)))
|
||||||
|
.willReturn(Map.of(202L, "/files/transcoded/22/poster.jpg?e=1&s=sig"));
|
||||||
|
|
||||||
AppDramaDetailVO detail = catalogService.dramaDetail(42L);
|
AppDramaDetailVO detail = catalogService.dramaDetail(42L);
|
||||||
|
|
||||||
@@ -89,6 +97,8 @@ class AppCatalogServiceTest {
|
|||||||
assertThat(detail.getEpisodes().get(0).getCommentCount()).isEqualTo(4L);
|
assertThat(detail.getEpisodes().get(0).getCommentCount()).isEqualTo(4L);
|
||||||
assertThat(detail.getEpisodes().get(0).getThumbnailsUrl())
|
assertThat(detail.getEpisodes().get(0).getThumbnailsUrl())
|
||||||
.isEqualTo("/files/transcoded/22/thumbnails/thumbnails.vtt");
|
.isEqualTo("/files/transcoded/22/thumbnails/thumbnails.vtt");
|
||||||
|
assertThat(detail.getEpisodes().get(0).getPosterUrl())
|
||||||
|
.isEqualTo("/files/transcoded/22/poster.jpg?e=1&s=sig");
|
||||||
verify(commentService).countByDrama(42L);
|
verify(commentService).countByDrama(42L);
|
||||||
verify(thumbnailUrlResolver).resolveAll(List.of(11L, 22L));
|
verify(thumbnailUrlResolver).resolveAll(List.of(11L, 22L));
|
||||||
}
|
}
|
||||||
@@ -109,6 +119,8 @@ class AppCatalogServiceTest {
|
|||||||
second.setFavoriteCount(80L);
|
second.setFavoriteCount(80L);
|
||||||
DramaEpisode firstEpisode = episode(11L, 1L, 320L);
|
DramaEpisode firstEpisode = episode(11L, 1L, 320L);
|
||||||
DramaEpisode secondEpisode = episode(22L, 2L, 120L);
|
DramaEpisode secondEpisode = episode(22L, 2L, 120L);
|
||||||
|
firstEpisode.setVideoAssetId(101L);
|
||||||
|
secondEpisode.setVideoAssetId(202L);
|
||||||
Map<Long, DramaEpisode> previews = new LinkedHashMap<>();
|
Map<Long, DramaEpisode> previews = new LinkedHashMap<>();
|
||||||
previews.put(2L, secondEpisode);
|
previews.put(2L, secondEpisode);
|
||||||
previews.put(1L, firstEpisode);
|
previews.put(1L, firstEpisode);
|
||||||
@@ -116,6 +128,8 @@ class AppCatalogServiceTest {
|
|||||||
given(dramaCategoryService.listBasic()).willReturn(List.of());
|
given(dramaCategoryService.listBasic()).willReturn(List.of());
|
||||||
given(commentService.countByEpisodes(List.of(11L, 22L)))
|
given(commentService.countByEpisodes(List.of(11L, 22L)))
|
||||||
.willReturn(Map.of(11L, 9L));
|
.willReturn(Map.of(11L, 9L));
|
||||||
|
given(posterUrlResolver.resolveAll(List.of(202L, 101L)))
|
||||||
|
.willReturn(Map.of(101L, "/files/transcoded/11/poster.jpg?e=1&s=sig"));
|
||||||
|
|
||||||
List<AppDramaCardVO> cards = catalogService.toCards(List.of(first, second));
|
List<AppDramaCardVO> cards = catalogService.toCards(List.of(first, second));
|
||||||
|
|
||||||
@@ -123,10 +137,13 @@ class AppCatalogServiceTest {
|
|||||||
assertThat(cards.get(0).getLikeCount()).isEqualTo(320L);
|
assertThat(cards.get(0).getLikeCount()).isEqualTo(320L);
|
||||||
assertThat(cards.get(0).getFavoriteCount()).isEqualTo(180L);
|
assertThat(cards.get(0).getFavoriteCount()).isEqualTo(180L);
|
||||||
assertThat(cards.get(0).getCommentCount()).isEqualTo(9L);
|
assertThat(cards.get(0).getCommentCount()).isEqualTo(9L);
|
||||||
|
assertThat(cards.get(0).getPreview().getPosterUrl())
|
||||||
|
.isEqualTo("/files/transcoded/11/poster.jpg?e=1&s=sig");
|
||||||
assertThat(cards.get(1).getLikeCount()).isEqualTo(120L);
|
assertThat(cards.get(1).getLikeCount()).isEqualTo(120L);
|
||||||
assertThat(cards.get(1).getFavoriteCount()).isEqualTo(80L);
|
assertThat(cards.get(1).getFavoriteCount()).isEqualTo(80L);
|
||||||
assertThat(cards.get(1).getCommentCount()).isZero();
|
assertThat(cards.get(1).getCommentCount()).isZero();
|
||||||
verify(commentService).countByEpisodes(List.of(11L, 22L));
|
verify(commentService).countByEpisodes(List.of(11L, 22L));
|
||||||
|
verify(posterUrlResolver).resolveAll(List.of(202L, 101L));
|
||||||
verify(commentService, never()).countByDrama(any());
|
verify(commentService, never()).countByDrama(any());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+18
-1
@@ -9,6 +9,7 @@ import com.fruitshorts.content.service.DramaService;
|
|||||||
import com.fruitshorts.content.service.EpisodeService;
|
import com.fruitshorts.content.service.EpisodeService;
|
||||||
import com.fruitshorts.media.dal.entity.MediaRendition;
|
import com.fruitshorts.media.dal.entity.MediaRendition;
|
||||||
import com.fruitshorts.media.service.PlaybackSigner;
|
import com.fruitshorts.media.service.PlaybackSigner;
|
||||||
|
import com.fruitshorts.media.service.PosterUrlResolver;
|
||||||
import com.fruitshorts.media.service.ThumbnailUrlResolver;
|
import com.fruitshorts.media.service.ThumbnailUrlResolver;
|
||||||
import com.fruitshorts.media.service.TranscodeService;
|
import com.fruitshorts.media.service.TranscodeService;
|
||||||
import com.fruitshorts.playback.dal.entity.PlaybackTicket;
|
import com.fruitshorts.playback.dal.entity.PlaybackTicket;
|
||||||
@@ -48,6 +49,7 @@ class PlaybackServiceTest {
|
|||||||
private EntitlementPort entitlementPort;
|
private EntitlementPort entitlementPort;
|
||||||
private TranscodeService transcodeService;
|
private TranscodeService transcodeService;
|
||||||
private ThumbnailUrlResolver thumbnailUrlResolver;
|
private ThumbnailUrlResolver thumbnailUrlResolver;
|
||||||
|
private PosterUrlResolver posterUrlResolver;
|
||||||
private PlaybackService playbackService;
|
private PlaybackService playbackService;
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
@@ -59,11 +61,13 @@ class PlaybackServiceTest {
|
|||||||
entitlementPort = mock(EntitlementPort.class);
|
entitlementPort = mock(EntitlementPort.class);
|
||||||
transcodeService = mock(TranscodeService.class);
|
transcodeService = mock(TranscodeService.class);
|
||||||
thumbnailUrlResolver = mock(ThumbnailUrlResolver.class);
|
thumbnailUrlResolver = mock(ThumbnailUrlResolver.class);
|
||||||
|
posterUrlResolver = mock(PosterUrlResolver.class);
|
||||||
playbackService = new PlaybackService(episodeService, dramaService, ticketMapper, signer,
|
playbackService = new PlaybackService(episodeService, dramaService, ticketMapper, signer,
|
||||||
entitlementPort, transcodeService, thumbnailUrlResolver);
|
entitlementPort, transcodeService, thumbnailUrlResolver, posterUrlResolver);
|
||||||
given(dramaService.getPublished(anyLong())).willReturn(drama());
|
given(dramaService.getPublished(anyLong())).willReturn(drama());
|
||||||
given(transcodeService.listRenditions(anyLong())).willReturn(List.of());
|
given(transcodeService.listRenditions(anyLong())).willReturn(List.of());
|
||||||
given(thumbnailUrlResolver.resolve(anyLong())).willReturn(null);
|
given(thumbnailUrlResolver.resolve(anyLong())).willReturn(null);
|
||||||
|
given(posterUrlResolver.resolve(anyLong())).willReturn(null);
|
||||||
given(signer.sign(anyString())).willReturn("/files/episode/1.mp4?e=1&s=sig");
|
given(signer.sign(anyString())).willReturn("/files/episode/1.mp4?e=1&s=sig");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -92,6 +96,19 @@ class PlaybackServiceTest {
|
|||||||
.isEqualTo("/files/transcoded/1/thumbnails/thumbnails.vtt?e=1&s=sig");
|
.isEqualTo("/files/transcoded/1/thumbnails/thumbnails.vtt?e=1&s=sig");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void should_return_signed_poster_url_when_poster_exists() {
|
||||||
|
DramaEpisode episode = episode(11L, 1, 0, "/files/episode/1.mp4");
|
||||||
|
episode.setVideoAssetId(101L);
|
||||||
|
given(episodeService.getPublished(11L)).willReturn(episode);
|
||||||
|
given(posterUrlResolver.resolve(101L))
|
||||||
|
.willReturn("/files/transcoded/1/poster.jpg?e=1&s=sig");
|
||||||
|
|
||||||
|
PlayRespVO resp = playbackService.play(null, 11L, "device-9", "203.0.113.8");
|
||||||
|
|
||||||
|
assertThat(resp.getPosterUrl()).isEqualTo("/files/transcoded/1/poster.jpg?e=1&s=sig");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void should_return_null_thumbnails_url_when_thumbnail_is_absent() {
|
void should_return_null_thumbnails_url_when_thumbnail_is_absent() {
|
||||||
given(episodeService.getPublished(11L)).willReturn(episode(11L, 1, 0, "/files/episode/1.mp4"));
|
given(episodeService.getPublished(11L)).willReturn(episode(11L, 1, 0, "/files/episode/1.mp4"));
|
||||||
|
|||||||
+54
@@ -0,0 +1,54 @@
|
|||||||
|
// Author: fruit.com.cn
|
||||||
|
|
||||||
|
package com.fruitshorts.media.service;
|
||||||
|
|
||||||
|
import com.fruitshorts.media.dal.entity.MediaAsset;
|
||||||
|
import com.fruitshorts.media.dal.mapper.MediaAssetMapper;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
import org.springframework.util.StringUtils;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/** 把 READY 媒资的高清 poster 解析成公开且已签名的地址。 */
|
||||||
|
@Component
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class PosterUrlResolver {
|
||||||
|
|
||||||
|
private final MediaAssetMapper mediaAssetMapper;
|
||||||
|
private final PlaybackSigner signer;
|
||||||
|
|
||||||
|
/** 单集播放使用。 */
|
||||||
|
public String resolve(Long mediaAssetId) {
|
||||||
|
if (mediaAssetId == null || mediaAssetId <= 0L) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return toUrl(mediaAssetMapper.selectById(mediaAssetId));
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 首页和详情列表批量解析,避免按分集逐条查询媒资。 */
|
||||||
|
public Map<Long, String> resolveAll(Collection<Long> mediaAssetIds) {
|
||||||
|
Map<Long, String> result = new LinkedHashMap<>();
|
||||||
|
if (mediaAssetIds == null || mediaAssetIds.isEmpty()) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
mediaAssetMapper.selectBatchIds(mediaAssetIds).forEach(asset -> {
|
||||||
|
String url = toUrl(asset);
|
||||||
|
if (url != null) {
|
||||||
|
result.put(asset.getId(), url);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String toUrl(MediaAsset asset) {
|
||||||
|
if (asset == null || !TranscodeService.STATUS_SUCCESS.equals(asset.getTranscodeStatus())
|
||||||
|
|| !StringUtils.hasText(asset.getPosterUrl())) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
String signed = signer.sign(asset.getPosterUrl());
|
||||||
|
return StringUtils.hasText(signed) ? signed : null;
|
||||||
|
}
|
||||||
|
}
|
||||||
+65
@@ -0,0 +1,65 @@
|
|||||||
|
// Author: fruit.com.cn
|
||||||
|
|
||||||
|
package com.fruitshorts.media.service;
|
||||||
|
|
||||||
|
import com.fruitshorts.media.dal.entity.MediaAsset;
|
||||||
|
import com.fruitshorts.media.dal.mapper.MediaAssetMapper;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
import static org.mockito.BDDMockito.given;
|
||||||
|
import static org.mockito.Mockito.mock;
|
||||||
|
import static org.mockito.Mockito.never;
|
||||||
|
import static org.mockito.Mockito.verify;
|
||||||
|
|
||||||
|
/** 高清首帧地址解析的签名和空值回退测试。 */
|
||||||
|
class PosterUrlResolverTest {
|
||||||
|
|
||||||
|
private final MediaAssetMapper mapper = mock(MediaAssetMapper.class);
|
||||||
|
private final PlaybackSigner signer = mock(PlaybackSigner.class);
|
||||||
|
private final PosterUrlResolver resolver = new PosterUrlResolver(mapper, signer);
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void should_sign_poster_when_media_is_ready() {
|
||||||
|
MediaAsset asset = asset(11L, "/files/transcoded/11/poster.jpg", TranscodeService.STATUS_SUCCESS);
|
||||||
|
given(mapper.selectById(11L)).willReturn(asset);
|
||||||
|
given(signer.sign(asset.getPosterUrl())).willReturn(asset.getPosterUrl() + "?e=1&s=sig");
|
||||||
|
|
||||||
|
assertThat(resolver.resolve(11L)).isEqualTo("/files/transcoded/11/poster.jpg?e=1&s=sig");
|
||||||
|
verify(signer).sign(asset.getPosterUrl());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void should_return_null_when_media_has_no_ready_poster() {
|
||||||
|
MediaAsset asset = asset(12L, "/files/transcoded/12/poster.jpg", TranscodeService.STATUS_FAILED);
|
||||||
|
given(mapper.selectById(12L)).willReturn(asset);
|
||||||
|
|
||||||
|
assertThat(resolver.resolve(12L)).isNull();
|
||||||
|
assertThat(resolver.resolve(null)).isNull();
|
||||||
|
verify(signer, never()).sign(asset.getPosterUrl());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void should_resolve_posters_in_one_batch_when_assets_are_ready() {
|
||||||
|
MediaAsset ready = asset(11L, "/files/transcoded/11/poster.jpg", TranscodeService.STATUS_SUCCESS);
|
||||||
|
MediaAsset absent = asset(12L, "", TranscodeService.STATUS_SUCCESS);
|
||||||
|
given(mapper.selectBatchIds(List.of(11L, 12L))).willReturn(List.of(ready, absent));
|
||||||
|
given(signer.sign(ready.getPosterUrl())).willReturn(ready.getPosterUrl() + "?e=1&s=sig");
|
||||||
|
|
||||||
|
assertThat(resolver.resolveAll(List.of(11L, 12L)))
|
||||||
|
.isEqualTo(Map.of(11L, "/files/transcoded/11/poster.jpg?e=1&s=sig"));
|
||||||
|
assertThat(resolver.resolveAll(List.of())).isEmpty();
|
||||||
|
verify(mapper).selectBatchIds(List.of(11L, 12L));
|
||||||
|
}
|
||||||
|
|
||||||
|
private MediaAsset asset(Long id, String posterUrl, String status) {
|
||||||
|
MediaAsset asset = new MediaAsset();
|
||||||
|
asset.setId(id);
|
||||||
|
asset.setPosterUrl(posterUrl);
|
||||||
|
asset.setTranscodeStatus(status);
|
||||||
|
return asset;
|
||||||
|
}
|
||||||
|
}
|
||||||
+3
@@ -10,6 +10,7 @@ import com.fruitshorts.content.service.DramaService;
|
|||||||
import com.fruitshorts.content.service.EpisodeService;
|
import com.fruitshorts.content.service.EpisodeService;
|
||||||
import com.fruitshorts.media.dal.entity.MediaRendition;
|
import com.fruitshorts.media.dal.entity.MediaRendition;
|
||||||
import com.fruitshorts.media.service.PlaybackSigner;
|
import com.fruitshorts.media.service.PlaybackSigner;
|
||||||
|
import com.fruitshorts.media.service.PosterUrlResolver;
|
||||||
import com.fruitshorts.media.service.ThumbnailUrlResolver;
|
import com.fruitshorts.media.service.ThumbnailUrlResolver;
|
||||||
import com.fruitshorts.media.service.TranscodeService;
|
import com.fruitshorts.media.service.TranscodeService;
|
||||||
import com.fruitshorts.playback.dal.entity.PlaybackTicket;
|
import com.fruitshorts.playback.dal.entity.PlaybackTicket;
|
||||||
@@ -51,6 +52,7 @@ public class PlaybackService {
|
|||||||
private final EntitlementPort entitlementPort;
|
private final EntitlementPort entitlementPort;
|
||||||
private final TranscodeService transcodeService;
|
private final TranscodeService transcodeService;
|
||||||
private final ThumbnailUrlResolver thumbnailUrlResolver;
|
private final ThumbnailUrlResolver thumbnailUrlResolver;
|
||||||
|
private final PosterUrlResolver posterUrlResolver;
|
||||||
|
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public PlayRespVO play(Long userId, Long episodeId, String deviceId, String clientIp) {
|
public PlayRespVO play(Long userId, Long episodeId, String deviceId, String clientIp) {
|
||||||
@@ -75,6 +77,7 @@ public class PlaybackService {
|
|||||||
vo.setPreviewSeconds(episode.getPreviewSeconds());
|
vo.setPreviewSeconds(episode.getPreviewSeconds());
|
||||||
vo.setQualities(qualitiesOf(episode.getId()));
|
vo.setQualities(qualitiesOf(episode.getId()));
|
||||||
vo.setThumbnailsUrl(thumbnailUrlResolver.resolve(episode.getId()));
|
vo.setThumbnailsUrl(thumbnailUrlResolver.resolve(episode.getId()));
|
||||||
|
vo.setPosterUrl(posterUrlResolver.resolve(episode.getVideoAssetId()));
|
||||||
|
|
||||||
if (!StringUtils.hasText(source)) {
|
if (!StringUtils.hasText(source)) {
|
||||||
// 还没转码或没上传片源:明确告诉客户端"没有片源",而不是给一个播不了的地址
|
// 还没转码或没上传片源:明确告诉客户端"没有片源",而不是给一个播不了的地址
|
||||||
|
|||||||
@@ -25,6 +25,8 @@ public class PlayRespVO {
|
|||||||
private List<String> qualities;
|
private List<String> qualities;
|
||||||
/** 各档签名地址。AUTO 是主播放列表,其余是单档 HLS。 */
|
/** 各档签名地址。AUTO 是主播放列表,其余是单档 HLS。 */
|
||||||
private List<PlayTrackVO> tracks;
|
private List<PlayTrackVO> tracks;
|
||||||
|
/** 高清首帧 poster 地址;没有 READY 媒资时为 null */
|
||||||
|
private String posterUrl;
|
||||||
/** 雪碧图 WebVTT 时间轴地址;没有产物时为 null */
|
/** 雪碧图 WebVTT 时间轴地址;没有产物时为 null */
|
||||||
private String thumbnailsUrl;
|
private String thumbnailsUrl;
|
||||||
/** 需要多少金币解锁 */
|
/** 需要多少金币解锁 */
|
||||||
|
|||||||
Reference in new issue
Block a user