player.go 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. package http
  2. import (
  3. "strconv"
  4. "time"
  5. "go-common/app/interface/main/report-click/model"
  6. "go-common/library/log"
  7. bm "go-common/library/net/http/blademaster"
  8. "go-common/library/net/metadata"
  9. )
  10. // reportPlayer write the archive data.
  11. func reportPlayer(c *bm.Context) {
  12. params := c.Request.Form
  13. header := c.Request.Header
  14. buvid := header.Get("Buvid")
  15. displayid := header.Get("Display-ID")
  16. ts := params.Get("ts")
  17. aid := params.Get("aid")
  18. cid := params.Get("cid")
  19. playedTime := params.Get("played_time")
  20. mid := params.Get("mid")
  21. moAp := params.Get("mobi_app")
  22. typeID := params.Get("type")
  23. subType := params.Get("sub_type")
  24. sid := params.Get("sid")
  25. epid := params.Get("epid")
  26. infocRealTime.Info(ts, buvid, displayid, mid, aid, cid, playedTime, strconv.FormatInt(time.Now().Unix(), 10), "1", moAp, "", typeID, subType, sid, epid, "")
  27. c.JSON(nil, nil)
  28. }
  29. // reportHeartbeat write the archive data.
  30. func reportHeartbeat(c *bm.Context) {
  31. params := c.Request.Form
  32. header := c.Request.Header
  33. buvid := header.Get("Buvid")
  34. displayid := header.Get("Display-ID")
  35. sts := params.Get("start_ts")
  36. aid := params.Get("aid")
  37. if aid == "" {
  38. aid = params.Get("avid")
  39. }
  40. cid := params.Get("cid")
  41. playedTime := params.Get("played_time")
  42. mid := params.Get("mid")
  43. moAp := params.Get("mobi_app")
  44. typeID := params.Get("type")
  45. subType := params.Get("sub_type")
  46. sid := params.Get("sid")
  47. epid := params.Get("epid")
  48. playType := params.Get("play_type")
  49. if playType == "" {
  50. playType = params.Get("playtype")
  51. }
  52. infocRealTime.Info(sts, buvid, displayid, mid, aid, cid, playedTime, strconv.FormatInt(time.Now().Unix(), 10), "2", moAp, "", typeID, subType, sid, epid, playType)
  53. c.JSON(nil, nil)
  54. }
  55. func heartbeatMobile(c *bm.Context) {
  56. params := c.Request.Form
  57. header := c.Request.Header
  58. sts := params.Get("start_ts")
  59. build := params.Get("build")
  60. buvid := header.Get("Buvid")
  61. mobileApp := params.Get("mobi_app")
  62. device := params.Get("device")
  63. platform := params.Get("platform")
  64. session := params.Get("session")
  65. mid := params.Get("mid")
  66. aid := params.Get("aid")
  67. cid := params.Get("cid")
  68. sid := params.Get("sid")
  69. epid := params.Get("epid")
  70. tp := params.Get("type")
  71. subType := params.Get("sub_type")
  72. quality := params.Get("quality")
  73. totalTime := params.Get("total_time")
  74. pausedTime := params.Get("paused_time")
  75. playedTime := params.Get("played_time")
  76. videoDuration := params.Get("video_duration")
  77. playType := params.Get("play_type")
  78. networkType := params.Get("network_type")
  79. playProgressTimeLast := params.Get("last_play_progress_time")
  80. playProgressTimeMax := params.Get("max_play_progress_time")
  81. playMode := params.Get("play_mode")
  82. from := params.Get("from")
  83. epidStatus := params.Get("epid_status")
  84. playStatus := params.Get("play_status")
  85. userStatus := params.Get("user_status")
  86. actualPlayedTime := params.Get("actual_played_time")
  87. autoPlay := params.Get("auto_play")
  88. detailPlayTime := params.Get("detail_play_time")
  89. listPlayTime := params.Get("list_play_time")
  90. userAgent := c.Request.Header.Get("User-Agent")
  91. ts, err := strconv.ParseInt(sts, 10, 64)
  92. if err != nil || ts <= 0 {
  93. ts = time.Now().Unix()
  94. sts = strconv.FormatInt(ts, 10)
  95. }
  96. // NOTE /x/report//heartbeat/mobile auto_play = 2 ===> /x/report/click/android2 & ios
  97. // (自动播放的上报>> 2:天马feed流inline) 播放时长转成播放点击
  98. autoPlayInt, _ := strconv.ParseInt(autoPlay, 10, 64)
  99. fromInt, _ := strconv.ParseInt(from, 10, 64)
  100. videoDurInt, _ := strconv.ParseInt(videoDuration, 10, 64)
  101. playedTimeInt, _ := strconv.ParseInt(playedTime, 10, 64)
  102. var needCompens bool
  103. if (autoPlayInt == 2 || autoPlayInt == 1) && fromMap[fromInt] {
  104. userAgent = userAgent + " (inline_play_to_view)" // change from auto_play to inline_play_heartbeat, then to inline_play_to_view
  105. needCompens = true
  106. }
  107. if (autoPlayInt == 2 || autoPlayInt == 1) && fromInlineMap[fromInt] && playedTimeInt >= inlineDuration && (videoDurInt >= playedTimeInt) {
  108. userAgent += " (played_time_enough)" // new logic, if inline play more than 10s, count it also
  109. needCompens = true
  110. }
  111. if needCompens {
  112. var cookieSid, plat string
  113. if ck, err := c.Request.Cookie("sid"); err == nil {
  114. cookieSid = ck.Value
  115. }
  116. ip := metadata.String(c, metadata.RemoteIP)
  117. switch platform {
  118. case "android":
  119. plat = _platAndroid
  120. case "ios":
  121. plat = _platIos
  122. }
  123. clickSvr.Play(c, plat, aid, cid, params.Get("part"), mid, params.Get("lv"),
  124. "0", sts, buvid, ip, userAgent, buvid,
  125. cookieSid, c.Request.Header.Get("Referer"), tp,
  126. subType, sid, epid, playMode, platform, device, mobileApp, autoPlay, session)
  127. log.Warn("plat:%s,aid:%s,cid:%s,part:%s,mid:%s,lv:%s,0:%s,sts:%s,buvid:%s,ip:%s,userAgent:%s,"+
  128. "buvid:%s,cookieSid:%s,Referer:%s,tp:%s,subType:%s,sid:%s,epid:%s,playMode:%s,"+
  129. "platform:%s,device:%s,mobileApp:%s,autoPlay:%s,session:%s",
  130. plat, aid, cid, params.Get("part"), mid, params.Get("lv"),
  131. "0", sts, buvid, ip, userAgent, buvid,
  132. cookieSid, c.Request.Header.Get("Referer"), tp,
  133. subType, sid, epid, playMode, platform, device, mobileApp, autoPlay, session)
  134. }
  135. buildInt, _ := strconv.ParseInt(build, 10, 64)
  136. clickSvr.SuccReport(c, &model.SuccReport{ // record the success by different build
  137. MobiApp: mobileApp,
  138. Build: buildInt,
  139. })
  140. infocStatistics.Info(sts, build, buvid, mobileApp, platform, session, mid, aid, cid, sid,
  141. epid, tp, subType, quality, totalTime, pausedTime, playedTime, videoDuration,
  142. playType, networkType, playProgressTimeLast, playProgressTimeMax, playMode, device, from, epidStatus, playStatus, userStatus, actualPlayedTime, autoPlay, detailPlayTime, listPlayTime)
  143. data := make(map[string]interface{}, 1)
  144. data["ts"] = ts
  145. c.JSON(data, nil)
  146. }
  147. // webHeartbeat write the archive data.
  148. func webHeartbeat(c *bm.Context) {
  149. var (
  150. buvid, mid, term string
  151. params = c.Request.Form
  152. )
  153. if ck, err := c.Request.Cookie("buvid3"); err == nil {
  154. buvid = ck.Value
  155. }
  156. sts := params.Get("start_ts")
  157. aid := params.Get("aid")
  158. cid := params.Get("cid")
  159. pause := params.Get("pause")
  160. playType := params.Get("play_type")
  161. if playType == "" {
  162. playType = params.Get("playtype")
  163. }
  164. playedTime := params.Get("played_time")
  165. if midI, ok := c.Get("mid"); ok {
  166. mid = strconv.FormatInt(midI.(int64), 10)
  167. }
  168. tp := params.Get("type")
  169. subType := params.Get("sub_type")
  170. sid := params.Get("sid")
  171. if sid == "" {
  172. sid = params.Get("seasonID")
  173. }
  174. epid := params.Get("epid")
  175. dt := params.Get("dt")
  176. if dt == "7" {
  177. // count m.bilibili.com visits times.
  178. term = "h5"
  179. } else {
  180. dt = "2"
  181. term = "web"
  182. }
  183. realtime := params.Get("realtime")
  184. ts := strconv.FormatInt(time.Now().Unix(), 10)
  185. infocRealTime.Info(sts, buvid, "", mid, aid, cid, playedTime, ts, dt, term, pause, tp, subType, sid, epid, playType)
  186. clickSvr.Report(c, playedTime, cid, tp, subType, realtime, aid, mid, sid, epid, dt, ts)
  187. c.JSON(nil, nil)
  188. }