Files
web_huangguo2_h5/app/api/web/play.go
T
2026-09-29 15:30:33 +07:00

306 lines
8.5 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package web
import (
"strings"
"videoweb/app/service/commentser"
"videoweb/app/service/playletser"
"videoweb/app/service/videoser"
"github.com/gin-gonic/gin"
)
// Play 播放页:GET /api/app/playlet/detail + GET /api/app/playlet/chapter/detail。
// 文档:http://172.104.181.99:25319/swagger/index.html#/app短剧相关接口/get_api_app_playlet_detail
func Play(c *gin.Context) {
if c.Request.URL.Query().Has("guessPage") {
NotFound(c)
return
}
q := playletser.ParsePlayQuery(c.Param("slug"), c.Param("ep"))
if strings.TrimSpace(c.Param("ep")) != "" && q.ChapterID <= 0 {
NotFound(c)
return
}
playletKey := c.Param("slug")
playlet := playletser.FetchDetailOrNilByKey(c, playletKey)
if playlet == nil {
NotFound(c)
return
}
chapterID := playletser.ResolvePlayChapterID(playlet, q.ChapterID)
listedChapter := playletser.FindChapter(playlet, chapterID)
if chapterID <= 0 || (q.ChapterID > 0 && listedChapter == nil) {
NotFound(c)
return
}
chapter := playletser.FetchChapterDetailOrNil(c, chapterID, playlet.ID, playlet.Slug)
if chapter == nil {
if listedChapter != nil {
chapter = playletser.ChapterFromList(*listedChapter)
}
}
if chapter == nil {
NotFound(c)
return
}
seo := playletser.ResolvePlayPageSEO(chapter, playlet)
title := playletser.ResolvePlayPageTitle(chapter, playlet)
if title == "" {
title = "在线播放 - 黄果短剧"
}
hot := playletser.FetchAllListOrEmpty(c, playletser.AllListQuery{
PageNum: 1,
PageSize: 8,
SortType: 2, // 最热
UpdateStatus: 0, // 全部
})
hotList := []playletser.CommonData(nil)
if hot != nil {
hotList = hot.List
}
guessPage := playletser.ParseGuessLikePage(c)
guessLike := playletser.FetchGuessLikeListOrEmpty(c, playletser.GuessLikeQuery{
PlayletID: playlet.ID,
PageNum: guessPage,
PageSize: 6,
})
if len(guessLike.List) == 0 && guessPage > 1 {
guessLike = playletser.FetchGuessLikeListOrEmpty(c, playletser.GuessLikeQuery{
PlayletID: playlet.ID,
PageNum: 1,
PageSize: 6,
})
}
commentObjectID := playlet.ID
commentObjectType := commentser.ObjectTypePlaylet
if chapterID > 0 {
commentObjectID = chapterID
commentObjectType = commentser.ObjectTypeChapter
}
comments := commentser.FetchListOrEmpty(c, commentser.ListQuery{
ObjectID: commentObjectID,
ObjectType: commentObjectType,
PageNum: 1,
PageSize: 4,
SortOrder: commentser.SortHot,
})
canWatch := false
episode := 0
if chapter != nil {
canWatch = chapter.AllowWatch()
episode = chapter.CurrentEpisode
}
if episode <= 0 {
for i, item := range playlet.PlayletChapterInfo {
if item.ID != chapterID {
continue
}
episode = item.CurrentEpisode
if episode <= 0 {
episode = i + 1
}
break
}
}
if episode <= 0 {
episode = 1
}
previewURL := strings.TrimSpace(playlet.Preview)
mainURL := ""
if canWatch && chapter != nil {
mainURL = strings.TrimSpace(chapter.VideoURL)
}
data := gin.H{
"title": title,
"navActive": "list",
"seoInfo": seo,
"playlet": playlet,
"chapter": chapter,
"chapterID": chapterID,
"episode": episode,
"canWatch": canWatch,
"mainURL": mainURL,
"previewURL": previewURL,
"hasPreview": previewURL != "",
"nextChapterID": playletser.NextChapterID(playlet, chapterID),
"advitise": playlet.Advitise,
"related": playlet.RelatedRecommendData,
"guessLike": guessLike.List,
"guessPage": guessLike.PageNum,
"guessPageSize": guessLike.PageSize,
"guessTotal": guessLike.TotalCount,
"hotList": hotList,
"hotMoreURL": playletser.AllListURL("all", 0, 0, 2, 1),
"comments": comments.List,
"commentTotal": comments.TotalCount,
"commentPage": comments.PageNum,
"commentSize": comments.PageSize,
"commentObjectID": commentObjectID,
"commentObjectType": commentObjectType,
"playResponse": gin.H{
"playlet": playlet,
"chapter": chapter,
"chapterID": chapterID,
"canWatch": canWatch,
"mainURL": mainURL,
"previewURL": previewURL,
"hasPreview": previewURL != "",
"guessLike": guessLike,
"hotList": hotList,
"comments": comments,
"commentObjectID": commentObjectID,
"commentObjectType": commentObjectType,
},
}
data["canonicalPath"] = playletser.PlayPath(playlet.Slug, playlet.ID)
HTMLOK(c, "play.html", data)
}
// SeriesPlay 视频播放页:GET /api/app/video/detail。
// 文档:http://172.104.181.99:25319/swagger/index.html#/视频相关接口/get_api_app_video_detail
func SeriesPlay(c *gin.Context) {
if c.Request.URL.Query().Has("guessPage") {
NotFound(c)
return
}
key := c.Param("slug")
video := videoser.FetchVideoDetailOrNilByKey(c, key)
if video == nil {
NotFound(c)
return
}
title := videoser.ResolveVideoPageTitle(video)
if title == "" {
title = "在线播放 - 黄果短剧"
} else {
title = title + " - 黄果短剧"
}
cover := video.CoverImg
if cover == "" {
cover = video.Video.Cover
}
videoURL := strings.TrimSpace(video.Video.URL)
canWatch := videoURL != ""
commentObjectID := video.ID
// 视频评论:objectType=20(swagger:10-短剧 11-短剧剧集 20-视频)
commentObjectType := commentser.ObjectTypeVideo
comments := commentser.FetchListOrEmpty(c, commentser.ListQuery{
ObjectID: commentObjectID,
ObjectType: commentObjectType,
PageNum: 1,
PageSize: 4,
SortOrder: commentser.SortHot,
})
if comments.PageNum <= 0 {
comments.PageNum = 1
}
if comments.PageSize <= 0 {
comments.PageSize = 4
}
commentTotal := comments.TotalCount
if commentTotal <= 0 && video.CountComment > 0 {
commentTotal = video.CountComment
}
hot := playletser.FetchAllListOrEmpty(c, playletser.AllListQuery{
PageNum: 1,
PageSize: 8,
SortType: 2, // 最热
UpdateStatus: 0, // 全部
})
hotList := []playletser.CommonData(nil)
if hot != nil {
hotList = hot.List
}
// 视频详情无 recommendVideos:猜你喜欢与 play.html 一致,走短剧同题材推荐。
// 以热榜首部短剧为种子 playletId(排除该剧本身)。
guessPlayletID := int64(0)
if len(hotList) > 0 {
guessPlayletID = hotList[0].ID
}
guessPage := playletser.ParseGuessLikePage(c)
guessLike := playletser.FetchGuessLikeListOrEmpty(c, playletser.GuessLikeQuery{
PlayletID: guessPlayletID,
PageNum: guessPage,
PageSize: 6,
})
if len(guessLike.List) == 0 && guessPage > 1 {
guessLike = playletser.FetchGuessLikeListOrEmpty(c, playletser.GuessLikeQuery{
PlayletID: guessPlayletID,
PageNum: 1,
PageSize: 6,
})
}
data := gin.H{
"title": title,
"navActive": "aiSeries",
"seoInfo": video.SeoInfo,
"video": video,
"videoID": video.ID,
"videoSlug": video.Slug,
"cover": cover,
"videoURL": videoURL,
"canWatch": canWatch,
"guessLike": guessLike.List,
"guessPage": guessLike.PageNum,
"guessPageSize": guessLike.PageSize,
"guessTotal": guessLike.TotalCount,
"guessPlayletID": guessPlayletID,
"advitise": video.Advitise,
"comments": comments.List,
"commentTotal": commentTotal,
"commentPage": comments.PageNum,
"commentSize": comments.PageSize,
"commentObjectID": commentObjectID,
"commentObjectType": commentObjectType,
"hotList": hotList,
"hotMoreURL": playletser.AllListURL("all", 0, 0, 2, 1),
"videoResponse": gin.H{
"video": video,
"videoURL": videoURL,
"canWatch": canWatch,
"comments": comments,
"hotList": hotList,
"guessLike": guessLike,
"guessPlayletID": guessPlayletID,
"commentObjectID": commentObjectID,
"commentObjectType": commentObjectType,
},
"commentDebug": gin.H{
"path": "/api/app/comment/list",
"objectId": commentObjectID,
"objectType": commentObjectType, // 20-视频
"pageNum": comments.PageNum,
"pageSize": comments.PageSize,
"totalCount": commentTotal,
"list": comments.List,
"apis": []string{
"GET /api/app/comment/list",
},
},
"playDebug": gin.H{
"canWatch": canWatch,
"videoURL": videoURL,
"cover": cover,
"videoTime": video.Video.VideoTime,
},
}
if strings.TrimSpace(c.Param("guessPage")) != "" {
data["canonicalPath"] = videoser.VideoPlayURL(video.Slug, video.ID)
}
HTMLOK(c, "seriesPlay.html", data)
}