full.go 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. package web
  2. import (
  3. "fmt"
  4. "math/rand"
  5. "time"
  6. "go-common/app/interface/main/web-goblin/conf"
  7. "go-common/app/service/main/archive/api"
  8. )
  9. const (
  10. _deal = 100
  11. )
  12. // Mi mi common .
  13. type Mi struct {
  14. ID int64 `json:"id"`
  15. Name string `json:"name"`
  16. Op string `json:"op"`
  17. AlternativeNames string `json:"alternative_names"`
  18. Cover Img `json:"cover"`
  19. Thumbnail Img `json:"thumbnail"`
  20. Description string `json:"description"`
  21. Tags string `json:"tags"`
  22. CreateTime string `json:"create_time"`
  23. ModifyTime string `json:"modify_time"`
  24. PublishTime string `json:"publish_time"`
  25. Author string `json:"author"`
  26. Category string `json:"category"`
  27. Rating float32 `json:"rating"`
  28. PlayCount int32 `json:"play_count"`
  29. PlayCountMonth int `json:"play_count_month"`
  30. PlayCountWeek int `json:"play_count_week"`
  31. PlayLength int64 `json:"play_length"`
  32. Language string `json:"language"`
  33. Images Img `json:"images"`
  34. Weburl string `json:"weburl"`
  35. Appurl string `json:"appurl"`
  36. MinVersion int `json:"min_version"`
  37. Pages []*PageInfo `json:"pages"`
  38. CommentCount int32 `json:"comment_count"`
  39. LikeCount int32 `json:"like_count"`
  40. }
  41. // PageInfo page3 .
  42. type PageInfo struct {
  43. Cid int64 `json:"cid"`
  44. Page int32 `json:"page"`
  45. }
  46. // Img img .
  47. type Img struct {
  48. URL string `json:"url"`
  49. Height int `json:"height"`
  50. Width int `json:"width"`
  51. }
  52. // SearchAids return aids .
  53. type SearchAids struct {
  54. Aid int64 `json:"aid"`
  55. Action string `json:"action"`
  56. }
  57. // FromArchive .
  58. func (f *Mi) FromArchive(a *api.Arc, p []*api.Page, op, source string) {
  59. f.ID = a.Aid
  60. f.Name = a.Title
  61. f.Author = a.Author.Name
  62. f.Category = a.TypeName
  63. f.Weburl = fmt.Sprintf("https://www.bilibili.com/video/av%d%s", a.Aid, source)
  64. f.Appurl = fmt.Sprintf("bilibili://video/%d", a.Aid)
  65. f.ModifyTime = a.PubDate.Time().Format("2006-01-02 15:04:05")
  66. f.Description = a.Desc
  67. f.CreateTime = a.Ctime.Time().Format("2006-01-02 15:04:05")
  68. f.Images.URL = a.Pic
  69. f.PlayLength = a.Duration
  70. f.Cover.URL = a.Pic
  71. f.Thumbnail.URL = a.Pic
  72. f.PlayCount = a.Stat.View
  73. f.PublishTime = a.PubDate.Time().Format("2006-01-02 15:04:05")
  74. f.MinVersion = 1
  75. f.Op = op
  76. f.CommentCount = a.Stat.Reply
  77. f.LikeCount = a.Stat.Like
  78. pLen := len(p)
  79. if pLen > 0 {
  80. f.Pages = make([]*PageInfo, pLen)
  81. for i := 0; i < pLen; i++ {
  82. f.Pages[i] = &PageInfo{}
  83. f.Pages[i].Page = p[i].Page
  84. f.Pages[i].Cid = p[i].Cid
  85. }
  86. } else {
  87. f.Pages = []*PageInfo{}
  88. }
  89. }
  90. // UgcFullDeal .
  91. func (f *Mi) UgcFullDeal() {
  92. var (
  93. lCount = conf.Conf.OutSearch.DealLikeFull
  94. commCount = conf.Conf.OutSearch.DealCommFull
  95. commRes = f.CommentCount + commCount
  96. likeRes = f.LikeCount + lCount
  97. )
  98. if f.PlayCount+f.CommentCount > 0 {
  99. commRes = commRes + (f.PlayCount/(f.PlayCount+f.CommentCount))*f.CommentCount
  100. }
  101. if f.PlayCount+f.LikeCount > 0 {
  102. likeRes = likeRes + (f.PlayCount/(f.PlayCount+f.LikeCount))*f.LikeCount
  103. }
  104. f.CommentCount = commRes
  105. f.LikeCount = likeRes
  106. }
  107. // UgcIncreDeal .
  108. func (f *Mi) UgcIncreDeal() {
  109. rand.Seed(time.Now().UnixNano())
  110. f.CommentCount = int32(rand.Intn(_deal))
  111. f.LikeCount = int32(rand.Intn(_deal)) + _deal
  112. }