Skip to content

Commit 17f357e

Browse files
committed
Merge branch 'main' of github.com:simon-ding/polaris
2 parents 7ccc73e + ff2f290 commit 17f357e

File tree

10 files changed

+51
-48
lines changed

10 files changed

+51
-48
lines changed

engine/integration.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,10 @@ func (c *Engine) findEpisodeFilesPreMoving(historyId int) error {
260260
return err
261261
}
262262
for _, id := range episodeIds {
263-
ep, _ := c.db.GetEpisode(his.MediaID, his.SeasonNum, id)
263+
ep, err := c.db.GetEpisode(his.MediaID, his.SeasonNum, id)
264+
if err != nil {
265+
continue
266+
}
264267
task.WalkFunc()(func(path string, info fs.FileInfo) error {
265268
if info.IsDir() {
266269
return nil

engine/resources.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,17 +165,20 @@ func (c *Engine) downloadTorrent(m *ent.Media, r1 torznab.Result, seasonNum int,
165165
c.db.SetSeasonAllEpisodeStatus(m.ID, seasonNum, episode.StatusDownloading)
166166
}
167167

168-
} else {
168+
} else {//movie download
169169
ep, _ := c.db.GetMovieDummyEpisode(m.ID)
170170
if ep.Status == episode.StatusMissing {
171171
c.db.SetEpisodeStatus(ep.ID, episode.StatusDownloading)
172172
}
173173

174174
}
175-
hash, err := utils.Link2Hash(r1.Link)
175+
176+
link, hash, err := utils.GetRealLinkAndHash(r1.Link)
176177
if err != nil {
177178
return nil, errors.Wrap(err, "get hash")
178179
}
180+
r1.Link = link
181+
179182
history, err := c.db.SaveHistoryRecord(ent.History{
180183
MediaID: m.ID,
181184
EpisodeNums: episodeNums,

engine/scheduler.go

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -204,35 +204,37 @@ func getSeasonNum(h *ent.History) int {
204204
}
205205

206206
func (c *Engine) GetEpisodeIds(r *ent.History) []int {
207-
var episodeIds []int
208-
seasonNum := getSeasonNum(r)
209207

210-
// if r.EpisodeID > 0 {
211-
// episodeIds = append(episodeIds, r.EpisodeID)
212-
// }
213208
series, err := c.db.GetMediaDetails(r.MediaID)
214209
if err != nil {
215210
log.Errorf("get media details error: %v", err)
216211
return []int{}
217212
}
218-
219-
if len(r.EpisodeNums) > 0 {
220-
for _, epNum := range r.EpisodeNums {
213+
if series.MediaType == media.MediaTypeMovie { //movie
214+
ep, _ := c.db.GetMovieDummyEpisode(series.ID)
215+
return []int{ep.ID}
216+
} else { //tv
217+
var episodeIds []int
218+
seasonNum := getSeasonNum(r)
219+
220+
if len(r.EpisodeNums) > 0 {
221+
for _, epNum := range r.EpisodeNums {
222+
for _, ep := range series.Episodes {
223+
if ep.SeasonNumber == seasonNum && ep.EpisodeNumber == epNum {
224+
episodeIds = append(episodeIds, ep.ID)
225+
}
226+
}
227+
}
228+
} else {
221229
for _, ep := range series.Episodes {
222-
if ep.SeasonNumber == seasonNum && ep.EpisodeNumber == epNum {
230+
if ep.SeasonNumber == seasonNum {
223231
episodeIds = append(episodeIds, ep.ID)
224232
}
225233
}
226-
}
227-
} else {
228-
for _, ep := range series.Episodes {
229-
if ep.SeasonNumber == seasonNum {
230-
episodeIds = append(episodeIds, ep.ID)
231-
}
232-
}
233234

235+
}
236+
return episodeIds
234237
}
235-
return episodeIds
236238
}
237239

238240
func (c *Engine) moveCompletedTask(id int) (err1 error) {

go.mod

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ require (
1010
github.com/mattn/go-sqlite3 v1.14.22 // indirect
1111
github.com/robfig/cron v1.2.0
1212
go.uber.org/zap v1.27.0
13-
golang.org/x/net v0.37.0
13+
golang.org/x/net v0.38.0
1414
)
1515

1616
require (
@@ -112,7 +112,6 @@ require (
112112
go.opentelemetry.io/otel/trace v1.28.0 // indirect
113113
golang.org/x/sync v0.12.0 // indirect
114114
golang.org/x/time v0.5.0 // indirect
115-
golang.org/x/tools v0.31.0 // indirect
116115
google.golang.org/appengine v1.6.8 // indirect
117116
gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect
118117
gopkg.in/yaml.v2 v2.4.0 // indirect

go.sum

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -278,8 +278,6 @@ github.com/huandu/xstrings v1.3.0/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq
278278
github.com/huandu/xstrings v1.3.1/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE=
279279
github.com/huandu/xstrings v1.3.2 h1:L18LIDzqlW6xN2rEkpdV8+oL/IXWJ1APd+vsdYy4Wdw=
280280
github.com/huandu/xstrings v1.3.2/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE=
281-
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
282-
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
283281
github.com/jordan-wright/email v4.0.1-0.20210109023952-943e75fe5223+incompatible h1:jdpOPRN1zP63Td1hDQbZW73xKmzDvZHzVdNYxhnTMDA=
284282
github.com/jordan-wright/email v4.0.1-0.20210109023952-943e75fe5223+incompatible/go.mod h1:1c7szIrayyPPB/987hsnvNzLushdWf4o/79s3P08L8A=
285283
github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
@@ -317,8 +315,6 @@ github.com/magiconair/properties v1.8.7 h1:IeQXZAiQcpL9mgcAe1Nu6cX9LLw6ExEHKjN0V
317315
github.com/magiconair/properties v1.8.7/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0=
318316
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
319317
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
320-
github.com/mattn/go-runewidth v0.0.9 h1:Lm995f3rfxdpd6TSmuVCHVb/QhupuXlYr8sCI/QdE+0=
321-
github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
322318
github.com/mattn/go-sqlite3 v1.14.22 h1:2gZY6PC6kBnID23Tichd1K+Z0oS6nE/XwU+Vz/5o4kU=
323319
github.com/mattn/go-sqlite3 v1.14.22/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y=
324320
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
@@ -353,8 +349,6 @@ github.com/ncruces/julianday v1.0.0 h1:fH0OKwa7NWvniGQtxdJRxAgkBMolni2BjDHaWTxqt
353349
github.com/ncruces/julianday v1.0.0/go.mod h1:Dusn2KvZrrovOMJuOt0TNXL6tB7U2E8kvza5fFc9G7g=
354350
github.com/nikoksr/notify v1.0.0 h1:qe9/6FRsWdxBgQgWcpvQ0sv8LRGJZDpRB4TkL2uNdO8=
355351
github.com/nikoksr/notify v1.0.0/go.mod h1:hPaaDt30d6LAA7/5nb0e48Bp/MctDfycCSs8VEgN29I=
356-
github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec=
357-
github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY=
358352
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
359353
github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
360354
github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
@@ -459,8 +453,6 @@ github.com/spf13/afero v1.11.0 h1:WJQKhtpdm3v2IzqG8VMqrr6Rf3UYpEF239Jy9wNepM8=
459453
github.com/spf13/afero v1.11.0/go.mod h1:GH9Y3pIexgf1MTIWtNGyogA5MwRIDXGUr+hbWNoBjkY=
460454
github.com/spf13/cast v1.6.0 h1:GEiTHELF+vaR5dhz3VqZfFSzZjYbgeKDpBxQVS4GYJ0=
461455
github.com/spf13/cast v1.6.0/go.mod h1:ancEpBxwJDODSW/UG4rDrAqiKolqNNh2DX3mk86cAdo=
462-
github.com/spf13/cobra v1.7.0 h1:hyqWnYt1ZQShIddO5kBpj3vu05/++x6tJ6dg8EC572I=
463-
github.com/spf13/cobra v1.7.0/go.mod h1:uLxZILRyS/50WlhOIKD7W6V5bgeIt+4sICxh6uRMrb0=
464456
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
465457
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
466458
github.com/spf13/viper v1.19.0 h1:RWq5SEjt8o25SROyN3z2OrDB9l7RPd3lwTWU8EcEdcI=
@@ -580,8 +572,8 @@ golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE=
580572
golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44=
581573
golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM=
582574
golang.org/x/net v0.33.0/go.mod h1:HXLR5J+9DxmrqMwG9qjGCxZ+zKXxBru04zlTvWlWuN4=
583-
golang.org/x/net v0.37.0 h1:1zLorHbz+LYj7MQlSf1+2tPIIgibq2eL5xkrGk6f+2c=
584-
golang.org/x/net v0.37.0/go.mod h1:ivrbrMbzFq5J41QOQh0siUuly180yBYtLp+CKbEaFx8=
575+
golang.org/x/net v0.38.0 h1:vRMAPTMaeGqVhG5QyLJHqNDwecKTomGeqbnfZyKlBI8=
576+
golang.org/x/net v0.38.0/go.mod h1:ivrbrMbzFq5J41QOQh0siUuly180yBYtLp+CKbEaFx8=
585577
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
586578
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
587579
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
@@ -667,10 +659,6 @@ golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc
667659
golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
668660
golang.org/x/tools v0.13.0/go.mod h1:HvlwmtVNQAhOuCjW7xxvovg8wbNq7LwfXh/k7wXUl58=
669661
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d/go.mod h1:aiJjzUbINMkxbQROHiO6hDPo2LHcIPhhQsa9DLh0yGk=
670-
golang.org/x/tools v0.24.0 h1:J1shsA93PJUEVaUSaay7UXAyE8aimq3GW0pjlolpa24=
671-
golang.org/x/tools v0.24.0/go.mod h1:YhNqVBIfWHdzvTLs0d8LCuMhkKUgSUKldakyV7W/WDQ=
672-
golang.org/x/tools v0.31.0 h1:0EedkvKDbh+qistFTd0Bcwe/YLh4vHwWEkiI0toFIBU=
673-
golang.org/x/tools v0.31.0/go.mod h1:naFTU+Cev749tSJRXJlna0T3WxKvb1kWEx15xA4SdmQ=
674662
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
675663
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
676664
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=

pkg/storage/local.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"io/ioutil"
77
"os"
88
"path/filepath"
9+
"polaris/log"
910

1011
"github.com/gabriel-vasile/mimetype"
1112
"github.com/pkg/errors"
@@ -30,6 +31,13 @@ func (l *LocalStorage) Copy(src, destDir string,walkFn WalkFn) error {
3031

3132
baseDest := filepath.Join(l.dir, destDir)
3233
uploadFunc := func(destPath string, destInfo fs.FileInfo, srcReader io.Reader, mimeType *mimetype.MIME) error {
34+
baseDir := filepath.Dir(destPath)
35+
if _, err := os.Stat(baseDir); os.IsNotExist(err) {
36+
if err := os.MkdirAll(baseDir, os.ModePerm); err != nil {
37+
return errors.Wrapf(err, "create dir %s", baseDir)
38+
}
39+
log.Infof("create local dir %s", baseDir)
40+
}
3341
if writer, err := os.OpenFile(destPath, os.O_RDWR|os.O_CREATE|os.O_TRUNC, os.ModePerm); err != nil {
3442
return errors.Wrapf(err, "create file %s", destPath)
3543
} else {

pkg/torznab/torznab.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ func Search(indexer *ent.Indexers, keyWord string) ([]Result, error) {
150150
log.Debugf("not found in cache, need query again: %v", key)
151151
res, err := doRequest(req)
152152
if err != nil {
153-
cc.Set(key, nil)
153+
//cc.Set(key, nil)
154154
return nil, errors.Wrap(err, "do http request")
155155
}
156156
cacheRes = res.ToResults(indexer)

pkg/utils/utils.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -222,9 +222,10 @@ func isWSL() bool {
222222
return strings.Contains(strings.ToLower(string(releaseData)), "microsoft")
223223
}
224224

225-
func Link2Hash(link string) (string, error) {
225+
func GetRealLinkAndHash(link string) (string, string, error) {
226226
if strings.HasPrefix(strings.ToLower(link), "magnet:") {
227-
return MagnetHash(link)
227+
hash, err := MagnetHash(link)
228+
return link, hash, err
228229
}
229230
client := &http.Client{
230231
CheckRedirect: func(req *http.Request, via []*http.Request) error {
@@ -234,19 +235,19 @@ func Link2Hash(link string) (string, error) {
234235

235236
resp, err := client.Get(link)
236237
if err != nil {
237-
return "", errors.Wrap(err, "get link")
238+
return "", "", errors.Wrap(err, "get link")
238239
}
239240
defer resp.Body.Close()
240241
if resp.StatusCode >= 300 && resp.StatusCode < 400 {
241242
//redirects
242243
tourl := resp.Header.Get("Location")
243-
return Link2Hash(tourl)
244+
return GetRealLinkAndHash(tourl)
244245
}
245246
info, err := metainfo.Load(resp.Body)
246247
if err != nil {
247-
return "", errors.Wrap(err, "parse response")
248+
return "", "", errors.Wrap(err, "parse response")
248249
}
249-
return info.HashInfoBytes().HexString(), nil
250+
return link,info.HashInfoBytes().HexString(), nil
250251
}
251252

252253
func Link2Magnet(link string) (string, error) {

pkg/utils/utils_test.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
package utils
22

33
import (
4-
"polaris/log"
54
"testing"
65
)
76

87
func TestLink2Magnet(t *testing.T) {
9-
s, err := Link2Hash("https://api.m-team.io/api/rss/dlv2?useHttps=true&type=ipv6&sign=1a5174668feea2630acfd6a665f41e5c&t=1738468436&tid=901313&uid=346577")
10-
log.Errorf("%v", err)
11-
log.Infof("%v", s)
8+
// s, err := Link2Hash("https://api.m-team.io/api/rss/dlv2?useHttps=true&type=ipv6&sign=1a5174668feea2630acfd6a665f41e5c&t=1738468436&tid=901313&uid=346577")
9+
// log.Errorf("%v", err)
10+
// log.Infof("%v", s)
1211
}

ui/lib/settings/general.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class _GeneralState extends ConsumerState<GeneralSettings> {
4747
FormBuilderTextField(
4848
name: "tmdb_api",
4949
decoration: const InputDecoration(
50-
labelText: "TMDB Api Key", icon: Icon(Icons.key), helperText: "未防止被限流,可以提供自定义的 TMDB Api Key"),
50+
labelText: "TMDB Api Key", icon: Icon(Icons.key), helperText: "为防止被限流,可以提供自定义的 TMDB Api Key"),
5151
//
5252
),
5353
FormBuilderTextField(

0 commit comments

Comments
 (0)