Create & Init Project...

This commit is contained in:
2019-04-22 18:49:16 +08:00
commit fc4fa37393
25440 changed files with 4054998 additions and 0 deletions

View File

@@ -0,0 +1,57 @@
load(
"@io_bazel_rules_go//go:def.bzl",
"go_library",
)
go_library(
name = "go_default_library",
srcs = [
"audit.go",
"audit_v2.go",
"auth.go",
"favorite.go",
"follow.go",
"loadpage.go",
"media.go",
"media_v2.go",
"module.go",
"others.go",
"pgc_cards.go",
"playurl.go",
"recommend.go",
"region.go",
"upgrade.go",
"zone_index.go",
],
importpath = "go-common/app/interface/main/tv/model",
tags = ["automanaged"],
visibility = ["//visibility:public"],
deps = [
"//app/service/main/archive/api:go_default_library",
"//library/ecode:go_default_library",
"//library/time:go_default_library",
],
)
filegroup(
name = "package-srcs",
srcs = glob(["**"]),
tags = ["automanaged"],
visibility = ["//visibility:private"],
)
filegroup(
name = "all-srcs",
srcs = [
":package-srcs",
"//app/interface/main/tv/model/goblin:all-srcs",
"//app/interface/main/tv/model/history:all-srcs",
"//app/interface/main/tv/model/search:all-srcs",
"//app/interface/main/tv/model/thirdp:all-srcs",
"//app/interface/main/tv/model/tvvip:all-srcs",
"//app/interface/main/tv/model/upper:all-srcs",
"//app/interface/main/tv/model/view:all-srcs",
],
tags = ["automanaged"],
visibility = ["//visibility:public"],
)

View File

@@ -0,0 +1,70 @@
package model
import (
"go-common/library/time"
)
// Content content def.
type Content struct {
ID int64
Title string
Subtitle string
Desc string
Cover string
SeasonID int
CID int
EPID int
MenuID int
State int
Valid int
AuditTime int
PayStatus int
IsDeleted int
Ctime time.Time
Mtime time.Time
InjectTime time.Time
Reason string
}
// TVEpSeason represents the season table
type TVEpSeason struct {
ID int64
OriginName string
Title string
Alias string
Category int8
Desc string
Style string
Area string
PlayTime time.Time
Info int8
State int8
Check int8
TotalNum int32
Upinfo string
Staff string
Role string
Copyright string
Cover string
AuditTime int
IsDeleted int8
Ctime time.Time
Mtime time.Time
Valid int8
InjectTime time.Time
Reason string
}
// Audit def.
type Audit struct {
IDList []*IDList `json:"id_list"`
OpType string `json:"optype"`
Count int `json:"count"`
AuditMsg string `json:"audit_msg"`
}
// Cont : UGC content struct
type Cont struct {
ID int
Title string
}

View File

@@ -0,0 +1,126 @@
package model
import (
"fmt"
"strconv"
"strings"
"go-common/library/ecode"
)
// audit related consts
const (
_ugcPrefix = "ugc"
_pgcPrefix = "xds"
// the field valid options
_hidden = 0
_online = 1
// pgc audit status
_seasonReject = 0
_seasonPass = 1
// ugc audit status
_ugcPass = 1
_ugcReject = 2
// audit type
_reject = "1"
// IDlist's type field
_season = "1"
// content type
PgcSn = "7"
PgcEp = "8"
UgcArc = "9"
UgcVideo = "10"
)
// IDList def.
type IDList struct {
Type string `json:"type"`
VID string `json:"vid"`
Action string `json:"action"`
AuditMsg string `json:"audit_msg"`
}
// IsReject def.
func (v *IDList) IsReject() bool {
return v.Action == _reject
}
// IsShell tells whether it's about archive/season
func (v *IDList) IsShell() bool {
return v.Type == _season
}
// AuditOp def.
type AuditOp struct {
KID int64 // aid/cid/sid/epid
Result int // pgc sn: `check`, pgc ep: state, ugc: result
Valid int
AuditMsg string
ContentType string // type
}
// ToMsg def
func (v *AuditOp) ToMsg() string {
return fmt.Sprintf("audit_Type(%s)_KID(%d)", v.ContentType, v.KID)
}
// parse prefix and get the real ID
func parsePrefix(value string, prefix string) (res bool, vid int64) {
if strings.Contains(value, prefix) {
res = true
ids := strings.Split(value, prefix)
vid, _ = strconv.ParseInt(ids[1], 10, 64)
}
return
}
// FromIDList def.
func (v *AuditOp) FromIDList(req *IDList) (err error) {
var (
isUGC, isPGC bool
)
// auditMsg treatment
v.AuditMsg = req.AuditMsg
// KID & content type treatment
if isPGC, v.KID = parsePrefix(req.VID, _pgcPrefix); !isPGC { // not pgc, try ugc
if isUGC, v.KID = parsePrefix(req.VID, _ugcPrefix); !isUGC { // not ugc, unknown type
return ecode.RequestErr // unknown type
}
}
// Valid treatment
if req.IsReject() { // decide the valid value
v.Valid = _hidden
} else {
v.Valid = _online
}
// Result & Content Type treatment
if isPGC { // pgc
if req.IsShell() { // season
v.ContentType = PgcSn
if req.IsReject() {
v.Result = _seasonReject
} else {
v.Result = _seasonPass
}
} else { // ep
v.ContentType = PgcEp
if req.IsReject() {
v.Result = _epRejected
} else {
v.Result = _epPass
}
}
} else { // ugc
if req.IsShell() {
v.ContentType = UgcArc
} else {
v.ContentType = UgcVideo
}
if req.IsReject() {
v.Result = _ugcReject
} else {
v.Result = _ugcPass
}
}
return
}

View File

@@ -0,0 +1,62 @@
package model
const (
_epPass = 3
_epRejected = 4
_noMarkWhiteList = 1
)
// EpAuth is the structure of ep in mc
type EpAuth struct {
ID int64 `json:"id"`
EPID int64 `json:"epid"`
SeasonID int64 `json:"season_id"`
State int `json:"state"`
Valid int `json:"valid"`
IsDeleted int `json:"is_deleted"`
NoMark int `json:"no_mark"`
}
// SnAuth is the structure of season in mc
type SnAuth struct {
ID int64 `json:"id"`
IsDeleted int8 `json:"is_deleted"`
Valid int `json:"valid"`
Check int8 `json:"check"`
}
// NotDeleted def.
func (s SnAuth) NotDeleted() bool {
return s.IsDeleted == 0
}
// NotDeleted def.
func (s EpAuth) NotDeleted() bool {
return s.IsDeleted == 0
}
// CanPlay returns whether the season is able to play
func (s EpAuth) CanPlay() bool {
return s.IsDeleted == 0 && s.Valid == 1 && s.State == 3
}
// Auditing checks whether the ep is still auditing
// func (s EpAuth) Auditing() bool {
// return s.State != _epPass && s.State != _epRejected && s.IsDeleted == _noDel
// }
// Whitelist checks whether the ep is in the whitelist of no mark eps
func (s EpAuth) Whitelist() bool {
return s.NoMark == _noMarkWhiteList
}
// CanPlay returns whether the season is able to play
func (s SnAuth) CanPlay() bool {
return s.IsDeleted == 0 && s.Valid == 1 && s.Check == 1
}
// ArcType def.
type ArcType struct {
ID int32 `json:"id"`
Name string `json:"name"`
}

View File

@@ -0,0 +1,64 @@
package model
import (
arcwar "go-common/app/service/main/archive/api"
)
// FormFav is the form validation for favorites display
type FormFav struct {
AccessKey string `form:"access_key" validate:"required"`
Pn int `form:"pn" default:"1"`
}
// ReqFav is request for favorites function
type ReqFav struct {
MID int64
Pn int
}
// ToReq def.
func (f *FormFav) ToReq(mid int64) *ReqFav {
return &ReqFav{
MID: mid,
Pn: f.Pn,
}
}
// FormFavAct is the form validation for favorite action
type FormFavAct struct {
AccessKey string `form:"access_key" validate:"required"`
AID int64 `form:"aid" validate:"required"`
Action int `form:"action" validate:"min=1,max=2"`
}
// ReqFavAct is request for favorites action ( add/del ) function
type ReqFavAct struct {
MID int64
AID int64 // resource id ( ugc avid )
Action int // 1=add,2=delete
}
// ToReq def.
func (f *FormFavAct) ToReq(mid int64) *ReqFavAct {
return &ReqFavAct{
MID: mid,
AID: f.AID,
Action: f.Action,
}
}
// FavMList def.
type FavMList struct {
Page struct {
Num int `json:"num"`
Size int `json:"size"`
Count int `json:"count"`
} `json:"page"`
List []*arcwar.Arc `json:"list"`
}
// RespFavAct is response strure for favorite actions
type RespFavAct struct {
Code int `json:"code"`
Message string `json:"message"`
}

View File

@@ -0,0 +1,97 @@
package model
// ResFollow is the result structure from PGC API
type ResFollow struct {
Code int `json:"code"`
Count string `json:"count"`
Pages string `json:"pages"`
Message string `json:"message"`
Result []*Follow `json:"result"`
}
// Up is the uploader info
type Up struct {
Mid string `json:"mid"`
Up string `json:"up"`
}
// EP is the newest EP info
type EP struct {
AVID string `json:"av_id"`
Coins string `json:"coins"`
Cover string `json:"cover"`
Danmaku string `json:"danmaku"`
EpisodeID string `json:"episode_id"`
Index string `json:"index"`
IndexTitle string `json:"index_title"`
IsWebplay string `json:"is_webplay"`
Page string `json:"page"`
Up *Up `json:"up"`
UpdateTime string `json:"update_time"`
WebplayURL string `json:"webplay_url"`
}
// Tag is the tag info
type Tag struct {
Bottoms string `json:"bottoms"`
Cover string `json:"cover"`
Index string `json:"index"`
OrderType string `json:"orderType"`
Seasons []string `json:"seasons"`
StyleID string `json:"style_id"`
TagID string `json:"tag_id"`
TagName string `json:"tag_name"`
Tops string `json:"tops"`
Type string `json:"type"`
}
// UserSeason is the user's season info
type UserSeason struct {
Attention string `json:"attention"`
LastEPID string `json:"last_ep_id"`
LastEPIndex string `json:"last_ep_index"`
LastTime string `json:"last_time"`
}
// Follow is the main structure of the followed season
type Follow struct {
Actor []string `json:"actor"`
Alias string `json:"alias"`
AllowBP string `json:"allow_bp"`
AllowDownload string `json:"allow_download"`
Area string `json:"area"`
AreaLimit int `json:"arealimit"`
BangumiID string `json:"bangumi_id"`
BangumiTitle string `json:"bangumi_title"`
Brief string `json:"brief"`
Coins string `json:"coins"`
Copyright string `json:"copyright"`
Cover string `json:"cover"`
DanmakuCount string `json:"danmaku_count"`
Episodes []string `json:"episodes"`
EDJump int `json:"ed_jump"`
Evaluate string `json:"evaluate"`
Favorites string `json:"favorites"`
IsFinish string `json:"is_finish"`
Progress string `json:"progress"`
NewEP *EP `json:"new_ep"`
NewestEPID string `json:"newest_ep_id"`
NewestEPIndex string `json:"newest_ep_index"`
PlayCount string `json:"play_count"`
PubTime string `json:"pub_time"`
RelatedSeasons []string `json:"related_seasons"`
SeasonID string `json:"season_id"`
SeasonTitle string `json:"season_title"`
Seasons []string `json:"seasons"`
ShareURL string `json:"share_url"`
SPID string `json:"spid"`
SquareCover string `json:"squareCover"`
Staff string `json:"staff"`
Tag2s []string `json:"tag2s"`
Tags []*Tag `json:"tags"`
Title string `json:"title"`
TotalCount string `json:"total_count"`
UserSeason *UserSeason `json:"user_season"`
Weekday string `json:"weekday"`
CornerMark *SnVipCorner `json:"cornermark"`
}

View File

@@ -0,0 +1,29 @@
package(default_visibility = ["//visibility:public"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_library",
)
go_library(
name = "go_default_library",
srcs = ["label.go"],
importpath = "go-common/app/interface/main/tv/model/goblin",
tags = ["automanaged"],
visibility = ["//visibility:public"],
deps = ["//app/interface/main/tv/conf:go_default_library"],
)
filegroup(
name = "package-srcs",
srcs = glob(["**"]),
tags = ["automanaged"],
visibility = ["//visibility:private"],
)
filegroup(
name = "all-srcs",
srcs = [":package-srcs"],
tags = ["automanaged"],
visibility = ["//visibility:public"],
)

View File

@@ -0,0 +1,65 @@
package goblin
import (
"strings"
"go-common/app/interface/main/tv/conf"
)
// Label def.
type Label struct {
ID int `json:"id"`
Name string `json:"name"`
Param string `json:"param"`
ParamName string `json:"param_name"`
Value string `json:"value"`
}
// TypeLabels def.
type TypeLabels struct {
ParamName string `json:"param_name"`
Param string `json:"param"`
Labels []*Label `json:"labels"`
}
// FromLabels def.
func (v *TypeLabels) FromLabels(labels []*Label) {
if len(labels) == 0 {
return
}
v.Param = labels[0].Param
v.ParamName = labels[0].ParamName
v.Labels = labels
}
// IndexLabels is used to combine the data in memory
type IndexLabels struct {
PGC map[int][]*TypeLabels // key is category, value is all the param and their labels
UGC map[int][]*TypeLabels
}
// YearVDur def.
type YearVDur struct {
Dur string `json:"dur"`
}
// TransYear transforms the value of year type labels
func (v *Label) TransYear(cfg *conf.IndexLabel) {
if !cfg.IsYear(v.Param) {
return
}
if len(cfg.YearV) == 0 {
return
}
if newV, ok := cfg.YearV[v.Value]; ok { // replace the value
v.Value = newV.Dur
}
if !strings.Contains(v.Value, "-") {
v.Value = v.Value + "-" + v.Value
} else { // transform 2004-2000 to 2000-2004
years := strings.Split(v.Value, "-")
if len(years) == 2 && years[0] != "" && years[1] != "" {
v.Value = years[1] + "-" + years[0]
}
}
}

View File

@@ -0,0 +1,32 @@
package(default_visibility = ["//visibility:public"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_library",
)
go_library(
name = "go_default_library",
srcs = ["history.go"],
importpath = "go-common/app/interface/main/tv/model/history",
tags = ["automanaged"],
visibility = ["//visibility:public"],
deps = [
"//app/interface/main/history/model:go_default_library",
"//app/interface/main/tv/model:go_default_library",
],
)
filegroup(
name = "package-srcs",
srcs = glob(["**"]),
tags = ["automanaged"],
visibility = ["//visibility:private"],
)
filegroup(
name = "all-srcs",
srcs = [":package-srcs"],
tags = ["automanaged"],
visibility = ["//visibility:public"],
)

View File

@@ -0,0 +1,69 @@
package history
import (
hismodel "go-common/app/interface/main/history/model"
"go-common/app/interface/main/tv/model"
)
// HisRes is the history resource model
type HisRes struct {
Mid int64 `json:"mid,omitempty"`
Oid int64 `json:"oid"` //
Sid int64 `json:"season_id,omitempty"`
Epid int64 `json:"epid,omitempty"`
Cid int64 `json:"cid,omitempty"`
Business string `json:"-"`
DT int8 `json:"dt,omitempty"`
Pro int64 `json:"pro"`
PageDuration int64 `json:"duration"`
Unix int64 `json:"view_at"`
Type int `json:"type"` // 1=pgc, 2=ugc
Title string `json:"title"` // common
Cover string `json:"cover"` // common
Page *HisPage `json:"page,omitempty"` // ugc page
EPMeta *HisEP `json:"bangumi,omitempty"` // pgc ep
CornerMark *model.SnVipCorner `json:"cornermark"`
}
// HisEP is history EP struct
type HisEP struct {
EPID int64 `json:"ep_id"`
Cover string `json:"cover"`
Title string `json:"title"`
LongTitle string `json:"long_title"`
}
// HisPage is history page struct
type HisPage struct {
CID int64 `json:"cid"`
Part string `json:"part"`
Page int `json:"page"`
}
// HisMC is history structure in MC
type HisMC struct {
MID int64
Res []*HisRes
LastViewAt int64 // timestamp the first view_at of cursor
}
// Dur is duration struct
type Dur struct {
Oid int64
Duration int64
}
// RespCacheHis is the the response of cacheHis function
type RespCacheHis struct {
Filtered []*HisRes
Res []*hismodel.Resource
UseCache bool
}
// ReqCombineHis is the request for the combineHis function
type ReqCombineHis struct {
Mid int64
OriRes []*hismodel.Resource
OkSids map[int64]int
OkAids map[int64]int
}

View File

@@ -0,0 +1,135 @@
package model
import (
"go-common/library/time"
)
const (
_TypeUGC = 2
_TypePGC = 1
)
// Homepage is the home page struct
type Homepage struct {
Recom []*Card `json:"recom"`
Latest []*Card `json:"latest"`
Lists map[string][]*Card `json:"lists"`
Follow []*Follow `json:"follow,omitempty"`
}
// Card is the unit to display
type Card struct {
SeasonID int `json:"season_id"`
Title string `json:"title"`
Cover string `json:"cover"`
Type int `json:"type"` // 1=pgc, 2=ugc
NewEP *NewEP `json:"new_ep"`
CornerMark *SnVipCorner `json:"cornermark"`
}
// IsUGC returns whether the card is ugc card
func (c Card) IsUGC() bool {
return c.Type == _TypeUGC
}
// BePGC def.
func (c *Card) BePGC() {
c.Type = _TypePGC
}
// NewEP is the latest EP of a season
type NewEP struct {
ID int64 `json:"id"`
Index string `json:"index"`
IndexShow string `json:"index_show"`
Cover string `json:"cover"`
}
// Rank represents the table TV_RANK
type Rank struct {
ID int64
Rank int
Title string
Type int8
CID int64
ContID int64
Category int8
Position int32
IsDeleted int8
Ctime time.Time
Mtime time.Time
}
// SimpleRank picks the necessary fields from tv_rank
type SimpleRank struct {
ContID int64
ContType int
}
// RespModInterv is the response struct for mod intervention
type RespModInterv struct {
Ranks []*SimpleRank
AIDs []int64
SIDs []int64
}
// IsUGC returns whether the card is ugc card
func (c SimpleRank) IsUGC() bool {
return c.ContType == _TypeUGC
}
// ReqZone is the request struct of zone page
type ReqZone struct {
SType int
IntervType int
LengthLimit int
IntervM int
PGCListM map[int][]*Card
}
//RespAI is the response of AI ugc rank data
type RespAI struct {
Note string `json:"note"`
SourceData string `json:"source_data"`
Code int `json:"code"`
Num int `json:"num"`
List []*AIData `json:"list"`
}
// AIData is the ai card structure
type AIData struct {
AID int `json:"aid"`
MID int `json:"mid"`
Pts int `json:"pts"`
Play int `json:"play"`
Coints int `json:"coins"`
VideoReview int `json:"video_review"`
}
//ToCard transforms an ArcCMS to Card
func (a ArcCMS) ToCard() *Card {
return &Card{
SeasonID: int(a.AID),
Title: a.Title,
Cover: a.Cover,
Type: _TypeUGC,
NewEP: &NewEP{Cover: a.Cover},
}
}
//ToIdxSn transforms an ArcCMS to IdxSeason
func (a ArcCMS) ToIdxSn() *IdxSeason {
return &IdxSeason{
SeasonID: a.AID,
Title: a.Title,
Cover: a.Cover,
Upinfo: "",
}
}
// ReqZoneInterv is the request structure for zone intervention
type ReqZoneInterv struct {
RankType int
Category int
Limit int
}

View File

@@ -0,0 +1,311 @@
package model
import (
"fmt"
"net/url"
"go-common/library/time"
)
const (
_epFree = 2
)
// SeasonCMS defines the elements could be changed from TV CMS side
type SeasonCMS struct {
SeasonID int64
Cover string
Desc string
Title string
UpInfo string
Category int8 // - cn, jp, movie, tv, documentary
Area string // - cn, jp, others
Playtime time.Time
Role string
Staff string
NewestOrder int // the newest passed ep's order
NewestEPID int64 // the newest passed ep's ID
NewestNb int // the newest ep's number ( after keyword filter )
TotalNum int
Style string
OriginName string
Alias string
PayStatus int
}
// NeedVip returns whether the season need vip to watch
func (s *SeasonCMS) NeedVip() bool {
return s.PayStatus == 1
}
// IdxSn is the structure of season in the index page
func (s *SeasonCMS) IdxSn() (idx *IdxSeason) {
return &IdxSeason{
SeasonID: s.SeasonID,
Title: s.Title,
Cover: s.Cover,
Upinfo: s.UpInfo,
}
}
// EpCMS defines the elements could be changed from TV CMS side
type EpCMS struct {
EPID int64 `json:"epid"`
Cover string `json:"cover"`
Title string `json:"title"`
Subtitle string `json:"subtitle"`
PayStatus int `json:"pay_status"`
}
// IsFree def.
func (v *EpCMS) IsFree() bool {
return v.PayStatus == _epFree
}
// EpDecor is used to decorate ep
type EpDecor struct {
*EpCMS
Watermark bool `json:"watermark"`
}
// ArcCMS reprensents the archive data structure in MC
type ArcCMS struct {
Title string
AID int64
Content string
Cover string
TypeID int
Pubtime time.Time
Videos int
Valid int
Deleted int
Result int
}
// NotDeleted def.
func (s *ArcCMS) NotDeleted() bool {
return s.Deleted == 0
}
// CanPlay returns whether the arc can play or not
func (s *ArcCMS) CanPlay() bool {
return s.Valid == 1 && s.Result == 1 && s.Deleted == 0
}
// VideoCMS def.
type VideoCMS struct {
// Media Info
CID int64
Title string
AID int64
IndexOrder int
// Auth Info
Valid int
Deleted int
Result int
}
// CanPlay returns whether the arc can play or not
func (s *VideoCMS) CanPlay() bool {
return s.Valid == 1 && s.Result == 1 && s.Deleted == 0
}
// NotDeleted def.
func (s *VideoCMS) NotDeleted() bool {
return s.Deleted == 0
}
// Auditing returns whether the video is begin audited by the license owner
func (s *VideoCMS) Auditing() bool {
return s.Result == 0 && s.Deleted == 0
}
// MediaParam def.
type MediaParam struct {
SeasonID int64 `form:"season_id"`
EpID int64 `form:"ep_id"`
TrackPath string `form:"track_path" validate:"required"`
AccessKey string `form:"access_key"`
MobiAPP string `form:"mobi_app" validate:"required"`
Platform string `form:"platform"`
Build int64 `form:"build"`
}
// GenerateUrl generates url.Values from tv media param struct
func (v *MediaParam) GenerateUrl() (params url.Values) {
params = url.Values{}
params.Set("build", fmt.Sprintf("%d", v.Build))
params.Set("mobi_app", v.MobiAPP)
params.Set("platform", v.Platform)
params.Set("access_key", v.AccessKey)
params.Set("track_path", v.TrackPath)
params.Set("season_id", fmt.Sprintf("%d", v.SeasonID))
return
}
// MediaResp is the structure of PGC display api response
type MediaResp struct {
Response
Result *SeasonDetail `json:"result"`
}
// SeasonDetail def
type SeasonDetail struct {
Episodes []*Episode `json:"episodes"`
IsNewDanmaku int `json:"is_new_danmaku"`
NewestEP *NewestEP `json:"newest_ep"`
Stat *Stat `json:"stat"`
UserStatus *UserStatus `json:"user_status"`
Sponsor *Sponsor `json:"sponsor"`
SeriesID int `json:"series_id"`
SnDetailCore
}
// CmsInterv def.
func (v *SnDetailCore) CmsInterv(snCMS *SeasonCMS) {
if snCMS.Title != "" {
v.Title = snCMS.Title
}
if snCMS.Cover != "" {
v.Cover = snCMS.Cover
}
if snCMS.Desc != "" {
v.Evaluate = snCMS.Desc
}
}
// UserStatus def
type UserStatus struct {
Follow int `json:"follow"`
IsVip int `json:"is_vip"`
Pay int `json:"pay"`
PayPackPaid int `json:"pay_pack_paid"`
Sponsor int `json:"sponsor"`
WatchProgress *WatchProgress `json:"watch_progress"`
}
// WatchProgress def.
type WatchProgress struct {
LastEpID int `json:"last_ep_id"`
LastEPIndex string `json:"last_ep_index"`
LastTime int64 `json:"last_time"`
}
// Stat def
type Stat struct {
Danmakus int `json:"danmakus"`
Favorites int `json:"favorites"`
Views int `json:"views"`
}
// List def
type List struct {
Face string `json:"face"`
UID int `json:"uid"`
Uname string `json:"uname"`
}
// Sponsor def
type Sponsor struct {
List []*List `json:"list"`
PointActivity *PointActivity `json:"point_activity"`
TotalBpCount int `json:"total_bp_count"`
WeekBpCount int `json:"week_bp_count"`
}
// PointActivity def
type PointActivity struct {
Content string `json:"content"`
Link string `json:"link"`
Tip string `json:"tip"`
}
// Season def
type Season struct {
SeasonV2
Title string `json:"title"`
}
// SeasonV2 def
type SeasonV2 struct {
IsNew int `json:"is_new"`
SeasonID int `json:"season_id"`
SeasonTitle string `json:"season_title"`
}
// Rights def
type Rights struct {
AllowBp int `json:"allow_bp"`
AllowDownload int `json:"allow_download"`
AllowReview int `json:"allow_review"`
AreaLimit int `json:"area_limit"`
BanAreaShow int `json:"ban_area_show"`
Copyright string `json:"copyright"`
IsPreview int `json:"is_preview"`
}
// Rating def
type Rating struct {
Count int `json:"count"`
Score float64 `json:"score"`
}
// Publish def
type Publish struct {
IsFinish int `json:"is_finish"`
IsStarted int `json:"is_started"`
PubTime string `json:"pub_time"`
PubTimeShow string `json:"pub_time_show"`
Weekday int `json:"weekday"`
}
// Paster def
type Paster struct {
AID int `json:"aid"`
CID int `json:"cid"`
AllowJump int `json:"allow_jump"`
Duration int `json:"duration"`
Type int `json:"type"`
URL string `json:"url"`
}
// NewestEP def
type NewestEP struct {
Desc string `json:"desc"`
ID int `json:"id"`
Index string `json:"index"`
IsNew int `jsontt:"is_new"`
}
// Episode def
type Episode struct {
AID int `json:"aid"`
CID int `json:"cid"`
Cover string `json:"cover"`
EPID int64 `json:"ep_id"`
EpisodeStatus int `json:"episode_status"`
From string `json:"from"`
Index string `json:"index"`
IndexTitle string `json:"index_title"`
MID int `json:"mid"`
Page int `json:"page"`
ShareURL string `json:"share_url"`
VID string `json:"vid"`
WaterMark bool `json:"hidemark"` // true means in the whitelist
}
// CmsInterv def.
func (v *Episode) CmsInterv(epCMS *EpCMS) {
if epCMS.Cover != "" {
v.Cover = epCMS.Cover
}
if epCMS.Title != "" {
v.IndexTitle = epCMS.Title
}
}
// ParamStyle .
type ParamStyle struct {
Name string `json:"name"`
StyleID int `json:"style_id"`
}

View File

@@ -0,0 +1,137 @@
package model
import "go-common/library/ecode"
// SnDetailCore is the common part of pgc media v1 and v2
type SnDetailCore struct {
Cover string `json:"cover"`
Evaluate string `json:"evaluate"`
Link string `json:"link"`
MediaID int `json:"media_id"`
Mode int `json:"mode"`
Paster *Paster `json:"paster"`
Publish *Publish `json:"publish"`
Rating *Rating `json:"rating"`
SeasonID int64 `json:"season_id"`
SeasonStatus int `json:"season_status"`
SeasonTitle string `json:"season_title"`
SeasonType int `json:"season_type"`
ShareURL string `json:"share_url"`
SquareCover string `json:"square_cover"`
Title string `json:"title"`
TotalEp int `json:"total_ep"`
Rights *Rights `json:"rights"`
StyleLabel []*ParamStyle `json:"style_label"`
}
// SnDetailV2 def
type SnDetailV2 struct {
Episodes []*EpisodeV2 `json:"episodes"`
NewestEP *NewEPV2 `json:"new_ep"`
Stat *StatV2 `json:"stat"`
UserStatus *UserStatusV2 `json:"user_status"`
Seasons []*SeasonV2 `json:"seasons"`
Section []*Section `json:"section"`
Type int `json:"type"`
SnDetailCore
}
// TypeTrans def.
func (v *SnDetailV2) TypeTrans() {
v.SeasonType = v.Type
}
// Section def.
type Section struct {
Episodes []*EpisodeV2 `json:"episodes"`
}
// EpisodeV2 def.
type EpisodeV2 struct {
AID int64 `json:"aid"`
Badge string `json:"badge"`
BadgeType int `json:"badge_type"`
CID int64 `json:"cid"`
Cover string `json:"cover"`
From string `json:"from"`
ID int64 `json:"id"`
LongTitle string `json:"long_title"`
ShareURL string `json:"share_url"`
Status int `json:"status"`
Title string `json:"title"`
VID string `json:"vid"`
WaterMark bool `json:"hidemark"` // true means in the whitelist
CornerMark *CornerMark `json:"cornermark"`
}
// CornerMark def.
type CornerMark struct {
Title string `json:"title"`
Cover string `json:"cover"`
}
// SnVipCorner def.
type SnVipCorner struct {
Title string `json:"title"`
Cover string `json:"cover"`
}
// CmsInterv def.
func (v *EpisodeV2) CmsInterv(epCMS *EpCMS) {
if epCMS.Cover != "" {
v.Cover = epCMS.Cover
}
if epCMS.Title != "" {
v.LongTitle = epCMS.Title
}
}
// NewEPV2 def.
type NewEPV2 struct {
Desc string `json:"desc"`
ID int64 `json:"id"`
IsNew int `json:"is_new"`
Title string `json:"title"`
}
// StatV2 def. 3 new fields
type StatV2 struct {
Coin int `json:"coin"`
Reply int `json:"reply"`
Share int `json:"share"`
Stat
}
// UserStatusV2 def.
type UserStatusV2 struct {
Follow int `json:"follow"`
Pay int `json:"pay"`
Progress *WatchProgress `json:"watch_progress"`
Review *ReviewV2 `json:"review"`
Sponsor int `json:"sponsor"`
}
// ReviewV2 def.
type ReviewV2 struct {
IsOpen int `json:"is_open"`
}
// Response standard structure
type Response struct {
Code int `json:"code"`
Message string `json:"message"`
}
// CodeErr generates the code error
func (r *Response) CodeErr() (err error) {
if r.Code != ecode.OK.Code() {
err = ecode.Int(r.Code)
}
return
}
// MediaRespV2 is the structure of PGC display api response
type MediaRespV2 struct {
Response
Result *SnDetailV2 `json:"result"`
}

View File

@@ -0,0 +1,86 @@
package model
const (
_OldIdx = 0
_OldZone = 1
_PgcIdx = 2
_UgcIdx = 3
_homepageID = 0
)
// Module def.
type Module struct {
ID int `json:"id"`
PageID int `json:"page_id"`
Type int `json:"type"`
Title string `json:"title"`
Icon string `json:"icon"`
Source int `json:"source"`
Flexible int `json:"flexible"`
Capacity int `json:"capacity"`
More int `json:"more"`
MoreType int `json:"more_type"`
MoreNewPage int `json:"more_new_page"`
MorePage int `json:"more_page"`
Order int `json:"order"`
Data []*ModCard `json:"data"`
SrcType int `json:"src_type"`
}
// JumpNewIdx tells whether this modules jumps to the new idx page
func (m *Module) JumpNewIdx() bool {
return m.MoreType == _PgcIdx || m.MoreType == _UgcIdx
}
// OnHomepage tells whether the module is on the homepage
func (m *Module) OnHomepage() bool {
return m.PageID == _homepageID
}
// MoreTreat treats the morepage and moretype related, used for zone/modpages, not homepage
func (m *Module) MoreTreat() {
if m.MorePage == 0 {
return
}
if m.MoreType == _OldIdx || m.MoreType == _OldZone { // if more jump setting is old zone/idx (<=1.13), set more_new_page = more_page
m.MoreNewPage = m.MorePage
}
if m.MoreType == _PgcIdx || m.MoreType == _UgcIdx { // if more jump setting is new ugc/pgc idx, set more_new_page = Idx category, more_page = page_id
m.MoreNewPage = m.MorePage
m.MorePage = m.PageID
}
}
// IsUGC returns whether the module is filled by ugc or not
func (m Module) IsUGC() bool {
return m.SrcType == _TypeUGC
}
// ModCard structure, based on normal Card, 4 more fields for Follow Module
type ModCard struct {
Card
LastEPIndex string `json:"last_ep_index"`
NewestEPIndex string `json:"newest_ep_index"`
TotalCount string `json:"total_count"`
IsFinish string `json:"is_finish"`
}
// ReqModData is the request body to modData function
type ReqModData struct {
Mod *Module
PGCListM map[int][]*Card
UGCListM map[int][]*Card
}
// ReqPageFollow is the request body to PageFollow function
type ReqPageFollow struct {
AccessKey string `form:"access_key"`
PageID int `form:"page_id" validate:"min=0"`
Build int `form:"build"`
}
// ReqHomeFollow is the request body to HomeFollow function
type ReqHomeFollow struct {
AccessKey string `form:"access_key"`
Build int `form:"build"`
}

View File

@@ -0,0 +1,33 @@
package model
import "go-common/library/time"
// Channel defines the structure of the channel & splash data
type Channel struct {
ID int
Title string
Desc string
Splash string
Deleted int
Ctime time.Time
Mtime time.Time
}
//ReqTransode is the request structure for the transcode api
type ReqTransode struct {
ContType string `form:"cont_type" validate:"required"` // content type: pgc/ugc
CID int64 `form:"cid" validate:"required"`
Action int64 `form:"action" validate:"min=0,max=2"` // 1 = finished, others = failed
}
// Hotword item def.
type Hotword struct {
Keyword string `json:"keyword"`
Status string `json:"status"`
}
// ReqApply is request for apply time storage
type ReqApply struct {
CID int64 `form:"cid" validate:"required"`
ApplyTime int64 `form:"apply_time" validate:"required"`
}

View File

@@ -0,0 +1,20 @@
package model
// PgcResponse is the result structure from PGC API
type PgcResponse struct {
Code int `json:"code"`
Message string `json:"message"`
Result map[string]*SeasonCard `json:"result"`
}
// SeasonCard is the result structure from PGC API
type SeasonCard struct {
NewEP *PgcNewEP `json:"new_ep"`
}
// PgcNewEP is the result from pgc return pgc new ep value
type PgcNewEP struct {
ID int `json:"id"`
IndexShow string `json:"index_show"`
Cover string `json:"cover"`
}

View File

@@ -0,0 +1,44 @@
package model
// PlayURLReq is used for getting ugc play url param from app
type PlayURLReq struct {
Platform string `form:"platform" validate:"required"`
Device string `form:"device"`
Expire string `form:"expire"`
Cid string `form:"cid" validate:"required"`
Avid int64 `form:"avid" validate:"required"`
Build string `form:"build"`
Qn string `form:"qn"`
Mid string `form:"mid"`
Npcybs string `form:"npcybs"`
Buvid string `form:"buvid"`
TrackPath string `form:"track_path"`
AccessKey string `form:"access_key"`
}
//PlayURLResp is used for return ugc play url result
type PlayURLResp struct {
Code int `json:"code"`
Result string `json:"result"`
Message string `json:"message"`
From string `json:"from"`
Quality int `json:"quality"`
Format string `json:"format"`
Timelength int `json:"timelength"`
AcceptFormat string `json:"accept_format"`
AcceptDescription []string `json:"accept_description"`
AcceptQuality []int `json:"accept_quality"`
AcceptWatermark []bool `json:"accept_watermark"`
VideoCodecid int `json:"video_codecid"`
VideoProject bool `json:"video_project"`
SeekParam string `json:"seek_param"`
SeekType string `json:"seek_type"`
Durl []struct {
Order int `json:"order"`
Length int `json:"length"`
Size int `json:"size"`
Ahead string `json:"ahead"`
Vhead string `json:"vhead"`
URL string `json:"url"`
} `json:"durl"`
}

View File

@@ -0,0 +1,33 @@
package model
// ResponseRecom is the result structure from PGC API
type ResponseRecom struct {
Code int `json:"code"`
Message string `json:"message"`
Result *ResultRecom `json:"result"`
}
// ResultRecom def.
type ResultRecom struct {
SeasonID int `json:"season_id"`
From int `json:"from"`
Title string `json:"title"`
List []*Recom `json:"list"`
}
// Recom def.
type Recom struct {
Cover string `json:"cover"`
FollowCount int `json:"follow_count"`
IsFinish int `json:"is_finish"`
IsStarted int `json:"is_started"`
NewestEPCover string `json:"newest_ep_cover"`
NewestEPIndex string `json:"newest_ep_index"`
SeasonID int64 `json:"season_id"`
SeasonStatus int `json:"season_status"`
SeasonType int `json:"season_type"`
SeasonTypeName string `json:"season_type_name"`
Title string `json:"title"`
TotalCount int `json:"total_count"`
CornerMark *SnVipCorner `json:"cornermark"`
}

View File

@@ -0,0 +1,9 @@
package model
// Region .
type Region struct {
PageID int `json:"id"`
Title string `json:"name"`
IndexTid int `json:"index_tid"`
IndexType int `json:"index_type"`
}

View File

@@ -0,0 +1,41 @@
package(default_visibility = ["//visibility:public"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_library",
)
go_library(
name = "go_default_library",
srcs = [
"client.go",
"elastic.go",
"result.go",
"sug.go",
"wild.go",
],
importpath = "go-common/app/interface/main/tv/model/search",
tags = ["automanaged"],
visibility = ["//visibility:public"],
deps = [
"//app/interface/main/tv/model:go_default_library",
"//app/interface/main/tv/model/thirdp:go_default_library",
"//app/service/main/archive/api:go_default_library",
"//library/time:go_default_library",
"//vendor/github.com/siddontang/go-mysql/mysql:go_default_library",
],
)
filegroup(
name = "package-srcs",
srcs = glob(["**"]),
tags = ["automanaged"],
visibility = ["//visibility:private"],
)
filegroup(
name = "all-srcs",
srcs = [":package-srcs"],
tags = ["automanaged"],
visibility = ["//visibility:public"],
)

View File

@@ -0,0 +1,17 @@
package search
//RespForClient def.
type RespForClient struct {
*ResultResponse
SearchType string `json:"search_type"`
PageInfo *pageinfo `json:"pageinfo"`
ResultAll *AllForClient `json:"resultall"`
PGC []*CommonResult `json:"pgc"`
UGC []*CommonResult `json:"ugc"`
}
//AllForClient def.
type AllForClient struct {
Pgc []*CommonResult `json:"tvpgc"`
Ugc []*CommonResult `json:"tvugc"`
}

View File

@@ -0,0 +1,266 @@
package search
import (
"encoding/json"
"go-common/app/interface/main/tv/model"
"go-common/app/interface/main/tv/model/thirdp"
"go-common/library/time"
"github.com/siddontang/go-mysql/mysql"
)
const (
_pgcType = 1
_ugcType = 2
_hotestOrder = 2
// AllLabel is the string that means all data
AllLabel = "-1" // it means all for index
)
// EsPage def.
type EsPage struct {
Num int `json:"num"`
Size int `json:"size"`
Total int `json:"total"`
PageNum int `json:"page_num"`
}
// GetPageNb def.
func (v *EsPage) GetPageNb() {
if v.Total%v.Size == 0 {
v.PageNum = v.Total / v.Size
} else {
v.PageNum = v.Total/v.Size + 1
}
}
// EsPgcResult def.
type EsPgcResult struct {
Page *EsPage `json:"page"`
Result []*PgcEsMdl `json:"result"`
}
// EsUgcResult def.
type EsUgcResult struct {
Page *EsPage `json:"page"`
Result []*UgcEsMdl `json:"result"`
}
// UgcEsMdl def.
type UgcEsMdl struct {
AID int64 `json:"aid"`
TypeID int32 `json:"typeid"`
}
// PgcEsMdl def.
type PgcEsMdl struct {
SeasonID int64 `json:"season_id"`
}
// EsCard def.
type EsCard struct {
model.Card
DataType int `json:"data_type"` // 1=pgc, 2=ugc
}
// EsPager def.
type EsPager struct {
Title string `json:"title"`
Page *EsPage `json:"page"`
Result []*EsCard `json:"result"`
}
// FromPgc def.
func (v *EsCard) FromPgc(card *model.Card) {
v.Card = *card
v.DataType = _pgcType
}
// FromUgc def.
func (v *EsCard) FromUgc(card *model.Card) {
v.Card = *card
v.DataType = _ugcType
}
// ReqEsPn is part of the es request for page related cfg
type ReqEsPn struct {
Ps int `form:"ps" default:"50"`
Pn int `form:"pn" default:"1"`
Order int `form:"order" validate:"required"`
Sort int `form:"sort" default:"0"`
}
// ReqPgcIdx is bm request for pgc index
type ReqPgcIdx struct {
SeasonType int `form:"category" validate:"required,max=5"`
ProducerID int `form:"producer_id"`
Year string `form:"year"`
StyleID int `form:"style_id"`
PubDate string `form:"pub_date"`
SeasonMonth int `form:"season_month" validate:"max=10"`
SeasonStatus []int `form:"season_status,split"`
Copyright []int `form:"copyright,split"`
IsFinish string `form:"is_finish"`
Area []int `form:"area,split"`
SeasonVersion int `form:"season_version"`
ReqEsPn
}
// IsDefault def.
func (v *ReqPgcIdx) IsDefault() bool {
return v.Order == _hotestOrder && v.ProducerID <= 0 &&
v.IsAllStr(v.Year) && v.StyleID <= 0 && v.IsAllStr(v.PubDate) && v.SeasonMonth <= 0 &&
v.IsAll(v.SeasonStatus) && v.IsAll(v.Copyright) && v.IsAllStr(v.IsFinish) && v.IsAll(v.Area) &&
v.SeasonVersion <= 0
}
// IsDefault def.
func (v *ReqUgcIdx) IsDefault() bool {
return v.Order == _hotestOrder && v.SecondTID <= 0 && (v.PubTime == "" || v.PubTime == AllLabel)
}
// Title def.
func (v *ReqPgcIdx) Title() string {
return thirdp.PgcCat(v.SeasonType)
}
// PgcOrder treats the order to get the responding field
func (v *ReqPgcIdx) PgcOrder() (field string) {
switch v.Order {
case 0: // update time
return "latest_time"
case 1:
return "dm_count"
case 2:
return "play_count"
case 3: // follow
return "fav_count"
case 4:
return "score"
case 5: // for others
return "pub_time"
case 6: // for movie
return "release_date"
default:
return "play_count"
}
}
// IdxSort treats the sort
func IdxSort(sortV int) (sort string) {
switch sortV {
case 0:
return "desc"
case 1:
return "asc"
default:
return "desc"
}
}
// ReqUgcIdx is bm request for ugc index
type ReqUgcIdx struct {
ParentTID int32 `form:"category" validate:"required"`
SecondTID int32 `form:"typeid"`
PubTime string `form:"pubtime"`
ReqEsPn
}
// TimeStr picks json str from request and returns the time range struct in String format
func (v *ReqUgcIdx) TimeStr() (res *UgcTime, err error) {
var pubTimeV = &UgcTimeV{}
if err = json.Unmarshal([]byte(v.PubTime), &pubTimeV); err != nil {
return
}
res = &UgcTime{
STime: pubTimeV.STime.Time().Format(mysql.TimeFormat),
ETime: pubTimeV.ETime.Time().Format(mysql.TimeFormat),
}
return
}
// UgcTimeV def. INT64 for http
type UgcTimeV struct {
STime time.Time `json:"stime"`
ETime time.Time `json:"etime"`
}
// UgcTime def. STRING for ES
type UgcTime struct {
STime string `json:"stime"`
ETime string `json:"etime"`
}
// SrvUgcIdx is the request treated by service for DAO, like type_id field and pub_time
type SrvUgcIdx struct {
TIDs []int32
PubTime *UgcTime
ReqEsPn
}
// UgcOrder treats the order to get the responding field
func (v *SrvUgcIdx) UgcOrder() (field string) {
switch v.Order {
case 1: // update time
return "pubtime"
case 2:
return "click"
default:
return "click"
}
}
// ReqIdxInterv is used for index intervention treatment
type ReqIdxInterv struct {
EsIDs []int64
Category int
IsPGC bool
Pn int
}
// FromPGC def.
func (v *ReqIdxInterv) FromPGC(sids []int64, req *ReqPgcIdx) {
v.EsIDs = sids
v.Category = req.SeasonType
v.IsPGC = true
v.Pn = req.Pn
}
// FromUGC def.
func (v *ReqIdxInterv) FromUGC(aids []int64, req *ReqUgcIdx) {
v.EsIDs = aids
v.Category = int(req.ParentTID)
v.IsPGC = false
v.Pn = req.Pn
}
// IdxIntervSave def.
type IdxIntervSave struct {
Pgc map[int][]int64
Ugc map[int][]int64
}
// IsAll checks whether a slice of int means all data
func (v *ReqPgcIdx) IsAll(params []int) (res bool) {
if len(params) == 0 {
return true
}
for _, v := range params {
if v < 0 {
return true
}
}
return false
}
// IsAllStr checks whether a string means all data
func (v *ReqPgcIdx) IsAllStr(duration string) (res bool) {
if duration == "" {
return true
}
if duration == AllLabel {
return true
}
return false
}

View File

@@ -0,0 +1,113 @@
package search
import (
"go-common/app/interface/main/tv/model"
)
// ResultResponse def .
type ResultResponse struct {
Page int `json:"page"`
Pagesize int `json:"pagesize"`
NumResults int `json:"numResults"`
NumPages int `json:"numPages"`
Seid string `json:"seid"`
}
type pageinfo struct {
Tvpgc *Page `json:"tvpgc"`
Tvugc *Page `json:"tvugc"`
}
// Page struct .
type Page struct {
NumResult int `json:"numResults"`
Total int `json:"total"`
Pages int `json:"pages"`
}
// RespAll def .
type RespAll struct {
Code int `json:"code"`
Msg string `json:"msg"`
*ResultResponse
PageInfo *pageinfo `json:"pageinfo"`
Result *AllResult `json:"result"`
}
// AllResult def .
type AllResult struct {
Pgc []*PgcResult `json:"tvpgc"`
Ugc []*UgcResult `json:"tvugc"`
}
// RespPgc def .
type RespPgc struct {
Code int `json:"code"`
Msg string `json:"msg"`
*ResultResponse
Result []*PgcResult `json:"result"`
}
// RespUgc def .
type RespUgc struct {
Code int `json:"code"`
Msg string `json:"msg"`
*ResultResponse
Result []*UgcResult `json:"result"`
}
// UgcResult def .
type UgcResult struct {
ID int `json:"id"`
Title string `json:"title"`
Cover string `json:"cover"`
Description string `json:"description"`
Pubtime int `json:"pubtime"`
Category int `json:"category"`
}
// PgcResult def .
type PgcResult struct {
*UgcResult
CV string `json:"cv"`
Staff string `json:"staff"`
CornerMark *model.SnVipCorner `json:"cornermark"`
}
// ToCommon transform pgc to common .
func (p *PgcResult) ToCommon() (res *CommonResult) {
return &CommonResult{
PgcResult: p,
Type: "pgc",
}
}
// ToCommon transform pgc to common .
func (p *UgcResult) ToCommon() (res *CommonResult) {
res = &CommonResult{}
res.PgcResult = &PgcResult{
UgcResult: p,
}
res.Type = "ugc"
return
}
// CommonResult is the common result for both pgc & ugc .
type CommonResult struct {
*PgcResult
Type string `json:"type"`
}
// ReqSearch def .
type ReqSearch struct {
SearchType string `form:"search_type" validate:"required"`
Order string `form:"order"`
Category int `form:"category"`
Platform string `form:"platform" validate:"required"`
Build string `form:"build" validate:"required"`
MobiAPP string `form:"mobi_app"`
Device string `form:"device"`
Keyword string `form:"keyword" validate:"required"`
Page int `form:"page" validate:"required,min=1"`
Pagesize int `form:"pagesize"`
}

View File

@@ -0,0 +1,55 @@
package search
// SugResponse is the structure of search api response
type SugResponse struct {
Code int `json:"code"`
Cost *Cost `json:"cost"`
Result *Result `json:"result"`
PageCaches *PageCaches `json:"page caches"`
Sengine *Sengine `json:"sengine"`
Stoken string `json:"stoken"`
}
// Cost def.
type Cost struct {
About *About `json:"about"`
}
// About def.
type About struct {
ParamsCheck string `json:"params_check"`
Total string `json:"total"`
MainHandler string `json:"main_handler"`
}
// Result def.
type Result struct {
Tag []*STag `json:"tag"`
}
// STag def.
type STag struct {
Value string `json:"value"`
Ref int `json:"ref"`
Name string `json:"name"`
Spid int `json:"spid"`
Type string `json:"type"`
}
// PageCaches def.
type PageCaches struct {
SaveCache string `json:"save cache"`
}
// Sengine def.
type Sengine struct {
Usage int `json:"usage"`
}
// ReqSug def.
type ReqSug struct {
MobiApp string `form:"mobi_app"`
Build string `form:"build"`
Platform string `form:"platform"`
Term string `form:"term" validate:"required"`
}

View File

@@ -0,0 +1,647 @@
package search
import (
"bytes"
"fmt"
"regexp"
"strconv"
"strings"
v1 "go-common/app/service/main/archive/api"
xtime "go-common/library/time"
)
// default .
const (
GotoBangumi = "bangumi"
GotoAv = "av"
GotoWeb = "web"
GotoMovie = "movie"
GotoBangumiWeb = "bangumi_web"
GotoSp = "sp"
GotoLive = "live"
GotoGame = "game"
GotoAuthor = "author"
GotoClip = "clip"
GotoAlbum = "album"
GotoArticle = "article"
GotoAudio = "audio"
GotoSpecial = "special"
GotoBanner = "banner"
GotoSpecialS = "special_s"
GotoConverge = "converge"
GotoPGC = "pgc"
GotoChannel = "channel"
GotoEP = "ep"
GotoTwitter = "twitter"
CoverIng = "即将上映"
CoverPay = "付费观看"
CoverFree = "免费观看"
CoverVipFree = "付费观看"
CoverVipOnly = "专享"
CoverVipFirst = "抢先"
)
// UserSearch user search request .
type UserSearch struct {
SearchType string `form:"search_type" validate:"required"`
Order string `form:"order"`
Category int `form:"category"`
Platform string `form:"platform"`
Build string `form:"build"`
MobiAPP string `form:"mobi_app"`
Device string `form:"device"`
Keyword string `form:"keyword" validate:"required"`
Page int `form:"page" validate:"required,min=1"`
Pagesize int `form:"pagesize"`
UserType int `form:"user_type"`
Highlight int `form:"highlight"`
OrderSort int `form:"order_sort"`
FromSource string `form:"from_source"`
Buvid string `form:"buvid"`
Duration int `form:"duration"` // 视频时长
// 传递参数给到dao用
SeasonNum int `form:"season_num"`
MovieNum int `form:"movie_num"`
RID int `form:"rid"`
MID int64 `form:"mid"`
}
// User struct res .
type User struct {
Type string `json:"type"`
Mid int64 `json:"mid,omitempty"`
Name string `json:"uname,omitempty"`
Usign string `json:"usign,omitempty"`
Fans int `json:"fans,omitempty"`
Videos int `json:"videos,omitempty"`
Pic string `json:"upic,omitempty"`
VerifyInfo string `json:"verify_info"`
Level int `json:"level,omitempty"`
Gender int `json:"gender"`
IsUpuser int `json:"is_upuser,omitempty"`
IsLive int `json:"is_live,omitempty"`
RoomID int64 `json:"room_id,omitempty"`
Res []*struct {
Aid int64 `json:"aid,omitempty"`
Title string `json:"title,omitempty"`
Pubdate int64 `json:"pubdate,omitempty"`
ArcURL string `json:"arcurl,omitempty"`
Pic string `json:"pic,omitempty"`
Play interface{} `json:"play,omitempty"`
Danmaku int `json:"dm,omitempty"`
Coin int `json:"coin"`
Fav int `json:"fav"`
Desc string `json:"desc"`
Duration string `json:"duration,omitempty"`
} `json:"res,omitempty"`
OfficialVerify *OfficialVerify `json:"official_verify,omitempty"`
*ResultResponse
}
// OfficialVerify struct .
type OfficialVerify struct {
Type int `json:"type"`
Desc string `json:"desc,omitempty"`
}
// Search all .
type Search struct {
Code int `json:"code,omitempty"`
Trackid string `json:"seid,omitempty"`
Page int `json:"page,omitempty"`
PageSize int `json:"pagesize,omitempty"`
Total int `json:"total,omitempty"`
NumResults int `json:"numResults,omitempty"`
NumPages int `json:"numPages,omitempty"`
SuggestKeyword string `json:"suggest_keyword,omitempty"`
Attribute int32 `json:"exp_bits,omitempty"`
PageInfo struct {
Bangumi *Page `json:"bangumi,omitempty"`
UpUser *Page `json:"upuser,omitempty"`
BiliUser *Page `json:"bili_user,omitempty"`
User *Page `json:"user,omitempty"`
Movie *Page `json:"movie,omitempty"`
Film *Page `json:"pgc,omitempty"`
MediaBangumi *Page `json:"media_bangumi,omitempty"`
MediaFt *Page `json:"media_ft,omitempty"`
} `json:"pageinfo,omitempty"`
Result struct {
Bangumi []*Bangumi `json:"bangumi,omitempty"`
UpUser []*User `json:"upuser,omitempty"`
BiliUser []*User `json:"bili_user,omitempty"`
User []*User `json:"user,omitempty"`
Movie []*Movie `json:"movie,omitempty"`
Video []*Video `json:"video,omitempty"`
MediaBangumi []*Media `json:"media_bangumi,omitempty"`
MediaFt []*Media `json:"media_ft,omitempty"`
} `json:"result,omitempty"`
}
// Media struct .
type Media struct {
MediaID int64 `json:"media_id,omitempty"`
SeasonID int64 `json:"season_id,omitempty"`
Title string `json:"title,omitempty"`
OrgTitle string `json:"org_title,omitempty"`
Styles string `json:"styles,omitempty"`
Cover string `json:"cover,omitempty"`
PlayState int `json:"play_state,omitempty"`
MediaScore *struct {
Score float64 `json:"score,omitempty"`
UserCount int `json:"user_count,omitempty"`
} `json:"media_score,omitempty"`
MediaType int `json:"media_type,omitempty"`
CV string `json:"cv,omitempty"`
Staff string `json:"staff,omitempty"`
Areas string `json:"areas,omitempty"`
GotoURL string `json:"goto_url,omitempty"`
Pubtime xtime.Time `json:"pubtime,omitempty"`
HitColumns []string `json:"hit_columns,omitempty"`
}
// Movie struct .
type Movie struct {
Title string `json:"title"`
SpID string `json:"spid"`
Type string `json:"type"`
Aid int64 `json:"aid"`
Desc string `json:"description"`
Actors string `json:"actors"`
Staff string `json:"staff"`
Cover string `json:"cover"`
Pic string `json:"pic"`
ScreenDate string `json:"screenDate"`
Area string `json:"area"`
Status int `json:"status"`
Length int `json:"length"`
Pages int `json:"numPages"`
}
// Video struct .
type Video struct {
ID int64 `json:"id"`
Author string `json:"author"`
Title string `json:"title"`
Pic string `json:"pic"`
Desc string `json:"description"`
Play interface{} `json:"play"`
Danmaku int `json:"video_review"`
Duration string `json:"duration"`
Pages int `json:"numPages"`
ViewType string `json:"view_type"`
RecTags []string `json:"rec_tags"`
}
// ResultAll struct .
type ResultAll struct {
Trackid string `json:"trackid,omitempty"`
Page int `json:"page,omitempty"`
NavInfo []*NavInfo `json:"nav,omitempty"`
Items ResultItems `json:"items,omitempty"`
Item []*Item `json:"item,omitempty"` // 混排的数据(未用到)
Attribute int32 `json:"attribute"` // 实验中开关
}
// ResultItems struct .
type ResultItems struct {
Season2 []*Item `json:"season2,omitempty"`
Season []*Item `json:"season,omitempty"` // 老数据字段(未用到)
Upper []*Item `json:"upper,omitempty"`
Movie2 []*Item `json:"movie2,omitempty"`
Movie []*Item `json:"movie,omitempty"` // 老数据字段(未用到)
Archive []*Item `json:"archive,omitempty"`
}
// NavInfo struct .
type NavInfo struct {
Name string `json:"name"`
Total int `json:"total"`
Pages int `json:"pages"`
Type int `json:"type"`
Show int `json:"show_more,omitempty"`
}
// Item struct .
type Item struct {
TrackID string `json:"trackid,omitempty"`
LinkType string `json:"linktype,omitempty"`
Position int `json:"position,omitempty"`
SuggestKeyword string `json:"suggest_keyword,omitempty"`
Title string `json:"title,omitempty"`
Name string `json:"name,omitempty"`
Cover string `json:"cover,omitempty"`
URI string `json:"uri,omitempty"`
Param string `json:"param,omitempty"`
Goto string `json:"goto,omitempty"`
// av
Play int `json:"play,omitempty"`
Danmaku int `json:"danmaku,omitempty"`
Author string `json:"author,omitempty"`
ViewType string `json:"view_type,omitempty"`
PTime xtime.Time `json:"ptime,omitempty"`
RecTags []string `json:"rec_tags,omitempty"`
// media bangumi and mdeia ft
Prompt string `json:"prompt,omitempty"`
Episodes []*Item `json:"episodes,omitempty"`
Label string `json:"label,omitempty"`
// bangumi season
Finish int8 `json:"finish,omitempty"`
Started int8 `json:"started,omitempty"`
Index string `json:"index,omitempty"`
NewestCat string `json:"newest_cat,omitempty"`
NewestSeason string `json:"newest_season,omitempty"`
CatDesc string `json:"cat_desc,omitempty"`
TotalCount int `json:"total_count,omitempty"`
MediaType int `json:"media_type,omitempty"`
PlayState int `json:"play_state,omitempty"`
Style string `json:"style,omitempty"`
CV string `json:"cv,omitempty"`
Rating float64 `json:"rating,omitempty"`
Vote int `json:"vote,omitempty"`
RatingCount int `json:"rating_count,omitempty"`
BadgeType int `json:"badge_type,omitempty"`
// upper
Sign string `json:"sign,omitempty"`
Fans int `json:"fans,omitempty"`
Level int `json:"level,omitempty"`
Desc string `json:"desc,omitempty"`
OfficialVerify *OfficialVerify `json:"official_verify,omitempty"`
AvItems []*Item `json:"av_items,omitempty"`
Item []*Item `json:"item,omitempty"`
CTime int64 `json:"ctime,omitempty"`
IsUp bool `json:"is_up,omitempty"`
LiveURI string `json:"live_uri,omitempty"`
// movie
ScreenDate string `json:"screen_date,omitempty"`
Area string `json:"area,omitempty"`
CoverMark string `json:"cover_mark,omitempty"`
// user
Face string `json:"face,omitempty"`
// arc and sp
Arcs int `json:"archives,omitempty"`
// arc and movie
Duration string `json:"duration,omitempty"`
DurationInt int64 `json:"duration_int,omitempty"`
Actors string `json:"actors,omitempty"`
Staff string `json:"staff,omitempty"`
Length int `json:"length,omitempty"`
Status int `json:"status,omitempty"`
}
// Bangumi struct .
type Bangumi struct {
Name string `json:"name,omitempty"`
SeasonID int `json:"season_id,omitempty"`
Title string `json:"title,omitempty"`
Cover string `json:"cover,omitempty"`
Evaluate string `json:"evaluate,omitempty"`
NewestEpID int `json:"newest_ep_id,omitempty"`
NewestEpIndex string `json:"newest_ep_index,omitempty"`
IsFinish int `json:"is_finish,omitempty"`
IsStarted int `json:"is_started,omitempty"`
NewestCat string `json:"newest_cat,omitempty"`
NewestSeason string `json:"newest_season,omitempty"`
TotalCount int `json:"total_count,omitempty"`
Pages int `json:"numPages,omitempty"`
CatList *struct {
TV int `json:"tv"`
Movie int `json:"movie"`
Ova int `json:"ova"`
} `json:"catlist,omitempty"`
}
// TypeSearch struct .
type TypeSearch struct {
TrackID string `json:"trackid"`
Pages int `json:"pages"`
Total int `json:"total"`
Items []*Item `json:"items,omitempty"`
}
// Card for bangumi .
type Card struct {
SeasonID int64 `json:"season_id"`
IsFollow int `json:"is_follow"`
IsSelection int `json:"is_selection"`
Badge string `json:"badge"`
BadgeType int `json:"badge_type"`
Episodes []*Episode `json:"episodes"`
}
// Episode for bangumi card .
type Episode struct {
ID int64 `json:"id"`
Badge string `json:"badge"`
BadgeType int `json:"badge_type"`
Status int `json:"status"`
Cover string `json:"cover"`
Index string `json:"index"`
IndexTitle string `json:"index_title"`
}
// StatusMark cover status mark .
func StatusMark(status int) string {
if status == 0 {
return CoverIng
} else if status == 1 {
return CoverPay
} else if status == 2 {
return CoverFree
} else if status == 3 {
return CoverVipFree
} else if status == 4 {
return CoverVipOnly
} else if status == 5 {
return CoverVipFirst
}
return ""
}
// FillURI deal app schema .
func FillURI(gt, param string, f func(uri string) string) (uri string) {
switch gt {
case GotoAv, "":
uri = "bilibili://video/" + param
case GotoLive:
uri = "bilibili://live/" + param
case GotoBangumi:
uri = "bilibili://bangumi/season/" + param
case GotoBangumiWeb:
uri = "http://bangumi.bilibili.com/anime/" + param
case GotoGame:
uri = "bilibili://game_center/detail?id=" + param + "&sourceType=adPut"
case GotoSp:
uri = "bilibili://splist/" + param
case GotoAuthor:
uri = "bilibili://author/" + param
case GotoClip:
uri = "bilibili://clip/" + param
case GotoAlbum:
uri = "bilibili://album/" + param
case GotoArticle:
uri = "bilibili://article/" + param
case GotoWeb:
uri = param
case GotoPGC:
uri = "https://www.bilibili.com/bangumi/play/ss" + param
case GotoChannel:
uri = "bilibili://pegasus/channel/" + param + "/"
case GotoEP:
uri = "https://www.bilibili.com/bangumi/play/ep" + param
case GotoTwitter:
uri = "bilibili://pictureshow/detail/" + param
}
if f != nil {
uri = f(uri)
}
return
}
// search const
var getHightLight = regexp.MustCompile(`<em.*?em>`)
var (
// AvHandler .
AvHandler = func(a *v1.Arc) func(uri string) string {
return func(uri string) string {
if a == nil {
return uri
}
if a.Dimension.Height != 0 || a.Dimension.Width != 0 {
return fmt.Sprintf("%s?player_width=%d&player_height=%d&player_rotate=%d", uri, a.Dimension.Width, a.Dimension.Height, a.Dimension.Rotate)
}
return uri
}
}
)
// FromSeason .
func (i *Item) FromSeason(b *Bangumi, bangumi string) {
i.Title = b.Title
i.Cover = b.Cover
i.Goto = GotoBangumi
i.Param = strconv.Itoa(int(b.SeasonID))
i.URI = FillURI(bangumi, i.Param, nil)
i.Finish = int8(b.IsFinish)
i.Started = int8(b.IsStarted)
i.Index = b.NewestEpIndex
i.NewestCat = b.NewestCat
i.NewestSeason = b.NewestSeason
i.TotalCount = b.TotalCount
var buf bytes.Buffer
if b.CatList.TV != 0 {
buf.WriteString(`TV(`)
buf.WriteString(strconv.Itoa(b.CatList.TV))
buf.WriteString(`) `)
}
if b.CatList.Movie != 0 {
buf.WriteString(`剧场版(`)
buf.WriteString(strconv.Itoa(b.CatList.Movie))
buf.WriteString(`) `)
}
if b.CatList.Ova != 0 {
buf.WriteString(`OVA/OAD/SP(`)
buf.WriteString(strconv.Itoa(b.CatList.Ova))
buf.WriteString(`)`)
}
i.CatDesc = buf.String()
}
// FromUpUser form func .
func (i *Item) FromUpUser(u *User, as map[int64]*v1.Arc) {
i.Title = u.Name
i.Cover = u.Pic
i.Goto = GotoAuthor
i.OfficialVerify = u.OfficialVerify
i.Param = strconv.Itoa(int(u.Mid))
i.URI = FillURI(i.Goto, i.Param, nil)
i.Sign = u.Usign
i.Fans = u.Fans
i.Level = u.Level
i.Arcs = u.Videos
i.AvItems = make([]*Item, 0, len(u.Res))
for _, v := range u.Res {
vi := &Item{}
vi.Title = v.Title
vi.Cover = v.Pic
vi.Goto = GotoAv
vi.Param = strconv.Itoa(int(v.Aid))
a, ok := as[v.Aid]
if ok {
vi.Play = int(a.Stat.View)
vi.Danmaku = int(a.Stat.Danmaku)
} else {
switch play := v.Play.(type) {
case float64:
vi.Play = int(play)
case string:
vi.Play, _ = strconv.Atoi(play)
}
vi.Danmaku = v.Danmaku
}
vi.CTime = v.Pubdate
vi.Duration = v.Duration
i.AvItems = append(i.AvItems, vi)
}
}
// FromUser form func .
func (i *Item) FromUser(u *User, as map[int64]*v1.Arc) {
i.Title = u.Name
i.Cover = u.Pic
i.Goto = GotoAuthor
i.OfficialVerify = u.OfficialVerify
i.Param = strconv.Itoa(int(u.Mid))
i.URI = FillURI(i.Goto, i.Param, nil)
i.Sign = u.Usign
i.Fans = u.Fans
i.Level = u.Level
i.Arcs = u.Videos
i.AvItems = make([]*Item, 0, len(u.Res))
if u.IsUpuser == 1 {
for _, v := range u.Res {
vi := &Item{}
vi.Title = v.Title
vi.Cover = v.Pic
vi.Goto = GotoAv
vi.Param = strconv.Itoa(int(v.Aid))
a, ok := as[v.Aid]
if ok {
vi.Play = int(a.Stat.View)
vi.Danmaku = int(a.Stat.Danmaku)
} else {
switch play := v.Play.(type) {
case float64:
vi.Play = int(play)
case string:
vi.Play, _ = strconv.Atoi(play)
}
vi.Danmaku = v.Danmaku
}
vi.CTime = v.Pubdate
vi.Duration = v.Duration
i.AvItems = append(i.AvItems, vi)
}
i.IsUp = true
}
}
// FromMovie form func .
func (i *Item) FromMovie(m *Movie, as map[int64]*v1.Arc) {
i.Title = m.Title
i.Desc = m.Desc
if m.Type == "movie" {
i.Cover = m.Cover
i.Param = strconv.Itoa(int(m.Aid))
i.Goto = GotoAv
i.URI = FillURI(i.Goto, i.Param, AvHandler(as[m.Aid]))
i.CoverMark = StatusMark(m.Status)
} else if m.Type == "special" {
i.Param = m.SpID
i.Goto = GotoSp
i.URI = FillURI(i.Goto, i.Param, nil)
i.Cover = m.Pic
}
i.Staff = m.Staff
i.Actors = m.Actors
i.Area = m.Area
i.Length = m.Length
i.Status = m.Status
i.ScreenDate = m.ScreenDate
}
// FromVideo form func .
func (i *Item) FromVideo(v *Video, a *v1.Arc) {
i.Title = v.Title
i.Cover = v.Pic
i.Author = v.Author
i.Param = strconv.Itoa(int(v.ID))
i.Goto = GotoAv
if a != nil {
i.Face = a.Author.Face
i.URI = FillURI(i.Goto, i.Param, AvHandler(a))
i.Play = int(a.Stat.View)
i.Danmaku = int(a.Stat.Danmaku)
} else {
i.URI = FillURI(i.Goto, i.Param, nil)
switch play := v.Play.(type) {
case float64:
i.Play = int(play)
case string:
i.Play, _ = strconv.Atoi(play)
}
i.Danmaku = v.Danmaku
}
i.Desc = v.Desc
i.Duration = v.Duration
i.ViewType = v.ViewType
i.RecTags = v.RecTags
}
// FromMedia form func .
func (i *Item) FromMedia(m *Media, prompt string, gt string, bangumis map[string]*Card) {
i.Title = m.Title
if i.Title == "" {
i.Title = m.OrgTitle
}
i.Cover = m.Cover
i.Goto = gt
i.Param = strconv.Itoa(int(m.SeasonID))
i.URI = m.GotoURL
i.MediaType = m.MediaType
i.PlayState = m.PlayState
i.Style = m.Styles
i.CV = m.CV
i.Staff = m.Staff
if m.MediaScore != nil {
i.Rating = m.MediaScore.Score
i.Vote = m.MediaScore.UserCount
}
i.PTime = m.Pubtime
areas := strings.Split(m.Areas, "、")
if len(areas) != 0 {
i.Area = areas[0]
}
i.Prompt = prompt
var hit string
for _, v := range m.HitColumns {
if v == "cv" {
hit = v
break
} else if v == "staff" {
hit = v
}
}
if hit == "cv" {
for _, v := range getHightLight.FindAllStringSubmatch(m.CV, -1) {
if gt == GotoBangumi {
i.Label = fmt.Sprintf("声优: %v...", v[0])
break
} else if gt == GotoMovie {
i.Label = fmt.Sprintf("演员: %v...", v[0])
break
}
}
} else if hit == "staff" {
for _, v := range getHightLight.FindAllStringSubmatch(m.Staff, -1) {
i.Label = fmt.Sprintf("制作人员: %v...", v[0])
break
}
}
// get from PGC API .
ssID := strconv.Itoa(int(m.SeasonID))
if bgm, ok := bangumis[ssID]; ok {
for _, v := range bgm.Episodes {
tmp := &Item{
Param: strconv.Itoa(int(v.ID)),
Index: v.Index,
BadgeType: v.BadgeType,
}
tmp.URI = FillURI(GotoEP, tmp.Param, nil)
i.Episodes = append(i.Episodes, tmp)
}
}
}

View File

@@ -0,0 +1,36 @@
package(default_visibility = ["//visibility:public"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_library",
)
go_library(
name = "go_default_library",
srcs = [
"dangbei.go",
"mango.go",
"mango_recom.go",
],
importpath = "go-common/app/interface/main/tv/model/thirdp",
tags = ["automanaged"],
visibility = ["//visibility:public"],
deps = [
"//app/interface/main/tv/model:go_default_library",
"//library/time:go_default_library",
],
)
filegroup(
name = "package-srcs",
srcs = glob(["**"]),
tags = ["automanaged"],
visibility = ["//visibility:private"],
)
filegroup(
name = "all-srcs",
srcs = [":package-srcs"],
tags = ["automanaged"],
visibility = ["//visibility:public"],
)

View File

@@ -0,0 +1,154 @@
package thirdp
import (
"strconv"
"go-common/app/interface/main/tv/model"
)
// DBeiPage is the dangbei page struct
type DBeiPage struct {
List []*DBeiSeason `json:"list"`
Pager *model.IdxPager `json:"pager"`
}
// DBeiSeason is the dangbei season struct
type DBeiSeason struct {
SeasonID *int64 `json:"cid,omitempty"`
Cover string `json:"cover"`
Desc string `json:"desc"`
Title string `json:"title"`
UpInfo string `json:"upinfo"`
Category string `json:"category"` // - cn, jp, movie, tv, documentary
Area string `json:"area"` // - cn, jp, others
Playtime string `json:"play_time"`
Role string `json:"role"`
Staff string `json:"staff"`
NewestOrder int `json:"newest_order"` // the newest passed ep's order
NewestNB int `json:"newest_nb"`
TotalNum int `json:"total_num"`
Style string `json:"style"`
Paystatus string `json:"pay_status"` // paid or not
Official string `json:"official"` // is official or preview
}
// VideoCMS def.
type VideoCMS struct {
// Media Info
CID int
Title string
AID int
IndexOrder int
// Auth Info
Valid int
Deleted int
Result int
}
// PgcCat transforms the pgc category to string
func PgcCat(cat int) (category string) {
switch cat {
case 1:
category = "番剧"
case 2:
category = "电影"
case 3:
category = "纪录片"
case 4:
category = "国创"
case 5:
category = "电视剧"
default:
category = "其他"
}
return
}
// DBeiSn transform the object
func DBeiSn(s *model.SeasonCMS) (dbei *DBeiSeason) {
var (
category, area string
official = "正片"
)
category = PgcCat(int(s.Category))
if s.NewestNb == 0 { // in case of job calculation fail
if s.NewestOrder == 0 {
s.NewestNb = s.TotalNum
} else {
s.NewestNb = min(s.TotalNum, s.NewestOrder)
}
}
areaInt, _ := strconv.ParseInt(s.Area, 10, 64)
if areaInt != 0 {
switch areaInt {
case 1:
area = "中国"
case 2:
area = "日本"
default:
area = "其他"
}
} else {
area = s.Area
}
dbei = &DBeiSeason{
SeasonID: &s.SeasonID,
Cover: s.Cover,
Desc: s.Desc,
Title: s.Title,
UpInfo: s.UpInfo,
Category: category,
Area: area,
Playtime: s.Playtime.Time().Format("2006-01-02"),
Role: s.Role,
Staff: s.Staff,
NewestOrder: s.NewestOrder,
NewestNB: s.NewestNb,
TotalNum: s.TotalNum,
Style: s.Style,
Paystatus: "",
Official: official,
}
return
}
// DbeiArc transforms an arc cms to dangbei season structure
func DbeiArc(s *model.ArcCMS, first, second string) (dbei *DBeiSeason) {
official := "正片"
dbei = &DBeiSeason{
SeasonID: &s.AID,
Cover: s.Cover,
Desc: s.Content,
Title: s.Title,
Category: first,
Playtime: s.Pubtime.Time().Format("2006-01-02"),
TotalNum: s.Videos,
Style: second,
Paystatus: "",
Official: official,
}
return
}
// return min value
func min(x, y int) int {
if x < y {
return x
}
return y
}
// ReqDBeiPages is request for dangbei pages
type ReqDBeiPages struct {
Page int64
LastID int64
Ps int64
TypeC string
}
// ReqPageID is request for page ID
type ReqPageID struct {
Page int64
ID int64
TypeC string
}

View File

@@ -0,0 +1,118 @@
package thirdp
import (
"go-common/app/interface/main/tv/model"
"go-common/library/time"
)
// MangoSn is the plus version of Dangbei Season
type MangoSn struct {
SID int64 `json:"sid"`
DBeiSeason
OriginName string `json:"origin_name"`
Alias string `json:"alias"`
Autorised bool `json:"autorised"`
Mtime time.Time `json:"mtime"`
EpCover string `json:"ep_cover"`
}
// ToMangoSn transforms an seasonCMS to mangoSn
func ToMangoSn(s *model.SeasonCMS, mtime time.Time, autorised bool) *MangoSn {
mSn := &MangoSn{
DBeiSeason: *DBeiSn(s),
SID: s.SeasonID,
OriginName: s.OriginName,
Alias: s.Alias,
Mtime: mtime,
Autorised: autorised,
}
mSn.SeasonID = nil
return mSn
}
// MangoEP is mango ep structure
type MangoEP struct {
model.EpCMS
SeasonID int64 `json:"sid"`
Autorised bool `json:"autorised"`
Mtime time.Time `json:"mtime"`
}
// MangoSnPage is mango sn page structure
type MangoSnPage struct {
List []*MangoSn `json:"list"`
Pager *model.IdxPager `json:"pager"`
}
// MangoEpPage is mango ep page structure
type MangoEpPage struct {
SeasonID int64 `json:"sid"`
List []*MangoEP `json:"list"`
Pager *model.IdxPager `json:"pager"`
}
// MangoArc is mango archive structure
type MangoArc struct {
AVID int64 `json:"avid"`
Cover string `json:"cover"`
Desc string `json:"desc"`
Title string `json:"title"`
PlayTime string `json:"play_time"`
Category1 string `json:"category_1"`
Category2 string `json:"category_2"`
Autorised bool `json:"autorised"`
Mtime time.Time `json:"mtime"`
}
// MangoVideo is mango video structure
type MangoVideo struct {
CID int64 `json:"cid"`
Page int `json:"page"`
Desc string `json:"desc"`
Title string `json:"title"`
Duration int64 `json:"duration"`
Autorised bool `json:"autorised"`
Mtime time.Time `json:"mtime"`
}
// MangoArcPage is mango arc page structure
type MangoArcPage struct {
List []*MangoArc `json:"list"`
Pager *model.IdxPager `json:"pager"`
}
// MangoVideoPage is mango video page structure
type MangoVideoPage struct {
AVID int64 `json:"avid"`
List []*MangoVideo `json:"list"`
Pager *model.IdxPager `json:"pager"`
}
// RespSid is response structure for sid
type RespSid struct {
Sid int64
Mtime time.Time
}
// PickSids picks sids from resp slices
func PickSids(resps []*RespSid) (sids []int64) {
for _, v := range resps {
sids = append(sids, v.Sid)
}
return
}
// ToMangoArc transforms an ArcCMS to MangoArc
func ToMangoArc(a *model.ArcCMS, mtime time.Time, cat1, cat2 string) *MangoArc {
return &MangoArc{
AVID: a.AID,
Cover: a.Cover,
Desc: a.Content,
Title: a.Title,
PlayTime: a.Pubtime.Time().Format("2006-01-02"),
Autorised: a.CanPlay(),
Mtime: mtime,
Category1: cat1,
Category2: cat2,
}
}

View File

@@ -0,0 +1,67 @@
package thirdp
import (
"fmt"
"go-common/library/time"
)
// MangoRecom is mango recom table structure
type MangoRecom struct {
ID int64 `json:"id"`
RID int64 `json:"rid"`
Rtype int `json:"rtype"`
Title string `json:"title"`
Cover string `json:"cover"`
Category int `json:"category"`
Playcount int64 `json:"playcount"`
JID int64 `json:"jid"`
Content string `json:"content"`
Staff string `json:"staff"`
Rorder int `json:"rorder"`
Mtime time.Time `json:"-"`
}
// MangoParams is the output structure for mango recom api
type MangoParams struct {
JumpParam string `json:"jump_param"` // combine
Title string `json:"title"`
Cover string `json:"cover"`
Playcount int64 `json:"play_count"`
Category string `json:"category"` // transform to CN
Desc string `json:"desc"`
Staff string `json:"staff"`
Role string `json:"role"` // from DB
PlayTime string `json:"play_time"` // from DB
}
// MangoOrder struct
type MangoOrder struct {
RIDs []int64
}
const (
_fixStr = "&progress=0&from=mango&resource=rec"
_pgcJump = "yst://com.xiaodianshi.tv.yst?type=3&isBangumi=1&seasonId=%d&epId=%d" + _fixStr
_ugcJump = "yst://com.xiaodianshi.tv.yst?type=3&isBangumi=0&avId=%d&cId=%d" + _fixStr
_rtypePGC = 1
_rtypeUGC = 2
)
// ToParam transforms an MangoRecom from DB to MangoParam for mango OS
func (m *MangoRecom) ToParam() *MangoParams {
param := &MangoParams{
Title: m.Title,
Cover: m.Cover,
Playcount: m.Playcount,
Desc: m.Content,
Staff: m.Staff,
}
if m.Rtype == _rtypePGC {
param.JumpParam = fmt.Sprintf(_pgcJump, m.RID, m.JID)
}
if m.Rtype == _rtypeUGC {
param.JumpParam = fmt.Sprintf(_ugcJump, m.RID, m.JID)
}
return param
}

View File

@@ -0,0 +1,29 @@
package(default_visibility = ["//visibility:public"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_library",
)
go_library(
name = "go_default_library",
srcs = ["vip.go"],
importpath = "go-common/app/interface/main/tv/model/tvvip",
tags = ["automanaged"],
visibility = ["//visibility:public"],
deps = ["//app/service/main/tv/api:go_default_library"],
)
filegroup(
name = "package-srcs",
srcs = glob(["**"]),
tags = ["automanaged"],
visibility = ["//visibility:private"],
)
filegroup(
name = "all-srcs",
srcs = [":package-srcs"],
tags = ["automanaged"],
visibility = ["//visibility:public"],
)

View File

@@ -0,0 +1,96 @@
package model
import (
pb "go-common/app/service/main/tv/api"
)
type CreateQrReq struct {
Mid int64 `form:"mid" validate:"required"`
Pid int32 `form:"pid" validate:"required"`
BuyNum int32 `form:"buy_num" validate:"required"`
AppChannel string `form:"app_channel"`
Guid string
}
func (in *CreateQrReq) CopyIntoPbCreateOrReq(out *pb.CreateQrReq) {
out.Mid = in.Mid
out.Pid = in.Pid
out.BuyNum = in.BuyNum
out.Guid = in.Guid
out.AppChannel = in.AppChannel
}
type CreateGuestQrReq struct {
Pid int32 `form:"pid" validate:"required"`
BuyNum int32 `form:"buy_num" validate:"required"`
AppChannel string `form:"app_channel"`
Guid string
}
func (in *CreateGuestQrReq) CopyIntoPbCreateGuestQrReq(out *pb.CreateGuestQrReq) {
out.Pid = in.Pid
out.BuyNum = in.BuyNum
out.Guid = in.Guid
out.AppChannel = in.AppChannel
}
type CreateOrderReq struct {
Token string `form:"token" validate:"required"`
Platform int8
PaymentType string
}
func (in *CreateOrderReq) CopyIntoPbCreateOrderReq(out *pb.CreateOrderReq) {
out.Token = in.Token
out.Platform = in.Platform
out.PaymentType = in.PaymentType
}
type CreateGuestOrderReq struct {
Token string `form:"token" validate:"required"`
Platform int8
PaymentType string
}
func (in *CreateGuestOrderReq) CopyIntoPbCreateGuestOrderReq(out *pb.CreateGuestOrderReq) {
out.Token = in.Token
out.Platform = in.Platform
out.PaymentType = in.PaymentType
}
type WxContractCallbackReq struct {
ContractId string `json:"contract_id" url:"contract_id" validate:"required"`
ContractCode string `json:"contract_code" url:"contract_code" validate:"required"`
ChangeType string `json:"change_type" url:"contract_id" validate:"required"`
ContractTerminationMode string `json:"contract_termination_mode" url:"contract_termination_mode,omitempty"`
Sign string `json:"sign" url:"sign" validate:"required"`
}
func (in *WxContractCallbackReq) CopyIntoPbWxContractCallbackReq(out *pb.WxContractCallbackReq) {
out.ContractId = in.ContractId
out.ContractCode = in.ContractCode
out.ChangeType = in.ChangeType
out.ContractTerminationMode = in.ContractTerminationMode
out.Sign = in.Sign
}
type YstPayCallbackReq struct {
SeqNo string `json:"seqno" validate:"required"`
TraceNo string `json:"traceno" validate:"required"`
TradeState string `json:"trade_state" validate:"required"`
ContractId string `json:"contract_id"`
Sign string `json:"sign" validate:"required"`
}
func (in *YstPayCallbackReq) CopyIntoPbPayCallbackReq(out *pb.PayCallbackReq) {
out.SeqNo = in.SeqNo
out.TraceNo = in.TraceNo
out.TradeState = in.TradeState
out.ContractId = in.ContractId
out.Sign = in.Sign
}
type YstUserInfoReq struct {
Mid int64 `form:"mid" validate:"required"`
Sign string `form:"sign" validate:"required"`
}

View File

@@ -0,0 +1,37 @@
package model
// VerUpdate Params
type VerUpdate struct {
MobiApp string
Build int
Channel string
Seed int
Sdkint int
Model string
OldID string
}
// HTTPData response
type HTTPData struct {
Ver string `json:"ver"`
Build int `json:"build"`
Info string `json:"info"`
Size string `json:"size"`
URL string `json:"url"`
Hash string `json:"hash"`
Policy int `json:"policy"`
IsForce int `json:"is_force"`
IsPush int `json:"is_push"`
IsGray int `json:"is_gray"`
Mtime int `json:"mtime"`
Patch *Patch `json:"patch"`
}
// Patch fix
type Patch struct {
NewID string `json:"new_id"`
OldID string `json:"old_id"`
URL string `json:"url"`
Md5 string `json:"md5"`
Size int `json:"size"`
}

View File

@@ -0,0 +1,28 @@
package(default_visibility = ["//visibility:public"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_library",
)
go_library(
name = "go_default_library",
srcs = ["upper.go"],
importpath = "go-common/app/interface/main/tv/model/upper",
tags = ["automanaged"],
visibility = ["//visibility:public"],
)
filegroup(
name = "package-srcs",
srcs = glob(["**"]),
tags = ["automanaged"],
visibility = ["//visibility:private"],
)
filegroup(
name = "all-srcs",
srcs = [":package-srcs"],
tags = ["automanaged"],
visibility = ["//visibility:public"],
)

View File

@@ -0,0 +1,20 @@
package upper
// Upper reprensents the uppers
type Upper struct {
ID int
MID int64
Toinit int
Submit int // 1=need report
OriName string // original name
CMSName string // cms intervened name
OriFace string // original face
CMSFace string // cms intervened face
Valid int // auth info: 1=online,0=hidden
Deleted int
}
// CanShow tells whether the upper can be displayed or not
func (u *Upper) CanShow() bool {
return u.Valid == 1 && u.Deleted == 0
}

View File

@@ -0,0 +1,32 @@
package(default_visibility = ["//visibility:public"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_library",
)
go_library(
name = "go_default_library",
srcs = [
"const.go",
"view.go",
],
importpath = "go-common/app/interface/main/tv/model/view",
tags = ["automanaged"],
visibility = ["//visibility:public"],
deps = ["//app/service/main/archive/api:go_default_library"],
)
filegroup(
name = "package-srcs",
srcs = glob(["**"]),
tags = ["automanaged"],
visibility = ["//visibility:private"],
)
filegroup(
name = "all-srcs",
srcs = [":package-srcs"],
tags = ["automanaged"],
visibility = ["//visibility:public"],
)

View File

@@ -0,0 +1,74 @@
package view
import (
"fmt"
arcwar "go-common/app/service/main/archive/api"
)
// Goto
const (
GotoAv = "av"
GotoWeb = "web"
GotoBangumi = "bangumi"
GotoLive = "live"
GotoGame = "game"
GotoArticle = "article"
GotoSpecial = "special"
GotoAudio = "audio"
GotoSong = "song"
GotoAudioTag = "audio_tag"
GotoAlbum = "album"
GotoClip = "clip"
GotoDaily = "daily"
)
// FillURI deal app schema.
func FillURI(gt, param string, f func(uri string) string) (uri string) {
if param == "" {
return
}
switch gt {
case GotoAv, "":
uri = "bilibili://video/" + param
case GotoLive:
uri = "bilibili://live/" + param
case GotoBangumi:
uri = "https://www.bilibili.com/bangumi/play/ss" + param
case GotoArticle:
uri = "bilibili://article/" + param
case GotoGame:
uri = param
case GotoAudio:
uri = "bilibili://music/menu/detail/" + param
case GotoSong:
uri = "bilibili://music/detail/" + param
case GotoAudioTag:
uri = "bilibili://music/categorydetail/" + param
case GotoDaily:
uri = "bilibili://pegasus/list/daily/" + param
case GotoAlbum:
uri = "bilibili://album/" + param
case GotoClip:
uri = "bilibili://clip/" + param
case GotoWeb:
uri = param
}
if f != nil {
uri = f(uri)
}
return
}
// AvHandler logic
var AvHandler = func(a *arcwar.Arc) func(uri string) string {
return func(uri string) string {
if a == nil {
return uri
}
if a.Dimension.Height != 0 || a.Dimension.Width != 0 {
return fmt.Sprintf("%s?player_width=%d&player_height=%d&player_rotate=%d", uri, a.Dimension.Width, a.Dimension.Height, a.Dimension.Rotate)
}
return uri
}
}

View File

@@ -0,0 +1,113 @@
package view
import (
"encoding/json"
"strconv"
arcwar "go-common/app/service/main/archive/api"
)
// View view+relates
type View struct {
*Static // relate data
ReqUser *ReqUser `json:"req_user,omitempty"` // now user
History *History `json:"history,omitempty"`
Relates []*Relate `json:"relates,omitempty"`
PID int32 `json:"category"` // father level partition ID
}
// ReqUser struct
type ReqUser struct {
Attention int `json:"attention"`
Favorite int8 `json:"favorite"`
Like int8 `json:"like"`
Dislike int8 `json:"dislike"`
Coin int8 `json:"coin"`
}
// Static .
type Static struct {
*arcwar.Arc
Pages []*Page `json:"pages,omitempty"`
}
// Page .
type Page struct {
*arcwar.Page
Metas []*Meta `json:"metas"`
}
// Meta .
type Meta struct {
Quality int `json:"quality"`
Format string `json:"format"`
Size int64 `json:"size"`
}
// Relate .
type Relate struct {
Aid int64 `json:"aid,omitempty"`
Pic string `json:"pic,omitempty"`
Title string `json:"title,omitempty"`
Author arcwar.Author `json:"owner,omitempty"`
Stat arcwar.Stat `json:"stat,omitempty"`
Duration int64 `json:"duration,omitempty"`
Goto string `json:"goto,omitempty"`
Param string `json:"param,omitempty"`
URI string `json:"uri,omitempty"`
Rating float64 `json:"rating,omitempty"`
Reserve string `json:"reserve,omitempty"`
From string `json:"from,omitempty"`
Desc string `json:"desc,omitempty"`
RcmdReason string `json:"rcmd_reason,omitempty"`
Badge string `json:"badge,omitempty"`
Cid int64 `json:"cid,omitempty"`
// cm ad
AdIndex int `json:"ad_index,omitempty"`
CmMark int `json:"cm_mark,omitempty"`
SrcID int64 `json:"src_id,omitempty"`
RequestID string `json:"request_id,omitempty"`
CreativeID int64 `json:"creative_id,omitempty"`
CreativeType int64 `json:"creative_type,omitempty"`
Type int `json:"type,omitempty"`
Cover string `json:"cover,omitempty"`
ButtonTitle string `json:"button_title,omitempty"`
View int `json:"view,omitempty"`
Danmaku int `json:"danmaku,omitempty"`
IsAd bool `json:"is_ad,omitempty"`
IsAdLoc bool `json:"is_ad_loc,omitempty"`
AdCb string `json:"ad_cb,omitempty"`
ShowURL string `json:"show_url,omitempty"`
ClickURL string `json:"click_url,omitempty"`
ClientIP string `json:"client_ip,omitempty"`
Extra json.RawMessage `json:"extra,omitempty"`
Button *Button `json:"button,omitempty"`
CardIndex int `json:"card_index,omitempty"`
}
// Button .
type Button struct {
Title string `json:"title,omitempty"`
URI string `json:"uri,omitempty"`
}
// FromAv treatment
func (r *Relate) FromAv(a *arcwar.Arc, from string) {
r.Aid = a.Aid
r.Title = a.Title
r.Pic = a.Pic
r.Author = a.Author
r.Stat = a.Stat
r.Duration = a.Duration
r.Cid = a.FirstCid
r.Goto = GotoAv
r.Param = strconv.FormatInt(a.Aid, 10)
r.URI = FillURI(r.Goto, r.Param, AvHandler(a))
r.From = from
}
// History struct
type History struct {
Cid int64 `json:"cid"`
Progress int64 `json:"progress"`
}

View File

@@ -0,0 +1,23 @@
package model
// IdxSeason is the struct of season in zone index page
type IdxSeason struct {
SeasonID int64 `json:"season_id"`
Title string `json:"title"`
Cover string `json:"cover"`
Upinfo string `json:"upinfo"`
}
// IdxData is the zone index data struct in http response
type IdxData struct {
List []*IdxSeason `json:"list"`
Pager *IdxPager `json:"pager"`
}
// IdxPager is the pager struct to return in zone index page
type IdxPager struct {
CurrentPage int `json:"current_page"`
TotalItems int `json:"total_items"`
TotalPages int `json:"total_pages"`
PageSize int `json:"page_size"`
}