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,79 @@
load(
"@io_bazel_rules_go//proto:def.bzl",
"go_proto_library",
)
package(default_visibility = ["//visibility:public"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_test",
"go_library",
)
proto_library(
name = "api_proto",
srcs = ["api.proto"],
tags = ["automanaged"],
deps = ["@gogo_special_proto//github.com/gogo/protobuf/gogoproto"],
)
go_proto_library(
name = "api_go_proto",
compilers = ["@io_bazel_rules_go//proto:gogofast_grpc"],
importpath = "go-common/app/service/main/archive/api",
proto = ":api_proto",
tags = ["automanaged"],
deps = [
"//library/time:go_default_library",
"@com_github_gogo_protobuf//gogoproto:go_default_library",
],
)
go_test(
name = "go_default_test",
srcs = ["client_test.go"],
embed = [":go_default_library"],
tags = ["automanaged"],
deps = [
"//library/ecode:go_default_library",
"//vendor/github.com/smartystreets/goconvey/convey:go_default_library",
],
)
go_library(
name = "go_default_library",
srcs = [
"client.go",
"model.go",
],
embed = [":api_go_proto"],
importpath = "go-common/app/service/main/archive/api",
tags = ["automanaged"],
visibility = ["//visibility:public"],
deps = [
"//library/net/rpc/warden:go_default_library",
"//library/time:go_default_library",
"@com_github_gogo_protobuf//gogoproto:go_default_library",
"@com_github_gogo_protobuf//proto:go_default_library",
"@org_golang_google_grpc//:go_default_library",
"@org_golang_x_net//context:go_default_library",
],
)
filegroup(
name = "package-srcs",
srcs = glob(["**"]),
tags = ["automanaged"],
visibility = ["//visibility:private"],
)
filegroup(
name = "all-srcs",
srcs = [
":package-srcs",
"//app/service/main/archive/api/gorpc:all-srcs",
],
tags = ["automanaged"],
visibility = ["//visibility:public"],
)

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,405 @@
syntax = "proto3";
import "github.com/gogo/protobuf/gogoproto/gogo.proto";
// use {app_id}.{version} as package name
package archive.service.v1;
option go_package = "api";
// Archive grpc
service Archive {
// Types 获取所有分区列表
rpc Types(NoArgRequest) returns(TypesReply);
// 获取单个稿件信息
rpc Arc(ArcRequest) returns(ArcReply);
// 批量获取稿件信息
rpc Arcs(ArcsRequest) returns(ArcsReply);
// 获取单个稿件计数信息
rpc Stat(StatRequest) returns(StatReply);
// 批量获取稿件计数信息
rpc Stats(StatsRequest) returns(StatsReply);
// 获取单个稿件+分P信息
rpc View(ViewRequest) returns(ViewReply);
// 批量获取稿件+分P信息
rpc Views(ViewsRequest) returns(ViewsReply);
// 获取稿件在各平台的点击数
rpc Click(ClickRequest) returns(ClickReply);
// 获取稿件的所有分P信息
rpc Page(PageRequest) returns(PageReply);
// 获取Up主绑定的相关推荐 *几乎废弃
rpc Recommend(RecommendRequest) returns(RecommendReply);
// 获取aid&cid对应的视频信息
rpc Video(VideoRequest) returns(VideoReply);
// 获取当前最大的aid各子业务防刷、防脏数据时使用
rpc MaxAid(NoArgRequest) returns(MaxAidReply);
// 获取稿件的长简介信息
rpc Description(DescriptionRequest) returns(DescriptionReply);
// 内部方法,管理稿件服务缓存,请勿使用-----------------------------------------------------------------------
rpc ArcFieldCache(ArcFieldCacheRequest) returns(NoReply);
rpc ArcCache(ArcCacheRequest) returns(NoReply);
rpc UpVideoCache(UpVideoCacheRequest) returns(NoReply);
rpc DelVideoCache(DelVideoCacheRequest) returns(NoReply);
rpc SetStat(SetStatRequest) returns(NoReply);
// 内部方法,管理稿件服务缓存,请勿使用-----------------------------------------------------------------------
}
// NoArgReq
message NoArgRequest{}
// NoReply
message NoReply{}
message DescriptionRequest {
int64 aid = 1;
}
message DescriptionReply {
string desc = 1;
}
message MaxAidReply {
int64 aid = 1;
}
message ArcRequest {
int64 aid = 1;
}
message ArcReply {
Arc arc = 1;
}
message ArcsRequest {
repeated int64 aids = 1;
}
message ArcsReply {
map<int64, Arc> arcs = 1;
}
message ViewRequest {
int64 aid = 1;
}
message StatRequest {
int64 aid = 1;
}
message StatReply {
Stat Stat = 1;
}
message StatsRequest {
repeated int64 aids = 1;
}
message StatsReply {
map<int64, Stat> Stats = 1;
}
message ViewReply {
Arc arc = 1 [(gogoproto.embed) = true, (gogoproto.jsontag) = ""];
repeated Page pages = 2;
}
message ViewsRequest {
repeated int64 aids = 1;
}
message ViewsReply {
map<int64, ViewReply> views = 1;
}
message TypesReply {
map<int32, Tp> types = 1;
}
message ClickRequest {
int64 aid = 1;
}
message ClickReply {
Click click = 1;
}
message PageRequest {
int64 aid = 1;
}
message PageReply {
repeated Page pages = 1;
}
message RecommendRequest {
int64 aid = 1;
}
message RecommendReply {
repeated Arc arcs = 1;
}
message VideoRequest {
int64 aid = 1;
int64 cid = 2;
}
message VideoReply {
Page page = 1;
}
message Tp {
// 分区id
int32 ID = 1 [(gogoproto.jsontag) = "id"];
// 该分区的父级id
int32 pid = 2 [(gogoproto.jsontag) = "pid"];
// 该分区对应的名称
string name = 3 [(gogoproto.jsontag) = "name"];
}
message AidVideos {
int64 Aid = 1 [(gogoproto.jsontag) = "aid"];
// 分P信息
repeated Page Pages = 2 [(gogoproto.jsontag) = "pages"];
}
message Arc {
int64 Aid = 1 [(gogoproto.jsontag) = "aid"];
// 稿件一共有多少分P
int64 Videos = 2 [(gogoproto.jsontag) = "videos"];
// 分区ID
int32 TypeID = 3 [(gogoproto.jsontag) = "tid"];
// 分区名
string TypeName = 4 [(gogoproto.jsontag) = "tname"];
// 是否转载 1=原创 2=转载 0=历史上可能遗留的脏数据
int32 Copyright = 5 [(gogoproto.jsontag) = "copyright"];
// 稿件封面图地址,绝对地址 如 http://i0.hdslb.com/bfs/xxx.jpg
string Pic = 6 [(gogoproto.jsontag) = "pic"];
// 稿件标题
string Title = 7 [(gogoproto.jsontag) = "title"];
// 稿件发布时间 对外展示的标准时间 时间戳格式
int64 PubDate = 8 [(gogoproto.jsontag) = "pubdate", (gogoproto.casttype) = "go-common/library/time.Time"];
// 用户提交稿件的时间 一般不对外展示 时间戳格式
int64 Ctime = 9 [(gogoproto.jsontag) = "ctime", (gogoproto.casttype) = "go-common/library/time.Time"];
// 稿件简介
string Desc = 10 [(gogoproto.jsontag) = "desc"];
// 稿件状态,>=0为前台用户可见状态其他值详见 http://info.bilibili.co/pages/viewpage.action?pageId=3686597#id-%E7%A8%BF%E4%BB%B6%E5%AD%97%E6%AE%B5%E6%9E%9A%E4%B8%BE%E5%80%BC%E5%B1%9E%E6%80%A7%E8%AF%B4%E6%98%8E-%E7%A8%BF%E4%BB%B6%E7%8A%B6%E6%80%81state&access
int32 State = 11 [(gogoproto.jsontag) = "state"];
// 稿件访问属性 0=全员可见 10000=登录用户可见(极少)
int32 Access = 12 [(gogoproto.jsontag) = "access,omitempty"];
// 稿件属性 详见State字段的文档
int32 Attribute = 13 [(gogoproto.jsontag) = "attribute,omitempty"];
// 废弃字段
string Tag = 14 [(gogoproto.jsontag) = "-"];
// 废弃字段
repeated string Tags = 15 [(gogoproto.jsontag) = "tags,omitempty"];
// 稿件总时长所有分P加起来的 单位=秒
int64 Duration = 16 [(gogoproto.jsontag) = "duration"];
// 稿件绑定的活动id
int64 MissionID = 17 [(gogoproto.jsontag) = "mission_id,omitempty"];
// 稿件绑定的商单id
int64 OrderID = 18 [(gogoproto.jsontag) = "order_id,omitempty"];
// 稿件后台设置的强制跳转地址,如果该值不为空,则必须调转到它对应的页面上
string RedirectURL = 19 [(gogoproto.jsontag) = "redirect_url,omitempty"];
int64 Forward = 20 [(gogoproto.jsontag) = "forward,omitempty"];
// 见Rights字段说明
Rights Rights = 21 [(gogoproto.jsontag) = "rights", (gogoproto.nullable) = false];
// 稿件作者信息详见Author字段说明
Author Author = 22 [(gogoproto.jsontag) = "owner", (gogoproto.nullable) = false];
// 稿件计数信息详见Stat字段说明
Stat Stat = 23 [(gogoproto.jsontag) = "stat", (gogoproto.nullable) = false];
string ReportResult = 24 [(gogoproto.jsontag) = "report_result,omitempty"];
// 发布稿件时Up主设置的动态描述仅在动态展示
string Dynamic = 25 [(gogoproto.jsontag) = "dynamic"];
// 稿件第一P的cid供秒开使用
int64 FirstCid = 26 [(gogoproto.jsontag) = "cid,omitempty"];
// 稿件第一P的分辨率详见Dimession字段说明
Dimension Dimension = 27 [(gogoproto.jsontag) = "dimension,omitempty", (gogoproto.nullable) = false];
// 联合投稿信息内部使用详见StaffInfo说明
repeated StaffInfo StaffInfo = 28 [(gogoproto.jsontag) = "-"];
}
message StaffInfo {
// 联合投稿的成员Up主id
int64 Mid = 1 [(gogoproto.jsontag) = "mid"];
// 联合投稿的成员角色(如 声优、字幕)
string Title = 2 [(gogoproto.jsontag) = "title"];
}
// Dimension 视频分辨率
message Dimension {
// 宽 如 1920
int64 Width = 1 [(gogoproto.jsontag) = "width"];
// 高 如 1080
int64 Height = 2 [(gogoproto.jsontag) = "height"];
// 是否竖屏 0=否 1=是
int64 Rotate = 3 [(gogoproto.jsontag) = "rotate"];
}
// Rights 稿件各常用属性 0=否 1=是
message Rights {
// 老版是否付费
int32 Bp = 1 [(gogoproto.jsontag) = "bp"];
// 是否支持充电 (不可直接使用,网关层请求业务方后才有值)
int32 Elec = 2 [(gogoproto.jsontag) = "elec"];
// 是否下载(不可直接使用,网关层请求业务方后才有值)
int32 Download = 3 [(gogoproto.jsontag) = "download"];
// 是否电影
int32 Movie = 4 [(gogoproto.jsontag) = "movie"];
// 是否PGC付费
int32 Pay = 5 [(gogoproto.jsontag) = "pay"];
// 无用
int32 HD5 = 6 [(gogoproto.jsontag) = "hd5"];
// 是否允许转发
int32 NoReprint = 7 [(gogoproto.jsontag) = "no_reprint"];
// 是否可以自动播放
int32 Autoplay = 8 [(gogoproto.jsontag) = "autoplay"];
// 是否UGC付费
int32 UGCPay = 9 [(gogoproto.jsontag) = "ugc_pay"];
// 是否联合投稿
int32 IsCooperation = 10 [(gogoproto.jsontag) = "is_cooperation"];
}
// Author 稿件作者信息
message Author {
// Up主mid
int64 Mid = 1 [(gogoproto.jsontag) = "mid"];
// Up主名称
string Name = 2 [(gogoproto.jsontag) = "name"];
// Up主头像地址 绝对地址
string Face = 3 [(gogoproto.jsontag) = "face"];
}
// Stat 稿件的所有计数信息
message Stat {
int64 Aid = 1 [(gogoproto.jsontag) = "aid"];
// 播放数
int32 View = 2 [(gogoproto.jsontag) = "view"];
// 弹幕数
int32 Danmaku = 3 [(gogoproto.jsontag) = "danmaku"];
// 评论数
int32 Reply = 4 [(gogoproto.jsontag) = "reply"];
// 收藏数
int32 Fav = 5 [(gogoproto.jsontag) = "favorite"];
// 投币数
int32 Coin = 6 [(gogoproto.jsontag) = "coin"];
// 分享数
int32 Share = 7 [(gogoproto.jsontag) = "share"];
// 当前排名
int32 NowRank = 8 [(gogoproto.jsontag) = "now_rank"];
// 历史最高排名
int32 HisRank = 9 [(gogoproto.jsontag) = "his_rank"];
// 点赞数
int32 Like = 10 [(gogoproto.jsontag) = "like"];
// 点踩数 已取消前台展示现在均返回0
int32 DisLike = 11 [(gogoproto.jsontag) = "dislike"];
}
// Click 点击数详情,老版本播放器使用
message Click {
int64 Aid = 1 [(gogoproto.jsontag) = "aid"];
// web端播放数
int32 Web = 2 [(gogoproto.jsontag) = "web"];
// iOS端播放数
int32 Ios = 3 [(gogoproto.jsontag) = "ios"];
// android端播放数
int32 Android = 4 [(gogoproto.jsontag) = "android"];
// h5端播放数
int32 H5 = 5 [(gogoproto.jsontag) = "h5"];
// 站外播放数
int32 Outter = 6 [(gogoproto.jsontag) = "outter"];
}
// Page 分P信息
message Page {
// 视频的cid
int64 Cid = 1 [(gogoproto.jsontag) = "cid"];
// 视频的序号顺序,从小到大
int32 Page = 2 [(gogoproto.jsontag) = "page"];
// 视频的来源99%为vupload=B站自己的少部分为腾讯qq、湖南tv(hunan)
string From = 3 [(gogoproto.jsontag) = "from"];
// 视频的标题
string Part = 4 [(gogoproto.jsontag) = "part"];
// 视频的时长 单位=秒
int64 Duration = 5 [(gogoproto.jsontag) = "duration"];
// 站外视频才有vid属性
string Vid = 6 [(gogoproto.jsontag) = "vid"];
// 视频的简介多P视频才可填写简介
string Desc = 7 [(gogoproto.jsontag) = "description,omitempty"];
// 站外视频跳转地址
string WebLink = 8 [(gogoproto.jsontag) = "weblink"];
// 视频分辨率信息
Dimension Dimension = 9 [(gogoproto.jsontag) = "dimension", (gogoproto.nullable) = false];
}
// !!!Note: only response message defined, since we put pb into http response body
message VideoFileInfo {
uint64 filesize = 1 [(gogoproto.jsontag) = "filesize", (gogoproto.casttype) = "int64"];
uint64 timelength = 2 [(gogoproto.jsontag) = "timelength", (gogoproto.casttype) ="int64"];
string ahead = 3 [(gogoproto.jsontag) = "ahead"];
string vhead = 4 [(gogoproto.jsontag) = "vhead"];
}
message VideoFormatFileInfo {
repeated VideoFileInfo infos = 1 [(gogoproto.jsontag) = "infos"];
}
message DashItem {
uint32 id = 1 [(gogoproto.jsontag) = "id", (gogoproto.casttype) = "int64"];
string baseUrl = 2 [(gogoproto.jsontag) = "base_url"];
uint32 bandwidth = 3 [(gogoproto.jsontag) = "bandwidth", (gogoproto.casttype) = "int64"];
uint32 codecid = 4 [(gogoproto.jsontag) = "codecid", (gogoproto.casttype) = "int64"];
}
message ResponseDash {
repeated DashItem video = 1 [(gogoproto.jsontag) = "video"];
repeated DashItem audio = 2 [(gogoproto.jsontag) = "audio"];
}
message BvcVideoItem {
uint64 expire_time = 1 [(gogoproto.jsontag) = "expire_time", (gogoproto.casttype) = "int64"];
uint32 cid = 2 [(gogoproto.jsontag) = "cid", (gogoproto.casttype) ="int64"];
repeated uint32 support_quality = 3 [(gogoproto.jsontag) = "support_quality", (gogoproto.casttype) = "int"];
repeated string support_formats = 4 [(gogoproto.jsontag) = "support_formats"];
repeated string support_description = 5 [(gogoproto.jsontag) = "support_description"];
uint32 quality = 6 [(gogoproto.jsontag) = "quality", (gogoproto.casttype) = "int"];
string url = 7 [(gogoproto.jsontag) = "url"];
map<uint32, VideoFormatFileInfo> file_info = 8 [(gogoproto.jsontag) = "file_info"];
uint32 video_codecid = 9 [(gogoproto.jsontag) = "video_codecid"];
bool video_project = 10 [(gogoproto.jsontag) = "video_project"];
uint32 fnver = 11 [(gogoproto.jsontag) = "fnver", (gogoproto.casttype) = "int"];
uint32 fnval = 12 [(gogoproto.jsontag) = "fnval", (gogoproto.casttype) = "int"];
ResponseDash dash = 13 [(gogoproto.jsontag) = "dash"];
}
message BvcResponseMsg {
uint32 code = 1 [(gogoproto.jsontag) = "code", (gogoproto.casttype) = "int64"];
map<uint32, BvcVideoItem> data = 2 [(gogoproto.jsontag) = "data"];
}
// 内部方法 请勿使用--------------------------------------------------------------------------------------------
message ArcCacheRequest {
int64 aid = 1;
string tp = 2;
int64 OldMid = 3;
}
message ArcFieldCacheRequest {
int64 aid = 1;
int32 typeID = 2;
int32 oldTypeID = 3;
}
message UpVideoCacheRequest {
int64 aid = 1;
int64 cid = 2;
}
message DelVideoCacheRequest {
int64 aid = 1;
int64 cid = 2;
}
message SetStatRequest {
Stat stat = 1;
}
// 使--------------------------------------------------------------------------------------------

View File

@@ -0,0 +1,25 @@
package api
import (
"context"
"fmt"
"go-common/library/net/rpc/warden"
"google.golang.org/grpc"
)
// AppID .
const AppID = "archive.service"
// NewClient new grpc client
func NewClient(cfg *warden.ClientConfig, opts ...grpc.DialOption) (ArchiveClient, error) {
client := warden.NewClient(cfg, opts...)
cc, err := client.Dial(context.Background(), fmt.Sprintf("discovery://default/%s", AppID))
if err != nil {
return nil, err
}
return NewArchiveClient(cc), nil
}
//go:generate $GOPATH/src/go-common/app/tool/warden/protoc.sh

View File

@@ -0,0 +1,99 @@
package api
import (
"context"
"testing"
"go-common/library/ecode"
"github.com/smartystreets/goconvey/convey"
)
var client ArchiveClient
func init() {
var err error
client, err = NewClient(nil)
if err != nil {
panic(err)
}
}
func TestTypes(t *testing.T) {
convey.Convey("Types", t, func(ctx convey.C) {
var c = context.Background()
ctx.Convey("When everything is correct", func(ctx convey.C) {
reply, err := client.Types(c, &NoArgRequest{})
ctx.So(err, convey.ShouldBeNil)
for k, v := range reply.Types {
ctx.Printf("key:%d id:%d name:%s pid:%d\n", k, v.ID, v.Name, v.Pid)
}
})
})
}
func TestArc(t *testing.T) {
convey.Convey("TestArc", t, func(ctx convey.C) {
var c = context.Background()
ctx.Convey("When everything is correct", func(ctx convey.C) {
reply, err := client.Arc(c, &ArcRequest{Aid: 10100696})
ctx.So(err, convey.ShouldBeNil)
ctx.Printf("%+v\n", reply.Arc)
})
ctx.Convey("When error", func(ctx convey.C) {
reply, err := client.Arc(context.TODO(), &ArcRequest{Aid: 99999999999})
ctx.So(err, convey.ShouldEqual, ecode.NothingFound)
ctx.So(reply, convey.ShouldBeNil)
})
})
}
func TestArcs(t *testing.T) {
convey.Convey("TestArcs", t, func(ctx convey.C) {
var c = context.Background()
ctx.Convey("When everything is correct", func(ctx convey.C) {
reply, err := client.Arcs(c, &ArcsRequest{Aids: []int64{10100696}})
ctx.So(err, convey.ShouldBeNil)
ctx.Printf("%+v\n", reply.Arcs)
})
ctx.Convey("When empty", func(ctx convey.C) {
reply, err := client.Arcs(c, &ArcsRequest{Aids: []int64{99999999999}})
// 批量接口 err=nil arcs=nil
ctx.So(err, convey.ShouldBeNil)
ctx.So(reply.Arcs, convey.ShouldBeNil)
})
})
}
func TestView(t *testing.T) {
convey.Convey("TestView", t, func(ctx convey.C) {
var c = context.Background()
ctx.Convey("When everything is correct", func(ctx convey.C) {
reply, err := client.View(c, &ViewRequest{Aid: 10100696})
ctx.So(err, convey.ShouldBeNil)
ctx.Printf("arc:%+v\n", reply.Arc)
ctx.Printf("pages:%+v\n", reply.Pages)
})
ctx.Convey("When empty", func(ctx convey.C) {
reply, err := client.View(c, &ViewRequest{Aid: 99999999999})
ctx.So(err, convey.ShouldNotBeNil)
ctx.So(reply, convey.ShouldBeNil)
})
})
}
func TestViews(t *testing.T) {
convey.Convey("TestViews", t, func(ctx convey.C) {
var c = context.Background()
ctx.Convey("When everything is correct", func(ctx convey.C) {
reply, err := client.Views(c, &ViewsRequest{Aids: []int64{10100696}})
ctx.So(err, convey.ShouldBeNil)
ctx.Printf("%+v\n", reply.Views)
})
ctx.Convey("When empty", func(ctx convey.C) {
arcs, err := client.Views(c, &ViewsRequest{Aids: []int64{99999999999}})
ctx.So(err, convey.ShouldBeNil)
ctx.So(arcs.Views, convey.ShouldBeNil)
})
})
}

View File

@@ -0,0 +1,50 @@
package(default_visibility = ["//visibility:public"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_test",
"go_library",
)
go_test(
name = "go_default_test",
srcs = ["archive2_test.go"],
embed = [":go_default_library"],
rundir = ".",
tags = ["automanaged"],
deps = [
"//app/service/main/archive/api:go_default_library",
"//app/service/main/archive/model/archive:go_default_library",
],
)
go_library(
name = "go_default_library",
srcs = [
"archive1.go",
"archive2.go",
"archive3.go",
],
importpath = "go-common/app/service/main/archive/api/gorpc",
tags = ["automanaged"],
visibility = ["//visibility:public"],
deps = [
"//app/service/main/archive/api:go_default_library",
"//app/service/main/archive/model/archive:go_default_library",
"//library/net/rpc: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,25 @@
package gorpc
import (
"go-common/library/net/rpc"
)
const (
_appid = "archive.service"
)
var (
_noArg = &struct{}{}
)
// Service2 is archive rpc client.
type Service2 struct {
client *rpc.Client2
}
// New2 new a archive rpc client.
func New2(c *rpc.ClientConfig) (s *Service2) {
s = &Service2{}
s.client = rpc.NewDiscoveryCli(_appid, c)
return
}

View File

@@ -0,0 +1,96 @@
package gorpc
import (
"context"
"go-common/app/service/main/archive/api"
model "go-common/app/service/main/archive/model/archive"
)
const (
_types2 = "RPC.Types2"
_videoshot2 = "RPC.Videoshot2"
_upCount2 = "RPC.UpCount2"
_upsPassed2 = "RPC.UpsPassed2"
_upVideo2 = "RPC.UpVideo2"
_delVideo2 = "RPC.DelVideo2"
_description2 = "RPC.Description2"
_ranksTopCount2 = "RPC.RanksTopCount2"
_arcCache2 = "RPC.ArcCache2"
_arcFieldCache2 = "RPC.ArcFieldCache2"
_setStat2 = "RPC.SetStat2"
_setStatCache2 = "RPC.SetStatCache2"
)
// Types2 get all archive types
func (s *Service2) Types2(c context.Context) (res map[int16]*model.ArcType, err error) {
err = s.client.Call(c, _types2, _noArg, &res)
return
}
// Videoshot2 get videoshot.
func (s *Service2) Videoshot2(c context.Context, arg *model.ArgCid2) (res *model.Videoshot, err error) {
res = new(model.Videoshot)
err = s.client.Call(c, _videoshot2, arg, res)
return
}
// UpCount2 up count2
func (s *Service2) UpCount2(c context.Context, arg *model.ArgUpCount2) (count int, err error) {
err = s.client.Call(c, _upCount2, arg, &count)
return
}
// UpsPassed2 get UpsPassed aid and ptime
func (s *Service2) UpsPassed2(c context.Context, arg *model.ArgUpsArcs2) (res map[int64][]*model.AidPubTime, err error) {
err = s.client.Call(c, _upsPassed2, arg, &res)
return
}
// UpVideo2 update video cache by aid & cid
func (s *Service2) UpVideo2(c context.Context, arg *model.ArgVideo2) (err error) {
err = s.client.Call(c, _upVideo2, arg, _noArg)
return
}
// DelVideo2 delete video cache by aid & cid
func (s *Service2) DelVideo2(c context.Context, arg *model.ArgVideo2) (err error) {
err = s.client.Call(c, _delVideo2, arg, _noArg)
return
}
// Description2 add share.
func (s *Service2) Description2(c context.Context, arg *model.ArgAid) (des string, err error) {
err = s.client.Call(c, _description2, arg, &des)
return
}
// RanksTopCount2 get top region count.
func (s *Service2) RanksTopCount2(c context.Context, arg *model.ArgRankTopsCount2) (res map[int16]int, err error) {
err = s.client.Call(c, _ranksTopCount2, arg, &res)
return
}
// ArcCache2 add/update archive cache
func (s *Service2) ArcCache2(c context.Context, arg *model.ArgCache2) (err error) {
err = s.client.Call(c, _arcCache2, arg, _noArg)
return
}
// ArcFieldCache2 update archive field cache
func (s *Service2) ArcFieldCache2(c context.Context, arg *model.ArgFieldCache2) (err error) {
err = s.client.Call(c, _arcFieldCache2, arg, _noArg)
return
}
// SetStat2 set all stat info.
func (s *Service2) SetStat2(c context.Context, arg *api.Stat) (err error) {
err = s.client.Call(c, _setStat2, arg, _noArg)
return
}
// SetStatCache2 up stat.
func (s *Service2) SetStatCache2(c context.Context, arg *model.ArgStat2) (err error) {
err = s.client.Call(c, _setStatCache2, arg, _noArg)
return
}

View File

@@ -0,0 +1,252 @@
package gorpc
import (
"context"
"fmt"
"testing"
"time"
"go-common/app/service/main/archive/api"
"go-common/app/service/main/archive/model/archive"
)
func TestDynamic(t *testing.T) {
s := New2(nil)
time.Sleep(5 * time.Second)
testArchivesWithPlayer(t, s)
testMaxAID(t, s)
testVideo3(t, s)
testUpsArcs3(t, s)
testUpArcs3(t, s)
testRecommend3(t, s)
testArchive3(t, s)
testArchives3(t, s)
testAidPTime(t, s)
testTypes2(t, s)
testVideoshot2(t, s)
testUpCount2(t, s)
testView3(t, s)
testViews3(t, s)
testClick3(t, s)
testRankArcs3(t, s)
testRanksArcs3(t, s)
testRankTopArcs3(t, s)
testRankAllArcs3(t, s)
testPage3(t, s)
testRanksTopCount2(t, s)
testStat3(t, s)
testStats3(t, s)
testArcCache2(t, s)
testArcFieldCache2(t, s)
testSetStat2(t, s)
testUpVideo2(t, s)
testDelVideo2(t, s)
testDescription2(t, s)
}
func testViews3(t *testing.T, s *Service2) {
var vs, err = s.Views3(context.TODO(), &archive.ArgAids2{Aids: []int64{10097450, 10097454}})
if err != nil {
t.Log(err)
return
}
for _, v := range vs {
t.Log(v.Archive3)
}
}
func testClick3(t *testing.T, s *Service2) {
t.Log(s.Click3(context.TODO(), &archive.ArgAid2{Aid: 10097454}))
}
func testRankArcs3(t *testing.T, s *Service2) {
t.Log(s.RankArcs3(context.TODO(), &archive.ArgRank2{Rid: 20, Type: 0, Ps: 20, Pn: 1}))
}
func testRanksArcs3(t *testing.T, s *Service2) {
t.Log(s.RanksArcs3(context.TODO(), &archive.ArgRanks2{Rids: []int16{20, 24}, Type: 0, Ps: 20, Pn: 1}))
}
func testRankTopArcs3(t *testing.T, s *Service2) {
t.Log(s.RankTopArcs3(context.TODO(), &archive.ArgRankTop2{ReID: 1, Pn: 1, Ps: 10}))
}
func testRankAllArcs3(t *testing.T, s *Service2) {
am, err := s.RankAllArcs3(context.TODO(), &archive.ArgRankAll2{Pn: 1, Ps: 40})
if err != nil {
t.Log(err)
return
}
t.Logf("allRankTop(%d)", am.Count)
for _, arc := range am.Archives {
t.Logf("archive(%+v)", arc)
}
}
func testAidPTime(t *testing.T, s *Service2) {
res, err := s.UpsPassed2(context.TODO(), &archive.ArgUpsArcs2{Mids: []int64{15555180, 27515256}})
fmt.Println(len(res))
if err != nil {
t.Logf("s.UpsPassed2 error(%v)", err)
return
}
for mid, v := range res {
t.Logf("mid:%d", mid)
for _, aidAndPtime := range v {
t.Logf("mid:%d, aid:%d, ptime:%d, copyright:%d", mid, aidAndPtime.Aid, aidAndPtime.PubDate, aidAndPtime.Copyright)
}
}
}
func testArchivesWithPlayer(t *testing.T, s *Service2) {
arg := &archive.ArgPlayer{Aids: []int64{10097272, 1}, Qn: 16, Platform: "html5", RealIP: "222.73.196.18"}
res, err := s.ArchivesWithPlayer(context.TODO(), arg)
if err != nil {
t.Logf("s.ArchivesWithPlayer(%+v) error(%v)", arg, err)
return
}
for k, v := range res {
t.Logf("aid:%d, arc:%+v, player:%+v", k, v, v.PlayerInfo)
}
}
func testVideo3(t *testing.T, s *Service2) {
t.Log(s.Video3(context.TODO(), &archive.ArgVideo2{Aid: 10097760, Cid: 10107336}))
}
func testRecommend3(t *testing.T, s *Service2) {
for i := 0; i < 50; i++ {
time.Sleep(100 * time.Millisecond)
res, err := s.Recommend3(context.TODO(), &archive.ArgAid2{Aid: 4052562})
if err != nil {
t.Logf("s.Recommend3 error(%v)", err)
continue
}
t.Log(res)
}
}
func testArchive3(t *testing.T, s *Service2) {
res, err := s.Archive3(context.TODO(), &archive.ArgAid2{Aid: 5463609})
if err != nil {
t.Logf("s.Archive3 error(%v)", err)
return
}
t.Log(res)
}
func testArchives3(t *testing.T, s *Service2) {
res, err := s.Archives3(context.TODO(), &archive.ArgAids2{Aids: []int64{5463609, 5463608, 10097657}})
if err != nil {
t.Logf("s.Archives3 error(%v)", err)
return
}
for _, a := range res {
t.Log(a)
}
}
func testMaxAID(t *testing.T, s *Service2) {
res, err := s.MaxAID(context.TODO())
if err != nil {
t.Error(err)
return
}
t.Logf("maxAID is %d", res)
}
func testTypes2(t *testing.T, s *Service2) {
res, err := s.Types2(context.TODO())
if err != nil {
t.Error(err)
return
}
for _, tp := range res {
t.Log(tp)
}
}
func testVideoshot2(t *testing.T, s *Service2) {
res, err := s.Videoshot2(context.TODO(), &archive.ArgCid2{Cid: 10108203})
t.Log(res, err)
}
func testUpArcs3(t *testing.T, s *Service2) {
res, err := s.UpArcs3(context.TODO(), &archive.ArgUpArcs2{Mid: 27515615, Pn: 1, Ps: 20})
if err != nil {
t.Error(err)
return
}
for _, a := range res {
t.Log(a)
}
}
func testUpCount2(t *testing.T, s *Service2) {
count, err := s.UpCount2(context.TODO(), &archive.ArgUpCount2{Mid: 27515615})
if err != nil {
t.Error(err)
return
}
t.Log(count)
}
func testUpsArcs3(t *testing.T, s *Service2) {
res, err := s.UpsArcs3(context.TODO(), &archive.ArgUpsArcs2{Mids: []int64{27515615, 1684013}})
if err != nil {
t.Error(err)
return
}
t.Log(res)
}
func testView3(t *testing.T, s *Service2) {
t.Log(s.View3(context.TODO(), &archive.ArgAid2{Aid: 10098067}))
}
func testPage3(t *testing.T, s *Service2) {
t.Log(s.Page3(context.TODO(), &archive.ArgAid2{Aid: 10097454}))
}
func testRanksTopCount2(t *testing.T, s *Service2) {
t.Log(s.RanksTopCount2(context.TODO(), &archive.ArgRankTopsCount2{ReIDs: []int16{1, 2}}))
}
func testStat3(t *testing.T, s *Service2) {
res, err := s.Stat3(context.TODO(), &archive.ArgAid2{Aid: 10989901})
if err != nil {
t.Errorf("testStats3 error(%v)", err)
return
}
t.Log(res, 1)
}
func testStats3(t *testing.T, s *Service2) {
res, err := s.Stats3(context.TODO(), &archive.ArgAids2{Aids: []int64{10989901, 10097453}})
if err != nil {
t.Logf("testStats3 error(%v)", err)
return
}
for aid, r := range res {
t.Logf("%d:%+v\n", aid, r)
}
}
func testArcCache2(t *testing.T, s *Service2) {
t.Log(s.ArcCache2(context.TODO(), &archive.ArgCache2{Aid: 10097454, Tp: archive.CacheUpdate}))
}
func testArcFieldCache2(t *testing.T, s *Service2) {
t.Log(s.ArcFieldCache2(context.TODO(), &archive.ArgFieldCache2{Aid: 10097454, TypeID: 20, OldTypeID: 10}))
}
func testSetStat2(t *testing.T, s *Service2) {
t.Log(s.SetStat2(context.TODO(), &api.Stat{Aid: 10097454, View: 0, Danmaku: 0, Reply: 10, Fav: 10, Coin: 10, Share: 10, HisRank: 10, NowRank: 10}))
}
func testUpVideo2(t *testing.T, s *Service2) {
t.Log(s.UpVideo2(context.TODO(), &archive.ArgVideo2{Aid: 10097760, Cid: 10107336}))
}
func testDelVideo2(t *testing.T, s *Service2) {
t.Log(s.DelVideo2(context.TODO(), &archive.ArgVideo2{Aid: 10097760, Cid: 10107336}))
}
func testDescription2(t *testing.T, s *Service2) {
t.Log(s.Description2(context.TODO(), &archive.ArgAid{Aid: 10097454}))
}

View File

@@ -0,0 +1,141 @@
package gorpc
import (
"context"
"go-common/app/service/main/archive/api"
model "go-common/app/service/main/archive/model/archive"
)
const (
_archive3 = "RPC.Archive3"
_archives3 = "RPC.Archives3"
_view3 = "RPC.View3"
_views3 = "RPC.Views3"
_stat3 = "RPC.Stat3"
_stats3 = "RPC.Stats3"
_click3 = "RPC.Click3"
_upArcs3 = "RPC.UpArcs3"
_upsArcs3 = "RPC.UpsArcs3"
_page3 = "RPC.Page3"
_recommend3 = "RPC.Recommend3"
_rankArcs3 = "RPC.RankArcs3"
_ranksArcs3 = "RPC.RanksArcs3"
_rankTopArcs3 = "RPC.RankTopArcs3"
_rankAllArcs3 = "RPC.RankAllArcs3"
_video3 = "RPC.Video3"
_archivesWithPlayer = "RPC.ArchivesWithPlayer"
_maxAid = "RPC.MaxAID"
)
// MaxAID get max aid
func (s *Service2) MaxAID(c context.Context) (id int64, err error) {
err = s.client.Call(c, _maxAid, _noArg, &id)
return
}
// Archive3 Get receive aid, then init archive info.
func (s *Service2) Archive3(c context.Context, arg *model.ArgAid2) (res *api.Arc, err error) {
res = new(api.Arc)
err = s.client.Call(c, _archive3, arg, res)
return
}
// Archives3 receive aids, then init archives info.
func (s *Service2) Archives3(c context.Context, arg *model.ArgAids2) (res map[int64]*api.Arc, err error) {
err = s.client.Call(c, _archives3, arg, &res)
return
}
// View3 get archive info and view pages.
func (s *Service2) View3(c context.Context, arg *model.ArgAid2) (res *model.View3, err error) {
res = new(model.View3)
err = s.client.Call(c, _view3, arg, res)
return
}
// Views3 get archives info and view pages.
func (s *Service2) Views3(c context.Context, arg *model.ArgAids2) (res map[int64]*model.View3, err error) {
err = s.client.Call(c, _views3, arg, &res)
return
}
// Stat3 get archive stat
func (s *Service2) Stat3(c context.Context, arg *model.ArgAid2) (res *api.Stat, err error) {
err = s.client.Call(c, _stat3, arg, &res)
return
}
// ArchivesWithPlayer archives witch player
func (s *Service2) ArchivesWithPlayer(c context.Context, arg *model.ArgPlayer) (res map[int64]*model.ArchiveWithPlayer, err error) {
err = s.client.Call(c, _archivesWithPlayer, arg, &res)
return
}
// Stats3 get archive stat
func (s *Service2) Stats3(c context.Context, arg *model.ArgAids2) (res map[int64]*api.Stat, err error) {
err = s.client.Call(c, _stats3, arg, &res)
return
}
// Click3 get archive click
func (s *Service2) Click3(c context.Context, arg *model.ArgAid2) (res *api.Click, err error) {
err = s.client.Call(c, _click3, arg, &res)
return
}
// UpsArcs3 get archives of upper.
func (s *Service2) UpsArcs3(c context.Context, arg *model.ArgUpsArcs2) (res map[int64][]*api.Arc, err error) {
err = s.client.Call(c, _upsArcs3, arg, &res)
return
}
// UpArcs3 get archives of upper.
func (s *Service2) UpArcs3(c context.Context, arg *model.ArgUpArcs2) (res []*api.Arc, err error) {
err = s.client.Call(c, _upArcs3, arg, &res)
return
}
// Page3 get videos by aid
func (s *Service2) Page3(c context.Context, arg *model.ArgAid2) (res []*api.Page, err error) {
err = s.client.Call(c, _page3, arg, &res)
return
}
// Recommend3 from archive_recommend by aid
func (s *Service2) Recommend3(c context.Context, arg *model.ArgAid2) (res []*api.Arc, err error) {
err = s.client.Call(c, _recommend3, arg, &res)
return
}
// RankArcs3 get rank archives by type.
func (s *Service2) RankArcs3(c context.Context, arg *model.ArgRank2) (res *model.RankArchives3, err error) {
res = new(model.RankArchives3)
err = s.client.Call(c, _rankArcs3, arg, res)
return
}
// RanksArcs3 get rank archives by types.
func (s *Service2) RanksArcs3(c context.Context, arg *model.ArgRanks2) (res map[int16]*model.RankArchives3, err error) {
err = s.client.Call(c, _ranksArcs3, arg, &res)
return
}
// RankTopArcs3 get top region archives by reid
func (s *Service2) RankTopArcs3(c context.Context, arg *model.ArgRankTop2) (res []*api.Arc, err error) {
err = s.client.Call(c, _rankTopArcs3, arg, &res)
return
}
// RankAllArcs3 get left 7 days all archives
func (s *Service2) RankAllArcs3(c context.Context, arg *model.ArgRankAll2) (res *model.RankArchives3, err error) {
err = s.client.Call(c, _rankAllArcs3, arg, &res)
return
}
// Video3 get video by aid & cid.
func (s *Service2) Video3(c context.Context, arg *model.ArgVideo2) (res *api.Page, err error) {
res = new(api.Page)
err = s.client.Call(c, _video3, arg, res)
return
}

View File

@@ -0,0 +1,3 @@
# API文档
http://info.bilibili.co/display/coding/archive-service

View File

@@ -0,0 +1,235 @@
package api
import (
"hash/crc32"
"strconv"
"strings"
"go-common/library/time"
)
// 各属性地址见 http://syncsvn.bilibili.co/platform/doc/blob/master/archive/field/state.md
// all const
const (
// open state
StateOpen = 0
StateOrange = 1
AccessMember = int32(10000)
// forbid state
StateForbidWait = -1
StateForbidRecicle = -2
StateForbidPolice = -3
StateForbidLock = -4
StateForbidFixed = -6
StateForbidLater = -7
StateForbidAdminDelay = -10
StateForbidXcodeFail = -16
StateForbidSubmit = -30
StateForbidUserDelay = -40
StateForbidUpDelete = -100
// copyright
CopyrightUnknow = int8(0)
CopyrightOriginal = int8(1)
CopyrightCopy = int8(2)
// attribute yes and no
AttrYes = int32(1)
AttrNo = int32(0)
// attribute bit
AttrBitNoRank = uint(0)
AttrBitNoDynamic = uint(1)
AttrBitNoWeb = uint(2)
AttrBitNoMobile = uint(3)
// AttrBitNoSearch = uint(4)
AttrBitOverseaLock = uint(5)
AttrBitNoRecommend = uint(6)
AttrBitNoReprint = uint(7)
AttrBitHasHD5 = uint(8)
AttrBitIsPGC = uint(9)
AttrBitAllowBp = uint(10)
AttrBitIsBangumi = uint(11)
AttrBitIsPorder = uint(12)
AttrBitLimitArea = uint(13)
AttrBitAllowTag = uint(14)
// AttrBitIsFromArcApi = uint(15)
AttrBitJumpUrl = uint(16)
AttrBitIsMovie = uint(17)
AttrBitBadgepay = uint(18)
AttrBitUGCPay = uint(22)
AttrBitHasBGM = uint(23)
AttrBitIsCooperation = uint(24)
AttrBitHasViewpoint = uint(25)
AttrBitHasArgument = uint(26)
)
var (
_emptyTags = []string{}
)
// IsNormal is
func (a *Arc) IsNormal() bool {
return a.State >= StateOpen || a.State == StateForbidFixed
}
// RegionArc RegionArc
type RegionArc struct {
Aid int64
Attribute int32
Copyright int8
PubDate time.Time
}
// AllowShow AllowShow
func (ra *RegionArc) AllowShow() bool {
return ra.attrVal(AttrBitNoWeb) == AttrNo && ra.attrVal(AttrBitNoMobile) == AttrNo
}
func (ra *RegionArc) attrVal(bit uint) int32 {
return (ra.Attribute >> bit) & int32(1)
}
// AttrVal get attr val by bit.
func (a *Arc) AttrVal(bit uint) int32 {
return (a.Attribute >> bit) & int32(1)
}
// FillDimension is
func (a *Arc) FillDimension(d string) {
if d == "" || d == "0,0,0" {
return
}
ds := strings.Split(d, ",")
if len(ds) != 3 {
return
}
var (
width, height, rotate int64
err error
)
if width, err = strconv.ParseInt(ds[0], 10, 64); err != nil {
return
}
if height, err = strconv.ParseInt(ds[1], 10, 64); err != nil {
return
}
if rotate, err = strconv.ParseInt(ds[2], 10, 64); err != nil {
return
}
a.Dimension = Dimension{
Width: width,
Height: height,
Rotate: rotate,
}
}
// FillDimension is
func (v *Page) FillDimension(d string) {
if d == "" || d == "0,0,0" {
return
}
ds := strings.Split(d, ",")
if len(ds) != 3 {
return
}
var (
width, height, rotate int64
err error
)
if width, err = strconv.ParseInt(ds[0], 10, 64); err != nil {
return
}
if height, err = strconv.ParseInt(ds[1], 10, 64); err != nil {
return
}
if rotate, err = strconv.ParseInt(ds[2], 10, 64); err != nil {
return
}
v.Dimension = Dimension{
Width: width,
Height: height,
Rotate: rotate,
}
}
// Fill file archive some field.
func (a *Arc) Fill() {
a.Tags = _emptyTags
a.Pic = coverURL(a.Pic)
a.Rights.Bp = a.AttrVal(AttrBitAllowBp)
a.Rights.Movie = a.AttrVal(AttrBitIsMovie)
a.Rights.Pay = a.AttrVal(AttrBitBadgepay)
a.Rights.HD5 = a.AttrVal(AttrBitHasHD5)
a.Rights.NoReprint = a.AttrVal(AttrBitNoReprint)
a.Rights.UGCPay = a.AttrVal(AttrBitUGCPay)
a.Rights.IsCooperation = a.AttrVal(AttrBitIsCooperation)
if a.FirstCid == 0 ||
a.Access == AccessMember ||
a.AttrVal(AttrBitIsPGC) == AttrYes ||
a.AttrVal(AttrBitAllowBp) == AttrYes ||
a.AttrVal(AttrBitBadgepay) == AttrYes ||
a.AttrVal(AttrBitOverseaLock) == AttrYes ||
a.AttrVal(AttrBitUGCPay) == AttrYes ||
a.AttrVal(AttrBitLimitArea) == AttrYes {
return
}
a.Rights.Autoplay = 1
}
// coverURL convert cover url to full url.
func coverURL(uri string) (cover string) {
if uri == "" {
cover = "http://static.hdslb.com/images/transparent.gif"
return
}
cover = uri
if strings.Index(uri, "http://") == 0 {
return
}
if len(uri) >= 10 && uri[:10] == "/templets/" {
return
}
if strings.HasPrefix(uri, "group1") {
cover = "http://i0.hdslb.com/" + uri
return
}
if pos := strings.Index(uri, "/uploads/"); pos != -1 && (pos == 0 || pos == 3) {
cover = uri[pos+8:]
}
cover = strings.Replace(cover, "{IMG}", "", -1)
cover = "http://i" + strconv.FormatInt(int64(crc32.ChecksumIEEE([]byte(cover)))%3, 10) + ".hdslb.com" + cover
return
}
// FillStat file stat, check access.
func (a *Arc) FillStat() {
if a.Access > 0 {
a.Stat.View = 0
}
}
// PlayerInfo player info
type PlayerInfo struct {
Cid int64 `json:"cid"`
ExpireTime int64 `json:"expire_time,omitempty"`
FileInfo map[int][]*PlayerFileInfo `json:"file_info"`
SupportQuality []int `json:"support_quality"`
SupportFormats []string `json:"support_formats"`
SupportDescription []string `json:"support_description"`
Quality int `json:"quality"`
URL string `json:"url,omitempty"`
VideoCodecid uint32 `json:"video_codecid"`
VideoProject bool `json:"video_project"`
Fnver int `json:"fnver"`
Fnval int `json:"fnval"`
Dash *ResponseDash `json:"dash,omitempty"`
}
// PlayerFileInfo is
type PlayerFileInfo struct {
TimeLength int64 `json:"timelength"`
FileSize int64 `json:"filesize"`
Ahead string `json:"ahead,omitempty"`
Vhead string `json:"vhead,omitempty"`
URL string `json:"url,omitempty"`
Order int64 `json:"order,omitempty"`
}