diff --git a/server/core/client.go b/engine/client.go similarity index 87% rename from server/core/client.go rename to engine/client.go index 5297e2b..c9bfed4 100644 --- a/server/core/client.go +++ b/engine/client.go @@ -1,4 +1,4 @@ -package core +package engine import ( "polaris/db" @@ -16,8 +16,8 @@ import ( "github.com/robfig/cron" ) -func NewClient(db *db.Client, language string) *Client { - return &Client{ +func NewEngine(db *db.Client, language string) *Engine { + return &Engine{ db: db, cron: cron.New(), tasks: make(map[int]*Task, 0), @@ -29,7 +29,7 @@ type scheduler struct { cron string f func() error } -type Client struct { +type Engine struct { db *db.Client cron *cron.Cron tasks map[int]*Task @@ -37,20 +37,20 @@ type Client struct { schedulers utils.Map[string, scheduler] } -func (c *Client) registerCronJob(name string, cron string, f func() error) { +func (c *Engine) registerCronJob(name string, cron string, f func() error) { c.schedulers.Store(name, scheduler{ cron: cron, f: f, }) } -func (c *Client) Init() { +func (c *Engine) Init() { go c.reloadTasks() c.addSysCron() go c.checkW500PosterOnStartup() } -func (c *Client) reloadTasks() { +func (c *Engine) reloadTasks() { allTasks := c.db.GetRunningHistories() for _, t := range allTasks { dl, err := c.db.GetDownloadClient(t.DownloadClientID) @@ -115,12 +115,12 @@ func (c *Client) reloadTasks() { log.Infof("------ task reloading done ------") } -func (c *Client) buildInDownloader() (pkg.Downloader, error) { +func (c *Engine) buildInDownloader() (pkg.Downloader, error) { dir := c.db.GetDownloadDir() return buildin.NewDownloader(dir) } -func (c *Client) GetDownloadClient() (pkg.Downloader, *ent.DownloadClients, error) { +func (c *Engine) GetDownloadClient() (pkg.Downloader, *ent.DownloadClients, error) { downloaders := c.db.GetAllDonloadClients() for _, d := range downloaders { if !d.Enable { @@ -158,7 +158,7 @@ func (c *Client) GetDownloadClient() (pkg.Downloader, *ent.DownloadClients, erro return nil, nil, errors.Errorf("no available download client") } -func (c *Client) TMDB() (*tmdb.Client, error) { +func (c *Engine) TMDB() (*tmdb.Client, error) { api := c.db.GetTmdbApiKey() if api == "" { return nil, errors.New("TMDB apiKey not set") @@ -168,7 +168,7 @@ func (c *Client) TMDB() (*tmdb.Client, error) { return tmdb.NewClient(api, proxy, adult == "true") } -func (c *Client) MustTMDB() *tmdb.Client { +func (c *Engine) MustTMDB() *tmdb.Client { t, err := c.TMDB() if err != nil { log.Panicf("get tmdb: %v", err) @@ -176,7 +176,7 @@ func (c *Client) MustTMDB() *tmdb.Client { return t } -func (c *Client) RemoveTaskAndTorrent(id int) error { +func (c *Engine) RemoveTaskAndTorrent(id int) error { torrent := c.tasks[id] if torrent != nil { if err := torrent.Remove(); err != nil { @@ -187,6 +187,6 @@ func (c *Client) RemoveTaskAndTorrent(id int) error { return nil } -func (c *Client) GetTasks() map[int]*Task { +func (c *Engine) GetTasks() map[int]*Task { return c.tasks } diff --git a/engine/fliters.go b/engine/fliters.go new file mode 100644 index 0000000..00a22ef --- /dev/null +++ b/engine/fliters.go @@ -0,0 +1 @@ +package engine diff --git a/server/core/importlist.go b/engine/importlist.go similarity index 91% rename from server/core/importlist.go rename to engine/importlist.go index e807eeb..09618b6 100644 --- a/server/core/importlist.go +++ b/engine/importlist.go @@ -1,4 +1,4 @@ -package core +package engine import ( "bytes" @@ -25,7 +25,7 @@ import ( "github.com/pkg/errors" ) -func (c *Client) periodicallyUpdateImportlist() error { +func (c *Engine) periodicallyUpdateImportlist() error { log.Infof("begin check import list") lists, err := c.db.GetAllImportLists() if err != nil { @@ -119,7 +119,7 @@ type AddWatchlistIn struct { PreferSize int64 `json:"prefer_size"` } -func (c *Client) AddTv2Watchlist(in AddWatchlistIn) (interface{}, error) { +func (c *Engine) AddTv2Watchlist(in AddWatchlistIn) (interface{}, error) { log.Debugf("add tv watchlist input %+v", in) if in.Folder == "" { return nil, errors.New("folder should be provided") @@ -200,7 +200,7 @@ func (c *Client) AddTv2Watchlist(in AddWatchlistIn) (interface{}, error) { epIds = append(epIds, epid) } } - + m := &ent.Media{ TmdbID: int(detail.ID), ImdbID: detail.IMDbID, @@ -247,7 +247,7 @@ func (c *Client) AddTv2Watchlist(in AddWatchlistIn) (interface{}, error) { return nil, nil } -func (c *Client) getAlterTitles(tmdbId int, mediaType media.MediaType) ([]schema.AlternativeTilte, error){ +func (c *Engine) getAlterTitles(tmdbId int, mediaType media.MediaType) ([]schema.AlternativeTilte, error) { var titles []schema.AlternativeTilte if mediaType == media.MediaTypeTv { @@ -255,26 +255,26 @@ func (c *Client) getAlterTitles(tmdbId int, mediaType media.MediaType) ([]schema if err != nil { return nil, errors.Wrap(err, "tmdb") } - + for _, t := range alterTitles.Results { titles = append(titles, schema.AlternativeTilte{ Iso3166_1: t.Iso3166_1, - Title: t.Title, - Type: t.Type, + Title: t.Title, + Type: t.Type, }) } - + } else if mediaType == media.MediaTypeMovie { alterTitles, err := c.MustTMDB().GetMovieAlternativeTitles(tmdbId, c.language) if err != nil { return nil, errors.Wrap(err, "tmdb") } - + for _, t := range alterTitles.Titles { titles = append(titles, schema.AlternativeTilte{ Iso3166_1: t.Iso3166_1, - Title: t.Title, - Type: t.Type, + Title: t.Title, + Type: t.Type, }) } } @@ -283,7 +283,7 @@ func (c *Client) getAlterTitles(tmdbId int, mediaType media.MediaType) ([]schema return titles, nil } -func (c *Client) AddMovie2Watchlist(in AddWatchlistIn) (interface{}, error) { +func (c *Engine) AddMovie2Watchlist(in AddWatchlistIn) (interface{}, error) { log.Infof("add movie watchlist input: %+v", in) detailCn, err := c.MustTMDB().GetMovieDetails(in.TmdbID, db.LanguageCN) if err != nil { @@ -306,7 +306,6 @@ func (c *Client) AddMovie2Watchlist(in AddWatchlistIn) (interface{}, error) { return nil, errors.Wrap(err, "get alter titles") } - epid, err := c.db.SaveEposideDetail(&ent.Episode{ SeasonNumber: 1, EpisodeNumber: 1, @@ -321,18 +320,18 @@ func (c *Client) AddMovie2Watchlist(in AddWatchlistIn) (interface{}, error) { log.Infof("added dummy episode for movie: %v", nameEn) movie := ent.Media{ - TmdbID: int(detail.ID), - ImdbID: detail.IMDbID, - MediaType: media.MediaTypeMovie, - NameCn: nameCn, - NameEn: nameEn, - OriginalName: detail.OriginalTitle, - Overview: detail.Overview, - AirDate: detail.ReleaseDate, - Resolution: media.Resolution(in.Resolution), - StorageID: in.StorageID, - TargetDir: in.Folder, - Limiter: schema.MediaLimiter{SizeMin: in.SizeMin, SizeMax: in.SizeMax}, + TmdbID: int(detail.ID), + ImdbID: detail.IMDbID, + MediaType: media.MediaTypeMovie, + NameCn: nameCn, + NameEn: nameEn, + OriginalName: detail.OriginalTitle, + Overview: detail.Overview, + AirDate: detail.ReleaseDate, + Resolution: media.Resolution(in.Resolution), + StorageID: in.StorageID, + TargetDir: in.Folder, + Limiter: schema.MediaLimiter{SizeMin: in.SizeMin, SizeMax: in.SizeMax}, AlternativeTitles: alterTitles, } @@ -372,7 +371,7 @@ func (c *Client) AddMovie2Watchlist(in AddWatchlistIn) (interface{}, error) { } -func (c *Client) checkMovieFolder(m *ent.Media) error { +func (c *Engine) checkMovieFolder(m *ent.Media) error { var storageImpl, err = c.GetStorage(m.StorageID, media.MediaTypeMovie) if err != nil { return err @@ -406,7 +405,7 @@ func IsJav(detail *tmdb.MovieDetails) bool { return false } -func (c *Client) GetJavid(id int) string { +func (c *Engine) GetJavid(id int) string { alters, err := c.MustTMDB().GetMovieAlternativeTitles(id, c.language) if err != nil { return "" @@ -419,23 +418,23 @@ func (c *Client) GetJavid(id int) string { return "" } -func (c *Client) downloadBackdrop(path string, mediaID int) error { +func (c *Engine) downloadBackdrop(path string, mediaID int) error { url := "https://image.tmdb.org/t/p/original" + path return c.downloadImage(url, mediaID, "backdrop.jpg") } -func (c *Client) downloadPoster(path string, mediaID int) error { +func (c *Engine) downloadPoster(path string, mediaID int) error { var url = "https://image.tmdb.org/t/p/original" + path return c.downloadImage(url, mediaID, "poster.jpg") } -func (c *Client) downloadW500Poster(path string, mediaID int) error { +func (c *Engine) downloadW500Poster(path string, mediaID int) error { url := "https://image.tmdb.org/t/p/w500" + path return c.downloadImage(url, mediaID, "poster_w500.jpg") } -func (c *Client) downloadImage(url string, mediaID int, name string) error { +func (c *Engine) downloadImage(url string, mediaID int, name string) error { log.Infof("try to download image: %v", url) var resp, err = http.Get(url) @@ -460,7 +459,7 @@ func (c *Client) downloadImage(url string, mediaID int, name string) error { } -func (c *Client) checkW500PosterOnStartup() { +func (c *Engine) checkW500PosterOnStartup() { log.Infof("check all w500 posters") all := c.db.GetMediaWatchlist(media.MediaTypeTv) movies := c.db.GetMediaWatchlist(media.MediaTypeMovie) @@ -470,37 +469,37 @@ func (c *Client) checkW500PosterOnStartup() { if _, err := os.Stat(targetFile); err != nil { log.Infof("poster_w500.jpg not exist for %s, will download it", e.NameEn) - if e.MediaType ==media.MediaTypeTv { + if e.MediaType == media.MediaTypeTv { detail, err := c.MustTMDB().GetTvDetails(e.TmdbID, db.LanguageCN) if err != nil { log.Warnf("get tmdb detail for %s error: %v", e.NameEn, err) continue } - + if err := c.downloadW500Poster(detail.PosterPath, e.ID); err != nil { log.Warnf("download w500 poster error: %v", err) continue } - + } else { detail, err := c.MustTMDB().GetMovieDetails(e.TmdbID, db.LanguageCN) if err != nil { log.Warnf("get tmdb detail for %s error: %v", e.NameEn, err) continue } - + if err := c.downloadW500Poster(detail.PosterPath, e.ID); err != nil { log.Warnf("download w500 poster error: %v", err) continue } - + } } } } -func (c *Client) SuggestedMovieFolderName(tmdbId int) (string, error) { +func (c *Engine) SuggestedMovieFolderName(tmdbId int) (string, error) { d1, err := c.MustTMDB().GetMovieDetails(tmdbId, c.language) if err != nil { @@ -545,7 +544,7 @@ func (c *Client) SuggestedMovieFolderName(tmdbId int) (string, error) { return res, nil } -func (c *Client) SuggestedSeriesFolderName(tmdbId int) (string, error) { +func (c *Engine) SuggestedSeriesFolderName(tmdbId int) (string, error) { d, err := c.MustTMDB().GetTvDetails(tmdbId, c.language) if err != nil { diff --git a/server/core/indexer.go b/engine/indexer.go similarity index 90% rename from server/core/indexer.go rename to engine/indexer.go index 459d38b..4949e26 100644 --- a/server/core/indexer.go +++ b/engine/indexer.go @@ -1,4 +1,4 @@ -package core +package engine import ( "polaris/ent" @@ -11,7 +11,7 @@ import ( const prowlarrPrefix = "Prowlarr_" -func (c *Client) SyncProwlarrIndexers(apiKey, url string) error { +func (c *Engine) SyncProwlarrIndexers(apiKey, url string) error { client := prowlarr.New(apiKey, url) if ins, err := client.GetIndexers(); err != nil { return errors.Wrap(err, "connect to prowlarr error") @@ -22,7 +22,7 @@ func (c *Client) SyncProwlarrIndexers(apiKey, url string) error { } all := c.db.GetAllIndexers() for _, index := range all { - + if index.Synced { if !prowlarrNames[strings.TrimPrefix(index.Name, prowlarrPrefix)] { c.db.DeleteIndexer(index.ID) //remove deleted indexers @@ -52,7 +52,7 @@ func (c *Client) SyncProwlarrIndexers(apiKey, url string) error { return nil } -func (c *Client) syncProwlarr() error { +func (c *Engine) syncProwlarr() error { p, err := c.db.GetProwlarrSetting() if err != nil { return errors.Wrap(err, "db") @@ -67,8 +67,7 @@ func (c *Client) syncProwlarr() error { return nil } - -func (c *Client) DeleteAllProwlarrIndexers() error { +func (c *Engine) DeleteAllProwlarrIndexers() error { all := c.db.GetAllIndexers() for _, index := range all { if index.Synced { @@ -77,4 +76,4 @@ func (c *Client) DeleteAllProwlarrIndexers() error { } } return nil -} \ No newline at end of file +} diff --git a/server/core/integration.go b/engine/integration.go similarity index 94% rename from server/core/integration.go rename to engine/integration.go index f3d3834..0990d21 100644 --- a/server/core/integration.go +++ b/engine/integration.go @@ -1,4 +1,4 @@ -package core +package engine import ( "bytes" @@ -21,7 +21,7 @@ import ( "github.com/pkg/errors" ) -func (c *Client) writeNfoFile(historyId int) error { +func (c *Engine) writeNfoFile(historyId int) error { if !c.nfoSupportEnabled() { return nil } @@ -106,7 +106,7 @@ func (c *Client) writeNfoFile(historyId int) error { return nil } -func (c *Client) writePlexmatch(historyId int) error { +func (c *Engine) writePlexmatch(historyId int) error { if !c.plexmatchEnabled() { return nil @@ -169,15 +169,15 @@ func (c *Client) writePlexmatch(historyId int) error { return st.WriteFile(seasonPlex, buff.Bytes()) } -func (c *Client) plexmatchEnabled() bool { +func (c *Engine) plexmatchEnabled() bool { return c.db.GetSetting(db.SettingPlexMatchEnabled) == "true" } -func (c *Client) nfoSupportEnabled() bool { +func (c *Engine) nfoSupportEnabled() bool { return c.db.GetSetting(db.SettingNfoSupportEnabled) == "true" } -func (c *Client) GetStorage(storageId int, mediaType media.MediaType) (storage.Storage, error) { +func (c *Engine) GetStorage(storageId int, mediaType media.MediaType) (storage.Storage, error) { st := c.db.GetStorage(storageId) targetPath := st.TvPath if mediaType == media.MediaTypeMovie { @@ -219,7 +219,7 @@ func (c *Client) GetStorage(storageId int, mediaType media.MediaType) (storage.S return nil, errors.New("no storage found") } -func (c *Client) sendMsg(msg string) { +func (c *Engine) sendMsg(msg string) { clients, err := c.db.GetAllNotificationClients2() if err != nil { log.Errorf("query notification clients: %v", err) @@ -248,7 +248,7 @@ func (c *Client) sendMsg(msg string) { } } -func (c *Client) findEpisodeFilesPreMoving(historyId int) error { +func (c *Engine) findEpisodeFilesPreMoving(historyId int) error { his := c.db.GetHistory(historyId) episodeIds := c.GetEpisodeIds(his) diff --git a/server/core/nfo.go b/engine/nfo.go similarity index 99% rename from server/core/nfo.go rename to engine/nfo.go index 7c63b49..3bba416 100644 --- a/server/core/nfo.go +++ b/engine/nfo.go @@ -1,4 +1,4 @@ -package core +package engine import "encoding/xml" diff --git a/server/core/resources.go b/engine/resources.go similarity index 94% rename from server/core/resources.go rename to engine/resources.go index 7697073..1b6af05 100644 --- a/server/core/resources.go +++ b/engine/resources.go @@ -1,4 +1,4 @@ -package core +package engine import ( "bytes" @@ -16,7 +16,7 @@ import ( "github.com/pkg/errors" ) -func (c *Client) DownloadEpisodeTorrent(r1 torznab.Result, seriesId, seasonNum int, episodeNums ...int) (*string, error) { +func (c *Engine) DownloadEpisodeTorrent(r1 torznab.Result, seriesId, seasonNum int, episodeNums ...int) (*string, error) { series, err := c.db.GetMedia(seriesId) if err != nil { @@ -30,7 +30,7 @@ func (c *Client) DownloadEpisodeTorrent(r1 torznab.Result, seriesId, seasonNum i tmdb 校验获取的资源名,如果用资源名在tmdb搜索出来的结果能匹配上想要的资源,则认为资源有效,否则无效 解决名称过于简单的影视会匹配过多资源的问题, 例如:梦魇绝镇 FROM */ -func (c *Client) checkBtReourceWithTmdb(r *torznab.Result, seriesId int) bool { +func (c *Engine) checkBtReourceWithTmdb(r *torznab.Result, seriesId int) bool { m := metadata.ParseTv(r.Name) se, err := c.MustTMDB().SearchMedia(m.NameEn, "", 1) if err != nil { @@ -57,7 +57,7 @@ func (c *Client) checkBtReourceWithTmdb(r *torznab.Result, seriesId int) bool { } } -func (c *Client) SearchAndDownload(seriesId, seasonNum int, episodeNums ...int) ([]string, error) { +func (c *Engine) SearchAndDownload(seriesId, seasonNum int, episodeNums ...int) ([]string, error) { res, err := SearchTvSeries(c.db, &SearchParam{ MediaId: seriesId, @@ -115,11 +115,11 @@ lo: return torrentNames, nil } -func (c *Client) DownloadMovie(m *ent.Media, r1 torznab.Result) (*string, error) { +func (c *Engine) DownloadMovie(m *ent.Media, r1 torznab.Result) (*string, error) { return c.downloadTorrent(m, r1, 0) } -func (c *Client) downloadTorrent(m *ent.Media, r1 torznab.Result, seasonNum int, episodeNums ...int) (*string, error) { +func (c *Engine) downloadTorrent(m *ent.Media, r1 torznab.Result, seasonNum int, episodeNums ...int) (*string, error) { trc, dlc, err := c.GetDownloadClient() if err != nil { return nil, errors.Wrap(err, "connect transmission") diff --git a/server/core/scheduler.go b/engine/scheduler.go similarity index 93% rename from server/core/scheduler.go rename to engine/scheduler.go index 4d4f201..ae8de2d 100644 --- a/server/core/scheduler.go +++ b/engine/scheduler.go @@ -1,4 +1,4 @@ -package core +package engine import ( "fmt" @@ -18,7 +18,7 @@ import ( "github.com/pkg/errors" ) -func (c *Client) addSysCron() { +func (c *Engine) addSysCron() { c.registerCronJob("check_running_tasks", "@every 1m", c.checkTasks) c.registerCronJob("check_available_medias_to_download", "0 0 * * * *", func() error { v := os.Getenv("POLARIS_NO_AUTO_DOWNLOAD") @@ -48,14 +48,14 @@ func (c *Client) addSysCron() { log.Infof("--------- add cron jobs done --------") } -func (c *Client) mustAddCron(spec string, cmd func()) { +func (c *Engine) mustAddCron(spec string, cmd func()) { if err := c.cron.AddFunc(spec, cmd); err != nil { log.Errorf("add func error: %v", err) panic(err) } } -func (c *Client) TriggerCronJob(name string) error { +func (c *Engine) TriggerCronJob(name string) error { job, ok := c.schedulers.Load(name) if !ok { return fmt.Errorf("job name not exists: %s", name) @@ -63,7 +63,7 @@ func (c *Client) TriggerCronJob(name string) error { return job.f() } -func (c *Client) checkTasks() error { +func (c *Engine) checkTasks() error { log.Debug("begin check tasks...") for id, t := range c.tasks { r := c.db.GetHistory(id) @@ -124,7 +124,7 @@ seeding状态中,会定时检查做种状态,达到指定分享率,会置 */ -func (c *Client) setHistoryStatus(id int, status history.Status) { +func (c *Engine) setHistoryStatus(id int, status history.Status) { r := c.db.GetHistory(id) episodeIds := c.GetEpisodeIds(r) @@ -152,7 +152,7 @@ func (c *Client) setHistoryStatus(id int, status history.Status) { } } -func (c *Client) setEpsideoStatus(episodeIds []int, status episode.Status) error { +func (c *Engine) setEpsideoStatus(episodeIds []int, status episode.Status) error { for _, id := range episodeIds { ep, err := c.db.GetEpisodeByID(id) if err != nil { @@ -171,7 +171,7 @@ func (c *Client) setEpsideoStatus(episodeIds []int, status episode.Status) error return nil } -func (c *Client) postTaskProcessing(id int) { +func (c *Engine) postTaskProcessing(id int) { if err := c.findEpisodeFilesPreMoving(id); err != nil { log.Errorf("finding all episode file error: %v", err) } else { @@ -199,7 +199,7 @@ func getSeasonNum(h *ent.History) int { return seasonNum } -func (c *Client) GetEpisodeIds(r *ent.History) []int { +func (c *Engine) GetEpisodeIds(r *ent.History) []int { var episodeIds []int seasonNum := getSeasonNum(r) @@ -231,7 +231,7 @@ func (c *Client) GetEpisodeIds(r *ent.History) []int { return episodeIds } -func (c *Client) moveCompletedTask(id int) (err1 error) { +func (c *Engine) moveCompletedTask(id int) (err1 error) { torrent := c.tasks[id] r := c.db.GetHistory(id) // if r.Status == history.StatusUploading { @@ -300,7 +300,7 @@ func (c *Client) moveCompletedTask(id int) (err1 error) { return nil } -func (c *Client) CheckDownloadedSeriesFiles(m *ent.Media) error { +func (c *Engine) CheckDownloadedSeriesFiles(m *ent.Media) error { if m.MediaType != media.MediaTypeTv { return nil } @@ -357,7 +357,7 @@ type Task struct { UploadProgresser func() float64 } -func (c *Client) DownloadSeriesAllEpisodes(id int) []string { +func (c *Engine) DownloadSeriesAllEpisodes(id int) []string { tvDetail, err := c.db.GetMediaDetails(id) if err != nil { log.Errorf("get media details error: %v", err) @@ -429,7 +429,7 @@ func (c *Client) DownloadSeriesAllEpisodes(id int) []string { return allNames } -func (c *Client) downloadAllTvSeries() { +func (c *Engine) downloadAllTvSeries() { log.Infof("begin check all tv series resources") allSeries := c.db.GetMediaWatchlist(media.MediaTypeTv) for _, series := range allSeries { @@ -437,7 +437,7 @@ func (c *Client) downloadAllTvSeries() { } } -func (c *Client) downloadAllMovies() { +func (c *Engine) downloadAllMovies() { log.Infof("begin check all movie resources") allSeries := c.db.GetMediaWatchlist(media.MediaTypeMovie) @@ -448,7 +448,7 @@ func (c *Client) downloadAllMovies() { } } -func (c *Client) DownloadMovieByID(id int) (string, error) { +func (c *Engine) DownloadMovieByID(id int) (string, error) { detail, err := c.db.GetMediaDetails(id) if err != nil { return "", errors.Wrap(err, "get media details") @@ -468,7 +468,7 @@ func (c *Client) DownloadMovieByID(id int) (string, error) { } } -func (c *Client) downloadMovieSingleEpisode(m *ent.Media, ep *ent.Episode) (string, error) { +func (c *Engine) downloadMovieSingleEpisode(m *ent.Media, ep *ent.Episode) (string, error) { qiangban := c.db.GetSetting(db.SettingAllowQiangban) allowQiangban := false @@ -495,7 +495,7 @@ func (c *Client) downloadMovieSingleEpisode(m *ent.Media, ep *ent.Episode) (stri return *s, nil } -func (c *Client) checkAllSeriesNewSeason() error { +func (c *Engine) checkAllSeriesNewSeason() error { log.Infof("begin checking series all new season") allSeries := c.db.GetMediaWatchlist(media.MediaTypeTv) for _, series := range allSeries { @@ -507,7 +507,7 @@ func (c *Client) checkAllSeriesNewSeason() error { return nil } -func (c *Client) checkSeiesNewSeason(media *ent.Media) error { +func (c *Engine) checkSeiesNewSeason(media *ent.Media) error { d, err := c.MustTMDB().GetTvDetails(media.TmdbID, c.language) if err != nil { return errors.Wrap(err, "tmdb") @@ -545,7 +545,7 @@ func (c *Client) checkSeiesNewSeason(media *ent.Media) error { return nil } -func (c *Client) isSeedRatioLimitReached(indexId int, t pkg.Torrent) (float64, bool) { +func (c *Engine) isSeedRatioLimitReached(indexId int, t pkg.Torrent) (float64, bool) { indexer, err := c.db.GetIndexer(indexId) if err != nil { return 0, true diff --git a/server/core/torrent.go b/engine/torrent.go similarity index 99% rename from server/core/torrent.go rename to engine/torrent.go index 5db567f..b919c58 100644 --- a/server/core/torrent.go +++ b/engine/torrent.go @@ -1,4 +1,4 @@ -package core +package engine import ( "fmt" diff --git a/server/core/fliters.go b/server/core/fliters.go deleted file mode 100644 index 25dcb76..0000000 --- a/server/core/fliters.go +++ /dev/null @@ -1,2 +0,0 @@ -package core - diff --git a/server/resources.go b/server/resources.go index 9020064..d0974ef 100644 --- a/server/resources.go +++ b/server/resources.go @@ -3,10 +3,10 @@ package server import ( "fmt" "polaris/db" + "polaris/engine" "polaris/ent/media" "polaris/log" "polaris/pkg/torznab" - "polaris/server/core" "strconv" "github.com/gin-gonic/gin" @@ -15,7 +15,7 @@ import ( func (s *Server) searchAndDownloadSeasonPackage(seriesId, seasonNum int) (*string, error) { - res, err := core.SearchTvSeries(s.db, &core.SearchParam{ + res, err := engine.SearchTvSeries(s.db, &engine.SearchParam{ MediaId: seriesId, SeasonNum: seasonNum, Episodes: nil, @@ -54,7 +54,7 @@ func (s *Server) SearchAvailableTorrents(c *gin.Context) (interface{}, error) { if in.Episode == 0 { //search season package log.Infof("search series season package S%02d", in.Season) - res, err = core.SearchTvSeries(s.db, &core.SearchParam{ + res, err = engine.SearchTvSeries(s.db, &engine.SearchParam{ MediaId: in.ID, SeasonNum: in.Season, Episodes: nil, @@ -64,7 +64,7 @@ func (s *Server) SearchAvailableTorrents(c *gin.Context) (interface{}, error) { } } else { log.Infof("search series episode S%02dE%02d", in.Season, in.Episode) - res, err = core.SearchTvSeries(s.db, &core.SearchParam{ + res, err = engine.SearchTvSeries(s.db, &engine.SearchParam{ MediaId: in.ID, SeasonNum: in.Season, Episodes: []int{in.Episode}, @@ -85,7 +85,7 @@ func (s *Server) SearchAvailableTorrents(c *gin.Context) (interface{}, error) { allowQiangban = true } - res, err = core.SearchMovie(s.db, &core.SearchParam{ + res, err = engine.SearchMovie(s.db, &engine.SearchParam{ MediaId: in.ID, FilterQiangban: !allowQiangban, }) diff --git a/server/server.go b/server/server.go index b5ce3e6..6faf0c6 100644 --- a/server/server.go +++ b/server/server.go @@ -6,10 +6,10 @@ import ( "net/http/httputil" "net/url" "polaris/db" + "polaris/engine" "polaris/log" "polaris/pkg/cache" "polaris/pkg/tmdb" - "polaris/server/core" "polaris/ui" "time" @@ -30,14 +30,14 @@ func NewServer(db *db.Client) *Server { monitorNumCache: cache.NewCache[int, int](10 * time.Minute), downloadNumCache: cache.NewCache[int, int](10 * time.Minute), } - s.core = core.NewClient(db, s.language) + s.core = engine.NewEngine(db, s.language) return s } type Server struct { r *gin.Engine db *db.Client - core *core.Client + core *engine.Engine language string jwtSerect string monitorNumCache *cache.Cache[int, int] diff --git a/server/watchlist.go b/server/watchlist.go index 58c4fdd..2d8de74 100644 --- a/server/watchlist.go +++ b/server/watchlist.go @@ -4,11 +4,11 @@ import ( "os" "path/filepath" "polaris/db" + "polaris/engine" "polaris/ent" "polaris/ent/episode" "polaris/ent/media" "polaris/log" - "polaris/server/core" "strconv" "strings" @@ -68,7 +68,7 @@ type addWatchlistIn struct { } func (s *Server) AddTv2Watchlist(c *gin.Context) (interface{}, error) { - var in core.AddWatchlistIn + var in engine.AddWatchlistIn if err := c.ShouldBindJSON(&in); err != nil { return nil, errors.Wrap(err, "bind query") } @@ -76,7 +76,7 @@ func (s *Server) AddTv2Watchlist(c *gin.Context) (interface{}, error) { } func (s *Server) AddMovie2Watchlist(c *gin.Context) (interface{}, error) { - var in core.AddWatchlistIn + var in engine.AddWatchlistIn if err := c.ShouldBindJSON(&in); err != nil { return nil, errors.Wrap(err, "bind query") }