1
0

preview.go 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. package v1
  2. import (
  3. "fmt"
  4. "github.com/ChineseSubFinder/ChineseSubFinder/pkg/mix_media_info"
  5. "github.com/ChineseSubFinder/ChineseSubFinder/pkg/settings"
  6. "github.com/Tnze/go.num/v2/zh"
  7. "github.com/jinzhu/now"
  8. PTN "github.com/middelink/go-parse-torrent-name"
  9. "net/http"
  10. "strconv"
  11. "github.com/ChineseSubFinder/ChineseSubFinder/pkg/decode"
  12. "github.com/ChineseSubFinder/ChineseSubFinder/pkg"
  13. "github.com/ChineseSubFinder/ChineseSubFinder/pkg/preview_queue"
  14. backend2 "github.com/ChineseSubFinder/ChineseSubFinder/pkg/types/backend"
  15. "github.com/gin-gonic/gin"
  16. )
  17. // PreviewAdd 添加需要预览的任务,弃用
  18. func (cb *ControllerBase) PreviewAdd(c *gin.Context) {
  19. var err error
  20. defer func() {
  21. // 统一的异常处理
  22. cb.ErrorProcess(c, "PreviewAdd", err)
  23. }()
  24. job := preview_queue.Job{}
  25. err = c.ShouldBindJSON(&job)
  26. if err != nil {
  27. return
  28. }
  29. // 暂时不支持蓝光的预览
  30. if pkg.IsFile(job.VideoFPath) == false {
  31. bok, _, _ := decode.IsFakeBDMVWorked(job.VideoFPath)
  32. if bok == true {
  33. c.JSON(http.StatusOK, backend2.ReplyCommon{Message: "not support blu-ray preview"})
  34. return
  35. } else {
  36. c.JSON(http.StatusOK, backend2.ReplyCommon{Message: "video file not found"})
  37. return
  38. }
  39. }
  40. cb.cronHelper.Downloader.PreviewQueue.Add(&job)
  41. c.JSON(http.StatusOK, backend2.ReplyCommon{Message: "ok"})
  42. return
  43. }
  44. // PreviewList 列举预览任务,弃用
  45. func (cb *ControllerBase) PreviewList(c *gin.Context) {
  46. var err error
  47. defer func() {
  48. // 统一的异常处理
  49. cb.ErrorProcess(c, "PreviewList", err)
  50. }()
  51. listJob := cb.cronHelper.Downloader.PreviewQueue.ListJob()
  52. c.JSON(http.StatusOK, preview_queue.Reply{
  53. Jobs: listJob,
  54. })
  55. }
  56. // PreviewIsJobInQueue 预览的任务是否在列表中,或者说是在执行中,弃用
  57. func (cb *ControllerBase) PreviewIsJobInQueue(c *gin.Context) {
  58. var err error
  59. defer func() {
  60. // 统一的异常处理
  61. cb.ErrorProcess(c, "PreviewIsJobInQueue", err)
  62. }()
  63. job := preview_queue.Job{}
  64. err = c.ShouldBindJSON(&job)
  65. if err != nil {
  66. return
  67. }
  68. found := cb.cronHelper.Downloader.PreviewQueue.IsJobInQueue(&preview_queue.Job{
  69. VideoFPath: job.VideoFPath,
  70. })
  71. c.JSON(http.StatusOK, backend2.ReplyCommon{Message: strconv.FormatBool(found)})
  72. return
  73. }
  74. // PreviewJobResult 预览的任务的结果,成功 ok,不存在空,其他是失败,弃用
  75. func (cb *ControllerBase) PreviewJobResult(c *gin.Context) {
  76. var err error
  77. defer func() {
  78. // 统一的异常处理
  79. cb.ErrorProcess(c, "PreviewJobResult", err)
  80. }()
  81. job := preview_queue.Job{}
  82. err = c.ShouldBindJSON(&job)
  83. if err != nil {
  84. return
  85. }
  86. result := cb.cronHelper.Downloader.PreviewQueue.JobResult(&preview_queue.Job{
  87. VideoFPath: job.VideoFPath,
  88. })
  89. c.JSON(http.StatusOK, backend2.ReplyCommon{Message: result})
  90. return
  91. }
  92. // PreviewGetExportInfo 预览的任务的导出信息,弃用
  93. func (cb *ControllerBase) PreviewGetExportInfo(c *gin.Context) {
  94. var err error
  95. defer func() {
  96. // 统一的异常处理
  97. cb.ErrorProcess(c, "PreviewGetExportInfo", err)
  98. }()
  99. job := preview_queue.Job{}
  100. err = c.ShouldBindJSON(&job)
  101. if err != nil {
  102. return
  103. }
  104. m3u8, subPaths, err := cb.cronHelper.Downloader.PreviewQueue.GetVideoHLSAndSubByTimeRangeExportPathInfo(job.VideoFPath, job.SubFPaths, job.StartTime, job.EndTime)
  105. if err != nil {
  106. return
  107. }
  108. c.JSON(http.StatusOK, preview_queue.Job{
  109. VideoFPath: m3u8,
  110. SubFPaths: subPaths,
  111. })
  112. return
  113. }
  114. func (cb *ControllerBase) PreviewCleanUp(c *gin.Context) {
  115. var err error
  116. defer func() {
  117. // 统一的异常处理
  118. cb.ErrorProcess(c, "PreviewCleanUp", err)
  119. }()
  120. if len(cb.cronHelper.Downloader.PreviewQueue.ListJob()) > 0 {
  121. c.JSON(http.StatusOK, backend2.ReplyCommon{Message: "false"})
  122. return
  123. }
  124. err = pkg.ClearVideoAndSubPreviewCacheFolder()
  125. if err != nil {
  126. return
  127. }
  128. c.JSON(http.StatusOK, backend2.ReplyCommon{Message: "true"})
  129. return
  130. }
  131. func (cb *ControllerBase) PreviewSearchOtherWeb(c *gin.Context) {
  132. var err error
  133. defer func() {
  134. // 统一的异常处理
  135. cb.ErrorProcess(c, "PreviewSearchOtherWeb", err)
  136. }()
  137. searchOtherWeb := SearchOtherWebReq{}
  138. err = c.ShouldBindJSON(&searchOtherWeb)
  139. if err != nil {
  140. return
  141. }
  142. if pkg.IsFile(searchOtherWeb.VideoFPath) == false {
  143. c.JSON(http.StatusOK, backend2.ReplyCommon{Message: "video file not found"})
  144. return
  145. }
  146. mixMediaInfo, err := mix_media_info.GetMixMediaInfo(cb.cronHelper.FileDownloader.MediaInfoDealers,
  147. searchOtherWeb.VideoFPath, searchOtherWeb.IsMovie)
  148. if err != nil {
  149. return
  150. }
  151. // 搜索网站的地址
  152. searchOtherWebReply := SearchOtherWebReply{}
  153. searchOtherWebReply.SearchUrls = make([]string, 0)
  154. searchOtherWebReply.SearchUrls = append(searchOtherWebReply.SearchUrls, settings.Get().AdvancedSettings.SuppliersSettings.Zimuku.GetSearchUrl())
  155. searchOtherWebReply.SearchUrls = append(searchOtherWebReply.SearchUrls, settings.Get().AdvancedSettings.SuppliersSettings.SubHD.GetSearchUrl())
  156. searchOtherWebReply.SearchUrls = append(searchOtherWebReply.SearchUrls, settings.Get().AdvancedSettings.SuppliersSettings.A4k.GetSearchUrl())
  157. year, err := now.Parse(mixMediaInfo.Year)
  158. if err != nil {
  159. return
  160. }
  161. strYear := fmt.Sprintf("%d", year.Year())
  162. // 返回多种关键词
  163. searchOtherWebReply.KeyWords = make([]string, 0)
  164. // imdb id
  165. searchOtherWebReply.KeyWords = append(searchOtherWebReply.KeyWords, mixMediaInfo.ImdbId)
  166. if searchOtherWeb.IsMovie == true {
  167. // 电影
  168. searchOtherWebReply.KeyWords = append(searchOtherWebReply.KeyWords, mixMediaInfo.TitleCn)
  169. searchOtherWebReply.KeyWords = append(searchOtherWebReply.KeyWords, mixMediaInfo.TitleCn+" "+strYear)
  170. if mixMediaInfo.TitleCn != mixMediaInfo.TitleEn {
  171. searchOtherWebReply.KeyWords = append(searchOtherWebReply.KeyWords, mixMediaInfo.TitleEn)
  172. searchOtherWebReply.KeyWords = append(searchOtherWebReply.KeyWords, mixMediaInfo.TitleEn+" "+strYear)
  173. }
  174. if mixMediaInfo.TitleCn != mixMediaInfo.OriginalTitle && mixMediaInfo.OriginalTitle != mixMediaInfo.TitleEn {
  175. searchOtherWebReply.KeyWords = append(searchOtherWebReply.KeyWords, mixMediaInfo.OriginalTitle)
  176. searchOtherWebReply.KeyWords = append(searchOtherWebReply.KeyWords, mixMediaInfo.OriginalTitle+" "+strYear)
  177. }
  178. } else {
  179. // 电视剧
  180. var ptn *PTN.TorrentInfo
  181. ptn, err = decode.GetVideoInfoFromFileName(searchOtherWeb.VideoFPath)
  182. if err != nil {
  183. return
  184. }
  185. seasonKeyWord0 := " 第" + zh.Uint64(ptn.Season).String() + "季"
  186. seasonKeyWord1 := fmt.Sprintf(" S%02d", ptn.Season)
  187. seasonKeyWord2 := " " + pkg.GetEpisodeKeyName(ptn.Season, ptn.Episode, true)
  188. searchOtherWebReply.KeyWords = append(searchOtherWebReply.KeyWords, mixMediaInfo.TitleCn)
  189. searchOtherWebReply.KeyWords = append(searchOtherWebReply.KeyWords, mixMediaInfo.TitleCn+seasonKeyWord0)
  190. searchOtherWebReply.KeyWords = append(searchOtherWebReply.KeyWords, mixMediaInfo.TitleCn+seasonKeyWord1)
  191. searchOtherWebReply.KeyWords = append(searchOtherWebReply.KeyWords, mixMediaInfo.TitleCn+seasonKeyWord2)
  192. if mixMediaInfo.TitleCn != mixMediaInfo.TitleEn {
  193. searchOtherWebReply.KeyWords = append(searchOtherWebReply.KeyWords, mixMediaInfo.TitleEn)
  194. searchOtherWebReply.KeyWords = append(searchOtherWebReply.KeyWords, mixMediaInfo.TitleEn+seasonKeyWord0)
  195. searchOtherWebReply.KeyWords = append(searchOtherWebReply.KeyWords, mixMediaInfo.TitleEn+seasonKeyWord1)
  196. searchOtherWebReply.KeyWords = append(searchOtherWebReply.KeyWords, mixMediaInfo.TitleEn+seasonKeyWord2)
  197. }
  198. if mixMediaInfo.TitleCn != mixMediaInfo.OriginalTitle && mixMediaInfo.OriginalTitle != mixMediaInfo.TitleEn {
  199. searchOtherWebReply.KeyWords = append(searchOtherWebReply.KeyWords, mixMediaInfo.OriginalTitle)
  200. searchOtherWebReply.KeyWords = append(searchOtherWebReply.KeyWords, mixMediaInfo.OriginalTitle+seasonKeyWord0)
  201. searchOtherWebReply.KeyWords = append(searchOtherWebReply.KeyWords, mixMediaInfo.OriginalTitle+seasonKeyWord1)
  202. searchOtherWebReply.KeyWords = append(searchOtherWebReply.KeyWords, mixMediaInfo.OriginalTitle+seasonKeyWord2)
  203. }
  204. }
  205. c.JSON(http.StatusOK, searchOtherWebReply)
  206. }
  207. type SearchOtherWebReq struct {
  208. VideoFPath string `json:"video_f_path"`
  209. IsMovie bool `json:"is_movie"`
  210. }
  211. type SearchOtherWebReply struct {
  212. KeyWords []string `json:"key_words"`
  213. SearchUrls []string `json:"search_url"`
  214. }