Skip to content

Commit

Permalink
对接 is_movie 接口
Browse files Browse the repository at this point in the history
Signed-off-by: allan716 <525223688@qq.com>
  • Loading branch information
allanpk716 committed Jun 10, 2022
1 parent 843dc93 commit 941f465
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 16 deletions.
7 changes: 5 additions & 2 deletions internal/logic/cron_helper/cron_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,11 @@ func (ch *CronHelper) Start(runImmediately bool) {
// 测试部分定时器代码,提前运行
if ch.Settings.SpeedDevMode == true {

//ch.uploadVideoSub()
//ch.scanVideoProcessAdd2DownloadQueue()
ch.scanPlayedVideoSub()

ch.scanVideoProcessAdd2DownloadQueue()

ch.uploadVideoSub()
}
}

Expand Down
4 changes: 4 additions & 0 deletions internal/logic/cron_helper/upload_played_video_sub.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,13 @@ func (ch *CronHelper) uploadPlayedVideoSub() {
// 问询这个字幕是否上传过了,如果没有就需要进入上传的队列
askForUploadReply, err := ch.FileDownloader.SubtitleBestApi.AskFroUpload(
notUploadedVideoSubInfos[0].SHA256,
notUploadedVideoSubInfos[0].IsMovie,
true,
finalQueryIMDBInfo.ImdbId,
finalQueryIMDBInfo.TmdbId,
notUploadedVideoSubInfos[0].Season,
notUploadedVideoSubInfos[0].Episode,
notUploadedVideoSubInfos[0].Feature,
ch.Settings.AdvancedSettings.ProxySettings,
)
if err != nil {
Expand Down Expand Up @@ -280,11 +282,13 @@ func (ch *CronHelper) uploadLowTrustVideoSub() {
// 问询这个字幕是否上传过了,如果没有就需要进入上传的队列
askForUploadReply, err := ch.FileDownloader.SubtitleBestApi.AskFroUpload(
notUploadedVideoSubInfos[0].SHA256,
notUploadedVideoSubInfos[0].IsMovie,
false,
"",
"",
0,
0,
notUploadedVideoSubInfos[0].Feature,
ch.Settings.AdvancedSettings.ProxySettings,
)
if err != nil {
Expand Down
49 changes: 35 additions & 14 deletions internal/pkg/subtitle_best_api/subtitle_best_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func (s *SubtitleBestApi) GetMediaInfo(id, source, videoType string, _proxySetti
}

// AskFroUpload 在使用这个接口前,需要从 IMDB ID 获取到 TMDB ID
func (s *SubtitleBestApi) AskFroUpload(subSha256 string, trusted bool, ImdbId, TmdbId string, Season, Episode int, _proxySettings ...*settings.ProxySettings) (*AskForUploadReply, error) {
func (s *SubtitleBestApi) AskFroUpload(subSha256 string, IsMovie, trusted bool, ImdbId, TmdbId string, Season, Episode int, VideoFeature string, _proxySettings ...*settings.ProxySettings) (*AskForUploadReply, 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")
Expand All @@ -85,26 +85,35 @@ func (s *SubtitleBestApi) AskFroUpload(subSha256 string, trusted bool, ImdbId, T
return nil, err
}

var askReq AskForUploadReq
isMovieStr := "false"
if IsMovie == true {
isMovieStr = "true"
}

trustedStr := "false"
if trusted == true {
trustedStr = "true"
}

formData := make(map[string]string)
if trusted == true {
askReq = AskForUploadReq{
SubSha256: subSha256,
Trusted: trusted,
ImdbId: ImdbId,
TmdbId: TmdbId,
Season: Season,
Episode: Episode,
}
formData["sub_sha256"] = subSha256
formData["is_movie"] = isMovieStr
formData["trusted"] = trustedStr
formData["imdb_id"] = ImdbId
formData["tmdb_id"] = TmdbId
formData["season"] = strconv.Itoa(Season)
formData["episode"] = strconv.Itoa(Episode)
formData["video_feature"] = VideoFeature
} else {
askReq = AskForUploadReq{
SubSha256: subSha256,
}
formData["sub_sha256"] = subSha256
formData["is_movie"] = isMovieStr
}

var askForUploadReply AskForUploadReply
_, err = httpClient.R().
SetHeader("Authorization", "beer "+authKey).
SetBody(askReq).
SetFormData(formData).
SetResult(&askForUploadReply).
Post(postUrl)
if err != nil {
Expand Down Expand Up @@ -155,12 +164,18 @@ func (s *SubtitleBestApi) UploadSub(videoSubInfo *models.VideoSubInfo, subSaveRo
isDouble = "true"
}

isMovieStr := "false"
if videoSubInfo.IsMovie == true {
isMovieStr = "true"
}

var uploadSubReply UploadSubReply
_, err = httpClient.R().
SetHeader("Authorization", "beer "+authKey).
SetFileReader("sub_file_context", videoSubInfo.SubName, bytes.NewReader(fd)).
SetFormData(map[string]string{
"sub_sha256": videoSubInfo.SHA256,
"is_movie": isMovieStr,
"season": strconv.Itoa(videoSubInfo.Season),
"episode": strconv.Itoa(videoSubInfo.Episode),
"is_double": isDouble,
Expand Down Expand Up @@ -220,12 +235,18 @@ func (s *SubtitleBestApi) UploadLowTrustSub(lowTrustVideoSubInfo *models.LowVide
isDouble = "true"
}

isMovieStr := "false"
if lowTrustVideoSubInfo.IsMovie == true {
isMovieStr = "true"
}

var uploadSubReply UploadSubReply
_, err = httpClient.R().
SetHeader("Authorization", "beer "+authKey).
SetFileReader("sub_file_context", lowTrustVideoSubInfo.SubName, bytes.NewReader(fd)).
SetFormData(map[string]string{
"sub_sha256": lowTrustVideoSubInfo.SHA256,
"is_movie": isMovieStr,
"season": strconv.Itoa(lowTrustVideoSubInfo.Season),
"episode": strconv.Itoa(lowTrustVideoSubInfo.Episode),
"is_double": isDouble,
Expand Down

0 comments on commit 941f465

Please sign in to comment.