player.go 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397
  1. package model
  2. import (
  3. "html/template"
  4. "strconv"
  5. "time"
  6. arcmdl "go-common/app/service/main/archive/api"
  7. "go-common/app/service/main/archive/model/archive"
  8. )
  9. var encodeTbl = []int64{
  10. 0xf3a97cb, 0x8aed379, 0xedf369a, 0x5c82647, 0xcaf6987, 0xad28536, 0xe5f2a7b, 0x72e85df,
  11. 0xac3d972, 0xca97fe5, 0xbcf5473, 0x85ad732, 0xcd6b324, 0xd549a72, 0xe72ab89, 0xfa6dc53,
  12. 0xa8e752b, 0xa73d25f, 0xcad8296, 0xb35f689, 0x7ce594b, 0x59ca743, 0xc4ab2d7, 0x9c8adf6,
  13. 0x93746c2, 0x6cea579, 0xcd36b75, 0x64a973e, 0xfa49c56, 0xb45f2d9, 0x72a56f8, 0x43d6fa9,
  14. 0x354cf2a, 0x26bf5d8, 0x39f64ad, 0xa4fd326, 0x39247d6, 0xec67f95, 0xed8c9b4, 0x29637db,
  15. 0xefabc54, 0xa9ed87c, 0xc2864ea, 0xf32d475, 0x53b6897, 0xe7f94b8, 0x7a4cfd2, 0x9a82e65,
  16. 0x369b7a4, 0x2cae6d4, 0xc7fba36, 0xd3e7846, 0xd324ba5, 0x7c56f24, 0x598c3af, 0x39fd4ae,
  17. 0x3b6472c, 0x2f9a8be, 0x9fcab42, 0x8f34aeb, 0x9e8b372, 0x8c42b9e, 0xf9b574c, 0x7c693fa,
  18. 0x245fc67, 0x823f4ce, 0x957f84d, 0xe529a87, 0xb625ead, 0xbd4f6a9, 0x863ca52, 0xd762cef,
  19. 0x8d6c479, 0xbc4f579, 0xa486fdc, 0xcd6f289, 0xda3b629, 0x4fce523, 0x2e8db97, 0xc3bf769,
  20. 0x9c64d7f, 0x52db6f7, 0x95cdf8e, 0xc872fe9, 0x964de53, 0x2bef897, 0xb7a962c, 0x38d72be,
  21. 0x26fa89c, 0x58b742e, 0xa3bd967, 0x3cae942, 0x4d3fb9c, 0xaf59ed3, 0x6f8379d, 0x2bf46d7,
  22. 0xcdbe243, 0x3754bf9, 0x82f9dc5, 0x8a46ef5, 0x5d48ac9, 0x9e6ca3d, 0xfec5a3b, 0x57dafe3,
  23. 0x82ed7a9, 0xbc3d687, 0x89ecbf7, 0x738549a, 0x928746c, 0x9cb7e83, 0xc85f9a7, 0x2947c8e,
  24. 0xba689fd, 0xebc4893, 0xa62cf7e, 0xa8e3cb5, 0xe47589d, 0x792edaf, 0x4635c2d, 0xa2c6bfe,
  25. 0xc456daf, 0x2d65f47, 0xf9ce625, 0x74a8b62, 0x9d728f5, 0x3e4a29d, 0x62a589c, 0x83cb629,
  26. 0xce5b6d3, 0x2fda9ce, 0x87af3bc, 0x837a695, 0xf935da4, 0x48b6ea2, 0x52dc4e9, 0x82a537b,
  27. 0xe23456f, 0x6cbdafe, 0x97bf34d, 0x4c72ad8, 0xa5c4982, 0x8afb76e, 0x895fca6, 0x85abd24,
  28. 0xae2475d, 0xf3c5eb8, 0xb4d2ef5, 0xbda463e, 0xf392a5e, 0x7a9fd58, 0xead48f6, 0x8a62537,
  29. 0x6c35ba2, 0x7589e24, 0xd24ec93, 0x6bc42a5, 0x34d9f87, 0xed3578f, 0x87452fa, 0x5439fca,
  30. 0x29b37c8, 0x8fe4c3b, 0x4c5368d, 0x58acf9b, 0x69c3ad2, 0xaf3827b, 0x328e46b, 0xbef7ca9,
  31. 0xda592c4, 0x45f7db2, 0xcb65a3d, 0x4578ec3, 0xc6deab9, 0xb689edc, 0x4aed59f, 0x25b9af7,
  32. 0x9b6d48f, 0x6de79bf, 0x249fa5e, 0x269a7ef, 0xd9e62a7, 0xb9a86d2, 0x539b72c, 0x8fa9ebc,
  33. 0xec397f5, 0xdbac4e2, 0x938e6fd, 0xe8a734f, 0xe4b8d7f, 0x84cd9b3, 0x75c6ef4, 0x956378c,
  34. 0x43f2d78, 0x74e9253, 0x25dbef4, 0xb7e26f9, 0x93b2c6d, 0x2faeb76, 0x3b278de, 0x6b5948f,
  35. 0x4967358, 0x49f3a7e, 0x7596ec4, 0x98cabf5, 0x95c638e, 0x6d258b7, 0x97e8b3f, 0x5ab7823,
  36. 0x53b6a89, 0xa3bc579, 0xac45d36, 0xcea9b28, 0x98f2356, 0xd694a2e, 0xf732e8a, 0xe7463d5,
  37. 0xf5ec9a8, 0x6dba984, 0xc798e5a, 0x6e9382b, 0xeac3249, 0x5238b9a, 0xd632eaf, 0xa92b685,
  38. 0xbcae435, 0x9726fd8, 0x3fcbea4, 0x5e9da23, 0xb93a4f7, 0x327d84c, 0x5db932f, 0x86274de,
  39. 0xa54bd72, 0x63f2ed5, 0x6d37285, 0xb4fe7c9, 0x549a6b3, 0x3b592ec, 0x73d456b, 0x49253b7,
  40. 0x2da9b8c, 0xb85642d, 0x37489ca, 0x726fe3b, 0x4ce6ad2, 0x376becd, 0x6f43bec, 0xf96dba4,
  41. 0xebc8d72, 0xf59b4ca, 0x263547f, 0xabcd87e, 0x3fd25ae, 0xc6f4b38, 0x36cd978, 0x6e94a37,
  42. }
  43. // Catalog catalog map
  44. var Catalog = map[int8]string{
  45. 1: "system",
  46. 2: "bangumi",
  47. 3: "news",
  48. }
  49. // Sid sid string.
  50. type Sid string
  51. // Valid valid sid.
  52. func (sid Sid) Valid() (b bool) {
  53. var (
  54. interval int64
  55. msec int64
  56. _xorKey int64
  57. hKey int64
  58. _dec int64
  59. _ts int64
  60. offset int
  61. ms int64
  62. err error
  63. )
  64. if len(sid) != 8 {
  65. return false
  66. }
  67. if interval, err = strconv.ParseInt(string(sid)[0:6], 36, 64); err != nil {
  68. return false
  69. }
  70. if msec, err = strconv.ParseInt(string(sid)[6:8], 36, 64); err != nil {
  71. return false
  72. }
  73. _xorKey = encodeTbl[msec%256]
  74. hKey = 1 << uint(28+msec%3)
  75. _dec = (interval ^ _xorKey)
  76. if (_dec & 0x70000000) != hKey {
  77. return false
  78. }
  79. _ts = (_dec^hKey)*1000 + msec
  80. _, offset = time.Now().Zone()
  81. ms = (time.Now().UnixNano() / int64(time.Millisecond)) + (int64(offset)/60)*60000 // GMT Timestamp
  82. return _ts <= (ms - 1388534400000 + 300000)
  83. }
  84. // Create create sid.
  85. func (sid Sid) Create() (re Sid) {
  86. var (
  87. offset int
  88. ms int64
  89. _interval int64
  90. msec int64
  91. msesStr string
  92. _xorKey int64
  93. hKey int64
  94. tsEncode string
  95. )
  96. _, offset = time.Now().Zone()
  97. ms = (time.Now().UnixNano() / int64(time.Millisecond)) - (int64(offset)/60)*60000 // GMT Timestamp
  98. _interval = ms/1000 - 1388534400
  99. msec = ms % 1000
  100. _xorKey = encodeTbl[msec%256]
  101. hKey = 1 << uint(28+msec%3)
  102. tsEncode = strconv.FormatInt(((hKey | _interval) ^ _xorKey), 36)
  103. for len(tsEncode) < 6 {
  104. tsEncode = "0" + tsEncode
  105. }
  106. msesStr = strconv.FormatInt(msec, 36)
  107. if len(msesStr) < 2 {
  108. msesStr = "0" + msesStr
  109. }
  110. sid = Sid(tsEncode + msesStr)
  111. return sid
  112. }
  113. // Item item struct.
  114. type Item struct {
  115. Content string `xml:",cdata"`
  116. Tooltip string `xml:"tooltip,attr"`
  117. Bgcolor string `xml:"bgcolor,attr"`
  118. Catalog string `xml:"catalog,attr"`
  119. ResourceID string `xml:"resourceid,attr"`
  120. SrcID string `xml:"srcid,attr"`
  121. ID string `xml:"id,attr"`
  122. }
  123. // Carousel carousel struct.
  124. type Carousel struct {
  125. Backcolor string
  126. Fontcolor string
  127. Hint string
  128. Link string
  129. Content string
  130. Category string
  131. }
  132. // Player player struct.
  133. type Player struct {
  134. IP string
  135. Zoneid int64
  136. Country string
  137. Isp string // 运营商暂时不需要
  138. Login bool
  139. Time int64
  140. ZoneIP string
  141. // user info
  142. Name string
  143. User int64
  144. UserHash string
  145. Money string
  146. Face string
  147. IsAdmin bool
  148. Upermission string
  149. Level string
  150. LevelInfo template.HTML
  151. Vip template.HTML
  152. OfficialVerify template.HTML
  153. BlockTime int64
  154. // archive info
  155. Aid int64
  156. Typeid int32
  157. Maxlimit int
  158. Click int
  159. FwClick int32
  160. Duration string
  161. Arctype string
  162. APermission bool
  163. SuggestComment bool
  164. Chatid int64
  165. Vtype string
  166. Oriurl string
  167. Pid int64
  168. AllowBp bool
  169. Bottom int8
  170. Acceptguest bool
  171. Acceptaccel bool
  172. Cache bool
  173. CacheDispatch bool
  174. BrTCP string
  175. BrWs string
  176. BrWss string
  177. DefaultDm int8
  178. //progress
  179. LastPlayTime int64
  180. LastCid int64
  181. Role string
  182. // has next page
  183. HasNext int8
  184. OnlineCount int64
  185. // dm mask
  186. MaskNew template.HTML
  187. // subtitle
  188. Subtitle template.HTML
  189. // player icon
  190. PlayerIcon template.HTML
  191. // view points
  192. ViewPoints template.HTML
  193. }
  194. // Progress progress struct.
  195. type Progress struct {
  196. Cid int64 `json:"cid"`
  197. Pro int64 `json:"pro"`
  198. }
  199. // Policy policy struct.
  200. type Policy struct {
  201. ID int64 `json:"id"`
  202. Des string `json:"description"`
  203. Type string `json:"type"`
  204. Start string `json:"start"`
  205. End string `json:"end"`
  206. Mtime string `json:"mtime"`
  207. StartTime time.Time
  208. EndTime time.Time
  209. MtimeTime time.Time
  210. Items []*Pitem `json:"items"`
  211. }
  212. // Pitem pitem struct
  213. type Pitem struct {
  214. ID int64 `json:"item_id"`
  215. Data string `json:"data"`
  216. Comment string `json:"comment"`
  217. ExtData string `json:"ext_data"`
  218. Ver int64 `json:"ver"`
  219. }
  220. // Param param struct.
  221. type Param struct {
  222. Name string
  223. Value string
  224. }
  225. // BlockTime block time struct
  226. type BlockTime struct {
  227. BlockStatus int `json:"block_status"`
  228. BlockedForever bool `json:"blocked_forever"`
  229. BlockedEnd int64 `json:"blocked_end"`
  230. }
  231. // Videoshot player video shot struct
  232. type Videoshot struct {
  233. *archive.Videoshot
  234. Index []uint16 `json:"index,omitempty"`
  235. }
  236. // PlayURLToken playurl token.
  237. type PlayURLToken struct {
  238. From string `json:"from"`
  239. Ts int64 `json:"ts"`
  240. Aid int64 `json:"aid"`
  241. Cid int64 `json:"cid"`
  242. Mid int64 `json:"mid"`
  243. VIP int `json:"vip"`
  244. SVIP int `json:"svip"`
  245. Owner int `json:"owner"`
  246. Fcs string `json:"fcs"`
  247. Token string `json:"token"`
  248. }
  249. // VIPInfo vip info.
  250. type VIPInfo struct {
  251. Type int32 `json:"vipType"`
  252. DueDate int64 `json:"vipDueDate"`
  253. DueRemark string `json:"dueRemark"`
  254. AccessStatus int32 `json:"accessStatus"`
  255. VipStatus int32 `json:"vipStatus"`
  256. VipStatusWarn string `json:"vipStatusWarn"`
  257. }
  258. // Official official.
  259. type Official struct {
  260. Type int8 `json:"type"`
  261. Desc string `json:"desc"`
  262. }
  263. // Points is
  264. type Points struct {
  265. Type int `json:"type"`
  266. From int64 `json:"from"`
  267. To int64 `json:"to"`
  268. Content string `json:"content"`
  269. }
  270. const (
  271. // TpWithUinfo tpl with user info.
  272. TpWithUinfo = `<ip>{{.IP}}</ip>
  273. <zoneid>{{.Zoneid}}</zoneid>
  274. <zoneip>{{.ZoneIP}}</zoneip>
  275. <country>{{.Country}}</country>
  276. <login>{{.Login}}</login>
  277. <time>{{.Time}}</time>
  278. <name>{{.Name}}</name>
  279. <user>{{.User}}</user>
  280. <user_hash>{{.UserHash}}</user_hash>
  281. <money>{{.Money}}</money>
  282. <face>{{.Face}}</face>
  283. <isadmin>{{.IsAdmin}}</isadmin>
  284. <permission>{{.Upermission}}</permission>
  285. <level>{{.Level}}</level>
  286. <level_info>{{.LevelInfo}}</level_info>
  287. <vip>{{.Vip}}</vip>
  288. <official_verify>{{.OfficialVerify}}</official_verify>
  289. <block_time>{{.BlockTime}}</block_time>
  290. <lastplaytime>{{.LastPlayTime}}</lastplaytime>
  291. <lastcid>{{.LastCid}}</lastcid>
  292. <aid>{{.Aid}}</aid>
  293. <typeid>{{.Typeid}}</typeid>
  294. <vtype>{{.Vtype}}</vtype>
  295. <oriurl>{{.Oriurl}}</oriurl>
  296. <suggest_comment>{{.SuggestComment}}</suggest_comment>
  297. <server>chat.bilibili.com</server>
  298. <maxlimit>{{.Maxlimit}}</maxlimit>
  299. <click>{{.Click}}</click>
  300. <fw_click>{{.FwClick}}</fw_click>
  301. <chatid>{{.Chatid}}</chatid>
  302. <pid>{{.Pid}}</pid>
  303. <duration>{{.Duration}}</duration>
  304. <arctype>{{.Arctype}}</arctype>
  305. <allow_bp>{{.AllowBp}}</allow_bp>
  306. <bottom>{{.Bottom}}</bottom>
  307. <shot>false</shot>
  308. <sinapi>1</sinapi>
  309. <acceptguest>{{.Acceptguest}}</acceptguest>
  310. <acceptaccel>{{.Acceptaccel}}</acceptaccel>
  311. <cache>{{.Cache}}</cache>
  312. <broadcast_tcp>{{.BrTCP}}</broadcast_tcp>
  313. <broadcast_ws>{{.BrWs}}</broadcast_ws>
  314. <broadcast_wss>{{.BrWss}}</broadcast_wss>
  315. <default_dm>{{.DefaultDm}}</default_dm>
  316. <dm_host>0://comment.bilibili.com,1://comment.bilibili.com/rc</dm_host>
  317. <role>{{.Role}}</role>
  318. <has_next>{{.HasNext}}</has_next>
  319. <online_count>{{.OnlineCount}}</online_count>
  320. <dm_mask></dm_mask>
  321. <mask_new>{{.MaskNew}}</mask_new>
  322. <subtitle>{{.Subtitle}}</subtitle>
  323. <player_icon>{{.PlayerIcon}}</player_icon>
  324. <view_points>{{.ViewPoints}}</view_points>
  325. `
  326. // TpWithNoUinfo tpl without user info.
  327. TpWithNoUinfo = `<ip>{{.IP}}</ip>
  328. <zoneip>{{.ZoneIP}}</zoneip>
  329. <zoneid>{{.Zoneid}}</zoneid>
  330. <country>{{.Country}}</country>
  331. <login>{{.Login}}</login>
  332. <time>{{.Time}}</time>
  333. <lastplaytime>0</lastplaytime>
  334. <lastcid>0</lastcid>
  335. <aid>{{.Aid}}</aid>
  336. <typeid>{{.Typeid}}</typeid>
  337. <vtype>{{.Vtype}}</vtype>
  338. <oriurl>{{.Oriurl}}</oriurl>
  339. <suggest_comment>{{.SuggestComment}}</suggest_comment>
  340. <server>chat.bilibili.com</server>
  341. <maxlimit>{{.Maxlimit}}</maxlimit>
  342. <click>{{.Click}}</click>
  343. <fw_click>{{.FwClick}}</fw_click>
  344. <chatid>{{.Chatid}}</chatid>
  345. <pid>{{.Pid}}</pid>
  346. <duration>{{.Duration}}</duration>
  347. <arctype>{{.Arctype}}</arctype>
  348. <allow_bp>{{.AllowBp}}</allow_bp>
  349. <bottom>{{.Bottom}}</bottom>
  350. <shot>false</shot>
  351. <sinapi>1</sinapi>
  352. <acceptguest>{{.Acceptguest}}</acceptguest>
  353. <acceptaccel>{{.Acceptaccel}}</acceptaccel>
  354. <cache>{{.Cache}}</cache>
  355. <broadcast_tcp>{{.BrTCP}}</broadcast_tcp>
  356. <broadcast_ws>{{.BrWs}}</broadcast_ws>
  357. <broadcast_wss>{{.BrWss}}</broadcast_wss>
  358. <default_dm>{{.DefaultDm}}</default_dm>
  359. <dm_host>0://comment.bilibili.com,1://comment.bilibili.com/rc</dm_host>
  360. <role>0</role>
  361. <has_next>{{.HasNext}}</has_next>
  362. <online_count>{{.OnlineCount}}</online_count>
  363. <dm_mask></dm_mask>
  364. <mask_new>{{.MaskNew}}</mask_new>
  365. <subtitle>{{.Subtitle}}</subtitle>
  366. <player_icon>{{.PlayerIcon}}</player_icon>
  367. <view_points>{{.ViewPoints}}</view_points>
  368. `
  369. )
  370. // View .
  371. type View struct {
  372. *arcmdl.Arc
  373. Pages []*arcmdl.Page `json:"pages"`
  374. }