ABS v1 test

This commit is contained in:
mubai
2023-12-24 23:22:20 +08:00
parent b48e53a637
commit 86e0501d2f
59 changed files with 538 additions and 1699 deletions

View File

@@ -68,6 +68,7 @@ type FilmSource struct {
SyncPictures bool `json:"syncPictures"` // 是否同步图片到服务器
CollectType ResourceType `json:"collectType"` // 采集资源类型
State bool `json:"state"` // 是否启用
Interval int `json:"interval"` // 采集时间间隔 单位/ms
}
// SaveCollectSourceList 保存采集站Api列表

View File

@@ -89,52 +89,59 @@ func GetPicturePage(page *Page) []Picture {
// SaveVirtualPic 保存待同步的图片信息
func SaveVirtualPic(pl []VirtualPicture) error {
// 保存对应的
// 保存对应的待同步图片信息
var zl []redis.Z
for _, p := range pl {
// 首先查询 Gallery 表中是否存在当前ID对应的图片信息, 如果不存在则保存
if !ExistPictureByRid(p.Id) {
m, _ := json.Marshal(p)
zl = append(zl, redis.Z{Score: float64(p.Id), Member: m})
}
//if !ExistPictureByRid(p.Id) {
// m, _ := json.Marshal(p)
// zl = append(zl, redis.Z{Score: float64(p.Id), Member: m})
//}
// 只要开启图片同步则将图片信息存入待同步图片信息集合中, 是否同步图片交由真正同步到本地时进行决断
m, _ := json.Marshal(p)
zl = append(zl, redis.Z{Score: float64(p.Id), Member: m})
}
return db.Rdb.ZAdd(db.Cxt, config.VirtualPictureKey, zl...).Err()
}
// SyncFilmPicture 同步新采集入栈还未同步的图片
func SyncFilmPicture() {
// 获取集合中的元素数量, 如果集合中没有元素则直接返回
count := db.Rdb.ZCard(db.Cxt, config.VirtualPictureKey).Val()
if count <= 0 {
return
}
// 扫描待同步图片的信息, 每次扫描count条
sl, cursor := db.Rdb.ZScan(db.Cxt, config.VirtualPictureKey, 0, "*", config.MaxScanCount).Val()
sl := db.Rdb.ZPopMax(db.Cxt, config.VirtualPictureKey, config.MaxScanCount).Val()
if len(sl) <= 0 {
return
}
// 获取 VirtualPicture
for i, s := range sl {
if i%2 == 0 {
// 获取图片信息
vp := VirtualPicture{}
_ = json.Unmarshal([]byte(s), &vp)
// 删除已经取出的数据
db.Rdb.ZRem(db.Cxt, config.VirtualPictureKey, []byte(s))
// 将图片同步到服务器
fileName, err := util.SaveOnlineFile(vp.Link, config.FilmPictureUploadDir)
if err != nil {
continue
}
// 完成同步后将图片信息保存到 Gallery 中
SaveGallery(Picture{
Link: fmt.Sprint(config.FilmPictureAccess, fileName),
Uid: config.UserIdInitialVal,
RelevanceId: vp.Id,
PicType: 0,
PicUid: regexp.MustCompile(`\.[^.]+$`).ReplaceAllString(fileName, ""),
})
for _, s := range sl {
// 获取图片信息
vp := VirtualPicture{}
_ = json.Unmarshal([]byte(s.Member.(string)), &vp)
// 判断当前影片是否已经同步过图片, 如果已经同步则直接跳过后续逻辑
if ExistPictureByRid(vp.Id) {
continue
}
// 将图片同步到服务器中
fileName, err := util.SaveOnlineFile(vp.Link, config.FilmPictureUploadDir)
if err != nil {
continue
}
// 完成同步后将图片信息保存到 Gallery 中
SaveGallery(Picture{
Link: fmt.Sprint(config.FilmPictureAccess, fileName),
Uid: config.UserIdInitialVal,
RelevanceId: vp.Id,
PicType: 0,
PicUid: regexp.MustCompile(`\.[^.]+$`).ReplaceAllString(fileName, ""),
})
}
// 如果 cursor != 0 则继续递归执行
if cursor > 0 {
SyncFilmPicture()
}
// 递归执行直到图片暂存信息为空
SyncFilmPicture()
}
// ReplaceDetailPic 将影片详情中的图片地址替换为自己的

View File

@@ -160,7 +160,7 @@ func SaveMovieBasicInfo(detail MovieDetail) {
}
// SaveSitePlayList 仅保存播放url列表信息到当前站点
func SaveSitePlayList(siteName string, list []MovieDetail) (err error) {
func SaveSitePlayList(id string, list []MovieDetail) (err error) {
// 如果list 为空则直接返回
if len(list) <= 0 {
return nil
@@ -183,7 +183,7 @@ func SaveSitePlayList(siteName string, list []MovieDetail) (err error) {
// 如果结果不为空,则将数据保存到redis中
if len(res) > 0 {
// 保存形式 key: MultipleSource:siteName Hash[hash(movieName)]list
err = db.Rdb.HMSet(db.Cxt, fmt.Sprintf(config.MultipleSiteDetail, siteName), res).Err()
err = db.Rdb.HMSet(db.Cxt, fmt.Sprintf(config.MultipleSiteDetail, id), res).Err()
}
return
}

View File

@@ -1,82 +0,0 @@
package system
/*
量子资源JSON解析
*/
// ClassInfo class 分类数据
type ClassInfo struct {
Id int64 `json:"type_id"` //分类ID
Pid int64 `json:"type_pid"` //上级分类ID
Name string `json:"type_name"` //分类名称
}
// MovieInfo 影片数据
type MovieInfo struct {
Id int64 `json:"vod_id"` // 影片ID
Name string `json:"vod_name"` // 影片名
Cid int64 `json:"type_id"` // 所属分类ID
CName string `json:"type_name"` // 所属分类名称
EnName string `json:"vod_en"` // 英文片名
Time string `json:"vod_time"` // 更新时间
Remarks string `json:"vod_remarks"` // 备注 | 清晰度
PlayFrom string `json:"vod_play_from"` // 播放来源
}
// MovieListInfo 影视列表响应数据
type MovieListInfo struct {
Code int64 `json:"code"`
Msg string `json:"msg"`
Page any `json:"page"`
PageCount int64 `json:"pagecount"`
Limit string `json:"limit"`
Total int64 `json:"total"`
List []MovieInfo `json:"list"`
Class []ClassInfo `json:"class"`
}
// MovieDetailInfo 影片详情数据 (只保留需要的部分)
type MovieDetailInfo struct {
Id int64 `json:"vod_id"` //影片Id
Cid int64 `json:"type_id"` //分类ID
Pid int64 `json:"type_id_1"` //一级分类ID
Name string `json:"vod_name"` //片名
SubTitle string `json:"vod_sub"` //子标题
CName string `json:"type_name"` //分类名称
EnName string `json:"vod_en"` //英文名
Initial string `json:"vod_letter"` //首字母
ClassTag string `json:"vod_class"` //分类标签
Pic string `json:"vod_pic"` //简介图片
Actor string `json:"vod_actor"` //主演
Director string `json:"vod_director"` //导演
Writer string `json:"vod_writer"` //作者
Blurb string `json:"vod_blurb"` //简介, 残缺,不建议使用
Remarks string `json:"vod_remarks"` // 更新情况
PubDate string `json:"vod_pubdate"` //上映时间
Area string `json:"vod_area"` // 地区
Language string `json:"vod_lang"` //语言
Year string `json:"vod_year"` //年份
State string `json:"vod_state"` //影片状态 正片|预告...
UpdateTime string `json:"vod_time"` //更新时间
AddTime int64 `json:"vod_time_add"` //资源添加时间戳
DbId int64 `json:"vod_douban_id"` //豆瓣id
DbScore string `json:"vod_douban_score"` // 豆瓣评分
Hits int64 `json:"vod_hits"` // 总热度
Content string `json:"vod_content"` //内容简介
PlayFrom string `json:"vod_play_from"` // 播放来源
PlaySeparator string `json:"vod_play_note"` // 播放信息分隔符
PlayUrl string `json:"vod_play_url"` //播放地址url
DownFrom string `json:"vod_down_from"` //下载来源 例: http
DownUrl string `json:"vod_down_url"` // 下载url地址
}
// DetailListInfo 影视详情信息
type DetailListInfo struct {
Code int64 `json:"code"`
Msg string `json:"msg"`
Page any `json:"page"`
PageCount int64 `json:"pagecount"`
Limit string `json:"limit"`
Total int64 `json:"total"`
List []MovieDetailInfo `json:"list"`
}

View File

@@ -261,7 +261,6 @@ func BatchSave(list []SearchInfo) {
if err := tx.CreateInBatches(list, len(list)).Error; err != nil {
// 插入失败则回滚事务, 重新进行插入
tx.Rollback()
return
}
// 保存成功后将相应tag数据缓存到redis中
BatchHandleSearchTag(list...)
@@ -357,26 +356,26 @@ func SyncSearchInfo(model int) {
// SearchInfoToMdb 扫描redis中的检索信息, 并批量存入mysql (model 执行模式 0-清空并保存 || 1-更新)
func SearchInfoToMdb(model int) {
// 获取集合中的元素数量, 如果集合中没有元素则直接返回
count := db.Rdb.ZCard(db.Cxt, config.SearchInfoTemp).Val()
if count <= 0 {
return
}
// 1.从redis中批量扫描详情信息
list, cursor := db.Rdb.ZScan(db.Cxt, config.SearchInfoTemp, 0, "*", config.MaxScanCount).Val()
list := db.Rdb.ZPopMax(db.Cxt, config.SearchInfoTemp, config.MaxScanCount).Val()
// 如果扫描到的信息为空则直接退出
if len(list) <= 0 {
return
}
// 2. 处理数据
var sl []SearchInfo
for i, s := range list {
// 3. 判断当前是否是元素
if i%2 == 0 {
info := SearchInfo{}
_ = json.Unmarshal([]byte(s), &info)
info.Model = gorm.Model{}
// 获取完则删除元素, 避免重复保存
db.Rdb.ZRem(db.Cxt, config.SearchInfoTemp, []byte(s))
sl = append(sl, info)
}
for _, s := range list {
// 解析详情数据
info := SearchInfo{}
_ = json.Unmarshal([]byte(s.Member.(string)), &info)
sl = append(sl, info)
}
//
// 通过model执行对应的保存方法
switch model {
case 0:
// 批量添加 SearchInfo
@@ -386,9 +385,7 @@ func SearchInfoToMdb(model int) {
BatchSaveOrUpdate(sl)
}
// 如果 SearchInfoTemp 依然存在数据, 则递归执行
if cursor > 0 {
SearchInfoToMdb(model)
}
SearchInfoToMdb(model)
}
// ================================= API 数据接口信息处理 =================================
@@ -533,8 +530,8 @@ func GetRelateMovieBasicInfo(search SearchInfo, page *Page) []MovieBasicInfo {
}
// GetMultiplePlay 通过影片名hash值匹配播放源
func GetMultiplePlay(siteName, key string) []MovieUrlInfo {
data := db.Rdb.HGet(db.Cxt, fmt.Sprintf(config.MultipleSiteDetail, siteName), key).Val()
func GetMultiplePlay(siteId, key string) []MovieUrlInfo {
data := db.Rdb.HGet(db.Cxt, fmt.Sprintf(config.MultipleSiteDetail, siteId), key).Val()
var playList []MovieUrlInfo
_ = json.Unmarshal([]byte(data), &playList)
return playList

View File

@@ -1,5 +1,6 @@
package system
// SearchTagsVO 搜索标签请求参数
type SearchTagsVO struct {
Pid int64 `json:"pid"`
Cid int64 `json:"cid"`
@@ -100,3 +101,15 @@ type UserInfoVo struct {
Avatar string `json:"avatar"` // 头像
Status int `json:"status"` // 状态
}
// PlayLinkVo 多站点播放链接数据列表
type PlayLinkVo struct {
Id string `json:"id"`
Name string `json:"name"`
LinkList []MovieUrlInfo `json:"linkList"`
}
type MovieDetailVo struct {
MovieDetail
List []PlayLinkVo `json:"list"`
}