Skip to content

Commit

Permalink
Merge branch 'release/0.3.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
vclass committed May 5, 2024
2 parents e5955e9 + 7cf5b69 commit fb1eb5b
Show file tree
Hide file tree
Showing 61 changed files with 2,401 additions and 1,140 deletions.
Binary file added .assets/design.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
.vscode/*
config.yaml
data.db
dist/*
build/*
web/dist/*
build/*
bilibo
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ RUN apt update && apt -y --no-install-recommends install musl-tools bash curl
COPY go.mod go.sum ./
RUN go mod download
COPY ./ ./
RUN rm -rf dist && \
RUN cd web && rm -rf dist && \
curl -L https://github.com/BoredTape/bilibo-web/releases/latest/download/dist.tar.gz -o dist.tar.gz && \
tar -zxvf dist.tar.gz && \
rm -rf dist.tar.gz && \
rm -rf dist.tar.gz && cd .. && \
CC=musl-gcc CGO_ENABLED=1 go build -ldflags '-s -w --extldflags "-static -fpic"' -o ./bin/bilibo -tags=jsoniter .

FROM alpine:latest
Expand Down
102 changes: 0 additions & 102 deletions bili/core.go

This file was deleted.

203 changes: 203 additions & 0 deletions bobo/bobo.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,203 @@
package bobo

import (
"bilibo/bobo/client"
"bilibo/consts"
"bilibo/log"
"bilibo/services"
"bilibo/universal"
"context"
"errors"
"fmt"
)

var bobo *BoBo

type BoBo struct {
client map[int]*client.Client
clientCancelFunc map[int]context.CancelFunc
}

func Init() {
bobo = &BoBo{
client: make(map[int]*client.Client),
clientCancelFunc: make(map[int]context.CancelFunc),
}
restoreClient()
go handleClient()
}

func GetBoBo() *BoBo {
return bobo
}

func (b *BoBo) ClientList() []int {
var list []int
for k := range b.client {
list = append(list, k)
}
return list
}

func (b *BoBo) GetClient(mid int) (*client.Client, error) {
if client, ok := b.client[mid]; ok {
return client, nil
}
return nil, errors.New("client not found")
}

func (b *BoBo) RefreshFav(mid int) *client.AllFavourFolderInfo {
logger := log.GetLogger()
if client, err := b.GetClient(mid); err == nil {
if data, err := client.GetAllFavourFolderInfo(mid, 2, 0); err == nil {
folderInfo := make([]services.FolderInfo, 0)
for _, v := range data.List {
folderInfo = append(folderInfo, services.FolderInfo{
Id: v.Id,
Fid: v.Fid,
Mid: v.Mid,
Attr: v.Attr,
Title: v.Title,
FavState: v.FavState,
MediaCount: v.MediaCount,
})
}
serviceData := services.FavourFolderInfo{
Count: data.Count,
List: folderInfo,
}
services.SetFavourInfo(mid, &serviceData)
return data
} else {
logger.Warnf("client %d get fav list error: %v", mid, err)
}
}
return nil
}

func (b *BoBo) RefreshFavVideo(mid int, data *client.AllFavourFolderInfo) {
logger := log.GetLogger()
logger.Infof("user: %d refresh fav list", mid)
fv_svc := services.VideoService{}
if client, err := b.GetClient(mid); err == nil {
if data != nil {
fv_svc.SetMid(mid)
for _, fav := range data.List {
mlid := fav.Id
fv_svc.V.Mlid = mlid
if fret, err := client.GetFavourList(mlid, 0, "", "", 0, 20, 1, "web"); err == nil {
for _, media := range fret.Medias {
bvid := media.BvId
fv_svc.V.Bvid = bvid
if vret, err := client.GetVideoInfoByBvid(bvid); err == nil {
for _, page := range vret.Pages {
cid := page.Cid
fv_svc.V.Cid = cid
fv_svc.V.Title = vret.Title
fv_svc.V.Part = page.Part
fv_svc.V.Height = page.Dimension.Height
fv_svc.V.Width = page.Dimension.Width
fv_svc.V.Rotate = page.Dimension.Rotate
fv_svc.V.Page = page.Page
fv_svc.V.Type = consts.VIDEO_TYPE_FAVOUR
fv_svc.Save()
}
}
}
}

}
} else {
logger.Warnf("user %d get fav list empty", mid)
}
}
}

func (b *BoBo) RefreshToView(mid int) {
fv_svc := services.VideoService{}
if client, err := b.GetClient(mid); err == nil {
fv_svc.SetMid(mid)
if toViewData, err := client.GetToView(); err == nil {
for _, data := range toViewData.List {
bvid := data.Bvid
fv_svc.V.Bvid = bvid
fv_svc.V.Mlid = 0
if vret, err := client.GetVideoInfoByBvid(bvid); err == nil {
for _, page := range vret.Pages {
cid := page.Cid
fv_svc.V.Cid = cid
fv_svc.V.Title = vret.Title
fv_svc.V.Part = page.Part
fv_svc.V.Height = page.Dimension.Height
fv_svc.V.Width = page.Dimension.Width
fv_svc.V.Rotate = page.Dimension.Rotate
fv_svc.V.Page = page.Page
fv_svc.V.Type = consts.VIDEO_TYPE_WATCH_LATER
fv_svc.Save()
}
}
}
}
}
}

func handleClient() {
for ch := range *universal.GetCH() {
if ch.Action == consts.CHANNEL_ACTION_ADD_CLIENT {
addClient(&ch)
} else if ch.Action == consts.CHANNEL_ACTION_DELETE_CLIENT {
delClient(&ch)
} else {
logger := log.GetLogger()
logger.Info(fmt.Sprintf("channel get unknown action: %d", ch.Action))
}
}
}

func addClient(ch *universal.CH) {
c := client.New(
client.WithUA(""), // 先使用默认的,可能以后会改成可修改的
client.WithCookiesStrings(ch.Cookies),
client.WithImgKey(ch.ImgKey),
client.WithSubKey(ch.SubKey),
client.WithMid(ch.Mid),
)
bobo.client[ch.Mid] = c
ctx, cancel := context.WithCancel(context.Background())
bobo.clientCancelFunc[ch.Mid] = cancel
go bobo.RefreshAll(ch.Mid)
go downloadFavVideo(c, ctx)
}

func (b *BoBo) RefreshAll(mid int) {
data := bobo.RefreshFav(mid)
bobo.RefreshFavVideo(mid, data)
bobo.RefreshToView(mid)
}

func (b *BoBo) DelClient(mid int) {
delete(b.client, mid)
if cancelFunc, ok := bobo.clientCancelFunc[mid]; ok {
cancelFunc()
}
delete(b.clientCancelFunc, mid)
}

func delClient(ch *universal.CH) {
bobo.DelClient(ch.Mid)
}

func restoreClient() {
accounts := services.GetAccountList()
for _, account := range *accounts {
addClient(&universal.CH{
Mid: account.Mid,
UName: account.UName,
Face: account.Face,
ImgKey: account.ImgKey,
SubKey: account.SubKey,
Cookies: account.Cookies,
Action: consts.CHANNEL_ACTION_ADD_CLIENT,
})
}
}
2 changes: 1 addition & 1 deletion bili/bili_client/Wbi.go → bobo/client/Wbi.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package bili_client
package client

import (
"crypto/md5"
Expand Down
4 changes: 2 additions & 2 deletions bili/bili_client/client.go → bobo/client/client.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// copy from https://github.com/CuteReimu/bilibili/blob/master/client.go
package bili_client
package client

import (
"net/http"
Expand Down Expand Up @@ -66,7 +66,7 @@ func WithCookiesStrings(cookies string) ClientOption {
}
}

func NewClient(opts ...ClientOption) *Client {
func New(opts ...ClientOption) *Client {
c := &Client{}
for _, opt := range opts {
opt(c)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// copy from https://github.com/CuteReimu/bilibili/blob/master/comment.go
package bili_client
package client

type Comment struct { // 评论条目对象
Rpid int64 `json:"rpid"` // 评论 rpid
Expand Down
2 changes: 1 addition & 1 deletion bili/bili_client/download.go → bobo/client/download.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package bili_client
package client

import (
"bilibo/consts"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package bili_client
package client

const (
/*
Expand Down
2 changes: 1 addition & 1 deletion bili/bili_client/fav.go → bobo/client/fav.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//copy from https://github.com/CuteReimu/bilibili/blob/master/fav.go

package bili_client
package client

import (
"encoding/json"
Expand Down
2 changes: 1 addition & 1 deletion bili/bili_client/fav_type.go → bobo/client/fav_type.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// copy from https://github.com/CuteReimu/bilibili/blob/master/fav.go
package bili_client
package client

type FavourFolderInfo struct {
Id int `json:"id"` // 收藏夹mlid(完整id),收藏夹原始id+创建者mid尾号2位
Expand Down
Loading

0 comments on commit fb1eb5b

Please sign in to comment.