media.go 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  1. package model
  2. import (
  3. "fmt"
  4. "net/url"
  5. "go-common/library/time"
  6. )
  7. const (
  8. _epFree = 2
  9. )
  10. // SeasonCMS defines the elements could be changed from TV CMS side
  11. type SeasonCMS struct {
  12. SeasonID int64
  13. Cover string
  14. Desc string
  15. Title string
  16. UpInfo string
  17. Category int8 // - cn, jp, movie, tv, documentary
  18. Area string // - cn, jp, others
  19. Playtime time.Time
  20. Role string
  21. Staff string
  22. NewestOrder int // the newest passed ep's order
  23. NewestEPID int64 // the newest passed ep's ID
  24. NewestNb int // the newest ep's number ( after keyword filter )
  25. TotalNum int
  26. Style string
  27. OriginName string
  28. Alias string
  29. PayStatus int
  30. }
  31. // NeedVip returns whether the season need vip to watch
  32. func (s *SeasonCMS) NeedVip() bool {
  33. return s.PayStatus == 1
  34. }
  35. // IdxSn is the structure of season in the index page
  36. func (s *SeasonCMS) IdxSn() (idx *IdxSeason) {
  37. return &IdxSeason{
  38. SeasonID: s.SeasonID,
  39. Title: s.Title,
  40. Cover: s.Cover,
  41. Upinfo: s.UpInfo,
  42. }
  43. }
  44. // EpCMS defines the elements could be changed from TV CMS side
  45. type EpCMS struct {
  46. EPID int64 `json:"epid"`
  47. Cover string `json:"cover"`
  48. Title string `json:"title"`
  49. Subtitle string `json:"subtitle"`
  50. PayStatus int `json:"pay_status"`
  51. }
  52. // IsFree def.
  53. func (v *EpCMS) IsFree() bool {
  54. return v.PayStatus == _epFree
  55. }
  56. // EpDecor is used to decorate ep
  57. type EpDecor struct {
  58. *EpCMS
  59. Watermark bool `json:"watermark"`
  60. }
  61. // ArcCMS reprensents the archive data structure in MC
  62. type ArcCMS struct {
  63. Title string
  64. AID int64
  65. Content string
  66. Cover string
  67. TypeID int
  68. Pubtime time.Time
  69. Videos int
  70. Valid int
  71. Deleted int
  72. Result int
  73. }
  74. // NotDeleted def.
  75. func (s *ArcCMS) NotDeleted() bool {
  76. return s.Deleted == 0
  77. }
  78. // CanPlay returns whether the arc can play or not
  79. func (s *ArcCMS) CanPlay() bool {
  80. return s.Valid == 1 && s.Result == 1 && s.Deleted == 0
  81. }
  82. // VideoCMS def.
  83. type VideoCMS struct {
  84. // Media Info
  85. CID int64
  86. Title string
  87. AID int64
  88. IndexOrder int
  89. // Auth Info
  90. Valid int
  91. Deleted int
  92. Result int
  93. }
  94. // CanPlay returns whether the arc can play or not
  95. func (s *VideoCMS) CanPlay() bool {
  96. return s.Valid == 1 && s.Result == 1 && s.Deleted == 0
  97. }
  98. // NotDeleted def.
  99. func (s *VideoCMS) NotDeleted() bool {
  100. return s.Deleted == 0
  101. }
  102. // Auditing returns whether the video is begin audited by the license owner
  103. func (s *VideoCMS) Auditing() bool {
  104. return s.Result == 0 && s.Deleted == 0
  105. }
  106. // MediaParam def.
  107. type MediaParam struct {
  108. SeasonID int64 `form:"season_id"`
  109. EpID int64 `form:"ep_id"`
  110. TrackPath string `form:"track_path" validate:"required"`
  111. AccessKey string `form:"access_key"`
  112. MobiAPP string `form:"mobi_app" validate:"required"`
  113. Platform string `form:"platform"`
  114. Build int64 `form:"build"`
  115. }
  116. // GenerateUrl generates url.Values from tv media param struct
  117. func (v *MediaParam) GenerateUrl() (params url.Values) {
  118. params = url.Values{}
  119. params.Set("build", fmt.Sprintf("%d", v.Build))
  120. params.Set("mobi_app", v.MobiAPP)
  121. params.Set("platform", v.Platform)
  122. params.Set("access_key", v.AccessKey)
  123. params.Set("track_path", v.TrackPath)
  124. params.Set("season_id", fmt.Sprintf("%d", v.SeasonID))
  125. return
  126. }
  127. // MediaResp is the structure of PGC display api response
  128. type MediaResp struct {
  129. Response
  130. Result *SeasonDetail `json:"result"`
  131. }
  132. // SeasonDetail def
  133. type SeasonDetail struct {
  134. Episodes []*Episode `json:"episodes"`
  135. IsNewDanmaku int `json:"is_new_danmaku"`
  136. NewestEP *NewestEP `json:"newest_ep"`
  137. Stat *Stat `json:"stat"`
  138. UserStatus *UserStatus `json:"user_status"`
  139. Sponsor *Sponsor `json:"sponsor"`
  140. SeriesID int `json:"series_id"`
  141. SnDetailCore
  142. }
  143. // CmsInterv def.
  144. func (v *SnDetailCore) CmsInterv(snCMS *SeasonCMS) {
  145. if snCMS.Title != "" {
  146. v.Title = snCMS.Title
  147. }
  148. if snCMS.Cover != "" {
  149. v.Cover = snCMS.Cover
  150. }
  151. if snCMS.Desc != "" {
  152. v.Evaluate = snCMS.Desc
  153. }
  154. }
  155. // UserStatus def
  156. type UserStatus struct {
  157. Follow int `json:"follow"`
  158. IsVip int `json:"is_vip"`
  159. Pay int `json:"pay"`
  160. PayPackPaid int `json:"pay_pack_paid"`
  161. Sponsor int `json:"sponsor"`
  162. WatchProgress *WatchProgress `json:"watch_progress"`
  163. }
  164. // WatchProgress def.
  165. type WatchProgress struct {
  166. LastEpID int `json:"last_ep_id"`
  167. LastEPIndex string `json:"last_ep_index"`
  168. LastTime int64 `json:"last_time"`
  169. }
  170. // Stat def
  171. type Stat struct {
  172. Danmakus int `json:"danmakus"`
  173. Favorites int `json:"favorites"`
  174. Views int `json:"views"`
  175. }
  176. // List def
  177. type List struct {
  178. Face string `json:"face"`
  179. UID int `json:"uid"`
  180. Uname string `json:"uname"`
  181. }
  182. // Sponsor def
  183. type Sponsor struct {
  184. List []*List `json:"list"`
  185. PointActivity *PointActivity `json:"point_activity"`
  186. TotalBpCount int `json:"total_bp_count"`
  187. WeekBpCount int `json:"week_bp_count"`
  188. }
  189. // PointActivity def
  190. type PointActivity struct {
  191. Content string `json:"content"`
  192. Link string `json:"link"`
  193. Tip string `json:"tip"`
  194. }
  195. // Season def
  196. type Season struct {
  197. SeasonV2
  198. Title string `json:"title"`
  199. }
  200. // SeasonV2 def
  201. type SeasonV2 struct {
  202. IsNew int `json:"is_new"`
  203. SeasonID int `json:"season_id"`
  204. SeasonTitle string `json:"season_title"`
  205. }
  206. // Rights def
  207. type Rights struct {
  208. AllowBp int `json:"allow_bp"`
  209. AllowDownload int `json:"allow_download"`
  210. AllowReview int `json:"allow_review"`
  211. AreaLimit int `json:"area_limit"`
  212. BanAreaShow int `json:"ban_area_show"`
  213. Copyright string `json:"copyright"`
  214. IsPreview int `json:"is_preview"`
  215. }
  216. // Rating def
  217. type Rating struct {
  218. Count int `json:"count"`
  219. Score float64 `json:"score"`
  220. }
  221. // Publish def
  222. type Publish struct {
  223. IsFinish int `json:"is_finish"`
  224. IsStarted int `json:"is_started"`
  225. PubTime string `json:"pub_time"`
  226. PubTimeShow string `json:"pub_time_show"`
  227. Weekday int `json:"weekday"`
  228. }
  229. // Paster def
  230. type Paster struct {
  231. AID int `json:"aid"`
  232. CID int `json:"cid"`
  233. AllowJump int `json:"allow_jump"`
  234. Duration int `json:"duration"`
  235. Type int `json:"type"`
  236. URL string `json:"url"`
  237. }
  238. // NewestEP def
  239. type NewestEP struct {
  240. Desc string `json:"desc"`
  241. ID int `json:"id"`
  242. Index string `json:"index"`
  243. IsNew int `jsontt:"is_new"`
  244. }
  245. // Episode def
  246. type Episode struct {
  247. AID int `json:"aid"`
  248. CID int `json:"cid"`
  249. Cover string `json:"cover"`
  250. EPID int64 `json:"ep_id"`
  251. EpisodeStatus int `json:"episode_status"`
  252. From string `json:"from"`
  253. Index string `json:"index"`
  254. IndexTitle string `json:"index_title"`
  255. MID int `json:"mid"`
  256. Page int `json:"page"`
  257. ShareURL string `json:"share_url"`
  258. VID string `json:"vid"`
  259. WaterMark bool `json:"hidemark"` // true means in the whitelist
  260. }
  261. // CmsInterv def.
  262. func (v *Episode) CmsInterv(epCMS *EpCMS) {
  263. if epCMS.Cover != "" {
  264. v.Cover = epCMS.Cover
  265. }
  266. if epCMS.Title != "" {
  267. v.IndexTitle = epCMS.Title
  268. }
  269. }
  270. // ParamStyle .
  271. type ParamStyle struct {
  272. Name string `json:"name"`
  273. StyleID int `json:"style_id"`
  274. }