|
@@ -1,16 +1,19 @@
|
|
|
-package main
|
|
|
+package internal
|
|
|
|
|
|
import (
|
|
|
- common2 "github.com/allanpk716/ChineseSubFinder/internal/common"
|
|
|
- emby_helper2 "github.com/allanpk716/ChineseSubFinder/internal/logic/emby_helper"
|
|
|
- mark_system2 "github.com/allanpk716/ChineseSubFinder/internal/logic/mark_system"
|
|
|
- series_helper2 "github.com/allanpk716/ChineseSubFinder/internal/logic/series_helper"
|
|
|
- sub_supplier2 "github.com/allanpk716/ChineseSubFinder/internal/logic/sub_supplier"
|
|
|
- shooter2 "github.com/allanpk716/ChineseSubFinder/internal/logic/sub_supplier/shooter"
|
|
|
- subhd2 "github.com/allanpk716/ChineseSubFinder/internal/logic/sub_supplier/subhd"
|
|
|
- xunlei2 "github.com/allanpk716/ChineseSubFinder/internal/logic/sub_supplier/xunlei"
|
|
|
- zimuku2 "github.com/allanpk716/ChineseSubFinder/internal/logic/sub_supplier/zimuku"
|
|
|
+ "github.com/allanpk716/ChineseSubFinder/internal/common"
|
|
|
+ embyHelper "github.com/allanpk716/ChineseSubFinder/internal/logic/emby_helper"
|
|
|
+ markSystem "github.com/allanpk716/ChineseSubFinder/internal/logic/mark_system"
|
|
|
+ seriesHelper "github.com/allanpk716/ChineseSubFinder/internal/logic/series_helper"
|
|
|
+ subSupplier "github.com/allanpk716/ChineseSubFinder/internal/logic/sub_supplier"
|
|
|
+ "github.com/allanpk716/ChineseSubFinder/internal/logic/sub_supplier/shooter"
|
|
|
+ "github.com/allanpk716/ChineseSubFinder/internal/logic/sub_supplier/subhd"
|
|
|
+ "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/language"
|
|
|
+ "github.com/allanpk716/ChineseSubFinder/internal/pkg/log_helper"
|
|
|
"github.com/allanpk716/ChineseSubFinder/internal/types"
|
|
|
"github.com/allanpk716/ChineseSubFinder/internal/types/emby"
|
|
|
"github.com/allanpk716/ChineseSubFinder/internal/types/series"
|
|
@@ -30,9 +33,9 @@ import (
|
|
|
type Downloader struct {
|
|
|
reqParam types.ReqParam
|
|
|
log *logrus.Logger
|
|
|
- topic int // 最多能够下载 Top 几的字幕,每一个网站
|
|
|
- mk *mark_system2.MarkingSystem // MarkingSystem
|
|
|
- embyHelper *emby_helper2.EmbyHelper
|
|
|
+ topic int // 最多能够下载 Top 几的字幕,每一个网站
|
|
|
+ mk *markSystem.MarkingSystem // MarkingSystem
|
|
|
+ embyHelper *embyHelper.EmbyHelper
|
|
|
movieDirList []string // 多个需要搜索字幕的电影目录
|
|
|
seriesSubNeedDlMap map[string][]emby.EmbyMixInfo // 多个需要搜索字幕的连续剧目录
|
|
|
}
|
|
@@ -40,8 +43,8 @@ type Downloader struct {
|
|
|
func NewDownloader(_reqParam ...types.ReqParam) *Downloader {
|
|
|
|
|
|
var downloader Downloader
|
|
|
- downloader.log = pkg.GetLogger()
|
|
|
- downloader.topic = common2.DownloadSubsPerSite
|
|
|
+ downloader.log = log_helper.GetLogger()
|
|
|
+ downloader.topic = common.DownloadSubsPerSite
|
|
|
if len(_reqParam) > 0 {
|
|
|
downloader.reqParam = _reqParam[0]
|
|
|
if downloader.reqParam.Topic > 0 && downloader.reqParam.Topic != downloader.topic {
|
|
@@ -55,7 +58,7 @@ func NewDownloader(_reqParam ...types.ReqParam) *Downloader {
|
|
|
}
|
|
|
// 初始化 Emby API 接口
|
|
|
if downloader.reqParam.EmbyConfig.Url != "" && downloader.reqParam.EmbyConfig.ApiKey != "" {
|
|
|
- downloader.embyHelper = emby_helper2.NewEmbyHelper(downloader.reqParam.EmbyConfig)
|
|
|
+ downloader.embyHelper = embyHelper.NewEmbyHelper(downloader.reqParam.EmbyConfig)
|
|
|
}
|
|
|
} else {
|
|
|
downloader.reqParam = *types.NewReqParam()
|
|
@@ -63,11 +66,11 @@ func NewDownloader(_reqParam ...types.ReqParam) *Downloader {
|
|
|
|
|
|
var sitesSequence = make([]string, 0)
|
|
|
// TODO 这里写固定了抉择字幕的顺序
|
|
|
- sitesSequence = append(sitesSequence, common2.SubSiteZiMuKu)
|
|
|
- sitesSequence = append(sitesSequence, common2.SubSiteSubHd)
|
|
|
- sitesSequence = append(sitesSequence, common2.SubSiteXunLei)
|
|
|
- sitesSequence = append(sitesSequence, common2.SubSiteShooter)
|
|
|
- downloader.mk = mark_system2.NewMarkingSystem(sitesSequence, downloader.reqParam.SubTypePriority)
|
|
|
+ sitesSequence = append(sitesSequence, common.SubSiteZiMuKu)
|
|
|
+ sitesSequence = append(sitesSequence, common.SubSiteSubHd)
|
|
|
+ sitesSequence = append(sitesSequence, common.SubSiteXunLei)
|
|
|
+ sitesSequence = append(sitesSequence, common.SubSiteShooter)
|
|
|
+ downloader.mk = markSystem.NewMarkingSystem(sitesSequence, downloader.reqParam.SubTypePriority)
|
|
|
|
|
|
downloader.movieDirList = make([]string, 0)
|
|
|
downloader.seriesSubNeedDlMap = make(map[string][]emby.EmbyMixInfo)
|
|
@@ -122,22 +125,22 @@ func (d Downloader) DownloadSub4Movie(dir string) error {
|
|
|
if err != nil {
|
|
|
d.log.Error("ClearRootTmpFolder", err)
|
|
|
}
|
|
|
- log.Infoln("Download Movie Sub End...")
|
|
|
+ d.log.Infoln("Download Movie Sub End...")
|
|
|
}()
|
|
|
var err error
|
|
|
- log.Infoln("Download Movie Sub Started...")
|
|
|
- // 是否是通过 emby api 获取的列表
|
|
|
+ d.log.Infoln("Download Movie Sub Started...")
|
|
|
+ // 是否是通过 emby_helper api 获取的列表
|
|
|
if d.embyHelper == nil {
|
|
|
- // 没有填写 emby api 的信息,那么就走常规的全文件扫描流程
|
|
|
+ // 没有填写 emby_helper api 的信息,那么就走常规的全文件扫描流程
|
|
|
d.movieDirList, err = pkg.SearchMatchedVideoFile(dir)
|
|
|
if err != nil {
|
|
|
return err
|
|
|
}
|
|
|
} else {
|
|
|
- // 进过 emby api 的信息读取
|
|
|
- log.Infoln("Movie Sub Dl From Emby API...")
|
|
|
+ // 进过 emby_helper api 的信息读取
|
|
|
+ d.log.Infoln("Movie Sub Dl From Emby API...")
|
|
|
if len(d.movieDirList) < 1 {
|
|
|
- log.Infoln("Movie Sub Dl From Emby API no movie need Dl sub")
|
|
|
+ d.log.Infoln("Movie Sub Dl From Emby API no movie need Dl sub")
|
|
|
return nil
|
|
|
}
|
|
|
}
|
|
@@ -146,11 +149,11 @@ func (d Downloader) DownloadSub4Movie(dir string) error {
|
|
|
inData := i.(InputData)
|
|
|
// -----------------------------------------------------
|
|
|
// 构建每个字幕站点下载者的实例
|
|
|
- var subSupplierHub = sub_supplier2.NewSubSupplierHub(
|
|
|
- subhd2.NewSupplier(d.reqParam),
|
|
|
- zimuku2.NewSupplier(d.reqParam),
|
|
|
- xunlei2.NewSupplier(d.reqParam),
|
|
|
- shooter2.NewSupplier(d.reqParam),
|
|
|
+ var subSupplierHub = subSupplier.NewSubSupplierHub(
|
|
|
+ subhd.NewSupplier(d.reqParam),
|
|
|
+ zimuku.NewSupplier(d.reqParam),
|
|
|
+ xunlei.NewSupplier(d.reqParam),
|
|
|
+ shooter.NewSupplier(d.reqParam),
|
|
|
)
|
|
|
// 字幕都下载缓存好了,需要抉择存哪一个,优先选择中文双语的,然后到中文
|
|
|
organizeSubFiles, err := subSupplierHub.DownloadSub4Movie(inData.OneVideoFullPath, inData.Index)
|
|
@@ -170,7 +173,7 @@ func (d Downloader) DownloadSub4Movie(dir string) error {
|
|
|
p, err := ants.NewPoolWithFunc(d.reqParam.Threads, func(inData interface{}) {
|
|
|
data := inData.(InputData)
|
|
|
defer data.Wg.Done()
|
|
|
- ctx, cancel := context.WithTimeout(context.Background(), common2.OneVideoProcessTimeOut)
|
|
|
+ ctx, cancel := context.WithTimeout(context.Background(), common.OneVideoProcessTimeOut)
|
|
|
defer cancel()
|
|
|
|
|
|
done := make(chan error, 1)
|
|
@@ -221,25 +224,25 @@ func (d Downloader) DownloadSub4Series(dir string) error {
|
|
|
if err != nil {
|
|
|
d.log.Error("ClearRootTmpFolder", err)
|
|
|
}
|
|
|
- log.Infoln("Download Series Sub End...")
|
|
|
+ d.log.Infoln("Download Series Sub End...")
|
|
|
}()
|
|
|
- log.Infoln("Download Series Sub Started...")
|
|
|
+ d.log.Infoln("Download Series Sub Started...")
|
|
|
|
|
|
// 并发控制
|
|
|
seriesDlFunc := func(i interface{}) error {
|
|
|
inData := i.(InputData)
|
|
|
// 构建每个字幕站点下载者的实例
|
|
|
- var subSupplierHub *sub_supplier2.SubSupplierHub
|
|
|
- subSupplierHub = sub_supplier2.NewSubSupplierHub(
|
|
|
- zimuku2.NewSupplier(d.reqParam),
|
|
|
- subhd2.NewSupplier(d.reqParam),
|
|
|
- xunlei2.NewSupplier(d.reqParam),
|
|
|
- shooter2.NewSupplier(d.reqParam),
|
|
|
+ var subSupplierHub *subSupplier.SubSupplierHub
|
|
|
+ subSupplierHub = subSupplier.NewSubSupplierHub(
|
|
|
+ zimuku.NewSupplier(d.reqParam),
|
|
|
+ subhd.NewSupplier(d.reqParam),
|
|
|
+ xunlei.NewSupplier(d.reqParam),
|
|
|
+ shooter.NewSupplier(d.reqParam),
|
|
|
)
|
|
|
// 这里拿到了这一部连续剧的所有的剧集信息,以及所有下载到的字幕信息
|
|
|
var seriesInfo *series.SeriesInfo
|
|
|
var organizeSubFiles map[string][]string
|
|
|
- // 是否是通过 emby api 获取的列表
|
|
|
+ // 是否是通过 emby_helper api 获取的列表
|
|
|
if d.embyHelper == nil {
|
|
|
seriesInfo, organizeSubFiles, err = subSupplierHub.DownloadSub4Series(inData.OneVideoFullPath, inData.Index)
|
|
|
if err != nil {
|
|
@@ -247,7 +250,7 @@ func (d Downloader) DownloadSub4Series(dir string) error {
|
|
|
return err
|
|
|
}
|
|
|
} else {
|
|
|
- // 先进性 emby api 的操作,读取需要更新字幕的项目
|
|
|
+ // 先进性 emby_helper api 的操作,读取需要更新字幕的项目
|
|
|
seriesInfo, organizeSubFiles, err = subSupplierHub.DownloadSub4SeriesFromEmby(
|
|
|
path.Join(dir, inData.OneVideoFullPath),
|
|
|
d.seriesSubNeedDlMap[inData.OneVideoFullPath], inData.Index)
|
|
@@ -285,7 +288,7 @@ func (d Downloader) DownloadSub4Series(dir string) error {
|
|
|
p, err := ants.NewPoolWithFunc(d.reqParam.Threads, func(inData interface{}) {
|
|
|
data := inData.(InputData)
|
|
|
defer data.Wg.Done()
|
|
|
- ctx, cancel := context.WithTimeout(context.Background(), common2.OneVideoProcessTimeOut)
|
|
|
+ ctx, cancel := context.WithTimeout(context.Background(), common.OneVideoProcessTimeOut)
|
|
|
defer cancel()
|
|
|
|
|
|
done := make(chan error, 1)
|
|
@@ -315,11 +318,11 @@ func (d Downloader) DownloadSub4Series(dir string) error {
|
|
|
}
|
|
|
defer p.Release()
|
|
|
|
|
|
- // 是否是通过 emby api 获取的列表
|
|
|
+ // 是否是通过 emby_helper api 获取的列表
|
|
|
var seriesDirList = make([]string, 0)
|
|
|
if d.embyHelper == nil {
|
|
|
// 遍历连续剧总目录下的第一层目录
|
|
|
- seriesDirList, err = series_helper2.GetSeriesList(dir)
|
|
|
+ seriesDirList, err = seriesHelper.GetSeriesList(dir)
|
|
|
if err != nil {
|
|
|
return err
|
|
|
}
|
|
@@ -409,7 +412,7 @@ func (d Downloader) saveFullSeasonSub(seriesInfo *series.SeriesInfo, organizeSub
|
|
|
continue
|
|
|
}
|
|
|
// 从字幕的文件名推断是 哪一季 的 那一集
|
|
|
- _, gusSeason, gusEpisode, err := pkg.GetSeasonAndEpisodeFromSubFileName(subFileName)
|
|
|
+ _, gusSeason, gusEpisode, err := decode.GetSeasonAndEpisodeFromSubFileName(subFileName)
|
|
|
if err != nil {
|
|
|
return nil
|
|
|
}
|
|
@@ -430,8 +433,8 @@ func (d Downloader) saveFullSeasonSub(seriesInfo *series.SeriesInfo, organizeSub
|
|
|
// 在前面需要进行语言的筛选、排序,这里仅仅是存储
|
|
|
func (d Downloader) writeSubFile2VideoPath(videoFileFullPath string, finalSubFile subparser.FileInfo, extraSubPreName string) error {
|
|
|
videoRootPath := filepath.Dir(videoFileFullPath)
|
|
|
- embyLanExtName := pkg.Lang2EmbyName(finalSubFile.Lang)
|
|
|
- // 构建视频文件加 emby 的字幕预研要求名称
|
|
|
+ embyLanExtName := language.Lang2EmbyName(finalSubFile.Lang)
|
|
|
+ // 构建视频文件加 emby_helper 的字幕预研要求名称
|
|
|
videoFileNameWithOutExt := strings.ReplaceAll(filepath.Base(videoFileFullPath),
|
|
|
filepath.Ext(videoFileFullPath), "")
|
|
|
if extraSubPreName != "" {
|
|
@@ -454,7 +457,7 @@ func (d Downloader) copySubFile2DesFolder(desFolder string, subFiles []string) e
|
|
|
|
|
|
// 需要进行字幕文件的缓存
|
|
|
// 把缓存的文件夹新建出来
|
|
|
- desFolderFullPath := path.Join(desFolder, common2.SubTmpFolderName)
|
|
|
+ desFolderFullPath := path.Join(desFolder, common.SubTmpFolderName)
|
|
|
err := os.MkdirAll(desFolderFullPath, os.ModePerm)
|
|
|
if err != nil {
|
|
|
return err
|