1
0

main.go 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. package main
  2. import (
  3. commonValue "github.com/allanpk716/ChineseSubFinder/internal/common"
  4. config2 "github.com/allanpk716/ChineseSubFinder/internal/pkg/config"
  5. "github.com/allanpk716/ChineseSubFinder/internal/pkg/hot_fix"
  6. "github.com/allanpk716/ChineseSubFinder/internal/pkg/log_helper"
  7. "github.com/allanpk716/ChineseSubFinder/internal/pkg/my_util"
  8. "github.com/allanpk716/ChineseSubFinder/internal/pkg/notify_center"
  9. "github.com/allanpk716/ChineseSubFinder/internal/pkg/rod_helper"
  10. "github.com/allanpk716/ChineseSubFinder/internal/pkg/sub_formatter"
  11. "github.com/allanpk716/ChineseSubFinder/internal/pkg/sub_formatter/common"
  12. "github.com/allanpk716/ChineseSubFinder/internal/pkg/url_connectedness_helper"
  13. "github.com/allanpk716/ChineseSubFinder/internal/types"
  14. "github.com/prometheus/common/log"
  15. "github.com/robfig/cron/v3"
  16. "github.com/sirupsen/logrus"
  17. )
  18. func init() {
  19. log.Infoln("ChineseSubFinder Version:", AppVersion)
  20. if my_util.OSCheck() == false {
  21. panic(`You should search runtime.GOOS in the project, Implement unimplemented function`)
  22. }
  23. }
  24. func main() {
  25. if log == nil {
  26. panic("log init error")
  27. }
  28. if config == nil {
  29. panic("read config error")
  30. }
  31. httpProxy := config.HttpProxy
  32. if config.UseProxy == false {
  33. httpProxy = ""
  34. }
  35. if config.UseProxy == false {
  36. log.Infoln("UseProxy = false")
  37. } else {
  38. log.Infoln("UseProxy:", httpProxy)
  39. proxySpeed, proxyStatus, err := url_connectedness_helper.UrlConnectednessTest(httpProxy)
  40. if err != nil {
  41. log.Errorln("UrlConnectednessTest Target Site http://google.com", err)
  42. return
  43. } else {
  44. log.Infoln("UrlConnectednessTest Target Site http://google.com", "Speed:", proxySpeed, "Status:", proxyStatus)
  45. }
  46. }
  47. // 判断文件夹是否存在
  48. if my_util.IsDir(config.MovieFolder) == false {
  49. log.Errorln("MovieFolder not found --", config.MovieFolder)
  50. return
  51. }
  52. if my_util.IsDir(config.SeriesFolder) == false {
  53. log.Errorln("SeriesFolder not found --", config.SeriesFolder)
  54. return
  55. }
  56. // 读取到的文件夹信息展示
  57. log.Infoln("MovieFolder:", config.MovieFolder)
  58. log.Infoln("SeriesFolder:", config.SeriesFolder)
  59. // ------ Hot Fix Start ------
  60. // 开始修复
  61. log.Infoln("HotFix Start, wait ...")
  62. log.Infoln(commonValue.NotifyStringTellUserWait)
  63. err := hot_fix.HotFixProcess(types.HotFixParam{
  64. MovieRootDir: config.MovieFolder,
  65. SeriesRootDir: config.SeriesFolder,
  66. })
  67. if err != nil {
  68. log.Errorln("HotFixProcess()", err)
  69. log.Infoln("HotFix End")
  70. return
  71. }
  72. log.Infoln("HotFix End")
  73. // ------ Hot Fix End ------
  74. // ------ Change SubName Format Start ------
  75. /*
  76. 字幕命名格式转换,需要数据库支持
  77. 如果数据库没有记录经过转换,那么默认从 Emby 的格式作为检测的起点,转换到目标的格式
  78. 然后需要在数据库中记录本次的转换结果
  79. */
  80. log.Infoln("Change Sub Name Format Start...")
  81. log.Infoln(commonValue.NotifyStringTellUserWait)
  82. renameResults, err := sub_formatter.SubFormatChangerProcess(config.MovieFolder, config.SeriesFolder, common.FormatterName(config.SubNameFormatter))
  83. // 出错的文件有哪一些
  84. for s, i := range renameResults.ErrFiles {
  85. log_helper.GetLogger().Errorln("reformat ErrFile:"+s, i)
  86. }
  87. if err != nil {
  88. log.Errorln("SubFormatChangerProcess()", err)
  89. return
  90. }
  91. log.Infoln("Change Sub Name Format End")
  92. // ------ Change SubName Format End ------
  93. // 初始化通知缓存模块
  94. notify_center.Notify = notify_center.NewNotifyCenter(config.WhenSubSupplierInvalidWebHook)
  95. log.Infoln("ReloadBrowser Start...")
  96. // ReloadBrowser 提前把浏览器下载好
  97. rod_helper.ReloadBrowser()
  98. log.Infoln("ReloadBrowser End")
  99. // 任务还没执行完,下一次执行时间到来,下一次执行就跳过不执行
  100. c := cron.New(cron.WithChain(cron.SkipIfStillRunning(cron.DefaultLogger)))
  101. // 定时器
  102. entryID, err := c.AddFunc("@every "+config.EveryTime, func() {
  103. DownLoadStart(httpProxy)
  104. })
  105. if err != nil {
  106. log.Errorln("cron entryID:", entryID, "Error:", err)
  107. return
  108. }
  109. if config.RunAtStartup == true {
  110. log.Infoln("First Time Download Start")
  111. DownLoadStart(httpProxy)
  112. log.Infoln("First Time Download End")
  113. } else {
  114. log.Infoln("config.yaml set RunAtStartup: false, so will not Run At Startup, wait", config.EveryTime, "to Download")
  115. }
  116. c.Start()
  117. // 阻塞
  118. select {}
  119. }
  120. func DownLoadStart(httpProxy string) {
  121. }
  122. /*
  123. 没有很好的想法,因为喜欢使用 tag 进行版本的输出标记,但是 tag 的时候编译 docker 前确实可以修改源码替换关键词做到版本与 tag 同步变更
  124. 但是, goreleaser 却不支持这样,会提示源码被改了,无法进行编译发布
  125. 除非不发布、编译 Linux 和 Windows 程序,这样就能做到 tag 与 程序内部输出版本一致。
  126. */
  127. var AppVersion = "unknow"