Browse Source

新增了 IMDB 的查询接口

Signed-off-by: 716 <[email protected]>
716 4 years ago
parent
commit
fb81b47bc1
8 changed files with 91 additions and 27 deletions
  1. 1 0
      go.mod
  2. 5 0
      go.sum
  3. 16 0
      model/imdb.go
  4. 16 0
      model/imdb_test.go
  5. 16 0
      model/util.go
  6. 3 14
      sub_supplier/subhd/subhd.go
  7. 19 13
      sub_supplier/zimuku/zimuku.go
  8. 15 0
      sub_supplier/zimuku/zimuku_test.go

+ 1 - 0
go.mod

@@ -4,6 +4,7 @@ go 1.15
 
 require (
 	github.com/PuerkitoBio/goquery v1.6.1
+	github.com/StalkR/imdb v1.0.7
 	github.com/abadojack/whatlanggo v1.0.1
 	github.com/axgle/mahonia v0.0.0-20180208002826-3358181d7394
 	github.com/beevik/etree v1.1.0

+ 5 - 0
go.sum

@@ -17,6 +17,9 @@ github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym
 github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU=
 github.com/PuerkitoBio/goquery v1.6.1 h1:FgjbQZKl5HTmcn4sKBgvx8vv63nhyhIpv7lJpFGCWpk=
 github.com/PuerkitoBio/goquery v1.6.1/go.mod h1:GsLWisAFVj4WgDibEWF4pvYnkVQBpKBKeU+7zCJoLcc=
+github.com/StalkR/httpcache v1.0.0/go.mod h1:yvbaYwH6w1USHPqgspMSwumbLwWE+B7jIZgfLYkTw1M=
+github.com/StalkR/imdb v1.0.7 h1:T9ra3IObhWoNB2I2CNT6EFe8sTQH56adKJdEQi1q0Ig=
+github.com/StalkR/imdb v1.0.7/go.mod h1:nxQmP4/nGtTVICl2+UmwhCnosVwVClmksdyptjE5Lj8=
 github.com/abadojack/whatlanggo v1.0.1 h1:19N6YogDnf71CTHm3Mp2qhYfkRdyvbgwWdd2EPxJRG4=
 github.com/abadojack/whatlanggo v1.0.1/go.mod h1:66WiQbSbJBIlOZMsvbKe5m6pzQovxCH9B/K8tQB2uoc=
 github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
@@ -70,6 +73,8 @@ github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7a
 github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4=
 github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
 github.com/golang/groupcache v0.0.0-20190129154638-5b532d6fd5ef/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
+github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
+github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
 github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
 github.com/golang/mock v1.2.0/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
 github.com/golang/mock v1.3.1/go.mod h1:sBzyDLLjw3U8JLTeZvSv8jJB+tU5PVekmnlKIyFUx0Y=

+ 16 - 0
model/imdb.go

@@ -0,0 +1,16 @@
+package model
+
+import (
+	"github.com/StalkR/imdb"
+	"net/http"
+)
+
+// GetVideoInfoFromIMDB 从 IMDB ID 查询影片的信息
+func GetVideoInfoFromIMDB(imdbID string) (*imdb.Title, error) {
+	client := http.DefaultClient
+	t, err := imdb.NewTitle(client, imdbID)
+	if err != nil {
+		return nil, err
+	}
+	return t, nil
+}

+ 16 - 0
model/imdb_test.go

@@ -0,0 +1,16 @@
+package model
+
+import "testing"
+
+func TestGetVideoInfoFromIMDB(t *testing.T) {
+	//imdbID := "tt12708542" // 星球大战:残次品
+	//imdbID := "tt7016936"	// 杀死伊芙
+	//imdbID := "tt2990738" 	// 恐怖直播
+	//imdbID := "tt3032476" 	// 风骚律师
+	imdbID := "tt6468322" 	// 纸钞屋
+	imdbInfo, err := GetVideoInfoFromIMDB(imdbID)
+	if err != nil {
+		t.Fatal(err)
+	}
+	println(imdbInfo.Name, imdbInfo.Year, imdbInfo.ID)
+}

+ 16 - 0
model/util.go

@@ -10,6 +10,7 @@ import (
 	"os"
 	"path"
 	"regexp"
+	"strconv"
 	"strings"
 )
 
@@ -172,6 +173,21 @@ func IsDir(path string) bool {
 	return s.IsDir()
 }
 
+func VideoNameSearchKeywordMaker(title string, year string) string {
+	iYear, err := strconv.Atoi(year)
+	if err != nil {
+		// 允许的错误
+		GetLogger().Errorln("VideoNameSearchKeywordMaker", "year to int", err)
+		iYear = 0
+	}
+	searchKeyword := title
+	if iYear >= 2020 {
+		searchKeyword = searchKeyword + year
+	}
+
+	return searchKeyword
+}
+
 var (
 	defDebugFolder = ""
 	defTmpFolder = ""

+ 3 - 14
sub_supplier/subhd/subhd.go

@@ -81,22 +81,11 @@ func (s Supplier) GetSubListFromFile(filePath string) ([]common.SupplierSubInfo,
 		// 允许的错误,跳过,继续进行文件名的搜索
 		s.log.Errorln("model.GetImdbIdAndYear", err)
 	}
-	iYear, err := strconv.Atoi(year)
-	if err != nil {
-		// 允许的错误
-		s.log.Errorln("GetImdbIdAndYear", "year to int",err)
-		iYear = 0
-	}
-
 	var subInfoList []common.SupplierSubInfo
 
 	if imdbId != "" {
-		searchKeyword := imdbId
-		if iYear >= 2020 {
-			searchKeyword = searchKeyword + year
-		}
 		// 先用 imdb id 找
-		subInfoList, err = s.GetSubListFromKeyword(searchKeyword)
+		subInfoList, err = s.GetSubListFromKeyword(imdbId)
 		if err != nil {
 			// 允许的错误,跳过,继续进行文件名的搜索
 			s.log.Errorln("GetSubListFromKeyword", "IMDBID can not found sub", filePath, err)
@@ -106,9 +95,9 @@ func (s Supplier) GetSubListFromFile(filePath string) ([]common.SupplierSubInfo,
 			return subInfoList, nil
 		}
 	}
-
 	// 如果没有,那么就用文件名查找
-	subInfoList, err = s.GetSubListFromKeyword(info.Title)
+	searchKeyword := model.VideoNameSearchKeywordMaker(info.Title, year)
+	subInfoList, err = s.GetSubListFromKeyword(searchKeyword)
 	if err != nil {
 		return nil, err
 	}

+ 19 - 13
sub_supplier/zimuku/zimuku.go

@@ -9,7 +9,6 @@ import (
 	"path/filepath"
 	"regexp"
 	"sort"
-	"strconv"
 	"strings"
 )
 
@@ -42,7 +41,23 @@ func (s Supplier) GetSubListFromFile4Movie(filePath string) ([]common.SupplierSu
 }
 
 func (s Supplier) GetSubListFromFile4Series(seriesPath string) ([]common.SupplierSubInfo, error) {
+	// 只考虑 IMDB 去查询,文件名目前发现可能会跟电影重复,导致很麻烦,本来也有前置要求要削刮器处理的
+	// TODO !GetImdbIdAndYear 需要输出 title 以及 originaltitle
+	imdbId, _, err := model.GetImdbIdAndYear(seriesPath)
+	if err != nil {
+		return nil, err
+	}
+	// 使用 IMDB 去
+	imdbInfo, err := model.GetVideoInfoFromIMDB(imdbId)
+	if err != nil {
+		return nil, err
+	}
+	subInfoList, err := s.GetSubListFromKeyword(imdbInfo.Name)
+	if err != nil {
+		return nil, err
+	}
 
+	return subInfoList, nil
 }
 
 func (s Supplier) GetSubListFromFile4Anime(animePath string) ([]common.SupplierSubInfo, error){
@@ -71,21 +86,11 @@ func (s Supplier) GetSubListFromFile(filePath string) ([]common.SupplierSubInfo,
 		// 允许的错误,跳过,继续进行文件名的搜索
 		s.log.Errorln("model.GetImdbIdAndYear", err)
 	}
-	iYear, err := strconv.Atoi(year)
-	if err != nil {
-		// 允许的错误
-		s.log.Errorln("GetImdbIdAndYear", "year to int",err)
-		iYear = 0
-	}
 	var subInfoList []common.SupplierSubInfo
 
 	if imdbId != "" {
-		searchKeyword := imdbId
-		if iYear >= 2020 {
-			searchKeyword = searchKeyword + year
-		}
 		// 先用 imdb id 找
-		subInfoList, err = s.GetSubListFromKeyword(searchKeyword)
+		subInfoList, err = s.GetSubListFromKeyword(imdbId)
 		if err != nil {
 			// 允许的错误,跳过,继续进行文件名的搜索
 			s.log.Errorln("GetSubListFromKeyword", "IMDBID can not found sub", filePath, err)
@@ -97,7 +102,8 @@ func (s Supplier) GetSubListFromFile(filePath string) ([]common.SupplierSubInfo,
 	}
 
 	// 如果没有,那么就用文件名查找
-	subInfoList, err = s.GetSubListFromKeyword(info.Title)
+	searchKeyword := model.VideoNameSearchKeywordMaker(info.Title, year)
+	subInfoList, err = s.GetSubListFromKeyword(searchKeyword)
 	if err != nil {
 		return nil, err
 	}

+ 15 - 0
sub_supplier/zimuku/zimuku_test.go

@@ -36,4 +36,19 @@ func TestSupplier_GetSubListFromFile(t *testing.T) {
 	for i, sublist := range outList {
 		println(i, sublist.Name, sublist.Ext, sublist.Language.String(), sublist.Score, len(sublist.Data))
 	}
+}
+
+func TestSupplier_GetSubListFromFile4Series(t *testing.T) {
+
+	//ser := "X:\\连续剧\\The Bad Batch"	// tt12708542
+	ser := "X:\\连续剧\\杀死伊芙 (2018)"	// tt12708542
+	s := NewSupplier()
+	outList, err := s.GetSubListFromFile4Series(ser)
+	if err != nil {
+		t.Error(err)
+	}
+	println(outList)
+	for i, sublist := range outList {
+		println(i, sublist.Name, sublist.Ext, sublist.Language.String(), sublist.Score, len(sublist.Data))
+	}
 }