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,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
}