const.go 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  1. package model
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "net/url"
  6. "strings"
  7. "go-common/app/service/main/archive/api"
  8. "go-common/app/service/main/archive/model/archive"
  9. )
  10. const (
  11. // PlatAndroid is int8 for android.
  12. PlatAndroid = int8(0)
  13. // PlatIPhone is int8 for iphone.
  14. PlatIPhone = int8(1)
  15. // PlatIPad is int8 for ipad.
  16. PlatIPad = int8(2)
  17. // PlatWPhone is int8 for wphone.
  18. PlatWPhone = int8(3)
  19. // PlatAndroidG is int8 for Android Googleplay.
  20. PlatAndroidG = int8(4)
  21. // PlatIPhoneI is int8 for Iphone Global.
  22. PlatIPhoneI = int8(5)
  23. // PlatIPadI is int8 for IPAD Global.
  24. PlatIPadI = int8(6)
  25. // PlatAndroidTV is int8 for AndroidTV Global.
  26. PlatAndroidTV = int8(7)
  27. // PlatAndroidI is int8 for Android Global.
  28. PlatAndroidI = int8(8)
  29. // PlatIpadHD is int8 for IpadHD
  30. PlatIpadHD = int8(9)
  31. // PlatAndroidB is int8 for android_b
  32. PlatAndroidB = int8(10)
  33. // PlatIPhoneB is int8 for iphone_b
  34. PlatIPhoneB = int8(11)
  35. // PlatAndroidTVYST is int8 for AndroidTV_YST Global.
  36. PlatAndroidTVYST = int8(12)
  37. GotoAv = "av"
  38. GotoWeb = "web"
  39. GotoBangumi = "bangumi"
  40. GotoLive = "live"
  41. GotoGame = "game"
  42. GotoArticle = "article"
  43. GotoSpecial = "special"
  44. GotoCm = "cm"
  45. GotoSearchUpper = "search_upper"
  46. // for fill uri
  47. GotoAudio = "audio"
  48. GotoSong = "song"
  49. GotoAudioTag = "audio_tag"
  50. GotoAlbum = "album"
  51. GotoClip = "clip"
  52. GotoDaily = "daily"
  53. // EnvPro is pro.
  54. EnvPro = "pro"
  55. EnvHK = "hk"
  56. // EnvTest is env.
  57. EnvTest = "test"
  58. // EnvDev is env.
  59. EnvDev = "dev"
  60. // ForbidCode is forbid by law
  61. ForbidCode = -110
  62. StatusIng = 0
  63. StatusPay = 1
  64. StatusFree = 2
  65. StatusVipFree = 3
  66. StatusVipOnly = 4
  67. StatusVipFirst = 5
  68. CoverIng = "即将上映"
  69. CoverPay = "付费观看"
  70. CoverFree = "免费观看"
  71. CoverVipFree = "付费观看"
  72. CoverVipOnly = "专享"
  73. CoverVipFirst = "抢先"
  74. Hans = "hans"
  75. Hant = "hant"
  76. FromOrder = "order"
  77. FromOperation = "operation"
  78. FromRcmd = "recommend"
  79. )
  80. var (
  81. OperateType = map[int]string{
  82. 0: GotoWeb,
  83. 1: GotoGame,
  84. 2: GotoAv,
  85. 3: GotoBangumi,
  86. 4: GotoLive,
  87. 6: GotoArticle,
  88. 7: GotoDaily,
  89. 8: GotoAudio,
  90. 9: GotoSong,
  91. 10: GotoAlbum,
  92. 11: GotoClip,
  93. }
  94. AvHandler = func(a *api.Arc, trackid string, ap *archive.PlayerInfo) func(uri string) string {
  95. var player string
  96. if ap != nil {
  97. bs, _ := json.Marshal(ap)
  98. player = url.QueryEscape(string(bs))
  99. if strings.IndexByte(player, '+') > -1 {
  100. player = strings.Replace(player, "+", "%20", -1)
  101. }
  102. }
  103. return func(uri string) string {
  104. if a == nil {
  105. return uri
  106. }
  107. var uriStr string
  108. if player != "" && (a.Dimension.Height != 0 || a.Dimension.Width != 0) {
  109. uriStr = fmt.Sprintf("%s?page=1&player_preload=%s&player_width=%d&player_height=%d&player_rotate=%d", uri, player, a.Dimension.Width, a.Dimension.Height, a.Dimension.Rotate)
  110. } else if player != "" {
  111. uriStr = fmt.Sprintf("%s?page=1&player_preload=%s", uri, player)
  112. } else if a.Dimension.Height != 0 || a.Dimension.Width != 0 {
  113. uriStr = fmt.Sprintf("%s?player_width=%d&player_height=%d&player_rotate=%d", uri, a.Dimension.Width, a.Dimension.Height, a.Dimension.Rotate)
  114. }
  115. if trackid != "" {
  116. if uriStr == "" {
  117. uriStr = fmt.Sprintf("%s?trackid=%s", uri, trackid)
  118. } else {
  119. uriStr = fmt.Sprintf("%s&trackid=%s", uriStr, trackid)
  120. }
  121. }
  122. if uriStr != "" {
  123. return uriStr
  124. }
  125. return uri
  126. }
  127. }
  128. LiveRoomHandler = func(broadcastType int) func(uri string) string {
  129. return func(uri string) string {
  130. return fmt.Sprintf("%s?broadcast_type=%d", uri, broadcastType)
  131. }
  132. }
  133. )
  134. // IsAndroid check plat is android or ipad.
  135. func IsAndroid(plat int8) bool {
  136. return plat == PlatAndroid || plat == PlatAndroidG || plat == PlatAndroidI
  137. }
  138. // IsIOS check plat is iphone or ipad.
  139. func IsIOS(plat int8) bool {
  140. return plat == PlatIPad || plat == PlatIPhone || plat == PlatIPadI || plat == PlatIPhoneI || plat == PlatIPhoneB
  141. }
  142. // IsIPhone check plat is iphone.
  143. func IsIPhone(plat int8) bool {
  144. return plat == PlatIPhone || plat == PlatIPhoneI || plat == PlatIPhoneB
  145. }
  146. // IsIPad check plat is pad.
  147. func IsIPad(plat int8) bool {
  148. return plat == PlatIPad || plat == PlatIPadI || plat == PlatIpadHD
  149. }
  150. // IsIOSNormal check plat is ios except iphone_b
  151. func IsIOSNormal(plat int8) bool {
  152. return plat == PlatIPad || plat == PlatIPhone || plat == PlatIPadI || plat == PlatIPhoneI
  153. }
  154. // IsIPhoneB check plat is iphone_b
  155. func IsIPhoneB(plat int8) bool {
  156. return plat == PlatIPhoneB
  157. }
  158. // Plat return plat by platStr or mobiApp
  159. func Plat(mobiApp, device string) int8 {
  160. switch mobiApp {
  161. case "iphone":
  162. if device == "pad" {
  163. return PlatIPad
  164. }
  165. return PlatIPhone
  166. case "white":
  167. return PlatIPhone
  168. case "ipad":
  169. return PlatIpadHD
  170. case "android", "android_b":
  171. return PlatAndroid
  172. case "win", "winphone":
  173. return PlatWPhone
  174. case "android_G":
  175. return PlatAndroidG
  176. case "android_i":
  177. return PlatAndroidI
  178. case "iphone_i":
  179. if device == "pad" {
  180. return PlatIPadI
  181. }
  182. return PlatIPhoneI
  183. case "ipad_i":
  184. return PlatIPadI
  185. case "android_tv":
  186. return PlatAndroidTV
  187. case "android_tv_yst":
  188. return PlatAndroidTVYST
  189. case "iphone_b":
  190. return PlatIPhoneB
  191. }
  192. return PlatIPhone
  193. }
  194. // IsOverseas is overseas
  195. func IsOverseas(plat int8) bool {
  196. return plat == PlatAndroidI || plat == PlatIPhoneI || plat == PlatIPadI
  197. }
  198. // FillURI deal app schema.
  199. func FillURI(gt, param string, f func(uri string) string) (uri string) {
  200. if param == "" {
  201. return
  202. }
  203. switch gt {
  204. case GotoAv, "":
  205. uri = "bilibili://video/" + param
  206. case GotoLive:
  207. uri = "bilibili://live/" + param
  208. case GotoBangumi:
  209. uri = "https://www.bilibili.com/bangumi/play/ss" + param
  210. case GotoArticle:
  211. uri = "bilibili://article/" + param
  212. case GotoGame:
  213. uri = param
  214. case GotoAudio:
  215. uri = "bilibili://music/menu/detail/" + param
  216. case GotoSong:
  217. uri = "bilibili://music/detail/" + param
  218. case GotoAudioTag:
  219. uri = "bilibili://music/categorydetail/" + param
  220. case GotoDaily:
  221. uri = "bilibili://pegasus/list/daily/" + param
  222. case GotoAlbum:
  223. uri = "bilibili://album/" + param
  224. case GotoClip:
  225. uri = "bilibili://clip/" + param
  226. case GotoWeb:
  227. uri = param
  228. }
  229. if f != nil {
  230. uri = f(uri)
  231. }
  232. return
  233. }
  234. func StatusMark(status int) string {
  235. if status == 0 {
  236. return CoverIng
  237. } else if status == 1 {
  238. return CoverPay
  239. } else if status == 2 {
  240. return CoverFree
  241. } else if status == 3 {
  242. return CoverVipFree
  243. } else if status == 4 {
  244. return CoverVipOnly
  245. } else if status == 5 {
  246. return CoverVipFirst
  247. }
  248. return ""
  249. }
  250. // InvalidBuild check source build is not allow by config build and condition.
  251. // eg: when condition is gt, means srcBuild must gt cfgBuild, otherwise is invalid srcBuild.
  252. func InvalidBuild(srcBuild, cfgBuild int, cfgCond string) bool {
  253. if cfgBuild != 0 && cfgCond != "" {
  254. switch cfgCond {
  255. case "gt":
  256. if cfgBuild >= srcBuild {
  257. return true
  258. }
  259. case "lt":
  260. if cfgBuild <= srcBuild {
  261. return true
  262. }
  263. case "eq":
  264. if cfgBuild != srcBuild {
  265. return true
  266. }
  267. case "ne":
  268. if cfgBuild == srcBuild {
  269. return true
  270. }
  271. }
  272. }
  273. return false
  274. }
  275. // Platform plat to platform
  276. func Platform(plat int8) string {
  277. if IsAndroid(plat) {
  278. return "android"
  279. } else {
  280. return "ios"
  281. }
  282. }