From 7af7eeec776a400eec6493e8a0adb4f3c982addf Mon Sep 17 00:00:00 2001 From: M1andy's debian Date: Wed, 17 Aug 2022 16:31:34 +0800 Subject: [PATCH] init projects --- .gitignore | 3 + MovieDataCapture.code-workspace | 8 ++ config.ini | 139 ++++++++++++++++++++++++++++++++ go.mod | 5 ++ go.sum | 2 + main.go | 16 ++++ test.ini | 39 +++++++++ utils/config.go | 135 +++++++++++++++++++++++++++++++ 8 files changed, 347 insertions(+) create mode 100644 .gitignore create mode 100644 MovieDataCapture.code-workspace create mode 100644 config.ini create mode 100644 go.mod create mode 100644 go.sum create mode 100644 main.go create mode 100644 test.ini create mode 100644 utils/config.go diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0ea4ebc --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +.vscode +Movie_Data_Capture_python +bin \ No newline at end of file diff --git a/MovieDataCapture.code-workspace b/MovieDataCapture.code-workspace new file mode 100644 index 0000000..876a149 --- /dev/null +++ b/MovieDataCapture.code-workspace @@ -0,0 +1,8 @@ +{ + "folders": [ + { + "path": "." + } + ], + "settings": {} +} \ No newline at end of file diff --git a/config.ini b/config.ini new file mode 100644 index 0000000..61e19cc --- /dev/null +++ b/config.ini @@ -0,0 +1,139 @@ +# 详细教程请看 +# - https://github.com/yoshiko2/Movie_Data_Capture/wiki#%E9%85%8D%E7%BD%AEconfigini +[common] +main_mode=1 +source_folder=./ +failed_output_folder=failed +success_output_folder=JAV_output +link_mode=0 +; 0: 不刮削硬链接文件 1: 刮削硬链接文件 +scan_hardlink=0 +failed_move=0 +auto_exit=0 +translate_to_sc=0 +multi_threading=0 +;actor_gender value: female(♀) or male(♂) or both(♀ ♂) or all(♂ ♀ ⚧) +actor_gender=female +del_empty_folder=1 +; 跳过最近(默认:30)天新修改过的.NFO,可避免整理模式(main_mode=3)和软连接(soft_link=0)时 +; 反复刮削靠前的视频文件,0为处理所有视频文件 +nfo_skip_days=30 +ignore_failed_list=0 +download_only_missing_images=1 +mapping_table_validity=7 +sleep=3 + +[advenced_sleep] +; 处理完多少个视频文件后停止,0为处理所有视频文件 +stop_counter=0 +; 再运行延迟时间,单位:h时m分s秒 举例: 1h30m45s(1小时30分45秒) 45(45秒) +; stop_counter不为零的条件下才有效,每处理stop_counter部影片后延迟rerun_delay秒再次运行 +rerun_delay=0 +; 以上参数配合使用可以以多次少量的方式刮削或整理数千个文件而不触发翻译或元数据站封禁 + +[proxy] +;proxytype: http or socks5 or socks5h switch: 0 1 +switch=0 +type=socks5h +proxy=127.0.0.1:1080 +timeout=20 +retry=3 +cacert_file= + +[Name_Rule] +location_rule=actor+'/'+number +naming_rule=number+'-'+title +max_title_len=50 + +[update] +update_check=1 + +[priority] +website=javbus,airav,jav321,fanza,xcity,mgstage,fc2,avsox,dlsite,carib,madou,mv91,getchu,javdb,gcolle + +[escape] +literals=\()/ +folders=failed,JAV_output + +[debug_mode] +switch=0 + +; 机器翻译 +[translate] +switch=0 +;可选项 google-free,azure +engine=google-free +; azure翻译密钥 +key= +; 翻译延迟 +delay=1 +values=title,outline +service_site=translate.google.cn + +; 预告片 +[trailer] +switch=0 + +; 用来确定是否是无码 +[uncensored] +uncensored_prefix=S2M,BT,LAF,SMD,SMBD,SM3D2DBD,SKY-,SKYHD,CWP,CWDV,CWBD,CW3D2DBD,MKD,MKBD,MXBD,MK3D2DBD,MCB3DBD,MCBD,RHJ,MMDV + +[media] +; 影片后缀 +media_type=.mp4,.avi,.rmvb,.wmv,.mov,.mkv,.flv,.ts,.webm,.iso,.mpg,.m4v +; 字幕后缀 +sub_type=.smi,.srt,.idx,.sub,.sup,.psb,.ssa,.ass,.usf,.xss,.ssf,.rt,.lrc,.sbv,.vtt,.ttml + +; 水印 +[watermark] +switch=1 +water=2 +; 左上 0, 右上 1, 右下 2, 左下 3 + +; 剧照 +[extrafanart] +switch=1 +parallel_download=5 +extrafanart_folder=extrafanart + +; 剧情简介 +[storyline] +switch=1 +; website为javbus javdb avsox xcity carib时,site censored_site uncensored_site 为获取剧情简介信息的 +; 可选数据源站点列表。列表内站点同时并发查询,取值优先级由冒号前的序号决定,从小到大,数字小的站点没数据才会采用后面站点获得的。 +; 其中airavwiki airav avno1 58avgo是中文剧情简介,区别是airav只能查有码,avno1 airavwiki 有码无码都能查, +; 58avgo只能查无码或者流出破解马赛克的影片(此功能没使用)。 +; xcity和amazon是日语的,由于amazon商城没有番号信息,选中对应DVD的准确率仅99.6%。如果三个列表全部为空则不查询, +; 设置成不查询可大幅提高刮削速度。 +; site= +site=1:avno1,4:airavwiki +censored_site=2:airav,5:xcity,6:amazon +uncensored_site=3:58avgo +; 运行模式:0:顺序执行(最慢) 1:线程池(默认值) 2:进程池(启动开销比线程池大,并发站点越多越快) +run_mode=1 +; show_result剧情简介调试信息 0关闭 1简略 2详细(详细部分不记入日志),剧情简介失效时可打开2查看原因 +show_result=0 + +; 繁简转换 繁简转换模式mode=0:不转换 1:繁转简 2:简转繁 +[cc_convert] +mode=1 +vars=outline,series,studio,tag,title + +[javdb] +sites=38,39,40 + +; 人脸识别 locations_model=hog:方向梯度直方图(不太准确,速度快) cnn:深度学习模型(准确,需要GPU/CUDA,速度慢) +; uncensored_only=0:对全部封面进行人脸识别 1:只识别无码封面,有码封面直接切右半部分 +; aways_imagecut=0:按各网站默认行为 1:总是裁剪封面,开启此项将无视[common]download_only_missing_images=1总是覆盖封面 +; 封面裁剪的宽高比可配置,公式为aspect_ratio/3。默认aspect_ratio=2.12: 适配大部分有码影片封面,前一版本默认为2/3即aspect_ratio=2 +[face] +locations_model=hog +uncensored_only=1 +aways_imagecut=0 +aspect_ratio=2.12 + +[jellyfin] +multi_part_fanart=0 + +[actor_photo] +download_for_kodi=0 diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..cef5d93 --- /dev/null +++ b/go.mod @@ -0,0 +1,5 @@ +module MovieDataCapture + +go 1.19 + +require gopkg.in/ini.v1 v1.67.0 // indirect diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..a8937af --- /dev/null +++ b/go.sum @@ -0,0 +1,2 @@ +gopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA= +gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= diff --git a/main.go b/main.go new file mode 100644 index 0000000..70d5176 --- /dev/null +++ b/main.go @@ -0,0 +1,16 @@ +package main + +import ( + "MovieDataCapture/utils" + "fmt" + "log" +) + +func main() { + config, err := utils.LoadConfig() + if err != nil { + log.Fatalf("load config error: %v", err) + } + fmt.Printf("%v\n", config) + +} diff --git a/test.ini b/test.ini new file mode 100644 index 0000000..f212188 --- /dev/null +++ b/test.ini @@ -0,0 +1,39 @@ +[common] +main_mode=1 +source_folder=./ +failed_output_folder=failed +success_output_folder=JAV_output +link_mode=0 +; 0: 不刮削硬链接文件 1: 刮削硬链接文件 +scan_hardlink=0 +failed_move=0 +auto_exit=0 +translate_to_sc=0 +multi_threading=0 +;actor_gender value: female(♀) or male(♂) or both(♀ ♂) or all(♂ ♀ ⚧) +actor_gender=female +del_empty_folder=1 +; 跳过最近(默认:30)天新修改过的.NFO,可避免整理模式(main_mode=3)和软连接(soft_link=0)时 +; 反复刮削靠前的视频文件,0为处理所有视频文件 +nfo_skip_days=30 +ignore_failed_list=0 +download_only_missing_images=1 +mapping_table_validity=7 +sleep=3 + +[advanced_sleep] +; 处理完多少个视频文件后停止,0为处理所有视频文件 +stop_counter=0 +; 再运行延迟时间,单位:h时m分s秒 举例: 1h30m45s(1小时30分45秒) 45(45秒) +; stop_counter不为零的条件下才有效,每处理stop_counter部影片后延迟rerun_delay秒再次运行 +rerun_delay=0 +; 以上参数配合使用可以以多次少量的方式刮削或整理数千个文件而不触发翻译或元数据站封禁 + +[proxy] +;proxytype: http or socks5 or socks5h switch: 0 1 +switch=0 +type=socks5h +proxy=127.0.0.1:1080 +timeout=20 +retry=3 +cacert_file= \ No newline at end of file diff --git a/utils/config.go b/utils/config.go new file mode 100644 index 0000000..5143d90 --- /dev/null +++ b/utils/config.go @@ -0,0 +1,135 @@ +package utils + +import ( + "fmt" + "os" + "path" + "time" + + "gopkg.in/ini.v1" +) + +var loadConfigOptions = ini.LoadOptions{ + IgnoreInlineComment: true, +} + +// config里位于common分区里的设置 +type commonConfig struct { + MainMode int `ini:"main_mode"` + SourceFolder string `ini:"source_folder"` + FailedFolder string `ini:"failed_output_folder"` + SuccessFolder string `ini:"success_output_folder"` + LinkMode bool `ini:"link_mode"` + ScanHardLink bool `ini:"scan_hardlink"` + Auto_exit bool `ini:"auto_exit"` + TranslateToSC bool `ini:"translate_to_sc"` + MultiThreading bool `ini:"multi_threading"` + ActorGender string `ini:"actor_gender"` + DelEmptyFolder bool `ini:"del_empty_folder"` + NfoSkipDays int `ini:"nfo_skip_days"` + IgnoreFailedList bool `ini:"ignore_failed_list"` + DownloadOnlyMissingFiles bool `ini:"download_only_missing_images"` + MappingTableValidity int `ini:"mapping_table_validity"` + Sleep int `ini:"sleep"` +} + +// config里位于advanced_sleep分区里的设置 +type advancedSleepConfig struct { + StopCounter int `ini:"stop_counter"` + RerunDelay time.Time `ini:"rerun_delay"` +} + +// config里位于Proxy分区里的设置 +type proxyConfig struct { + ProxySwitch bool `ini:"switch"` + ProxyType string `ini:"type"` + Host string `ini:"proxy"` + Timeout int `ini:"timeout"` + RetryCount int `ini:"retry"` + CacertFile string `ini:"cacert_file"` +} + +type Config struct { + Common commonConfig + AdvancedSleep advancedSleepConfig + Proxy proxyConfig +} + +func PathExists(path string) (bool, error) { + _, err := os.Stat(path) + if err == nil { + return true, nil + } + if os.IsNotExist(err) { + return false, nil + } + return false, err +} + +func GenerateConfigPath() ([]string, error) { + var SearchPath []string + homePath, err := os.UserHomeDir() + if err != nil { + return nil, fmt.Errorf("get user home directory failed: %v", err) + } + + currentPath, err := os.Getwd() + if err != nil { + return nil, fmt.Errorf("get current home directory failed: %v", err) + } + + // 添加搜索config的路径 + // SearchPath = append(SearchPath, path.Join(currentPath, "config.ini")) + SearchPath = append(SearchPath, path.Join(currentPath, "config.ini")) + SearchPath = append(SearchPath, path.Join(homePath, "mdc.ini")) + SearchPath = append(SearchPath, path.Join(homePath, ".mdc.ini")) + SearchPath = append(SearchPath, path.Join(homePath, ".mdc/config.ini")) + SearchPath = append(SearchPath, path.Join(homePath, ".config/mdc/config.ini")) + + return SearchPath, nil +} + +func mapConfig(config *Config, rawData *ini.File) error { + if err := rawData.Section("common").MapTo(&config.Common); err != nil { + return fmt.Errorf("mapping config error: %v", err) + } + if err := rawData.Section("advanced_sleep").MapTo(&config.AdvancedSleep); err != nil { + return fmt.Errorf("mapping config error: %v", err) + } + if err := rawData.Section("proxy").MapTo(&config.Proxy); err != nil { + return fmt.Errorf("mapping config error: %v", err) + } + return nil +} + +func LoadConfig() (*Config, error) { + paths, err := GenerateConfigPath() + if err != nil { + return nil, err + } + + var config = new(Config) + var path string + + for _, path = range paths { + if ok, err := PathExists(path); ok { + break + } else { + return nil, err + } + } + rawData, err := ini.LoadSources(loadConfigOptions, path) + if err != nil { + return nil, fmt.Errorf("loading config error: %v", err) + } + + if err := mapConfig(config, rawData); err != nil { + return nil, err + } + + return config, nil + +} + +func init() { +}