浏览代码

取消外置的数据结构

Signed-off-by: 716 <[email protected]>
716 3 年之前
父节点
当前提交
bd3c94d8b8

+ 0 - 1
go.mod

@@ -7,7 +7,6 @@ require (
 	github.com/StalkR/imdb v1.0.7
 	github.com/Tnze/go.num/v2 v2.0.0-20191006170829-cb483d4c9152
 	github.com/abadojack/whatlanggo v1.0.1
-	github.com/allanpk716/ChineseSubModels v0.0.3
 	github.com/allanpk716/fake-useragent v0.2.1
 	github.com/axgle/mahonia v0.0.0-20180208002826-3358181d7394
 	github.com/baabaaox/go-webrtcvad v1.0.1

+ 0 - 2
go.sum

@@ -51,8 +51,6 @@ github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuy
 github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
 github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
 github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
-github.com/allanpk716/ChineseSubModels v0.0.3 h1:GqNzuak+1vu+llqRul6n9r85cMK38iT3mkT9pF815+o=
-github.com/allanpk716/ChineseSubModels v0.0.3/go.mod h1:4Yd7MJ5jPxCKSHUJkJT8wlrC8wj2Rh5D4yLtXAEp1uE=
 github.com/allanpk716/fake-useragent v0.2.1 h1:5EurHovAMGNwMZNbZ2cFOH8HsLdHwopnnKWCsV3PtNI=
 github.com/allanpk716/fake-useragent v0.2.1/go.mod h1:U3tmrxBYvSPeQKQ/9x59CXJPkHbU4x4eXw3ji5TDhPk=
 github.com/allanpk716/go-parse-torrent-name v0.0.0-20220212145434-430ea25cbba7 h1:5AYgeYsVjtDPG5sUS77lyeEPiRMduIKstLjkBLiVPRc=

+ 1 - 2
internal/dao/init.go

@@ -7,7 +7,6 @@ import (
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/log_helper"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/my_folder"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/my_util"
-	gModels "github.com/allanpk716/ChineseSubModels/models"
 	"gorm.io/driver/sqlite"
 	"gorm.io/gorm"
 	"os"
@@ -69,7 +68,7 @@ func InitDb() error {
 	}
 	// 迁移 schema
 	err = db.AutoMigrate(&models.HotFix{}, &models.SubFormatRec{},
-		&gModels.IMDBInfo{}, &gModels.VideoSubInfo{})
+		&models.IMDBInfo{}, &models.VideoSubInfo{})
 	if err != nil {
 		return errors.New(fmt.Sprintf("db AutoMigrate error, %s", err.Error()))
 	}

+ 1 - 1
internal/logic/scan_played_video_subinfo/scan_played_video_subinfo.go

@@ -8,6 +8,7 @@ import (
 	embyHelper "github.com/allanpk716/ChineseSubFinder/internal/logic/emby_helper"
 	"github.com/allanpk716/ChineseSubFinder/internal/logic/sub_parser/ass"
 	"github.com/allanpk716/ChineseSubFinder/internal/logic/sub_parser/srt"
+	"github.com/allanpk716/ChineseSubFinder/internal/models"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/decode"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/imdb_helper"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/language"
@@ -22,7 +23,6 @@ import (
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/task_control"
 	"github.com/allanpk716/ChineseSubFinder/internal/types"
 	"github.com/allanpk716/ChineseSubFinder/internal/types/common"
-	"github.com/allanpk716/ChineseSubModels/models"
 	"github.com/sirupsen/logrus"
 	"golang.org/x/net/context"
 	"os"

+ 2 - 2
internal/logic/series_helper/seriesHelper.go

@@ -5,6 +5,7 @@ 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/models"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/decode"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/imdb_helper"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/log_helper"
@@ -16,7 +17,6 @@ import (
 	"github.com/allanpk716/ChineseSubFinder/internal/types/emby"
 	"github.com/allanpk716/ChineseSubFinder/internal/types/series"
 	"github.com/allanpk716/ChineseSubFinder/internal/types/supplier"
-	gModels "github.com/allanpk716/ChineseSubModels/models"
 	"github.com/emirpasic/gods/maps/treemap"
 	"github.com/jinzhu/now"
 	"path/filepath"
@@ -133,7 +133,7 @@ func ReadSeriesInfoFromEmby(seriesDir string, seriesVideoList []emby.EmbyMixInfo
 }
 
 // SkipChineseSeries 跳过中文连续剧
-func SkipChineseSeries(seriesRootPath string, _proxySettings ...*settings.ProxySettings) (bool, *gModels.IMDBInfo, error) {
+func SkipChineseSeries(seriesRootPath string, _proxySettings ...*settings.ProxySettings) (bool, *models.IMDBInfo, error) {
 
 	imdbInfo, err := decode.GetImdbInfo4SeriesDir(seriesRootPath)
 	if err != nil {

+ 6 - 0
internal/models/imdb_aka.go

@@ -0,0 +1,6 @@
+package models
+
+type IMDBAKA struct {
+	AKA        string `json:"aka" binding:"required"`
+	IMDBInfoID uint   `json:"imdb_info_id" binding:"required"`
+}

+ 15 - 0
internal/models/imdb_info.go

@@ -0,0 +1,15 @@
+package models
+
+type IMDBInfo struct {
+	IMDBID        string         `gorm:"primaryKey" json:"imdb_id"  binding:"required"`                   // IMDB ID
+	Name          string         `json:"name" binding:"required"`                                         // 视频名称
+	Year          int            `gorm:"default:0" json:"year"  binding:"required"`                       // 发布的时间
+	Description   string         `json:"description"  binding:"required"`                                 // 描述
+	Languages     StringList     `gorm:"type:varchar(255);not null" json:"languages"  binding:"required"` // 语言
+	AKA           StringList     `gorm:"type:varchar(255);not null" json:"AKA"  binding:"required"`       // 又名 xx xxx
+	VideoSubInfos []VideoSubInfo `gorm:"foreignKey:IMDBInfoID"`                                           // 视频对应的字幕,外键约束
+}
+
+func NewIMDBInfo(IMDBID string, name string, year int, description string, languages StringList, AKA StringList) *IMDBInfo {
+	return &IMDBInfo{IMDBID: IMDBID, Name: name, Year: year, Description: description, Languages: languages, AKA: AKA, VideoSubInfos: make([]VideoSubInfo, 0)}
+}

+ 6 - 0
internal/models/imdb_language.go

@@ -0,0 +1,6 @@
+package models
+
+type IMDBLanguage struct {
+	Language   string `json:"language" binding:"required"`
+	IMDBInfoID uint   `json:"imdb_info_id" binding:"required"`
+}

+ 16 - 0
internal/models/string_array.go

@@ -0,0 +1,16 @@
+package models
+
+import (
+	"database/sql/driver"
+	"encoding/json"
+)
+
+type StringList []string
+
+func (p StringList) Value() (driver.Value, error) {
+	return json.Marshal(p)
+}
+
+func (p *StringList) Scan(data interface{}) error {
+	return json.Unmarshal(data.([]byte), &p)
+}

+ 22 - 0
internal/models/video_sub_info.go

@@ -0,0 +1,22 @@
+package models
+
+// VideoSubInfo 属于 IMDBInfo,IMDBInfoID 是外键,使用了 GORM 的 HasMany 关联
+type VideoSubInfo struct {
+	Feature      string `gorm:"primaryKey" json:"feature"  binding:"required"` // 特征码,这个未必有,比如是蓝光格式,分散成多个视频文件的时候,暂定使用本程序的特征提前方式
+	SubName      string `json:"sub_name" binding:"required"`                   // 字幕的文件名
+	Season       int    `json:"season"`                                        // 如果对应的是电影则可能是 0,没有
+	Episode      int    `json:"episode"`                                       // 如果对应的是电影则可能是 0,没有
+	LanguageISO  string `json:"language_iso" binding:"required"`               // 字幕的语言,目标语言,就算是双语,中英,也应该是中文。ISO_639-1_codes 标准,见 ISOLanguage.go 文件,这里无法区分简体繁体
+	IsDouble     bool   `json:"is_double" binding:"required"`                  // 是否是双语,上面是主体语言,比如是中文,
+	ChineseISO   string `json:"chinese_iso" binding:"required"`                // 中文语言编码变种,见 ISOLanguage.go 文件,这里区分简体、繁体等,如果语言是非中文则这里是空
+	MyLanguage   string `json:"my_language" binding:"required"`                // 这个是本程序定义的语言类型,见 my_language.go 文件
+	StoreRPath   string `json:"store_r_path"`                                  // 字幕存在出本地的哪里相对路径上,cache/CSF-ShareSubCache
+	ExtraPreName string `json:"extra_pre_name" binding:"required"`             // 字幕额外的命名信息,指 Emby 字幕命名格式(简英,subhd),的 subhd
+	SHA256       string `json:"sha_256" binding:"required"`                    // 当前文件的 sha256 的值
+	IsSend       bool   `json:"is_send"`                                       // 是否已经发送
+	IMDBInfoID   string `json:"imdb_info_id"  binding:"required"`              // IMDB ID
+}
+
+func NewVideoSubInfo(feature string, subName string, languageISO string, isDouble bool, chineseISO string, myLanguage string, storeFPath string, extraPreName string, sha256String string) *VideoSubInfo {
+	return &VideoSubInfo{Feature: feature, SubName: subName, LanguageISO: languageISO, IsDouble: isDouble, ChineseISO: chineseISO, MyLanguage: myLanguage, StoreRPath: storeFPath, ExtraPreName: extraPreName, SHA256: sha256String}
+}

+ 0 - 1
internal/pkg/hot_fix/hot_fix_002.go

@@ -3,7 +3,6 @@ package hot_fix
 import (
 	"github.com/allanpk716/ChineseSubFinder/internal/dao"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/log_helper"
-	"github.com/allanpk716/ChineseSubModels/models"
 )
 
 /*

+ 7 - 7
internal/pkg/imdb_helper/imdb.go

@@ -4,10 +4,10 @@ import (
 	"crypto/tls"
 	"github.com/StalkR/imdb"
 	"github.com/allanpk716/ChineseSubFinder/internal/dao"
+	"github.com/allanpk716/ChineseSubFinder/internal/models"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/log_helper"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/notify_center"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/settings"
-	gModels "github.com/allanpk716/ChineseSubModels/models"
 	"net/http"
 	"net/url"
 	"strings"
@@ -51,14 +51,14 @@ func GetVideoInfoFromIMDBWeb(imdbID string, _proxySettings ...*settings.ProxySet
 }
 
 // GetVideoIMDBInfoFromLocal 从本地获取 IMDB 信息,如果找不到则去网络获取并写入本地缓存
-func GetVideoIMDBInfoFromLocal(imdbID string, _proxySettings ...*settings.ProxySettings) (*gModels.IMDBInfo, error) {
+func GetVideoIMDBInfoFromLocal(imdbID string, _proxySettings ...*settings.ProxySettings) (*models.IMDBInfo, error) {
 
 	log_helper.GetLogger().Debugln("GetVideoIMDBInfoFromLocal", 0)
 
 	// 首先从数据库中查找是否存在这个 IMDB 信息,如果不存在再使用 Web 查找,且写入数据库
-	var imdbInfos []gModels.IMDBInfo
+	var imdbInfos []models.IMDBInfo
 	// 把嵌套关联的 has many 的信息都查询出来
-	dao.GetDb().Preload("VideoSubInfos").Limit(1).Where(&gModels.IMDBInfo{IMDBID: imdbID}).Find(&imdbInfos)
+	dao.GetDb().Preload("VideoSubInfos").Limit(1).Where(&models.IMDBInfo{IMDBID: imdbID}).Find(&imdbInfos)
 
 	log_helper.GetLogger().Debugln("GetVideoIMDBInfoFromLocal", 1)
 
@@ -71,8 +71,8 @@ func GetVideoIMDBInfoFromLocal(imdbID string, _proxySettings ...*settings.ProxyS
 		log_helper.GetLogger().Debugln("GetVideoIMDBInfoFromLocal", 2)
 
 		// 存入数据库
-		nowIMDBInfo := gModels.NewIMDBInfo(imdbID, t.Name, t.Year, t.Description, t.Languages, t.AKA)
-		imdbInfos = make([]gModels.IMDBInfo, 0)
+		nowIMDBInfo := models.NewIMDBInfo(imdbID, t.Name, t.Year, t.Description, t.Languages, t.AKA)
+		imdbInfos = make([]models.IMDBInfo, 0)
 		imdbInfos = append(imdbInfos, *nowIMDBInfo)
 		dao.GetDb().Create(nowIMDBInfo)
 
@@ -88,7 +88,7 @@ func GetVideoIMDBInfoFromLocal(imdbID string, _proxySettings ...*settings.ProxyS
 }
 
 // IsChineseVideo 从 imdbID 去查询判断是否是中文视频
-func IsChineseVideo(imdbID string, _proxySettings ...*settings.ProxySettings) (bool, *gModels.IMDBInfo, error) {
+func IsChineseVideo(imdbID string, _proxySettings ...*settings.ProxySettings) (bool, *models.IMDBInfo, error) {
 
 	const chName0 = "chinese"
 	const chName1 = "mandarin"