Browse Source

正在研究怎么从 tvdb 拿到中文信息,然后在去对应的字幕网站查找,这样能避免命名问题

Signed-off-by: 716 <[email protected]>
716 4 years ago
parent
commit
9c3fa1716b
11 changed files with 80 additions and 12 deletions
  1. 1 0
      .gitignore
  2. 3 0
      common/urls.go
  3. 2 1
      common/videoInfo.go
  4. 2 1
      config.yaml.sample
  5. 1 0
      go.mod
  6. 2 0
      go.sum
  7. 2 2
      main.go
  8. 1 1
      model/config.go
  9. 7 7
      model/decode.go
  10. 36 0
      model/tvdb.go
  11. 23 0
      model/tvdb_test.go

+ 1 - 0
.gitignore

@@ -12,3 +12,4 @@
 /*.zip
 /*.rar
 /sub_supplier/subhd/Logs
+/model/config.yaml

+ 3 - 0
common/urls.go

@@ -9,4 +9,7 @@ const (
 
 	SubSubHDRootUrl  = "https://subhd.tv"
 	SubSubHDSearchUrl  = SubSubHDRootUrl + "/search/%s"
+
+	TVDBRootUrl = "https://thetvdb.com"
+	TVDBSearchUrl = TVDBRootUrl + "/search"
 )

+ 2 - 1
common/imdbInfo.go → common/videoInfo.go

@@ -1,7 +1,8 @@
 package common
 
-type ImdbInfo struct {
+type VideoInfo struct {
 	ImdbId string
+	TVdbId string
 	Year string
 	Title string
 	OriginalTitle string

+ 2 - 1
config.yaml.sample

@@ -4,4 +4,5 @@ EveryTime: 6h
 DebugMode: false
 SaveMultiSub: false
 FoundExistSubFileThanSkip: true
-MovieFolder: X:\电影
+MovieFolder: X:\电影
+TVdbApiKey: 123456

+ 1 - 0
go.mod

@@ -17,6 +17,7 @@ require (
 	github.com/mholt/archiver/v3 v3.5.0
 	github.com/middelink/go-parse-torrent-name v0.0.0-20190301154245-3ff4efacd4c4
 	github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646
+	github.com/pioz/tvdb v0.0.0-20200804122320-6d5b1ef61c13 // indirect
 	github.com/pkg/errors v0.9.1 // indirect
 	github.com/robfig/cron/v3 v3.0.0
 	github.com/saintfish/chardet v0.0.0-20120816061221-3af4cd4741ca

+ 2 - 0
go.sum

@@ -182,6 +182,8 @@ github.com/pelletier/go-toml v1.2.0 h1:T5zMGML61Wp+FlcbWjRDT7yAxhJNAiPPLOFECq181
 github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
 github.com/pierrec/lz4/v4 v4.0.3 h1:vNQKSVZNYUEAvRY9FaUXAF1XPbSOHJtDTiP41kzDz2E=
 github.com/pierrec/lz4/v4 v4.0.3/go.mod h1:gZWDp/Ze/IJXGXf23ltt2EXimqmTUXEy0GFuRQyBid4=
+github.com/pioz/tvdb v0.0.0-20200804122320-6d5b1ef61c13 h1:yqj2COB4SN6t3xmImSjnEAIvLeLKL3p4pi7CGknZvNc=
+github.com/pioz/tvdb v0.0.0-20200804122320-6d5b1ef61c13/go.mod h1:nhHRTrbEzdp4lXtiozX4Yuvo4AHi29nOvM1J7H/XJMM=
 github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
 github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
 github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=

+ 2 - 2
main.go

@@ -11,12 +11,12 @@ import (
 func init() {
 	var err error
 	log = model.GetLogger()
-	configViper, err = InitConfigure()
+	configViper, err = model.InitConfigure()
 	if err != nil {
 		log.Errorln("InitConfigure", err)
 		return 
 	}
-	config, err = ReadConfig(configViper)
+	config, err = model.ReadConfig(configViper)
 	if err != nil {
 		log.Errorln("ReadConfig", err)
 		return 

+ 1 - 1
config.go → model/config.go

@@ -1,4 +1,4 @@
-package main
+package model
 
 import (
 	"github.com/allanpk716/ChineseSubFinder/common"

+ 7 - 7
model/decode.go

@@ -13,9 +13,9 @@ import (
 	"strings"
 )
 
-func getImdbAndYearMovieXml(movieFilePath string) (common.ImdbInfo, error) {
+func getImdbAndYearMovieXml(movieFilePath string) (common.VideoInfo, error) {
 
-	videoInfo := common.ImdbInfo{}
+	videoInfo := common.VideoInfo{}
 	doc := etree.NewDocument()
 	if err := doc.ReadFromFile(movieFilePath); err != nil {
 		return videoInfo, err
@@ -34,9 +34,9 @@ func getImdbAndYearMovieXml(movieFilePath string) (common.ImdbInfo, error) {
 	return videoInfo, common.CanNotFindIMDBID
 }
 
-func getImdbAndYearNfo(nfoFilePath string) (common.ImdbInfo, error) {
-
-	imdbInfo := common.ImdbInfo{}
+func getImdbAndYearNfo(nfoFilePath string) (common.VideoInfo, error) {
+	// TODO 新增 TVDB ID 的读取
+	imdbInfo := common.VideoInfo{}
 	doc := etree.NewDocument()
 	// 这里会遇到一个梗,下面的关键词,可能是小写、大写、首字母大写
 	// 读取文件转换为全部的小写,然后在解析 xml ? etree 在转换为小写后,某些类型的文件的内容会崩溃···
@@ -67,9 +67,9 @@ func getImdbAndYearNfo(nfoFilePath string) (common.ImdbInfo, error) {
 	return imdbInfo, common.CanNotFindIMDBID
 }
 
-func GetImdbInfo(dirPth string) (common.ImdbInfo, error) {
+func GetImdbInfo(dirPth string) (common.VideoInfo, error) {
 
-	imdbInfo := common.ImdbInfo{}
+	imdbInfo := common.VideoInfo{}
 	dir, err := ioutil.ReadDir(dirPth)
 	if err != nil {
 		return imdbInfo, err

+ 36 - 0
model/tvdb.go

@@ -0,0 +1,36 @@
+package model
+
+import (
+	"github.com/allanpk716/ChineseSubFinder/common"
+	"github.com/go-resty/resty/v2"
+)
+
+type TVDB struct {
+	reqParam common.ReqParam
+	httpClient *resty.Client
+}
+
+// TODO 从 TVDB ID 查找对应的影片信息,得到中文名称,然后再去搜索字幕
+// 半泽直树 zho 半澤直樹 zhtw
+// 到了 list 列表搜索 zho ,第一个元素,然后找它的父级,获取 text 应该就能拿到中文名称了
+func NewTVDB(_reqParam ...common.ReqParam) *TVDB {
+	tv := TVDB{}
+	if len(_reqParam) > 0 {
+		tv.reqParam = _reqParam[0]
+	}
+	tv.httpClient = NewHttpClient(tv.reqParam)
+	return &tv
+}
+
+func (t TVDB) SearchAndGetChineseName() error {
+	resp, err := t.httpClient.R().
+		SetQueryParams(map[string]string{
+			"query": ,
+		}).
+		Get(common.TVDBSearchUrl)
+	if err != nil {
+		return err
+	}
+	println(resp)
+	return nil
+}

+ 23 - 0
model/tvdb_test.go

@@ -0,0 +1,23 @@
+package model
+
+import (
+	"testing"
+)
+
+func TestNewTVDB(t *testing.T) {
+
+	configViper, err := InitConfigure()
+	if err != nil {
+		t.Fatal(err)
+	}
+	c, err := ReadConfig(configViper)
+	if err != nil {
+		t.Fatal(err)
+	}
+
+	tv := NewTVDB(c.TVdbApiKey)
+	err = tv.login()
+	if err != nil {
+		t.Fatal(err)
+	}
+}