@@ -0,0 +1,266 @@
|
||||
package laosijiser
|
||||
|
||||
import (
|
||||
"91porn-server/common"
|
||||
"91porn-server/common/laosiji"
|
||||
"91porn-server/common/log"
|
||||
"91porn-server/models/v/mediacontentmod"
|
||||
"91porn-server/models/v/mediamod"
|
||||
"91porn-server/web/service/vidser"
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
)
|
||||
|
||||
func ComicsSearch(ctx context.Context, param laosiji.ComicsSearchListReq) (resp laosiji.ComicsSearchListResp, err error) {
|
||||
comicsResp, err := laosiji.ComicsSearch(ctx, param)
|
||||
if err != nil {
|
||||
log.Error("MovieSearch", log.E(err))
|
||||
return
|
||||
}
|
||||
|
||||
//是否导入
|
||||
lsjIds := make([]string, 0)
|
||||
for _, v := range comicsResp.Data {
|
||||
lsjIds = append(lsjIds, v.Id)
|
||||
}
|
||||
comicsList, _ := mediamod.GetListByLsjIds(lsjIds)
|
||||
|
||||
// 处理域名
|
||||
resp = laosiji.ComicsSearchListResp{
|
||||
Data: make([]laosiji.ComicsSearchInfo, 0),
|
||||
Total: comicsResp.Total,
|
||||
Current_page: comicsResp.Current_page,
|
||||
Page_size: comicsResp.Page_size,
|
||||
Last_page: comicsResp.Last_page,
|
||||
}
|
||||
for _, comicsInfo := range comicsResp.Data {
|
||||
//comicsInfo.Img = common.JoinUrlPath(laosiji.IMAGEYUAN, comicsInfo.Img)
|
||||
comicsInfo.Img = common.JoinUrlPath("laosiji", comicsInfo.Img)
|
||||
|
||||
for _, comicsIn := range comicsList {
|
||||
if comicsIn.LsjId == comicsInfo.Id {
|
||||
comicsInfo.IsAdd = true
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
resp.Data = append(resp.Data, comicsInfo)
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func ComicsDetail(ctx context.Context, param laosiji.ComicsDetailReq) (resp laosiji.ComicsDetailResp, serr error) {
|
||||
resp, serr = laosiji.ComicsDetail(ctx, param)
|
||||
if serr != nil {
|
||||
log.Error("MovieSearch", log.E(serr))
|
||||
return
|
||||
}
|
||||
|
||||
// 处理域名
|
||||
//resp.Img = common.JoinUrlPath(laosiji.IMAGEYUAN, resp.Img)
|
||||
resp.Img = common.JoinUrlPath("laosiji", resp.Img)
|
||||
if resp.Chapter != nil && len(resp.Chapter) > 0 {
|
||||
for i, cha := range resp.Chapter {
|
||||
if len(cha.Img) > 0 {
|
||||
//resp.Chapter[i].Img = common.JoinUrlPath(laosiji.IMAGEYUAN, resp.Chapter[i].Img)
|
||||
resp.Chapter[i].Img = common.JoinUrlPath("laosiji", resp.Chapter[i].Img)
|
||||
}
|
||||
if cha.Content != nil && len(cha.Content) > 0 {
|
||||
for y, content := range cha.Content {
|
||||
//resp.Chapter[i].Content[y].F = common.JoinUrlPath(laosiji.IMAGEYUAN, content.F)
|
||||
resp.Chapter[i].Content[y].F = common.JoinUrlPath("laosiji", content.F)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func ComicsAddList(ctx context.Context, param laosiji.ComicsSyncReq, manager string) (hits []vidser.SensitiveHit, err error) {
|
||||
if param.Ids == nil || len(param.Ids) <= 0 {
|
||||
return
|
||||
}
|
||||
// 批量查询所有详情
|
||||
comicsDetails := make([]laosiji.ComicsDetailResp, 0)
|
||||
for _, id := range param.Ids {
|
||||
var comicsDetail laosiji.ComicsDetailResp
|
||||
req := laosiji.ComicsDetailReq{
|
||||
Id: id,
|
||||
}
|
||||
comicsDetail, err = laosiji.ComicsDetail(ctx, req)
|
||||
if err != nil {
|
||||
log.Warn("ComicsAddList laosiji.ComicsDetail failed", log.Any("id", id), log.E(err))
|
||||
continue
|
||||
}
|
||||
// 处理域名
|
||||
//comicsDetail.Img = common.JoinUrlPath(laosiji.IMAGEYUAN, comicsDetail.Img)
|
||||
comicsDetail.Img = common.JoinUrlPath("laosiji", comicsDetail.Img)
|
||||
if comicsDetail.Chapter != nil && len(comicsDetail.Chapter) > 0 {
|
||||
for i, cha := range comicsDetail.Chapter {
|
||||
if len(cha.Img) > 0 {
|
||||
comicsDetail.Chapter[i].Img = common.JoinUrlPath("laosiji", comicsDetail.Chapter[i].Img)
|
||||
}
|
||||
if cha.Content != nil && len(cha.Content) > 0 {
|
||||
for y, content := range cha.Content {
|
||||
comicsDetail.Chapter[i].Content[y].F = common.JoinUrlPath("laosiji", content.F)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
comicsDetails = append(comicsDetails, comicsDetail)
|
||||
}
|
||||
if len(comicsDetails) <= 0 {
|
||||
log.Warn("ComicsAddList laosiji.ComicsDetailResp len is 0")
|
||||
err = errors.New("laosiji.ComicsDetailResp len is 0")
|
||||
return
|
||||
}
|
||||
// 批量处理标签
|
||||
tags := make(map[string]struct{})
|
||||
for _, comicsDetail := range comicsDetails {
|
||||
if comicsDetail.Tags != nil && len(comicsDetail.Tags) > 0 {
|
||||
for _, tag := range comicsDetail.Tags {
|
||||
tags[tag.Name] = struct{}{}
|
||||
}
|
||||
}
|
||||
}
|
||||
tagMaps := make(map[string]primitive.ObjectID)
|
||||
if len(tags) > 0 {
|
||||
tagList := make([]string, 0)
|
||||
for k, _ := range tags {
|
||||
tagList = append(tagList, k)
|
||||
}
|
||||
tagMaps, err = checkInsertMediaTag(tagList, 2)
|
||||
if err != nil {
|
||||
log.Error("ComicsAdd checkInsertMediaTag failed", log.E(err))
|
||||
return
|
||||
}
|
||||
}
|
||||
terms := vidser.LoadEnabledSensitiveTerms()
|
||||
hits = make([]vidser.SensitiveHit, 0)
|
||||
failedIds := make([]string, 0)
|
||||
for _, comicsDetail := range comicsDetails {
|
||||
hit, oneErr := syncOneComics(comicsDetail, tagMaps, manager, terms)
|
||||
if oneErr != nil {
|
||||
log.Warn("ComicsAdd syncOneComics failed", log.Any("id", comicsDetail.Id), log.E(oneErr))
|
||||
failedIds = append(failedIds, comicsDetail.Id)
|
||||
continue
|
||||
}
|
||||
if hit != nil {
|
||||
hits = append(hits, *hit)
|
||||
}
|
||||
}
|
||||
if len(failedIds) > 0 {
|
||||
err = errors.New(fmt.Sprintf("需要同步%d部漫画,失败%d,失败Id[%s]", len(param.Ids), len(failedIds), strings.Join(failedIds, ",")))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func syncOneComics(comicsDetail laosiji.ComicsDetailResp, tagMaps map[string]primitive.ObjectID, manager string, terms []string) (*vidser.SensitiveHit, error) {
|
||||
now := time.Now()
|
||||
mediaTemp, err := mediamod.GetListByLsjId(comicsDetail.Id)
|
||||
if err != nil {
|
||||
log.Warn("syncOneComics GetListByLsjId failed", log.Any("id", comicsDetail.Id), log.Any("err", err))
|
||||
return nil, err
|
||||
}
|
||||
if !mediaTemp.ID.IsZero() {
|
||||
return nil, nil
|
||||
}
|
||||
mediaTemp = mediamod.Media{
|
||||
ID: primitive.NewObjectID(),
|
||||
LsjId: comicsDetail.Id,
|
||||
Title: comicsDetail.Name,
|
||||
HorizontalCover: comicsDetail.Img,
|
||||
VerticalCover: comicsDetail.Img,
|
||||
Tags: make([]primitive.ObjectID, 0),
|
||||
TagDetails: make([]mediamod.TagDetail, 0),
|
||||
Summary: comicsDetail.Description,
|
||||
FreeEpisode: 0,
|
||||
CurrentEpisode: 0,
|
||||
MediaType: mediamod.MediaTypeImage,
|
||||
Kind: 5,
|
||||
PermissionIconHide: false,
|
||||
Permission: 2,
|
||||
Price: 0,
|
||||
ContentsPrice: 0,
|
||||
Status: 1,
|
||||
CreatedAt: now,
|
||||
UpdateTime: now,
|
||||
UpdatedAct: manager,
|
||||
}
|
||||
mediaTemp.TotalEpisode, _ = strconv.Atoi(comicsDetail.Chapter_count)
|
||||
mediaTemp.UpdateStatus, _ = strconv.Atoi(comicsDetail.Update_status)
|
||||
mediaTemp.Price, _ = strconv.ParseInt(comicsDetail.Money, 10, 64)
|
||||
if mediaTemp.Price > 0 {
|
||||
mediaTemp.Permission = 1
|
||||
}
|
||||
//if mediaTemp.UpdateStatus == 1 {
|
||||
// mediaTemp.UpdatedDesc = fmt.Sprintf("已完结%d话", mediaTemp.TotalEpisode)
|
||||
//} else {
|
||||
// mediaTemp.UpdatedDesc = fmt.Sprintf("更新至%d话", mediaTemp.TotalEpisode)
|
||||
//}
|
||||
for _, tag := range comicsDetail.Tags {
|
||||
if v, ok := tagMaps[tag.Name]; ok {
|
||||
mediaTemp.TagDetails = append(mediaTemp.TagDetails, mediamod.TagDetail{
|
||||
Id: v,
|
||||
Name: tag.Name,
|
||||
})
|
||||
mediaTemp.Tags = append(mediaTemp.Tags, v)
|
||||
}
|
||||
}
|
||||
contents := make([]mediacontentmod.MediaContent, 0)
|
||||
if len(comicsDetail.Chapter) > 0 {
|
||||
for i, chapter := range comicsDetail.Chapter {
|
||||
mediaContent := mediacontentmod.MediaContent{
|
||||
ID: primitive.NewObjectID(),
|
||||
MediaID: mediaTemp.ID,
|
||||
EpisodeNumber: i + 1,
|
||||
ListenPermission: mediaTemp.Permission,
|
||||
Price: mediaTemp.Price,
|
||||
Name: fmt.Sprintf("第%d话", i+1),
|
||||
Text: "",
|
||||
Md5: "",
|
||||
VideoUrl: "",
|
||||
UrlSet: make([]string, 0),
|
||||
Status: 1,
|
||||
IsActive: true,
|
||||
UpdatedAct: manager,
|
||||
CreatedAt: now,
|
||||
UpdateTime: now,
|
||||
HashId: chapter.Id,
|
||||
}
|
||||
mediaContent.Height, _ = strconv.Atoi(chapter.Content[0].H)
|
||||
mediaContent.Weight, _ = strconv.Atoi(chapter.Content[0].W)
|
||||
if chapter.Content != nil && len(chapter.Content) > 0 {
|
||||
for _, content := range chapter.Content {
|
||||
mediaContent.UrlSet = append(mediaContent.UrlSet, content.F)
|
||||
}
|
||||
}
|
||||
contents = append(contents, mediaContent)
|
||||
}
|
||||
}
|
||||
mediaTemp.CurrentEpisode = len(contents)
|
||||
// 敏感词命中 → 强制下架(Status=0)
|
||||
hit := vidser.CheckTextHits(terms, comicsDetail.Id, mediaTemp.Title, mediaTemp.Summary, "")
|
||||
if hit != nil {
|
||||
mediaTemp.Status = 0
|
||||
log.Warn("syncOneComics sensitive hit, forced offline",
|
||||
log.Any("sourceId", hit.SourceID),
|
||||
log.Any("title", hit.Title),
|
||||
log.Any("detail", hit.Detail))
|
||||
}
|
||||
_, err = mediamod.Insert(nil, mediaTemp)
|
||||
if err != nil {
|
||||
log.Warn("syncOneComics InsertMedia failed", log.Any("media", mediaTemp.ID), log.E(err))
|
||||
return nil, err
|
||||
}
|
||||
if len(contents) > 0 {
|
||||
_ = mediacontentmod.InsetBatch(nil, contents)
|
||||
}
|
||||
return hit, nil
|
||||
}
|
||||
Reference in New Issue
Block a user