Skip to content

Commit

Permalink
1,新增,当一部电影根目录,一部连续剧的根目录存在 .ignore 文件,则跳过下载字幕的扫描
Browse files Browse the repository at this point in the history
2,AutoDetectThenChangeTo 也判断  .ignore 文件,有则跳过字幕命名的自动修改逻辑,这里需要之一 hot fix 的逻辑是不能跳过的

Signed-off-by: allan716 <525223688@qq.com>
  • Loading branch information
allanpk716 committed Nov 5, 2021
1 parent eb73ae0 commit 86a5ab6
Show file tree
Hide file tree
Showing 37 changed files with 167 additions and 131 deletions.
8 changes: 4 additions & 4 deletions cmd/chinesesubfinder/main.go
Expand Up @@ -3,10 +3,10 @@ package main
import (
"github.com/allanpk716/ChineseSubFinder/internal"
"github.com/allanpk716/ChineseSubFinder/internal/logic/sub_timeline_fixer"
"github.com/allanpk716/ChineseSubFinder/internal/pkg"
config2 "github.com/allanpk716/ChineseSubFinder/internal/pkg/config"
"github.com/allanpk716/ChineseSubFinder/internal/pkg/hot_fix"
"github.com/allanpk716/ChineseSubFinder/internal/pkg/log_helper"
"github.com/allanpk716/ChineseSubFinder/internal/pkg/my_util"
"github.com/allanpk716/ChineseSubFinder/internal/pkg/notify_center"
"github.com/allanpk716/ChineseSubFinder/internal/pkg/proxy_helper"
"github.com/allanpk716/ChineseSubFinder/internal/pkg/sub_formatter"
Expand All @@ -22,7 +22,7 @@ func init() {

log.Infoln("ChineseSubFinder Version:", AppVersion)

if pkg.OSCheck() == false {
if my_util.OSCheck() == false {
panic(`only support Linux and Windows, if you want support MacOS,
you need implement getDbName() in file: internal/dao/init.go
and
Expand Down Expand Up @@ -57,11 +57,11 @@ func main() {
}

// 判断文件夹是否存在
if pkg.IsDir(config.MovieFolder) == false {
if my_util.IsDir(config.MovieFolder) == false {
log.Errorln("MovieFolder not found --", config.MovieFolder)
return
}
if pkg.IsDir(config.SeriesFolder) == false {
if my_util.IsDir(config.SeriesFolder) == false {
log.Errorln("SeriesFolder not found --", config.SeriesFolder)
return
}
Expand Down
2 changes: 2 additions & 0 deletions internal/common/constvalue.go
Expand Up @@ -35,3 +35,5 @@ const (
TimeFormatAss = "15:04:05.00"
TimeFormatSrt = "15:04:05,000"
)

const Ignore = ".ignore"
6 changes: 3 additions & 3 deletions internal/dao/init.go
Expand Up @@ -4,8 +4,8 @@ import (
"errors"
"fmt"
"github.com/allanpk716/ChineseSubFinder/internal/models"
"github.com/allanpk716/ChineseSubFinder/internal/pkg"
"github.com/allanpk716/ChineseSubFinder/internal/pkg/log_helper"
"github.com/allanpk716/ChineseSubFinder/internal/pkg/my_util"
"github.com/allanpk716/ChineseSubFinder/internal/pkg/sqlite"
"gorm.io/gorm"
"os"
Expand Down Expand Up @@ -46,7 +46,7 @@ func DeleteDbFile() error {
// 如果是 Linux 则在 /config 目录下
nowDbFileName := getDbName()

if pkg.IsFile(nowDbFileName) == true {
if my_util.IsFile(nowDbFileName) == true {
return os.Remove(nowDbFileName)
}
return nil
Expand All @@ -63,7 +63,7 @@ you need implement getDbName() in file: internal/dao/init.go `))
}

dbDir := filepath.Dir(nowDbFileName)
if pkg.IsDir(dbDir) == false {
if my_util.IsDir(dbDir) == false {
_ = os.MkdirAll(dbDir, os.ModePerm)
}
db, err = gorm.Open(sqlite.Open(nowDbFileName), &gorm.Config{})
Expand Down
24 changes: 12 additions & 12 deletions internal/downloader.go
Expand Up @@ -11,9 +11,9 @@ import (
"github.com/allanpk716/ChineseSubFinder/internal/logic/sub_supplier/shooter"
"github.com/allanpk716/ChineseSubFinder/internal/logic/sub_supplier/xunlei"
"github.com/allanpk716/ChineseSubFinder/internal/logic/sub_supplier/zimuku"
"github.com/allanpk716/ChineseSubFinder/internal/pkg"
"github.com/allanpk716/ChineseSubFinder/internal/pkg/decode"
"github.com/allanpk716/ChineseSubFinder/internal/pkg/log_helper"
"github.com/allanpk716/ChineseSubFinder/internal/pkg/my_util"
subcommon "github.com/allanpk716/ChineseSubFinder/internal/pkg/sub_formatter/common"
"github.com/allanpk716/ChineseSubFinder/internal/pkg/sub_helper"
"github.com/allanpk716/ChineseSubFinder/internal/types"
Expand Down Expand Up @@ -153,7 +153,7 @@ func (d Downloader) RefreshEmbySubList() error {
func (d Downloader) DownloadSub4Movie(dir string) error {
defer func() {
// 所有的电影字幕下载完成,抉择完成,需要清理缓存目录
err := pkg.ClearRootTmpFolder()
err := my_util.ClearRootTmpFolder()
if err != nil {
d.log.Error("ClearRootTmpFolder", err)
}
Expand All @@ -164,15 +164,15 @@ func (d Downloader) DownloadSub4Movie(dir string) error {
// 优先判断特殊的操作
if d.needForcedScanAndDownSub == true {
// 全扫描
d.movieFileFullPathList, err = pkg.SearchMatchedVideoFile(dir)
d.movieFileFullPathList, err = my_util.SearchMatchedVideoFile(dir)
if err != nil {
return err
}
} else {
// 是否是通过 emby_helper api 获取的列表
if d.embyHelper == nil {
// 没有填写 emby_helper api 的信息,那么就走常规的全文件扫描流程
d.movieFileFullPathList, err = pkg.SearchMatchedVideoFile(dir)
d.movieFileFullPathList, err = my_util.SearchMatchedVideoFile(dir)
if err != nil {
return err
}
Expand Down Expand Up @@ -268,7 +268,7 @@ func (d Downloader) DownloadSub4Series(dir string) error {
var err error
defer func() {
// 所有的连续剧字幕下载完成,抉择完成,需要清理缓存目录
err := pkg.ClearRootTmpFolder()
err := my_util.ClearRootTmpFolder()
if err != nil {
d.log.Error("ClearRootTmpFolder", err)
}
Expand Down Expand Up @@ -337,7 +337,7 @@ func (d Downloader) DownloadSub4Series(dir string) error {
continue
}
// 匹配对应的 Eps 去处理
seasonEpsKey := pkg.GetEpisodeKeyName(episodeInfo.Season, episodeInfo.Episode)
seasonEpsKey := my_util.GetEpisodeKeyName(episodeInfo.Season, episodeInfo.Episode)
d.oneVideoSelectBestSub(episodeInfo.FileFullPath, fullSeasonSubDict[seasonEpsKey])
}
// 是否清理全季的缓存字幕文件夹
Expand Down Expand Up @@ -520,7 +520,7 @@ func (d Downloader) saveFullSeasonSub(seriesInfo *series.SeriesInfo, organizeSub
var fullSeasonSubDict = make(map[string][]string)

for _, season := range seriesInfo.SeasonDict {
seasonKey := pkg.GetEpisodeKeyName(season, 0)
seasonKey := my_util.GetEpisodeKeyName(season, 0)
subs, ok := organizeSubFiles[seasonKey]
if ok == false {
continue
Expand All @@ -530,7 +530,7 @@ func (d Downloader) saveFullSeasonSub(seriesInfo *series.SeriesInfo, organizeSub
newSeasonSubRootPath := filepath.Join(seriesInfo.DirPath, "Sub_"+seasonKey)
_ = os.MkdirAll(newSeasonSubRootPath, os.ModePerm)
newSubFullPath := filepath.Join(newSeasonSubRootPath, subFileName)
err := pkg.CopyFile(sub, newSubFullPath)
err := my_util.CopyFile(sub, newSubFullPath)
if err != nil {
d.log.Errorln("saveFullSeasonSub", subFileName, err)
continue
Expand All @@ -541,7 +541,7 @@ func (d Downloader) saveFullSeasonSub(seriesInfo *series.SeriesInfo, organizeSub
return nil
}
// 把整季的字幕缓存位置也提供出去,如果之前没有下载到的,这里返回出来的可以补上
seasonEpsKey := pkg.GetEpisodeKeyName(gusSeason, gusEpisode)
seasonEpsKey := my_util.GetEpisodeKeyName(gusSeason, gusEpisode)
_, ok := fullSeasonSubDict[seasonEpsKey]
if ok == false {
// 初始化
Expand All @@ -563,15 +563,15 @@ func (d Downloader) writeSubFile2VideoPath(videoFileFullPath string, finalSubFil
desSubFullPath := filepath.Join(videoRootPath, subNewName)
if setDefault == true {
// 先判断没有 default 的字幕是否存在了,在的话,先删除,然后再写入
if pkg.IsFile(desSubFullPath) == true {
if my_util.IsFile(desSubFullPath) == true {
_ = os.Remove(desSubFullPath)
}
desSubFullPath = filepath.Join(videoRootPath, subNewNameWithDefault)
}

if skipExistFile == true {
// 需要判断文件是否存在在,有则跳过
if pkg.IsFile(desSubFullPath) == true {
if my_util.IsFile(desSubFullPath) == true {
d.log.Infoln("OrgSubName:", finalSubFile.Name)
d.log.Infoln("Sub Skip DownAt:", desSubFullPath)
return nil
Expand Down Expand Up @@ -601,7 +601,7 @@ func (d Downloader) copySubFile2DesFolder(desFolder string, subFiles []string) e
// 复制下载在 tmp 文件夹中的字幕文件到视频文件夹下面
for _, subFile := range subFiles {
newFn := filepath.Join(desFolderFullPath, filepath.Base(subFile))
err = pkg.CopyFile(subFile, newFn)
err = my_util.CopyFile(subFile, newFn)
if err != nil {
return err
}
Expand Down
Expand Up @@ -3,7 +3,7 @@ package forced_scan_and_down_sub
import (
"errors"
"fmt"
"github.com/allanpk716/ChineseSubFinder/internal/pkg"
"github.com/allanpk716/ChineseSubFinder/internal/pkg/my_util"
"os"
"runtime"
)
Expand All @@ -16,7 +16,7 @@ func CheckSpeFile() (bool, error) {
return false, errors.New(fmt.Sprintf(`forced_scan_and_down_sub.getSpeFileName() is empty, not support this OS.
you needd implement getSpeFileName() in internal/logic/forced_scan_and_down_sub/forced_scan_and_down_sub.go`))
}
if pkg.IsFile(nowSpeFileName) == false {
if my_util.IsFile(nowSpeFileName) == false {
return false, nil
}
// 先删除这个文件,然后再标记执行该逻辑
Expand Down
@@ -1,7 +1,7 @@
package forced_scan_and_down_sub

import (
"github.com/allanpk716/ChineseSubFinder/internal/pkg"
"github.com/allanpk716/ChineseSubFinder/internal/pkg/my_util"
"os"
"testing"
)
Expand Down Expand Up @@ -30,7 +30,7 @@ func TestCheckSpeFile(t *testing.T) {
t.Fatal(err)
}

if got == false || pkg.IsFile(getSpeFileName()) == true {
if got == false || my_util.IsFile(getSpeFileName()) == true {
t.Fatal("CheckSpeFile fatal")
}
}
12 changes: 6 additions & 6 deletions internal/logic/series_helper/seriesHelper.go
Expand Up @@ -6,10 +6,10 @@ import (
"github.com/allanpk716/ChineseSubFinder/internal/ifaces"
"github.com/allanpk716/ChineseSubFinder/internal/logic/sub_parser/ass"
"github.com/allanpk716/ChineseSubFinder/internal/logic/sub_parser/srt"
"github.com/allanpk716/ChineseSubFinder/internal/pkg"
"github.com/allanpk716/ChineseSubFinder/internal/pkg/decode"
"github.com/allanpk716/ChineseSubFinder/internal/pkg/imdb_helper"
"github.com/allanpk716/ChineseSubFinder/internal/pkg/log_helper"
"github.com/allanpk716/ChineseSubFinder/internal/pkg/my_util"
"github.com/allanpk716/ChineseSubFinder/internal/pkg/sub_helper"
"github.com/allanpk716/ChineseSubFinder/internal/pkg/sub_parser_hub"
"github.com/allanpk716/ChineseSubFinder/internal/types"
Expand All @@ -34,7 +34,7 @@ func ReadSeriesInfoFromDir(seriesDir string, imdbInfo *imdb.Title, forcedScanAnd
return nil, err
}
// 搜索所有的视频
videoFiles, err := pkg.SearchMatchedVideoFile(seriesDir)
videoFiles, err := my_util.SearchMatchedVideoFile(seriesDir)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -64,7 +64,7 @@ func ReadSeriesInfoFromDir(seriesDir string, imdbInfo *imdb.Title, forcedScanAnd
log_helper.GetLogger().Warnln("DetermineFileTypeFromFile", subFile, "not support SubType")
continue
}
epsKey := pkg.GetEpisodeKeyName(info.Season, info.Episode)
epsKey := my_util.GetEpisodeKeyName(info.Season, info.Episode)
oneFileSubInfo := series.SubInfo{
Title: info.Title,
Season: info.Season,
Expand Down Expand Up @@ -226,7 +226,7 @@ func whichSeasonEpsNeedDownloadSub(seriesInfo *series.SeriesInfo, forcedScanAndD
if forcedScanAndDownloadSub == true {
for _, epsInfo := range seriesInfo.EpList {
// 添加
epsKey := pkg.GetEpisodeKeyName(epsInfo.Season, epsInfo.Episode)
epsKey := my_util.GetEpisodeKeyName(epsInfo.Season, epsInfo.Episode)
needDlSubEpsList[epsKey] = epsInfo
needDlSeasonList[epsInfo.Season] = epsInfo.Season
}
Expand All @@ -252,7 +252,7 @@ func whichSeasonEpsNeedDownloadSub(seriesInfo *series.SeriesInfo, forcedScanAndD

if len(epsInfo.SubAlreadyDownloadedList) < 1 || baseTime.Add(dayRange).After(currentTime) == true {
// 添加
epsKey := pkg.GetEpisodeKeyName(epsInfo.Season, epsInfo.Episode)
epsKey := my_util.GetEpisodeKeyName(epsInfo.Season, epsInfo.Episode)
needDlSubEpsList[epsKey] = epsInfo
needDlSeasonList[epsInfo.Season] = epsInfo.Season
} else {
Expand Down Expand Up @@ -310,7 +310,7 @@ func getEpsInfoAndSubDic(videoFile string, EpisodeDict map[string]series.Episode
log_helper.GetLogger().Errorln("model.GetImdbInfo4OneSeriesEpisode", err)
return
}
epsKey := pkg.GetEpisodeKeyName(info.Season, info.Episode)
epsKey := my_util.GetEpisodeKeyName(info.Season, info.Episode)
_, ok := EpisodeDict[epsKey]
if ok == false {
// 初始化
Expand Down
4 changes: 2 additions & 2 deletions internal/logic/sub_parser/ass/ass_test.go
@@ -1,15 +1,15 @@
package ass

import (
"github.com/allanpk716/ChineseSubFinder/internal/pkg"
"github.com/allanpk716/ChineseSubFinder/internal/pkg/my_util"
"github.com/allanpk716/ChineseSubFinder/internal/types/language"
"testing"
)

func TestParser_DetermineFileTypeFromFile(t *testing.T) {

testDataPath := "../../../../TestData/sub_parser"
testRootDir, err := pkg.CopyTestData(testDataPath)
testRootDir, err := my_util.CopyTestData(testDataPath)
if err != nil {
t.Fatal(err)
}
Expand Down
4 changes: 2 additions & 2 deletions internal/logic/sub_parser/srt/srt_test.go
@@ -1,15 +1,15 @@
package srt

import (
"github.com/allanpk716/ChineseSubFinder/internal/pkg"
"github.com/allanpk716/ChineseSubFinder/internal/pkg/my_util"
"github.com/allanpk716/ChineseSubFinder/internal/types/language"
"path/filepath"
"testing"
)

func TestParser_DetermineFileType(t *testing.T) {
testDataPath := "../../../../TestData/sub_parser"
testRootDir, err := pkg.CopyTestData(testDataPath)
testRootDir, err := my_util.CopyTestData(testDataPath)
if err != nil {
t.Fatal(err)
}
Expand Down
6 changes: 3 additions & 3 deletions internal/logic/sub_supplier/shooter/shooter.go
Expand Up @@ -4,8 +4,8 @@ import (
"crypto/md5"
"fmt"
"github.com/allanpk716/ChineseSubFinder/internal/common"
"github.com/allanpk716/ChineseSubFinder/internal/pkg"
"github.com/allanpk716/ChineseSubFinder/internal/pkg/log_helper"
"github.com/allanpk716/ChineseSubFinder/internal/pkg/my_util"
"github.com/allanpk716/ChineseSubFinder/internal/types"
"github.com/allanpk716/ChineseSubFinder/internal/types/language"
"github.com/allanpk716/ChineseSubFinder/internal/types/series"
Expand Down Expand Up @@ -74,7 +74,7 @@ func (s Supplier) getSubListFromFile(filePath string) ([]supplier.SubInfo, error

fileName := filepath.Base(filePath)

httpClient := pkg.NewHttpClient(s.reqParam)
httpClient := my_util.NewHttpClient(s.reqParam)

_, err = httpClient.R().
SetFormData(map[string]string{
Expand All @@ -95,7 +95,7 @@ func (s Supplier) getSubListFromFile(filePath string) ([]supplier.SubInfo, error
subExt = "." + subExt
}

data, _, err := pkg.DownFile(file.Link)
data, _, err := my_util.DownFile(file.Link)
if err != nil {
s.log.Error(err)
continue
Expand Down
20 changes: 20 additions & 0 deletions internal/logic/sub_supplier/subSupplierHub.go
@@ -1,10 +1,12 @@
package sub_supplier

import (
"github.com/allanpk716/ChineseSubFinder/internal/common"
"github.com/allanpk716/ChineseSubFinder/internal/ifaces"
movieHelper "github.com/allanpk716/ChineseSubFinder/internal/logic/movie_helper"
seriesHelper "github.com/allanpk716/ChineseSubFinder/internal/logic/series_helper"
"github.com/allanpk716/ChineseSubFinder/internal/pkg/log_helper"
"github.com/allanpk716/ChineseSubFinder/internal/pkg/my_util"
"github.com/allanpk716/ChineseSubFinder/internal/pkg/sub_helper"
"github.com/allanpk716/ChineseSubFinder/internal/types/emby"
"github.com/allanpk716/ChineseSubFinder/internal/types/series"
Expand Down Expand Up @@ -36,6 +38,15 @@ func NewSubSupplierHub(one ifaces.ISupplier, _inSupplier ...ifaces.ISupplier) *S
// DownloadSub4Movie 某一个电影字幕下载,下载完毕后,返回下载缓存每个字幕的位置
func (d SubSupplierHub) DownloadSub4Movie(videoFullPath string, index int, forcedScanAndDownloadSub bool) ([]string, error) {

if forcedScanAndDownloadSub == false {
// 非强制扫描的时候,需要判断这个视频根目录是否有 .ignore 文件,有也跳过
if my_util.IsFile(filepath.Join(filepath.Dir(videoFullPath), common.Ignore)) == true {
d.log.Infoln("Found", common.Ignore, "Skip", videoFullPath)
// 跳过下载字幕
return nil, nil
}
}

// 跳过中文的电影,不是一定要跳过的
skip, err := movieHelper.SkipChineseMovie(videoFullPath, d.Suppliers[0].GetReqParam())
if err != nil {
Expand Down Expand Up @@ -78,6 +89,15 @@ func (d SubSupplierHub) DownloadSub4Movie(videoFullPath string, index int, force
// DownloadSub4Series 某一部连续剧的字幕下载,下载完毕后,返回下载缓存每个字幕的位置
func (d SubSupplierHub) DownloadSub4Series(seriesDirPath string, index int, forcedScanAndDownloadSub bool) (*series.SeriesInfo, map[string][]string, error) {

if forcedScanAndDownloadSub == false {
// 非强制扫描的时候,需要判断这个视频根目录是否有 .ignore 文件,有也跳过
if my_util.IsFile(filepath.Join(seriesDirPath, common.Ignore)) == true {
d.log.Infoln("Found", common.Ignore, "Skip", seriesDirPath)
// 跳过下载字幕
return nil, nil, nil
}
}

// 跳过中文的连续剧,不是一定要跳过的
skip, imdbInfo, err := seriesHelper.SkipChineseSeries(seriesDirPath, d.Suppliers[0].GetReqParam())
if err != nil {
Expand Down

0 comments on commit 86a5ab6

Please sign in to comment.