1
0
Эх сурвалжийг харах

新增,手动搜索字幕,关键词获取接口

Signed-off-by: allan716 <[email protected]>
allan716 3 жил өмнө
parent
commit
dc597593d2

+ 0 - 2
cmd/chinesesubfinder/main.go

@@ -2,7 +2,6 @@ package main
 
 import (
 	"flag"
-	"fmt"
 	"path/filepath"
 	"strings"
 	"time"
@@ -176,7 +175,6 @@ func main() {
 	}
 
 	nowPort := pkg.ReadCustomPortFile(loggerBase)
-	loggerBase.Infoln(fmt.Sprintf("WebUI will listen at 0.0.0.0:%d", nowPort))
 	// 支持在外部配置特殊的端口号,以防止本地本占用了无法使用
 	restartSignal := make(chan interface{}, 1)
 	defer close(restartSignal)

+ 1 - 1
go.mod

@@ -69,6 +69,7 @@ require (
 require (
 	github.com/allanpk716/is_running_in_docker v0.0.1
 	github.com/araddon/dateparse v0.0.0-20210429162001-6b43995a97de
+	github.com/arl/statsviz v0.5.1
 	github.com/cyruzin/golang-tmdb v1.4.4
 	github.com/elazarl/goproxy v0.0.0-20220417044921-416226498f94
 	github.com/longbridgeapp/opencc v0.1.7
@@ -85,7 +86,6 @@ require (
 	github.com/acomagu/bufpipe v1.0.3 // indirect
 	github.com/andybalholm/brotli v1.0.0 // indirect
 	github.com/andybalholm/cascadia v1.2.0 // indirect
-	github.com/arl/statsviz v0.5.1 // indirect
 	github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310 // indirect
 	github.com/bodgit/plumbing v1.1.0 // indirect
 	github.com/bodgit/windows v1.0.0 // indirect

+ 2 - 1
go.sum

@@ -524,8 +524,9 @@ github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6So
 github.com/rogpeppe/go-charset v0.0.0-20180617210344-2471d30d28b4/go.mod h1:qgYeAmZ5ZIpBWTGllZSQnw97Dj+woV0toclVaRGI8pc=
 github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
 github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc=
-github.com/rogpeppe/go-internal v1.8.0 h1:FCbCCtXNOY3UtUuHUYaghJg4y7Fd14rXifAYUAtL9R8=
 github.com/rogpeppe/go-internal v1.8.0/go.mod h1:WmiCO8CzOY8rg0OYDC4/i/2WRWAB6poM+XZ2dLUbcbE=
+github.com/rogpeppe/go-internal v1.8.1 h1:geMPLpDpQOgVyCg5z5GoRwLHepNdb71NXb67XFkP+Eg=
+github.com/rogpeppe/go-internal v1.8.1/go.mod h1:JeRgkft04UBgHMgCIwADu4Pn6Mtm5d4nPKWu0nJ5d+o=
 github.com/rs/xid v1.2.1/go.mod h1:+uKXf+4Djp6Md1KODXJxgGQPKngRmWyn10oCKFzNHOQ=
 github.com/rs/zerolog v1.21.0/go.mod h1:ZPhntP/xmq1nnND05hhpAh2QMhSsA4UN3MGZ6O2J3hM=
 github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=

+ 1 - 0
internal/backend/base_router.go

@@ -136,6 +136,7 @@ func InitRouter(
 		GroupV1.POST("/preview/clean_up", cbV1.PreviewCleanUp)
 		GroupV1.GET("/preview/playlist/:videofpathbase64", cbV1.HlsPlaylist)
 		GroupV1.GET("/preview/segments/:resolution/:segment/:videofpathbase64", cbV1.HlsSegment)
+		GroupV1.POST("/preview/search_other_web", cbV1.PreviewSearchOtherWeb)
 
 	}
 

+ 99 - 0
internal/backend/controllers/v1/preview.go

@@ -1,6 +1,12 @@
 package v1
 
 import (
+	"fmt"
+	"github.com/Tnze/go.num/v2/zh"
+	"github.com/allanpk716/ChineseSubFinder/pkg/mix_media_info"
+	"github.com/allanpk716/ChineseSubFinder/pkg/settings"
+	"github.com/jinzhu/now"
+	PTN "github.com/middelink/go-parse-torrent-name"
 	"net/http"
 	"strconv"
 
@@ -149,3 +155,96 @@ func (cb *ControllerBase) PreviewCleanUp(c *gin.Context) {
 	c.JSON(http.StatusOK, backend2.ReplyCommon{Message: "true"})
 	return
 }
+
+func (cb *ControllerBase) PreviewSearchOtherWeb(c *gin.Context) {
+	var err error
+	defer func() {
+		// 统一的异常处理
+		cb.ErrorProcess(c, "PreviewSearchOtherWeb", err)
+	}()
+
+	searchOtherWeb := SearchOtherWebReq{}
+	err = c.ShouldBindJSON(&searchOtherWeb)
+	if err != nil {
+		return
+	}
+
+	if pkg.IsFile(searchOtherWeb.VideoFPath) == false {
+		c.JSON(http.StatusOK, backend2.ReplyCommon{Message: "video file not found"})
+		return
+	}
+
+	mixMediaInfo, err := mix_media_info.GetMixMediaInfo(cb.cronHelper.FileDownloader.MediaInfoDealers,
+		searchOtherWeb.VideoFPath, searchOtherWeb.IsMovie)
+	if err != nil {
+		return
+	}
+	// 搜索网站的地址
+	searchOtherWebReply := SearchOtherWebReply{}
+	searchOtherWebReply.SearchUrls = make([]string, 0)
+	searchOtherWebReply.SearchUrls = append(searchOtherWebReply.SearchUrls, settings.Get().AdvancedSettings.SuppliersSettings.Zimuku.GetSearchUrl())
+	searchOtherWebReply.SearchUrls = append(searchOtherWebReply.SearchUrls, settings.Get().AdvancedSettings.SuppliersSettings.SubHD.GetSearchUrl())
+	searchOtherWebReply.SearchUrls = append(searchOtherWebReply.SearchUrls, settings.Get().AdvancedSettings.SuppliersSettings.A4k.GetSearchUrl())
+
+	year, err := now.Parse(mixMediaInfo.Year)
+	if err != nil {
+		return
+	}
+	strYear := fmt.Sprintf("%d", year.Year())
+	// 返回多种关键词
+	searchOtherWebReply.KeyWords = make([]string, 0)
+	// imdb id
+	searchOtherWebReply.KeyWords = append(searchOtherWebReply.KeyWords, mixMediaInfo.ImdbId)
+
+	if searchOtherWeb.IsMovie == true {
+		// 电影
+		searchOtherWebReply.KeyWords = append(searchOtherWebReply.KeyWords, mixMediaInfo.TitleCn)
+		searchOtherWebReply.KeyWords = append(searchOtherWebReply.KeyWords, mixMediaInfo.TitleCn+" "+strYear)
+		if mixMediaInfo.TitleCn != mixMediaInfo.TitleEn {
+			searchOtherWebReply.KeyWords = append(searchOtherWebReply.KeyWords, mixMediaInfo.TitleEn)
+			searchOtherWebReply.KeyWords = append(searchOtherWebReply.KeyWords, mixMediaInfo.TitleEn+" "+strYear)
+		}
+		if mixMediaInfo.TitleCn != mixMediaInfo.OriginalTitle && mixMediaInfo.OriginalTitle != mixMediaInfo.TitleEn {
+			searchOtherWebReply.KeyWords = append(searchOtherWebReply.KeyWords, mixMediaInfo.OriginalTitle)
+			searchOtherWebReply.KeyWords = append(searchOtherWebReply.KeyWords, mixMediaInfo.OriginalTitle+" "+strYear)
+		}
+	} else {
+		// 电视剧
+		var ptn *PTN.TorrentInfo
+		ptn, err = decode.GetVideoInfoFromFileName(searchOtherWeb.VideoFPath)
+		if err != nil {
+			return
+		}
+		seasonKeyWord0 := " 第" + zh.Uint64(ptn.Season).String() + "季"
+		seasonKeyWord1 := fmt.Sprintf(" S%02d", ptn.Season)
+		seasonKeyWord2 := " " + pkg.GetEpisodeKeyName(ptn.Season, ptn.Episode, true)
+		searchOtherWebReply.KeyWords = append(searchOtherWebReply.KeyWords, mixMediaInfo.TitleCn)
+		searchOtherWebReply.KeyWords = append(searchOtherWebReply.KeyWords, mixMediaInfo.TitleCn+seasonKeyWord0)
+		searchOtherWebReply.KeyWords = append(searchOtherWebReply.KeyWords, mixMediaInfo.TitleCn+seasonKeyWord1)
+		searchOtherWebReply.KeyWords = append(searchOtherWebReply.KeyWords, mixMediaInfo.TitleCn+seasonKeyWord2)
+		if mixMediaInfo.TitleCn != mixMediaInfo.TitleEn {
+			searchOtherWebReply.KeyWords = append(searchOtherWebReply.KeyWords, mixMediaInfo.TitleEn)
+			searchOtherWebReply.KeyWords = append(searchOtherWebReply.KeyWords, mixMediaInfo.TitleEn+seasonKeyWord0)
+			searchOtherWebReply.KeyWords = append(searchOtherWebReply.KeyWords, mixMediaInfo.TitleEn+seasonKeyWord1)
+			searchOtherWebReply.KeyWords = append(searchOtherWebReply.KeyWords, mixMediaInfo.TitleEn+seasonKeyWord2)
+		}
+		if mixMediaInfo.TitleCn != mixMediaInfo.OriginalTitle && mixMediaInfo.OriginalTitle != mixMediaInfo.TitleEn {
+			searchOtherWebReply.KeyWords = append(searchOtherWebReply.KeyWords, mixMediaInfo.OriginalTitle)
+			searchOtherWebReply.KeyWords = append(searchOtherWebReply.KeyWords, mixMediaInfo.OriginalTitle+seasonKeyWord0)
+			searchOtherWebReply.KeyWords = append(searchOtherWebReply.KeyWords, mixMediaInfo.OriginalTitle+seasonKeyWord1)
+			searchOtherWebReply.KeyWords = append(searchOtherWebReply.KeyWords, mixMediaInfo.OriginalTitle+seasonKeyWord2)
+		}
+	}
+
+	c.JSON(http.StatusOK, searchOtherWebReply)
+}
+
+type SearchOtherWebReq struct {
+	VideoFPath string `json:"video_f_path"`
+	IsMovie    bool   `json:"is_movie"`
+}
+
+type SearchOtherWebReply struct {
+	KeyWords   []string `json:"key_words"`
+	SearchUrls []string `json:"search_url"`
+}

+ 1 - 0
pkg/imdb_helper/imdb.go

@@ -32,6 +32,7 @@ func GetIMDBInfoFromVideoFile(dealers *media_info_dealers.Dealers, videoFPath st
 		dealers.Logger.Warningln("getSubListFromFile", videoFPath, err)
 		return nil, err
 	}
+	// 这里一定会保存本地的 IMDB 信息
 	imdbInfo, err := GetIMDBInfoFromVideoNfoInfo(dealers, videoNfoInfo)
 	if err != nil {
 		dealers.Logger.Warningln("GetIMDBInfoFromVideoNfoInfo", videoFPath, err)

+ 1 - 1
pkg/mix_media_info/mix_media_info.go

@@ -19,7 +19,7 @@ import (
 func GetMixMediaInfo(
 	dealers *media_info_dealers.Dealers,
 	videoFPath string, isMovie bool) (*models.MediaInfo, error) {
-
+	// 从本地读取 IMDB ID 信息,找到基本 ID 信息后,也会去 IMDB web 找到对应的额外信息填充
 	imdbInfo, err := imdb_helper.GetIMDBInfoFromVideoFile(dealers, videoFPath, isMovie)
 	if err != nil {
 		return nil, err

+ 14 - 9
pkg/settings/supplier_settings.go

@@ -16,22 +16,27 @@ type SuppliersSettings struct {
 
 func NewSuppliersSettings() *SuppliersSettings {
 	return &SuppliersSettings{
-		ChineseSubFinder: NewOneSupplierSettings(common.SubSiteChineseSubFinder, "haha", -1),
-		Xunlei:           NewOneSupplierSettings(common.SubSiteXunLei, common.SubXunLeiRootUrlDef, -1),
-		Shooter:          NewOneSupplierSettings(common.SubSiteShooter, common.SubShooterRootUrlDef, -1),
-		SubHD:            NewOneSupplierSettings(common.SubSiteSubHd, common.SubSubHDRootUrlDef, 20),
-		Zimuku:           NewOneSupplierSettings(common.SubSiteZiMuKu, common.SubZiMuKuRootUrlDef, 20),
-		Assrt:            NewOneSupplierSettings(common.SubSiteAssrt, common.SubAssrtRootUrlDef, -1),
-		A4k:              NewOneSupplierSettings(common.SubSiteA4K, common.SubA4kRootUrlDef, -1),
+		ChineseSubFinder: NewOneSupplierSettings(common.SubSiteChineseSubFinder, "haha", "haha", -1),
+		Xunlei:           NewOneSupplierSettings(common.SubSiteXunLei, common.SubXunLeiRootUrlDef, "", -1),
+		Shooter:          NewOneSupplierSettings(common.SubSiteShooter, common.SubShooterRootUrlDef, "", -1),
+		SubHD:            NewOneSupplierSettings(common.SubSiteSubHd, common.SubSubHDRootUrlDef, common.SubSubHDSearchUrl, 20),
+		Zimuku:           NewOneSupplierSettings(common.SubSiteZiMuKu, common.SubZiMuKuRootUrlDef, common.SubZiMuKuSearchFormatUrl, 20),
+		Assrt:            NewOneSupplierSettings(common.SubSiteAssrt, common.SubAssrtRootUrlDef, "", -1),
+		A4k:              NewOneSupplierSettings(common.SubSiteA4K, common.SubA4kRootUrlDef, common.SubA4kSearchUrl, -1),
 	}
 }
 
 type OneSupplierSettings struct {
 	Name               string `json:"name"`
 	RootUrl            string `json:"root_url"`
+	SearchUrl          string `json:"search_url"`
 	DailyDownloadLimit int    `json:"daily_download_limit" default:"-1"` // -1 是无限制
 }
 
-func NewOneSupplierSettings(name string, rootUrl string, dailyDownloadLimit int) *OneSupplierSettings {
-	return &OneSupplierSettings{Name: name, RootUrl: rootUrl, DailyDownloadLimit: dailyDownloadLimit}
+func NewOneSupplierSettings(name string, rootUrl, searchUrl string, dailyDownloadLimit int) *OneSupplierSettings {
+	return &OneSupplierSettings{Name: name, RootUrl: rootUrl, SearchUrl: searchUrl, DailyDownloadLimit: dailyDownloadLimit}
+}
+
+func (s *OneSupplierSettings) GetSearchUrl() string {
+	return s.RootUrl + s.SearchUrl
 }

+ 1 - 0
pkg/types/common/urls.go

@@ -13,4 +13,5 @@ const (
 	SubAssrtRootUrlDef = "https://api.assrt.net/v1"
 
 	SubA4kRootUrlDef = "https://www.a4k.net"
+	SubA4kSearchUrl  = "/search?term="
 )