Преглед на файлове

添加 tmdb 转 imdb 的查询接口

Signed-off-by: allan716 <[email protected]>
allan716 преди 3 години
родител
ревизия
9482b0e0f4
променени са 3 файла, в които са добавени 71 реда и са изтрити 5 реда
  1. 13 0
      pkg/subtitle_best_api/media_info.go
  2. 45 0
      pkg/subtitle_best_api/subtitle_best_api.go
  3. 13 5
      pkg/subtitle_best_api/subtitle_best_api_test.go

+ 13 - 0
pkg/subtitle_best_api/media_info.go

@@ -52,3 +52,16 @@ type MediaInfoReply struct {
 	TitleCN          string `json:"title_cn,omitempty"`
 	Year             string `json:"year,omitempty"`
 }
+
+type IdConvertReq struct {
+	Id        string `json:"id"`
+	Source    string `json:"source"`     // options=imdb|tmdb
+	VideoType string `json:"video_type"` // ,options=movie|series
+}
+
+type IdConvertReply struct {
+	Status  int    `json:"status"` // 0 失败,1 成功
+	Message string `json:"message"`
+	IMDBId  string `json:"imdb_id,omitempty"`
+	TVDBId  string `json:"tvdb_id,omitempty"`
+}

+ 45 - 0
pkg/subtitle_best_api/subtitle_best_api.go

@@ -563,6 +563,51 @@ func (s *SubtitleBestApi) DownloadSub(SubSha256, DownloadToken, ApiKey, download
 	return &downloadReply, nil
 }
 
+func (s SubtitleBestApi) ConvertId(id, source, videoType string) (*IdConvertReply, error) {
+
+	if s.authKey.BaseKey == random_auth_key.BaseKey || s.authKey.AESKey16 == random_auth_key.AESKey16 || s.authKey.AESIv16 == random_auth_key.AESIv16 {
+		return nil, errors.New("auth key is not set")
+	}
+	if len(s.authKey.AESKey16) != 16 {
+		return nil, errors.New(fmt.Sprintf("AESKey16 is not set, %s", s.authKey.AESKey16))
+	}
+	if len(s.authKey.AESIv16) != 16 {
+		return nil, errors.New(fmt.Sprintf("AESIv16 is not set, %s", s.authKey.AESIv16))
+	}
+
+	postUrl := webUrlBase + "/v1/id-convert"
+	httpClient, err := my_util.NewHttpClient(s.proxySettings)
+	if err != nil {
+		return nil, err
+	}
+
+	authKey, err := s.randomAuthKey.GetAuthKey()
+	if err != nil {
+		return nil, err
+	}
+
+	var idConvertReply IdConvertReply
+	resp, err := httpClient.R().
+		SetHeader("Authorization", "beer "+authKey).
+		SetBody(IdConvertReq{
+			Id:        id,
+			Source:    source,
+			VideoType: videoType,
+		}).
+		SetResult(&idConvertReply).
+		Post(postUrl)
+	if err != nil {
+		s.log.Errorln("convert id error, status code:", resp.StatusCode(), "Error:", err)
+		return nil, err
+	}
+
+	if idConvertReply.Status == 0 {
+		s.log.Warningln("status code:", resp.StatusCode())
+	}
+
+	return &idConvertReply, nil
+}
+
 const (
 	webUrlBase = "https://api.subtitle.best"
 	//webUrlBase = "http://127.0.0.1:8890"

+ 13 - 5
pkg/subtitle_best_api/subtitle_best_api_test.go

@@ -15,11 +15,13 @@ import (
 func TestSubtitleBestApi_GetMediaInfo(t *testing.T) {
 
 	my_util.ReadCustomAuthFile(log_helper.GetLogger4Tester())
-	bapi := NewSubtitleBestApi(random_auth_key.AuthKey{
-		BaseKey:  global_value.BaseKey(),
-		AESKey16: global_value.AESKey16(),
-		AESIv16:  global_value.AESIv16(),
-	}, settings.GetSettings().AdvancedSettings.ProxySettings)
+	bapi := NewSubtitleBestApi(
+		log_helper.GetLogger4Tester(),
+		random_auth_key.AuthKey{
+			BaseKey:  global_value.BaseKey(),
+			AESKey16: global_value.AESKey16(),
+			AESIv16:  global_value.AESIv16(),
+		}, settings.GetSettings().AdvancedSettings.ProxySettings)
 
 	mediaInfo, err := bapi.GetMediaInfo("tt7278862", "imdb", "series")
 	if err != nil {
@@ -27,6 +29,12 @@ func TestSubtitleBestApi_GetMediaInfo(t *testing.T) {
 	}
 	println(mediaInfo.TitleCN)
 
+	convertIDResult, err := bapi.ConvertId("438148", "tmdb", "movie")
+	if err != nil {
+		t.Fatal(err)
+	}
+	println("IMDBId", convertIDResult.IMDBId)
+
 	askFindSubReply, err := bapi.AskFindSub("0053b934afa0285e4de140e148c1c3768de73cfaad4170825c698308f8485c19",
 		"tt4236770", "73586", "4", "1", "haha123456", "")
 	if err != nil {