Compare commits

...

146 Commits

Author SHA1 Message Date
Simon Ding
8ab33f3d54 ui refactor 2024-08-04 10:54:47 +08:00
Simon Ding
4d3b26135c fix: ui alignment 2024-08-04 10:22:47 +08:00
Simon Ding
56d5cdb2bf refactor ui resource list 2024-08-03 23:05:17 +08:00
Simon Ding
6f80da779b fix: download client id 2024-08-03 17:12:20 +08:00
Simon Ding
5fef156052 fix: indexid 2024-08-03 17:10:49 +08:00
Simon Ding
eab3a6ca2b try fix seed ratio 2024-08-03 16:47:58 +08:00
Simon Ding
ffa5c37c4c fix: name matching 2024-08-03 15:03:47 +08:00
Simon Ding
241e30152b feat: file size limiter 2024-08-03 12:31:53 +08:00
Simon Ding
16216fcc4f feat: change single episode monitoring status 2024-08-03 10:46:52 +08:00
Simon Ding
578b6a9d78 feat: proxy only affects tmdb 2024-08-03 09:54:23 +08:00
Simon Ding
f4da80c845 add testcases & add parse condition 2024-08-02 21:04:34 +08:00
Simon Ding
5a9acd3e6e ui: improve tv display 2024-08-02 19:10:53 +08:00
Simon Ding
8bfa8f84b9 fix monitor 2024-08-02 14:56:14 +08:00
Simon Ding
5b0b2ce5b0 fix: status 2024-08-02 14:39:01 +08:00
Simon Ding
b24c1a1501 ui: add monitored field 2024-08-02 14:06:44 +08:00
Simon Ding
aa320c6dcb fix: monitored 2024-08-02 13:06:38 +08:00
Simon Ding
5132714247 feat: change method to monitor episodes 2024-08-02 12:52:54 +08:00
Simon Ding
3aeecac4fb updates 2024-08-02 12:19:53 +08:00
Simon Ding
7f8c613a65 fix number formats 2024-08-02 11:14:21 +08:00
Simon Ding
c787d71fbd code refactor 2024-08-02 10:08:26 +08:00
Simon Ding
c28e16805e fix: empty list 2024-08-01 20:34:23 +08:00
Simon Ding
fc3d3878bc feat: disable indexer 2024-08-01 20:12:42 +08:00
Simon Ding
e26e86a63f feat: implement seed ratio check logic 2024-08-01 19:52:40 +08:00
Simon Ding
408ff163ef feat: improve support for pt 2024-08-01 19:12:14 +08:00
Simon Ding
35d299b60c feat: improve indexer setting 2024-08-01 17:36:40 +08:00
Simon Ding
6e002b1198 fix: add defaults 2024-08-01 13:05:05 +08:00
Simon Ding
7508a264a6 chore: ci update 2024-08-01 09:42:37 +08:00
Simon Ding
0022c9dad5 fix: umask 2024-08-01 09:39:38 +08:00
Simon Ding
654d8b50b4 chore: add more screenshot 2024-08-01 09:23:13 +08:00
Simon Ding
97ede5d9c9 feat: add badges 2024-08-01 00:01:55 +08:00
Simon Ding
4803567818 fix: remove attestations 2024-07-31 23:43:07 +08:00
Simon Ding
4e0014cb3f fix: sha256 tags in repo 2024-07-31 23:41:58 +08:00
Simon Ding
c256d46d5c test ci 2024-07-31 23:11:55 +08:00
Simon Ding
b765f16ea6 chore: updates 2024-07-31 20:59:40 +08:00
Simon Ding
9350e376f4 fix 2024-07-31 17:50:37 +08:00
Simon Ding
06f935871a chore: improve ui & fix 2024-07-31 17:43:42 +08:00
Simon Ding
001b850d8f feat: add imdbid to .plexmatch file 2024-07-31 17:01:50 +08:00
Simon Ding
1340305f2d feat: change progress display 2024-07-31 16:55:01 +08:00
Simon Ding
b337e40fcc feat: change name suggestting 2024-07-31 16:23:22 +08:00
Simon Ding
e94386e455 chore: better text display 2024-07-31 15:45:49 +08:00
Simon Ding
2b4fb99c89 chore: improve ui 2024-07-31 15:40:24 +08:00
Simon Ding
faa603d5df code refactor & improve search page 2024-07-31 15:26:34 +08:00
Simon Ding
9ba59a7d5a refactor code 2024-07-31 14:41:57 +08:00
Simon Ding
0ea1c040a2 chore: optimize log 2024-07-30 22:56:17 +08:00
Simon Ding
eba646f5db chore: delete not exist tasks 2024-07-30 22:11:41 +08:00
Simon Ding
ebcc0c32da fix: panic 2024-07-30 22:10:18 +08:00
Simon Ding
769f217506 feat: add option to control whether to deleted task 2024-07-30 21:55:54 +08:00
Simon Ding
3525d1bb83 feat: try hard link first 2024-07-30 21:15:35 +08:00
Simon Ding
2c3fd89f2a fix: plexmatch 2024-07-30 20:56:44 +08:00
Simon Ding
19ab8c65de chore: fixes 2024-07-30 20:37:42 +08:00
Simon Ding
979218f615 feat: season plexmatch file 2024-07-30 20:01:41 +08:00
Simon Ding
d4dd2da335 set umask to 0011 2024-07-30 19:22:17 +08:00
Simon Ding
000717fcd9 fix plexmatch 2024-07-30 17:22:28 +08:00
Simon Ding
300f9a478b chore: update readme 2024-07-30 16:35:59 +08:00
Simon Ding
88a554b186 fix: local storage dir 2024-07-30 16:12:10 +08:00
Simon Ding
6ef4bedebe feat: support generate .plexmatch 2024-07-30 15:51:54 +08:00
Simon Ding
233970ef39 feat: display loading animation 2024-07-30 14:02:24 +08:00
Simon Ding
e2bba8ec71 fix: target dir 2024-07-30 11:49:42 +08:00
Simon Ding
b7aeb9c3c6 fix: create file permission 2024-07-30 11:27:06 +08:00
Simon Ding
4a93d51fdc fix: chinese naming 2024-07-30 11:16:51 +08:00
Simon Ding
f158b74be6 fix: movie suggested naming 2024-07-30 11:11:07 +08:00
Simon Ding
2c8c715540 feat: movie also requires suggested dir 2024-07-30 10:50:40 +08:00
Simon Ding
ba532d406a feat: default to html render 2024-07-30 10:08:21 +08:00
Simon Ding
cff093ca98 fix: use root user, for now 2024-07-29 22:12:05 +08:00
Simon Ding
8f677b29a7 chore: change cron 2024-07-29 19:48:05 +08:00
Simon Ding
e08c126af2 feat: add bark push notification 2024-07-29 18:06:32 +08:00
Simon Ding
eed72c5eb9 refactor: settings page 2024-07-29 16:34:32 +08:00
Simon Ding
fcff47041a feat: support push notification clients 2024-07-29 15:56:29 +08:00
Simon Ding
f9d4f851eb feat: no animation 2024-07-29 10:45:31 +08:00
Simon Ding
262baf769f feat: fade route transition and fixes 2024-07-29 09:21:11 +08:00
Simon Ding
6ef2e5b347 feat: offline support 2024-07-28 21:28:29 +08:00
Simon Ding
e0e11b70bb fix: add movie download 2024-07-28 19:30:06 +08:00
Simon Ding
3de2f89107 feat: use cookie to store jwt token, better performance 2024-07-28 18:07:24 +08:00
Simon Ding
b024b5f6dc feat: add default download client 2024-07-28 17:19:05 +08:00
Simon Ding
961d762f35 feat: add text to empty screen 2024-07-28 16:43:59 +08:00
Simon Ding
7f025a6246 fix: bugs 2024-07-28 15:54:51 +08:00
Simon Ding
fc86a441f4 feat: option to download all episodes 2024-07-28 13:22:12 +08:00
Simon Ding
34fa05e7dd fix: var 2024-07-28 12:31:22 +08:00
Simon Ding
9c3757a1bf feat: season package list 2024-07-28 11:50:58 +08:00
Simon Ding
e63a899df5 chore: remove unused code 2024-07-28 11:13:26 +08:00
Simon Ding
3a4e303d9d feat: log to console in dev 2024-07-28 11:08:17 +08:00
Simon Ding
ef9e4487c6 fix: class to dart3 record 2024-07-28 11:04:51 +08:00
Simon Ding
02f6cfb5b7 fix 2024-07-27 23:42:28 +08:00
Simon Ding
e73ae86801 add parse tv & movie api 2024-07-27 23:42:06 +08:00
Simon Ding
b19938f2df remove 2024-07-27 22:42:29 +08:00
Simon Ding
bb3c4551af fix: api call 2024-07-27 22:35:49 +08:00
Simon Ding
eae35ce862 feat: show episode resource 2024-07-27 22:22:06 +08:00
Simon Ding
feecc9f983 feat: app proxy 2024-07-27 17:18:38 +08:00
Simon Ding
5175e651ee fix: donot use git shallow copy 2024-07-27 16:04:01 +08:00
Simon Ding
f065abfbf9 fix: install git 2024-07-27 15:55:08 +08:00
Simon Ding
cd4d600f5e feat: add app version ui 2024-07-27 15:44:49 +08:00
Simon Ding
741a4024fd feat: add app version 2024-07-27 15:34:58 +08:00
Simon Ding
0433cc7b0a chore: update doc 2024-07-27 11:24:22 +08:00
Simon Ding
accc02c74c chore: update doc 2024-07-27 11:21:34 +08:00
Simon Ding
87b6c99f1f feat: better doc 2024-07-27 11:17:16 +08:00
Simon Ding
b2a092c64e feat: add get all torrents api 2024-07-27 09:26:51 +08:00
Simon Ding
51fc5c3c74 chore: fix typo 2024-07-27 00:08:46 +08:00
Simon Ding
5e6a17f86c change padding 2024-07-27 00:06:18 +08:00
Simon Ding
2fedfd6c76 fix: not display error 2024-07-26 23:56:29 +08:00
Simon Ding
61bc9b72bd feat: disable webgl2 on safari 2024-07-26 23:26:14 +08:00
Simon Ding
a997726a5f feat: size readable 2024-07-26 17:13:43 +08:00
Simon Ding
7a2c67af04 main page 2024-07-26 17:07:36 +08:00
Simon Ding
3698170d0b chore: update main page 2024-07-26 17:03:08 +08:00
Simon Ding
6c38db5248 chore: upper case log level 2024-07-26 17:00:43 +08:00
Simon Ding
b597edab8a feat: add system page 2024-07-26 16:59:33 +08:00
Simon Ding
2e3b67dfce fix: db init 2024-07-26 14:28:58 +08:00
Simon Ding
1dd61ccbca feat: add log level setting 2024-07-26 14:22:08 +08:00
Simon Ding
f5f8434832 feat: support log rotation 2024-07-26 13:59:10 +08:00
Simon Ding
2cb6a15c0b feat: movie ignore sound tracks 2024-07-26 13:45:25 +08:00
Simon Ding
317f5655b8 chore: add space vertical 2024-07-26 13:33:24 +08:00
Simon Ding
00506df5a1 change image width 2024-07-26 13:12:40 +08:00
Simon Ding
57de442eb9 feat: simple tv & movie status 2024-07-26 13:07:54 +08:00
Simon Ding
690ce272c2 chore: change ui 2024-07-26 12:54:37 +08:00
Simon Ding
6a9f63fff6 feat: add movie status to ui 2024-07-26 12:25:23 +08:00
Simon Ding
7b9b619de6 add log 2024-07-25 20:44:04 +08:00
Simon Ding
8bc9076d90 fix: debug level default 2024-07-25 20:34:43 +08:00
Simon Ding
891be34504 feat: log to file 2024-07-25 20:28:13 +08:00
Simon Ding
04df9adfdf feat: change task scheduler 2024-07-25 15:35:44 +08:00
Simon Ding
3c47eba618 feat: add default timezone 2024-07-25 14:52:34 +08:00
Simon Ding
e85bd231c9 feat: add source field 2024-07-25 14:43:45 +08:00
Simon Ding
58e65b21fb feat: check connect before add download client 2024-07-25 14:19:03 +08:00
Simon Ding
520933085d fix: remove url check 2024-07-25 14:09:58 +08:00
Simon Ding
5cc88986d2 feat: better form 2024-07-25 14:02:47 +08:00
Simon Ding
d63a923589 feat: not allow empty fields 2024-07-25 11:16:31 +08:00
Simon Ding
bca68befb1 fix: name not exist 2024-07-25 10:58:58 +08:00
Simon Ding
1be44bff9e fix: add storage 2024-07-25 10:38:37 +08:00
Simon Ding
3998270cbd feat: check new season every 12h 2024-07-25 09:44:02 +08:00
Simon Ding
73e76c2185 feat: change logic 2024-07-25 08:43:49 +08:00
Simon Ding
c72a460509 update 2024-07-25 01:09:44 +08:00
Simon Ding
912293d8e8 feat: match anime that only rely on episode number 2024-07-25 01:07:24 +08:00
Simon Ding
7f2e84ad52 feat: no need auto dispose 2024-07-25 00:36:55 +08:00
Simon Ding
e52ad612c1 fix: extra spaces 2024-07-25 00:11:15 +08:00
Simon Ding
45a212fec5 feat: add msg 2024-07-24 23:51:20 +08:00
Simon Ding
39bfda4cda feat: remove unicode hindden char 2024-07-24 23:11:45 +08:00
Simon Ding
24a4d3152d fix: condition mismatch 2024-07-24 22:47:25 +08:00
Simon Ding
6c6670a8c0 fix name match 2024-07-24 22:35:50 +08:00
Simon Ding
63fc4f277b feat: better episode matching 2024-07-24 22:26:25 +08:00
Simon Ding
45d2a4fb79 feat: better name parser 2024-07-24 22:15:59 +08:00
Simon Ding
5e337871c9 fix: finding season pack 2024-07-24 21:57:50 +08:00
Simon Ding
803dcfeacd fix: replace strings 2024-07-24 21:48:14 +08:00
Simon Ding
c26e61bbee fix: incase name not submitted 2024-07-24 21:35:59 +08:00
Simon Ding
e334acba32 feat: submit all torrent info to server 2024-07-24 21:24:36 +08:00
Simon Ding
1359df599b feat: follow jackett redirect to get real link 2024-07-24 19:30:24 +08:00
Simon Ding
16ca00d19c fix: name cannot parsed 2024-07-24 18:35:01 +08:00
Simon Ding
f4b8d03cfc add log 2024-07-24 18:18:48 +08:00
Simon Ding
8811b89889 fix local storage 2024-07-24 18:12:11 +08:00
139 changed files with 9658 additions and 2872 deletions

View File

@@ -17,14 +17,11 @@ jobs:
build-and-push-image:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
attestations: write
id-token: write
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Login to image repository
uses: docker/login-action@v2
@@ -49,9 +46,3 @@ jobs:
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
- name: Generate artifact attestation
uses: actions/attest-build-provenance@v1
with:
subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME}}
subject-digest: ${{ steps.push.outputs.digest }}
push-to-registry: true

View File

@@ -22,6 +22,8 @@ jobs:
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set Up QEMU
uses: docker/setup-qemu-action@v3
@@ -59,4 +61,4 @@ jobs:
with:
subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME}}
subject-digest: ${{ steps.push.outputs.digest }}
push-to-registry: true
push-to-registry: false

View File

@@ -3,7 +3,7 @@ WORKDIR /app
COPY ./ui/pubspec.yaml ./ui/pubspec.lock ./
RUN flutter pub get
COPY ./ui/ ./
RUN flutter build web
RUN flutter build web --no-web-resources-cdn --web-renderer html
# 打包依赖阶段使用golang作为基础镜像
FROM golang:1.22 as builder
@@ -22,9 +22,10 @@ COPY . .
COPY --from=flutter /app/build/web ./ui/build/web/
# 指定OS等并go build
RUN CGO_ENABLED=1 go build -o polaris ./cmd/
RUN CGO_ENABLED=1 go build -o polaris -ldflags="-X polaris/db.Version=$(git describe --tags --long)" ./cmd/
FROM debian:12
FROM debian:stable-slim
ENV TZ="Asia/Shanghai" GIN_MODE=release
WORKDIR /app
RUN apt-get update && apt-get -y install ca-certificates
@@ -34,4 +35,6 @@ COPY --from=builder /app/polaris .
EXPOSE 8080
#USER 1000:1000
ENTRYPOINT ["./polaris"]

View File

@@ -1,9 +1,16 @@
# polaris
# Polaris
![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/simon-ding/polaris/go.yml)
![GitHub Release](https://img.shields.io/github/v/release/simon-ding/polaris)
![GitHub Repo stars](https://img.shields.io/github/stars/simon-ding/polaris)
![GitHub go.mod Go version](https://img.shields.io/github/go-mod/go-version/simon-ding/polaris)
Polaris 是一个电视剧和电影的追踪软件。配置好了之后当剧集或者电影播出后会第一时间下载对应的资源。支持本地存储或者webdav。
![main_page](assets/main_page.png)
![detail_page](assets/detail_page.png)
![main_page](./doc/assets/main_page.png)
![detail_page](./doc/assets/detail_page.png)
![anime](./doc/assets/anime_match.png)
交流群: https://t.me/+8R2nzrlSs2JhMDgx
@@ -12,76 +19,40 @@ Polaris 是一个电视剧和电影的追踪软件。配置好了之后,当剧
- [x] 电视剧自动追踪下载
- [x] 电影自动追踪下载
- [x] webdav 存储支持,配合 [alist](https://github.com/alist-org/alist) 或阿里云等实现更多功能
- [x] 事件通知推送,目前支持 Pushover和 Bark还在扩充中
- [x] 后台代理支持
- [x] 用户认证
- [x] plex 刮削支持
- [x] and more...
## Todos
- [] qbittorrent客户端支持
- [] 更多通知客户端支持
- [] 第三方watchlist导入支持
## 使用
使用此程序参考 [【快速开始】](./doc/quick_start.md)
## 原理
本程序不提供任何视频相关资源,所有的资源都通过 jackett/prowlarr 所对接的BT/PT站点提供。
1. 此程序通过调用 jackett/prowlarr API搜索相关资源然后匹配上对应的剧集
2. 把搜索到的资源送到下载器下载
3. 下载完成后归入对应的路径
## 对比 sonarr/radarr
* 更好的中文支持
* 对于动漫、日剧的良好支持,配合国内站点基本能匹配上对应资源
* 支持 webdav 后端存储,可以配合 alist 或者阿里云来实现下载后实时传到云上的功能。这样外出就可以不依靠家里的宽带来看电影了,或者实现个轻 NAS 功能,下载功能放在本地,数据放在云盘
* golang 实现后端,相比于 .NET 更节省资源
* 一个程序同时实现了电影、电视剧功能,不需要装两个程序
* 当然 sonarr/radarr 也是非常优秀的开源项目,目前 Polaris 功能还没有 sonarr/radarr 丰富
## 快速开始
最简单部署 Polaris 的方式是使用 docker compose
```yaml
services:
polaris:
image: ghcr.io/simon-ding/polaris:latest
restart: always
volumes:
- ./config/polaris:/app/data #程序配置文件路径
- /downloads:/downloads #下载路径,需要和下载客户端配置一致
- /data:/data #媒体数据存储路径也可以启动自己配置webdav存储
ports:
- 8080:8080
transmission: #下载客户端,也可以不安装使用已有的
image: lscr.io/linuxserver/transmission:latest
container_name: transmission
environment:
- PUID=1000
- PGID=1000
- TZ=Asia/Shanghai
volumes:
- ./config/transmission:/config
- /downloads:/downloads #此路径要与polaris下载路径保持一致
ports:
- 9091:9091
- 51413:51413
- 51413:51413/udp
```
拉起之后访问 http://< ip >:8080 的形式访问
## 配置
要正确使用此程序,需要配置好以下设置:
### TMDB设置
因为此程序需要使用到 TMDB 的数据,使用此程序首先要申请一个 TMDB 的 Api Key
### 索引器
索引器是资源提供者,目前支持 torznab 协议,意味着 polarr 或者 jackett 都可以支持。请自行部署相关程序。
推荐使用 linuxserver 的镜像https://docs.linuxserver.io/images/docker-jackett/
### 下载器
资源由谁下载,目前可支持 tansmission需要配置好对应下载器
### 存储设置
程序默认所有剧集和电影存储在 /data 路径下如果想修改路径或者webdav存储需要在存储配置下修改
## 开始使用
配置完了这些,开始享受使用此程序吧!可以搜索几部自己想看的电影或者电视机,加入想看列表。当剧集有更新或者电影有资源是就会自动下载对应资源了。
-------------
## 请我喝杯咖啡
<img src="assets/wechat.JPG" width=40% height=40%>
<img src="./doc/assets/wechat.JPG" width=40% height=40%>

View File

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.7 MiB

View File

@@ -4,9 +4,14 @@ import (
"polaris/db"
"polaris/log"
"polaris/server"
"syscall"
)
func main() {
log.Infof("------------------- Starting Polaris ---------------------")
syscall.Umask(0) //max permission 0777
dbClient, err := db.Open()
if err != nil {
log.Panicf("init db error: %v", err)

View File

@@ -1,11 +1,16 @@
package db
var Version = "undefined"
const (
SettingTmdbApiKey = "tmdb_api_key"
SettingLanguage = "language"
SettingJacketUrl = "jacket_url"
SettingJacketApiKey = "jacket_api_key"
SettingDownloadDir = "download_dir"
SettingLogLevel = "log_level"
SettingProxy = "proxy"
SettingPlexMatchEnabled = "plexmatch_enabled"
)
const (
@@ -18,6 +23,7 @@ const (
IndexerTorznabImpl = "torznab"
DataPath = "./data"
ImgPath = DataPath + "/img"
LogPath = DataPath + "/logs"
)
const (
@@ -27,16 +33,4 @@ const (
type ResolutionType string
const (
Any ResolutionType = "any"
R720p ResolutionType = "720p"
R1080p ResolutionType = "1080p"
R4k ResolutionType = "4k"
)
func (r ResolutionType) String() string {
return string(r)
}
const JwtSerectKey = "jwt_secrect_key"

174
db/db.go
View File

@@ -42,6 +42,7 @@ func Open() (*Client, error) {
c := &Client{
ent: client,
}
c.init()
return c, nil
}
@@ -55,7 +56,16 @@ func (c *Client) init() {
downloadDir := c.GetSetting(SettingDownloadDir)
if downloadDir == "" {
log.Infof("set default download dir")
c.SetSetting(downloadDir, "/downloads")
c.SetSetting(SettingDownloadDir, "/downloads")
}
logLevel := c.GetSetting(SettingLogLevel)
if logLevel == "" {
log.Infof("set default log level")
c.SetSetting(SettingLogLevel, "info")
}
if tr := c.GetTransmission(); tr == nil {
log.Warnf("no download client, set default download client")
c.SaveTransmission("transmission", "http://transmission:9091", "", "")
}
}
@@ -77,18 +87,16 @@ func (c *Client) generateDefaultLocalStorage() error {
return c.AddStorage(&StorageInfo{
Name: "local",
Implementation: "local",
TvPath: "/data/tv/",
MoviePath: "/data/movies/",
Default: true,
Settings: map[string]string{
"tv_path": "/data/tv/",
"movie_path": "/data/movies/",
},
})
}
func (c *Client) GetSetting(key string) string {
v, err := c.ent.Settings.Query().Where(settings.Key(key)).Only(context.TODO())
if err != nil {
log.Errorf("get setting by key: %s error: %v", key, err)
log.Debugf("get setting by key: %s error: %v", key, err)
return ""
}
return v.Value
@@ -138,6 +146,8 @@ func (c *Client) AddMediaWatchlist(m *ent.Media, episodes []int) (*ent.Media, er
SetAirDate(m.AirDate).
SetResolution(m.Resolution).
SetTargetDir(m.TargetDir).
SetDownloadHistoryEpisodes(m.DownloadHistoryEpisodes).
SetLimiter(m.Limiter).
AddEpisodeIDs(episodes...).
Save(context.TODO())
return r, err
@@ -157,11 +167,18 @@ func (c *Client) GetEpisode(seriesId, seasonNum, episodeNum int) (*ent.Episode,
return c.ent.Episode.Query().Where(episode.MediaID(seriesId), episode.SeasonNumber(seasonNum),
episode.EpisodeNumber(episodeNum)).First(context.TODO())
}
func (c *Client) GetEpisodeByID(epID int) (*ent.Episode, error) {
return c.ent.Episode.Query().Where(episode.ID(epID)).First(context.TODO())
}
func (c *Client) UpdateEpiode(episodeId int, name, overview string) error {
return c.ent.Episode.Update().Where(episode.ID(episodeId)).SetTitle(name).SetOverview(overview).Exec(context.TODO())
}
func (c *Client) UpdateEpiode2(episodeId int, name, overview, airdate string) error {
return c.ent.Episode.Update().Where(episode.ID(episodeId)).SetTitle(name).SetOverview(overview).SetAirDate(airdate).Exec(context.TODO())
}
type MediaDetails struct {
*ent.Media
Episodes []*ent.Episode `json:"episodes"`
@@ -187,6 +204,10 @@ func (c *Client) GetMediaDetails(id int) *MediaDetails {
return md
}
func (c *Client) GetMedia(id int) (*ent.Media, error) {
return c.ent.Media.Query().Where(media.ID(id)).First(context.TODO())
}
func (c *Client) DeleteMedia(id int) error {
_, err := c.ent.Episode.Delete().Where(episode.MediaID(id)).Exec(context.TODO())
if err != nil {
@@ -202,6 +223,22 @@ func (c *Client) SaveEposideDetail(d *ent.Episode) (int, error) {
SetSeasonNumber(d.SeasonNumber).
SetEpisodeNumber(d.EpisodeNumber).
SetOverview(d.Overview).
SetMonitored(d.Monitored).
SetTitle(d.Title).Save(context.TODO())
if err != nil {
return 0, errors.Wrap(err, "save episode")
}
return ep.ID, nil
}
func (c *Client) SaveEposideDetail2(d *ent.Episode) (int, error) {
ep, err := c.ent.Episode.Create().
SetAirDate(d.AirDate).
SetSeasonNumber(d.SeasonNumber).
SetEpisodeNumber(d.EpisodeNumber).
SetMediaID(d.MediaID).
SetStatus(d.Status).
SetOverview(d.Overview).
SetTitle(d.Title).Save(context.TODO())
return ep.ID, err
@@ -212,19 +249,23 @@ type TorznabSetting struct {
ApiKey string `json:"api_key"`
}
func (c *Client) SaveTorznabInfo(name string, setting TorznabSetting) error {
data, err := json.Marshal(setting)
if err != nil {
return errors.Wrap(err, "marshal json")
func (c *Client) SaveIndexer(in *ent.Indexers) error {
if in.ID != 0 {
//update setting
return c.ent.Indexers.Update().Where(indexers.ID(in.ID)).SetName(in.Name).SetImplementation(in.Implementation).
SetPriority(in.Priority).SetSettings(in.Settings).SetSeedRatio(in.SeedRatio).SetDisabled(in.Disabled).Exec(context.Background())
}
count := c.ent.Indexers.Query().Where(indexers.Name(name)).CountX(context.TODO())
//create new one
count := c.ent.Indexers.Query().Where(indexers.Name(in.Name)).CountX(context.TODO())
if count > 0 {
c.ent.Indexers.Update().Where(indexers.Name(name)).SetSettings(string(data)).Save(context.TODO())
return err
return fmt.Errorf("name already esxits: %v", in.Name)
}
_, err = c.ent.Indexers.Create().
SetName(name).SetImplementation(IndexerTorznabImpl).SetPriority(1).SetSettings(string(data)).Save(context.TODO())
_, err := c.ent.Indexers.Create().
SetName(in.Name).SetImplementation(in.Implementation).SetPriority(in.Priority).SetSettings(in.Settings).SetSeedRatio(in.SeedRatio).
SetDisabled(in.Disabled).Save(context.TODO())
if err != nil {
return errors.Wrap(err, "save db")
}
@@ -236,9 +277,21 @@ func (c *Client) DeleteTorznab(id int) {
c.ent.Indexers.Delete().Where(indexers.ID(id)).Exec(context.TODO())
}
func (c *Client) GetIndexer(id int) (*TorznabInfo, error) {
res, err := c.ent.Indexers.Query().Where(indexers.ID(id)).First(context.TODO())
if err != nil {
return nil, err
}
var ss TorznabSetting
err = json.Unmarshal([]byte(res.Settings), &ss)
if err != nil {
return nil, fmt.Errorf("unmarshal torznab %s error: %v", res.Name, err)
}
return &TorznabInfo{Indexers: res, TorznabSetting: ss}, nil
}
type TorznabInfo struct {
ID int `json:"id"`
Name string `json:"name"`
*ent.Indexers
TorznabSetting
}
@@ -254,8 +307,7 @@ func (c *Client) GetAllTorznabInfo() []*TorznabInfo {
continue
}
l = append(l, &TorznabInfo{
ID: r.ID,
Name: r.Name,
Indexers: r,
TorznabSetting: ss,
})
}
@@ -299,10 +351,12 @@ func (c *Client) DeleteDownloadCLient(id int) {
// Storage is the model entity for the Storage schema.
type StorageInfo struct {
Name string `json:"name"`
Implementation string `json:"implementation"`
Settings map[string]string `json:"settings"`
Default bool `json:"default"`
Name string `json:"name" binding:"required"`
Implementation string `json:"implementation" binding:"required"`
Settings map[string]string `json:"settings" binding:"required"`
TvPath string `json:"tv_path" binding:"required"`
MoviePath string `json:"movie_path" binding:"required"`
Default bool `json:"default"`
}
func (s *StorageInfo) ToWebDavSetting() WebdavSetting {
@@ -310,36 +364,30 @@ func (s *StorageInfo) ToWebDavSetting() WebdavSetting {
panic("not webdav storage")
}
return WebdavSetting{
URL: s.Settings["url"],
TvPath: s.Settings["tv_path"],
MoviePath: s.Settings["movie_path"],
User: s.Settings["user"],
Password: s.Settings["password"],
URL: s.Settings["url"],
User: s.Settings["user"],
Password: s.Settings["password"],
ChangeFileHash: s.Settings["change_file_hash"],
}
}
type LocalDirSetting struct {
TvPath string `json:"tv_path"`
MoviePath string `json:"movie_path"`
}
type WebdavSetting struct {
URL string `json:"url"`
TvPath string `json:"tv_path"`
MoviePath string `json:"movie_path"`
User string `json:"user"`
Password string `json:"password"`
ChangeFileHash string `json:"change_file_hash"`
}
func (c *Client) AddStorage(st *StorageInfo) error {
if !strings.HasSuffix(st.Settings["tv_path"], "/") {
st.Settings["tv_path"] += "/"
if !strings.HasSuffix(st.TvPath, "/") {
st.TvPath += "/"
}
if !strings.HasSuffix(st.Settings["movie_path"], "/") {
st.Settings["movie_path"] += "/"
if !strings.HasSuffix(st.MoviePath, "/") {
st.MoviePath += "/"
}
if st.Settings == nil {
st.Settings = map[string]string{}
}
data, err := json.Marshal(st.Settings)
@@ -351,7 +399,7 @@ func (c *Client) AddStorage(st *StorageInfo) error {
if count > 0 {
//storage already exist, edit exist one
return c.ent.Storage.Update().Where(storage.Name(st.Name)).
SetImplementation(storage.Implementation(st.Implementation)).
SetImplementation(storage.Implementation(st.Implementation)).SetTvPath(st.TvPath).SetMoviePath(st.MoviePath).
SetSettings(string(data)).Exec(context.TODO())
}
countAll := c.ent.Storage.Query().Where(storage.Deleted(false)).CountX(context.TODO())
@@ -360,7 +408,7 @@ func (c *Client) AddStorage(st *StorageInfo) error {
st.Default = true
}
_, err = c.ent.Storage.Create().SetName(st.Name).
SetImplementation(storage.Implementation(st.Implementation)).
SetImplementation(storage.Implementation(st.Implementation)).SetTvPath(st.TvPath).SetMoviePath(st.MoviePath).
SetSettings(string(data)).SetDefault(st.Default).Save(context.TODO())
if err != nil {
return err
@@ -381,15 +429,6 @@ type Storage struct {
ent.Storage
}
func (s *Storage) ToLocalSetting() LocalDirSetting {
if s.Implementation != storage.ImplementationLocal {
panic("not local storage")
}
var localSetting LocalDirSetting
json.Unmarshal([]byte(s.Settings), &localSetting)
return localSetting
}
func (s *Storage) ToWebDavSetting() WebdavSetting {
if s.Implementation != storage.ImplementationWebdav {
panic("not webdav storage")
@@ -399,12 +438,6 @@ func (s *Storage) ToWebDavSetting() WebdavSetting {
return webdavSetting
}
func (s *Storage) GetPath() (tvPath string, moviePath string) {
var m map[string]string
json.Unmarshal([]byte(s.Settings), &m)
return m["tv_path"], m["movie_path"]
}
func (c *Client) GetStorage(id int) *Storage {
r, err := c.ent.Storage.Query().Where(storage.ID(id)).First(context.TODO())
if err != nil {
@@ -439,7 +472,8 @@ func (c *Client) SetDefaultStorageByName(name string) error {
func (c *Client) SaveHistoryRecord(h ent.History) (*ent.History, error) {
return c.ent.History.Create().SetMediaID(h.MediaID).SetEpisodeID(h.EpisodeID).SetDate(time.Now()).
SetStatus(h.Status).SetTargetDir(h.TargetDir).SetSourceTitle(h.SourceTitle).SetSaved(h.Saved).Save(context.TODO())
SetStatus(h.Status).SetTargetDir(h.TargetDir).SetSourceTitle(h.SourceTitle).SetIndexerID(h.IndexerID).
SetDownloadClientID(h.DownloadClientID).SetSaved(h.Saved).Save(context.TODO())
}
func (c *Client) SetHistoryStatus(id int, status history.Status) error {
@@ -480,13 +514,13 @@ func (c *Client) GetDownloadDir() string {
return r.Value
}
func (c *Client) UpdateEpisodeFile(mediaID int, seasonNum, episodeNum int, file string) error {
func (c *Client) UpdateEpisodeStatus(mediaID int, seasonNum, episodeNum int) error {
ep, err := c.ent.Episode.Query().Where(episode.MediaID(mediaID)).Where(episode.EpisodeNumber(episodeNum)).
Where(episode.SeasonNumber(seasonNum)).First(context.TODO())
if err != nil {
return errors.Wrap(err, "finding episode")
}
return ep.Update().SetFileInStorage(file).SetStatus(episode.StatusDownloaded).Exec(context.TODO())
return ep.Update().SetStatus(episode.StatusDownloaded).Exec(context.TODO())
}
func (c *Client) SetEpisodeStatus(id int, status episode.Status) error {
@@ -501,7 +535,27 @@ func (c *Client) TmdbIdInWatchlist(tmdb_id int) bool {
return c.ent.Media.Query().Where(media.TmdbID(tmdb_id)).CountX(context.TODO()) > 0
}
func (c *Client) GetDownloadHistory(mediaID int) ([]*ent.History, error) {
return c.ent.History.Query().Where(history.MediaID(mediaID)).All(context.TODO())
}
func (c *Client) GetMovieDummyEpisode(movieId int) (*ent.Episode, error) {
_, err := c.ent.Media.Query().Where(media.ID(movieId), media.MediaTypeEQ(media.MediaTypeMovie)).First(context.TODO())
if err != nil {
return nil, errors.Wrap(err, "get movie")
}
ep, err := c.ent.Episode.Query().Where(episode.MediaID(movieId)).First(context.TODO())
if err != nil {
return nil, errors.Wrap(err, "query episode")
}
return ep, nil
}
func (c *Client) GetDownloadClient(id int) (*ent.DownloadClients, error) {
return c.ent.DownloadClients.Query().Where(downloadclients.ID(id)).First(context.Background())
}
func (c *Client) SetEpisodeMonitoring(id int, b bool) error {
return c.ent.Episode.Update().Where(episode.ID(id)).SetMonitored(b).Exec(context.Background())
}

97
db/notification.go Normal file
View File

@@ -0,0 +1,97 @@
package db
import (
"context"
"encoding/json"
"polaris/ent"
"polaris/ent/notificationclient"
"polaris/pkg/notifier"
"strings"
"github.com/pkg/errors"
)
func (c *Client) GetAllNotificationClients2() ([]*ent.NotificationClient, error) {
return c.ent.NotificationClient.Query().All(context.TODO())
}
func (c *Client) GetAllNotificationClients() ([]*NotificationClient, error) {
all, err := c.ent.NotificationClient.Query().All(context.TODO())
if err != nil {
return nil, errors.Wrap(err, "query db")
}
var all1 []*NotificationClient
for _, item := range all {
cl, err := toNotificationClient(item)
if err != nil {
return nil, errors.Wrap(err, "convert")
}
all1 = append(all1, cl)
}
return all1, nil
}
func (c *Client) AddNotificationClient(name, service string, setting string, enabled bool) error {
// data, err := json.Marshal(setting)
// if err != nil {
// return errors.Wrap(err, "json")
// }
service = strings.ToLower(service)
count, err := c.ent.NotificationClient.Query().Where(notificationclient.Name(name)).Count(context.Background())
if err == nil && count > 0 {
//update exist one
return c.ent.NotificationClient.Update().Where(notificationclient.Name(name)).SetService(service).
SetSettings(setting).SetEnabled(enabled).Exec(context.Background())
}
return c.ent.NotificationClient.Create().SetName(name).SetService(service).
SetSettings(setting).SetEnabled(enabled).Exec(context.Background())
}
func (c *Client) DeleteNotificationClient(id int) error {
_, err := c.ent.NotificationClient.Delete().Where(notificationclient.ID(id)).Exec(context.Background())
return err
}
func (c *Client) GetNotificationClient(id int) (*NotificationClient, error) {
noti, err := c.ent.NotificationClient.Query().Where(notificationclient.ID(id)).First(context.Background())
if err != nil {
return nil, errors.Wrap(err, "query")
}
return toNotificationClient(noti)
}
func toNotificationClient(cl *ent.NotificationClient) (*NotificationClient, error) {
var settings interface{}
switch cl.Service {
case "pushover":
settings = notifier.PushoverConfig{}
case "dingtalk":
settings = notifier.DingTalkConfig{}
case "telegram":
settings = notifier.TelegramConfig{}
case "bark":
settings = notifier.BarkConfig{}
}
err := json.Unmarshal([]byte(cl.Settings), &settings)
if err != nil {
return nil, errors.Wrap(err, "json")
}
return &NotificationClient{
ID: cl.ID,
Name: cl.Name,
Service: cl.Service,
Enabled: cl.Enabled,
Settings: settings,
}, nil
}
type NotificationClient struct {
ID int `json:"id"`
Name string `json:"name"`
Service string `json:"service"`
Enabled bool `json:"enabled"`
Settings interface{} `json:"settings"`
}

BIN
doc/assets/add_indexer.png Normal file
View File

Binary file not shown.

After

Width:  |  Height:  |  Size: 92 KiB

BIN
doc/assets/add_series.png Normal file
View File

Binary file not shown.

After

Width:  |  Height:  |  Size: 804 KiB

BIN
doc/assets/anime_match.png Normal file
View File

Binary file not shown.

After

Width:  |  Height:  |  Size: 774 KiB

BIN
doc/assets/copy_feed.png Normal file
View File

Binary file not shown.

After

Width:  |  Height:  |  Size: 106 KiB

View File

Before

Width:  |  Height:  |  Size: 2.1 MiB

After

Width:  |  Height:  |  Size: 2.1 MiB

BIN
doc/assets/downloader.png Normal file
View File

Binary file not shown.

After

Width:  |  Height:  |  Size: 60 KiB

View File

Binary file not shown.

After

Width:  |  Height:  |  Size: 115 KiB

View File

Binary file not shown.

After

Width:  |  Height:  |  Size: 63 KiB

BIN
doc/assets/main_page.png Normal file
View File

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 MiB

View File

Binary file not shown.

After

Width:  |  Height:  |  Size: 39 KiB

BIN
doc/assets/search_add.png Normal file
View File

Binary file not shown.

After

Width:  |  Height:  |  Size: 80 KiB

View File

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 MiB

View File

Binary file not shown.

After

Width:  |  Height:  |  Size: 80 KiB

View File

Before

Width:  |  Height:  |  Size: 111 KiB

After

Width:  |  Height:  |  Size: 111 KiB

54
doc/configuration.md Normal file
View File

@@ -0,0 +1,54 @@
# 配置
要正确使用此程序,需要配置好以下设置:
### TMDB设置
1. 因为此程序需要使用到 TMDB 的数据,使用此程序首先要申请一个 TMDB 的 Api Key. 申请教程请 google [tmdb api key申请](https://www.google.com/search?q=tmdb+api+key%E7%94%B3%E8%AF%B7)
2. 拿到 TMDB Api Key之后请填到 *设置 -> 常规设置 -> TMDB Api Key里*
### 索引器
索引器是资源提供者,目前支持 torznab 协议,意味着 polarr 或者 jackett 都可以支持。请自行部署相关程序,或者使用的 docker compose 配置一起拉起
推荐使用 linuxserver 的镜像https://docs.linuxserver.io/images/docker-jackett/
#### 索引器配置
索引器配置这里以 jackett 为例。使用默认 docker compose 配置拉起后以 http://< ip >:9117 可访问 jackett 的主页。
1. 打开 jackett 主页后,点击页面上面的 Add indexer会出现 BT/PT 站点列表,选择你需要的站点点击+号添加。如果是PT请自行配置好相关配置
![add indexer](./assets/add_indexer.png)
![search add](./assets/search_add.png)
2. 添加后主页即会显示相应的BT/PT站点点击 *Copy Torznab Feed* 即得到了我们需要的地址
![copy feed](./assets/copy_feed.png)
3. 回到我们的主程序 Polaris 当中,点击 *设置 -> 索引器设置* -> 点击+号增加新的索引器输入一个名称拷贝我们第2步得到的地址到地址栏
![polaris add indexer](./assets/polaris_add_indexer.png)
4. 选相框中我们可以看到,还需要一个 API Key我们回到 Jackett 中,在页面右上角,复制我们需要的 API Key
![api key](./assets/jackett_api_key.png)
5. 恭喜!你已经成功完成了索引器配置。如需要更多的站点,请重复相同的操作完成配置
### 下载器
资源下载器,目前可支持 tansmission请配置好对应配置
![transmission](./assets/downloader.png)
### 存储设置
默认配置了名为 local 的本地存储,如果你不知道怎么配置。请使用默认配置
![local_storage](./assets/local_storage.png)
类型里选择 webdav 可以使用 webdav 存储,配合 alist/clouddrive 等,可以实现存储到云盘里的功能。
![webdav](./assets/webdav_storage.png)

69
doc/quick_start.md Normal file
View File

@@ -0,0 +1,69 @@
## 快速开始
最简单部署 Polaris 的方式是使用 docker composePolaris要完整运行另外需要一个索引客户端和一个下载客户端。索引客户端支持 polarr 或 jackett下载客户端目前只支持 transmission。
下面是一个示例 docker-compose 配置,为了简单起见,一起拉起了 transmission 和 jackett你也可选择单独安装
**注意:** transmission 的下载路径映射要和 polaris 保持一致,如果您不知道怎么做,请保持默认设置。
```yaml
services:
polaris:
image: ghcr.io/simon-ding/polaris:latest
restart: always
volumes:
- ./config/polaris:/app/data #程序配置文件路径
- /downloads:/downloads #下载路径,需要和下载客户端配置一致
- /data:/data #媒体数据存储路径也可以启动自己配置webdav存储
ports:
- 8080:8080
transmission: #下载客户端,也可以不安装使用已有的
image: lscr.io/linuxserver/transmission:latest
environment:
- PUID=1000
- PGID=1000
- TZ=Asia/Shanghai
volumes:
- ./config/transmission:/config
- /downloads:/downloads #此路径要与polaris下载路径保持一致
ports:
- 9091:9091
- 51413:51413
- 51413:51413/udp
jackett: #索引客户端,也可以不安装使用已有的
image: lscr.io/linuxserver/jackett:latest
environment:
- PUID=1000
- PGID=1000
- TZ=Asia/Shanghai
volumes:
- ./config/jackett:/config
ports:
- 9117:9117
restart: unless-stopped
```
拉起之后访问 http://< ip >:8080 的形式访问
![](./assets/main_page.png)
## 配置
详细配置请看 [配置篇](./configuration.md)
## 开始使用
1. 完成配置之后,我们就可以在右上角的搜索按钮里输入我们想看的电影、电视剧。
![search](./assets/search_series.png)
2. 找到对应电影电视剧后,点击加入想看列表
![add](./assets/add_series.png)
3. 当电影有资源、或者电视剧有更新时,程序就会自动下载对应资源到指定的存储。对于剧集,您也可以进入剧集的详细页面,点击搜索按钮来自己搜索对应集的资源。
到此,您已经基本掌握了此程序的使用方式,请尽情体验吧!

View File

@@ -16,6 +16,7 @@ import (
"polaris/ent/history"
"polaris/ent/indexers"
"polaris/ent/media"
"polaris/ent/notificationclient"
"polaris/ent/settings"
"polaris/ent/storage"
@@ -40,6 +41,8 @@ type Client struct {
Indexers *IndexersClient
// Media is the client for interacting with the Media builders.
Media *MediaClient
// NotificationClient is the client for interacting with the NotificationClient builders.
NotificationClient *NotificationClientClient
// Settings is the client for interacting with the Settings builders.
Settings *SettingsClient
// Storage is the client for interacting with the Storage builders.
@@ -60,6 +63,7 @@ func (c *Client) init() {
c.History = NewHistoryClient(c.config)
c.Indexers = NewIndexersClient(c.config)
c.Media = NewMediaClient(c.config)
c.NotificationClient = NewNotificationClientClient(c.config)
c.Settings = NewSettingsClient(c.config)
c.Storage = NewStorageClient(c.config)
}
@@ -152,15 +156,16 @@ func (c *Client) Tx(ctx context.Context) (*Tx, error) {
cfg := c.config
cfg.driver = tx
return &Tx{
ctx: ctx,
config: cfg,
DownloadClients: NewDownloadClientsClient(cfg),
Episode: NewEpisodeClient(cfg),
History: NewHistoryClient(cfg),
Indexers: NewIndexersClient(cfg),
Media: NewMediaClient(cfg),
Settings: NewSettingsClient(cfg),
Storage: NewStorageClient(cfg),
ctx: ctx,
config: cfg,
DownloadClients: NewDownloadClientsClient(cfg),
Episode: NewEpisodeClient(cfg),
History: NewHistoryClient(cfg),
Indexers: NewIndexersClient(cfg),
Media: NewMediaClient(cfg),
NotificationClient: NewNotificationClientClient(cfg),
Settings: NewSettingsClient(cfg),
Storage: NewStorageClient(cfg),
}, nil
}
@@ -178,15 +183,16 @@ func (c *Client) BeginTx(ctx context.Context, opts *sql.TxOptions) (*Tx, error)
cfg := c.config
cfg.driver = &txDriver{tx: tx, drv: c.driver}
return &Tx{
ctx: ctx,
config: cfg,
DownloadClients: NewDownloadClientsClient(cfg),
Episode: NewEpisodeClient(cfg),
History: NewHistoryClient(cfg),
Indexers: NewIndexersClient(cfg),
Media: NewMediaClient(cfg),
Settings: NewSettingsClient(cfg),
Storage: NewStorageClient(cfg),
ctx: ctx,
config: cfg,
DownloadClients: NewDownloadClientsClient(cfg),
Episode: NewEpisodeClient(cfg),
History: NewHistoryClient(cfg),
Indexers: NewIndexersClient(cfg),
Media: NewMediaClient(cfg),
NotificationClient: NewNotificationClientClient(cfg),
Settings: NewSettingsClient(cfg),
Storage: NewStorageClient(cfg),
}, nil
}
@@ -216,8 +222,8 @@ func (c *Client) Close() error {
// In order to add hooks to a specific client, call: `client.Node.Use(...)`.
func (c *Client) Use(hooks ...Hook) {
for _, n := range []interface{ Use(...Hook) }{
c.DownloadClients, c.Episode, c.History, c.Indexers, c.Media, c.Settings,
c.Storage,
c.DownloadClients, c.Episode, c.History, c.Indexers, c.Media,
c.NotificationClient, c.Settings, c.Storage,
} {
n.Use(hooks...)
}
@@ -227,8 +233,8 @@ func (c *Client) Use(hooks ...Hook) {
// In order to add interceptors to a specific client, call: `client.Node.Intercept(...)`.
func (c *Client) Intercept(interceptors ...Interceptor) {
for _, n := range []interface{ Intercept(...Interceptor) }{
c.DownloadClients, c.Episode, c.History, c.Indexers, c.Media, c.Settings,
c.Storage,
c.DownloadClients, c.Episode, c.History, c.Indexers, c.Media,
c.NotificationClient, c.Settings, c.Storage,
} {
n.Intercept(interceptors...)
}
@@ -247,6 +253,8 @@ func (c *Client) Mutate(ctx context.Context, m Mutation) (Value, error) {
return c.Indexers.mutate(ctx, m)
case *MediaMutation:
return c.Media.mutate(ctx, m)
case *NotificationClientMutation:
return c.NotificationClient.mutate(ctx, m)
case *SettingsMutation:
return c.Settings.mutate(ctx, m)
case *StorageMutation:
@@ -953,6 +961,139 @@ func (c *MediaClient) mutate(ctx context.Context, m *MediaMutation) (Value, erro
}
}
// NotificationClientClient is a client for the NotificationClient schema.
type NotificationClientClient struct {
config
}
// NewNotificationClientClient returns a client for the NotificationClient from the given config.
func NewNotificationClientClient(c config) *NotificationClientClient {
return &NotificationClientClient{config: c}
}
// Use adds a list of mutation hooks to the hooks stack.
// A call to `Use(f, g, h)` equals to `notificationclient.Hooks(f(g(h())))`.
func (c *NotificationClientClient) Use(hooks ...Hook) {
c.hooks.NotificationClient = append(c.hooks.NotificationClient, hooks...)
}
// Intercept adds a list of query interceptors to the interceptors stack.
// A call to `Intercept(f, g, h)` equals to `notificationclient.Intercept(f(g(h())))`.
func (c *NotificationClientClient) Intercept(interceptors ...Interceptor) {
c.inters.NotificationClient = append(c.inters.NotificationClient, interceptors...)
}
// Create returns a builder for creating a NotificationClient entity.
func (c *NotificationClientClient) Create() *NotificationClientCreate {
mutation := newNotificationClientMutation(c.config, OpCreate)
return &NotificationClientCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// CreateBulk returns a builder for creating a bulk of NotificationClient entities.
func (c *NotificationClientClient) CreateBulk(builders ...*NotificationClientCreate) *NotificationClientCreateBulk {
return &NotificationClientCreateBulk{config: c.config, builders: builders}
}
// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates
// a builder and applies setFunc on it.
func (c *NotificationClientClient) MapCreateBulk(slice any, setFunc func(*NotificationClientCreate, int)) *NotificationClientCreateBulk {
rv := reflect.ValueOf(slice)
if rv.Kind() != reflect.Slice {
return &NotificationClientCreateBulk{err: fmt.Errorf("calling to NotificationClientClient.MapCreateBulk with wrong type %T, need slice", slice)}
}
builders := make([]*NotificationClientCreate, rv.Len())
for i := 0; i < rv.Len(); i++ {
builders[i] = c.Create()
setFunc(builders[i], i)
}
return &NotificationClientCreateBulk{config: c.config, builders: builders}
}
// Update returns an update builder for NotificationClient.
func (c *NotificationClientClient) Update() *NotificationClientUpdate {
mutation := newNotificationClientMutation(c.config, OpUpdate)
return &NotificationClientUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// UpdateOne returns an update builder for the given entity.
func (c *NotificationClientClient) UpdateOne(nc *NotificationClient) *NotificationClientUpdateOne {
mutation := newNotificationClientMutation(c.config, OpUpdateOne, withNotificationClient(nc))
return &NotificationClientUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// UpdateOneID returns an update builder for the given id.
func (c *NotificationClientClient) UpdateOneID(id int) *NotificationClientUpdateOne {
mutation := newNotificationClientMutation(c.config, OpUpdateOne, withNotificationClientID(id))
return &NotificationClientUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// Delete returns a delete builder for NotificationClient.
func (c *NotificationClientClient) Delete() *NotificationClientDelete {
mutation := newNotificationClientMutation(c.config, OpDelete)
return &NotificationClientDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// DeleteOne returns a builder for deleting the given entity.
func (c *NotificationClientClient) DeleteOne(nc *NotificationClient) *NotificationClientDeleteOne {
return c.DeleteOneID(nc.ID)
}
// DeleteOneID returns a builder for deleting the given entity by its id.
func (c *NotificationClientClient) DeleteOneID(id int) *NotificationClientDeleteOne {
builder := c.Delete().Where(notificationclient.ID(id))
builder.mutation.id = &id
builder.mutation.op = OpDeleteOne
return &NotificationClientDeleteOne{builder}
}
// Query returns a query builder for NotificationClient.
func (c *NotificationClientClient) Query() *NotificationClientQuery {
return &NotificationClientQuery{
config: c.config,
ctx: &QueryContext{Type: TypeNotificationClient},
inters: c.Interceptors(),
}
}
// Get returns a NotificationClient entity by its id.
func (c *NotificationClientClient) Get(ctx context.Context, id int) (*NotificationClient, error) {
return c.Query().Where(notificationclient.ID(id)).Only(ctx)
}
// GetX is like Get, but panics if an error occurs.
func (c *NotificationClientClient) GetX(ctx context.Context, id int) *NotificationClient {
obj, err := c.Get(ctx, id)
if err != nil {
panic(err)
}
return obj
}
// Hooks returns the client hooks.
func (c *NotificationClientClient) Hooks() []Hook {
return c.hooks.NotificationClient
}
// Interceptors returns the client interceptors.
func (c *NotificationClientClient) Interceptors() []Interceptor {
return c.inters.NotificationClient
}
func (c *NotificationClientClient) mutate(ctx context.Context, m *NotificationClientMutation) (Value, error) {
switch m.Op() {
case OpCreate:
return (&NotificationClientCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
case OpUpdate:
return (&NotificationClientUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
case OpUpdateOne:
return (&NotificationClientUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
case OpDelete, OpDeleteOne:
return (&NotificationClientDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
default:
return nil, fmt.Errorf("ent: unknown NotificationClient mutation op: %q", m.Op())
}
}
// SettingsClient is a client for the Settings schema.
type SettingsClient struct {
config
@@ -1222,10 +1363,11 @@ func (c *StorageClient) mutate(ctx context.Context, m *StorageMutation) (Value,
// hooks and interceptors per client, for fast access.
type (
hooks struct {
DownloadClients, Episode, History, Indexers, Media, Settings, Storage []ent.Hook
DownloadClients, Episode, History, Indexers, Media, NotificationClient,
Settings, Storage []ent.Hook
}
inters struct {
DownloadClients, Episode, History, Indexers, Media, Settings,
Storage []ent.Interceptor
DownloadClients, Episode, History, Indexers, Media, NotificationClient,
Settings, Storage []ent.Interceptor
}
)

View File

@@ -11,6 +11,7 @@ import (
"polaris/ent/history"
"polaris/ent/indexers"
"polaris/ent/media"
"polaris/ent/notificationclient"
"polaris/ent/settings"
"polaris/ent/storage"
"reflect"
@@ -79,13 +80,14 @@ var (
func checkColumn(table, column string) error {
initCheck.Do(func() {
columnCheck = sql.NewColumnCheck(map[string]func(string) bool{
downloadclients.Table: downloadclients.ValidColumn,
episode.Table: episode.ValidColumn,
history.Table: history.ValidColumn,
indexers.Table: indexers.ValidColumn,
media.Table: media.ValidColumn,
settings.Table: settings.ValidColumn,
storage.Table: storage.ValidColumn,
downloadclients.Table: downloadclients.ValidColumn,
episode.Table: episode.ValidColumn,
history.Table: history.ValidColumn,
indexers.Table: indexers.ValidColumn,
media.Table: media.ValidColumn,
notificationclient.Table: notificationclient.ValidColumn,
settings.Table: settings.ValidColumn,
storage.Table: storage.ValidColumn,
})
})
return columnCheck(table, column)

View File

@@ -31,8 +31,8 @@ type Episode struct {
AirDate string `json:"air_date,omitempty"`
// Status holds the value of the "status" field.
Status episode.Status `json:"status,omitempty"`
// FileInStorage holds the value of the "file_in_storage" field.
FileInStorage string `json:"file_in_storage,omitempty"`
// Monitored holds the value of the "monitored" field.
Monitored bool `json:"monitored"`
// Edges holds the relations/edges for other nodes in the graph.
// The values are being populated by the EpisodeQuery when eager-loading is set.
Edges EpisodeEdges `json:"edges"`
@@ -64,9 +64,11 @@ func (*Episode) scanValues(columns []string) ([]any, error) {
values := make([]any, len(columns))
for i := range columns {
switch columns[i] {
case episode.FieldMonitored:
values[i] = new(sql.NullBool)
case episode.FieldID, episode.FieldMediaID, episode.FieldSeasonNumber, episode.FieldEpisodeNumber:
values[i] = new(sql.NullInt64)
case episode.FieldTitle, episode.FieldOverview, episode.FieldAirDate, episode.FieldStatus, episode.FieldFileInStorage:
case episode.FieldTitle, episode.FieldOverview, episode.FieldAirDate, episode.FieldStatus:
values[i] = new(sql.NullString)
default:
values[i] = new(sql.UnknownType)
@@ -131,11 +133,11 @@ func (e *Episode) assignValues(columns []string, values []any) error {
} else if value.Valid {
e.Status = episode.Status(value.String)
}
case episode.FieldFileInStorage:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field file_in_storage", values[i])
case episode.FieldMonitored:
if value, ok := values[i].(*sql.NullBool); !ok {
return fmt.Errorf("unexpected type %T for field monitored", values[i])
} else if value.Valid {
e.FileInStorage = value.String
e.Monitored = value.Bool
}
default:
e.selectValues.Set(columns[i], values[i])
@@ -199,8 +201,8 @@ func (e *Episode) String() string {
builder.WriteString("status=")
builder.WriteString(fmt.Sprintf("%v", e.Status))
builder.WriteString(", ")
builder.WriteString("file_in_storage=")
builder.WriteString(e.FileInStorage)
builder.WriteString("monitored=")
builder.WriteString(fmt.Sprintf("%v", e.Monitored))
builder.WriteByte(')')
return builder.String()
}

View File

@@ -28,8 +28,8 @@ const (
FieldAirDate = "air_date"
// FieldStatus holds the string denoting the status field in the database.
FieldStatus = "status"
// FieldFileInStorage holds the string denoting the file_in_storage field in the database.
FieldFileInStorage = "file_in_storage"
// FieldMonitored holds the string denoting the monitored field in the database.
FieldMonitored = "monitored"
// EdgeMedia holds the string denoting the media edge name in mutations.
EdgeMedia = "media"
// Table holds the table name of the episode in the database.
@@ -53,7 +53,7 @@ var Columns = []string{
FieldOverview,
FieldAirDate,
FieldStatus,
FieldFileInStorage,
FieldMonitored,
}
// ValidColumn reports if the column name is valid (part of the table columns).
@@ -66,6 +66,11 @@ func ValidColumn(column string) bool {
return false
}
var (
// DefaultMonitored holds the default value on creation for the "monitored" field.
DefaultMonitored bool
)
// Status defines the type for the "status" enum field.
type Status string
@@ -136,9 +141,9 @@ func ByStatus(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldStatus, opts...).ToFunc()
}
// ByFileInStorage orders the results by the file_in_storage field.
func ByFileInStorage(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldFileInStorage, opts...).ToFunc()
// ByMonitored orders the results by the monitored field.
func ByMonitored(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldMonitored, opts...).ToFunc()
}
// ByMediaField orders the results by media field.

View File

@@ -84,9 +84,9 @@ func AirDate(v string) predicate.Episode {
return predicate.Episode(sql.FieldEQ(FieldAirDate, v))
}
// FileInStorage applies equality check predicate on the "file_in_storage" field. It's identical to FileInStorageEQ.
func FileInStorage(v string) predicate.Episode {
return predicate.Episode(sql.FieldEQ(FieldFileInStorage, v))
// Monitored applies equality check predicate on the "monitored" field. It's identical to MonitoredEQ.
func Monitored(v bool) predicate.Episode {
return predicate.Episode(sql.FieldEQ(FieldMonitored, v))
}
// MediaIDEQ applies the EQ predicate on the "media_id" field.
@@ -414,79 +414,14 @@ func StatusNotIn(vs ...Status) predicate.Episode {
return predicate.Episode(sql.FieldNotIn(FieldStatus, vs...))
}
// FileInStorageEQ applies the EQ predicate on the "file_in_storage" field.
func FileInStorageEQ(v string) predicate.Episode {
return predicate.Episode(sql.FieldEQ(FieldFileInStorage, v))
// MonitoredEQ applies the EQ predicate on the "monitored" field.
func MonitoredEQ(v bool) predicate.Episode {
return predicate.Episode(sql.FieldEQ(FieldMonitored, v))
}
// FileInStorageNEQ applies the NEQ predicate on the "file_in_storage" field.
func FileInStorageNEQ(v string) predicate.Episode {
return predicate.Episode(sql.FieldNEQ(FieldFileInStorage, v))
}
// FileInStorageIn applies the In predicate on the "file_in_storage" field.
func FileInStorageIn(vs ...string) predicate.Episode {
return predicate.Episode(sql.FieldIn(FieldFileInStorage, vs...))
}
// FileInStorageNotIn applies the NotIn predicate on the "file_in_storage" field.
func FileInStorageNotIn(vs ...string) predicate.Episode {
return predicate.Episode(sql.FieldNotIn(FieldFileInStorage, vs...))
}
// FileInStorageGT applies the GT predicate on the "file_in_storage" field.
func FileInStorageGT(v string) predicate.Episode {
return predicate.Episode(sql.FieldGT(FieldFileInStorage, v))
}
// FileInStorageGTE applies the GTE predicate on the "file_in_storage" field.
func FileInStorageGTE(v string) predicate.Episode {
return predicate.Episode(sql.FieldGTE(FieldFileInStorage, v))
}
// FileInStorageLT applies the LT predicate on the "file_in_storage" field.
func FileInStorageLT(v string) predicate.Episode {
return predicate.Episode(sql.FieldLT(FieldFileInStorage, v))
}
// FileInStorageLTE applies the LTE predicate on the "file_in_storage" field.
func FileInStorageLTE(v string) predicate.Episode {
return predicate.Episode(sql.FieldLTE(FieldFileInStorage, v))
}
// FileInStorageContains applies the Contains predicate on the "file_in_storage" field.
func FileInStorageContains(v string) predicate.Episode {
return predicate.Episode(sql.FieldContains(FieldFileInStorage, v))
}
// FileInStorageHasPrefix applies the HasPrefix predicate on the "file_in_storage" field.
func FileInStorageHasPrefix(v string) predicate.Episode {
return predicate.Episode(sql.FieldHasPrefix(FieldFileInStorage, v))
}
// FileInStorageHasSuffix applies the HasSuffix predicate on the "file_in_storage" field.
func FileInStorageHasSuffix(v string) predicate.Episode {
return predicate.Episode(sql.FieldHasSuffix(FieldFileInStorage, v))
}
// FileInStorageIsNil applies the IsNil predicate on the "file_in_storage" field.
func FileInStorageIsNil() predicate.Episode {
return predicate.Episode(sql.FieldIsNull(FieldFileInStorage))
}
// FileInStorageNotNil applies the NotNil predicate on the "file_in_storage" field.
func FileInStorageNotNil() predicate.Episode {
return predicate.Episode(sql.FieldNotNull(FieldFileInStorage))
}
// FileInStorageEqualFold applies the EqualFold predicate on the "file_in_storage" field.
func FileInStorageEqualFold(v string) predicate.Episode {
return predicate.Episode(sql.FieldEqualFold(FieldFileInStorage, v))
}
// FileInStorageContainsFold applies the ContainsFold predicate on the "file_in_storage" field.
func FileInStorageContainsFold(v string) predicate.Episode {
return predicate.Episode(sql.FieldContainsFold(FieldFileInStorage, v))
// MonitoredNEQ applies the NEQ predicate on the "monitored" field.
func MonitoredNEQ(v bool) predicate.Episode {
return predicate.Episode(sql.FieldNEQ(FieldMonitored, v))
}
// HasMedia applies the HasEdge predicate on the "media" edge.

View File

@@ -78,16 +78,16 @@ func (ec *EpisodeCreate) SetNillableStatus(e *episode.Status) *EpisodeCreate {
return ec
}
// SetFileInStorage sets the "file_in_storage" field.
func (ec *EpisodeCreate) SetFileInStorage(s string) *EpisodeCreate {
ec.mutation.SetFileInStorage(s)
// SetMonitored sets the "monitored" field.
func (ec *EpisodeCreate) SetMonitored(b bool) *EpisodeCreate {
ec.mutation.SetMonitored(b)
return ec
}
// SetNillableFileInStorage sets the "file_in_storage" field if the given value is not nil.
func (ec *EpisodeCreate) SetNillableFileInStorage(s *string) *EpisodeCreate {
if s != nil {
ec.SetFileInStorage(*s)
// SetNillableMonitored sets the "monitored" field if the given value is not nil.
func (ec *EpisodeCreate) SetNillableMonitored(b *bool) *EpisodeCreate {
if b != nil {
ec.SetMonitored(*b)
}
return ec
}
@@ -136,6 +136,10 @@ func (ec *EpisodeCreate) defaults() {
v := episode.DefaultStatus
ec.mutation.SetStatus(v)
}
if _, ok := ec.mutation.Monitored(); !ok {
v := episode.DefaultMonitored
ec.mutation.SetMonitored(v)
}
}
// check runs all checks and user-defined validators on the builder.
@@ -163,6 +167,9 @@ func (ec *EpisodeCreate) check() error {
return &ValidationError{Name: "status", err: fmt.Errorf(`ent: validator failed for field "Episode.status": %w`, err)}
}
}
if _, ok := ec.mutation.Monitored(); !ok {
return &ValidationError{Name: "monitored", err: errors.New(`ent: missing required field "Episode.monitored"`)}
}
return nil
}
@@ -213,9 +220,9 @@ func (ec *EpisodeCreate) createSpec() (*Episode, *sqlgraph.CreateSpec) {
_spec.SetField(episode.FieldStatus, field.TypeEnum, value)
_node.Status = value
}
if value, ok := ec.mutation.FileInStorage(); ok {
_spec.SetField(episode.FieldFileInStorage, field.TypeString, value)
_node.FileInStorage = value
if value, ok := ec.mutation.Monitored(); ok {
_spec.SetField(episode.FieldMonitored, field.TypeBool, value)
_node.Monitored = value
}
if nodes := ec.mutation.MediaIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{

View File

@@ -146,26 +146,20 @@ func (eu *EpisodeUpdate) SetNillableStatus(e *episode.Status) *EpisodeUpdate {
return eu
}
// SetFileInStorage sets the "file_in_storage" field.
func (eu *EpisodeUpdate) SetFileInStorage(s string) *EpisodeUpdate {
eu.mutation.SetFileInStorage(s)
// SetMonitored sets the "monitored" field.
func (eu *EpisodeUpdate) SetMonitored(b bool) *EpisodeUpdate {
eu.mutation.SetMonitored(b)
return eu
}
// SetNillableFileInStorage sets the "file_in_storage" field if the given value is not nil.
func (eu *EpisodeUpdate) SetNillableFileInStorage(s *string) *EpisodeUpdate {
if s != nil {
eu.SetFileInStorage(*s)
// SetNillableMonitored sets the "monitored" field if the given value is not nil.
func (eu *EpisodeUpdate) SetNillableMonitored(b *bool) *EpisodeUpdate {
if b != nil {
eu.SetMonitored(*b)
}
return eu
}
// ClearFileInStorage clears the value of the "file_in_storage" field.
func (eu *EpisodeUpdate) ClearFileInStorage() *EpisodeUpdate {
eu.mutation.ClearFileInStorage()
return eu
}
// SetMedia sets the "media" edge to the Media entity.
func (eu *EpisodeUpdate) SetMedia(m *Media) *EpisodeUpdate {
return eu.SetMediaID(m.ID)
@@ -255,11 +249,8 @@ func (eu *EpisodeUpdate) sqlSave(ctx context.Context) (n int, err error) {
if value, ok := eu.mutation.Status(); ok {
_spec.SetField(episode.FieldStatus, field.TypeEnum, value)
}
if value, ok := eu.mutation.FileInStorage(); ok {
_spec.SetField(episode.FieldFileInStorage, field.TypeString, value)
}
if eu.mutation.FileInStorageCleared() {
_spec.ClearField(episode.FieldFileInStorage, field.TypeString)
if value, ok := eu.mutation.Monitored(); ok {
_spec.SetField(episode.FieldMonitored, field.TypeBool, value)
}
if eu.mutation.MediaCleared() {
edge := &sqlgraph.EdgeSpec{
@@ -428,26 +419,20 @@ func (euo *EpisodeUpdateOne) SetNillableStatus(e *episode.Status) *EpisodeUpdate
return euo
}
// SetFileInStorage sets the "file_in_storage" field.
func (euo *EpisodeUpdateOne) SetFileInStorage(s string) *EpisodeUpdateOne {
euo.mutation.SetFileInStorage(s)
// SetMonitored sets the "monitored" field.
func (euo *EpisodeUpdateOne) SetMonitored(b bool) *EpisodeUpdateOne {
euo.mutation.SetMonitored(b)
return euo
}
// SetNillableFileInStorage sets the "file_in_storage" field if the given value is not nil.
func (euo *EpisodeUpdateOne) SetNillableFileInStorage(s *string) *EpisodeUpdateOne {
if s != nil {
euo.SetFileInStorage(*s)
// SetNillableMonitored sets the "monitored" field if the given value is not nil.
func (euo *EpisodeUpdateOne) SetNillableMonitored(b *bool) *EpisodeUpdateOne {
if b != nil {
euo.SetMonitored(*b)
}
return euo
}
// ClearFileInStorage clears the value of the "file_in_storage" field.
func (euo *EpisodeUpdateOne) ClearFileInStorage() *EpisodeUpdateOne {
euo.mutation.ClearFileInStorage()
return euo
}
// SetMedia sets the "media" edge to the Media entity.
func (euo *EpisodeUpdateOne) SetMedia(m *Media) *EpisodeUpdateOne {
return euo.SetMediaID(m.ID)
@@ -567,11 +552,8 @@ func (euo *EpisodeUpdateOne) sqlSave(ctx context.Context) (_node *Episode, err e
if value, ok := euo.mutation.Status(); ok {
_spec.SetField(episode.FieldStatus, field.TypeEnum, value)
}
if value, ok := euo.mutation.FileInStorage(); ok {
_spec.SetField(episode.FieldFileInStorage, field.TypeString, value)
}
if euo.mutation.FileInStorageCleared() {
_spec.ClearField(episode.FieldFileInStorage, field.TypeString)
if value, ok := euo.mutation.Monitored(); ok {
_spec.SetField(episode.FieldMonitored, field.TypeBool, value)
}
if euo.mutation.MediaCleared() {
edge := &sqlgraph.EdgeSpec{

View File

@@ -29,6 +29,10 @@ type History struct {
TargetDir string `json:"target_dir,omitempty"`
// Size holds the value of the "size" field.
Size int `json:"size,omitempty"`
// DownloadClientID holds the value of the "download_client_id" field.
DownloadClientID int `json:"download_client_id,omitempty"`
// IndexerID holds the value of the "indexer_id" field.
IndexerID int `json:"indexer_id,omitempty"`
// Status holds the value of the "status" field.
Status history.Status `json:"status,omitempty"`
// Saved holds the value of the "saved" field.
@@ -41,7 +45,7 @@ func (*History) scanValues(columns []string) ([]any, error) {
values := make([]any, len(columns))
for i := range columns {
switch columns[i] {
case history.FieldID, history.FieldMediaID, history.FieldEpisodeID, history.FieldSize:
case history.FieldID, history.FieldMediaID, history.FieldEpisodeID, history.FieldSize, history.FieldDownloadClientID, history.FieldIndexerID:
values[i] = new(sql.NullInt64)
case history.FieldSourceTitle, history.FieldTargetDir, history.FieldStatus, history.FieldSaved:
values[i] = new(sql.NullString)
@@ -104,6 +108,18 @@ func (h *History) assignValues(columns []string, values []any) error {
} else if value.Valid {
h.Size = int(value.Int64)
}
case history.FieldDownloadClientID:
if value, ok := values[i].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for field download_client_id", values[i])
} else if value.Valid {
h.DownloadClientID = int(value.Int64)
}
case history.FieldIndexerID:
if value, ok := values[i].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for field indexer_id", values[i])
} else if value.Valid {
h.IndexerID = int(value.Int64)
}
case history.FieldStatus:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field status", values[i])
@@ -170,6 +186,12 @@ func (h *History) String() string {
builder.WriteString("size=")
builder.WriteString(fmt.Sprintf("%v", h.Size))
builder.WriteString(", ")
builder.WriteString("download_client_id=")
builder.WriteString(fmt.Sprintf("%v", h.DownloadClientID))
builder.WriteString(", ")
builder.WriteString("indexer_id=")
builder.WriteString(fmt.Sprintf("%v", h.IndexerID))
builder.WriteString(", ")
builder.WriteString("status=")
builder.WriteString(fmt.Sprintf("%v", h.Status))
builder.WriteString(", ")

View File

@@ -25,6 +25,10 @@ const (
FieldTargetDir = "target_dir"
// FieldSize holds the string denoting the size field in the database.
FieldSize = "size"
// FieldDownloadClientID holds the string denoting the download_client_id field in the database.
FieldDownloadClientID = "download_client_id"
// FieldIndexerID holds the string denoting the indexer_id field in the database.
FieldIndexerID = "indexer_id"
// FieldStatus holds the string denoting the status field in the database.
FieldStatus = "status"
// FieldSaved holds the string denoting the saved field in the database.
@@ -42,6 +46,8 @@ var Columns = []string{
FieldDate,
FieldTargetDir,
FieldSize,
FieldDownloadClientID,
FieldIndexerID,
FieldStatus,
FieldSaved,
}
@@ -124,6 +130,16 @@ func BySize(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldSize, opts...).ToFunc()
}
// ByDownloadClientID orders the results by the download_client_id field.
func ByDownloadClientID(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldDownloadClientID, opts...).ToFunc()
}
// ByIndexerID orders the results by the indexer_id field.
func ByIndexerID(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldIndexerID, opts...).ToFunc()
}
// ByStatus orders the results by the status field.
func ByStatus(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldStatus, opts...).ToFunc()

View File

@@ -84,6 +84,16 @@ func Size(v int) predicate.History {
return predicate.History(sql.FieldEQ(FieldSize, v))
}
// DownloadClientID applies equality check predicate on the "download_client_id" field. It's identical to DownloadClientIDEQ.
func DownloadClientID(v int) predicate.History {
return predicate.History(sql.FieldEQ(FieldDownloadClientID, v))
}
// IndexerID applies equality check predicate on the "indexer_id" field. It's identical to IndexerIDEQ.
func IndexerID(v int) predicate.History {
return predicate.History(sql.FieldEQ(FieldIndexerID, v))
}
// Saved applies equality check predicate on the "saved" field. It's identical to SavedEQ.
func Saved(v string) predicate.History {
return predicate.History(sql.FieldEQ(FieldSaved, v))
@@ -389,6 +399,106 @@ func SizeLTE(v int) predicate.History {
return predicate.History(sql.FieldLTE(FieldSize, v))
}
// DownloadClientIDEQ applies the EQ predicate on the "download_client_id" field.
func DownloadClientIDEQ(v int) predicate.History {
return predicate.History(sql.FieldEQ(FieldDownloadClientID, v))
}
// DownloadClientIDNEQ applies the NEQ predicate on the "download_client_id" field.
func DownloadClientIDNEQ(v int) predicate.History {
return predicate.History(sql.FieldNEQ(FieldDownloadClientID, v))
}
// DownloadClientIDIn applies the In predicate on the "download_client_id" field.
func DownloadClientIDIn(vs ...int) predicate.History {
return predicate.History(sql.FieldIn(FieldDownloadClientID, vs...))
}
// DownloadClientIDNotIn applies the NotIn predicate on the "download_client_id" field.
func DownloadClientIDNotIn(vs ...int) predicate.History {
return predicate.History(sql.FieldNotIn(FieldDownloadClientID, vs...))
}
// DownloadClientIDGT applies the GT predicate on the "download_client_id" field.
func DownloadClientIDGT(v int) predicate.History {
return predicate.History(sql.FieldGT(FieldDownloadClientID, v))
}
// DownloadClientIDGTE applies the GTE predicate on the "download_client_id" field.
func DownloadClientIDGTE(v int) predicate.History {
return predicate.History(sql.FieldGTE(FieldDownloadClientID, v))
}
// DownloadClientIDLT applies the LT predicate on the "download_client_id" field.
func DownloadClientIDLT(v int) predicate.History {
return predicate.History(sql.FieldLT(FieldDownloadClientID, v))
}
// DownloadClientIDLTE applies the LTE predicate on the "download_client_id" field.
func DownloadClientIDLTE(v int) predicate.History {
return predicate.History(sql.FieldLTE(FieldDownloadClientID, v))
}
// DownloadClientIDIsNil applies the IsNil predicate on the "download_client_id" field.
func DownloadClientIDIsNil() predicate.History {
return predicate.History(sql.FieldIsNull(FieldDownloadClientID))
}
// DownloadClientIDNotNil applies the NotNil predicate on the "download_client_id" field.
func DownloadClientIDNotNil() predicate.History {
return predicate.History(sql.FieldNotNull(FieldDownloadClientID))
}
// IndexerIDEQ applies the EQ predicate on the "indexer_id" field.
func IndexerIDEQ(v int) predicate.History {
return predicate.History(sql.FieldEQ(FieldIndexerID, v))
}
// IndexerIDNEQ applies the NEQ predicate on the "indexer_id" field.
func IndexerIDNEQ(v int) predicate.History {
return predicate.History(sql.FieldNEQ(FieldIndexerID, v))
}
// IndexerIDIn applies the In predicate on the "indexer_id" field.
func IndexerIDIn(vs ...int) predicate.History {
return predicate.History(sql.FieldIn(FieldIndexerID, vs...))
}
// IndexerIDNotIn applies the NotIn predicate on the "indexer_id" field.
func IndexerIDNotIn(vs ...int) predicate.History {
return predicate.History(sql.FieldNotIn(FieldIndexerID, vs...))
}
// IndexerIDGT applies the GT predicate on the "indexer_id" field.
func IndexerIDGT(v int) predicate.History {
return predicate.History(sql.FieldGT(FieldIndexerID, v))
}
// IndexerIDGTE applies the GTE predicate on the "indexer_id" field.
func IndexerIDGTE(v int) predicate.History {
return predicate.History(sql.FieldGTE(FieldIndexerID, v))
}
// IndexerIDLT applies the LT predicate on the "indexer_id" field.
func IndexerIDLT(v int) predicate.History {
return predicate.History(sql.FieldLT(FieldIndexerID, v))
}
// IndexerIDLTE applies the LTE predicate on the "indexer_id" field.
func IndexerIDLTE(v int) predicate.History {
return predicate.History(sql.FieldLTE(FieldIndexerID, v))
}
// IndexerIDIsNil applies the IsNil predicate on the "indexer_id" field.
func IndexerIDIsNil() predicate.History {
return predicate.History(sql.FieldIsNull(FieldIndexerID))
}
// IndexerIDNotNil applies the NotNil predicate on the "indexer_id" field.
func IndexerIDNotNil() predicate.History {
return predicate.History(sql.FieldNotNull(FieldIndexerID))
}
// StatusEQ applies the EQ predicate on the "status" field.
func StatusEQ(v Status) predicate.History {
return predicate.History(sql.FieldEQ(FieldStatus, v))

View File

@@ -72,6 +72,34 @@ func (hc *HistoryCreate) SetNillableSize(i *int) *HistoryCreate {
return hc
}
// SetDownloadClientID sets the "download_client_id" field.
func (hc *HistoryCreate) SetDownloadClientID(i int) *HistoryCreate {
hc.mutation.SetDownloadClientID(i)
return hc
}
// SetNillableDownloadClientID sets the "download_client_id" field if the given value is not nil.
func (hc *HistoryCreate) SetNillableDownloadClientID(i *int) *HistoryCreate {
if i != nil {
hc.SetDownloadClientID(*i)
}
return hc
}
// SetIndexerID sets the "indexer_id" field.
func (hc *HistoryCreate) SetIndexerID(i int) *HistoryCreate {
hc.mutation.SetIndexerID(i)
return hc
}
// SetNillableIndexerID sets the "indexer_id" field if the given value is not nil.
func (hc *HistoryCreate) SetNillableIndexerID(i *int) *HistoryCreate {
if i != nil {
hc.SetIndexerID(*i)
}
return hc
}
// SetStatus sets the "status" field.
func (hc *HistoryCreate) SetStatus(h history.Status) *HistoryCreate {
hc.mutation.SetStatus(h)
@@ -208,6 +236,14 @@ func (hc *HistoryCreate) createSpec() (*History, *sqlgraph.CreateSpec) {
_spec.SetField(history.FieldSize, field.TypeInt, value)
_node.Size = value
}
if value, ok := hc.mutation.DownloadClientID(); ok {
_spec.SetField(history.FieldDownloadClientID, field.TypeInt, value)
_node.DownloadClientID = value
}
if value, ok := hc.mutation.IndexerID(); ok {
_spec.SetField(history.FieldIndexerID, field.TypeInt, value)
_node.IndexerID = value
}
if value, ok := hc.mutation.Status(); ok {
_spec.SetField(history.FieldStatus, field.TypeEnum, value)
_node.Status = value

View File

@@ -139,6 +139,60 @@ func (hu *HistoryUpdate) AddSize(i int) *HistoryUpdate {
return hu
}
// SetDownloadClientID sets the "download_client_id" field.
func (hu *HistoryUpdate) SetDownloadClientID(i int) *HistoryUpdate {
hu.mutation.ResetDownloadClientID()
hu.mutation.SetDownloadClientID(i)
return hu
}
// SetNillableDownloadClientID sets the "download_client_id" field if the given value is not nil.
func (hu *HistoryUpdate) SetNillableDownloadClientID(i *int) *HistoryUpdate {
if i != nil {
hu.SetDownloadClientID(*i)
}
return hu
}
// AddDownloadClientID adds i to the "download_client_id" field.
func (hu *HistoryUpdate) AddDownloadClientID(i int) *HistoryUpdate {
hu.mutation.AddDownloadClientID(i)
return hu
}
// ClearDownloadClientID clears the value of the "download_client_id" field.
func (hu *HistoryUpdate) ClearDownloadClientID() *HistoryUpdate {
hu.mutation.ClearDownloadClientID()
return hu
}
// SetIndexerID sets the "indexer_id" field.
func (hu *HistoryUpdate) SetIndexerID(i int) *HistoryUpdate {
hu.mutation.ResetIndexerID()
hu.mutation.SetIndexerID(i)
return hu
}
// SetNillableIndexerID sets the "indexer_id" field if the given value is not nil.
func (hu *HistoryUpdate) SetNillableIndexerID(i *int) *HistoryUpdate {
if i != nil {
hu.SetIndexerID(*i)
}
return hu
}
// AddIndexerID adds i to the "indexer_id" field.
func (hu *HistoryUpdate) AddIndexerID(i int) *HistoryUpdate {
hu.mutation.AddIndexerID(i)
return hu
}
// ClearIndexerID clears the value of the "indexer_id" field.
func (hu *HistoryUpdate) ClearIndexerID() *HistoryUpdate {
hu.mutation.ClearIndexerID()
return hu
}
// SetStatus sets the "status" field.
func (hu *HistoryUpdate) SetStatus(h history.Status) *HistoryUpdate {
hu.mutation.SetStatus(h)
@@ -257,6 +311,24 @@ func (hu *HistoryUpdate) sqlSave(ctx context.Context) (n int, err error) {
if value, ok := hu.mutation.AddedSize(); ok {
_spec.AddField(history.FieldSize, field.TypeInt, value)
}
if value, ok := hu.mutation.DownloadClientID(); ok {
_spec.SetField(history.FieldDownloadClientID, field.TypeInt, value)
}
if value, ok := hu.mutation.AddedDownloadClientID(); ok {
_spec.AddField(history.FieldDownloadClientID, field.TypeInt, value)
}
if hu.mutation.DownloadClientIDCleared() {
_spec.ClearField(history.FieldDownloadClientID, field.TypeInt)
}
if value, ok := hu.mutation.IndexerID(); ok {
_spec.SetField(history.FieldIndexerID, field.TypeInt, value)
}
if value, ok := hu.mutation.AddedIndexerID(); ok {
_spec.AddField(history.FieldIndexerID, field.TypeInt, value)
}
if hu.mutation.IndexerIDCleared() {
_spec.ClearField(history.FieldIndexerID, field.TypeInt)
}
if value, ok := hu.mutation.Status(); ok {
_spec.SetField(history.FieldStatus, field.TypeEnum, value)
}
@@ -397,6 +469,60 @@ func (huo *HistoryUpdateOne) AddSize(i int) *HistoryUpdateOne {
return huo
}
// SetDownloadClientID sets the "download_client_id" field.
func (huo *HistoryUpdateOne) SetDownloadClientID(i int) *HistoryUpdateOne {
huo.mutation.ResetDownloadClientID()
huo.mutation.SetDownloadClientID(i)
return huo
}
// SetNillableDownloadClientID sets the "download_client_id" field if the given value is not nil.
func (huo *HistoryUpdateOne) SetNillableDownloadClientID(i *int) *HistoryUpdateOne {
if i != nil {
huo.SetDownloadClientID(*i)
}
return huo
}
// AddDownloadClientID adds i to the "download_client_id" field.
func (huo *HistoryUpdateOne) AddDownloadClientID(i int) *HistoryUpdateOne {
huo.mutation.AddDownloadClientID(i)
return huo
}
// ClearDownloadClientID clears the value of the "download_client_id" field.
func (huo *HistoryUpdateOne) ClearDownloadClientID() *HistoryUpdateOne {
huo.mutation.ClearDownloadClientID()
return huo
}
// SetIndexerID sets the "indexer_id" field.
func (huo *HistoryUpdateOne) SetIndexerID(i int) *HistoryUpdateOne {
huo.mutation.ResetIndexerID()
huo.mutation.SetIndexerID(i)
return huo
}
// SetNillableIndexerID sets the "indexer_id" field if the given value is not nil.
func (huo *HistoryUpdateOne) SetNillableIndexerID(i *int) *HistoryUpdateOne {
if i != nil {
huo.SetIndexerID(*i)
}
return huo
}
// AddIndexerID adds i to the "indexer_id" field.
func (huo *HistoryUpdateOne) AddIndexerID(i int) *HistoryUpdateOne {
huo.mutation.AddIndexerID(i)
return huo
}
// ClearIndexerID clears the value of the "indexer_id" field.
func (huo *HistoryUpdateOne) ClearIndexerID() *HistoryUpdateOne {
huo.mutation.ClearIndexerID()
return huo
}
// SetStatus sets the "status" field.
func (huo *HistoryUpdateOne) SetStatus(h history.Status) *HistoryUpdateOne {
huo.mutation.SetStatus(h)
@@ -545,6 +671,24 @@ func (huo *HistoryUpdateOne) sqlSave(ctx context.Context) (_node *History, err e
if value, ok := huo.mutation.AddedSize(); ok {
_spec.AddField(history.FieldSize, field.TypeInt, value)
}
if value, ok := huo.mutation.DownloadClientID(); ok {
_spec.SetField(history.FieldDownloadClientID, field.TypeInt, value)
}
if value, ok := huo.mutation.AddedDownloadClientID(); ok {
_spec.AddField(history.FieldDownloadClientID, field.TypeInt, value)
}
if huo.mutation.DownloadClientIDCleared() {
_spec.ClearField(history.FieldDownloadClientID, field.TypeInt)
}
if value, ok := huo.mutation.IndexerID(); ok {
_spec.SetField(history.FieldIndexerID, field.TypeInt, value)
}
if value, ok := huo.mutation.AddedIndexerID(); ok {
_spec.AddField(history.FieldIndexerID, field.TypeInt, value)
}
if huo.mutation.IndexerIDCleared() {
_spec.ClearField(history.FieldIndexerID, field.TypeInt)
}
if value, ok := huo.mutation.Status(); ok {
_spec.SetField(history.FieldStatus, field.TypeEnum, value)
}

View File

@@ -68,6 +68,18 @@ func (f MediaFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error
return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.MediaMutation", m)
}
// The NotificationClientFunc type is an adapter to allow the use of ordinary
// function as NotificationClient mutator.
type NotificationClientFunc func(context.Context, *ent.NotificationClientMutation) (ent.Value, error)
// Mutate calls f(ctx, m).
func (f NotificationClientFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) {
if mv, ok := m.(*ent.NotificationClientMutation); ok {
return f(ctx, mv)
}
return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.NotificationClientMutation", m)
}
// The SettingsFunc type is an adapter to allow the use of ordinary
// function as Settings mutator.
type SettingsFunc func(context.Context, *ent.SettingsMutation) (ent.Value, error)

View File

@@ -25,7 +25,11 @@ type Indexers struct {
// EnableRss holds the value of the "enable_rss" field.
EnableRss bool `json:"enable_rss,omitempty"`
// Priority holds the value of the "priority" field.
Priority int `json:"priority,omitempty"`
Priority int `json:"priority,omitempty"`
// minimal seed ratio requied, before removing torrent
SeedRatio float32 `json:"seed_ratio,omitempty"`
// Disabled holds the value of the "disabled" field.
Disabled bool `json:"disabled,omitempty"`
selectValues sql.SelectValues
}
@@ -34,8 +38,10 @@ func (*Indexers) scanValues(columns []string) ([]any, error) {
values := make([]any, len(columns))
for i := range columns {
switch columns[i] {
case indexers.FieldEnableRss:
case indexers.FieldEnableRss, indexers.FieldDisabled:
values[i] = new(sql.NullBool)
case indexers.FieldSeedRatio:
values[i] = new(sql.NullFloat64)
case indexers.FieldID, indexers.FieldPriority:
values[i] = new(sql.NullInt64)
case indexers.FieldName, indexers.FieldImplementation, indexers.FieldSettings:
@@ -91,6 +97,18 @@ func (i *Indexers) assignValues(columns []string, values []any) error {
} else if value.Valid {
i.Priority = int(value.Int64)
}
case indexers.FieldSeedRatio:
if value, ok := values[j].(*sql.NullFloat64); !ok {
return fmt.Errorf("unexpected type %T for field seed_ratio", values[j])
} else if value.Valid {
i.SeedRatio = float32(value.Float64)
}
case indexers.FieldDisabled:
if value, ok := values[j].(*sql.NullBool); !ok {
return fmt.Errorf("unexpected type %T for field disabled", values[j])
} else if value.Valid {
i.Disabled = value.Bool
}
default:
i.selectValues.Set(columns[j], values[j])
}
@@ -141,6 +159,12 @@ func (i *Indexers) String() string {
builder.WriteString(", ")
builder.WriteString("priority=")
builder.WriteString(fmt.Sprintf("%v", i.Priority))
builder.WriteString(", ")
builder.WriteString("seed_ratio=")
builder.WriteString(fmt.Sprintf("%v", i.SeedRatio))
builder.WriteString(", ")
builder.WriteString("disabled=")
builder.WriteString(fmt.Sprintf("%v", i.Disabled))
builder.WriteByte(')')
return builder.String()
}

View File

@@ -21,6 +21,10 @@ const (
FieldEnableRss = "enable_rss"
// FieldPriority holds the string denoting the priority field in the database.
FieldPriority = "priority"
// FieldSeedRatio holds the string denoting the seed_ratio field in the database.
FieldSeedRatio = "seed_ratio"
// FieldDisabled holds the string denoting the disabled field in the database.
FieldDisabled = "disabled"
// Table holds the table name of the indexers in the database.
Table = "indexers"
)
@@ -33,6 +37,8 @@ var Columns = []string{
FieldSettings,
FieldEnableRss,
FieldPriority,
FieldSeedRatio,
FieldDisabled,
}
// ValidColumn reports if the column name is valid (part of the table columns).
@@ -48,6 +54,12 @@ func ValidColumn(column string) bool {
var (
// DefaultEnableRss holds the default value on creation for the "enable_rss" field.
DefaultEnableRss bool
// DefaultPriority holds the default value on creation for the "priority" field.
DefaultPriority int
// DefaultSeedRatio holds the default value on creation for the "seed_ratio" field.
DefaultSeedRatio float32
// DefaultDisabled holds the default value on creation for the "disabled" field.
DefaultDisabled bool
)
// OrderOption defines the ordering options for the Indexers queries.
@@ -82,3 +94,13 @@ func ByEnableRss(opts ...sql.OrderTermOption) OrderOption {
func ByPriority(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldPriority, opts...).ToFunc()
}
// BySeedRatio orders the results by the seed_ratio field.
func BySeedRatio(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldSeedRatio, opts...).ToFunc()
}
// ByDisabled orders the results by the disabled field.
func ByDisabled(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldDisabled, opts...).ToFunc()
}

View File

@@ -78,6 +78,16 @@ func Priority(v int) predicate.Indexers {
return predicate.Indexers(sql.FieldEQ(FieldPriority, v))
}
// SeedRatio applies equality check predicate on the "seed_ratio" field. It's identical to SeedRatioEQ.
func SeedRatio(v float32) predicate.Indexers {
return predicate.Indexers(sql.FieldEQ(FieldSeedRatio, v))
}
// Disabled applies equality check predicate on the "disabled" field. It's identical to DisabledEQ.
func Disabled(v bool) predicate.Indexers {
return predicate.Indexers(sql.FieldEQ(FieldDisabled, v))
}
// NameEQ applies the EQ predicate on the "name" field.
func NameEQ(v string) predicate.Indexers {
return predicate.Indexers(sql.FieldEQ(FieldName, v))
@@ -323,6 +333,76 @@ func PriorityLTE(v int) predicate.Indexers {
return predicate.Indexers(sql.FieldLTE(FieldPriority, v))
}
// SeedRatioEQ applies the EQ predicate on the "seed_ratio" field.
func SeedRatioEQ(v float32) predicate.Indexers {
return predicate.Indexers(sql.FieldEQ(FieldSeedRatio, v))
}
// SeedRatioNEQ applies the NEQ predicate on the "seed_ratio" field.
func SeedRatioNEQ(v float32) predicate.Indexers {
return predicate.Indexers(sql.FieldNEQ(FieldSeedRatio, v))
}
// SeedRatioIn applies the In predicate on the "seed_ratio" field.
func SeedRatioIn(vs ...float32) predicate.Indexers {
return predicate.Indexers(sql.FieldIn(FieldSeedRatio, vs...))
}
// SeedRatioNotIn applies the NotIn predicate on the "seed_ratio" field.
func SeedRatioNotIn(vs ...float32) predicate.Indexers {
return predicate.Indexers(sql.FieldNotIn(FieldSeedRatio, vs...))
}
// SeedRatioGT applies the GT predicate on the "seed_ratio" field.
func SeedRatioGT(v float32) predicate.Indexers {
return predicate.Indexers(sql.FieldGT(FieldSeedRatio, v))
}
// SeedRatioGTE applies the GTE predicate on the "seed_ratio" field.
func SeedRatioGTE(v float32) predicate.Indexers {
return predicate.Indexers(sql.FieldGTE(FieldSeedRatio, v))
}
// SeedRatioLT applies the LT predicate on the "seed_ratio" field.
func SeedRatioLT(v float32) predicate.Indexers {
return predicate.Indexers(sql.FieldLT(FieldSeedRatio, v))
}
// SeedRatioLTE applies the LTE predicate on the "seed_ratio" field.
func SeedRatioLTE(v float32) predicate.Indexers {
return predicate.Indexers(sql.FieldLTE(FieldSeedRatio, v))
}
// SeedRatioIsNil applies the IsNil predicate on the "seed_ratio" field.
func SeedRatioIsNil() predicate.Indexers {
return predicate.Indexers(sql.FieldIsNull(FieldSeedRatio))
}
// SeedRatioNotNil applies the NotNil predicate on the "seed_ratio" field.
func SeedRatioNotNil() predicate.Indexers {
return predicate.Indexers(sql.FieldNotNull(FieldSeedRatio))
}
// DisabledEQ applies the EQ predicate on the "disabled" field.
func DisabledEQ(v bool) predicate.Indexers {
return predicate.Indexers(sql.FieldEQ(FieldDisabled, v))
}
// DisabledNEQ applies the NEQ predicate on the "disabled" field.
func DisabledNEQ(v bool) predicate.Indexers {
return predicate.Indexers(sql.FieldNEQ(FieldDisabled, v))
}
// DisabledIsNil applies the IsNil predicate on the "disabled" field.
func DisabledIsNil() predicate.Indexers {
return predicate.Indexers(sql.FieldIsNull(FieldDisabled))
}
// DisabledNotNil applies the NotNil predicate on the "disabled" field.
func DisabledNotNil() predicate.Indexers {
return predicate.Indexers(sql.FieldNotNull(FieldDisabled))
}
// And groups predicates with the AND operator between them.
func And(predicates ...predicate.Indexers) predicate.Indexers {
return predicate.Indexers(sql.AndPredicates(predicates...))

View File

@@ -57,6 +57,42 @@ func (ic *IndexersCreate) SetPriority(i int) *IndexersCreate {
return ic
}
// SetNillablePriority sets the "priority" field if the given value is not nil.
func (ic *IndexersCreate) SetNillablePriority(i *int) *IndexersCreate {
if i != nil {
ic.SetPriority(*i)
}
return ic
}
// SetSeedRatio sets the "seed_ratio" field.
func (ic *IndexersCreate) SetSeedRatio(f float32) *IndexersCreate {
ic.mutation.SetSeedRatio(f)
return ic
}
// SetNillableSeedRatio sets the "seed_ratio" field if the given value is not nil.
func (ic *IndexersCreate) SetNillableSeedRatio(f *float32) *IndexersCreate {
if f != nil {
ic.SetSeedRatio(*f)
}
return ic
}
// SetDisabled sets the "disabled" field.
func (ic *IndexersCreate) SetDisabled(b bool) *IndexersCreate {
ic.mutation.SetDisabled(b)
return ic
}
// SetNillableDisabled sets the "disabled" field if the given value is not nil.
func (ic *IndexersCreate) SetNillableDisabled(b *bool) *IndexersCreate {
if b != nil {
ic.SetDisabled(*b)
}
return ic
}
// Mutation returns the IndexersMutation object of the builder.
func (ic *IndexersCreate) Mutation() *IndexersMutation {
return ic.mutation
@@ -96,6 +132,18 @@ func (ic *IndexersCreate) defaults() {
v := indexers.DefaultEnableRss
ic.mutation.SetEnableRss(v)
}
if _, ok := ic.mutation.Priority(); !ok {
v := indexers.DefaultPriority
ic.mutation.SetPriority(v)
}
if _, ok := ic.mutation.SeedRatio(); !ok {
v := indexers.DefaultSeedRatio
ic.mutation.SetSeedRatio(v)
}
if _, ok := ic.mutation.Disabled(); !ok {
v := indexers.DefaultDisabled
ic.mutation.SetDisabled(v)
}
}
// check runs all checks and user-defined validators on the builder.
@@ -161,6 +209,14 @@ func (ic *IndexersCreate) createSpec() (*Indexers, *sqlgraph.CreateSpec) {
_spec.SetField(indexers.FieldPriority, field.TypeInt, value)
_node.Priority = value
}
if value, ok := ic.mutation.SeedRatio(); ok {
_spec.SetField(indexers.FieldSeedRatio, field.TypeFloat32, value)
_node.SeedRatio = value
}
if value, ok := ic.mutation.Disabled(); ok {
_spec.SetField(indexers.FieldDisabled, field.TypeBool, value)
_node.Disabled = value
}
return _node, _spec
}

View File

@@ -104,6 +104,53 @@ func (iu *IndexersUpdate) AddPriority(i int) *IndexersUpdate {
return iu
}
// SetSeedRatio sets the "seed_ratio" field.
func (iu *IndexersUpdate) SetSeedRatio(f float32) *IndexersUpdate {
iu.mutation.ResetSeedRatio()
iu.mutation.SetSeedRatio(f)
return iu
}
// SetNillableSeedRatio sets the "seed_ratio" field if the given value is not nil.
func (iu *IndexersUpdate) SetNillableSeedRatio(f *float32) *IndexersUpdate {
if f != nil {
iu.SetSeedRatio(*f)
}
return iu
}
// AddSeedRatio adds f to the "seed_ratio" field.
func (iu *IndexersUpdate) AddSeedRatio(f float32) *IndexersUpdate {
iu.mutation.AddSeedRatio(f)
return iu
}
// ClearSeedRatio clears the value of the "seed_ratio" field.
func (iu *IndexersUpdate) ClearSeedRatio() *IndexersUpdate {
iu.mutation.ClearSeedRatio()
return iu
}
// SetDisabled sets the "disabled" field.
func (iu *IndexersUpdate) SetDisabled(b bool) *IndexersUpdate {
iu.mutation.SetDisabled(b)
return iu
}
// SetNillableDisabled sets the "disabled" field if the given value is not nil.
func (iu *IndexersUpdate) SetNillableDisabled(b *bool) *IndexersUpdate {
if b != nil {
iu.SetDisabled(*b)
}
return iu
}
// ClearDisabled clears the value of the "disabled" field.
func (iu *IndexersUpdate) ClearDisabled() *IndexersUpdate {
iu.mutation.ClearDisabled()
return iu
}
// Mutation returns the IndexersMutation object of the builder.
func (iu *IndexersUpdate) Mutation() *IndexersMutation {
return iu.mutation
@@ -163,6 +210,21 @@ func (iu *IndexersUpdate) sqlSave(ctx context.Context) (n int, err error) {
if value, ok := iu.mutation.AddedPriority(); ok {
_spec.AddField(indexers.FieldPriority, field.TypeInt, value)
}
if value, ok := iu.mutation.SeedRatio(); ok {
_spec.SetField(indexers.FieldSeedRatio, field.TypeFloat32, value)
}
if value, ok := iu.mutation.AddedSeedRatio(); ok {
_spec.AddField(indexers.FieldSeedRatio, field.TypeFloat32, value)
}
if iu.mutation.SeedRatioCleared() {
_spec.ClearField(indexers.FieldSeedRatio, field.TypeFloat32)
}
if value, ok := iu.mutation.Disabled(); ok {
_spec.SetField(indexers.FieldDisabled, field.TypeBool, value)
}
if iu.mutation.DisabledCleared() {
_spec.ClearField(indexers.FieldDisabled, field.TypeBool)
}
if n, err = sqlgraph.UpdateNodes(ctx, iu.driver, _spec); err != nil {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{indexers.Label}
@@ -260,6 +322,53 @@ func (iuo *IndexersUpdateOne) AddPriority(i int) *IndexersUpdateOne {
return iuo
}
// SetSeedRatio sets the "seed_ratio" field.
func (iuo *IndexersUpdateOne) SetSeedRatio(f float32) *IndexersUpdateOne {
iuo.mutation.ResetSeedRatio()
iuo.mutation.SetSeedRatio(f)
return iuo
}
// SetNillableSeedRatio sets the "seed_ratio" field if the given value is not nil.
func (iuo *IndexersUpdateOne) SetNillableSeedRatio(f *float32) *IndexersUpdateOne {
if f != nil {
iuo.SetSeedRatio(*f)
}
return iuo
}
// AddSeedRatio adds f to the "seed_ratio" field.
func (iuo *IndexersUpdateOne) AddSeedRatio(f float32) *IndexersUpdateOne {
iuo.mutation.AddSeedRatio(f)
return iuo
}
// ClearSeedRatio clears the value of the "seed_ratio" field.
func (iuo *IndexersUpdateOne) ClearSeedRatio() *IndexersUpdateOne {
iuo.mutation.ClearSeedRatio()
return iuo
}
// SetDisabled sets the "disabled" field.
func (iuo *IndexersUpdateOne) SetDisabled(b bool) *IndexersUpdateOne {
iuo.mutation.SetDisabled(b)
return iuo
}
// SetNillableDisabled sets the "disabled" field if the given value is not nil.
func (iuo *IndexersUpdateOne) SetNillableDisabled(b *bool) *IndexersUpdateOne {
if b != nil {
iuo.SetDisabled(*b)
}
return iuo
}
// ClearDisabled clears the value of the "disabled" field.
func (iuo *IndexersUpdateOne) ClearDisabled() *IndexersUpdateOne {
iuo.mutation.ClearDisabled()
return iuo
}
// Mutation returns the IndexersMutation object of the builder.
func (iuo *IndexersUpdateOne) Mutation() *IndexersMutation {
return iuo.mutation
@@ -349,6 +458,21 @@ func (iuo *IndexersUpdateOne) sqlSave(ctx context.Context) (_node *Indexers, err
if value, ok := iuo.mutation.AddedPriority(); ok {
_spec.AddField(indexers.FieldPriority, field.TypeInt, value)
}
if value, ok := iuo.mutation.SeedRatio(); ok {
_spec.SetField(indexers.FieldSeedRatio, field.TypeFloat32, value)
}
if value, ok := iuo.mutation.AddedSeedRatio(); ok {
_spec.AddField(indexers.FieldSeedRatio, field.TypeFloat32, value)
}
if iuo.mutation.SeedRatioCleared() {
_spec.ClearField(indexers.FieldSeedRatio, field.TypeFloat32)
}
if value, ok := iuo.mutation.Disabled(); ok {
_spec.SetField(indexers.FieldDisabled, field.TypeBool, value)
}
if iuo.mutation.DisabledCleared() {
_spec.ClearField(indexers.FieldDisabled, field.TypeBool)
}
_node = &Indexers{config: iuo.config}
_spec.Assign = _node.assignValues
_spec.ScanValues = _node.scanValues

View File

@@ -3,8 +3,10 @@
package ent
import (
"encoding/json"
"fmt"
"polaris/ent/media"
"polaris/ent/schema"
"strings"
"time"
@@ -41,6 +43,10 @@ type Media struct {
StorageID int `json:"storage_id,omitempty"`
// TargetDir holds the value of the "target_dir" field.
TargetDir string `json:"target_dir,omitempty"`
// tv series only
DownloadHistoryEpisodes bool `json:"download_history_episodes,omitempty"`
// Limiter holds the value of the "limiter" field.
Limiter *schema.MediaLimiter `json:"limiter,omitempty"`
// Edges holds the relations/edges for other nodes in the graph.
// The values are being populated by the MediaQuery when eager-loading is set.
Edges MediaEdges `json:"edges"`
@@ -70,6 +76,10 @@ func (*Media) scanValues(columns []string) ([]any, error) {
values := make([]any, len(columns))
for i := range columns {
switch columns[i] {
case media.FieldLimiter:
values[i] = new([]byte)
case media.FieldDownloadHistoryEpisodes:
values[i] = new(sql.NullBool)
case media.FieldID, media.FieldTmdbID, media.FieldStorageID:
values[i] = new(sql.NullInt64)
case media.FieldImdbID, media.FieldMediaType, media.FieldNameCn, media.FieldNameEn, media.FieldOriginalName, media.FieldOverview, media.FieldAirDate, media.FieldResolution, media.FieldTargetDir:
@@ -169,6 +179,20 @@ func (m *Media) assignValues(columns []string, values []any) error {
} else if value.Valid {
m.TargetDir = value.String
}
case media.FieldDownloadHistoryEpisodes:
if value, ok := values[i].(*sql.NullBool); !ok {
return fmt.Errorf("unexpected type %T for field download_history_episodes", values[i])
} else if value.Valid {
m.DownloadHistoryEpisodes = value.Bool
}
case media.FieldLimiter:
if value, ok := values[i].(*[]byte); !ok {
return fmt.Errorf("unexpected type %T for field limiter", values[i])
} else if value != nil && len(*value) > 0 {
if err := json.Unmarshal(*value, &m.Limiter); err != nil {
return fmt.Errorf("unmarshal field limiter: %w", err)
}
}
default:
m.selectValues.Set(columns[i], values[i])
}
@@ -245,6 +269,12 @@ func (m *Media) String() string {
builder.WriteString(", ")
builder.WriteString("target_dir=")
builder.WriteString(m.TargetDir)
builder.WriteString(", ")
builder.WriteString("download_history_episodes=")
builder.WriteString(fmt.Sprintf("%v", m.DownloadHistoryEpisodes))
builder.WriteString(", ")
builder.WriteString("limiter=")
builder.WriteString(fmt.Sprintf("%v", m.Limiter))
builder.WriteByte(')')
return builder.String()
}

View File

@@ -39,6 +39,10 @@ const (
FieldStorageID = "storage_id"
// FieldTargetDir holds the string denoting the target_dir field in the database.
FieldTargetDir = "target_dir"
// FieldDownloadHistoryEpisodes holds the string denoting the download_history_episodes field in the database.
FieldDownloadHistoryEpisodes = "download_history_episodes"
// FieldLimiter holds the string denoting the limiter field in the database.
FieldLimiter = "limiter"
// EdgeEpisodes holds the string denoting the episodes edge name in mutations.
EdgeEpisodes = "episodes"
// Table holds the table name of the media in the database.
@@ -67,6 +71,8 @@ var Columns = []string{
FieldResolution,
FieldStorageID,
FieldTargetDir,
FieldDownloadHistoryEpisodes,
FieldLimiter,
}
// ValidColumn reports if the column name is valid (part of the table columns).
@@ -84,6 +90,8 @@ var (
DefaultCreatedAt time.Time
// DefaultAirDate holds the default value on creation for the "air_date" field.
DefaultAirDate string
// DefaultDownloadHistoryEpisodes holds the default value on creation for the "download_history_episodes" field.
DefaultDownloadHistoryEpisodes bool
)
// MediaType defines the type for the "media_type" enum field.
@@ -119,7 +127,7 @@ const DefaultResolution = Resolution1080p
const (
Resolution720p Resolution = "720p"
Resolution1080p Resolution = "1080p"
Resolution4k Resolution = "4k"
Resolution2160p Resolution = "2160p"
)
func (r Resolution) String() string {
@@ -129,7 +137,7 @@ func (r Resolution) String() string {
// ResolutionValidator is a validator for the "resolution" field enum values. It is called by the builders before save.
func ResolutionValidator(r Resolution) error {
switch r {
case Resolution720p, Resolution1080p, Resolution4k:
case Resolution720p, Resolution1080p, Resolution2160p:
return nil
default:
return fmt.Errorf("media: invalid enum value for resolution field: %q", r)
@@ -204,6 +212,11 @@ func ByTargetDir(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldTargetDir, opts...).ToFunc()
}
// ByDownloadHistoryEpisodes orders the results by the download_history_episodes field.
func ByDownloadHistoryEpisodes(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldDownloadHistoryEpisodes, opts...).ToFunc()
}
// ByEpisodesCount orders the results by episodes count.
func ByEpisodesCount(opts ...sql.OrderTermOption) OrderOption {
return func(s *sql.Selector) {

View File

@@ -105,6 +105,11 @@ func TargetDir(v string) predicate.Media {
return predicate.Media(sql.FieldEQ(FieldTargetDir, v))
}
// DownloadHistoryEpisodes applies equality check predicate on the "download_history_episodes" field. It's identical to DownloadHistoryEpisodesEQ.
func DownloadHistoryEpisodes(v bool) predicate.Media {
return predicate.Media(sql.FieldEQ(FieldDownloadHistoryEpisodes, v))
}
// TmdbIDEQ applies the EQ predicate on the "tmdb_id" field.
func TmdbIDEQ(v int) predicate.Media {
return predicate.Media(sql.FieldEQ(FieldTmdbID, v))
@@ -750,6 +755,36 @@ func TargetDirContainsFold(v string) predicate.Media {
return predicate.Media(sql.FieldContainsFold(FieldTargetDir, v))
}
// DownloadHistoryEpisodesEQ applies the EQ predicate on the "download_history_episodes" field.
func DownloadHistoryEpisodesEQ(v bool) predicate.Media {
return predicate.Media(sql.FieldEQ(FieldDownloadHistoryEpisodes, v))
}
// DownloadHistoryEpisodesNEQ applies the NEQ predicate on the "download_history_episodes" field.
func DownloadHistoryEpisodesNEQ(v bool) predicate.Media {
return predicate.Media(sql.FieldNEQ(FieldDownloadHistoryEpisodes, v))
}
// DownloadHistoryEpisodesIsNil applies the IsNil predicate on the "download_history_episodes" field.
func DownloadHistoryEpisodesIsNil() predicate.Media {
return predicate.Media(sql.FieldIsNull(FieldDownloadHistoryEpisodes))
}
// DownloadHistoryEpisodesNotNil applies the NotNil predicate on the "download_history_episodes" field.
func DownloadHistoryEpisodesNotNil() predicate.Media {
return predicate.Media(sql.FieldNotNull(FieldDownloadHistoryEpisodes))
}
// LimiterIsNil applies the IsNil predicate on the "limiter" field.
func LimiterIsNil() predicate.Media {
return predicate.Media(sql.FieldIsNull(FieldLimiter))
}
// LimiterNotNil applies the NotNil predicate on the "limiter" field.
func LimiterNotNil() predicate.Media {
return predicate.Media(sql.FieldNotNull(FieldLimiter))
}
// HasEpisodes applies the HasEdge predicate on the "episodes" edge.
func HasEpisodes() predicate.Media {
return predicate.Media(func(s *sql.Selector) {

View File

@@ -8,6 +8,7 @@ import (
"fmt"
"polaris/ent/episode"
"polaris/ent/media"
"polaris/ent/schema"
"time"
"entgo.io/ent/dialect/sql/sqlgraph"
@@ -141,6 +142,26 @@ func (mc *MediaCreate) SetNillableTargetDir(s *string) *MediaCreate {
return mc
}
// SetDownloadHistoryEpisodes sets the "download_history_episodes" field.
func (mc *MediaCreate) SetDownloadHistoryEpisodes(b bool) *MediaCreate {
mc.mutation.SetDownloadHistoryEpisodes(b)
return mc
}
// SetNillableDownloadHistoryEpisodes sets the "download_history_episodes" field if the given value is not nil.
func (mc *MediaCreate) SetNillableDownloadHistoryEpisodes(b *bool) *MediaCreate {
if b != nil {
mc.SetDownloadHistoryEpisodes(*b)
}
return mc
}
// SetLimiter sets the "limiter" field.
func (mc *MediaCreate) SetLimiter(sl *schema.MediaLimiter) *MediaCreate {
mc.mutation.SetLimiter(sl)
return mc
}
// AddEpisodeIDs adds the "episodes" edge to the Episode entity by IDs.
func (mc *MediaCreate) AddEpisodeIDs(ids ...int) *MediaCreate {
mc.mutation.AddEpisodeIDs(ids...)
@@ -203,6 +224,10 @@ func (mc *MediaCreate) defaults() {
v := media.DefaultResolution
mc.mutation.SetResolution(v)
}
if _, ok := mc.mutation.DownloadHistoryEpisodes(); !ok {
v := media.DefaultDownloadHistoryEpisodes
mc.mutation.SetDownloadHistoryEpisodes(v)
}
}
// check runs all checks and user-defined validators on the builder.
@@ -318,6 +343,14 @@ func (mc *MediaCreate) createSpec() (*Media, *sqlgraph.CreateSpec) {
_spec.SetField(media.FieldTargetDir, field.TypeString, value)
_node.TargetDir = value
}
if value, ok := mc.mutation.DownloadHistoryEpisodes(); ok {
_spec.SetField(media.FieldDownloadHistoryEpisodes, field.TypeBool, value)
_node.DownloadHistoryEpisodes = value
}
if value, ok := mc.mutation.Limiter(); ok {
_spec.SetField(media.FieldLimiter, field.TypeJSON, value)
_node.Limiter = value
}
if nodes := mc.mutation.EpisodesIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,

View File

@@ -9,6 +9,7 @@ import (
"polaris/ent/episode"
"polaris/ent/media"
"polaris/ent/predicate"
"polaris/ent/schema"
"time"
"entgo.io/ent/dialect/sql"
@@ -229,6 +230,38 @@ func (mu *MediaUpdate) ClearTargetDir() *MediaUpdate {
return mu
}
// SetDownloadHistoryEpisodes sets the "download_history_episodes" field.
func (mu *MediaUpdate) SetDownloadHistoryEpisodes(b bool) *MediaUpdate {
mu.mutation.SetDownloadHistoryEpisodes(b)
return mu
}
// SetNillableDownloadHistoryEpisodes sets the "download_history_episodes" field if the given value is not nil.
func (mu *MediaUpdate) SetNillableDownloadHistoryEpisodes(b *bool) *MediaUpdate {
if b != nil {
mu.SetDownloadHistoryEpisodes(*b)
}
return mu
}
// ClearDownloadHistoryEpisodes clears the value of the "download_history_episodes" field.
func (mu *MediaUpdate) ClearDownloadHistoryEpisodes() *MediaUpdate {
mu.mutation.ClearDownloadHistoryEpisodes()
return mu
}
// SetLimiter sets the "limiter" field.
func (mu *MediaUpdate) SetLimiter(sl *schema.MediaLimiter) *MediaUpdate {
mu.mutation.SetLimiter(sl)
return mu
}
// ClearLimiter clears the value of the "limiter" field.
func (mu *MediaUpdate) ClearLimiter() *MediaUpdate {
mu.mutation.ClearLimiter()
return mu
}
// AddEpisodeIDs adds the "episodes" edge to the Episode entity by IDs.
func (mu *MediaUpdate) AddEpisodeIDs(ids ...int) *MediaUpdate {
mu.mutation.AddEpisodeIDs(ids...)
@@ -375,6 +408,18 @@ func (mu *MediaUpdate) sqlSave(ctx context.Context) (n int, err error) {
if mu.mutation.TargetDirCleared() {
_spec.ClearField(media.FieldTargetDir, field.TypeString)
}
if value, ok := mu.mutation.DownloadHistoryEpisodes(); ok {
_spec.SetField(media.FieldDownloadHistoryEpisodes, field.TypeBool, value)
}
if mu.mutation.DownloadHistoryEpisodesCleared() {
_spec.ClearField(media.FieldDownloadHistoryEpisodes, field.TypeBool)
}
if value, ok := mu.mutation.Limiter(); ok {
_spec.SetField(media.FieldLimiter, field.TypeJSON, value)
}
if mu.mutation.LimiterCleared() {
_spec.ClearField(media.FieldLimiter, field.TypeJSON)
}
if mu.mutation.EpisodesCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
@@ -640,6 +685,38 @@ func (muo *MediaUpdateOne) ClearTargetDir() *MediaUpdateOne {
return muo
}
// SetDownloadHistoryEpisodes sets the "download_history_episodes" field.
func (muo *MediaUpdateOne) SetDownloadHistoryEpisodes(b bool) *MediaUpdateOne {
muo.mutation.SetDownloadHistoryEpisodes(b)
return muo
}
// SetNillableDownloadHistoryEpisodes sets the "download_history_episodes" field if the given value is not nil.
func (muo *MediaUpdateOne) SetNillableDownloadHistoryEpisodes(b *bool) *MediaUpdateOne {
if b != nil {
muo.SetDownloadHistoryEpisodes(*b)
}
return muo
}
// ClearDownloadHistoryEpisodes clears the value of the "download_history_episodes" field.
func (muo *MediaUpdateOne) ClearDownloadHistoryEpisodes() *MediaUpdateOne {
muo.mutation.ClearDownloadHistoryEpisodes()
return muo
}
// SetLimiter sets the "limiter" field.
func (muo *MediaUpdateOne) SetLimiter(sl *schema.MediaLimiter) *MediaUpdateOne {
muo.mutation.SetLimiter(sl)
return muo
}
// ClearLimiter clears the value of the "limiter" field.
func (muo *MediaUpdateOne) ClearLimiter() *MediaUpdateOne {
muo.mutation.ClearLimiter()
return muo
}
// AddEpisodeIDs adds the "episodes" edge to the Episode entity by IDs.
func (muo *MediaUpdateOne) AddEpisodeIDs(ids ...int) *MediaUpdateOne {
muo.mutation.AddEpisodeIDs(ids...)
@@ -816,6 +893,18 @@ func (muo *MediaUpdateOne) sqlSave(ctx context.Context) (_node *Media, err error
if muo.mutation.TargetDirCleared() {
_spec.ClearField(media.FieldTargetDir, field.TypeString)
}
if value, ok := muo.mutation.DownloadHistoryEpisodes(); ok {
_spec.SetField(media.FieldDownloadHistoryEpisodes, field.TypeBool, value)
}
if muo.mutation.DownloadHistoryEpisodesCleared() {
_spec.ClearField(media.FieldDownloadHistoryEpisodes, field.TypeBool)
}
if value, ok := muo.mutation.Limiter(); ok {
_spec.SetField(media.FieldLimiter, field.TypeJSON, value)
}
if muo.mutation.LimiterCleared() {
_spec.ClearField(media.FieldLimiter, field.TypeJSON)
}
if muo.mutation.EpisodesCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,

View File

@@ -38,7 +38,7 @@ var (
{Name: "overview", Type: field.TypeString},
{Name: "air_date", Type: field.TypeString},
{Name: "status", Type: field.TypeEnum, Enums: []string{"missing", "downloading", "downloaded"}, Default: "missing"},
{Name: "file_in_storage", Type: field.TypeString, Nullable: true},
{Name: "monitored", Type: field.TypeBool, Default: false},
{Name: "media_id", Type: field.TypeInt, Nullable: true},
}
// EpisodesTable holds the schema information for the "episodes" table.
@@ -64,6 +64,8 @@ var (
{Name: "date", Type: field.TypeTime},
{Name: "target_dir", Type: field.TypeString},
{Name: "size", Type: field.TypeInt, Default: 0},
{Name: "download_client_id", Type: field.TypeInt, Nullable: true},
{Name: "indexer_id", Type: field.TypeInt, Nullable: true},
{Name: "status", Type: field.TypeEnum, Enums: []string{"running", "success", "fail", "uploading"}},
{Name: "saved", Type: field.TypeString, Nullable: true},
}
@@ -80,7 +82,9 @@ var (
{Name: "implementation", Type: field.TypeString},
{Name: "settings", Type: field.TypeString},
{Name: "enable_rss", Type: field.TypeBool, Default: true},
{Name: "priority", Type: field.TypeInt},
{Name: "priority", Type: field.TypeInt, Default: 50},
{Name: "seed_ratio", Type: field.TypeFloat32, Nullable: true, Default: 0},
{Name: "disabled", Type: field.TypeBool, Nullable: true, Default: false},
}
// IndexersTable holds the schema information for the "indexers" table.
IndexersTable = &schema.Table{
@@ -100,9 +104,11 @@ var (
{Name: "overview", Type: field.TypeString},
{Name: "created_at", Type: field.TypeTime},
{Name: "air_date", Type: field.TypeString, Default: ""},
{Name: "resolution", Type: field.TypeEnum, Enums: []string{"720p", "1080p", "4k"}, Default: "1080p"},
{Name: "resolution", Type: field.TypeEnum, Enums: []string{"720p", "1080p", "2160p"}, Default: "1080p"},
{Name: "storage_id", Type: field.TypeInt, Nullable: true},
{Name: "target_dir", Type: field.TypeString, Nullable: true},
{Name: "download_history_episodes", Type: field.TypeBool, Nullable: true, Default: false},
{Name: "limiter", Type: field.TypeJSON, Nullable: true},
}
// MediaTable holds the schema information for the "media" table.
MediaTable = &schema.Table{
@@ -110,6 +116,20 @@ var (
Columns: MediaColumns,
PrimaryKey: []*schema.Column{MediaColumns[0]},
}
// NotificationClientsColumns holds the columns for the "notification_clients" table.
NotificationClientsColumns = []*schema.Column{
{Name: "id", Type: field.TypeInt, Increment: true},
{Name: "name", Type: field.TypeString},
{Name: "service", Type: field.TypeString},
{Name: "settings", Type: field.TypeString},
{Name: "enabled", Type: field.TypeBool, Default: true},
}
// NotificationClientsTable holds the schema information for the "notification_clients" table.
NotificationClientsTable = &schema.Table{
Name: "notification_clients",
Columns: NotificationClientsColumns,
PrimaryKey: []*schema.Column{NotificationClientsColumns[0]},
}
// SettingsColumns holds the columns for the "settings" table.
SettingsColumns = []*schema.Column{
{Name: "id", Type: field.TypeInt, Increment: true},
@@ -127,6 +147,8 @@ var (
{Name: "id", Type: field.TypeInt, Increment: true},
{Name: "name", Type: field.TypeString, Unique: true},
{Name: "implementation", Type: field.TypeEnum, Enums: []string{"webdav", "local"}},
{Name: "tv_path", Type: field.TypeString, Nullable: true},
{Name: "movie_path", Type: field.TypeString, Nullable: true},
{Name: "settings", Type: field.TypeString, Nullable: true},
{Name: "deleted", Type: field.TypeBool, Default: false},
{Name: "default", Type: field.TypeBool, Default: false},
@@ -144,6 +166,7 @@ var (
HistoriesTable,
IndexersTable,
MediaTable,
NotificationClientsTable,
SettingsTable,
StoragesTable,
}

View File

File diff suppressed because it is too large Load Diff

138
ent/notificationclient.go Normal file
View File

@@ -0,0 +1,138 @@
// Code generated by ent, DO NOT EDIT.
package ent
import (
"fmt"
"polaris/ent/notificationclient"
"strings"
"entgo.io/ent"
"entgo.io/ent/dialect/sql"
)
// NotificationClient is the model entity for the NotificationClient schema.
type NotificationClient struct {
config `json:"-"`
// ID of the ent.
ID int `json:"id,omitempty"`
// Name holds the value of the "name" field.
Name string `json:"name,omitempty"`
// Service holds the value of the "service" field.
Service string `json:"service,omitempty"`
// Settings holds the value of the "settings" field.
Settings string `json:"settings,omitempty"`
// Enabled holds the value of the "enabled" field.
Enabled bool `json:"enabled,omitempty"`
selectValues sql.SelectValues
}
// scanValues returns the types for scanning values from sql.Rows.
func (*NotificationClient) scanValues(columns []string) ([]any, error) {
values := make([]any, len(columns))
for i := range columns {
switch columns[i] {
case notificationclient.FieldEnabled:
values[i] = new(sql.NullBool)
case notificationclient.FieldID:
values[i] = new(sql.NullInt64)
case notificationclient.FieldName, notificationclient.FieldService, notificationclient.FieldSettings:
values[i] = new(sql.NullString)
default:
values[i] = new(sql.UnknownType)
}
}
return values, nil
}
// assignValues assigns the values that were returned from sql.Rows (after scanning)
// to the NotificationClient fields.
func (nc *NotificationClient) assignValues(columns []string, values []any) error {
if m, n := len(values), len(columns); m < n {
return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
}
for i := range columns {
switch columns[i] {
case notificationclient.FieldID:
value, ok := values[i].(*sql.NullInt64)
if !ok {
return fmt.Errorf("unexpected type %T for field id", value)
}
nc.ID = int(value.Int64)
case notificationclient.FieldName:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field name", values[i])
} else if value.Valid {
nc.Name = value.String
}
case notificationclient.FieldService:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field service", values[i])
} else if value.Valid {
nc.Service = value.String
}
case notificationclient.FieldSettings:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field settings", values[i])
} else if value.Valid {
nc.Settings = value.String
}
case notificationclient.FieldEnabled:
if value, ok := values[i].(*sql.NullBool); !ok {
return fmt.Errorf("unexpected type %T for field enabled", values[i])
} else if value.Valid {
nc.Enabled = value.Bool
}
default:
nc.selectValues.Set(columns[i], values[i])
}
}
return nil
}
// Value returns the ent.Value that was dynamically selected and assigned to the NotificationClient.
// This includes values selected through modifiers, order, etc.
func (nc *NotificationClient) Value(name string) (ent.Value, error) {
return nc.selectValues.Get(name)
}
// Update returns a builder for updating this NotificationClient.
// Note that you need to call NotificationClient.Unwrap() before calling this method if this NotificationClient
// was returned from a transaction, and the transaction was committed or rolled back.
func (nc *NotificationClient) Update() *NotificationClientUpdateOne {
return NewNotificationClientClient(nc.config).UpdateOne(nc)
}
// Unwrap unwraps the NotificationClient entity that was returned from a transaction after it was closed,
// so that all future queries will be executed through the driver which created the transaction.
func (nc *NotificationClient) Unwrap() *NotificationClient {
_tx, ok := nc.config.driver.(*txDriver)
if !ok {
panic("ent: NotificationClient is not a transactional entity")
}
nc.config.driver = _tx.drv
return nc
}
// String implements the fmt.Stringer.
func (nc *NotificationClient) String() string {
var builder strings.Builder
builder.WriteString("NotificationClient(")
builder.WriteString(fmt.Sprintf("id=%v, ", nc.ID))
builder.WriteString("name=")
builder.WriteString(nc.Name)
builder.WriteString(", ")
builder.WriteString("service=")
builder.WriteString(nc.Service)
builder.WriteString(", ")
builder.WriteString("settings=")
builder.WriteString(nc.Settings)
builder.WriteString(", ")
builder.WriteString("enabled=")
builder.WriteString(fmt.Sprintf("%v", nc.Enabled))
builder.WriteByte(')')
return builder.String()
}
// NotificationClients is a parsable slice of NotificationClient.
type NotificationClients []*NotificationClient

View File

@@ -0,0 +1,76 @@
// Code generated by ent, DO NOT EDIT.
package notificationclient
import (
"entgo.io/ent/dialect/sql"
)
const (
// Label holds the string label denoting the notificationclient type in the database.
Label = "notification_client"
// FieldID holds the string denoting the id field in the database.
FieldID = "id"
// FieldName holds the string denoting the name field in the database.
FieldName = "name"
// FieldService holds the string denoting the service field in the database.
FieldService = "service"
// FieldSettings holds the string denoting the settings field in the database.
FieldSettings = "settings"
// FieldEnabled holds the string denoting the enabled field in the database.
FieldEnabled = "enabled"
// Table holds the table name of the notificationclient in the database.
Table = "notification_clients"
)
// Columns holds all SQL columns for notificationclient fields.
var Columns = []string{
FieldID,
FieldName,
FieldService,
FieldSettings,
FieldEnabled,
}
// ValidColumn reports if the column name is valid (part of the table columns).
func ValidColumn(column string) bool {
for i := range Columns {
if column == Columns[i] {
return true
}
}
return false
}
var (
// DefaultEnabled holds the default value on creation for the "enabled" field.
DefaultEnabled bool
)
// OrderOption defines the ordering options for the NotificationClient queries.
type OrderOption func(*sql.Selector)
// ByID orders the results by the id field.
func ByID(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldID, opts...).ToFunc()
}
// ByName orders the results by the name field.
func ByName(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldName, opts...).ToFunc()
}
// ByService orders the results by the service field.
func ByService(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldService, opts...).ToFunc()
}
// BySettings orders the results by the settings field.
func BySettings(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldSettings, opts...).ToFunc()
}
// ByEnabled orders the results by the enabled field.
func ByEnabled(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldEnabled, opts...).ToFunc()
}

View File

@@ -0,0 +1,294 @@
// Code generated by ent, DO NOT EDIT.
package notificationclient
import (
"polaris/ent/predicate"
"entgo.io/ent/dialect/sql"
)
// ID filters vertices based on their ID field.
func ID(id int) predicate.NotificationClient {
return predicate.NotificationClient(sql.FieldEQ(FieldID, id))
}
// IDEQ applies the EQ predicate on the ID field.
func IDEQ(id int) predicate.NotificationClient {
return predicate.NotificationClient(sql.FieldEQ(FieldID, id))
}
// IDNEQ applies the NEQ predicate on the ID field.
func IDNEQ(id int) predicate.NotificationClient {
return predicate.NotificationClient(sql.FieldNEQ(FieldID, id))
}
// IDIn applies the In predicate on the ID field.
func IDIn(ids ...int) predicate.NotificationClient {
return predicate.NotificationClient(sql.FieldIn(FieldID, ids...))
}
// IDNotIn applies the NotIn predicate on the ID field.
func IDNotIn(ids ...int) predicate.NotificationClient {
return predicate.NotificationClient(sql.FieldNotIn(FieldID, ids...))
}
// IDGT applies the GT predicate on the ID field.
func IDGT(id int) predicate.NotificationClient {
return predicate.NotificationClient(sql.FieldGT(FieldID, id))
}
// IDGTE applies the GTE predicate on the ID field.
func IDGTE(id int) predicate.NotificationClient {
return predicate.NotificationClient(sql.FieldGTE(FieldID, id))
}
// IDLT applies the LT predicate on the ID field.
func IDLT(id int) predicate.NotificationClient {
return predicate.NotificationClient(sql.FieldLT(FieldID, id))
}
// IDLTE applies the LTE predicate on the ID field.
func IDLTE(id int) predicate.NotificationClient {
return predicate.NotificationClient(sql.FieldLTE(FieldID, id))
}
// Name applies equality check predicate on the "name" field. It's identical to NameEQ.
func Name(v string) predicate.NotificationClient {
return predicate.NotificationClient(sql.FieldEQ(FieldName, v))
}
// Service applies equality check predicate on the "service" field. It's identical to ServiceEQ.
func Service(v string) predicate.NotificationClient {
return predicate.NotificationClient(sql.FieldEQ(FieldService, v))
}
// Settings applies equality check predicate on the "settings" field. It's identical to SettingsEQ.
func Settings(v string) predicate.NotificationClient {
return predicate.NotificationClient(sql.FieldEQ(FieldSettings, v))
}
// Enabled applies equality check predicate on the "enabled" field. It's identical to EnabledEQ.
func Enabled(v bool) predicate.NotificationClient {
return predicate.NotificationClient(sql.FieldEQ(FieldEnabled, v))
}
// NameEQ applies the EQ predicate on the "name" field.
func NameEQ(v string) predicate.NotificationClient {
return predicate.NotificationClient(sql.FieldEQ(FieldName, v))
}
// NameNEQ applies the NEQ predicate on the "name" field.
func NameNEQ(v string) predicate.NotificationClient {
return predicate.NotificationClient(sql.FieldNEQ(FieldName, v))
}
// NameIn applies the In predicate on the "name" field.
func NameIn(vs ...string) predicate.NotificationClient {
return predicate.NotificationClient(sql.FieldIn(FieldName, vs...))
}
// NameNotIn applies the NotIn predicate on the "name" field.
func NameNotIn(vs ...string) predicate.NotificationClient {
return predicate.NotificationClient(sql.FieldNotIn(FieldName, vs...))
}
// NameGT applies the GT predicate on the "name" field.
func NameGT(v string) predicate.NotificationClient {
return predicate.NotificationClient(sql.FieldGT(FieldName, v))
}
// NameGTE applies the GTE predicate on the "name" field.
func NameGTE(v string) predicate.NotificationClient {
return predicate.NotificationClient(sql.FieldGTE(FieldName, v))
}
// NameLT applies the LT predicate on the "name" field.
func NameLT(v string) predicate.NotificationClient {
return predicate.NotificationClient(sql.FieldLT(FieldName, v))
}
// NameLTE applies the LTE predicate on the "name" field.
func NameLTE(v string) predicate.NotificationClient {
return predicate.NotificationClient(sql.FieldLTE(FieldName, v))
}
// NameContains applies the Contains predicate on the "name" field.
func NameContains(v string) predicate.NotificationClient {
return predicate.NotificationClient(sql.FieldContains(FieldName, v))
}
// NameHasPrefix applies the HasPrefix predicate on the "name" field.
func NameHasPrefix(v string) predicate.NotificationClient {
return predicate.NotificationClient(sql.FieldHasPrefix(FieldName, v))
}
// NameHasSuffix applies the HasSuffix predicate on the "name" field.
func NameHasSuffix(v string) predicate.NotificationClient {
return predicate.NotificationClient(sql.FieldHasSuffix(FieldName, v))
}
// NameEqualFold applies the EqualFold predicate on the "name" field.
func NameEqualFold(v string) predicate.NotificationClient {
return predicate.NotificationClient(sql.FieldEqualFold(FieldName, v))
}
// NameContainsFold applies the ContainsFold predicate on the "name" field.
func NameContainsFold(v string) predicate.NotificationClient {
return predicate.NotificationClient(sql.FieldContainsFold(FieldName, v))
}
// ServiceEQ applies the EQ predicate on the "service" field.
func ServiceEQ(v string) predicate.NotificationClient {
return predicate.NotificationClient(sql.FieldEQ(FieldService, v))
}
// ServiceNEQ applies the NEQ predicate on the "service" field.
func ServiceNEQ(v string) predicate.NotificationClient {
return predicate.NotificationClient(sql.FieldNEQ(FieldService, v))
}
// ServiceIn applies the In predicate on the "service" field.
func ServiceIn(vs ...string) predicate.NotificationClient {
return predicate.NotificationClient(sql.FieldIn(FieldService, vs...))
}
// ServiceNotIn applies the NotIn predicate on the "service" field.
func ServiceNotIn(vs ...string) predicate.NotificationClient {
return predicate.NotificationClient(sql.FieldNotIn(FieldService, vs...))
}
// ServiceGT applies the GT predicate on the "service" field.
func ServiceGT(v string) predicate.NotificationClient {
return predicate.NotificationClient(sql.FieldGT(FieldService, v))
}
// ServiceGTE applies the GTE predicate on the "service" field.
func ServiceGTE(v string) predicate.NotificationClient {
return predicate.NotificationClient(sql.FieldGTE(FieldService, v))
}
// ServiceLT applies the LT predicate on the "service" field.
func ServiceLT(v string) predicate.NotificationClient {
return predicate.NotificationClient(sql.FieldLT(FieldService, v))
}
// ServiceLTE applies the LTE predicate on the "service" field.
func ServiceLTE(v string) predicate.NotificationClient {
return predicate.NotificationClient(sql.FieldLTE(FieldService, v))
}
// ServiceContains applies the Contains predicate on the "service" field.
func ServiceContains(v string) predicate.NotificationClient {
return predicate.NotificationClient(sql.FieldContains(FieldService, v))
}
// ServiceHasPrefix applies the HasPrefix predicate on the "service" field.
func ServiceHasPrefix(v string) predicate.NotificationClient {
return predicate.NotificationClient(sql.FieldHasPrefix(FieldService, v))
}
// ServiceHasSuffix applies the HasSuffix predicate on the "service" field.
func ServiceHasSuffix(v string) predicate.NotificationClient {
return predicate.NotificationClient(sql.FieldHasSuffix(FieldService, v))
}
// ServiceEqualFold applies the EqualFold predicate on the "service" field.
func ServiceEqualFold(v string) predicate.NotificationClient {
return predicate.NotificationClient(sql.FieldEqualFold(FieldService, v))
}
// ServiceContainsFold applies the ContainsFold predicate on the "service" field.
func ServiceContainsFold(v string) predicate.NotificationClient {
return predicate.NotificationClient(sql.FieldContainsFold(FieldService, v))
}
// SettingsEQ applies the EQ predicate on the "settings" field.
func SettingsEQ(v string) predicate.NotificationClient {
return predicate.NotificationClient(sql.FieldEQ(FieldSettings, v))
}
// SettingsNEQ applies the NEQ predicate on the "settings" field.
func SettingsNEQ(v string) predicate.NotificationClient {
return predicate.NotificationClient(sql.FieldNEQ(FieldSettings, v))
}
// SettingsIn applies the In predicate on the "settings" field.
func SettingsIn(vs ...string) predicate.NotificationClient {
return predicate.NotificationClient(sql.FieldIn(FieldSettings, vs...))
}
// SettingsNotIn applies the NotIn predicate on the "settings" field.
func SettingsNotIn(vs ...string) predicate.NotificationClient {
return predicate.NotificationClient(sql.FieldNotIn(FieldSettings, vs...))
}
// SettingsGT applies the GT predicate on the "settings" field.
func SettingsGT(v string) predicate.NotificationClient {
return predicate.NotificationClient(sql.FieldGT(FieldSettings, v))
}
// SettingsGTE applies the GTE predicate on the "settings" field.
func SettingsGTE(v string) predicate.NotificationClient {
return predicate.NotificationClient(sql.FieldGTE(FieldSettings, v))
}
// SettingsLT applies the LT predicate on the "settings" field.
func SettingsLT(v string) predicate.NotificationClient {
return predicate.NotificationClient(sql.FieldLT(FieldSettings, v))
}
// SettingsLTE applies the LTE predicate on the "settings" field.
func SettingsLTE(v string) predicate.NotificationClient {
return predicate.NotificationClient(sql.FieldLTE(FieldSettings, v))
}
// SettingsContains applies the Contains predicate on the "settings" field.
func SettingsContains(v string) predicate.NotificationClient {
return predicate.NotificationClient(sql.FieldContains(FieldSettings, v))
}
// SettingsHasPrefix applies the HasPrefix predicate on the "settings" field.
func SettingsHasPrefix(v string) predicate.NotificationClient {
return predicate.NotificationClient(sql.FieldHasPrefix(FieldSettings, v))
}
// SettingsHasSuffix applies the HasSuffix predicate on the "settings" field.
func SettingsHasSuffix(v string) predicate.NotificationClient {
return predicate.NotificationClient(sql.FieldHasSuffix(FieldSettings, v))
}
// SettingsEqualFold applies the EqualFold predicate on the "settings" field.
func SettingsEqualFold(v string) predicate.NotificationClient {
return predicate.NotificationClient(sql.FieldEqualFold(FieldSettings, v))
}
// SettingsContainsFold applies the ContainsFold predicate on the "settings" field.
func SettingsContainsFold(v string) predicate.NotificationClient {
return predicate.NotificationClient(sql.FieldContainsFold(FieldSettings, v))
}
// EnabledEQ applies the EQ predicate on the "enabled" field.
func EnabledEQ(v bool) predicate.NotificationClient {
return predicate.NotificationClient(sql.FieldEQ(FieldEnabled, v))
}
// EnabledNEQ applies the NEQ predicate on the "enabled" field.
func EnabledNEQ(v bool) predicate.NotificationClient {
return predicate.NotificationClient(sql.FieldNEQ(FieldEnabled, v))
}
// And groups predicates with the AND operator between them.
func And(predicates ...predicate.NotificationClient) predicate.NotificationClient {
return predicate.NotificationClient(sql.AndPredicates(predicates...))
}
// Or groups predicates with the OR operator between them.
func Or(predicates ...predicate.NotificationClient) predicate.NotificationClient {
return predicate.NotificationClient(sql.OrPredicates(predicates...))
}
// Not applies the not operator on the given predicate.
func Not(p predicate.NotificationClient) predicate.NotificationClient {
return predicate.NotificationClient(sql.NotPredicates(p))
}

View File

@@ -0,0 +1,240 @@
// Code generated by ent, DO NOT EDIT.
package ent
import (
"context"
"errors"
"fmt"
"polaris/ent/notificationclient"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
)
// NotificationClientCreate is the builder for creating a NotificationClient entity.
type NotificationClientCreate struct {
config
mutation *NotificationClientMutation
hooks []Hook
}
// SetName sets the "name" field.
func (ncc *NotificationClientCreate) SetName(s string) *NotificationClientCreate {
ncc.mutation.SetName(s)
return ncc
}
// SetService sets the "service" field.
func (ncc *NotificationClientCreate) SetService(s string) *NotificationClientCreate {
ncc.mutation.SetService(s)
return ncc
}
// SetSettings sets the "settings" field.
func (ncc *NotificationClientCreate) SetSettings(s string) *NotificationClientCreate {
ncc.mutation.SetSettings(s)
return ncc
}
// SetEnabled sets the "enabled" field.
func (ncc *NotificationClientCreate) SetEnabled(b bool) *NotificationClientCreate {
ncc.mutation.SetEnabled(b)
return ncc
}
// SetNillableEnabled sets the "enabled" field if the given value is not nil.
func (ncc *NotificationClientCreate) SetNillableEnabled(b *bool) *NotificationClientCreate {
if b != nil {
ncc.SetEnabled(*b)
}
return ncc
}
// Mutation returns the NotificationClientMutation object of the builder.
func (ncc *NotificationClientCreate) Mutation() *NotificationClientMutation {
return ncc.mutation
}
// Save creates the NotificationClient in the database.
func (ncc *NotificationClientCreate) Save(ctx context.Context) (*NotificationClient, error) {
ncc.defaults()
return withHooks(ctx, ncc.sqlSave, ncc.mutation, ncc.hooks)
}
// SaveX calls Save and panics if Save returns an error.
func (ncc *NotificationClientCreate) SaveX(ctx context.Context) *NotificationClient {
v, err := ncc.Save(ctx)
if err != nil {
panic(err)
}
return v
}
// Exec executes the query.
func (ncc *NotificationClientCreate) Exec(ctx context.Context) error {
_, err := ncc.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (ncc *NotificationClientCreate) ExecX(ctx context.Context) {
if err := ncc.Exec(ctx); err != nil {
panic(err)
}
}
// defaults sets the default values of the builder before save.
func (ncc *NotificationClientCreate) defaults() {
if _, ok := ncc.mutation.Enabled(); !ok {
v := notificationclient.DefaultEnabled
ncc.mutation.SetEnabled(v)
}
}
// check runs all checks and user-defined validators on the builder.
func (ncc *NotificationClientCreate) check() error {
if _, ok := ncc.mutation.Name(); !ok {
return &ValidationError{Name: "name", err: errors.New(`ent: missing required field "NotificationClient.name"`)}
}
if _, ok := ncc.mutation.Service(); !ok {
return &ValidationError{Name: "service", err: errors.New(`ent: missing required field "NotificationClient.service"`)}
}
if _, ok := ncc.mutation.Settings(); !ok {
return &ValidationError{Name: "settings", err: errors.New(`ent: missing required field "NotificationClient.settings"`)}
}
if _, ok := ncc.mutation.Enabled(); !ok {
return &ValidationError{Name: "enabled", err: errors.New(`ent: missing required field "NotificationClient.enabled"`)}
}
return nil
}
func (ncc *NotificationClientCreate) sqlSave(ctx context.Context) (*NotificationClient, error) {
if err := ncc.check(); err != nil {
return nil, err
}
_node, _spec := ncc.createSpec()
if err := sqlgraph.CreateNode(ctx, ncc.driver, _spec); err != nil {
if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
return nil, err
}
id := _spec.ID.Value.(int64)
_node.ID = int(id)
ncc.mutation.id = &_node.ID
ncc.mutation.done = true
return _node, nil
}
func (ncc *NotificationClientCreate) createSpec() (*NotificationClient, *sqlgraph.CreateSpec) {
var (
_node = &NotificationClient{config: ncc.config}
_spec = sqlgraph.NewCreateSpec(notificationclient.Table, sqlgraph.NewFieldSpec(notificationclient.FieldID, field.TypeInt))
)
if value, ok := ncc.mutation.Name(); ok {
_spec.SetField(notificationclient.FieldName, field.TypeString, value)
_node.Name = value
}
if value, ok := ncc.mutation.Service(); ok {
_spec.SetField(notificationclient.FieldService, field.TypeString, value)
_node.Service = value
}
if value, ok := ncc.mutation.Settings(); ok {
_spec.SetField(notificationclient.FieldSettings, field.TypeString, value)
_node.Settings = value
}
if value, ok := ncc.mutation.Enabled(); ok {
_spec.SetField(notificationclient.FieldEnabled, field.TypeBool, value)
_node.Enabled = value
}
return _node, _spec
}
// NotificationClientCreateBulk is the builder for creating many NotificationClient entities in bulk.
type NotificationClientCreateBulk struct {
config
err error
builders []*NotificationClientCreate
}
// Save creates the NotificationClient entities in the database.
func (nccb *NotificationClientCreateBulk) Save(ctx context.Context) ([]*NotificationClient, error) {
if nccb.err != nil {
return nil, nccb.err
}
specs := make([]*sqlgraph.CreateSpec, len(nccb.builders))
nodes := make([]*NotificationClient, len(nccb.builders))
mutators := make([]Mutator, len(nccb.builders))
for i := range nccb.builders {
func(i int, root context.Context) {
builder := nccb.builders[i]
builder.defaults()
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
mutation, ok := m.(*NotificationClientMutation)
if !ok {
return nil, fmt.Errorf("unexpected mutation type %T", m)
}
if err := builder.check(); err != nil {
return nil, err
}
builder.mutation = mutation
var err error
nodes[i], specs[i] = builder.createSpec()
if i < len(mutators)-1 {
_, err = mutators[i+1].Mutate(root, nccb.builders[i+1].mutation)
} else {
spec := &sqlgraph.BatchCreateSpec{Nodes: specs}
// Invoke the actual operation on the latest mutation in the chain.
if err = sqlgraph.BatchCreate(ctx, nccb.driver, spec); err != nil {
if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
}
}
if err != nil {
return nil, err
}
mutation.id = &nodes[i].ID
if specs[i].ID.Value != nil {
id := specs[i].ID.Value.(int64)
nodes[i].ID = int(id)
}
mutation.done = true
return nodes[i], nil
})
for i := len(builder.hooks) - 1; i >= 0; i-- {
mut = builder.hooks[i](mut)
}
mutators[i] = mut
}(i, ctx)
}
if len(mutators) > 0 {
if _, err := mutators[0].Mutate(ctx, nccb.builders[0].mutation); err != nil {
return nil, err
}
}
return nodes, nil
}
// SaveX is like Save, but panics if an error occurs.
func (nccb *NotificationClientCreateBulk) SaveX(ctx context.Context) []*NotificationClient {
v, err := nccb.Save(ctx)
if err != nil {
panic(err)
}
return v
}
// Exec executes the query.
func (nccb *NotificationClientCreateBulk) Exec(ctx context.Context) error {
_, err := nccb.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (nccb *NotificationClientCreateBulk) ExecX(ctx context.Context) {
if err := nccb.Exec(ctx); err != nil {
panic(err)
}
}

View File

@@ -0,0 +1,88 @@
// Code generated by ent, DO NOT EDIT.
package ent
import (
"context"
"polaris/ent/notificationclient"
"polaris/ent/predicate"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
)
// NotificationClientDelete is the builder for deleting a NotificationClient entity.
type NotificationClientDelete struct {
config
hooks []Hook
mutation *NotificationClientMutation
}
// Where appends a list predicates to the NotificationClientDelete builder.
func (ncd *NotificationClientDelete) Where(ps ...predicate.NotificationClient) *NotificationClientDelete {
ncd.mutation.Where(ps...)
return ncd
}
// Exec executes the deletion query and returns how many vertices were deleted.
func (ncd *NotificationClientDelete) Exec(ctx context.Context) (int, error) {
return withHooks(ctx, ncd.sqlExec, ncd.mutation, ncd.hooks)
}
// ExecX is like Exec, but panics if an error occurs.
func (ncd *NotificationClientDelete) ExecX(ctx context.Context) int {
n, err := ncd.Exec(ctx)
if err != nil {
panic(err)
}
return n
}
func (ncd *NotificationClientDelete) sqlExec(ctx context.Context) (int, error) {
_spec := sqlgraph.NewDeleteSpec(notificationclient.Table, sqlgraph.NewFieldSpec(notificationclient.FieldID, field.TypeInt))
if ps := ncd.mutation.predicates; len(ps) > 0 {
_spec.Predicate = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
affected, err := sqlgraph.DeleteNodes(ctx, ncd.driver, _spec)
if err != nil && sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
ncd.mutation.done = true
return affected, err
}
// NotificationClientDeleteOne is the builder for deleting a single NotificationClient entity.
type NotificationClientDeleteOne struct {
ncd *NotificationClientDelete
}
// Where appends a list predicates to the NotificationClientDelete builder.
func (ncdo *NotificationClientDeleteOne) Where(ps ...predicate.NotificationClient) *NotificationClientDeleteOne {
ncdo.ncd.mutation.Where(ps...)
return ncdo
}
// Exec executes the deletion query.
func (ncdo *NotificationClientDeleteOne) Exec(ctx context.Context) error {
n, err := ncdo.ncd.Exec(ctx)
switch {
case err != nil:
return err
case n == 0:
return &NotFoundError{notificationclient.Label}
default:
return nil
}
}
// ExecX is like Exec, but panics if an error occurs.
func (ncdo *NotificationClientDeleteOne) ExecX(ctx context.Context) {
if err := ncdo.Exec(ctx); err != nil {
panic(err)
}
}

View File

@@ -0,0 +1,526 @@
// Code generated by ent, DO NOT EDIT.
package ent
import (
"context"
"fmt"
"math"
"polaris/ent/notificationclient"
"polaris/ent/predicate"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
)
// NotificationClientQuery is the builder for querying NotificationClient entities.
type NotificationClientQuery struct {
config
ctx *QueryContext
order []notificationclient.OrderOption
inters []Interceptor
predicates []predicate.NotificationClient
// intermediate query (i.e. traversal path).
sql *sql.Selector
path func(context.Context) (*sql.Selector, error)
}
// Where adds a new predicate for the NotificationClientQuery builder.
func (ncq *NotificationClientQuery) Where(ps ...predicate.NotificationClient) *NotificationClientQuery {
ncq.predicates = append(ncq.predicates, ps...)
return ncq
}
// Limit the number of records to be returned by this query.
func (ncq *NotificationClientQuery) Limit(limit int) *NotificationClientQuery {
ncq.ctx.Limit = &limit
return ncq
}
// Offset to start from.
func (ncq *NotificationClientQuery) Offset(offset int) *NotificationClientQuery {
ncq.ctx.Offset = &offset
return ncq
}
// Unique configures the query builder to filter duplicate records on query.
// By default, unique is set to true, and can be disabled using this method.
func (ncq *NotificationClientQuery) Unique(unique bool) *NotificationClientQuery {
ncq.ctx.Unique = &unique
return ncq
}
// Order specifies how the records should be ordered.
func (ncq *NotificationClientQuery) Order(o ...notificationclient.OrderOption) *NotificationClientQuery {
ncq.order = append(ncq.order, o...)
return ncq
}
// First returns the first NotificationClient entity from the query.
// Returns a *NotFoundError when no NotificationClient was found.
func (ncq *NotificationClientQuery) First(ctx context.Context) (*NotificationClient, error) {
nodes, err := ncq.Limit(1).All(setContextOp(ctx, ncq.ctx, "First"))
if err != nil {
return nil, err
}
if len(nodes) == 0 {
return nil, &NotFoundError{notificationclient.Label}
}
return nodes[0], nil
}
// FirstX is like First, but panics if an error occurs.
func (ncq *NotificationClientQuery) FirstX(ctx context.Context) *NotificationClient {
node, err := ncq.First(ctx)
if err != nil && !IsNotFound(err) {
panic(err)
}
return node
}
// FirstID returns the first NotificationClient ID from the query.
// Returns a *NotFoundError when no NotificationClient ID was found.
func (ncq *NotificationClientQuery) FirstID(ctx context.Context) (id int, err error) {
var ids []int
if ids, err = ncq.Limit(1).IDs(setContextOp(ctx, ncq.ctx, "FirstID")); err != nil {
return
}
if len(ids) == 0 {
err = &NotFoundError{notificationclient.Label}
return
}
return ids[0], nil
}
// FirstIDX is like FirstID, but panics if an error occurs.
func (ncq *NotificationClientQuery) FirstIDX(ctx context.Context) int {
id, err := ncq.FirstID(ctx)
if err != nil && !IsNotFound(err) {
panic(err)
}
return id
}
// Only returns a single NotificationClient entity found by the query, ensuring it only returns one.
// Returns a *NotSingularError when more than one NotificationClient entity is found.
// Returns a *NotFoundError when no NotificationClient entities are found.
func (ncq *NotificationClientQuery) Only(ctx context.Context) (*NotificationClient, error) {
nodes, err := ncq.Limit(2).All(setContextOp(ctx, ncq.ctx, "Only"))
if err != nil {
return nil, err
}
switch len(nodes) {
case 1:
return nodes[0], nil
case 0:
return nil, &NotFoundError{notificationclient.Label}
default:
return nil, &NotSingularError{notificationclient.Label}
}
}
// OnlyX is like Only, but panics if an error occurs.
func (ncq *NotificationClientQuery) OnlyX(ctx context.Context) *NotificationClient {
node, err := ncq.Only(ctx)
if err != nil {
panic(err)
}
return node
}
// OnlyID is like Only, but returns the only NotificationClient ID in the query.
// Returns a *NotSingularError when more than one NotificationClient ID is found.
// Returns a *NotFoundError when no entities are found.
func (ncq *NotificationClientQuery) OnlyID(ctx context.Context) (id int, err error) {
var ids []int
if ids, err = ncq.Limit(2).IDs(setContextOp(ctx, ncq.ctx, "OnlyID")); err != nil {
return
}
switch len(ids) {
case 1:
id = ids[0]
case 0:
err = &NotFoundError{notificationclient.Label}
default:
err = &NotSingularError{notificationclient.Label}
}
return
}
// OnlyIDX is like OnlyID, but panics if an error occurs.
func (ncq *NotificationClientQuery) OnlyIDX(ctx context.Context) int {
id, err := ncq.OnlyID(ctx)
if err != nil {
panic(err)
}
return id
}
// All executes the query and returns a list of NotificationClients.
func (ncq *NotificationClientQuery) All(ctx context.Context) ([]*NotificationClient, error) {
ctx = setContextOp(ctx, ncq.ctx, "All")
if err := ncq.prepareQuery(ctx); err != nil {
return nil, err
}
qr := querierAll[[]*NotificationClient, *NotificationClientQuery]()
return withInterceptors[[]*NotificationClient](ctx, ncq, qr, ncq.inters)
}
// AllX is like All, but panics if an error occurs.
func (ncq *NotificationClientQuery) AllX(ctx context.Context) []*NotificationClient {
nodes, err := ncq.All(ctx)
if err != nil {
panic(err)
}
return nodes
}
// IDs executes the query and returns a list of NotificationClient IDs.
func (ncq *NotificationClientQuery) IDs(ctx context.Context) (ids []int, err error) {
if ncq.ctx.Unique == nil && ncq.path != nil {
ncq.Unique(true)
}
ctx = setContextOp(ctx, ncq.ctx, "IDs")
if err = ncq.Select(notificationclient.FieldID).Scan(ctx, &ids); err != nil {
return nil, err
}
return ids, nil
}
// IDsX is like IDs, but panics if an error occurs.
func (ncq *NotificationClientQuery) IDsX(ctx context.Context) []int {
ids, err := ncq.IDs(ctx)
if err != nil {
panic(err)
}
return ids
}
// Count returns the count of the given query.
func (ncq *NotificationClientQuery) Count(ctx context.Context) (int, error) {
ctx = setContextOp(ctx, ncq.ctx, "Count")
if err := ncq.prepareQuery(ctx); err != nil {
return 0, err
}
return withInterceptors[int](ctx, ncq, querierCount[*NotificationClientQuery](), ncq.inters)
}
// CountX is like Count, but panics if an error occurs.
func (ncq *NotificationClientQuery) CountX(ctx context.Context) int {
count, err := ncq.Count(ctx)
if err != nil {
panic(err)
}
return count
}
// Exist returns true if the query has elements in the graph.
func (ncq *NotificationClientQuery) Exist(ctx context.Context) (bool, error) {
ctx = setContextOp(ctx, ncq.ctx, "Exist")
switch _, err := ncq.FirstID(ctx); {
case IsNotFound(err):
return false, nil
case err != nil:
return false, fmt.Errorf("ent: check existence: %w", err)
default:
return true, nil
}
}
// ExistX is like Exist, but panics if an error occurs.
func (ncq *NotificationClientQuery) ExistX(ctx context.Context) bool {
exist, err := ncq.Exist(ctx)
if err != nil {
panic(err)
}
return exist
}
// Clone returns a duplicate of the NotificationClientQuery builder, including all associated steps. It can be
// used to prepare common query builders and use them differently after the clone is made.
func (ncq *NotificationClientQuery) Clone() *NotificationClientQuery {
if ncq == nil {
return nil
}
return &NotificationClientQuery{
config: ncq.config,
ctx: ncq.ctx.Clone(),
order: append([]notificationclient.OrderOption{}, ncq.order...),
inters: append([]Interceptor{}, ncq.inters...),
predicates: append([]predicate.NotificationClient{}, ncq.predicates...),
// clone intermediate query.
sql: ncq.sql.Clone(),
path: ncq.path,
}
}
// GroupBy is used to group vertices by one or more fields/columns.
// It is often used with aggregate functions, like: count, max, mean, min, sum.
//
// Example:
//
// var v []struct {
// Name string `json:"name,omitempty"`
// Count int `json:"count,omitempty"`
// }
//
// client.NotificationClient.Query().
// GroupBy(notificationclient.FieldName).
// Aggregate(ent.Count()).
// Scan(ctx, &v)
func (ncq *NotificationClientQuery) GroupBy(field string, fields ...string) *NotificationClientGroupBy {
ncq.ctx.Fields = append([]string{field}, fields...)
grbuild := &NotificationClientGroupBy{build: ncq}
grbuild.flds = &ncq.ctx.Fields
grbuild.label = notificationclient.Label
grbuild.scan = grbuild.Scan
return grbuild
}
// Select allows the selection one or more fields/columns for the given query,
// instead of selecting all fields in the entity.
//
// Example:
//
// var v []struct {
// Name string `json:"name,omitempty"`
// }
//
// client.NotificationClient.Query().
// Select(notificationclient.FieldName).
// Scan(ctx, &v)
func (ncq *NotificationClientQuery) Select(fields ...string) *NotificationClientSelect {
ncq.ctx.Fields = append(ncq.ctx.Fields, fields...)
sbuild := &NotificationClientSelect{NotificationClientQuery: ncq}
sbuild.label = notificationclient.Label
sbuild.flds, sbuild.scan = &ncq.ctx.Fields, sbuild.Scan
return sbuild
}
// Aggregate returns a NotificationClientSelect configured with the given aggregations.
func (ncq *NotificationClientQuery) Aggregate(fns ...AggregateFunc) *NotificationClientSelect {
return ncq.Select().Aggregate(fns...)
}
func (ncq *NotificationClientQuery) prepareQuery(ctx context.Context) error {
for _, inter := range ncq.inters {
if inter == nil {
return fmt.Errorf("ent: uninitialized interceptor (forgotten import ent/runtime?)")
}
if trv, ok := inter.(Traverser); ok {
if err := trv.Traverse(ctx, ncq); err != nil {
return err
}
}
}
for _, f := range ncq.ctx.Fields {
if !notificationclient.ValidColumn(f) {
return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
}
}
if ncq.path != nil {
prev, err := ncq.path(ctx)
if err != nil {
return err
}
ncq.sql = prev
}
return nil
}
func (ncq *NotificationClientQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*NotificationClient, error) {
var (
nodes = []*NotificationClient{}
_spec = ncq.querySpec()
)
_spec.ScanValues = func(columns []string) ([]any, error) {
return (*NotificationClient).scanValues(nil, columns)
}
_spec.Assign = func(columns []string, values []any) error {
node := &NotificationClient{config: ncq.config}
nodes = append(nodes, node)
return node.assignValues(columns, values)
}
for i := range hooks {
hooks[i](ctx, _spec)
}
if err := sqlgraph.QueryNodes(ctx, ncq.driver, _spec); err != nil {
return nil, err
}
if len(nodes) == 0 {
return nodes, nil
}
return nodes, nil
}
func (ncq *NotificationClientQuery) sqlCount(ctx context.Context) (int, error) {
_spec := ncq.querySpec()
_spec.Node.Columns = ncq.ctx.Fields
if len(ncq.ctx.Fields) > 0 {
_spec.Unique = ncq.ctx.Unique != nil && *ncq.ctx.Unique
}
return sqlgraph.CountNodes(ctx, ncq.driver, _spec)
}
func (ncq *NotificationClientQuery) querySpec() *sqlgraph.QuerySpec {
_spec := sqlgraph.NewQuerySpec(notificationclient.Table, notificationclient.Columns, sqlgraph.NewFieldSpec(notificationclient.FieldID, field.TypeInt))
_spec.From = ncq.sql
if unique := ncq.ctx.Unique; unique != nil {
_spec.Unique = *unique
} else if ncq.path != nil {
_spec.Unique = true
}
if fields := ncq.ctx.Fields; len(fields) > 0 {
_spec.Node.Columns = make([]string, 0, len(fields))
_spec.Node.Columns = append(_spec.Node.Columns, notificationclient.FieldID)
for i := range fields {
if fields[i] != notificationclient.FieldID {
_spec.Node.Columns = append(_spec.Node.Columns, fields[i])
}
}
}
if ps := ncq.predicates; len(ps) > 0 {
_spec.Predicate = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
if limit := ncq.ctx.Limit; limit != nil {
_spec.Limit = *limit
}
if offset := ncq.ctx.Offset; offset != nil {
_spec.Offset = *offset
}
if ps := ncq.order; len(ps) > 0 {
_spec.Order = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
return _spec
}
func (ncq *NotificationClientQuery) sqlQuery(ctx context.Context) *sql.Selector {
builder := sql.Dialect(ncq.driver.Dialect())
t1 := builder.Table(notificationclient.Table)
columns := ncq.ctx.Fields
if len(columns) == 0 {
columns = notificationclient.Columns
}
selector := builder.Select(t1.Columns(columns...)...).From(t1)
if ncq.sql != nil {
selector = ncq.sql
selector.Select(selector.Columns(columns...)...)
}
if ncq.ctx.Unique != nil && *ncq.ctx.Unique {
selector.Distinct()
}
for _, p := range ncq.predicates {
p(selector)
}
for _, p := range ncq.order {
p(selector)
}
if offset := ncq.ctx.Offset; offset != nil {
// limit is mandatory for offset clause. We start
// with default value, and override it below if needed.
selector.Offset(*offset).Limit(math.MaxInt32)
}
if limit := ncq.ctx.Limit; limit != nil {
selector.Limit(*limit)
}
return selector
}
// NotificationClientGroupBy is the group-by builder for NotificationClient entities.
type NotificationClientGroupBy struct {
selector
build *NotificationClientQuery
}
// Aggregate adds the given aggregation functions to the group-by query.
func (ncgb *NotificationClientGroupBy) Aggregate(fns ...AggregateFunc) *NotificationClientGroupBy {
ncgb.fns = append(ncgb.fns, fns...)
return ncgb
}
// Scan applies the selector query and scans the result into the given value.
func (ncgb *NotificationClientGroupBy) Scan(ctx context.Context, v any) error {
ctx = setContextOp(ctx, ncgb.build.ctx, "GroupBy")
if err := ncgb.build.prepareQuery(ctx); err != nil {
return err
}
return scanWithInterceptors[*NotificationClientQuery, *NotificationClientGroupBy](ctx, ncgb.build, ncgb, ncgb.build.inters, v)
}
func (ncgb *NotificationClientGroupBy) sqlScan(ctx context.Context, root *NotificationClientQuery, v any) error {
selector := root.sqlQuery(ctx).Select()
aggregation := make([]string, 0, len(ncgb.fns))
for _, fn := range ncgb.fns {
aggregation = append(aggregation, fn(selector))
}
if len(selector.SelectedColumns()) == 0 {
columns := make([]string, 0, len(*ncgb.flds)+len(ncgb.fns))
for _, f := range *ncgb.flds {
columns = append(columns, selector.C(f))
}
columns = append(columns, aggregation...)
selector.Select(columns...)
}
selector.GroupBy(selector.Columns(*ncgb.flds...)...)
if err := selector.Err(); err != nil {
return err
}
rows := &sql.Rows{}
query, args := selector.Query()
if err := ncgb.build.driver.Query(ctx, query, args, rows); err != nil {
return err
}
defer rows.Close()
return sql.ScanSlice(rows, v)
}
// NotificationClientSelect is the builder for selecting fields of NotificationClient entities.
type NotificationClientSelect struct {
*NotificationClientQuery
selector
}
// Aggregate adds the given aggregation functions to the selector query.
func (ncs *NotificationClientSelect) Aggregate(fns ...AggregateFunc) *NotificationClientSelect {
ncs.fns = append(ncs.fns, fns...)
return ncs
}
// Scan applies the selector query and scans the result into the given value.
func (ncs *NotificationClientSelect) Scan(ctx context.Context, v any) error {
ctx = setContextOp(ctx, ncs.ctx, "Select")
if err := ncs.prepareQuery(ctx); err != nil {
return err
}
return scanWithInterceptors[*NotificationClientQuery, *NotificationClientSelect](ctx, ncs.NotificationClientQuery, ncs, ncs.inters, v)
}
func (ncs *NotificationClientSelect) sqlScan(ctx context.Context, root *NotificationClientQuery, v any) error {
selector := root.sqlQuery(ctx)
aggregation := make([]string, 0, len(ncs.fns))
for _, fn := range ncs.fns {
aggregation = append(aggregation, fn(selector))
}
switch n := len(*ncs.selector.flds); {
case n == 0 && len(aggregation) > 0:
selector.Select(aggregation...)
case n != 0 && len(aggregation) > 0:
selector.AppendSelect(aggregation...)
}
rows := &sql.Rows{}
query, args := selector.Query()
if err := ncs.driver.Query(ctx, query, args, rows); err != nil {
return err
}
defer rows.Close()
return sql.ScanSlice(rows, v)
}

View File

@@ -0,0 +1,311 @@
// Code generated by ent, DO NOT EDIT.
package ent
import (
"context"
"errors"
"fmt"
"polaris/ent/notificationclient"
"polaris/ent/predicate"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
)
// NotificationClientUpdate is the builder for updating NotificationClient entities.
type NotificationClientUpdate struct {
config
hooks []Hook
mutation *NotificationClientMutation
}
// Where appends a list predicates to the NotificationClientUpdate builder.
func (ncu *NotificationClientUpdate) Where(ps ...predicate.NotificationClient) *NotificationClientUpdate {
ncu.mutation.Where(ps...)
return ncu
}
// SetName sets the "name" field.
func (ncu *NotificationClientUpdate) SetName(s string) *NotificationClientUpdate {
ncu.mutation.SetName(s)
return ncu
}
// SetNillableName sets the "name" field if the given value is not nil.
func (ncu *NotificationClientUpdate) SetNillableName(s *string) *NotificationClientUpdate {
if s != nil {
ncu.SetName(*s)
}
return ncu
}
// SetService sets the "service" field.
func (ncu *NotificationClientUpdate) SetService(s string) *NotificationClientUpdate {
ncu.mutation.SetService(s)
return ncu
}
// SetNillableService sets the "service" field if the given value is not nil.
func (ncu *NotificationClientUpdate) SetNillableService(s *string) *NotificationClientUpdate {
if s != nil {
ncu.SetService(*s)
}
return ncu
}
// SetSettings sets the "settings" field.
func (ncu *NotificationClientUpdate) SetSettings(s string) *NotificationClientUpdate {
ncu.mutation.SetSettings(s)
return ncu
}
// SetNillableSettings sets the "settings" field if the given value is not nil.
func (ncu *NotificationClientUpdate) SetNillableSettings(s *string) *NotificationClientUpdate {
if s != nil {
ncu.SetSettings(*s)
}
return ncu
}
// SetEnabled sets the "enabled" field.
func (ncu *NotificationClientUpdate) SetEnabled(b bool) *NotificationClientUpdate {
ncu.mutation.SetEnabled(b)
return ncu
}
// SetNillableEnabled sets the "enabled" field if the given value is not nil.
func (ncu *NotificationClientUpdate) SetNillableEnabled(b *bool) *NotificationClientUpdate {
if b != nil {
ncu.SetEnabled(*b)
}
return ncu
}
// Mutation returns the NotificationClientMutation object of the builder.
func (ncu *NotificationClientUpdate) Mutation() *NotificationClientMutation {
return ncu.mutation
}
// Save executes the query and returns the number of nodes affected by the update operation.
func (ncu *NotificationClientUpdate) Save(ctx context.Context) (int, error) {
return withHooks(ctx, ncu.sqlSave, ncu.mutation, ncu.hooks)
}
// SaveX is like Save, but panics if an error occurs.
func (ncu *NotificationClientUpdate) SaveX(ctx context.Context) int {
affected, err := ncu.Save(ctx)
if err != nil {
panic(err)
}
return affected
}
// Exec executes the query.
func (ncu *NotificationClientUpdate) Exec(ctx context.Context) error {
_, err := ncu.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (ncu *NotificationClientUpdate) ExecX(ctx context.Context) {
if err := ncu.Exec(ctx); err != nil {
panic(err)
}
}
func (ncu *NotificationClientUpdate) sqlSave(ctx context.Context) (n int, err error) {
_spec := sqlgraph.NewUpdateSpec(notificationclient.Table, notificationclient.Columns, sqlgraph.NewFieldSpec(notificationclient.FieldID, field.TypeInt))
if ps := ncu.mutation.predicates; len(ps) > 0 {
_spec.Predicate = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
if value, ok := ncu.mutation.Name(); ok {
_spec.SetField(notificationclient.FieldName, field.TypeString, value)
}
if value, ok := ncu.mutation.Service(); ok {
_spec.SetField(notificationclient.FieldService, field.TypeString, value)
}
if value, ok := ncu.mutation.Settings(); ok {
_spec.SetField(notificationclient.FieldSettings, field.TypeString, value)
}
if value, ok := ncu.mutation.Enabled(); ok {
_spec.SetField(notificationclient.FieldEnabled, field.TypeBool, value)
}
if n, err = sqlgraph.UpdateNodes(ctx, ncu.driver, _spec); err != nil {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{notificationclient.Label}
} else if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
return 0, err
}
ncu.mutation.done = true
return n, nil
}
// NotificationClientUpdateOne is the builder for updating a single NotificationClient entity.
type NotificationClientUpdateOne struct {
config
fields []string
hooks []Hook
mutation *NotificationClientMutation
}
// SetName sets the "name" field.
func (ncuo *NotificationClientUpdateOne) SetName(s string) *NotificationClientUpdateOne {
ncuo.mutation.SetName(s)
return ncuo
}
// SetNillableName sets the "name" field if the given value is not nil.
func (ncuo *NotificationClientUpdateOne) SetNillableName(s *string) *NotificationClientUpdateOne {
if s != nil {
ncuo.SetName(*s)
}
return ncuo
}
// SetService sets the "service" field.
func (ncuo *NotificationClientUpdateOne) SetService(s string) *NotificationClientUpdateOne {
ncuo.mutation.SetService(s)
return ncuo
}
// SetNillableService sets the "service" field if the given value is not nil.
func (ncuo *NotificationClientUpdateOne) SetNillableService(s *string) *NotificationClientUpdateOne {
if s != nil {
ncuo.SetService(*s)
}
return ncuo
}
// SetSettings sets the "settings" field.
func (ncuo *NotificationClientUpdateOne) SetSettings(s string) *NotificationClientUpdateOne {
ncuo.mutation.SetSettings(s)
return ncuo
}
// SetNillableSettings sets the "settings" field if the given value is not nil.
func (ncuo *NotificationClientUpdateOne) SetNillableSettings(s *string) *NotificationClientUpdateOne {
if s != nil {
ncuo.SetSettings(*s)
}
return ncuo
}
// SetEnabled sets the "enabled" field.
func (ncuo *NotificationClientUpdateOne) SetEnabled(b bool) *NotificationClientUpdateOne {
ncuo.mutation.SetEnabled(b)
return ncuo
}
// SetNillableEnabled sets the "enabled" field if the given value is not nil.
func (ncuo *NotificationClientUpdateOne) SetNillableEnabled(b *bool) *NotificationClientUpdateOne {
if b != nil {
ncuo.SetEnabled(*b)
}
return ncuo
}
// Mutation returns the NotificationClientMutation object of the builder.
func (ncuo *NotificationClientUpdateOne) Mutation() *NotificationClientMutation {
return ncuo.mutation
}
// Where appends a list predicates to the NotificationClientUpdate builder.
func (ncuo *NotificationClientUpdateOne) Where(ps ...predicate.NotificationClient) *NotificationClientUpdateOne {
ncuo.mutation.Where(ps...)
return ncuo
}
// Select allows selecting one or more fields (columns) of the returned entity.
// The default is selecting all fields defined in the entity schema.
func (ncuo *NotificationClientUpdateOne) Select(field string, fields ...string) *NotificationClientUpdateOne {
ncuo.fields = append([]string{field}, fields...)
return ncuo
}
// Save executes the query and returns the updated NotificationClient entity.
func (ncuo *NotificationClientUpdateOne) Save(ctx context.Context) (*NotificationClient, error) {
return withHooks(ctx, ncuo.sqlSave, ncuo.mutation, ncuo.hooks)
}
// SaveX is like Save, but panics if an error occurs.
func (ncuo *NotificationClientUpdateOne) SaveX(ctx context.Context) *NotificationClient {
node, err := ncuo.Save(ctx)
if err != nil {
panic(err)
}
return node
}
// Exec executes the query on the entity.
func (ncuo *NotificationClientUpdateOne) Exec(ctx context.Context) error {
_, err := ncuo.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (ncuo *NotificationClientUpdateOne) ExecX(ctx context.Context) {
if err := ncuo.Exec(ctx); err != nil {
panic(err)
}
}
func (ncuo *NotificationClientUpdateOne) sqlSave(ctx context.Context) (_node *NotificationClient, err error) {
_spec := sqlgraph.NewUpdateSpec(notificationclient.Table, notificationclient.Columns, sqlgraph.NewFieldSpec(notificationclient.FieldID, field.TypeInt))
id, ok := ncuo.mutation.ID()
if !ok {
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "NotificationClient.id" for update`)}
}
_spec.Node.ID.Value = id
if fields := ncuo.fields; len(fields) > 0 {
_spec.Node.Columns = make([]string, 0, len(fields))
_spec.Node.Columns = append(_spec.Node.Columns, notificationclient.FieldID)
for _, f := range fields {
if !notificationclient.ValidColumn(f) {
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
}
if f != notificationclient.FieldID {
_spec.Node.Columns = append(_spec.Node.Columns, f)
}
}
}
if ps := ncuo.mutation.predicates; len(ps) > 0 {
_spec.Predicate = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
if value, ok := ncuo.mutation.Name(); ok {
_spec.SetField(notificationclient.FieldName, field.TypeString, value)
}
if value, ok := ncuo.mutation.Service(); ok {
_spec.SetField(notificationclient.FieldService, field.TypeString, value)
}
if value, ok := ncuo.mutation.Settings(); ok {
_spec.SetField(notificationclient.FieldSettings, field.TypeString, value)
}
if value, ok := ncuo.mutation.Enabled(); ok {
_spec.SetField(notificationclient.FieldEnabled, field.TypeBool, value)
}
_node = &NotificationClient{config: ncuo.config}
_spec.Assign = _node.assignValues
_spec.ScanValues = _node.scanValues
if err = sqlgraph.UpdateNode(ctx, ncuo.driver, _spec); err != nil {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{notificationclient.Label}
} else if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
return nil, err
}
ncuo.mutation.done = true
return _node, nil
}

View File

@@ -21,6 +21,9 @@ type Indexers func(*sql.Selector)
// Media is the predicate function for media builders.
type Media func(*sql.Selector)
// NotificationClient is the predicate function for notificationclient builders.
type NotificationClient func(*sql.Selector)
// Settings is the predicate function for settings builders.
type Settings func(*sql.Selector)

View File

@@ -4,9 +4,11 @@ package ent
import (
"polaris/ent/downloadclients"
"polaris/ent/episode"
"polaris/ent/history"
"polaris/ent/indexers"
"polaris/ent/media"
"polaris/ent/notificationclient"
"polaris/ent/schema"
"polaris/ent/storage"
"time"
@@ -48,6 +50,10 @@ func init() {
downloadclients.DefaultTags = downloadclientsDescTags.Default.(string)
episodeFields := schema.Episode{}.Fields()
_ = episodeFields
// episodeDescMonitored is the schema descriptor for monitored field.
episodeDescMonitored := episodeFields[7].Descriptor()
// episode.DefaultMonitored holds the default value on creation for the monitored field.
episode.DefaultMonitored = episodeDescMonitored.Default.(bool)
historyFields := schema.History{}.Fields()
_ = historyFields
// historyDescSize is the schema descriptor for size field.
@@ -60,6 +66,18 @@ func init() {
indexersDescEnableRss := indexersFields[3].Descriptor()
// indexers.DefaultEnableRss holds the default value on creation for the enable_rss field.
indexers.DefaultEnableRss = indexersDescEnableRss.Default.(bool)
// indexersDescPriority is the schema descriptor for priority field.
indexersDescPriority := indexersFields[4].Descriptor()
// indexers.DefaultPriority holds the default value on creation for the priority field.
indexers.DefaultPriority = indexersDescPriority.Default.(int)
// indexersDescSeedRatio is the schema descriptor for seed_ratio field.
indexersDescSeedRatio := indexersFields[5].Descriptor()
// indexers.DefaultSeedRatio holds the default value on creation for the seed_ratio field.
indexers.DefaultSeedRatio = indexersDescSeedRatio.Default.(float32)
// indexersDescDisabled is the schema descriptor for disabled field.
indexersDescDisabled := indexersFields[6].Descriptor()
// indexers.DefaultDisabled holds the default value on creation for the disabled field.
indexers.DefaultDisabled = indexersDescDisabled.Default.(bool)
mediaFields := schema.Media{}.Fields()
_ = mediaFields
// mediaDescCreatedAt is the schema descriptor for created_at field.
@@ -70,14 +88,24 @@ func init() {
mediaDescAirDate := mediaFields[8].Descriptor()
// media.DefaultAirDate holds the default value on creation for the air_date field.
media.DefaultAirDate = mediaDescAirDate.Default.(string)
// mediaDescDownloadHistoryEpisodes is the schema descriptor for download_history_episodes field.
mediaDescDownloadHistoryEpisodes := mediaFields[12].Descriptor()
// media.DefaultDownloadHistoryEpisodes holds the default value on creation for the download_history_episodes field.
media.DefaultDownloadHistoryEpisodes = mediaDescDownloadHistoryEpisodes.Default.(bool)
notificationclientFields := schema.NotificationClient{}.Fields()
_ = notificationclientFields
// notificationclientDescEnabled is the schema descriptor for enabled field.
notificationclientDescEnabled := notificationclientFields[3].Descriptor()
// notificationclient.DefaultEnabled holds the default value on creation for the enabled field.
notificationclient.DefaultEnabled = notificationclientDescEnabled.Default.(bool)
storageFields := schema.Storage{}.Fields()
_ = storageFields
// storageDescDeleted is the schema descriptor for deleted field.
storageDescDeleted := storageFields[3].Descriptor()
storageDescDeleted := storageFields[5].Descriptor()
// storage.DefaultDeleted holds the default value on creation for the deleted field.
storage.DefaultDeleted = storageDescDeleted.Default.(bool)
// storageDescDefault is the schema descriptor for default field.
storageDescDefault := storageFields[4].Descriptor()
storageDescDefault := storageFields[6].Descriptor()
// storage.DefaultDefault holds the default value on creation for the default field.
storage.DefaultDefault = storageDescDefault.Default.(bool)
}

View File

@@ -21,7 +21,7 @@ func (Episode) Fields() []ent.Field {
field.String("overview"),
field.String("air_date"),
field.Enum("status").Values("missing", "downloading", "downloaded").Default("missing"),
field.String("file_in_storage").Optional(),
field.Bool("monitored").Default(false).StructTag("json:\"monitored\""), //whether this episode is monitored
}
}

View File

@@ -19,6 +19,8 @@ func (History) Fields() []ent.Field {
field.Time("date"),
field.String("target_dir"),
field.Int("size").Default(0),
field.Int("download_client_id").Optional(),
field.Int("indexer_id").Optional(),
field.Enum("status").Values("running", "success", "fail", "uploading"),
field.String("saved").Optional(),
}

View File

@@ -17,7 +17,9 @@ func (Indexers) Fields() []ent.Field {
field.String("implementation"),
field.String("settings"),
field.Bool("enable_rss").Default(true),
field.Int("priority"),
field.Int("priority").Default(50),
field.Float32("seed_ratio").Optional().Default(0).Comment("minimal seed ratio requied, before removing torrent"),
field.Bool("disabled").Optional().Default(false),
}
}

View File

@@ -25,9 +25,11 @@ func (Media) Fields() []ent.Field {
field.String("overview"),
field.Time("created_at").Default(time.Now()),
field.String("air_date").Default(""),
field.Enum("resolution").Values("720p", "1080p", "4k").Default("1080p"),
field.Enum("resolution").Values("720p", "1080p", "2160p").Default("1080p"),
field.Int("storage_id").Optional(),
field.String("target_dir").Optional(),
field.Bool("download_history_episodes").Optional().Default(false).Comment("tv series only"),
field.JSON("limiter", &MediaLimiter{}).Optional(),
}
}
@@ -37,3 +39,8 @@ func (Media) Edges() []ent.Edge {
edge.To("episodes", Episode.Type),
}
}
type MediaLimiter struct {
SizeMin int `json:"size_min"`
SizeMax int `json:"size_max"`
}

View File

@@ -0,0 +1,26 @@
package schema
import (
"entgo.io/ent"
"entgo.io/ent/schema/field"
)
// NotificationClient holds the schema definition for the NotificationClient entity.
type NotificationClient struct {
ent.Schema
}
// Fields of the NotificationClient.
func (NotificationClient) Fields() []ent.Field {
return []ent.Field{
field.String("name"),
field.String("service"),
field.String("settings"),
field.Bool("enabled").Default(true),
}
}
// Edges of the NotificationClient.
func (NotificationClient) Edges() []ent.Edge {
return nil
}

View File

@@ -15,6 +15,8 @@ func (Storage) Fields() []ent.Field {
return []ent.Field{
field.String("name").Unique(),
field.Enum("implementation").Values("webdav", "local"),
field.String("tv_path").Optional(),
field.String("movie_path").Optional(),
field.String("settings").Optional(),
field.Bool("deleted").Default(false),
field.Bool("default").Default(false),

View File

@@ -20,6 +20,10 @@ type Storage struct {
Name string `json:"name,omitempty"`
// Implementation holds the value of the "implementation" field.
Implementation storage.Implementation `json:"implementation,omitempty"`
// TvPath holds the value of the "tv_path" field.
TvPath string `json:"tv_path,omitempty"`
// MoviePath holds the value of the "movie_path" field.
MoviePath string `json:"movie_path,omitempty"`
// Settings holds the value of the "settings" field.
Settings string `json:"settings,omitempty"`
// Deleted holds the value of the "deleted" field.
@@ -38,7 +42,7 @@ func (*Storage) scanValues(columns []string) ([]any, error) {
values[i] = new(sql.NullBool)
case storage.FieldID:
values[i] = new(sql.NullInt64)
case storage.FieldName, storage.FieldImplementation, storage.FieldSettings:
case storage.FieldName, storage.FieldImplementation, storage.FieldTvPath, storage.FieldMoviePath, storage.FieldSettings:
values[i] = new(sql.NullString)
default:
values[i] = new(sql.UnknownType)
@@ -73,6 +77,18 @@ func (s *Storage) assignValues(columns []string, values []any) error {
} else if value.Valid {
s.Implementation = storage.Implementation(value.String)
}
case storage.FieldTvPath:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field tv_path", values[i])
} else if value.Valid {
s.TvPath = value.String
}
case storage.FieldMoviePath:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field movie_path", values[i])
} else if value.Valid {
s.MoviePath = value.String
}
case storage.FieldSettings:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field settings", values[i])
@@ -133,6 +149,12 @@ func (s *Storage) String() string {
builder.WriteString("implementation=")
builder.WriteString(fmt.Sprintf("%v", s.Implementation))
builder.WriteString(", ")
builder.WriteString("tv_path=")
builder.WriteString(s.TvPath)
builder.WriteString(", ")
builder.WriteString("movie_path=")
builder.WriteString(s.MoviePath)
builder.WriteString(", ")
builder.WriteString("settings=")
builder.WriteString(s.Settings)
builder.WriteString(", ")

View File

@@ -17,6 +17,10 @@ const (
FieldName = "name"
// FieldImplementation holds the string denoting the implementation field in the database.
FieldImplementation = "implementation"
// FieldTvPath holds the string denoting the tv_path field in the database.
FieldTvPath = "tv_path"
// FieldMoviePath holds the string denoting the movie_path field in the database.
FieldMoviePath = "movie_path"
// FieldSettings holds the string denoting the settings field in the database.
FieldSettings = "settings"
// FieldDeleted holds the string denoting the deleted field in the database.
@@ -32,6 +36,8 @@ var Columns = []string{
FieldID,
FieldName,
FieldImplementation,
FieldTvPath,
FieldMoviePath,
FieldSettings,
FieldDeleted,
FieldDefault,
@@ -95,6 +101,16 @@ func ByImplementation(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldImplementation, opts...).ToFunc()
}
// ByTvPath orders the results by the tv_path field.
func ByTvPath(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldTvPath, opts...).ToFunc()
}
// ByMoviePath orders the results by the movie_path field.
func ByMoviePath(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldMoviePath, opts...).ToFunc()
}
// BySettings orders the results by the settings field.
func BySettings(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldSettings, opts...).ToFunc()

View File

@@ -58,6 +58,16 @@ func Name(v string) predicate.Storage {
return predicate.Storage(sql.FieldEQ(FieldName, v))
}
// TvPath applies equality check predicate on the "tv_path" field. It's identical to TvPathEQ.
func TvPath(v string) predicate.Storage {
return predicate.Storage(sql.FieldEQ(FieldTvPath, v))
}
// MoviePath applies equality check predicate on the "movie_path" field. It's identical to MoviePathEQ.
func MoviePath(v string) predicate.Storage {
return predicate.Storage(sql.FieldEQ(FieldMoviePath, v))
}
// Settings applies equality check predicate on the "settings" field. It's identical to SettingsEQ.
func Settings(v string) predicate.Storage {
return predicate.Storage(sql.FieldEQ(FieldSettings, v))
@@ -158,6 +168,156 @@ func ImplementationNotIn(vs ...Implementation) predicate.Storage {
return predicate.Storage(sql.FieldNotIn(FieldImplementation, vs...))
}
// TvPathEQ applies the EQ predicate on the "tv_path" field.
func TvPathEQ(v string) predicate.Storage {
return predicate.Storage(sql.FieldEQ(FieldTvPath, v))
}
// TvPathNEQ applies the NEQ predicate on the "tv_path" field.
func TvPathNEQ(v string) predicate.Storage {
return predicate.Storage(sql.FieldNEQ(FieldTvPath, v))
}
// TvPathIn applies the In predicate on the "tv_path" field.
func TvPathIn(vs ...string) predicate.Storage {
return predicate.Storage(sql.FieldIn(FieldTvPath, vs...))
}
// TvPathNotIn applies the NotIn predicate on the "tv_path" field.
func TvPathNotIn(vs ...string) predicate.Storage {
return predicate.Storage(sql.FieldNotIn(FieldTvPath, vs...))
}
// TvPathGT applies the GT predicate on the "tv_path" field.
func TvPathGT(v string) predicate.Storage {
return predicate.Storage(sql.FieldGT(FieldTvPath, v))
}
// TvPathGTE applies the GTE predicate on the "tv_path" field.
func TvPathGTE(v string) predicate.Storage {
return predicate.Storage(sql.FieldGTE(FieldTvPath, v))
}
// TvPathLT applies the LT predicate on the "tv_path" field.
func TvPathLT(v string) predicate.Storage {
return predicate.Storage(sql.FieldLT(FieldTvPath, v))
}
// TvPathLTE applies the LTE predicate on the "tv_path" field.
func TvPathLTE(v string) predicate.Storage {
return predicate.Storage(sql.FieldLTE(FieldTvPath, v))
}
// TvPathContains applies the Contains predicate on the "tv_path" field.
func TvPathContains(v string) predicate.Storage {
return predicate.Storage(sql.FieldContains(FieldTvPath, v))
}
// TvPathHasPrefix applies the HasPrefix predicate on the "tv_path" field.
func TvPathHasPrefix(v string) predicate.Storage {
return predicate.Storage(sql.FieldHasPrefix(FieldTvPath, v))
}
// TvPathHasSuffix applies the HasSuffix predicate on the "tv_path" field.
func TvPathHasSuffix(v string) predicate.Storage {
return predicate.Storage(sql.FieldHasSuffix(FieldTvPath, v))
}
// TvPathIsNil applies the IsNil predicate on the "tv_path" field.
func TvPathIsNil() predicate.Storage {
return predicate.Storage(sql.FieldIsNull(FieldTvPath))
}
// TvPathNotNil applies the NotNil predicate on the "tv_path" field.
func TvPathNotNil() predicate.Storage {
return predicate.Storage(sql.FieldNotNull(FieldTvPath))
}
// TvPathEqualFold applies the EqualFold predicate on the "tv_path" field.
func TvPathEqualFold(v string) predicate.Storage {
return predicate.Storage(sql.FieldEqualFold(FieldTvPath, v))
}
// TvPathContainsFold applies the ContainsFold predicate on the "tv_path" field.
func TvPathContainsFold(v string) predicate.Storage {
return predicate.Storage(sql.FieldContainsFold(FieldTvPath, v))
}
// MoviePathEQ applies the EQ predicate on the "movie_path" field.
func MoviePathEQ(v string) predicate.Storage {
return predicate.Storage(sql.FieldEQ(FieldMoviePath, v))
}
// MoviePathNEQ applies the NEQ predicate on the "movie_path" field.
func MoviePathNEQ(v string) predicate.Storage {
return predicate.Storage(sql.FieldNEQ(FieldMoviePath, v))
}
// MoviePathIn applies the In predicate on the "movie_path" field.
func MoviePathIn(vs ...string) predicate.Storage {
return predicate.Storage(sql.FieldIn(FieldMoviePath, vs...))
}
// MoviePathNotIn applies the NotIn predicate on the "movie_path" field.
func MoviePathNotIn(vs ...string) predicate.Storage {
return predicate.Storage(sql.FieldNotIn(FieldMoviePath, vs...))
}
// MoviePathGT applies the GT predicate on the "movie_path" field.
func MoviePathGT(v string) predicate.Storage {
return predicate.Storage(sql.FieldGT(FieldMoviePath, v))
}
// MoviePathGTE applies the GTE predicate on the "movie_path" field.
func MoviePathGTE(v string) predicate.Storage {
return predicate.Storage(sql.FieldGTE(FieldMoviePath, v))
}
// MoviePathLT applies the LT predicate on the "movie_path" field.
func MoviePathLT(v string) predicate.Storage {
return predicate.Storage(sql.FieldLT(FieldMoviePath, v))
}
// MoviePathLTE applies the LTE predicate on the "movie_path" field.
func MoviePathLTE(v string) predicate.Storage {
return predicate.Storage(sql.FieldLTE(FieldMoviePath, v))
}
// MoviePathContains applies the Contains predicate on the "movie_path" field.
func MoviePathContains(v string) predicate.Storage {
return predicate.Storage(sql.FieldContains(FieldMoviePath, v))
}
// MoviePathHasPrefix applies the HasPrefix predicate on the "movie_path" field.
func MoviePathHasPrefix(v string) predicate.Storage {
return predicate.Storage(sql.FieldHasPrefix(FieldMoviePath, v))
}
// MoviePathHasSuffix applies the HasSuffix predicate on the "movie_path" field.
func MoviePathHasSuffix(v string) predicate.Storage {
return predicate.Storage(sql.FieldHasSuffix(FieldMoviePath, v))
}
// MoviePathIsNil applies the IsNil predicate on the "movie_path" field.
func MoviePathIsNil() predicate.Storage {
return predicate.Storage(sql.FieldIsNull(FieldMoviePath))
}
// MoviePathNotNil applies the NotNil predicate on the "movie_path" field.
func MoviePathNotNil() predicate.Storage {
return predicate.Storage(sql.FieldNotNull(FieldMoviePath))
}
// MoviePathEqualFold applies the EqualFold predicate on the "movie_path" field.
func MoviePathEqualFold(v string) predicate.Storage {
return predicate.Storage(sql.FieldEqualFold(FieldMoviePath, v))
}
// MoviePathContainsFold applies the ContainsFold predicate on the "movie_path" field.
func MoviePathContainsFold(v string) predicate.Storage {
return predicate.Storage(sql.FieldContainsFold(FieldMoviePath, v))
}
// SettingsEQ applies the EQ predicate on the "settings" field.
func SettingsEQ(v string) predicate.Storage {
return predicate.Storage(sql.FieldEQ(FieldSettings, v))

View File

@@ -31,6 +31,34 @@ func (sc *StorageCreate) SetImplementation(s storage.Implementation) *StorageCre
return sc
}
// SetTvPath sets the "tv_path" field.
func (sc *StorageCreate) SetTvPath(s string) *StorageCreate {
sc.mutation.SetTvPath(s)
return sc
}
// SetNillableTvPath sets the "tv_path" field if the given value is not nil.
func (sc *StorageCreate) SetNillableTvPath(s *string) *StorageCreate {
if s != nil {
sc.SetTvPath(*s)
}
return sc
}
// SetMoviePath sets the "movie_path" field.
func (sc *StorageCreate) SetMoviePath(s string) *StorageCreate {
sc.mutation.SetMoviePath(s)
return sc
}
// SetNillableMoviePath sets the "movie_path" field if the given value is not nil.
func (sc *StorageCreate) SetNillableMoviePath(s *string) *StorageCreate {
if s != nil {
sc.SetMoviePath(*s)
}
return sc
}
// SetSettings sets the "settings" field.
func (sc *StorageCreate) SetSettings(s string) *StorageCreate {
sc.mutation.SetSettings(s)
@@ -171,6 +199,14 @@ func (sc *StorageCreate) createSpec() (*Storage, *sqlgraph.CreateSpec) {
_spec.SetField(storage.FieldImplementation, field.TypeEnum, value)
_node.Implementation = value
}
if value, ok := sc.mutation.TvPath(); ok {
_spec.SetField(storage.FieldTvPath, field.TypeString, value)
_node.TvPath = value
}
if value, ok := sc.mutation.MoviePath(); ok {
_spec.SetField(storage.FieldMoviePath, field.TypeString, value)
_node.MoviePath = value
}
if value, ok := sc.mutation.Settings(); ok {
_spec.SetField(storage.FieldSettings, field.TypeString, value)
_node.Settings = value

View File

@@ -55,6 +55,46 @@ func (su *StorageUpdate) SetNillableImplementation(s *storage.Implementation) *S
return su
}
// SetTvPath sets the "tv_path" field.
func (su *StorageUpdate) SetTvPath(s string) *StorageUpdate {
su.mutation.SetTvPath(s)
return su
}
// SetNillableTvPath sets the "tv_path" field if the given value is not nil.
func (su *StorageUpdate) SetNillableTvPath(s *string) *StorageUpdate {
if s != nil {
su.SetTvPath(*s)
}
return su
}
// ClearTvPath clears the value of the "tv_path" field.
func (su *StorageUpdate) ClearTvPath() *StorageUpdate {
su.mutation.ClearTvPath()
return su
}
// SetMoviePath sets the "movie_path" field.
func (su *StorageUpdate) SetMoviePath(s string) *StorageUpdate {
su.mutation.SetMoviePath(s)
return su
}
// SetNillableMoviePath sets the "movie_path" field if the given value is not nil.
func (su *StorageUpdate) SetNillableMoviePath(s *string) *StorageUpdate {
if s != nil {
su.SetMoviePath(*s)
}
return su
}
// ClearMoviePath clears the value of the "movie_path" field.
func (su *StorageUpdate) ClearMoviePath() *StorageUpdate {
su.mutation.ClearMoviePath()
return su
}
// SetSettings sets the "settings" field.
func (su *StorageUpdate) SetSettings(s string) *StorageUpdate {
su.mutation.SetSettings(s)
@@ -163,6 +203,18 @@ func (su *StorageUpdate) sqlSave(ctx context.Context) (n int, err error) {
if value, ok := su.mutation.Implementation(); ok {
_spec.SetField(storage.FieldImplementation, field.TypeEnum, value)
}
if value, ok := su.mutation.TvPath(); ok {
_spec.SetField(storage.FieldTvPath, field.TypeString, value)
}
if su.mutation.TvPathCleared() {
_spec.ClearField(storage.FieldTvPath, field.TypeString)
}
if value, ok := su.mutation.MoviePath(); ok {
_spec.SetField(storage.FieldMoviePath, field.TypeString, value)
}
if su.mutation.MoviePathCleared() {
_spec.ClearField(storage.FieldMoviePath, field.TypeString)
}
if value, ok := su.mutation.Settings(); ok {
_spec.SetField(storage.FieldSettings, field.TypeString, value)
}
@@ -223,6 +275,46 @@ func (suo *StorageUpdateOne) SetNillableImplementation(s *storage.Implementation
return suo
}
// SetTvPath sets the "tv_path" field.
func (suo *StorageUpdateOne) SetTvPath(s string) *StorageUpdateOne {
suo.mutation.SetTvPath(s)
return suo
}
// SetNillableTvPath sets the "tv_path" field if the given value is not nil.
func (suo *StorageUpdateOne) SetNillableTvPath(s *string) *StorageUpdateOne {
if s != nil {
suo.SetTvPath(*s)
}
return suo
}
// ClearTvPath clears the value of the "tv_path" field.
func (suo *StorageUpdateOne) ClearTvPath() *StorageUpdateOne {
suo.mutation.ClearTvPath()
return suo
}
// SetMoviePath sets the "movie_path" field.
func (suo *StorageUpdateOne) SetMoviePath(s string) *StorageUpdateOne {
suo.mutation.SetMoviePath(s)
return suo
}
// SetNillableMoviePath sets the "movie_path" field if the given value is not nil.
func (suo *StorageUpdateOne) SetNillableMoviePath(s *string) *StorageUpdateOne {
if s != nil {
suo.SetMoviePath(*s)
}
return suo
}
// ClearMoviePath clears the value of the "movie_path" field.
func (suo *StorageUpdateOne) ClearMoviePath() *StorageUpdateOne {
suo.mutation.ClearMoviePath()
return suo
}
// SetSettings sets the "settings" field.
func (suo *StorageUpdateOne) SetSettings(s string) *StorageUpdateOne {
suo.mutation.SetSettings(s)
@@ -361,6 +453,18 @@ func (suo *StorageUpdateOne) sqlSave(ctx context.Context) (_node *Storage, err e
if value, ok := suo.mutation.Implementation(); ok {
_spec.SetField(storage.FieldImplementation, field.TypeEnum, value)
}
if value, ok := suo.mutation.TvPath(); ok {
_spec.SetField(storage.FieldTvPath, field.TypeString, value)
}
if suo.mutation.TvPathCleared() {
_spec.ClearField(storage.FieldTvPath, field.TypeString)
}
if value, ok := suo.mutation.MoviePath(); ok {
_spec.SetField(storage.FieldMoviePath, field.TypeString, value)
}
if suo.mutation.MoviePathCleared() {
_spec.ClearField(storage.FieldMoviePath, field.TypeString)
}
if value, ok := suo.mutation.Settings(); ok {
_spec.SetField(storage.FieldSettings, field.TypeString, value)
}

View File

@@ -22,6 +22,8 @@ type Tx struct {
Indexers *IndexersClient
// Media is the client for interacting with the Media builders.
Media *MediaClient
// NotificationClient is the client for interacting with the NotificationClient builders.
NotificationClient *NotificationClientClient
// Settings is the client for interacting with the Settings builders.
Settings *SettingsClient
// Storage is the client for interacting with the Storage builders.
@@ -162,6 +164,7 @@ func (tx *Tx) init() {
tx.History = NewHistoryClient(tx.config)
tx.Indexers = NewIndexersClient(tx.config)
tx.Media = NewMediaClient(tx.config)
tx.NotificationClient = NewNotificationClientClient(tx.config)
tx.Settings = NewSettingsClient(tx.config)
tx.Storage = NewStorageClient(tx.config)
}

38
go.mod
View File

@@ -8,10 +8,29 @@ require (
github.com/mattn/go-sqlite3 v1.14.16
github.com/robfig/cron v1.2.0
go.uber.org/zap v1.27.0
golang.org/x/net v0.25.0
golang.org/x/net v0.27.0
)
require github.com/adrg/strutil v0.3.1 // indirect
require (
github.com/adrg/strutil v0.3.1
github.com/gin-contrib/zap v1.1.3
github.com/nikoksr/notify v1.0.0
)
require (
github.com/BurntSushi/toml v1.4.0 // indirect
github.com/blinkbean/dingtalk v1.1.3 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/go-telegram-bot-api/telegram-bot-api v4.6.4+incompatible // indirect
github.com/gregdel/pushover v1.3.1 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/stretchr/objx v0.5.2 // indirect
github.com/stretchr/testify v1.9.0 // indirect
github.com/technoweenie/multipartstreamer v1.0.1 // indirect
golang.org/x/sync v0.7.0 // indirect
gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
)
require (
ariga.io/atlas v0.19.1-0.20240203083654-5948b60a8e43 // indirect
@@ -31,7 +50,7 @@ require (
github.com/go-playground/validator/v10 v10.20.0 // indirect
github.com/goccy/go-json v0.10.2 // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/google/uuid v1.4.0 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/hashicorp/hcl/v2 v2.13.0 // indirect
@@ -55,12 +74,12 @@ require (
github.com/ugorji/go/codec v1.2.12 // indirect
github.com/zclconf/go-cty v1.8.0 // indirect
golang.org/x/arch v0.8.0 // indirect
golang.org/x/crypto v0.23.0
golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842 // indirect
golang.org/x/mod v0.17.0 // indirect
golang.org/x/sys v0.21.0 // indirect
golang.org/x/crypto v0.25.0
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56
golang.org/x/mod v0.19.0 // indirect
golang.org/x/sys v0.22.0
golang.org/x/text v0.16.0 // indirect
google.golang.org/protobuf v1.34.1 // indirect
google.golang.org/protobuf v1.34.2 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
@@ -72,7 +91,8 @@ require (
github.com/json-iterator/go v1.1.12 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/natefinch/lumberjack v2.0.0+incompatible
github.com/pkg/errors v0.9.1
github.com/spf13/viper v1.19.0
go.uber.org/multierr v1.10.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
)

57
go.sum
View File

@@ -2,6 +2,8 @@ ariga.io/atlas v0.19.1-0.20240203083654-5948b60a8e43 h1:GwdJbXydHCYPedeeLt4x/lrl
ariga.io/atlas v0.19.1-0.20240203083654-5948b60a8e43/go.mod h1:uj3pm+hUTVN/X5yfdBexHlZv+1Xu5u5ZbZx7+CDavNU=
entgo.io/ent v0.13.1 h1:uD8QwN1h6SNphdCCzmkMN3feSUzNnVvV/WIkHKMbzOE=
entgo.io/ent v0.13.1/go.mod h1:qCEmo+biw3ccBn9OyL4ZK5dfpwg++l1Gxwac5B1206A=
github.com/BurntSushi/toml v1.4.0 h1:kuoIxZQy2WRRk1pttg9asf+WVv6tWQuBNVmK8+nqPr0=
github.com/BurntSushi/toml v1.4.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho=
github.com/DATA-DOG/go-sqlmock v1.5.0 h1:Shsta01QNfFxHCfpW6YH2STWB0MudeXXEWMr20OEh60=
github.com/DATA-DOG/go-sqlmock v1.5.0/go.mod h1:f/Ixk793poVmq4qj/V1dPUg2JEAKC73Q5eFN3EC/SaM=
github.com/adrg/strutil v0.3.1 h1:OLvSS7CSJO8lBii4YmBt8jiK9QOtB9CzCzwl4Ic/Fz4=
@@ -10,6 +12,8 @@ github.com/agext/levenshtein v1.2.1 h1:QmvMAjj2aEICytGiWzmxoE0x2KZvE0fvmqMOfy2tj
github.com/agext/levenshtein v1.2.1/go.mod h1:JEDfjyjHDjOF/1e4FlBE/PkbqA9OfWu2ki2W0IB5558=
github.com/apparentlymart/go-textseg/v13 v13.0.0 h1:Y+KvPE1NYz0xl601PVImeQfFyEy6iT90AvPUL1NNfNw=
github.com/apparentlymart/go-textseg/v13 v13.0.0/go.mod h1:ZK2fH7c4NqDTLtiYLvIkEghdlcqw7yxLeM89kiTRPUo=
github.com/blinkbean/dingtalk v1.1.3 h1:MbidFZYom7DTFHD/YIs+eaI7kRy52kmWE/sy0xjo6E4=
github.com/blinkbean/dingtalk v1.1.3/go.mod h1:9BaLuGSBqY3vT5hstValh48DbsKO7vaHaJnG9pXwbto=
github.com/bytedance/sonic v1.11.6 h1:oUp34TzMlL+OY1OUWxHqsdkgC/Zfc85zGqw9siXjrc0=
github.com/bytedance/sonic v1.11.6/go.mod h1:LysEHSvpvDySVdC2f87zGWf6CIKJcAvqab1ZaiQtds4=
github.com/bytedance/sonic/loader v0.1.1 h1:c+e5Pt1k/cy5wMveRDyk2X4B9hF4g7an8N3zCYjJFNM=
@@ -34,6 +38,8 @@ github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE
github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI=
github.com/gin-contrib/static v1.1.2 h1:c3kT4bFkUJn2aoRU3s6XnMjJT8J6nNWJkR0NglqmlZ4=
github.com/gin-contrib/static v1.1.2/go.mod h1:Fw90ozjHCmZBWbgrsqrDvO28YbhKEKzKp8GixhR4yLw=
github.com/gin-contrib/zap v1.1.3 h1:9e/U9fYd4/OBfmSEBs5hHZq114uACn7bpuzvCkcJySA=
github.com/gin-contrib/zap v1.1.3/go.mod h1:+BD/6NYZKJyUpqVoJEvgeq9GLz8pINEQvak9LHNOTSE=
github.com/gin-gonic/gin v1.10.0 h1:nTuyha1TYqgedzytsKYqna+DfLos46nTv2ygFy86HFU=
github.com/gin-gonic/gin v1.10.0/go.mod h1:4PMNQiOhvDRa013RKVbsiNwoyezlm2rm0uX/T7kzp5Y=
github.com/go-openapi/inflect v0.19.0 h1:9jCH9scKIbHeV9m12SmPilScz6krDxKRasNNSNPXu/4=
@@ -46,6 +52,8 @@ github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJn
github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY=
github.com/go-playground/validator/v10 v10.20.0 h1:K9ISHbSaI0lyB2eWMPJo+kOS/FBExVwjEviJTixqxL8=
github.com/go-playground/validator/v10 v10.20.0/go.mod h1:dbuPbCMFw/DrkbEynArYaCwl3amGuJotoKCe95atGMM=
github.com/go-telegram-bot-api/telegram-bot-api v4.6.4+incompatible h1:2cauKuaELYAEARXRkq2LrJ0yDDv1rW7+wrTEdVL3uaU=
github.com/go-telegram-bot-api/telegram-bot-api v4.6.4+incompatible/go.mod h1:qf9acutJ8cwBUhm1bqgz6Bei9/C/c93FPDljKWwsOgM=
github.com/go-test/deep v1.0.3 h1:ZrJSEWsXzPOxaZnFteGEfooLba+ju3FYIbOrS+rQd68=
github.com/go-test/deep v1.0.3/go.mod h1:wGDj63lr65AM2AQyKZd/NYHGb0R+1RLqB8NKt3aSFNA=
github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU=
@@ -58,8 +66,10 @@ github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMyw
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/google/uuid v1.4.0 h1:MtMxsa51/r9yyhkyLsVeVt0B+BGQZzpQiTQ4eHZ8bc4=
github.com/google/uuid v1.4.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/gregdel/pushover v1.3.1 h1:4bMLITOZ15+Zpi6qqoGqOPuVHCwSUvMCgVnN5Xhilfo=
github.com/gregdel/pushover v1.3.1/go.mod h1:EcaO66Nn1StkpEm1iKtBTV3d2A16SoMsVER1PthX7to=
github.com/hashicorp/go-cleanhttp v0.5.2 h1:035FKYIWjmULyFRBKPs8TBQoi0x6d9G4xc9neXJWAZQ=
github.com/hashicorp/go-cleanhttp v0.5.2/go.mod h1:kO/YDlP8L1346E6Sodw+PrpBSV4/SoxCXGY6BqNFT48=
github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4=
@@ -104,6 +114,10 @@ github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
github.com/natefinch/lumberjack v2.0.0+incompatible h1:4QJd3OLAMgj7ph+yZTuX13Ld4UpgHp07nNdFX7mqFfM=
github.com/natefinch/lumberjack v2.0.0+incompatible/go.mod h1:Wi9p2TTF5DG5oU+6YfsmYQpsTIOm0B1VNzQg9Mw6nPk=
github.com/nikoksr/notify v1.0.0 h1:qe9/6FRsWdxBgQgWcpvQ0sv8LRGJZDpRB4TkL2uNdO8=
github.com/nikoksr/notify v1.0.0/go.mod h1:hPaaDt30d6LAA7/5nb0e48Bp/MctDfycCSs8VEgN29I=
github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec=
github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY=
github.com/pelletier/go-toml/v2 v2.2.2 h1:aYUidT7k73Pcl9nb2gScu7NSrKCSHIDE89b3+6Wq+LM=
@@ -138,6 +152,7 @@ github.com/spf13/viper v1.19.0/go.mod h1:GQUN9bilAbhU/jgc1bKs99f/suXKeUMct8Adx5+
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY=
github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
@@ -149,6 +164,8 @@ github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsT
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8=
github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU=
github.com/technoweenie/multipartstreamer v1.0.1 h1:XRztA5MXiR1TIRHxH2uNxXxaIkKQDeX7m2XsSOlQEnM=
github.com/technoweenie/multipartstreamer v1.0.1/go.mod h1:jNVxdtShOxzAsukZwTSw6MDx5eUJoiEBsSvzDU9uzog=
github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI=
github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08=
github.com/ugorji/go/codec v1.2.12 h1:9LC83zGrHhuUA9l16C9AHXAqEV/2wBQ4nkvumAE65EE=
@@ -159,48 +176,52 @@ github.com/zclconf/go-cty v1.8.0 h1:s4AvqaeQzJIu3ndv4gVIhplVD0krU+bgrcLSVUnaWuA=
github.com/zclconf/go-cty v1.8.0/go.mod h1:vVKLxnk3puL4qRAv72AO+W99LUD4da90g3uUAzyuvAk=
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
go.uber.org/multierr v1.10.0 h1:S0h4aNzvfcFsC3dRF1jLoaov7oRaKqRGC/pUEJ2yvPQ=
go.uber.org/multierr v1.10.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y=
go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0=
go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y=
go.uber.org/zap v1.27.0 h1:aJMhYGrd5QSmlpLMr2MftRKl7t8J8PTZPA732ud/XR8=
go.uber.org/zap v1.27.0/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E=
golang.org/x/arch v0.0.0-20210923205945-b76863e36670/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8=
golang.org/x/arch v0.8.0 h1:3wRIsP3pM4yUptoR96otTUOXI367OS0+c9eeRi9doIc=
golang.org/x/arch v0.8.0/go.mod h1:FEVrYAQjsQXMVJ1nsMoVVXPZg6p2JE2mx8psSWTDQys=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.23.0 h1:dIJU/v2J8Mdglj/8rJ6UUOM3Zc9zLZxVZwwxMooUSAI=
golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v8=
golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842 h1:vr/HnozRka3pE4EsMEg1lgkXJkTFJCVUX+S/ZT6wYzM=
golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842/go.mod h1:XtvwrStGgqGPLc4cjQfWqZHG1YFdYs6swckp8vpsjnc=
golang.org/x/mod v0.17.0 h1:zY54UmvipHiNd+pm+m0x9KhZ9hl1/7QNMyxXbc6ICqA=
golang.org/x/mod v0.17.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
golang.org/x/crypto v0.25.0 h1:ypSNr+bnYL2YhwoMt2zPxHFmbAN1KZs/njMG3hxUp30=
golang.org/x/crypto v0.25.0/go.mod h1:T+wALwcMOSE0kXgUAnPAHqTLW+XHgcELELW8VaDgm/M=
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56 h1:2dVuKD2vS7b0QIHQbpyTISPd0LeHDbnYEryqj5Q1ug8=
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56/go.mod h1:M4RDyNAINzryxdtnbRXRL/OHtkFuWGRjvuhBJpk2IlY=
golang.org/x/mod v0.19.0 h1:fEdghXQSo20giMthA7cd28ZC+jts4amQ3YMXiP5oMQ8=
golang.org/x/mod v0.19.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks=
golang.org/x/net v0.0.0-20200301022130-244492dfa37a/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.25.0 h1:d/OCCoBEUq33pjydKrGQhw7IlUPI2Oylr+8qLx49kac=
golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM=
golang.org/x/net v0.27.0 h1:5K3Njcw06/l2y9vpGCSdcxWOYHOUk3dVNGDXN+FvAys=
golang.org/x/net v0.27.0/go.mod h1:dDi0PyhWNoiUOrAS8uXv/vnScO4wnHQO4mj9fn/RytE=
golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M=
golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.21.0 h1:rF+pYz3DAGSQAxAu1CbC7catZg4ebC4UIeIhKxBZvws=
golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.22.0 h1:RI27ohtqKCnwULzJLqkv897zojh5/DwS/ENaMzUOaWI=
golang.org/x/sys v0.22.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4=
golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d h1:vU5i/LfpvrRCpgM/VPfJLg5KjxD3E+hfT1SH+d9zLwg=
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d/go.mod h1:aiJjzUbINMkxbQROHiO6hDPo2LHcIPhhQsa9DLh0yGk=
golang.org/x/tools v0.23.0 h1:SGsXPZ+2l4JsgaCKkx+FQ9YZ5XEtA1GZYuoDjenLjvg=
golang.org/x/tools v0.23.0/go.mod h1:pnu6ufv6vQkll6szChhK3C3L/ruaIv5eBeztNG8wtsI=
google.golang.org/appengine v1.6.5/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc=
google.golang.org/protobuf v1.34.1 h1:9ddQBjfCyZPOHPUiPxpYESBLc+T8P3E+Vo4IbKZgFWg=
google.golang.org/protobuf v1.34.1/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg=
google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
gopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA=
gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
gopkg.in/natefinch/lumberjack.v2 v2.2.1 h1:bBRl1b0OH9s/DuPhuXpNl+VtCaJXFZ5/uEFST95x9zc=
gopkg.in/natefinch/lumberjack.v2 v2.2.1/go.mod h1:YD8tP3GAjkrDg1eZH7EGmyESg/lsYskCTPBJVb9jqSc=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

View File

@@ -1,18 +1,62 @@
package log
import (
"os"
"path/filepath"
"strings"
"github.com/natefinch/lumberjack"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
)
var sugar *zap.SugaredLogger
var atom zap.AtomicLevel
const dataPath = "./data"
func init() {
config := zap.NewDevelopmentConfig()
config.EncoderConfig.EncodeLevel = zapcore.CapitalColorLevelEncoder
config.DisableStacktrace = true
logger, _ := config.Build(zap.AddCallerSkip(1))
atom = zap.NewAtomicLevel()
atom.SetLevel(zap.DebugLevel)
w := zapcore.Lock(os.Stdout)
if os.Getenv("GIN_MODE") == "release" {
w = zapcore.AddSync(&lumberjack.Logger{
Filename: filepath.Join(dataPath, "logs", "polaris.log"),
MaxSize: 50, // megabytes
MaxBackups: 3,
MaxAge: 30, // days
})
}
consoleEncoder := zapcore.NewConsoleEncoder(zap.NewDevelopmentEncoderConfig())
logger := zap.New(zapcore.NewCore(consoleEncoder, w, atom), zap.AddCallerSkip(1),zap.AddCaller())
sugar = logger.Sugar()
}
func SetLogLevel(l string) {
switch strings.TrimSpace(strings.ToLower(l)) {
case "debug":
atom.SetLevel(zap.DebugLevel)
Debug("set log level to debug")
case "info":
atom.SetLevel(zap.InfoLevel)
Info("set log level to info")
case "warn", "warning":
atom.SetLevel(zap.WarnLevel)
Warn("set log level to warning")
case "error":
atom.SetLevel(zap.ErrorLevel)
Error("set log level to error")
}
}
func Logger() *zap.SugaredLogger {
return sugar
}
func Info(args ...interface{}) {

View File

@@ -8,6 +8,7 @@ type Torrent interface {
Remove() error
Save() string
Exists() bool
SeedRatio() *float64
}

23
pkg/metadata/doc.go Normal file
View File

@@ -0,0 +1,23 @@
package metadata
/*
tv name examples
Cowboy Cartel S01E02 XviD-AFG [eztv]
The.Bold.and.the.Beautiful.S37E219.XviD-AFG
As Husband As Wife 2024 S01E05-E06 1080p WEB-DL HEVC DDP 2Audios-QHstudIo
Twinkle Love 2024 S04 Complete 2160p WEB-DL HEVC AAC-QHstudIo
[HorribleSubs] One Punch Man S2 - 08 [720p].mkv
[Breeze] One Punch Man S01 S02 [1080p BD AV1][dual audio]
[HYSUB]ONE PUNCH MAN[S1+S2][BDrip][GB_MP4][1920X1080]
Cowboy Cartel S01E04 Photo Finish 1080p ATVP WEB-DL DDP5 1 Atmos H 264-FLUX [eztv]
Limitless Wrestling 2021 01 06 The Road Season 2 Episode 12 XviD-AFG [eztv]
[千夏字幕组][小市民系列_Shoushimin Series][第03话][1080p_HEVC][简繁内封][招募新人]
[OPFans楓雪動漫][ONE PIECE 海賊王][第1113話][周日版][1080p][MP4][簡體]
[桜都字幕组] 亦叶亦花 / Nanare Hananare [04][1080p][简体内嵌]
[ANi] 戰國妖狐 千魔混沌篇 - 16 [1080P][Baha][WEB-DL][AAC AVC][CHT][MP4]
[ANi] 這是妳與我的最後戰場,或是開創世界的聖戰 第二季 - 04 [1080P][Baha][WEB-DL][AAC AVC][CHT][MP4]
[桜都字幕组][一拳超人 第2季/One Punch Man 2nd Season][01-12 END][BIG5][720P]
一拳超人第二季One.Punch.Man.Season2.2160p.10Bit.HEVC.AAC.CHS&JPN
*/

View File

@@ -15,6 +15,7 @@ type MovieMetadata struct {
}
func ParseMovie(name string) *MovieMetadata {
name = strings.Join(strings.Fields(name), " ") //remove unnessary spaces
name = strings.ToLower(strings.TrimSpace(name))
var meta = &MovieMetadata{}
yearRe := regexp.MustCompile(`\(\d{4}\)`)

View File

@@ -9,42 +9,31 @@ import (
)
type Metadata struct {
NameEn string
NameCn string
Season int
Episode int
Resolution string
NameEn string
NameCn string
Season int
Episode int
Resolution string
IsSeasonPack bool
}
func ParseTv(name string) *Metadata {
name = strings.ToLower(name)
if utils.IsASCII(name) { //english name
return parseEnglishName(name)
}
name = strings.ReplaceAll(name, "\u200b", "") //remove unicode hidden character
if utils.ContainsChineseChar(name) {
return parseChineseName(name)
}
return nil
return parseEnglishName(name)
}
func parseEnglishName(name string) *Metadata {
re := regexp.MustCompile(`[^\p{L}\w\s]`)
name = re.ReplaceAllString(strings.ToLower(name), "")
splits := strings.Split(strings.TrimSpace(name), " ")
var newSplits []string
for _, p := range splits {
p = strings.TrimSpace(p)
if p == "" {
continue
}
newSplits = append(newSplits, p)
}
name = re.ReplaceAllString(strings.ToLower(name), " ")
newSplits := strings.Split(strings.TrimSpace(name), " ")
seasonRe := regexp.MustCompile(`^s\d{1,2}`)
resRe := regexp.MustCompile(`^\d{3,4}p`)
episodeRe := regexp.MustCompile(`e\d{1,2}`)
episodeRe := regexp.MustCompile(`e\d{1,3}`)
var seasonIndex = -1
var episodeIndex = -1
@@ -60,7 +49,7 @@ func parseEnglishName(name string) *Metadata {
} else if resRe.MatchString(p) {
resIndex = i
}
if episodeRe.MatchString(p) {
if i >= seasonIndex && episodeRe.MatchString(p) {
episodeIndex = i
}
}
@@ -71,11 +60,6 @@ func parseEnglishName(name string) *Metadata {
}
if seasonIndex != -1 {
//season exists
if seasonIndex != 0 {
//name exists
names := newSplits[0:seasonIndex]
meta.NameEn = strings.Join(names, " ")
}
ss := seasonRe.FindAllString(newSplits[seasonIndex], -1)
if len(ss) != 0 {
//season info
@@ -87,6 +71,24 @@ func parseEnglishName(name string) *Metadata {
}
meta.Season = n
}
} else { //maybe like Season 1?
seasonRe := regexp.MustCompile(`season \d{1,2}`)
matches := seasonRe.FindAllString(name, -1)
if len(matches) > 0 {
for i, s := range newSplits {
if s == "season" {
seasonIndex = i
}
}
numRe := regexp.MustCompile(`\d{1,2}`)
seNum := numRe.FindAllString(matches[0], -1)[0]
n, err := strconv.Atoi(seNum)
if err != nil {
panic(fmt.Sprintf("convert %s error: %v", seNum, err))
}
meta.Season = n
}
}
if episodeIndex != -1 {
ep := episodeRe.FindAllString(newSplits[episodeIndex], -1)
@@ -99,21 +101,55 @@ func parseEnglishName(name string) *Metadata {
}
meta.Episode = n
}
} else { //no episode, maybe like One Punch Man S2 - 08 [1080p].mkv
// numRe := regexp.MustCompile(`^\d{1,2}$`)
// for i, p := range newSplits {
// if numRe.MatchString(p) {
// if i > 0 && strings.Contains(newSplits[i-1], "season") { //last word cannot be season
// continue
// }
// if i < seasonIndex {
// //episode number most likely should comes alfter season number
// continue
// }
// //episodeIndex = i
// n, err := strconv.Atoi(p)
// if err != nil {
// panic(fmt.Sprintf("convert %s error: %v", p, err))
// }
// meta.Episode = n
// }
// }
}
if resIndex != -1 {
//resolution exists
meta.Resolution = newSplits[resIndex]
}
if meta.Episode == -1 {
meta.Episode = -1
meta.IsSeasonPack = true
}
if seasonIndex > 0 {
//name exists
names := newSplits[0:seasonIndex]
meta.NameEn = strings.TrimSpace(strings.Join(names, " "))
} else {
meta.NameEn = name
}
return meta
}
func parseChineseName(name string) *Metadata {
var meta = &Metadata{
Season: 1,
var meta = parseEnglishName(name)
if meta.Season != -1 && (meta.Episode != -1 || meta.IsSeasonPack) {
return meta
}
meta = &Metadata{Season: 1}
//season pack
packRe := regexp.MustCompile(`(\d{1,2}-\d{1,2})|(全集)`)
if packRe.MatchString(name) {
@@ -144,10 +180,10 @@ func parseChineseName(name string) *Metadata {
}
meta.Episode = n
} else { //【第09話】
re2 := regexp.MustCompile(`第\d{1,2}(话|話|集)`)
re2 := regexp.MustCompile(`第\d{1,4}(话|話|集)`)
episodeMatches1 := re2.FindAllString(name, -1)
if len(episodeMatches1) > 0 {
re := regexp.MustCompile(`\d{1,2}`)
re := regexp.MustCompile(`\d{1,4}`)
epNum := re.FindAllString(episodeMatches1[0], -1)[0]
n, err := strconv.Atoi(epNum)
if err != nil {
@@ -158,9 +194,9 @@ func parseChineseName(name string) *Metadata {
re3 := regexp.MustCompile(`[^\d\w]\d{1,2}[^\d\w]`)
epNums := re3.FindAllString(name, -1)
if len(epNums) > 0 {
re3 := regexp.MustCompile(`\d{1,2}`)
epNum := re3.FindAllString(epNums[0],-1)[0]
epNum := re3.FindAllString(epNums[0], -1)[0]
n, err := strconv.Atoi(epNum)
if err != nil {
panic(fmt.Sprintf("convert %s error: %v", epNum, err))
@@ -203,10 +239,10 @@ func parseChineseName(name string) *Metadata {
}
}
if meta.IsSeasonPack && meta.Episode != 0{
if meta.IsSeasonPack && meta.Episode != 0 {
meta.Season = meta.Episode
meta.Episode = -1
}
}
//tv name
title := name

147
pkg/metadata/tv_test.go Normal file
View File

@@ -0,0 +1,147 @@
package metadata
import (
"polaris/log"
"testing"
"github.com/stretchr/testify/assert"
)
func Test_ParseTV1(t *testing.T) {
s1 := "Twinkle Love 2024 S04 Complete 2160p WEB-DL HEVC AAC-QHstudIo"
m := ParseTv(s1)
log.Infof("results: %+v", m)
assert.Equal(t, m.Season, 4)
assert.Equal(t, m.IsSeasonPack, true)
assert.Equal(t, m.Resolution, "2160p")
}
func Test_ParseTV2(t *testing.T) {
s1 := "Cowboy Cartel S01E04 Photo Finish 1080p ATVP WEB-DL DDP5 1 Atmos H 264-FLUX [eztv] "
m := ParseTv(s1)
log.Infof("results: %+v", m)
assert.Equal(t, m.Season, 1)
assert.Equal(t, m.Episode, 4)
assert.Equal(t, m.IsSeasonPack, false)
assert.Equal(t, m.Resolution, "1080p")
}
func Test_ParseTV3(t *testing.T) {
s1 := "The.Bold.and.the.Beautiful.S37E219.XviD-AFG "
m := ParseTv(s1)
log.Infof("results: %+v", m)
assert.Equal(t, m.Season, 37)
assert.Equal(t, m.Episode, 219)
assert.Equal(t, m.IsSeasonPack, false)
//assert.Equal(t, m.Resolution, "1080p")
}
func Test_ParseTV4(t *testing.T) {
s1 := "Limitless Wrestling 2021 01 06 The Road Season 2 Episode 12 XviD-AFG [eztv] "
m := ParseTv(s1)
log.Infof("results: %+v", m)
assert.Equal(t, m.Season, 2)
//assert.Equal(t, m.Episode, 219)
assert.Equal(t, m.IsSeasonPack, true)
//assert.Equal(t, m.Resolution, "1080p")
}
func Test_ParseTV5(t *testing.T) {
s1 := "[Breeze] One Punch Man S01 S02 [1080p BD AV1][dual audio]"
m := ParseTv(s1)
log.Infof("results: %+v", m)
assert.Equal(t, m.Season, 1)
//assert.Equal(t, m.Episode, 219)
assert.Equal(t, m.IsSeasonPack, true)
//assert.Equal(t, m.Resolution, "1080p")
}
func Test_ParseTV6(t *testing.T) {
s1 := "[千夏字幕组][小市民系列_Shoushimin Series][第03话][1080p_HEVC][简繁内封][招募新人]"
m := ParseTv(s1)
log.Infof("results: %+v", m)
assert.Equal(t, m.Season, 1)
assert.Equal(t, m.Episode, 3)
assert.Equal(t, m.IsSeasonPack, false)
assert.Equal(t, m.Resolution, "1080p")
}
func Test_ParseTV7(t *testing.T) {
s1 := " [OPFans楓雪動漫][ONE PIECE 海賊王][第1113話][周日版][1080p][MP4][簡體]"
m := ParseTv(s1)
log.Infof("results: %+v", m)
assert.Equal(t, m.Season, 1)
assert.Equal(t, m.Episode, 1113)
assert.Equal(t, m.IsSeasonPack, false)
assert.Equal(t, m.Resolution, "1080p")
}
func Test_ParseTV8(t *testing.T) {
s1 := "[桜都字幕组] 亦叶亦花 / Nanare Hananare [04][1080p][简体内嵌] "
m := ParseTv(s1)
log.Infof("results: %+v", m)
assert.Equal(t, m.Season, 1)
assert.Equal(t, m.Episode, 4)
assert.Equal(t, m.IsSeasonPack, false)
assert.Equal(t, m.Resolution, "1080p")
}
func Test_ParseTV9(t *testing.T) {
s1 := "[ANi] 戰國妖狐 千魔混沌篇 - 16 [1080P][Baha][WEB-DL][AAC AVC][CHT][MP4]"
m := ParseTv(s1)
log.Infof("results: %+v", m)
assert.Equal(t, m.Season, 1)
assert.Equal(t, m.Episode, 16)
assert.Equal(t, m.IsSeasonPack, false)
assert.Equal(t, m.Resolution, "1080p")
}
func Test_ParseTV10(t *testing.T) {
s1 := " [桜都字幕组][一拳超人 第2季/One Punch Man 2nd Season][01-12 END][BIG5][720P]"
m := ParseTv(s1)
log.Infof("results: %+v", m)
assert.Equal(t, 2, m.Season)
//assert.Equal(t, 01, m.Episode)
assert.Equal(t, true, m.IsSeasonPack)
assert.Equal(t, "720p", m.Resolution)
}
func Test_ParseTV11(t *testing.T) {
s1 := " [ANi] 這是妳與我的最後戰場,或是開創世界的聖戰 第二季 - 04 [1080P][Baha][WEB-DL][AAC AVC][CHT][MP4] "
m := ParseTv(s1)
log.Infof("results: %+v", m)
assert.Equal(t, 2, m.Season)
assert.Equal(t, 4, m.Episode)
assert.Equal(t, false, m.IsSeasonPack)
assert.Equal(t, "1080p", m.Resolution)
}
func Test_ParseTV12(t *testing.T) {
s1 := " 牛仔Cowboy Cartel S02E04 Photo Finish 1080p ATVP WEB-DL DDP5 1 Atmos H 264-FLUX [eztv] "
m := ParseTv(s1)
log.Infof("results: %+v", m)
assert.Equal(t, 2, m.Season)
assert.Equal(t, 4, m.Episode)
assert.Equal(t, false, m.IsSeasonPack)
assert.Equal(t, "1080p", m.Resolution)
}
func Test_ParseTV13(t *testing.T) {
s1 := "House of Dragon 2024 1080p S02E08 Leaked HQCAM NOT COMPLETE English Audio x264 ESub BOTHD"
m := ParseTv(s1)
log.Infof("results: %+v", m)
assert.Equal(t, 2, m.Season)
assert.Equal(t, 8, m.Episode)
assert.Equal(t, false, m.IsSeasonPack)
assert.Equal(t, "1080p", m.Resolution)
}
func Test_ParseTV14(t *testing.T) {
s1 := ""
m := ParseTv(s1)
log.Infof("results: %+v", m)
assert.Equal(t, 2, m.Season)
assert.Equal(t, 01, m.Episode)
assert.Equal(t, false, m.IsSeasonPack)
assert.Equal(t, "720p", m.Resolution)
}

90
pkg/notifier/clients.go Normal file
View File

@@ -0,0 +1,90 @@
package notifier
import (
"encoding/json"
"github.com/nikoksr/notify/service/bark"
"github.com/nikoksr/notify/service/dingding"
po "github.com/nikoksr/notify/service/pushover"
"github.com/nikoksr/notify/service/telegram"
"github.com/pkg/errors"
)
type PushoverConfig struct {
UserKey string `json:"user_key"`
GroupKey string `json:"group_key"`
AppToken string `json:"app_token"`
}
func NewPushoverClient(s string) (NotificationClient, error) {
var cfg PushoverConfig
if err := json.Unmarshal([]byte(s), &cfg); err != nil {
return nil, errors.Wrap(err, "json")
}
c := po.New(cfg.AppToken)
if cfg.UserKey != "" {
c.AddReceivers(cfg.UserKey)
}
if cfg.GroupKey != "" {
c.AddReceivers(cfg.GroupKey)
}
return &Notifier{service: c}, nil
}
type DingTalkConfig struct {
Token string `json:"token"`
Secret string `json:"secret"`
}
func NewDingTalkClient(s string) (NotificationClient, error) {
var cfg DingTalkConfig
if err := json.Unmarshal([]byte(s), &cfg); err != nil {
return nil, errors.Wrap(err, "json")
}
svc := dingding.New(&dingding.Config{
Token: cfg.Token,
Secret: cfg.Secret,
})
return &Notifier{service: svc}, nil
}
type TelegramConfig struct {
Token string `json:"token"`
ChatID int64 `json:"chat_id"`
}
func NewTelegramClient(s string) (NotificationClient, error) {
var cfg TelegramConfig
if err := json.Unmarshal([]byte(s), &cfg); err != nil {
return nil, errors.Wrap(err, "json")
}
svc, err := telegram.New(cfg.Token)
if err != nil {
panic(err)
}
svc.AddReceivers(cfg.ChatID)
return &Notifier{service: svc}, nil
}
type BarkConfig struct {
DeviceKey string `json:"device_key"`
URL string `json:"url"`
}
func NewbarkClient(s string) (NotificationClient, error) {
var cfg BarkConfig
if err := json.Unmarshal([]byte(s), &cfg); err != nil {
return nil, errors.Wrap(err, "json")
}
url := cfg.URL
if url == "" {
url = bark.DefaultServerURL
}
b := bark.NewWithServers(cfg.DeviceKey, url)
return &Notifier{service: b}, nil
}

37
pkg/notifier/doc.go Normal file
View File

@@ -0,0 +1,37 @@
package notifier
import (
"context"
"polaris/pkg/utils"
"github.com/nikoksr/notify"
)
type HandlerFunc func(string) (NotificationClient, error)
type NotificationClient interface {
SendMsg(msg string) error
}
type Notifier struct {
service notify.Notifier
}
func (s *Notifier) SendMsg(msg string) error {
notifier := notify.New()
notifier.UseServices(s.service)
return notifier.Send(context.TODO(), "Polaris", msg)
}
var handler = utils.Map[string, HandlerFunc]{}
func init() {
handler.Store("pushover", NewPushoverClient)
handler.Store("dingtalk", NewDingTalkClient)
handler.Store("telegram", NewTelegramClient)
handler.Store("bark", NewbarkClient)
}
func Gethandler(name string) (HandlerFunc, bool) {
return handler.Load(name)
}

View File

@@ -0,0 +1,8 @@
package message
const (
BeginDownload = "开始下载:%v"
DownloadComplete = "下载完成:%v"
ProcessingComplete = "文件处理完成:%v"
ProcessingFailed = "文件处理失败:%v"
)

View File

@@ -13,7 +13,10 @@ import (
type Storage interface {
Move(src, dest string) error
Copy(src, dest string) error
ReadDir(dir string) ([]fs.FileInfo, error)
ReadFile(string) ([]byte, error)
WriteFile(string, []byte) error
}
func NewLocalStorage(dir string) (*LocalStorage, error) {
@@ -26,10 +29,20 @@ type LocalStorage struct {
dir string
}
func (l *LocalStorage) Move(src, dest string) error {
targetDir := filepath.Join(l.dir, dest)
os.MkdirAll(targetDir, 0655)
err := filepath.Walk(src, func(path string, info fs.FileInfo, err error) error {
func (l *LocalStorage) Copy(src, destDir string) error {
os.MkdirAll(filepath.Join(l.dir, destDir), os.ModePerm)
targetBase := filepath.Join(l.dir, destDir, filepath.Base(src)) //文件的场景,要加上文件名, move filename ./dir/
info, err := os.Stat(src)
if err != nil {
return errors.Wrap(err, "read source dir")
}
if info.IsDir() { //如果是路径,则只移动路径里面的文件,不管当前路径, 行为类似 move dirname/* target_dir/
targetBase = filepath.Join(l.dir, destDir)
}
log.Debugf("local storage target base dir is: %v", targetBase)
err = filepath.Walk(src, func(path string, info fs.FileInfo, err error) error {
if err != nil {
return err
}
@@ -37,24 +50,28 @@ func (l *LocalStorage) Move(src, dest string) error {
if err != nil {
return errors.Wrapf(err, "relation between %s and %s", src, path)
}
destName := filepath.Join(targetDir, rel)
destName := filepath.Join(targetBase, rel)
if info.IsDir() {
os.Mkdir(destName, 0655)
os.Mkdir(destName, os.ModePerm)
} else { //is file
if writer, err := os.Create(destName); err != nil {
return errors.Wrapf(err, "create file %s", destName)
} else {
defer writer.Close()
if f, err := os.OpenFile(path, os.O_RDONLY, 0666); err != nil {
return errors.Wrapf(err, "read file %v", path)
} else { //open success
defer f.Close()
_, err := io.Copy(writer, f)
if err != nil {
return errors.Wrap(err, "transmitting data error")
if err := os.Link(path, destName); err != nil {
log.Warnf("hard link file error: %v, will try copy file, source: %s, dest: %s", err, path, destName)
if writer, err := os.OpenFile(destName, os.O_RDWR|os.O_CREATE|os.O_TRUNC, os.ModePerm); err != nil {
return errors.Wrapf(err, "create file %s", destName)
} else {
defer writer.Close()
if f, err := os.OpenFile(path, os.O_RDONLY, os.ModePerm); err != nil {
return errors.Wrapf(err, "read file %v", path)
} else { //open success
defer f.Close()
_, err := io.Copy(writer, f)
if err != nil {
return errors.Wrap(err, "transmitting data error")
}
}
}
}
}
log.Infof("file copy complete: %v", destName)
@@ -63,10 +80,24 @@ func (l *LocalStorage) Move(src, dest string) error {
if err != nil {
return errors.Wrap(err, "move file error")
}
return os.RemoveAll(src)
return nil
}
func (l *LocalStorage) Move(src, destDir string) error {
if err := l.Copy(src, destDir); err != nil {
return err
}
return os.RemoveAll(src)
}
func (l *LocalStorage) ReadDir(dir string) ([]fs.FileInfo, error) {
return ioutil.ReadDir(filepath.Join(l.dir, dir))
}
func (l *LocalStorage) ReadFile(name string) ([]byte, error) {
return os.ReadFile(filepath.Join(l.dir, name))
}
func (l *LocalStorage) WriteFile(name string, data []byte) error {
return os.WriteFile(filepath.Join(l.dir, name), data, os.ModePerm)
}

View File

@@ -14,8 +14,8 @@ import (
)
type WebdavStorage struct {
fs *gowebdav.Client
dir string
fs *gowebdav.Client
dir string
changeMediaHash bool
}
@@ -25,18 +25,24 @@ func NewWebdavStorage(url, user, password, path string, changeMediaHash bool) (*
return nil, errors.Wrap(err, "connect webdav")
}
return &WebdavStorage{
fs: c,
fs: c,
dir: path,
}, nil
}
func (w *WebdavStorage) Move(local, remote string) error {
remoteBase := filepath.Join(w.dir,remote)
func (w *WebdavStorage) Copy(local, remoteDir string) error {
remoteBase := filepath.Join(w.dir, remoteDir, filepath.Base(local))
info, err := os.Stat(local)
if err != nil {
return errors.Wrap(err, "read source dir")
}
if info.IsDir() { //如果是路径,则只移动路径里面的文件,不管当前路径, 行为类似 move dirname/* target_dir/
remoteBase = filepath.Join(w.dir, remoteDir)
}
//log.Infof("remove all content in %s", remoteBase)
//w.fs.RemoveAll(remoteBase)
err := filepath.Walk(local, func(path string, info fs.FileInfo, err error) error {
err = filepath.Walk(local, func(path string, info fs.FileInfo, err error) error {
if err != nil {
return errors.Wrapf(err, "read file %v", path)
}
@@ -73,7 +79,7 @@ func (w *WebdavStorage) Move(local, remote string) error {
r.Header.Set("Content-Type", mtype.String())
r.ContentLength = info.Size()
}
if err := w.fs.WriteStream(remoteName, f, 0666, callback); err != nil {
return errors.Wrap(err, "transmitting data error")
}
@@ -85,9 +91,24 @@ func (w *WebdavStorage) Move(local, remote string) error {
if err != nil {
return errors.Wrap(err, "move file error")
}
return nil
}
func (w *WebdavStorage) Move(local, remoteDir string) error {
if err := w.Copy(local, remoteDir); err != nil {
return err
}
return os.RemoveAll(local)
}
func (w *WebdavStorage) ReadDir(dir string) ([]fs.FileInfo, error) {
return w.fs.ReadDir(filepath.Join(w.dir, dir))
}
func (w *WebdavStorage) ReadFile(name string) ([]byte, error) {
return w.fs.Read(filepath.Join(w.dir, name))
}
func (w *WebdavStorage) WriteFile(name string, data []byte) error {
return w.fs.Write(filepath.Join(w.dir, name), data, os.ModePerm)
}

View File

@@ -1,9 +1,12 @@
package tmdb
import (
"net/http"
"net/url"
"polaris/log"
"strconv"
"strings"
"time"
tmdb "github.com/cyruzin/golang-tmdb"
"github.com/pkg/errors"
@@ -14,11 +17,29 @@ type Client struct {
tmdbClient *tmdb.Client
}
func NewClient(apiKey string) (*Client, error) {
func NewClient(apiKey, proxyUrl string) (*Client, error) {
tmdbClient, err := tmdb.Init(apiKey)
if err != nil {
return nil, errors.Wrap(err, "new tmdb client")
}
if proxyUrl != "" {
//set proxy
u, err := url.Parse(proxyUrl)
if err != nil {
log.Errorf("parse proxy %v error, skip: %v", proxyUrl, err)
} else {
tmdbClient.SetClientConfig(http.Client{
Timeout: time.Second * 10,
Transport: &http.Transport{
Proxy: http.ProxyURL(u),
MaxIdleConns: 10,
IdleConnTimeout: 15 * time.Second,
},
})
}
}
return &Client{
apiKey: apiKey,
@@ -28,6 +49,9 @@ func NewClient(apiKey string) (*Client, error) {
func (c *Client) GetTvDetails(id int, language string) (*tmdb.TVDetails, error) {
d, err := c.tmdbClient.GetTVDetails(id, withLangOption(language))
if err != nil {
return nil, errors.Wrap(err, "get tv detail")
}
log.Infof("tv id %d, language %s", id, language)
if !episodeNameUseful(d.LastEpisodeToAir.Name) {
@@ -38,17 +62,15 @@ func (c *Client) GetTvDetails(id int, language string) (*tmdb.TVDetails, error)
if err != nil {
return d, nil
}
}
if episodeNameUseful(detailEN.LastEpisodeToAir.Name) {
d.LastEpisodeToAir.Name = detailEN.LastEpisodeToAir.Name
d.LastEpisodeToAir.Overview = detailEN.LastEpisodeToAir.Overview
d.NextEpisodeToAir.Name = detailEN.NextEpisodeToAir.Name
d.NextEpisodeToAir.Overview = detailEN.NextEpisodeToAir.Overview
if episodeNameUseful(detailEN.LastEpisodeToAir.Name) {
d.LastEpisodeToAir.Name = detailEN.LastEpisodeToAir.Name
d.LastEpisodeToAir.Overview = detailEN.LastEpisodeToAir.Overview
d.NextEpisodeToAir.Name = detailEN.NextEpisodeToAir.Name
d.NextEpisodeToAir.Overview = detailEN.NextEpisodeToAir.Overview
}
}
}
return d, err
}
@@ -150,7 +172,7 @@ func (c *Client) GetEposideDetail(id, seasonNumber, eposideNumber int, language
return d, err
}
d.Name = detailEN.Name
d.Overview = detailEN.Overview
d.Overview = detailEN.Overview
}
return d, err
@@ -170,7 +192,7 @@ func (c *Client) GetSeasonDetails(id, seasonNumber int, language string) (*tmdb.
}
for i, ep := range detailCN.Episodes {
if !episodeNameUseful(ep.Name) && episodeNameUseful(detailEN.Episodes[i].Name){
if !episodeNameUseful(ep.Name) && episodeNameUseful(detailEN.Episodes[i].Name) {
detailCN.Episodes[i].Name = detailEN.Episodes[i].Name
detailCN.Episodes[i].Overview = detailEN.Episodes[i].Overview
}
@@ -196,7 +218,6 @@ func withLangOption(language string) map[string]string {
}
}
func episodeNameUseful(name string) bool {
return !strings.HasSuffix(name, "集") && !strings.HasPrefix(strings.ToLower(name), "episode")
}
}

View File

@@ -6,6 +6,7 @@ import (
"io"
"net/http"
"net/url"
"polaris/db"
"polaris/log"
"strconv"
"time"
@@ -71,17 +72,22 @@ func (i *Item) GetAttr(key string) string {
}
return ""
}
func (r *Response) ToResults() []Result {
func (r *Response) ToResults(indexer *db.TorznabInfo) []Result {
var res []Result
for _, item := range r.Channel.Item {
r := Result{
Name: item.Title,
Magnet: item.Link,
Size: mustAtoI(item.Size),
Seeders: mustAtoI(item.GetAttr("seeders")),
Peers: mustAtoI(item.GetAttr("peers")),
Category: mustAtoI(item.GetAttr("category")),
Source: r.Channel.Title,
Name: item.Title,
Link: item.Link,
Size: mustAtoI(item.Size),
Seeders: mustAtoI(item.GetAttr("seeders")),
Peers: mustAtoI(item.GetAttr("peers")),
Category: mustAtoI(item.GetAttr("category")),
DownloadVolumeFactor: tryParseFloat(item.GetAttr("downloadvolumefactor")),
UploadVolumeFactor: tryParseFloat(item.GetAttr("uploadvolumefactor")),
Source: indexer.Name,
IndexerId: indexer.ID,
Priority: indexer.Priority,
IsPrivate: item.Type == "private",
}
res = append(res, r)
}
@@ -96,11 +102,21 @@ func mustAtoI(key string) int {
}
return i
}
func Search(torznabUrl, api, keyWord string) ([]Result, error) {
func tryParseFloat(s string) float32 {
r, err := strconv.ParseFloat(s, 32)
if err != nil {
log.Warnf("parse float error: %v", err)
return 0
}
return float32(r)
}
func Search(indexer *db.TorznabInfo, api, keyWord string) ([]Result, error) {
ctx, cancel := context.WithTimeout(context.TODO(), 10*time.Second)
defer cancel()
req, err := http.NewRequestWithContext(ctx, http.MethodGet, torznabUrl, nil)
req, err := http.NewRequestWithContext(ctx, http.MethodGet, indexer.URL, nil)
if err != nil {
return nil, errors.Wrap(err, "new request")
}
@@ -124,15 +140,20 @@ func Search(torznabUrl, api, keyWord string) ([]Result, error) {
if err != nil {
return nil, errors.Wrap(err, "json unmarshal")
}
return res.ToResults(), nil
return res.ToResults(indexer), nil
}
type Result struct {
Name string
Magnet string
Size int
Seeders int
Peers int
Category int
Source string
Name string `json:"name"`
Link string `json:"link"`
Size int `json:"size"`
Seeders int `json:"seeders"`
Peers int `json:"peers"`
Category int `json:"category"`
Source string `json:"source"`
DownloadVolumeFactor float32 `json:"download_volume_factor"`
UploadVolumeFactor float32 `json:"upload_volume_factor"`
IndexerId int `json:"indexer_id"`
Priority int `json:"priority"`
IsPrivate bool `json:"is_private"`
}

View File

@@ -3,8 +3,11 @@ package transmission
import (
"context"
"encoding/json"
"fmt"
"net/http"
"net/url"
"polaris/log"
"strings"
"github.com/hekmon/transmissionrpc/v3"
"github.com/pkg/errors"
@@ -25,6 +28,10 @@ func NewClient(c Config) (*Client, error) {
if err != nil {
return nil, errors.Wrap(err, "connect transmission")
}
_, err = tbt.TorrentGetAll(context.TODO())
if err != nil {
return nil, errors.Wrap(err, "transmission cannot connect")
}
return &Client{c: tbt, cfg: c}, nil
}
@@ -34,20 +41,58 @@ type Config struct {
Password string `json:"password"`
}
type Client struct {
c *transmissionrpc.Client
c *transmissionrpc.Client
cfg Config
}
func (c *Client) Download(magnet, dir string) (*Torrent, error) {
func (c *Client) GetAll() ([]*Torrent, error) {
all, err := c.c.TorrentGetAll(context.TODO())
if err != nil {
return nil, errors.Wrap(err, "get all")
}
var torrents []*Torrent
for _, t := range all {
torrents = append(torrents, &Torrent{
ID: *t.ID,
c: c.c,
Config: c.cfg,
})
}
return torrents, nil
}
func (c *Client) Download(link, dir string) (*Torrent, error) {
if strings.HasPrefix(link, "http") {
client := &http.Client{
CheckRedirect: func(req *http.Request, via []*http.Request) error {
return http.ErrUseLastResponse
},
}
resp, err:=client.Get(link)
if err == nil {
if resp.StatusCode == http.StatusFound {
loc, err := resp.Location()
if err == nil {
link = loc.String()
log.Warnf("transimision redirect to url: %v", link)
}
}
}
}
t, err := c.c.TorrentAdd(context.TODO(), transmissionrpc.TorrentAddPayload{
Filename: &magnet,
Filename: &link,
DownloadDir: &dir,
})
log.Infof("get torrent info: %+v", t)
if t.ID == nil {
return nil, fmt.Errorf("download torrent error: %v", link)
}
return &Torrent{
ID: *t.ID,
c: c.c,
ID: *t.ID,
c: c.c,
Config: c.cfg,
}, err
}
@@ -85,6 +130,9 @@ func (t *Torrent) Exists() bool {
}
func (t *Torrent) Name() string {
if !t.Exists() {
return ""
}
return *t.getTorrent().Name
}
@@ -95,7 +143,7 @@ func (t *Torrent) Progress() int {
if t.getTorrent().PercentComplete != nil && *t.getTorrent().PercentComplete >= 1 {
return 100
}
if t.getTorrent().PercentComplete != nil {
p := int(*t.getTorrent().PercentComplete * 100)
if p == 100 {
@@ -110,6 +158,10 @@ func (t *Torrent) Stop() error {
return t.c.TorrentStopIDs(context.TODO(), []int64{t.ID})
}
func (t *Torrent) SeedRatio() *float64 {
return t.getTorrent().UploadRatio
}
func (t *Torrent) Start() error {
return t.c.TorrentStartIDs(context.TODO(), []int64{t.ID})
}
@@ -143,4 +195,4 @@ func ReloadTorrent(s string) (*Torrent, error) {
return nil, errors.Wrap(err, "reload client")
}
return &torrent, nil
}
}

13
pkg/uptime/uptime.go Normal file
View File

@@ -0,0 +1,13 @@
package uptime
import "time"
var startTime time.Time
func Uptime() time.Duration {
return time.Since(startTime)
}
func init() {
startTime = time.Now()
}

31
pkg/utils/map.go Normal file
View File

@@ -0,0 +1,31 @@
package utils
import "sync"
type Map[K comparable, V any] struct {
m sync.Map
}
func (m *Map[K, V]) Delete(key K) { m.m.Delete(key) }
func (m *Map[K, V]) Load(key K) (value V, ok bool) {
v, ok := m.m.Load(key)
if !ok {
return value, ok
}
return v.(V), ok
}
func (m *Map[K, V]) LoadAndDelete(key K) (value V, loaded bool) {
v, loaded := m.m.LoadAndDelete(key)
if !loaded {
return value, loaded
}
return v.(V), loaded
}
func (m *Map[K, V]) LoadOrStore(key K, value V) (actual V, loaded bool) {
a, loaded := m.m.LoadOrStore(key, value)
return a.(V), loaded
}
func (m *Map[K, V]) Range(f func(key K, value V) bool) {
m.m.Range(func(key, value any) bool { return f(key.(K), value.(V)) })
}
func (m *Map[K, V]) Store(key K, value V) { m.m.Store(key, value) }

View File

@@ -7,8 +7,6 @@ import (
"strings"
"unicode"
"github.com/adrg/strutil"
"github.com/adrg/strutil/metrics"
"github.com/pkg/errors"
"golang.org/x/crypto/bcrypt"
"golang.org/x/exp/rand"
@@ -57,11 +55,15 @@ func RandString(n int) string {
}
func IsNameAcceptable(name1, name2 string) bool {
re := regexp.MustCompile(`[^\p{L}\w\s]`)
name1 = re.ReplaceAllString(strings.ToLower(name1), "")
name2 = re.ReplaceAllString(strings.ToLower(name2), "")
return strutil.Similarity(name1, name2, metrics.NewHamming()) > 0.4
name1 = re.ReplaceAllString(strings.ToLower(name1), " ")
name2 = re.ReplaceAllString(strings.ToLower(name2), " ")
name1 = strings.Join(strings.Fields(name1), " ")
name2 = strings.Join(strings.Fields(name2), " ")
if strings.Contains(name1, name2) || strings.Contains(name2, name1) {
return true
}
return false
}
func FindSeasonEpisodeNum(name string) (se int, ep int, err error) {
@@ -108,21 +110,6 @@ func FindSeasonPackageInfo(name string) (se int, err error) {
return se, err
}
func IsSeasonPackageName(name string) bool {
seRe := regexp.MustCompile(`S\d+`)
epRe := regexp.MustCompile(`E\d+`)
nameUpper := strings.ToUpper(name)
matchEp := epRe.FindAllString(nameUpper, -1)
if len(matchEp) != 0 {
return false //episode number should not exist
}
matchSe := seRe.FindAllString(nameUpper, -1)
if len(matchSe) == 0 {
return false //no season num
}
return true
}
func ContainsIgnoreCase(s, substr string) bool {
return strings.Contains(strings.ToLower(s), strings.ToLower(substr))
}

View File

@@ -32,7 +32,7 @@ func (s *Server) GetAllActivities(c *gin.Context) (interface{}, error) {
a := Activity{
History: h,
}
for id, task := range s.tasks {
for id, task := range s.core.GetTasks() {
if h.ID == id && task.Exists() {
a.Progress = task.Progress()
}
@@ -54,13 +54,11 @@ func (s *Server) RemoveActivity(c *gin.Context) (interface{}, error) {
log.Errorf("no record of id: %d", id)
return nil, nil
}
torrent := s.tasks[his.ID]
if torrent != nil {
if err := torrent.Remove(); err != nil {
return nil, errors.Wrap(err, "remove torrent")
}
delete(s.tasks, his.ID)
if err := s.core.RemoveTaskAndTorrent(his.ID); err != nil {
return nil, errors.Wrap(err, "remove torrent")
}
if his.EpisodeID != 0 {
s.db.SetEpisodeStatus(his.EpisodeID, episode.StatusMissing)
@@ -93,3 +91,33 @@ func (s *Server) GetMediaDownloadHistory(c *gin.Context) (interface{}, error) {
}
return his, nil
}
type TorrentInfo struct {
Name string `json:"name"`
ID int64 `json:"id"`
SeedRatio float32 `json:"seed_ratio"`
Progress int `json:"progress"`
}
func (s *Server) GetAllTorrents(c *gin.Context) (interface{}, error) {
trc, _, err := s.getDownloadClient()
if err != nil {
return nil, errors.Wrap(err, "connect transmission")
}
all, err := trc.GetAll()
if err != nil {
return nil, errors.Wrap(err, "get all")
}
var infos []TorrentInfo
for _, t := range all {
if !t.Exists() {
continue
}
infos = append(infos, TorrentInfo{
Name: t.Name(),
ID: t.ID,
Progress: t.Progress(),
})
}
return infos, nil
}

View File

@@ -5,7 +5,6 @@ import (
"polaris/db"
"polaris/log"
"polaris/pkg/utils"
"strings"
"time"
"github.com/gin-gonic/gin"
@@ -23,16 +22,15 @@ func (s *Server) authModdleware(c *gin.Context) {
c.Next()
return
}
auth := c.GetHeader("Authorization")
if auth == "" {
log.Infof("token is not present, abort")
token, err := c.Cookie("token")
if err != nil {
log.Errorf("token error: %v", err)
c.AbortWithStatus(http.StatusForbidden)
return
}
auth = strings.TrimPrefix(auth, "Bearer ")
//log.Infof("current token: %v", auth)
token, err := jwt.ParseWithClaims(auth, &jwt.RegisteredClaims{}, func(t *jwt.Token) (interface{}, error) {
//log.Debugf("current token: %v", auth)
tokenParsed, err := jwt.ParseWithClaims(token, &jwt.RegisteredClaims{}, func(t *jwt.Token) (interface{}, error) {
return []byte(s.jwtSerect), nil
})
if err != nil {
@@ -40,15 +38,15 @@ func (s *Server) authModdleware(c *gin.Context) {
c.AbortWithStatus(http.StatusForbidden)
return
}
if !token.Valid {
log.Errorf("token is not valid: %v", auth)
if !tokenParsed.Valid {
log.Errorf("token is not valid: %v", token)
c.AbortWithStatus(http.StatusForbidden)
return
}
claim := token.Claims.(*jwt.RegisteredClaims)
claim := tokenParsed.Claims.(*jwt.RegisteredClaims)
if time.Until(claim.ExpiresAt.Time) <= 0 {
log.Infof("token is no longer valid: %s", auth)
log.Infof("token is no longer valid: %s", token)
c.AbortWithStatus(http.StatusForbidden)
return
}
@@ -61,7 +59,6 @@ type LoginIn struct {
Password string `json:"password"`
}
func (s *Server) Login(c *gin.Context) (interface{}, error) {
var in LoginIn
@@ -93,11 +90,23 @@ func (s *Server) Login(c *gin.Context) (interface{}, error) {
if err != nil {
return nil, errors.Wrap(err, "sign")
}
c.SetSameSite(http.SameSiteNoneMode)
c.SetCookie("token", sig, 0, "/", "", true, false)
return gin.H{
"token": sig,
}, nil
}
func (s *Server) Logout(c *gin.Context) (interface{}, error) {
if !s.isAuthEnabled() {
return nil, errors.New( "auth is not enabled")
}
c.SetSameSite(http.SameSiteNoneMode)
c.SetCookie("token", "", -1, "/", "", true, false)
return nil, nil
}
type EnableAuthIn struct {
Enable bool `json:"enable"`
User string `json:"user"`

View File

@@ -19,7 +19,7 @@ func HttpHandler(f func(*gin.Context) (interface{}, error)) gin.HandlerFunc {
})
return
}
//log.Infof("url %v return: %+v", ctx.Request.URL, r)
log.Debugf("url %v return: %+v", ctx.Request.URL, r)
ctx.JSON(200, Response{
Code: 0,

95
server/core/client.go Normal file
View File

@@ -0,0 +1,95 @@
package core
import (
"polaris/db"
"polaris/ent"
"polaris/log"
"polaris/pkg/tmdb"
"polaris/pkg/transmission"
"github.com/pkg/errors"
"github.com/robfig/cron"
)
func NewClient(db *db.Client, language string) *Client {
return &Client{
db: db,
cron: cron.New(),
tasks: make(map[int]*Task, 0),
language: language,
}
}
type Client struct {
db *db.Client
cron *cron.Cron
tasks map[int]*Task
language string
}
func (c *Client) Init() {
c.reloadTasks()
c.addSysCron()
}
func (c *Client) reloadTasks() {
allTasks := c.db.GetHistories()
for _, t := range allTasks {
torrent, err := transmission.ReloadTorrent(t.Saved)
if err != nil {
log.Errorf("relaod task %s failed: %v", t.SourceTitle, err)
continue
}
if !torrent.Exists() { //只要种子还存在于客户端中,就重新加载,有可能是还在做种中
continue
}
log.Infof("reloading task: %d %s", t.ID, t.SourceTitle)
c.tasks[t.ID] = &Task{Torrent: torrent}
}
}
func (c *Client) getDownloadClient() (*transmission.Client, *ent.DownloadClients, error) {
tr := c.db.GetTransmission()
trc, err := transmission.NewClient(transmission.Config{
URL: tr.URL,
User: tr.User,
Password: tr.Password,
})
if err != nil {
return nil, nil, errors.Wrap(err, "connect transmission")
}
return trc, tr, nil
}
func (c *Client) TMDB() (*tmdb.Client, error) {
api := c.db.GetSetting(db.SettingTmdbApiKey)
if api == "" {
return nil, errors.New("TMDB apiKey not set")
}
proxy := c.db.GetSetting(db.SettingProxy)
return tmdb.NewClient(api, proxy)
}
func (c *Client) MustTMDB() *tmdb.Client {
t, err := c.TMDB()
if err != nil {
log.Panicf("get tmdb: %v", err)
}
return t
}
func (c *Client) RemoveTaskAndTorrent(id int)error {
torrent := c.tasks[id]
if torrent != nil {
if err := torrent.Remove(); err != nil {
return errors.Wrap(err, "remove torrent")
}
delete(c.tasks, id)
}
return nil
}
func (c *Client) GetTasks() map[int]*Task {
return c.tasks
}

121
server/core/integration.go Normal file
View File

@@ -0,0 +1,121 @@
package core
import (
"bytes"
"fmt"
"path/filepath"
"polaris/db"
"polaris/ent/media"
storage1 "polaris/ent/storage"
"polaris/log"
"polaris/pkg/notifier"
"polaris/pkg/storage"
"github.com/pkg/errors"
)
func (c *Client) writePlexmatch(seriesId int, episodeId int, targetDir, name string) error {
if !c.plexmatchEnabled() {
return nil
}
series, err := c.db.GetMedia(seriesId)
if err != nil {
return err
}
if series.MediaType != media.MediaTypeTv {
return nil
}
st, err := c.getStorage(series.StorageID, media.MediaTypeTv)
if err != nil {
return errors.Wrap(err, "get storage")
}
//series plexmatch file
_, err = st.ReadFile(filepath.Join(series.TargetDir, ".plexmatch"))
if err != nil {
//create new
log.Warnf(".plexmatch file not found, create new one: %s", series.NameEn)
if err := st.WriteFile(filepath.Join(series.TargetDir, ".plexmatch"),
[]byte(fmt.Sprintf("tmdbid: %d\n", series.TmdbID))); err != nil {
return errors.Wrap(err, "series plexmatch")
}
}
//season plexmatch file
ep, err := c.db.GetEpisodeByID(episodeId)
if err != nil {
return errors.Wrap(err, "query episode")
}
buff := bytes.Buffer{}
seasonPlex := filepath.Join(targetDir, ".plexmatch")
data, err := st.ReadFile(seasonPlex)
if err != nil {
log.Infof("read season plexmatch: %v", err)
} else {
buff.Write(data)
}
buff.WriteString(fmt.Sprintf("\nep: %d: %s\n", ep.EpisodeNumber, name))
log.Infof("write season plexmatch file content: %s", buff.String())
return st.WriteFile(seasonPlex, buff.Bytes())
}
func (c *Client) plexmatchEnabled() bool {
return c.db.GetSetting(db.SettingPlexMatchEnabled) == "true"
}
func (c *Client) getStorage(storageId int, mediaType media.MediaType) (storage.Storage, error) {
st := c.db.GetStorage(storageId)
targetPath := st.TvPath
if mediaType == media.MediaTypeMovie {
targetPath = st.MoviePath
}
switch st.Implementation {
case storage1.ImplementationLocal:
storageImpl1, err := storage.NewLocalStorage(targetPath)
if err != nil {
return nil, errors.Wrap(err, "new local")
}
return storageImpl1, nil
case storage1.ImplementationWebdav:
ws := st.ToWebDavSetting()
storageImpl1, err := storage.NewWebdavStorage(ws.URL, ws.User, ws.Password, targetPath, ws.ChangeFileHash == "true")
if err != nil {
return nil, errors.Wrap(err, "new webdav")
}
return storageImpl1, nil
}
return nil, errors.New("no storage found")
}
func (c *Client) sendMsg(msg string) {
clients, err := c.db.GetAllNotificationClients2()
if err != nil {
log.Errorf("query notification clients: %v", err)
return
}
for _, cl := range clients {
if !cl.Enabled {
continue
}
handler, ok := notifier.Gethandler(cl.Service)
if !ok {
log.Errorf("no notification implementation of service %s", cl.Service)
continue
}
noCl, err := handler(cl.Settings)
if err != nil {
log.Errorf("handle setting for name %s error: %v", cl.Name, err)
continue
}
err = noCl.SendMsg(msg)
if err != nil {
log.Errorf("send message error: %v", err)
continue
}
log.Debugf("send message to %s success, msg is %s", cl.Name, msg)
}
}

165
server/core/resources.go Normal file
View File

@@ -0,0 +1,165 @@
package core
import (
"fmt"
"polaris/ent"
"polaris/ent/episode"
"polaris/ent/history"
"polaris/log"
"polaris/pkg/notifier/message"
"polaris/pkg/torznab"
"polaris/pkg/utils"
"github.com/pkg/errors"
)
func (c *Client) DownloadSeasonPackage(r1 torznab.Result, seriesId, seasonNum int) (*string, error) {
trc, dlClient, err := c.getDownloadClient()
if err != nil {
return nil, errors.Wrap(err, "connect transmission")
}
downloadDir := c.db.GetDownloadDir()
size := utils.AvailableSpace(downloadDir)
if size < uint64(r1.Size) {
log.Errorf("space available %v, space needed %v", size, r1.Size)
return nil, errors.New("no enough space")
}
torrent, err := trc.Download(r1.Link, c.db.GetDownloadDir())
if err != nil {
return nil, errors.Wrap(err, "downloading")
}
torrent.Start()
series := c.db.GetMediaDetails(seriesId)
if series == nil {
return nil, fmt.Errorf("no tv series of id %v", seriesId)
}
dir := fmt.Sprintf("%s/Season %02d/", series.TargetDir, seasonNum)
history, err := c.db.SaveHistoryRecord(ent.History{
MediaID: seriesId,
EpisodeID: 0,
SourceTitle: r1.Name,
TargetDir: dir,
Status: history.StatusRunning,
Size: r1.Size,
Saved: torrent.Save(),
DownloadClientID: dlClient.ID,
IndexerID: r1.IndexerId,
})
if err != nil {
return nil, errors.Wrap(err, "save record")
}
c.db.SetSeasonAllEpisodeStatus(seriesId, seasonNum, episode.StatusDownloading)
c.tasks[history.ID] = &Task{Torrent: torrent}
c.sendMsg(fmt.Sprintf(message.BeginDownload, r1.Name))
return &r1.Name, nil
}
func (c *Client) DownloadEpisodeTorrent(r1 torznab.Result, seriesId, seasonNum, episodeNum int) (*string, error) {
trc, dlc, err := c.getDownloadClient()
if err != nil {
return nil, errors.Wrap(err, "connect transmission")
}
series := c.db.GetMediaDetails(seriesId)
if series == nil {
return nil, fmt.Errorf("no tv series of id %v", seriesId)
}
var ep *ent.Episode
for _, e := range series.Episodes {
if e.SeasonNumber == seasonNum && e.EpisodeNumber == episodeNum {
ep = e
}
}
if ep == nil {
return nil, errors.Errorf("no episode of season %d episode %d", seasonNum, episodeNum)
}
torrent, err := trc.Download(r1.Link, c.db.GetDownloadDir())
if err != nil {
return nil, errors.Wrap(err, "downloading")
}
torrent.Start()
dir := fmt.Sprintf("%s/Season %02d/", series.TargetDir, seasonNum)
history, err := c.db.SaveHistoryRecord(ent.History{
MediaID: ep.MediaID,
EpisodeID: ep.ID,
SourceTitle: r1.Name,
TargetDir: dir,
Status: history.StatusRunning,
Size: r1.Size,
Saved: torrent.Save(),
DownloadClientID: dlc.ID,
IndexerID: r1.IndexerId,
})
if err != nil {
return nil, errors.Wrap(err, "save record")
}
c.db.SetEpisodeStatus(ep.ID, episode.StatusDownloading)
c.tasks[history.ID] = &Task{Torrent: torrent}
c.sendMsg(fmt.Sprintf(message.BeginDownload, r1.Name))
log.Infof("success add %s to download task", r1.Name)
return &r1.Name, nil
}
func (c *Client) SearchAndDownload(seriesId, seasonNum, episodeNum int) (*string, error) {
res, err := SearchTvSeries(c.db, seriesId, seasonNum, []int{episodeNum}, true, true)
if err != nil {
return nil, err
}
r1 := res[0]
log.Infof("found resource to download: %+v", r1)
return c.DownloadEpisodeTorrent(r1, seriesId, seasonNum, episodeNum)
}
func (c *Client) DownloadMovie(m *ent.Media,link, name string, size int, indexerID int) (*string, error) {
trc, dlc, err := c.getDownloadClient()
if err != nil {
return nil, errors.Wrap(err, "connect transmission")
}
torrent, err := trc.Download(link, c.db.GetDownloadDir())
if err != nil {
return nil, errors.Wrap(err, "downloading")
}
torrent.Start()
if name == "" {
name = m.OriginalName
}
go func() {
ep, _ := c.db.GetMovieDummyEpisode(m.ID)
history, err := c.db.SaveHistoryRecord(ent.History{
MediaID: m.ID,
EpisodeID: ep.ID,
SourceTitle: name,
TargetDir: m.TargetDir,
Status: history.StatusRunning,
Size: size,
Saved: torrent.Save(),
DownloadClientID: dlc.ID,
IndexerID: indexerID,
})
if err != nil {
log.Errorf("save history error: %v", err)
}
c.tasks[history.ID] = &Task{Torrent: torrent}
c.db.SetEpisodeStatus(ep.ID, episode.StatusDownloading)
}()
c.sendMsg(fmt.Sprintf(message.BeginDownload, name))
log.Infof("success add %s to download task", name)
return &name, nil
}

351
server/core/scheduler.go Normal file
View File

@@ -0,0 +1,351 @@
package core
import (
"fmt"
"path/filepath"
"polaris/ent"
"polaris/ent/episode"
"polaris/ent/history"
"polaris/ent/media"
"polaris/log"
"polaris/pkg"
"polaris/pkg/notifier/message"
"polaris/pkg/utils"
"github.com/pkg/errors"
)
func (c *Client) addSysCron() {
c.mustAddCron("@every 1m", c.checkTasks)
c.mustAddCron("0 0 * * * *", func() {
c.downloadTvSeries()
c.downloadMovie()
})
c.mustAddCron("0 0 */12 * * *", c.checkAllSeriesNewSeason)
c.cron.Start()
}
func (c *Client) 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) checkTasks() {
log.Debug("begin check tasks...")
for id, t := range c.tasks {
if !t.Exists() {
log.Infof("task no longer exists: %v", id)
delete(c.tasks, id)
continue
}
log.Infof("task (%s) percentage done: %d%%", t.Name(), t.Progress())
if t.Progress() == 100 {
r := c.db.GetHistory(id)
if r.Status == history.StatusSuccess {
//task already success, check seed ratio
torrent := c.tasks[id]
ok := c.isSeedRatioLimitReached(r.IndexerID, torrent)
if ok {
log.Infof("torrent file seed ratio reached, remove: %v", torrent.Name())
torrent.Remove()
delete(c.tasks, id)
} else {
log.Infof("torrent file still sedding: %v", torrent.Name())
}
continue
}
log.Infof("task is done: %v", t.Name())
c.sendMsg(fmt.Sprintf(message.DownloadComplete, t.Name()))
go func() {
if err := c.moveCompletedTask(id); err != nil {
log.Infof("post tasks for id %v fail: %v", id, err)
}
}()
}
}
}
func (c *Client) moveCompletedTask(id int) (err1 error) {
torrent := c.tasks[id]
r := c.db.GetHistory(id)
if r.Status == history.StatusUploading {
log.Infof("task %d is already uploading, skip", id)
return nil
}
c.db.SetHistoryStatus(r.ID, history.StatusUploading)
seasonNum, err := utils.SeasonId(r.TargetDir)
if err != nil {
log.Errorf("no season id: %v", r.TargetDir)
seasonNum = -1
}
downloadclient, err := c.db.GetDownloadClient(r.DownloadClientID)
if err != nil {
log.Errorf("get task download client error: %v, use default one", err)
downloadclient = &ent.DownloadClients{RemoveCompletedDownloads: true, RemoveFailedDownloads: true}
}
torrentName := torrent.Name()
defer func() {
if err1 != nil {
c.db.SetHistoryStatus(r.ID, history.StatusFail)
if r.EpisodeID != 0 {
c.db.SetEpisodeStatus(r.EpisodeID, episode.StatusMissing)
} else {
c.db.SetSeasonAllEpisodeStatus(r.MediaID, seasonNum, episode.StatusMissing)
}
c.sendMsg(fmt.Sprintf(message.ProcessingFailed, err))
if downloadclient.RemoveFailedDownloads {
log.Debugf("task failed, remove failed torrent and files related")
delete(c.tasks, r.ID)
torrent.Remove()
}
}
}()
series := c.db.GetMediaDetails(r.MediaID)
if series == nil {
return nil
}
st := c.db.GetStorage(series.StorageID)
log.Infof("move task files to target dir: %v", r.TargetDir)
stImpl, err := c.getStorage(st.ID, series.MediaType)
if err != nil {
return err
}
//如果种子是路径,则会把路径展开,只移动文件,类似 move dir/* dir2/, 如果种子是文件,则会直接移动文件,类似 move file dir/
if err := stImpl.Copy(filepath.Join(c.db.GetDownloadDir(), torrentName), r.TargetDir); err != nil {
return errors.Wrap(err, "move file")
}
// .plexmatch file
if err := c.writePlexmatch(r.MediaID, r.EpisodeID, r.TargetDir, torrentName); err != nil {
log.Errorf("create .plexmatch file error: %v", err)
}
c.db.SetHistoryStatus(r.ID, history.StatusSuccess)
if r.EpisodeID != 0 {
c.db.SetEpisodeStatus(r.EpisodeID, episode.StatusDownloaded)
} else {
c.db.SetSeasonAllEpisodeStatus(r.MediaID, seasonNum, episode.StatusDownloaded)
}
c.sendMsg(fmt.Sprintf(message.ProcessingComplete, torrentName))
//判断是否需要删除本地文件
ok := c.isSeedRatioLimitReached(r.IndexerID, torrent)
if downloadclient.RemoveCompletedDownloads && ok {
log.Debugf("download complete,remove torrent and files related")
delete(c.tasks, r.ID)
torrent.Remove()
}
log.Infof("move downloaded files to target dir success, file: %v, target dir: %v", torrentName, r.TargetDir)
return nil
}
func (c *Client) CheckDownloadedSeriesFiles(m *ent.Media) error {
if m.MediaType != media.MediaTypeTv {
return nil
}
log.Infof("check files in directory: %s", m.TargetDir)
var storageImpl, err = c.getStorage(m.StorageID, media.MediaTypeTv)
if err != nil {
return err
}
files, err := storageImpl.ReadDir(m.TargetDir)
if err != nil {
return errors.Wrapf(err, "read dir %s", m.TargetDir)
}
for _, in := range files {
if !in.IsDir() { //season dir, ignore file
continue
}
dir := filepath.Join(m.TargetDir, in.Name())
epFiles, err := storageImpl.ReadDir(dir)
if err != nil {
log.Errorf("read dir %s error: %v", dir, err)
continue
}
for _, ep := range epFiles {
log.Infof("found file: %v", ep.Name())
seNum, epNum, err := utils.FindSeasonEpisodeNum(ep.Name())
if err != nil {
log.Errorf("find season episode num error: %v", err)
continue
}
log.Infof("found match, season num %d, episode num %d", seNum, epNum)
ep, err := c.db.GetEpisode(m.ID, seNum, epNum)
if err != nil {
log.Error("update episode: %v", err)
continue
}
err = c.db.SetEpisodeStatus(ep.ID, episode.StatusDownloaded)
if err != nil {
log.Error("update episode: %v", err)
continue
}
}
}
return nil
}
type Task struct {
//Processing bool
pkg.Torrent
}
func (c *Client) downloadTvSeries() {
log.Infof("begin check all tv series resources")
allSeries := c.db.GetMediaWatchlist(media.MediaTypeTv)
for _, series := range allSeries {
tvDetail := c.db.GetMediaDetails(series.ID)
for _, ep := range tvDetail.Episodes {
if !ep.Monitored { //未监控的剧集不去下载
continue
}
if ep.Status != episode.StatusMissing { //已经下载的不去下载
continue
}
name, err := c.SearchAndDownload(series.ID, ep.SeasonNumber, ep.EpisodeNumber)
if err != nil {
log.Infof("cannot find resource to download for %s: %v", ep.Title, err)
} else {
log.Infof("begin download torrent resource: %v", name)
}
}
}
}
func (c *Client) downloadMovie() {
log.Infof("begin check all movie resources")
allSeries := c.db.GetMediaWatchlist(media.MediaTypeMovie)
for _, series := range allSeries {
detail := c.db.GetMediaDetails(series.ID)
if len(detail.Episodes) == 0 {
log.Errorf("no related dummy episode: %v", detail.NameEn)
continue
}
ep := detail.Episodes[0]
if ep.Status == episode.StatusDownloaded {
continue
}
if err := c.downloadMovieSingleEpisode(ep); err != nil {
log.Errorf("download movie error: %v", err)
}
}
}
func (c *Client) downloadMovieSingleEpisode(ep *ent.Episode) error {
trc, dlc, err := c.getDownloadClient()
if err != nil {
return errors.Wrap(err, "connect transmission")
}
res, err := SearchMovie(c.db, ep.MediaID, true, true)
if err != nil {
return errors.Wrap(err, "search movie")
}
r1 := res[0]
log.Infof("begin download torrent resource: %v", r1.Name)
torrent, err := trc.Download(r1.Link, c.db.GetDownloadDir())
if err != nil {
return errors.Wrap(err, "downloading")
}
torrent.Start()
history, err := c.db.SaveHistoryRecord(ent.History{
MediaID: ep.MediaID,
EpisodeID: ep.ID,
SourceTitle: r1.Name,
TargetDir: "./",
Status: history.StatusRunning,
Size: r1.Size,
Saved: torrent.Save(),
DownloadClientID: dlc.ID,
IndexerID: r1.IndexerId,
})
if err != nil {
log.Errorf("save history error: %v", err)
}
c.tasks[history.ID] = &Task{Torrent: torrent}
c.db.SetEpisodeStatus(ep.ID, episode.StatusDownloading)
return nil
}
func (c *Client) checkAllSeriesNewSeason() {
log.Infof("begin checking series all new season")
allSeries := c.db.GetMediaWatchlist(media.MediaTypeTv)
for _, series := range allSeries {
err := c.checkSeiesNewSeason(series)
if err != nil {
log.Errorf("check series new season error: series name %v, error: %v", series.NameEn, err)
}
}
}
func (c *Client) checkSeiesNewSeason(media *ent.Media) error {
d, err := c.MustTMDB().GetTvDetails(media.TmdbID, c.language)
if err != nil {
return errors.Wrap(err, "tmdb")
}
lastsSason := d.NumberOfSeasons
seasonDetail, err := c.MustTMDB().GetSeasonDetails(media.TmdbID, lastsSason, c.language)
if err != nil {
return errors.Wrap(err, "tmdb season")
}
for _, ep := range seasonDetail.Episodes {
epDb, err := c.db.GetEpisode(media.ID, ep.SeasonNumber, ep.EpisodeNumber)
if err != nil {
if ent.IsNotFound(err) {
log.Infof("add new episode: %+v", ep)
episode := &ent.Episode{
MediaID: media.ID,
SeasonNumber: ep.SeasonNumber,
EpisodeNumber: ep.EpisodeNumber,
Title: ep.Name,
Overview: ep.Overview,
AirDate: ep.AirDate,
Status: episode.StatusMissing,
Monitored: true,
}
c.db.SaveEposideDetail2(episode)
}
} else { //update episode
if ep.Name != epDb.Title || ep.Overview != epDb.Overview || ep.AirDate != epDb.AirDate {
log.Infof("update new episode: %+v", ep)
c.db.UpdateEpiode2(epDb.ID, ep.Name, ep.Overview, ep.AirDate)
}
}
}
return nil
}
func (c *Client) isSeedRatioLimitReached(indexId int, t pkg.Torrent) bool {
indexer, err := c.db.GetIndexer(indexId)
if err != nil {
return true
}
currentRatio := t.SeedRatio()
if currentRatio == nil {
log.Warnf("get current seed ratio error, current ratio is nil")
return indexer.SeedRatio == 0
}
return *currentRatio >= float64(indexer.SeedRatio)
}

View File

@@ -7,6 +7,7 @@ import (
"polaris/pkg/metadata"
"polaris/pkg/torznab"
"polaris/pkg/utils"
"slices"
"sort"
"strconv"
"strings"
@@ -15,15 +16,12 @@ import (
"github.com/pkg/errors"
)
func SearchSeasonPackage(db1 *db.Client, seriesId, seasonNum int, checkResolution bool) ([]torznab.Result, error) {
return SearchEpisode(db1, seriesId, seasonNum, -1, checkResolution)
}
func SearchEpisode(db1 *db.Client, seriesId, seasonNum, episodeNum int, checkResolution bool) ([]torznab.Result, error) {
func SearchTvSeries(db1 *db.Client, seriesId, seasonNum int, episodes []int, checkResolution bool, checkFileSize bool) ([]torznab.Result, error) {
series := db1.GetMediaDetails(seriesId)
if series == nil {
return nil, fmt.Errorf("no tv series of id %v", seriesId)
}
log.Debugf("check tv series %s, season %d, episode %v", series.NameEn, seasonNum, episodes)
res := searchWithTorznab(db1, series.NameEn)
resCn := searchWithTorznab(db1, series.NameCn)
@@ -31,11 +29,24 @@ func SearchEpisode(db1 *db.Client, seriesId, seasonNum, episodeNum int, checkRes
var filtered []torznab.Result
for _, r := range res {
//log.Infof("torrent resource: %+v", r)
meta := metadata.ParseTv(r.Name)
if meta.Season != seasonNum {
if meta == nil { //cannot parse name
continue
}
if episodeNum != -1 && meta.Episode != episodeNum { //not season pack
if !isNumberedSeries(series) && meta.Season != seasonNum { //do not check season on series that only rely on episode number
continue
}
if isNumberedSeries(series) && len(episodes) == 0 {
//should not want season
continue
}
if len(episodes) > 0 && !slices.Contains(episodes, meta.Episode) { //not season pack, but episode number not equal
continue
} else if len(episodes) == 0 && !meta.IsSeasonPack { //want season pack, but not season pack
continue
}
if checkResolution && meta.Resolution != series.Resolution.String() {
@@ -44,17 +55,43 @@ func SearchEpisode(db1 *db.Client, seriesId, seasonNum, episodeNum int, checkRes
if !utils.IsNameAcceptable(meta.NameEn, series.NameEn) && !utils.IsNameAcceptable(meta.NameCn, series.NameCn) {
continue
}
if checkFileSize && series.Limiter != nil {
if series.Limiter.SizeMin > 0 && r.Size < series.Limiter.SizeMin {
//min size not satified
continue
}
if series.Limiter.SizeMax > 0 && r.Size > series.Limiter.SizeMax {
//max size not satified
continue
}
}
filtered = append(filtered, r)
}
if len(filtered) == 0 {
return nil, errors.New("no resource found")
}
filtered = dedup(filtered)
return filtered, nil
}
func SearchMovie(db1 *db.Client, movieId int, checkResolution bool) ([]torznab.Result, error) {
func isNumberedSeries(detail *db.MediaDetails) bool {
hasSeason2 := false
season2HasEpisode1 := false
for _, ep := range detail.Episodes {
if ep.SeasonNumber == 2 {
hasSeason2 = true
if ep.EpisodeNumber == 1 {
season2HasEpisode1 = true
}
}
}
return hasSeason2 && !season2HasEpisode1 //only one 1st episode
}
func SearchMovie(db1 *db.Client, movieId int, checkResolution bool, checkFileSize bool) ([]torznab.Result, error) {
movieDetail := db1.GetMediaDetails(movieId)
if movieDetail == nil {
return nil, errors.New("no media found of id")
@@ -77,6 +114,18 @@ func SearchMovie(db1 *db.Client, movieId int, checkResolution bool) ([]torznab.R
if checkResolution && meta.Resolution != movieDetail.Resolution.String() {
continue
}
if checkFileSize && movieDetail.Limiter != nil {
if movieDetail.Limiter.SizeMin > 0 && r.Size < movieDetail.Limiter.SizeMin {
//min size not satified
continue
}
if movieDetail.Limiter.SizeMax > 0 && r.Size > movieDetail.Limiter.SizeMax {
//max size not satified
continue
}
}
ss := strings.Split(movieDetail.AirDate, "-")[0]
year, _ := strconv.Atoi(ss)
if meta.Year != year && meta.Year != year-1 && meta.Year != year+1 { //year not match
@@ -89,6 +138,7 @@ func SearchMovie(db1 *db.Client, movieId int, checkResolution bool) ([]torznab.R
if len(filtered) == 0 {
return nil, errors.New("no resource found")
}
filtered = dedup(filtered)
return filtered, nil
@@ -102,17 +152,20 @@ func searchWithTorznab(db *db.Client, q string) []torznab.Result {
var wg sync.WaitGroup
for _, tor := range allTorznab {
if tor.Disabled {
continue
}
wg.Add(1)
go func () {
go func() {
log.Debugf("search torznab %v with %v", tor.Name, q)
defer wg.Done()
resp, err := torznab.Search(tor.URL, tor.ApiKey, q)
resp, err := torznab.Search(tor, tor.ApiKey, q)
if err != nil {
log.Errorf("search %s error: %v", tor.Name, err)
return
}
resChan <- resp
}()
}
go func() {
@@ -124,11 +177,53 @@ func searchWithTorznab(db *db.Client, q string) []torznab.Result {
res = append(res, result...)
}
sort.Slice(res, func(i, j int) bool {
//res = dedup(res)
sort.SliceStable(res, func(i, j int) bool { //先按做种人数排序
var s1 = res[i]
var s2 = res[j]
return s1.Seeders > s2.Seeders
})
sort.SliceStable(res, func(i, j int) bool { //再按优先级排序,优先级高的种子排前面
var s1 = res[i]
var s2 = res[j]
return s1.Priority > s2.Priority
})
//pt资源中同一indexer内部优先下载free的资源
sort.SliceStable(res, func(i, j int) bool {
var s1 = res[i]
var s2 = res[j]
if s1.IndexerId == s2.IndexerId && s1.IsPrivate {
return s1.DownloadVolumeFactor < s2.DownloadVolumeFactor
}
return false
})
//同一indexer内部如果下载消耗一样则优先下载上传奖励较多的
sort.SliceStable(res, func(i, j int) bool {
var s1 = res[i]
var s2 = res[j]
if s1.IndexerId == s2.IndexerId && s1.IsPrivate && s1.DownloadVolumeFactor == s2.DownloadVolumeFactor {
return s1.UploadVolumeFactor > s2.UploadVolumeFactor
}
return false
})
return res
}
func dedup(list []torznab.Result) []torznab.Result {
var res = make([]torznab.Result, 0, len(list))
seen := make(map[string]bool, 0)
for _, r := range list {
key := fmt.Sprintf("%s%s%d%d", r.Name, r.Source, r.Seeders, r.Peers)
if seen[key] {
continue
}
seen[key] = true
res = append(res, r)
}
return res
}

44
server/notify_client.go Normal file
View File

@@ -0,0 +1,44 @@
package server
import (
"polaris/ent"
"strconv"
"github.com/gin-gonic/gin"
"github.com/pkg/errors"
)
func (s *Server) GetAllNotificationClients(c *gin.Context) (interface{}, error) {
return s.db.GetAllNotificationClients()
}
func (s *Server) GetNotificationClient(c *gin.Context) (interface{}, error) {
ids := c.Param("id")
id, err := strconv.Atoi(ids)
if err != nil {
return nil, errors.Wrap(err, "convert")
}
return s.db.GetNotificationClient(id)
}
func (s *Server) DeleteNotificationClient(c *gin.Context) (interface{}, error) {
ids := c.Param("id")
id, err := strconv.Atoi(ids)
if err != nil {
return nil, errors.Wrap(err, "convert")
}
return nil, s.db.DeleteNotificationClient(id)
}
func (s *Server) AddNotificationClient(c *gin.Context) (interface{}, error) {
var in ent.NotificationClient
if err := c.ShouldBindJSON(&in); err != nil {
return nil, errors.Wrap(err, "json")
}
err := s.db.AddNotificationClient(in.Name, in.Service, in.Settings, in.Enabled)
if err != nil {
return nil, errors.Wrap(err, "save db")
}
return nil, nil
}

View File

@@ -2,174 +2,26 @@ package server
import (
"fmt"
"polaris/db"
"polaris/ent"
"polaris/ent/episode"
"polaris/ent/history"
"polaris/ent/media"
"polaris/log"
"polaris/pkg/transmission"
"polaris/pkg/utils"
"polaris/pkg/torznab"
"polaris/server/core"
"strconv"
"github.com/gin-gonic/gin"
"github.com/pkg/errors"
)
type addTorznabIn struct {
Name string `json:"name"`
URL string `json:"url"`
ApiKey string `json:"api_key"`
}
func (s *Server) AddTorznabInfo(c *gin.Context) (interface{}, error) {
var in addTorznabIn
if err := c.ShouldBindJSON(&in); err != nil {
return nil, errors.Wrap(err, "bind json")
}
err := s.db.SaveTorznabInfo(in.Name, db.TorznabSetting{
URL: in.URL,
ApiKey: in.ApiKey,
})
if err != nil {
return nil, errors.Wrap(err, "add ")
}
return nil, nil
}
func (s *Server) DeleteTorznabInfo(c *gin.Context) (interface{}, error) {
var ids = c.Param("id")
id, err := strconv.Atoi(ids)
if err != nil {
return nil, fmt.Errorf("id is not correct: %v", ids)
}
s.db.DeleteTorznab(id)
return "success", nil
}
func (s *Server) GetAllIndexers(c *gin.Context) (interface{}, error) {
indexers := s.db.GetAllTorznabInfo()
if len(indexers) == 0 {
return nil, nil
}
return indexers, nil
}
func (s *Server) getDownloadClient() (*transmission.Client, error) {
tr := s.db.GetTransmission()
trc, err := transmission.NewClient(transmission.Config{
URL: tr.URL,
User: tr.User,
Password: tr.Password,
})
if err != nil {
return nil, errors.Wrap(err, "connect transmission")
}
return trc, nil
}
func (s *Server) searchAndDownloadSeasonPackage(seriesId, seasonNum int) (*string, error) {
trc, err := s.getDownloadClient()
if err != nil {
return nil, errors.Wrap(err, "connect transmission")
}
res, err := core.SearchSeasonPackage(s.db, seriesId, seasonNum, true)
res, err := core.SearchTvSeries(s.db, seriesId, seasonNum, nil, true, true)
if err != nil {
return nil, err
}
r1 := res[0]
log.Infof("found resource to download: %v", r1)
log.Infof("found resource to download: %+v", r1)
return s.core.DownloadSeasonPackage(r1, seriesId, seasonNum)
downloadDir := s.db.GetDownloadDir()
size := utils.AvailableSpace(downloadDir)
if size < uint64(r1.Size) {
log.Errorf("space available %v, space needed %v", size, r1.Size)
return nil, errors.New("no enough space")
}
torrent, err := trc.Download(r1.Magnet, s.db.GetDownloadDir())
if err != nil {
return nil, errors.Wrap(err, "downloading")
}
torrent.Start()
series := s.db.GetMediaDetails(seriesId)
if series == nil {
return nil, fmt.Errorf("no tv series of id %v", seriesId)
}
dir := fmt.Sprintf("%s/Season %02d", series.TargetDir, seasonNum)
history, err := s.db.SaveHistoryRecord(ent.History{
MediaID: seriesId,
EpisodeID: 0,
SourceTitle: r1.Name,
TargetDir: dir,
Status: history.StatusRunning,
Size: r1.Size,
Saved: torrent.Save(),
})
if err != nil {
return nil, errors.Wrap(err, "save record")
}
s.db.SetSeasonAllEpisodeStatus(seriesId, seasonNum, episode.StatusDownloading)
s.tasks[history.ID] = &Task{Torrent: torrent}
return &r1.Name, nil
}
func (s *Server) searchAndDownload(seriesId, seasonNum, episodeNum int) (*string, error) {
trc, err := s.getDownloadClient()
if err != nil {
return nil, errors.Wrap(err, "connect transmission")
}
series := s.db.GetMediaDetails(seriesId)
if series == nil {
return nil, fmt.Errorf("no tv series of id %v", seriesId)
}
var ep *ent.Episode
for _, e := range series.Episodes {
if e.SeasonNumber == seasonNum && e.EpisodeNumber == episodeNum {
ep = e
}
}
if ep == nil {
return nil, errors.Errorf("no episode of season %d episode %d", seasonNum, episodeNum)
}
res, err := core.SearchEpisode(s.db, seriesId, seasonNum, episodeNum, true)
if err != nil {
return nil, err
}
r1 := res[0]
log.Infof("found resource to download: %v", r1)
torrent, err := trc.Download(r1.Magnet, s.db.GetDownloadDir())
if err != nil {
return nil, errors.Wrap(err, "downloading")
}
torrent.Start()
dir := fmt.Sprintf("%s/Season %02d", series.TargetDir, seasonNum)
history, err := s.db.SaveHistoryRecord(ent.History{
MediaID: ep.MediaID,
EpisodeID: ep.ID,
SourceTitle: r1.Name,
TargetDir: dir,
Status: history.StatusRunning,
Size: r1.Size,
Saved: torrent.Save(),
})
if err != nil {
return nil, errors.Wrap(err, "save record")
}
s.db.SetEpisodeStatus(ep.ID, episode.StatusDownloading)
s.tasks[history.ID] = &Task{Torrent: torrent}
log.Infof("success add %s to download task", r1.Name)
return &r1.Name, nil
}
type searchAndDownloadIn struct {
@@ -178,30 +30,48 @@ type searchAndDownloadIn struct {
Episode int `json:"episode"`
}
func (s *Server) SearchAvailableEpisodeResource(c *gin.Context) (interface{}, error) {
func (s *Server) SearchAvailableTorrents(c *gin.Context) (interface{}, error) {
var in searchAndDownloadIn
if err := c.ShouldBindJSON(&in); err != nil {
return nil, errors.Wrap(err, "bind json")
}
log.Infof("search episode resources link: %v", in)
res, err := core.SearchEpisode(s.db, in.ID, in.Season, in.Episode, true)
m, err := s.db.GetMedia(in.ID)
if err != nil {
return nil, errors.Wrap(err, "search episode")
return nil, errors.Wrap(err, "get media")
}
var searchResults []TorznabSearchResult
for _, r := range res {
searchResults = append(searchResults, TorznabSearchResult{
Name: r.Name,
Size: r.Size,
Seeders: r.Seeders,
Peers: r.Peers,
Link: r.Magnet,
})
log.Infof("search torrents resources link: %+v", in)
var res []torznab.Result
if m.MediaType == media.MediaTypeTv {
if in.Episode == 0 {
//search season package
log.Infof("search series season package S%02d", in.Season)
res, err = core.SearchTvSeries(s.db, in.ID, in.Season, nil, false, false)
if err != nil {
return nil, errors.Wrap(err, "search season package")
}
} else {
log.Infof("search series episode S%02dE%02d", in.Season, in.Episode)
res, err = core.SearchTvSeries(s.db, in.ID, in.Season, []int{in.Episode}, false, false)
if err != nil {
if err.Error() == "no resource found" {
return []string{}, nil
}
return nil, errors.Wrap(err, "search episode")
}
}
} else {
log.Info("search movie %d", in.ID)
res, err = core.SearchMovie(s.db, in.ID, false, false)
if err != nil {
if err.Error() == "no resource found" {
return []string{}, nil
}
return nil, err
}
}
if len(searchResults) == 0 {
return nil, errors.New("no resource found")
}
return searchResults, nil
return res, nil
}
func (s *Server) SearchTvAndDownload(c *gin.Context) (interface{}, error) {
@@ -221,7 +91,7 @@ func (s *Server) SearchTvAndDownload(c *gin.Context) (interface{}, error) {
name = *name1
} else {
log.Infof("season episode search")
name1, err := s.searchAndDownload(in.ID, in.Season, in.Episode)
name1, err := s.core.SearchAndDownload(in.ID, in.Season, in.Episode)
if err != nil {
return nil, errors.Wrap(err, "download")
}
@@ -233,135 +103,43 @@ func (s *Server) SearchTvAndDownload(c *gin.Context) (interface{}, error) {
}, nil
}
type TorznabSearchResult struct {
Name string `json:"name"`
Size int `json:"size"`
Link string `json:"link"`
Seeders int `json:"seeders"`
Peers int `json:"peers"`
}
func (s *Server) SearchAvailableMovies(c *gin.Context) (interface{}, error) {
ids := c.Param("id")
id, err := strconv.Atoi(ids)
if err != nil {
return nil, errors.Wrap(err, "convert")
}
movieDetail := s.db.GetMediaDetails(id)
if movieDetail == nil {
return nil, errors.New("no media found of id " + ids)
}
res, err := core.SearchMovie(s.db, id, false)
if err != nil {
if err.Error() == "no resource found" {
return []TorznabSearchResult{}, nil
}
return nil, err
}
var searchResults []TorznabSearchResult
for _, r := range res {
searchResults = append(searchResults, TorznabSearchResult{
Name: r.Name,
Size: r.Size,
Seeders: r.Seeders,
Peers: r.Peers,
Link: r.Magnet,
})
}
if len(searchResults) == 0 {
return []TorznabSearchResult{}, nil
}
return searchResults, nil
}
type downloadTorrentIn struct {
MediaID int `json:"media_id" binding:"required"`
TorznabSearchResult
MediaID int `json:"id" binding:"required"`
Season int `json:"season"`
Episode int `json:"episode"`
torznab.Result
}
func (s *Server) DownloadMovieTorrent(c *gin.Context) (interface{}, error) {
func (s *Server) DownloadTorrent(c *gin.Context) (interface{}, error) {
var in downloadTorrentIn
if err := c.ShouldBindJSON(&in); err != nil {
return nil, errors.Wrap(err, "bind json")
}
log.Infof("download torrent input: %+v", in)
trc, err := s.getDownloadClient()
m, err := s.db.GetMedia(in.MediaID)
if err != nil {
return nil, errors.Wrap(err, "connect transmission")
}
media := s.db.GetMediaDetails(in.MediaID)
if media == nil {
return nil, fmt.Errorf("no tv series of id %v", in.MediaID)
}
torrent, err := trc.Download(in.Link, s.db.GetDownloadDir())
if err != nil {
return nil, errors.Wrap(err, "downloading")
}
torrent.Start()
go func() {
ep := media.Episodes[0]
history, err := s.db.SaveHistoryRecord(ent.History{
MediaID: media.ID,
EpisodeID: ep.ID,
SourceTitle: media.NameCn,
TargetDir: "./",
Status: history.StatusRunning,
Size: in.Size,
Saved: torrent.Save(),
})
if err != nil {
log.Errorf("save history error: %v", err)
if m.MediaType == media.MediaTypeTv {
if in.Episode == 0 {
//download season package
name := in.Name
if name == "" {
name = fmt.Sprintf("%v S%02d", m.OriginalName, in.Season)
}
res := torznab.Result{Name: name, Link: in.Link, Size: in.Size}
return s.core.DownloadSeasonPackage(res, in.MediaID, in.Season)
}
s.tasks[history.ID] = &Task{Torrent: torrent}
s.db.SetEpisodeStatus(ep.ID, episode.StatusDownloading)
}()
log.Infof("success add %s to download task", media.NameEn)
return media.NameEn, nil
}
type downloadClientIn struct {
Name string `json:"name"`
URL string `json:"url"`
User string `json:"user"`
Password string `json:"password"`
Implementation string `json:"implementation"`
}
func (s *Server) AddDownloadClient(c *gin.Context) (interface{}, error) {
var in downloadClientIn
if err := c.ShouldBindJSON(&in); err != nil {
return nil, errors.Wrap(err, "bind json")
name := in.Name
if name == "" {
name = fmt.Sprintf("%v S%02dE%02d", m.OriginalName, in.Season, in.Episode)
}
res := torznab.Result{Name: name, Link: in.Link, Size: in.Size, IndexerId: in.IndexerId}
return s.core.DownloadEpisodeTorrent(res, in.MediaID, in.Season, in.Episode)
} else {
//movie
return s.core.DownloadMovie(m, in.Link, in.Name, in.Size, in.IndexerId)
}
if err := s.db.SaveTransmission(in.Name, in.URL, in.User, in.Password); err != nil {
return nil, errors.Wrap(err, "save transmission")
}
return nil, nil
}
func (s *Server) GetAllDonloadClients(c *gin.Context) (interface{}, error) {
res := s.db.GetAllDonloadClients()
if len(res) == 0 {
return nil, nil
}
return res, nil
}
func (s *Server) DeleteDownloadCLient(c *gin.Context) (interface{}, error) {
var ids = c.Param("id")
id, err := strconv.Atoi(ids)
if err != nil {
return nil, fmt.Errorf("id is not correct: %v", ids)
}
s.db.DeleteDownloadCLient(id)
return "success", nil
}

Some files were not shown because too many files have changed in this diff Show More