mirror of
https://github.com/ProudMuBai/GoFilm.git
synced 2026-02-18 16:44:41 +08:00
optimize player
This commit is contained in:
@@ -49,14 +49,14 @@ const (
|
||||
const (
|
||||
|
||||
// SearchTableName 存放检索信息的数据表名
|
||||
SearchTableName = "search"
|
||||
SearchTableName = "search_mt"
|
||||
|
||||
//mysql服务配置信息 root:root 设置mysql账户的用户名和密码
|
||||
|
||||
//MysqlDsn = "root:root@(192.168.20.10:3307)/FilmSite?charset=utf8mb4&parseTime=True&loc=Local"
|
||||
MysqlDsn = "root:root@(192.168.20.10:3307)/FilmSite?charset=utf8mb4&parseTime=True&loc=Local"
|
||||
|
||||
// MysqlDsn docker compose 环境下的链接信息 mysql:3306 为 docker compose 中 mysql服务对应的网络名称和端口
|
||||
MysqlDsn = "root:root@(mysql:3306)/FilmSite?charset=utf8mb4&parseTime=True&loc=Local"
|
||||
//MysqlDsn = "root:root@(mysql:3306)/FilmSite?charset=utf8mb4&parseTime=True&loc=Local"
|
||||
|
||||
/*
|
||||
redis 配置信息
|
||||
@@ -64,12 +64,12 @@ const (
|
||||
RedisPassword redis访问密码
|
||||
RedisDBNo 使用第几号库
|
||||
*/
|
||||
//RedisAddr = `192.168.20.10:6379`
|
||||
//RedisPassword = `root`
|
||||
//RedisDBNo = 1
|
||||
RedisAddr = `192.168.20.10:6379`
|
||||
RedisPassword = `root`
|
||||
RedisDBNo = 1
|
||||
|
||||
// RedisAddr docker compose 环境下运行使用如下配置信息
|
||||
RedisAddr = `redis:6379`
|
||||
RedisPassword = `root`
|
||||
RedisDBNo = 0
|
||||
//RedisAddr = `redis:6379`
|
||||
//RedisPassword = `root`
|
||||
//RedisDBNo = 0
|
||||
)
|
||||
|
||||
@@ -2,11 +2,9 @@ package controller
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"log"
|
||||
"net/http"
|
||||
"server/config"
|
||||
"server/model"
|
||||
"server/plugin/spider"
|
||||
"server/logic"
|
||||
)
|
||||
|
||||
// SpiderRe 数据清零重开
|
||||
@@ -20,8 +18,7 @@ func SpiderRe(c *gin.Context) {
|
||||
})
|
||||
return
|
||||
}
|
||||
// 如果指令正确,则执行重制
|
||||
spider.StartSpiderRe()
|
||||
logic.SL.ReZero()
|
||||
}
|
||||
|
||||
// FixFilmDetail 修复因网络异常造成的影片详情数据丢失
|
||||
@@ -36,11 +33,22 @@ func FixFilmDetail(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
// 如果指令正确,则执行详情数据获取
|
||||
spider.MainSiteSpider()
|
||||
log.Println("FilmDetail 重制完成!!!")
|
||||
// 先截断表中的数据
|
||||
model.TunCateSearchTable()
|
||||
// 重新扫描完整的信息到mysql中
|
||||
spider.SearchInfoToMdb()
|
||||
log.Println("SearchInfo 重制完成!!!")
|
||||
logic.SL.FixDetail()
|
||||
}
|
||||
|
||||
// RefreshSitePlay 清空附属站点影片数据并重新获取
|
||||
func RefreshSitePlay(c *gin.Context) {
|
||||
// 获取指令参数
|
||||
cip := c.Query("cipher")
|
||||
if cip != config.SpiderCipher {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"status": StatusFailed,
|
||||
"message": "指令错误无法进行此操作",
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 执行多站点播放数据重置
|
||||
logic.SL.SpiderMtPlayRe()
|
||||
|
||||
}
|
||||
|
||||
44
server/logic/SpiderLogic.go
Normal file
44
server/logic/SpiderLogic.go
Normal file
@@ -0,0 +1,44 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"server/config"
|
||||
"server/model"
|
||||
"server/plugin/spider"
|
||||
)
|
||||
|
||||
type SpiderLogic struct {
|
||||
}
|
||||
|
||||
var SL *SpiderLogic
|
||||
|
||||
// ReZero 清空所有数据从零开始拉取
|
||||
func (sl *SpiderLogic) ReZero() {
|
||||
// 如果指令正确,则执行重制
|
||||
spider.StartSpiderRe()
|
||||
}
|
||||
|
||||
// FixDetail 重新获取主站点数据信息
|
||||
func (sl *SpiderLogic) FixDetail() {
|
||||
spider.MainSiteSpider()
|
||||
log.Println("FilmDetail 重制完成!!!")
|
||||
// 先截断表中的数据
|
||||
model.TunCateSearchTable()
|
||||
// 重新扫描完整的信息到mysql中
|
||||
spider.SearchInfoToMdb()
|
||||
log.Println("SearchInfo 重制完成!!!")
|
||||
}
|
||||
|
||||
// SpiderMtPlayRe 多站点播放数据清空重新获取
|
||||
func (sl *SpiderLogic) SpiderMtPlayRe() {
|
||||
// 先清空有所附加播放源
|
||||
var keys []string
|
||||
for _, site := range spider.SiteList {
|
||||
keys = append(keys, fmt.Sprintf(config.MultipleSiteDetail, site.Name))
|
||||
}
|
||||
model.DelMtPlay(keys)
|
||||
// 如果指令正确,则执行详情数据获取
|
||||
spider.MtSiteSpider()
|
||||
log.Println("MtSiteSpider 重制完成!!!")
|
||||
}
|
||||
@@ -89,6 +89,11 @@ func RemoveAll() {
|
||||
db.Mdb.Exec(fmt.Sprintf(`drop table if exists %s`, s.TableName()))
|
||||
}
|
||||
|
||||
// DelMtPlay 清空附加播放源信息
|
||||
func DelMtPlay(keys []string) {
|
||||
db.Rdb.Del(db.Cxt, keys...)
|
||||
}
|
||||
|
||||
// ================================= Spider 数据处理(mysql) =================================
|
||||
|
||||
// CreateSearchTable 创建存储检索信息的数据表
|
||||
@@ -211,12 +216,12 @@ func SearchFilmKeyword(keyword string, page *Page) []SearchInfo {
|
||||
var searchList []SearchInfo
|
||||
// 1. 先统计搜索满足条件的数据量
|
||||
var count int64
|
||||
db.Mdb.Model(&SearchInfo{}).Where("name LIKE ?", fmt.Sprint(`%`, keyword, `%`)).Count(&count)
|
||||
db.Mdb.Model(&SearchInfo{}).Where("name LIKE ?", fmt.Sprint(`%`, keyword, `%`)).Or("sub_title LIKE ?", fmt.Sprint(`%`, keyword, `%`)).Count(&count)
|
||||
page.Total = int(count)
|
||||
page.PageCount = int((page.Total + page.PageSize - 1) / page.PageSize)
|
||||
// 2. 获取满足条件的数据
|
||||
db.Mdb.Limit(page.PageSize).Offset((page.Current-1)*page.PageSize).
|
||||
Where("name LIKE ?", fmt.Sprint(`%`, keyword, `%`)).Order("year DESC, time DESC").Find(&searchList)
|
||||
Where("name LIKE ?", fmt.Sprint(`%`, keyword, `%`)).Or("sub_title LIKE ?", fmt.Sprint(`%`, keyword, `%`)).Order("year DESC, time DESC").Find(&searchList)
|
||||
return searchList
|
||||
}
|
||||
|
||||
@@ -259,7 +264,7 @@ func GetRelateMovieBasicInfo(search SearchInfo, page *Page) []MovieBasicInfo {
|
||||
re := regexp.MustCompile("第.{1,3}季")
|
||||
if re.MatchString(search.Name) {
|
||||
search.Name = re.ReplaceAllString(search.Name, "")
|
||||
sql = fmt.Sprintf(`select * from %s where name LIKE "%%%s%%" union`, search.TableName(), search.Name)
|
||||
sql = fmt.Sprintf(`select * from %s where name LIKE "%%%s%%" or sub_title LIKE "%%%[2]s%%" union`, search.TableName(), search.Name)
|
||||
}
|
||||
// 执行后续匹配内容
|
||||
//sql = fmt.Sprintf(`%s select * from %s where cid=%d AND area="%s" AND language="%s" AND`, sql, search.TableName(), search.Cid, search.Area, search.Language)
|
||||
|
||||
@@ -24,7 +24,7 @@ func InitMysql() (err error) {
|
||||
SingularTable: true, //是否使用 结构体名称作为表名 (关闭自动变复数)
|
||||
//NameReplacer: strings.NewReplacer("spider_", ""), // 替表名和字段中的 Me 为 空
|
||||
},
|
||||
//Logger: logger.Default.LogMode(logger.Info), //设置日志级别为Info
|
||||
//Logger: logger.Default.LogMode(logger.Info), //设置日志级别为Info
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
@@ -27,6 +27,7 @@ import (
|
||||
3. api数据格式不变, 获取影片详情时通过subTitle 去redis匹配其他站点的对应播放源并整合到主站详情信息的playUrl中
|
||||
4. 影片搜索时不再使用name进行匹配, 改为使用 subTitle 进行匹配
|
||||
*/
|
||||
|
||||
const (
|
||||
MainSite = "https://www.feisuzyapi.com/api.php/provide/vod/"
|
||||
)
|
||||
@@ -40,10 +41,11 @@ type Site struct {
|
||||
var SiteList = []Site{
|
||||
//{"tk", "https://api.tiankongapi.com/api.php/provide/vod"},
|
||||
//{"yh", "https://m3u8.apiyhzy.com/api.php/provide/vod/"},
|
||||
{"su", "https://subocaiji.com/api.php/provide/vod/at/json"},
|
||||
//{"fs", "https://www.feisuzyapi.com/api.php/provide/vod/"},
|
||||
|
||||
{"lz", "https://cj.lziapi.com/api.php/provide/vod/"},
|
||||
{"ff", "https://cj.ffzyapi.com/api.php/provide/vod/"},
|
||||
//{"fs", "https://www.feisuzyapi.com/api.php/provide/vod/"},
|
||||
{"su", "https://subocaiji.com/api.php/provide/vod/at/json"},
|
||||
}
|
||||
|
||||
// StartSpider 执行多源spider
|
||||
@@ -249,7 +251,7 @@ func UpdateMainDetail() {
|
||||
func UpdatePlayDetail() {
|
||||
for _, s := range SiteList {
|
||||
// 获取单个站点的分页数
|
||||
r := RequestInfo{Uri: MainSite, Params: url.Values{}}
|
||||
r := RequestInfo{Uri: s.Name, Params: url.Values{}}
|
||||
r.Params.Set("h", config.UpdateInterval)
|
||||
pageCount, err := GetPageCount(r)
|
||||
if err != nil {
|
||||
|
||||
@@ -27,6 +27,7 @@ func SetupRouter() *gin.Engine {
|
||||
spiderRoute.GET("/SpiderRe", controller.SpiderRe)
|
||||
// 获取影片详情, 用于网路不稳定导致的影片数据缺失
|
||||
spiderRoute.GET(`/FixFilmDetail`, controller.FixFilmDetail)
|
||||
spiderRoute.GET(`/RefreshSitePlay`, controller.RefreshSitePlay)
|
||||
}
|
||||
|
||||
return r
|
||||
|
||||
Reference in New Issue
Block a user