result.go 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318
  1. package search
  2. import (
  3. "bytes"
  4. "encoding/json"
  5. "fmt"
  6. // "hash/crc32"
  7. "math"
  8. "regexp"
  9. "strconv"
  10. "strings"
  11. "go-common/app/interface/main/app-interface/model"
  12. bangumimdl "go-common/app/interface/main/app-interface/model/bangumi"
  13. "go-common/app/interface/main/app-interface/model/bplus"
  14. "go-common/app/interface/main/app-interface/model/live"
  15. tagmdl "go-common/app/interface/main/app-interface/model/tag"
  16. article "go-common/app/interface/openplatform/article/model"
  17. account "go-common/app/service/main/account/model"
  18. "go-common/app/service/main/archive/api"
  19. "go-common/app/service/main/archive/model/archive"
  20. seasongrpc "go-common/app/service/openplatform/pgc-season/api/grpc/season/v1"
  21. "go-common/library/log"
  22. xtime "go-common/library/time"
  23. )
  24. var (
  25. getHightLight = regexp.MustCompile(`<em.*?em>`)
  26. payBadge = &model.ReasonStyle{Text: "付费",
  27. TextColor: "#FFFFFFFF",
  28. TextColorNight: "#E5E5E5",
  29. BgColor: "#FAAB4B",
  30. BgColorNight: "#BA833F",
  31. BorderColor: "#FAAB4B",
  32. BorderColorNight: "#BA833F",
  33. BgStyle: BgStyleFill,
  34. }
  35. cooperationBadge = &model.ReasonStyle{Text: "合作",
  36. TextColor: "#FFFFFFFF",
  37. TextColorNight: "#E5E5E5",
  38. BgColor: "#FB7299",
  39. BgColorNight: "#BB5B76",
  40. BorderColor: "#FB7299",
  41. BorderColorNight: "#BB5B76",
  42. BgStyle: BgStyleFill,
  43. }
  44. videoStrongStyle = &model.ReasonStyle{
  45. TextColor: "#FFFFFFFF",
  46. TextColorNight: "#E5E5E5",
  47. BgColor: "#FAAB4B",
  48. BgColorNight: "#BA833F",
  49. BorderColor: "#FAAB4B",
  50. BorderColorNight: "#BA833F",
  51. BgStyle: BgStyleFill,
  52. }
  53. videoWeekStyle = &model.ReasonStyle{
  54. TextColor: "#FAAB4B",
  55. TextColorNight: "#BA833F",
  56. BgColor: "",
  57. BgColorNight: "",
  58. BorderColor: "#FAAB4B",
  59. BorderColorNight: "#BA833F",
  60. BgStyle: BgStyleStroke,
  61. }
  62. )
  63. // search const
  64. const (
  65. _emptyLiveCover = "https://static.hdslb.com/images/transparent.gif"
  66. _emptyLiveCover2 = "https://i0.hdslb.com/bfs/live/0477300d2adf65062a3d1fb7ef92122b82213b0f.png"
  67. StarSpace = 1
  68. StarChannel = 2
  69. BgStyleFill = int8(1)
  70. BgStyleStroke = int8(2)
  71. BgStyleFillAndStroke = int8(3)
  72. BgStyleNoFillAndNoStroke = int8(4)
  73. )
  74. // Result struct
  75. type Result struct {
  76. Trackid string `json:"trackid,omitempty"`
  77. Page int `json:"page,omitempty"`
  78. NavInfo []*NavInfo `json:"nav,omitempty"`
  79. Items ResultItems `json:"items,omitempty"`
  80. Item []*Item `json:"item,omitempty"`
  81. Array int `json:"array,omitempty"`
  82. Attribute int32 `json:"attribute"`
  83. EasterEgg *EasterEgg `json:"easter_egg,omitempty"`
  84. }
  85. // ResultItems struct
  86. type ResultItems struct {
  87. SuggestKeyWord *Item `json:"suggest_keyword,omitempty"`
  88. Operation []*Item `json:"operation,omitempty"`
  89. Season2 []*Item `json:"season2,omitempty"`
  90. Season []*Item `json:"season,omitempty"`
  91. Upper []*Item `json:"upper,omitempty"`
  92. Movie2 []*Item `json:"movie2,omitempty"`
  93. Movie []*Item `json:"movie,omitempty"`
  94. Archive []*Item `json:"archive,omitempty"`
  95. LiveRoom []*Item `json:"live_room,omitempty"`
  96. LiveUser []*Item `json:"live_user,omitempty"`
  97. }
  98. // NavInfo struct
  99. type NavInfo struct {
  100. Name string `json:"name"`
  101. Total int `json:"total"`
  102. Pages int `json:"pages"`
  103. Type int `json:"type"`
  104. Show int `json:"show_more,omitempty"`
  105. }
  106. // TypeSearch struct
  107. type TypeSearch struct {
  108. TrackID string `json:"trackid"`
  109. Pages int `json:"pages"`
  110. Total int `json:"total"`
  111. Items []*Item `json:"items,omitempty"`
  112. }
  113. // TypeSearchLiveAll struct
  114. type TypeSearchLiveAll struct {
  115. TrackID string `json:"trackid"`
  116. Pages int `json:"pages"`
  117. Total int `json:"total"`
  118. Master *TypeSearch `json:"live_master,omitempty"`
  119. Room *TypeSearch `json:"live_room,omitempty"`
  120. }
  121. // Suggestion struct
  122. type Suggestion struct {
  123. TrackID string `json:"trackid"`
  124. UpUser interface{} `json:"upuser,omitempty"`
  125. Bangumi interface{} `json:"bangumi,omitempty"`
  126. Suggest []string `json:"suggest,omitempty"`
  127. }
  128. // Suggestion2 struct
  129. type Suggestion2 struct {
  130. TrackID string `json:"trackid"`
  131. List []*Item `json:"list,omitempty"`
  132. }
  133. // SuggestionResult3 struct
  134. type SuggestionResult3 struct {
  135. TrackID string `json:"trackid"`
  136. List []*Item `json:"list,omitempty"`
  137. }
  138. // RecommendResult struct
  139. type RecommendResult struct {
  140. TrackID string `json:"trackid"`
  141. Title string `json:"title,omitempty"`
  142. Pages int `json:"pages"`
  143. Items []*Item `json:"list,omitempty"`
  144. }
  145. // DefaultWordResult struct
  146. type DefaultWordResult struct {
  147. TrackID string `json:"trackid"`
  148. Title string `json:"title,omitempty"`
  149. Pages int `json:"pages"`
  150. Items []*Item `json:"items,omitempty"`
  151. }
  152. // NoResultRcndResult struct
  153. type NoResultRcndResult struct {
  154. TrackID string `json:"trackid"`
  155. Title string `json:"title,omitempty"`
  156. Pages int `json:"pages"`
  157. Items []*Item `json:"items,omitempty"`
  158. }
  159. // EasterEgg struct
  160. type EasterEgg struct {
  161. ID int64 `json:"id,omitempty"`
  162. ShowCount int `json:"show_count,omitempty"`
  163. }
  164. // RecommendPreResult struct
  165. type RecommendPreResult struct {
  166. TrackID string `json:"trackid"`
  167. Total int `json:"total"`
  168. Items []*Item `json:"items,omitempty"`
  169. }
  170. // Item struct
  171. type Item struct {
  172. TrackID string `json:"trackid,omitempty"`
  173. LinkType string `json:"linktype,omitempty"`
  174. Position int `json:"position,omitempty"`
  175. SuggestKeyword string `json:"suggest_keyword,omitempty"`
  176. Title string `json:"title,omitempty"`
  177. Name string `json:"name,omitempty"`
  178. Cover string `json:"cover,omitempty"`
  179. URI string `json:"uri,omitempty"`
  180. Param string `json:"param,omitempty"`
  181. Goto string `json:"goto,omitempty"`
  182. // av
  183. Play int `json:"play,omitempty"`
  184. Danmaku int `json:"danmaku,omitempty"`
  185. Author string `json:"author,omitempty"`
  186. ViewType string `json:"view_type,omitempty"`
  187. PTime xtime.Time `json:"ptime,omitempty"`
  188. RecTags []string `json:"rec_tags,omitempty"`
  189. IsPay int `json:"is_pay,omitempty"`
  190. NewRecTags []*model.ReasonStyle `json:"new_rec_tags,omitempty"`
  191. // bangumi season
  192. SeasonID int64 `json:"season_id,omitempty"`
  193. SeasonType int `json:"season_type,omitempty"`
  194. SeasonTypeName string `json:"season_type_name,omitempty"`
  195. Finish int8 `json:"finish,omitempty"`
  196. Started int8 `json:"started,omitempty"`
  197. Index string `json:"index,omitempty"`
  198. NewestCat string `json:"newest_cat,omitempty"`
  199. NewestSeason string `json:"newest_season,omitempty"`
  200. CatDesc string `json:"cat_desc,omitempty"`
  201. TotalCount int `json:"total_count,omitempty"`
  202. MediaType int `json:"media_type,omitempty"`
  203. PlayState int `json:"play_state,omitempty"`
  204. Style string `json:"style,omitempty"`
  205. Styles string `json:"styles,omitempty"`
  206. CV string `json:"cv,omitempty"`
  207. Rating float64 `json:"rating,omitempty"`
  208. Vote int `json:"vote,omitempty"`
  209. RatingCount int `json:"rating_count,omitempty"`
  210. // BadgeType int `json:"badge_type,omitempty"`
  211. OutName string `json:"out_name,omitempty"`
  212. OutIcon string `json:"out_icon,omitempty"`
  213. OutURL string `json:"out_url,omitempty"`
  214. // upper
  215. Sign string `json:"sign,omitempty"`
  216. Fans int `json:"fans,omitempty"`
  217. Level int `json:"level,omitempty"`
  218. Desc string `json:"desc,omitempty"`
  219. OfficialVerify *OfficialVerify `json:"official_verify,omitempty"`
  220. AvItems []*Item `json:"av_items,omitempty"`
  221. Item []*Item `json:"item,omitempty"`
  222. CTime int64 `json:"ctime,omitempty"`
  223. IsUp bool `json:"is_up,omitempty"`
  224. LiveURI string `json:"live_uri,omitempty"`
  225. // movie
  226. ScreenDate string `json:"screen_date,omitempty"`
  227. Area string `json:"area,omitempty"`
  228. CoverMark string `json:"cover_mark,omitempty"`
  229. // arc and sp
  230. Arcs int `json:"archives,omitempty"`
  231. // arc and movie
  232. Duration string `json:"duration,omitempty"`
  233. DurationInt int64 `json:"duration_int,omitempty"`
  234. Actors string `json:"actors,omitempty"`
  235. Staff string `json:"staff,omitempty"`
  236. Length int `json:"length,omitempty"`
  237. Status int `json:"status,omitempty"`
  238. // live
  239. RoomID int64 `json:"roomid,omitempty"`
  240. Mid int64 `json:"mid,omitempty"`
  241. Type string `json:"type,omitempty"`
  242. Attentions int `json:"attentions,omitempty"`
  243. LiveStatus int `json:"live_status,omitempty"`
  244. Tags string `json:"tags,omitempty"`
  245. Region int `json:"region,omitempty"`
  246. Online int `json:"online,omitempty"`
  247. ShortID int `json:"short_id,omitempty"`
  248. CateName string `json:"area_v2_name,omitempty"`
  249. IsSelection int `json:"is_selection,omitempty"`
  250. // article
  251. ID int64 `json:"id,omitempty"`
  252. TemplateID int `json:"template_id,omitempty"`
  253. ImageUrls []string `json:"image_urls,omitempty"`
  254. View int `json:"view,omitempty"`
  255. Like int `json:"like,omitempty"`
  256. Reply int `json:"reply,omitempty"`
  257. // special
  258. Badge string `json:"badge,omitempty"`
  259. RcmdReason *RcmdReason `json:"rcmd_reason,omitempty"`
  260. // media bangumi and mdeia ft
  261. Prompt string `json:"prompt,omitempty"`
  262. Episodes []*Item `json:"episodes,omitempty"`
  263. Label string `json:"label,omitempty"`
  264. // game
  265. Reserve string `json:"reserve,omitempty"`
  266. // user
  267. Face string `json:"face,omitempty"`
  268. // suggest
  269. From string `json:"from,omitempty"`
  270. KeyWord string `json:"keyword,omitempty"`
  271. CoverSize float64 `json:"cover_size,omitempty"`
  272. SugType string `json:"sug_type,omitempty"`
  273. TermType int `json:"term_type,omitempty"`
  274. // rcmd query
  275. List []*Item `json:"list,omitempty"`
  276. FromSource string `json:"from_source,omitempty"`
  277. // live master
  278. UCover string `json:"ucover,omitempty"`
  279. VerifyType int `json:"verify_type,omitempty"`
  280. VerifyDesc string `json:"verify_desc,omitempty"`
  281. LevelColor int64 `json:"level_color,omitempty"`
  282. IsAttention int `json:"is_atten,omitempty"`
  283. CateParentName string `json:"cate_parent_name,omitempty"`
  284. CateNameNew string `json:"cate_name,omitempty"`
  285. Glory *Glory `json:"glory_info,omitempty"`
  286. // twitter
  287. Covers []string `json:"covers,omitempty"`
  288. CoverCount int `json:"cover_count,omitempty"`
  289. Upper *Item `json:"upper,omitempty"`
  290. State *Item `json:"stat,omitempty"`
  291. // star
  292. TagItems []*Item `json:"tag_items,omitempty"`
  293. TagID int64 `json:"tag_id,omitempty"`
  294. URIType int `json:"uri_type,omitempty"`
  295. // ticket
  296. ShowTime string `json:"show_time,omitempty"`
  297. City string `json:"city,omitempty"`
  298. Venue string `json:"venue,omitempty"`
  299. Price int `json:"price,omitempty"`
  300. PriceComplete string `json:"price_complete,omitempty"`
  301. PriceType int `json:"price_type,omitempty"`
  302. ReqNum int `json:"required_number,omitempty"`
  303. // product
  304. ShopName string `json:"shop_name,omitempty"`
  305. // specialer_guide
  306. Phone string `json:"phone,omitempty"`
  307. Badges []*model.ReasonStyle `json:"badges,omitempty"`
  308. ComicURL string `json:"comic_url,omitempty"`
  309. // suggest_keyword
  310. SugKeyWordType int `json:"sugKeyWord_type,omitempty"`
  311. }
  312. // Glory live struct
  313. type Glory struct {
  314. Title string `json:"title,omitempty"`
  315. Total int `json:"total"`
  316. Items []*Item `json:"items,omitempty"`
  317. }
  318. // RcmdReason struct
  319. type RcmdReason struct {
  320. Content string `json:"content,omitempty"`
  321. }
  322. // UserResult struct
  323. type UserResult struct {
  324. Items []*Item `json:"items,omitempty"`
  325. }
  326. // DefaultWords struct
  327. type DefaultWords struct {
  328. Trackid string `json:"trackid,omitempty"`
  329. Param string `json:"param,omitempty"`
  330. Show string `json:"show,omitempty"`
  331. Word string `json:"word,omitempty"`
  332. ShowFront int `json:"show_front,omitempty"`
  333. }
  334. // FromSeason form func
  335. func (i *Item) FromSeason(b *Bangumi, bangumi string) {
  336. i.Title = b.Title
  337. i.Cover = b.Cover
  338. i.Goto = model.GotoBangumi
  339. i.Param = strconv.Itoa(int(b.SeasonID))
  340. i.URI = model.FillURI(bangumi, i.Param, nil)
  341. i.Finish = int8(b.IsFinish)
  342. i.Started = int8(b.IsStarted)
  343. i.Index = b.NewestEpIndex
  344. i.NewestCat = b.NewestCat
  345. i.NewestSeason = b.NewestSeason
  346. i.TotalCount = b.TotalCount
  347. var buf bytes.Buffer
  348. if b.CatList.TV != 0 {
  349. buf.WriteString(`TV(`)
  350. buf.WriteString(strconv.Itoa(b.CatList.TV))
  351. buf.WriteString(`) `)
  352. }
  353. if b.CatList.Movie != 0 {
  354. buf.WriteString(`剧场版(`)
  355. buf.WriteString(strconv.Itoa(b.CatList.Movie))
  356. buf.WriteString(`) `)
  357. }
  358. if b.CatList.Ova != 0 {
  359. buf.WriteString(`OVA/OAD/SP(`)
  360. buf.WriteString(strconv.Itoa(b.CatList.Ova))
  361. buf.WriteString(`)`)
  362. }
  363. i.CatDesc = buf.String()
  364. }
  365. // FromUpUser form func
  366. func (i *Item) FromUpUser(u *User, as map[int64]*api.Arc, lv *live.RoomInfo) {
  367. i.Title = u.Name
  368. i.Cover = u.Pic
  369. i.Goto = model.GotoAuthor
  370. i.OfficialVerify = u.OfficialVerify
  371. i.Param = strconv.Itoa(int(u.Mid))
  372. i.URI = model.FillURI(i.Goto, i.Param, nil)
  373. i.Mid = u.Mid
  374. i.Sign = u.Usign
  375. i.Fans = u.Fans
  376. i.Level = u.Level
  377. i.Arcs = u.Videos
  378. i.AvItems = make([]*Item, 0, len(u.Res))
  379. for _, v := range u.Res {
  380. vi := &Item{}
  381. vi.Title = v.Title
  382. vi.Cover = v.Pic
  383. vi.Goto = model.GotoAv
  384. vi.Param = strconv.Itoa(int(v.Aid))
  385. vi.URI = model.FillURI(vi.Goto, vi.Param, model.AvHandler(archive.BuildArchive3(as[v.Aid])))
  386. a, ok := as[v.Aid]
  387. if ok {
  388. vi.Play = int(a.Stat.View)
  389. vi.Danmaku = int(a.Stat.Danmaku)
  390. if a.Rights.UGCPay == 1 {
  391. vi.Badges = append(vi.Badges, payBadge)
  392. }
  393. if a.Rights.IsCooperation == 1 {
  394. vi.Badges = append(vi.Badges, cooperationBadge)
  395. }
  396. } else {
  397. switch play := v.Play.(type) {
  398. case float64:
  399. vi.Play = int(play)
  400. case string:
  401. vi.Play, _ = strconv.Atoi(play)
  402. }
  403. vi.Danmaku = v.Danmaku
  404. }
  405. vi.IsPay = v.IsPay
  406. vi.CTime = v.Pubdate
  407. vi.Duration = v.Duration
  408. i.AvItems = append(i.AvItems, vi)
  409. }
  410. i.LiveStatus = u.IsLive
  411. i.RoomID = u.RoomID
  412. i.IsUp = u.IsUpuser == 1
  413. if i.RoomID != 0 {
  414. i.LiveURI = model.FillURI(model.GotoLive, strconv.Itoa(int(u.RoomID)), model.LiveHandler(lv))
  415. }
  416. }
  417. // FromUser form func
  418. func (i *Item) FromUser(u *User, as map[int64]*api.Arc, lv *live.RoomInfo) {
  419. i.Title = u.Name
  420. i.Cover = u.Pic
  421. i.Goto = model.GotoAuthor
  422. i.OfficialVerify = u.OfficialVerify
  423. i.Param = strconv.Itoa(int(u.Mid))
  424. i.URI = model.FillURI(i.Goto, i.Param, nil)
  425. i.Mid = u.Mid
  426. i.Sign = u.Usign
  427. i.Fans = u.Fans
  428. i.Level = u.Level
  429. i.Arcs = u.Videos
  430. i.AvItems = make([]*Item, 0, len(u.Res))
  431. i.LiveStatus = u.IsLive
  432. i.RoomID = u.RoomID
  433. if i.RoomID != 0 {
  434. i.LiveURI = model.FillURI(model.GotoLive, strconv.Itoa(int(u.RoomID)), model.LiveHandler(lv))
  435. }
  436. if u.IsUpuser == 1 {
  437. for _, v := range u.Res {
  438. vi := &Item{}
  439. vi.Title = v.Title
  440. vi.Cover = v.Pic
  441. vi.Goto = model.GotoAv
  442. vi.Param = strconv.Itoa(int(v.Aid))
  443. vi.URI = model.FillURI(vi.Goto, vi.Param, model.AvHandler(archive.BuildArchive3(as[v.Aid])))
  444. a, ok := as[v.Aid]
  445. if ok {
  446. vi.Play = int(a.Stat.View)
  447. vi.Danmaku = int(a.Stat.Danmaku)
  448. if a.Rights.UGCPay == 1 {
  449. vi.Badges = append(vi.Badges, payBadge)
  450. }
  451. if a.Rights.IsCooperation == 1 {
  452. vi.Badges = append(vi.Badges, cooperationBadge)
  453. }
  454. } else {
  455. switch play := v.Play.(type) {
  456. case float64:
  457. vi.Play = int(play)
  458. case string:
  459. vi.Play, _ = strconv.Atoi(play)
  460. }
  461. vi.Danmaku = v.Danmaku
  462. }
  463. vi.IsPay = v.IsPay
  464. vi.CTime = v.Pubdate
  465. vi.Duration = v.Duration
  466. i.AvItems = append(i.AvItems, vi)
  467. }
  468. i.IsUp = true
  469. }
  470. }
  471. // FromMovie form func
  472. func (i *Item) FromMovie(m *Movie, as map[int64]*api.Arc) {
  473. i.Title = m.Title
  474. i.Desc = m.Desc
  475. if m.Type == "movie" {
  476. i.Cover = m.Cover
  477. i.Param = strconv.Itoa(int(m.Aid))
  478. i.Goto = model.GotoAv
  479. i.URI = model.FillURI(i.Goto, i.Param, model.AvHandler(archive.BuildArchive3(as[m.Aid])))
  480. i.CoverMark = model.StatusMark(m.Status)
  481. } else if m.Type == "special" {
  482. i.Param = m.SpID
  483. i.Goto = model.GotoSp
  484. i.URI = model.FillURI(i.Goto, i.Param, nil)
  485. i.Cover = m.Pic
  486. }
  487. i.Staff = m.Staff
  488. i.Actors = m.Actors
  489. i.Area = m.Area
  490. i.Length = m.Length
  491. i.Status = m.Status
  492. i.ScreenDate = m.ScreenDate
  493. }
  494. // FromVideo form func
  495. func (i *Item) FromVideo(v *Video, a *api.Arc, cooperation bool) {
  496. i.Title = v.Title
  497. i.Cover = v.Pic
  498. i.Author = v.Author
  499. i.Param = strconv.Itoa(int(v.ID))
  500. i.Goto = model.GotoAv
  501. if a != nil {
  502. i.Face = a.Author.Face
  503. i.URI = model.FillURI(i.Goto, i.Param, model.AvHandler(archive.BuildArchive3(a)))
  504. i.Play = int(a.Stat.View)
  505. i.Danmaku = int(a.Stat.Danmaku)
  506. i.Mid = a.Author.Mid
  507. if a.Rights.UGCPay == 1 {
  508. i.Badges = append(i.Badges, payBadge)
  509. }
  510. if a.Rights.IsCooperation == 1 {
  511. i.Badges = append(i.Badges, cooperationBadge)
  512. if i.Author != "" && cooperation {
  513. i.Author += " 等联合创作"
  514. }
  515. }
  516. } else {
  517. i.URI = model.FillURI(i.Goto, i.Param, nil)
  518. switch play := v.Play.(type) {
  519. case float64:
  520. i.Play = int(play)
  521. case string:
  522. i.Play, _ = strconv.Atoi(play)
  523. }
  524. i.Danmaku = v.Danmaku
  525. }
  526. i.IsPay = v.IsPay
  527. i.Desc = v.Desc
  528. i.Duration = v.Duration
  529. i.ViewType = v.ViewType
  530. i.RecTags = v.RecTags
  531. for _, r := range v.NewRecTags {
  532. if r.Name != "" {
  533. switch r.Style {
  534. case BgStyleFill:
  535. videoStrongStyle.Text = r.Name
  536. i.NewRecTags = append(i.NewRecTags, videoStrongStyle)
  537. case BgStyleStroke:
  538. videoWeekStyle.Text = r.Name
  539. i.NewRecTags = append(i.NewRecTags, videoWeekStyle)
  540. }
  541. }
  542. }
  543. }
  544. // FromLive form func
  545. func (i *Item) FromLive(l *Live, lv *live.RoomInfo) {
  546. i.RoomID = l.RoomID
  547. i.Mid = l.UID
  548. i.Title = l.Title
  549. i.Type = l.Type
  550. if l.Cover == "" {
  551. i.Cover = l.Uface
  552. } else {
  553. i.Cover = l.Cover
  554. }
  555. i.Name = l.Uname
  556. i.Online = l.Online
  557. i.Attentions = l.Attentions
  558. i.Goto = model.GotoLive
  559. if i.Type == "live_user" {
  560. i.Param = strconv.Itoa(int(i.Mid))
  561. } else {
  562. i.Param = strconv.Itoa(int(i.RoomID))
  563. }
  564. i.URI = model.FillURI(i.Goto, i.Param, model.LiveHandler(lv))
  565. i.Tags = l.Tags
  566. i.Region = l.Area
  567. i.Badge = "直播"
  568. }
  569. // FromLive2 form func
  570. func (i *Item) FromLive2(l *Live, lv *live.RoomInfo) {
  571. i.RoomID = l.RoomID
  572. i.Mid = l.UID
  573. i.Title = l.Title
  574. i.Type = l.Type
  575. if l.UserCover != "" && l.UserCover != _emptyLiveCover {
  576. i.Cover = l.UserCover
  577. } else if l.Cover != "" && l.Cover != _emptyLiveCover {
  578. i.Cover = l.Cover
  579. } else {
  580. i.Cover = _emptyLiveCover2
  581. }
  582. i.Name = l.Uname
  583. i.Online = l.Online
  584. i.Attentions = l.Attentions
  585. i.Goto = model.GotoLive
  586. if i.Type == "live_user" {
  587. i.Param = strconv.Itoa(int(i.Mid))
  588. } else {
  589. i.Param = strconv.Itoa(int(i.RoomID))
  590. }
  591. i.URI = model.FillURI(i.Goto, i.Param, model.LiveHandler(lv))
  592. i.Tags = l.Tags
  593. i.Region = l.Area
  594. i.Badge = "直播"
  595. i.ShortID = l.ShortID
  596. i.CateName = l.CateName
  597. i.LiveStatus = l.LiveStatus
  598. }
  599. // FromArticle form func
  600. func (i *Item) FromArticle(a *Article, acc *account.Info) {
  601. i.ID = a.ID
  602. i.Mid = a.Mid
  603. if acc != nil {
  604. i.Author = acc.Name
  605. }
  606. i.TemplateID = a.TemplateID
  607. i.Title = a.Title
  608. i.Desc = a.Desc
  609. i.ImageUrls = a.ImageUrls
  610. i.View = a.View
  611. i.Play = a.View
  612. i.Like = a.Like
  613. i.Reply = a.Reply
  614. i.Badge = "专栏"
  615. i.Goto = model.GotoArticle
  616. i.Param = strconv.Itoa(int(a.ID))
  617. i.URI = model.FillURI(i.Goto, i.Param, nil)
  618. }
  619. // FromOperate form func
  620. func (i *Item) FromOperate(o *Operate, gt string) {
  621. i.Title = o.Title
  622. i.Cover = o.Cover
  623. i.URI = o.RedirectURL
  624. i.Param = strconv.FormatInt(o.ID, 10)
  625. i.Desc = o.Desc
  626. i.Badge = o.Corner
  627. i.Goto = gt
  628. if o.RecReason != "" {
  629. i.RcmdReason = &RcmdReason{Content: o.RecReason}
  630. }
  631. }
  632. // FromConverge form func
  633. func (i *Item) FromConverge(o *Operate, am map[int64]*api.Arc, rm map[int64]*live.Room, artm map[int64]*article.Meta) {
  634. const _convergeMinCount = 2
  635. cis := make([]*Item, 0, len(o.ContentList))
  636. for _, c := range o.ContentList {
  637. ci := &Item{}
  638. switch c.Type {
  639. case 0:
  640. if a, ok := am[c.ID]; ok && a.IsNormal() {
  641. ci.Title = a.Title
  642. ci.Cover = a.Pic
  643. ci.Goto = model.GotoAv
  644. ci.Param = strconv.FormatInt(a.Aid, 10)
  645. ci.URI = model.FillURI(ci.Goto, ci.Param, model.AvHandler(archive.BuildArchive3(a)))
  646. ci.fillArcStat(a)
  647. cis = append(cis, ci)
  648. }
  649. case 1:
  650. if r, ok := rm[c.ID]; ok {
  651. if r.LiveStatus == 0 {
  652. continue
  653. }
  654. ci.Title = r.Title
  655. ci.Cover = r.Cover
  656. ci.Goto = model.GotoLive
  657. ci.Param = strconv.FormatInt(r.RoomID, 10)
  658. ci.Online = r.Online
  659. ci.URI = model.FillURI(ci.Goto, ci.Param, nil) + "?broadcast_type=" + strconv.Itoa(r.BroadcastType)
  660. ci.Badge = "直播"
  661. cis = append(cis, ci)
  662. }
  663. case 2:
  664. if art, ok := artm[c.ID]; ok {
  665. ci.Title = art.Title
  666. ci.Desc = art.Summary
  667. if len(art.ImageURLs) != 0 {
  668. ci.Cover = art.ImageURLs[0]
  669. }
  670. ci.Goto = model.GotoArticle
  671. ci.Param = strconv.FormatInt(art.ID, 10)
  672. ci.URI = model.FillURI(ci.Goto, ci.Param, nil)
  673. if art.Stats != nil {
  674. ci.fillArtStat(art)
  675. }
  676. ci.Badge = "文章"
  677. cis = append(cis, ci)
  678. }
  679. }
  680. }
  681. if len(cis) < _convergeMinCount {
  682. return
  683. }
  684. i.Item = cis
  685. i.Title = o.Title
  686. i.Cover = o.Cover
  687. i.URI = o.RedirectURL
  688. i.Param = strconv.FormatInt(o.ID, 10)
  689. i.Desc = o.Desc
  690. i.Badge = o.Corner
  691. i.Goto = model.GotoConverge
  692. if o.RecReason != "" {
  693. i.RcmdReason = &RcmdReason{Content: o.RecReason}
  694. }
  695. }
  696. // FromMedia form func
  697. func (i *Item) FromMedia(m *Media, prompt string, gt string, bangumis map[string]*bangumimdl.Card) {
  698. i.Title = m.Title
  699. if i.Title == "" {
  700. i.Title = m.OrgTitle
  701. }
  702. i.Cover = m.Cover
  703. i.Goto = gt
  704. i.Param = strconv.Itoa(int(m.MediaID))
  705. i.URI = m.GotoURL
  706. i.MediaType = m.MediaType
  707. i.PlayState = m.PlayState
  708. i.Style = m.Styles
  709. i.CV = m.CV
  710. i.Staff = m.Staff
  711. if m.MediaScore != nil {
  712. i.Rating = m.MediaScore.Score
  713. i.Vote = m.MediaScore.UserCount
  714. }
  715. i.PTime = m.Pubtime
  716. areas := strings.Split(m.Areas, "、")
  717. if len(areas) != 0 {
  718. i.Area = areas[0]
  719. }
  720. i.Prompt = prompt
  721. i.OutName = m.AllNetName
  722. i.OutIcon = m.AllNetIcon
  723. i.OutURL = m.AllNetURL
  724. var hit string
  725. for _, v := range m.HitColumns {
  726. if v == "cv" {
  727. hit = v
  728. break
  729. } else if v == "staff" {
  730. hit = v
  731. }
  732. }
  733. if hit == "cv" {
  734. for _, v := range getHightLight.FindAllStringSubmatch(m.CV, -1) {
  735. if m.MediaType == 7 {
  736. i.Label = fmt.Sprintf("嘉宾: %v...", v[0])
  737. break
  738. }
  739. if gt == model.GotoBangumi {
  740. i.Label = fmt.Sprintf("声优: %v...", v[0])
  741. break
  742. } else if gt == model.GotoMovie {
  743. i.Label = fmt.Sprintf("演员: %v...", v[0])
  744. break
  745. }
  746. }
  747. } else if hit == "staff" {
  748. for _, v := range getHightLight.FindAllStringSubmatch(m.Staff, -1) {
  749. i.Label = fmt.Sprintf("制作人员: %v...", v[0])
  750. break
  751. }
  752. } else if hit == "" {
  753. i.Label = FormPGCLabel(m.MediaType, m.Styles, m.Staff, m.CV)
  754. }
  755. // get from PGC API.
  756. i.SeasonID = m.SeasonID
  757. ssID := strconv.Itoa(int(m.SeasonID))
  758. if bgm, ok := bangumis[ssID]; ok {
  759. i.Badge = model.FormMediaType(bgm.SeasonType)
  760. i.SeasonTypeName = bgm.SeasonTypeName
  761. i.IsAttention = bgm.IsFollow
  762. i.IsSelection = bgm.IsSelection
  763. i.SeasonType = bgm.SeasonType
  764. for _, v := range bgm.Episodes {
  765. tmp := &Item{
  766. Param: strconv.Itoa(int(v.ID)),
  767. Index: v.Index,
  768. Badges: v.Badges,
  769. }
  770. tmp.URI = model.FillURI(model.GotoEP, tmp.Param, nil)
  771. i.Episodes = append(i.Episodes, tmp)
  772. }
  773. }
  774. var (
  775. badges []*model.ReasonStyle
  776. err error
  777. )
  778. err = json.Unmarshal(m.DisplayInfo, &badges)
  779. if err != nil {
  780. log.Error("%v", err)
  781. return
  782. }
  783. i.Badges = badges
  784. }
  785. // FromGame form func
  786. func (i *Item) FromGame(g *Game) {
  787. i.Title = g.Title
  788. i.Cover = g.Cover
  789. i.Desc = g.Desc
  790. i.Rating = g.View
  791. var reserve string
  792. if g.Status == 1 || g.Status == 2 {
  793. if g.Like < 10000 {
  794. reserve = strconv.FormatInt(g.Like, 10) + "人预约"
  795. } else {
  796. reserve = strconv.FormatFloat(float64(g.Like)/10000, 'f', 1, 64) + "万人预约"
  797. }
  798. }
  799. i.Reserve = reserve
  800. i.Goto = model.GotoGame
  801. i.Param = strconv.FormatInt(g.ID, 10)
  802. i.URI = g.RedirectURL
  803. }
  804. // fillArcStat fill func
  805. func (i *Item) fillArcStat(a *api.Arc) {
  806. if a.Access == 0 {
  807. i.Play = int(a.Stat.View)
  808. }
  809. i.Danmaku = int(a.Stat.Danmaku)
  810. i.Reply = int(a.Stat.Reply)
  811. i.Like = int(a.Stat.Like)
  812. }
  813. // fillArtStat fill func
  814. func (i *Item) fillArtStat(m *article.Meta) {
  815. i.Play = int(m.Stats.View)
  816. i.Reply = int(m.Stats.Reply)
  817. }
  818. // FromSuggest form func
  819. func (i *Item) FromSuggest(st *SuggestTag) {
  820. i.From = "search"
  821. if st.SpID == SuggestionJump {
  822. switch st.Type {
  823. case SuggestionAV:
  824. i.Title = st.Value
  825. i.Goto = model.GotoAv
  826. i.URI = model.FillURI(i.Goto, strconv.Itoa(int(st.Ref)), nil)
  827. case SuggestionLive:
  828. i.Title = st.Value
  829. i.Goto = model.GotoLive
  830. i.URI = model.FillURI(i.Goto, strconv.Itoa(int(st.Ref)), nil)
  831. }
  832. } else {
  833. i.Title = st.Value
  834. }
  835. }
  836. // FromSuggest2 form func
  837. func (i *Item) FromSuggest2(st *SuggestTag, as map[int64]*api.Arc, ls map[int64]*live.RoomInfo) {
  838. i.From = "search"
  839. if st.SpID == SuggestionJump {
  840. switch st.Type {
  841. case SuggestionAV:
  842. i.Title = st.Value
  843. i.Goto = model.GotoAv
  844. i.URI = model.FillURI(i.Goto, strconv.Itoa(int(st.Ref)), model.AvHandler(archive.BuildArchive3(as[st.Ref])))
  845. case SuggestionLive:
  846. var (
  847. l *live.RoomInfo
  848. ok bool
  849. )
  850. i.Title = st.Value
  851. i.Goto = model.GotoLive
  852. if l, ok = ls[st.Ref]; !ok {
  853. for _, v := range ls {
  854. if v.ShortID == st.Ref {
  855. l = v
  856. break
  857. }
  858. }
  859. }
  860. i.URI = model.FillURI(i.Goto, strconv.Itoa(int(st.Ref)), model.LiveHandler(l))
  861. if strings.Contains(i.URI, "broadcast_type") {
  862. i.URI += "&extra_jump_from=23004"
  863. } else {
  864. i.URI += "?extra_jump_from=23004"
  865. }
  866. }
  867. } else {
  868. i.Title = st.Value
  869. }
  870. }
  871. // FromSuggest3 form func
  872. func (i *Item) FromSuggest3(st *Sug, as map[int64]*api.Arc, ls map[int64]*live.RoomInfo) {
  873. i.From = "search"
  874. i.Title = st.ShowName
  875. i.KeyWord = st.Term
  876. i.Position = st.Pos
  877. i.Cover = st.Cover
  878. i.CoverSize = st.CoverSize
  879. i.SugType = st.SubType
  880. i.TermType = st.TermType
  881. if st.TermType == SuggestionJump {
  882. switch st.SubType {
  883. case SuggestionAV:
  884. i.Goto = model.GotoAv
  885. i.URI = model.FillURI(i.Goto, strconv.Itoa(int(st.Ref)), model.AvHandler(archive.BuildArchive3(as[st.Ref])))
  886. i.SugType = "视频"
  887. case SuggestionLive:
  888. var (
  889. l *live.RoomInfo
  890. ok bool
  891. )
  892. i.Goto = model.GotoLive
  893. if l, ok = ls[st.Ref]; !ok {
  894. for _, v := range ls {
  895. if v.ShortID == st.Ref {
  896. l = v
  897. break
  898. }
  899. }
  900. }
  901. i.URI = model.FillURI(i.Goto, strconv.Itoa(int(st.Ref)), model.LiveHandler(l))
  902. if strings.Contains(i.URI, "broadcast_type") {
  903. i.URI += "&extra_jump_from=23004"
  904. } else {
  905. i.URI += "?extra_jump_from=23004"
  906. }
  907. i.SugType = "直播"
  908. case SuggestionArticle:
  909. i.Goto = model.GotoArticle
  910. i.URI = model.FillURI(i.Goto, strconv.Itoa(int(st.Ref)), nil)
  911. if !strings.Contains(i.URI, "column_from") {
  912. i.URI += "?column_from=search"
  913. }
  914. i.SugType = "专栏"
  915. }
  916. } else if st.TermType == SuggestionJumpUser && st.User != nil {
  917. i.Title = st.User.Name
  918. i.Cover = st.User.Face
  919. i.Goto = model.GotoAuthor
  920. i.OfficialVerify = &OfficialVerify{Type: st.User.OfficialVerifyType}
  921. i.Param = strconv.Itoa(int(st.User.Mid))
  922. i.URI = model.FillURI(i.Goto, i.Param, nil)
  923. i.Mid = st.User.Mid
  924. i.Fans = st.User.Fans
  925. i.Level = st.User.Level
  926. i.Arcs = st.User.Videos
  927. } else if st.TermType == SuggestionJumpPGC && st.PGC != nil {
  928. var styles []string
  929. i.Title = st.PGC.Title
  930. i.Cover = st.PGC.Cover
  931. i.PTime = st.PGC.Pubtime
  932. i.URI = st.PGC.GotoURL
  933. if pt := i.PTime.Time().Format("2006"); pt != "" {
  934. styles = append(styles, pt)
  935. }
  936. i.SeasonTypeName = model.FormMediaType(st.PGC.MediaType)
  937. if i.SeasonTypeName != "" {
  938. styles = append(styles, i.SeasonTypeName)
  939. }
  940. i.Goto = model.GotoPGC
  941. i.Param = strconv.Itoa(int(st.PGC.MediaID))
  942. i.Area = st.PGC.Areas
  943. if i.Area != "" {
  944. styles = append(styles, i.Area)
  945. }
  946. i.Style = st.PGC.Styles
  947. if len(styles) > 0 {
  948. i.Styles = strings.Join(styles, "|")
  949. }
  950. i.Label = FormPGCLabel(st.PGC.MediaType, st.PGC.Styles, st.PGC.Staff, st.PGC.CV)
  951. i.Rating = st.PGC.MediaScore
  952. i.Vote = st.PGC.MediaUserCount
  953. i.Badges = st.PGC.Badges
  954. }
  955. }
  956. // FromQuery form func
  957. func (i *Item) FromQuery(qs []*Query) {
  958. i.Goto = model.GOtoRecommendWord
  959. for _, q := range qs {
  960. i.List = append(i.List, &Item{Param: strconv.FormatInt(q.ID, 10), Title: q.Name, Type: q.Type, FromSource: q.FromSource})
  961. }
  962. }
  963. func (i *Item) FromComic(c *Comic) {
  964. i.ID = c.ID
  965. i.Title = c.Title
  966. if len(c.Author) > 0 {
  967. i.Name = fmt.Sprintf("作者: %v", strings.Join(c.Author, "、"))
  968. }
  969. i.Style = c.Styles
  970. i.Cover = c.Cover
  971. i.URI = c.URL
  972. i.ComicURL = c.ComicURL
  973. i.Param = strconv.FormatInt(c.ID, 10)
  974. i.Goto = model.GotoComic
  975. i.Badge = "漫画"
  976. }
  977. // FromLiveMaster form func
  978. func (i *Item) FromLiveMaster(l *Live, lv *live.RoomInfo) {
  979. i.Type = l.Type
  980. i.Name = l.Uname
  981. i.UCover = l.Uface
  982. i.Attentions = l.Fans
  983. i.VerifyType = l.VerifyType
  984. i.VerifyDesc = l.VerifyDesc
  985. i.Title = l.Title
  986. if l.Cover != "" && l.Cover != _emptyLiveCover {
  987. i.Cover = l.Cover
  988. } else {
  989. i.Cover = _emptyLiveCover2
  990. }
  991. i.Goto = model.GotoLive
  992. i.Mid = l.UID
  993. i.RoomID = l.RoomID
  994. i.Param = strconv.Itoa(int(i.RoomID))
  995. i.URI = model.FillURI(i.Goto, i.Param, model.LiveHandler(lv))
  996. i.Online = l.Online
  997. i.LiveStatus = l.LiveStatus
  998. i.CateParentName = l.CateParentName
  999. i.CateNameNew = l.CateName
  1000. }
  1001. // FromChannel form func
  1002. func (i *Item) FromChannel(c *Channel, avm map[int64]*api.Arc, bangumis map[int32]*seasongrpc.CardInfoProto, lm map[int64]*live.RoomInfo, tagMyInfos []*tagmdl.Tag) {
  1003. i.ID = c.TagID
  1004. i.Title = c.TagName
  1005. i.Cover = c.Cover
  1006. i.Param = strconv.FormatInt(c.TagID, 10)
  1007. i.Goto = model.GotoChannel
  1008. i.URI = model.FillURI(i.Goto, i.Param, nil)
  1009. i.Type = c.Type
  1010. i.Attentions = c.AttenCount
  1011. i.Desc = c.Desc
  1012. for _, myInfo := range tagMyInfos {
  1013. if myInfo != nil && myInfo.TagID == c.TagID {
  1014. i.IsAttention = myInfo.IsAtten
  1015. break
  1016. }
  1017. }
  1018. var (
  1019. item []*Item
  1020. cooperation bool
  1021. )
  1022. for _, v := range c.Values {
  1023. ii := &Item{TrackID: v.TrackID, LinkType: v.LinkType, Position: v.Position}
  1024. switch v.Type {
  1025. case TypeVideo:
  1026. ii.FromVideo(v.Video, avm[v.Video.ID], cooperation)
  1027. //case TypeLive:
  1028. // ii.FromLive(v.Live, lm[v.Live.RoomID])
  1029. //case TypeMediaBangumi, TypeMediaFt:
  1030. // if bangumi, ok := bangumis[int32(v.Media.SeasonID)]; ok {
  1031. // ii.FromTagPGC(v.Media, bangumi)
  1032. // }
  1033. //case TypeTicket:
  1034. // ii.FromTicket(v.Ticket)
  1035. //case TypeProduct:
  1036. // ii.FromProduct(v.Product)
  1037. //case TypeArticle:
  1038. // ii.FromArticle(v.Article, nil)
  1039. }
  1040. if ii.Goto != "" {
  1041. item = append(item, ii)
  1042. }
  1043. }
  1044. i.Item = item
  1045. }
  1046. // FromTwitter form twitter
  1047. func (i *Item) FromTwitter(t *Twitter, details map[int64]*bplus.Detail, isUP, isCount, isNew bool) {
  1048. var (
  1049. gt, id string
  1050. )
  1051. i.Title = t.Content
  1052. i.Covers = t.Cover
  1053. i.CoverCount = t.CoverCount
  1054. i.Param = strconv.FormatInt(t.ID, 10)
  1055. i.Goto = model.GotoTwitter
  1056. if isNew {
  1057. gt = model.GotoDynamic
  1058. id = i.Param
  1059. } else {
  1060. gt = model.GotoTwitter
  1061. id = strconv.FormatInt(t.PicID, 10)
  1062. }
  1063. i.URI = model.FillURI(gt, id, nil)
  1064. if detail, ok := details[t.ID]; ok {
  1065. if isUP {
  1066. ii := &Item{
  1067. Mid: detail.Mid,
  1068. Title: detail.NickName,
  1069. Cover: detail.FaceImg,
  1070. }
  1071. i.Upper = ii
  1072. }
  1073. if isCount {
  1074. ii := &Item{
  1075. Play: detail.ViewCount,
  1076. Like: detail.LikeCount,
  1077. Reply: detail.CommentCount,
  1078. }
  1079. i.State = ii
  1080. }
  1081. }
  1082. }
  1083. // FromRcmdPre from rcmd pre.
  1084. func (i *Item) FromRcmdPre(id int64, a *api.Arc, bangumi *seasongrpc.CardInfoProto) {
  1085. if a != nil {
  1086. i.Title = a.Title
  1087. i.Cover = a.Pic
  1088. i.Author = a.Author.Name
  1089. i.Param = strconv.Itoa(int(id))
  1090. i.Goto = model.GotoAv
  1091. i.URI = model.FillURI(i.Goto, i.Param, model.AvHandler(archive.BuildArchive3(a)))
  1092. i.fillArcStat(a)
  1093. i.Desc = a.Desc
  1094. i.DurationInt = a.Duration
  1095. } else if bangumi != nil {
  1096. i.Title = bangumi.Title
  1097. i.Cover = bangumi.Cover
  1098. i.Param = strconv.Itoa(int(id))
  1099. i.Goto = model.GotoPGC
  1100. i.URI = model.FillURI(i.Goto, i.Param, nil)
  1101. i.Badge = bangumi.SeasonTypeName
  1102. i.Started = int8(bangumi.IsStarted)
  1103. i.Play = int(bangumi.Stat.View)
  1104. if bangumi.Rating != nil {
  1105. i.Rating = float64(bangumi.Rating.Score)
  1106. i.RatingCount = int(bangumi.Rating.Count)
  1107. }
  1108. i.MediaType = int(bangumi.SeasonType) // 1:番剧,2:电影,3:纪录片,4:国漫,5:电视剧
  1109. if bangumi.Stat != nil {
  1110. i.Attentions = int(bangumi.Stat.Follow)
  1111. }
  1112. if bangumi.NewEp != nil {
  1113. i.Label = bangumi.NewEp.IndexShow
  1114. }
  1115. }
  1116. }
  1117. // FromStar form func
  1118. func (i *Item) FromStar(s *Star) {
  1119. var cooperation bool
  1120. i.Title = s.Title
  1121. i.Cover = s.Cover
  1122. i.Desc = s.Desc
  1123. if i.URIType == StarSpace {
  1124. i.URI = model.FillURI(model.GotoSpace, strconv.Itoa(int(s.MID)), nil)
  1125. } else if i.URIType == StarChannel {
  1126. i.URI = model.FillURI(model.GotoChannel, strconv.Itoa(int(s.TagID)), nil)
  1127. }
  1128. i.Param = strconv.Itoa(int(s.ID))
  1129. i.Goto = model.GotoStar
  1130. i.Mid = s.MID
  1131. i.TagID = s.TagID
  1132. i.TagItems = make([]*Item, 0, len(s.TagList))
  1133. for _, v := range s.TagList {
  1134. if v == nil {
  1135. continue
  1136. }
  1137. vi := &Item{}
  1138. vi.Title = v.TagName
  1139. vi.KeyWord = v.KeyWord
  1140. vi.Item = make([]*Item, 0, len(v.ValueList))
  1141. for _, vv := range v.ValueList {
  1142. if vv == nil || vv.Video == nil {
  1143. continue
  1144. }
  1145. vvi := &Item{}
  1146. vvi.FromVideo(vv.Video, nil, cooperation)
  1147. vi.Item = append(vi.Item, vvi)
  1148. }
  1149. i.TagItems = append(i.TagItems, vi)
  1150. }
  1151. }
  1152. // FromTicket from ticket
  1153. func (i *Item) FromTicket(t *Ticket) {
  1154. i.ID = t.ID
  1155. i.Param = strconv.Itoa(int(t.ID))
  1156. i.Goto = model.GotoTicket
  1157. i.Badge = "展演"
  1158. i.Title = t.Title
  1159. i.Cover = t.Cover
  1160. i.ShowTime = t.ShowTime
  1161. i.City = t.CityName
  1162. i.Venue = t.VenueName
  1163. i.Price = int(math.Ceil(float64(t.PriceLow) / 100))
  1164. i.PriceComplete = strconv.FormatFloat(float64(t.PriceLow)/100, 'f', -1, 64)
  1165. i.PriceType = t.PriceType
  1166. i.ReqNum = t.ReqNum
  1167. i.URI = t.URL
  1168. }
  1169. // FromProduct from ticket
  1170. func (i *Item) FromProduct(p *Product) {
  1171. i.ID = p.ID
  1172. i.Param = strconv.Itoa(int(p.ID))
  1173. i.Goto = model.GotoProduct
  1174. i.Badge = "商品"
  1175. i.Title = p.Title
  1176. i.Cover = p.Cover
  1177. i.ShopName = p.ShopName
  1178. i.Price = int(math.Ceil(float64(p.Price) / 100))
  1179. i.PriceComplete = strconv.FormatFloat(float64(p.Price)/100, 'f', -1, 64)
  1180. i.PriceType = p.PriceType
  1181. i.ReqNum = p.ReqNum
  1182. i.URI = p.URL
  1183. }
  1184. // FromSpecialerGuide from ticket
  1185. func (i *Item) FromSpecialerGuide(sg *SpecialerGuide) {
  1186. i.ID = sg.ID
  1187. i.Param = strconv.Itoa(int(sg.ID))
  1188. i.Goto = model.GotoSpecialerGuide
  1189. i.Title = sg.Title
  1190. i.Cover = sg.Cover
  1191. i.Desc = sg.Desc
  1192. i.Phone = sg.Tel
  1193. }
  1194. func (i *Item) FromTagPGC(m *Media, bangumi *seasongrpc.CardInfoProto) {
  1195. if m.SeasonID == 0 {
  1196. return
  1197. }
  1198. ssid := strconv.Itoa(int(m.SeasonID))
  1199. i.Title = bangumi.Title
  1200. i.Cover = bangumi.Cover
  1201. i.Param = strconv.Itoa(int(m.MediaID))
  1202. i.Goto = model.GotoPGC
  1203. i.URI = model.FillURI(i.Goto, ssid, nil)
  1204. i.Badge = bangumi.SeasonTypeName
  1205. i.Started = int8(bangumi.IsStarted)
  1206. i.Play = int(bangumi.Stat.View)
  1207. if bangumi.Rating != nil {
  1208. i.Rating = float64(bangumi.Rating.Score)
  1209. i.RatingCount = int(bangumi.Rating.Count)
  1210. }
  1211. i.MediaType = int(bangumi.SeasonType) // 1:番剧,2:电影,3:纪录片,4:国漫,5:电视剧
  1212. if bangumi.Stat != nil {
  1213. i.Attentions = int(bangumi.Stat.Follow)
  1214. }
  1215. if bangumi.NewEp != nil {
  1216. i.Label = bangumi.NewEp.IndexShow
  1217. }
  1218. }
  1219. // flowTest form func
  1220. // func flowTest(buvid string) (ok bool) {
  1221. // id := crc32.ChecksumIEEE([]byte(reverseString(buvid))) % 2
  1222. // if id%2 > 0 {
  1223. // ok = true
  1224. // }
  1225. // return
  1226. // }
  1227. // reverseString form func
  1228. // func reverseString(s string) string {
  1229. // runes := []rune(s)
  1230. // for from, to := 0, len(runes)-1; from < to; from, to = from+1, to-1 {
  1231. // runes[from], runes[to] = runes[to], runes[from]
  1232. // }
  1233. // return string(runes)
  1234. // }
  1235. func FormPGCLabel(mediaType int, styles, staff, cv string) (label string) {
  1236. switch mediaType {
  1237. case 1: // 演员
  1238. label = strings.Replace(styles, "\n", "、", -1)
  1239. case 2: // 电影
  1240. label = "演员:" + strings.Replace(cv, "\n", "、", -1)
  1241. case 3: // 纪录片
  1242. label = strings.Replace(staff, "\n", "、", -1)
  1243. case 4: // 国创
  1244. label = strings.Replace(styles, "\n", "、", -1)
  1245. case 5: // 电视剧
  1246. label = "演员:" + strings.Replace(cv, "\n", "、", -1)
  1247. case 7: // 综艺
  1248. label = strings.Replace(cv, "\n", "、", -1)
  1249. case 123: // 电视剧
  1250. label = "演员:" + strings.Replace(cv, "\n", "、", -1)
  1251. case 124: // 综艺
  1252. label = strings.Replace(cv, "\n", "、", -1)
  1253. case 125: // 纪录片
  1254. label = strings.Replace(staff, "\n", "、", -1)
  1255. case 126: // 电影
  1256. label = "演员:" + strings.Replace(cv, "\n", "、", -1)
  1257. case 127: // 动漫
  1258. label = strings.Replace(styles, "\n", "、", -1)
  1259. default:
  1260. label = strings.Replace(cv, "\n", "、", -1)
  1261. }
  1262. return
  1263. }