mirror of
https://github.com/simon-ding/polaris.git
synced 2026-02-18 21:10:49 +08:00
Compare commits
16 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
daff2cfcfc | ||
|
|
79ec63bfdb | ||
|
|
bd0ada5897 | ||
|
|
a7dfa2d0f0 | ||
|
|
33f0a5b53f | ||
|
|
1878d6b679 | ||
|
|
627f838ab9 | ||
|
|
215511fab0 | ||
|
|
730db5c94a | ||
|
|
55f5ce329c | ||
|
|
5b2d86d301 | ||
|
|
95708a4c0c | ||
|
|
c41b3026df | ||
|
|
fa84f881a4 | ||
|
|
90ac4cddff | ||
|
|
2c5e4d0530 |
@@ -5,6 +5,8 @@ Polaris 是一个电视剧和电影的追踪软件。配置好了之后,当剧
|
||||

|
||||

|
||||
|
||||
交流群: https://t.me/+8R2nzrlSs2JhMDgx
|
||||
|
||||
## 功能
|
||||
|
||||
- [x] 电视剧自动追踪下载
|
||||
|
||||
15
db/db.go
15
db/db.go
@@ -305,6 +305,21 @@ type StorageInfo struct {
|
||||
Default bool `json:"default"`
|
||||
}
|
||||
|
||||
func (s *StorageInfo) ToWebDavSetting() WebdavSetting {
|
||||
if s.Implementation != storage.ImplementationWebdav.String() {
|
||||
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"],
|
||||
ChangeFileHash: s.Settings["change_file_hash"],
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
type LocalDirSetting struct {
|
||||
TvPath string `json:"tv_path"`
|
||||
MoviePath string `json:"movie_path"`
|
||||
|
||||
43
pkg/metadata/movie.go
Normal file
43
pkg/metadata/movie.go
Normal file
@@ -0,0 +1,43 @@
|
||||
package metadata
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type MovieMetadata struct {
|
||||
NameEn string
|
||||
NameCN string
|
||||
Year int
|
||||
Resolution string
|
||||
}
|
||||
|
||||
func ParseMovie(name string) *MovieMetadata {
|
||||
name = strings.ToLower(strings.TrimSpace(name))
|
||||
var meta = &MovieMetadata{}
|
||||
yearRe := regexp.MustCompile(`\(\d{4}\)`)
|
||||
yearMatches := yearRe.FindAllString(name, -1)
|
||||
var yearIndex = -1
|
||||
if len(yearMatches) > 0 {
|
||||
yearIndex = strings.Index(name, yearMatches[0])
|
||||
y := yearMatches[0][1 : len(yearMatches[0])-1]
|
||||
n, err := strconv.Atoi(y)
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("convert %s error: %v", y, err))
|
||||
}
|
||||
meta.Year = n
|
||||
}
|
||||
if yearIndex != -1 {
|
||||
meta.NameEn = name[:yearIndex]
|
||||
} else {
|
||||
meta.NameEn = name
|
||||
}
|
||||
resRe := regexp.MustCompile(`\d{3,4}p`)
|
||||
resMatches := resRe.FindAllString(name, -1)
|
||||
if len(resMatches) > 0 {
|
||||
meta.Resolution = resMatches[0]
|
||||
}
|
||||
return meta
|
||||
}
|
||||
261
pkg/metadata/tv.go
Normal file
261
pkg/metadata/tv.go
Normal file
@@ -0,0 +1,261 @@
|
||||
package metadata
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"polaris/pkg/utils"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type Metadata struct {
|
||||
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)
|
||||
}
|
||||
if utils.ContainsChineseChar(name) {
|
||||
return parseChineseName(name)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
seasonRe := regexp.MustCompile(`^s\d{1,2}`)
|
||||
resRe := regexp.MustCompile(`^\d{3,4}p`)
|
||||
episodeRe := regexp.MustCompile(`e\d{1,2}`)
|
||||
|
||||
var seasonIndex = -1
|
||||
var episodeIndex = -1
|
||||
var resIndex = -1
|
||||
for i, p := range newSplits {
|
||||
p = strings.TrimSpace(p)
|
||||
if p == "" {
|
||||
continue
|
||||
}
|
||||
if seasonRe.MatchString(p) {
|
||||
//season part
|
||||
seasonIndex = i
|
||||
} else if resRe.MatchString(p) {
|
||||
resIndex = i
|
||||
}
|
||||
if episodeRe.MatchString(p) {
|
||||
episodeIndex = i
|
||||
}
|
||||
}
|
||||
|
||||
meta := &Metadata{
|
||||
Season: -1,
|
||||
Episode: -1,
|
||||
}
|
||||
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
|
||||
|
||||
ssNum := strings.TrimLeft(ss[0], "s")
|
||||
n, err := strconv.Atoi(ssNum)
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("convert %s error: %v", ssNum, err))
|
||||
}
|
||||
meta.Season = n
|
||||
}
|
||||
}
|
||||
if episodeIndex != -1 {
|
||||
ep := episodeRe.FindAllString(newSplits[episodeIndex], -1)
|
||||
if len(ep) > 0 {
|
||||
//episode info exists
|
||||
epNum := strings.TrimLeft(ep[0], "e")
|
||||
n, err := strconv.Atoi(epNum)
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("convert %s error: %v", epNum, err))
|
||||
}
|
||||
meta.Episode = n
|
||||
}
|
||||
}
|
||||
if resIndex != -1 {
|
||||
//resolution exists
|
||||
meta.Resolution = newSplits[resIndex]
|
||||
}
|
||||
if meta.Episode == -1 {
|
||||
meta.IsSeasonPack = true
|
||||
}
|
||||
return meta
|
||||
}
|
||||
|
||||
func parseChineseName(name string) *Metadata {
|
||||
var meta = &Metadata{
|
||||
Season: 1,
|
||||
}
|
||||
//season pack
|
||||
packRe := regexp.MustCompile(`(\d{1,2}-\d{1,2})|(全集)`)
|
||||
if packRe.MatchString(name) {
|
||||
meta.IsSeasonPack = true
|
||||
}
|
||||
//resolution
|
||||
resRe := regexp.MustCompile(`\d{3,4}p`)
|
||||
resMatches := resRe.FindAllString(name, -1)
|
||||
if len(resMatches) != 0 {
|
||||
meta.Resolution = resMatches[0]
|
||||
} else {
|
||||
if strings.Contains(name, "720") {
|
||||
meta.Resolution = "720p"
|
||||
} else if strings.Contains(name, "1080") {
|
||||
meta.Resolution = "1080p"
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//episode number
|
||||
re1 := regexp.MustCompile(`\[\d{1,2}\]`)
|
||||
episodeMatches1 := re1.FindAllString(name, -1)
|
||||
if len(episodeMatches1) > 0 { //[11] [1080p]
|
||||
epNum := strings.TrimRight(strings.TrimLeft(episodeMatches1[0], "["), "]")
|
||||
n, err := strconv.Atoi(epNum)
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("convert %s error: %v", epNum, err))
|
||||
}
|
||||
meta.Episode = n
|
||||
} else { //【第09話】
|
||||
re2 := regexp.MustCompile(`第\d{1,2}(话|話|集)`)
|
||||
episodeMatches1 := re2.FindAllString(name, -1)
|
||||
if len(episodeMatches1) > 0 {
|
||||
re := regexp.MustCompile(`\d{1,2}`)
|
||||
epNum := re.FindAllString(episodeMatches1[0], -1)[0]
|
||||
n, err := strconv.Atoi(epNum)
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("convert %s error: %v", epNum, err))
|
||||
}
|
||||
meta.Episode = n
|
||||
} else { //SHY 靦腆英雄 / Shy -05 ( CR 1920x1080 AVC AAC MKV)
|
||||
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]
|
||||
n, err := strconv.Atoi(epNum)
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("convert %s error: %v", epNum, err))
|
||||
}
|
||||
meta.Episode = n
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//season numner
|
||||
seasonRe1 := regexp.MustCompile(`s\d{1,2}`)
|
||||
seasonMatches := seasonRe1.FindAllString(name, -1)
|
||||
if len(seasonMatches) > 0 {
|
||||
seNum := seasonMatches[0][1:]
|
||||
n, err := strconv.Atoi(seNum)
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("convert %s error: %v", seNum, err))
|
||||
}
|
||||
meta.Season = n
|
||||
} else {
|
||||
seasonRe1 := regexp.MustCompile(`season \d{1,2}`)
|
||||
seasonMatches := seasonRe1.FindAllString(name, -1)
|
||||
if len(seasonMatches) > 0 {
|
||||
re3 := regexp.MustCompile(`\d{1,2}`)
|
||||
seNum := re3.FindAllString(seasonMatches[0], -1)[0]
|
||||
n, err := strconv.Atoi(seNum)
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("convert %s error: %v", seNum, err))
|
||||
}
|
||||
meta.Season = n
|
||||
} else {
|
||||
seasonRe1 := regexp.MustCompile(`第.{1}季`)
|
||||
seasonMatches := seasonRe1.FindAllString(name, -1)
|
||||
if len(seasonMatches) > 0 {
|
||||
se := []rune(seasonMatches[0])
|
||||
seNum := se[1]
|
||||
meta.Season = chinese2Num[string(seNum)]
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if meta.IsSeasonPack && meta.Episode != 0{
|
||||
meta.Season = meta.Episode
|
||||
meta.Episode = -1
|
||||
}
|
||||
|
||||
//tv name
|
||||
title := name
|
||||
|
||||
fields := strings.FieldsFunc(title, func(r rune) bool {
|
||||
return r == '[' || r == ']' || r == '【' || r == '】'
|
||||
})
|
||||
title = ""
|
||||
for _, p := range fields { //寻找匹配的最长的字符串,最有可能是名字
|
||||
if len([]rune(p)) > len([]rune(title)) {
|
||||
title = p
|
||||
}
|
||||
}
|
||||
re := regexp.MustCompile(`[^\p{L}\w\s]`)
|
||||
title = re.ReplaceAllString(strings.TrimSpace(strings.ToLower(title)), "")
|
||||
|
||||
meta.NameCn = title
|
||||
cnRe := regexp.MustCompile(`\p{Han}.*\p{Han}`)
|
||||
cnmatches := cnRe.FindAllString(title, -1)
|
||||
|
||||
if len(cnmatches) > 0 {
|
||||
for _, t := range cnmatches {
|
||||
if len([]rune(t)) > len([]rune(meta.NameCn)) {
|
||||
meta.NameCn = strings.ToLower(t)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
enRe := regexp.MustCompile(`[[:ascii:]]*`)
|
||||
enM := enRe.FindAllString(title, -1)
|
||||
if len(enM) > 0 {
|
||||
for _, t := range enM {
|
||||
if len(t) > len(meta.NameEn) {
|
||||
meta.NameEn = strings.ToLower(t)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return meta
|
||||
}
|
||||
|
||||
var chinese2Num = map[string]int{
|
||||
"一": 1,
|
||||
"二": 2,
|
||||
"三": 3,
|
||||
"四": 4,
|
||||
"五": 5,
|
||||
"六": 6,
|
||||
"七": 7,
|
||||
"八": 8,
|
||||
"九": 9,
|
||||
}
|
||||
@@ -170,7 +170,7 @@ func (c *Client) GetSeasonDetails(id, seasonNumber int, language string) (*tmdb.
|
||||
}
|
||||
|
||||
for i, ep := range detailCN.Episodes {
|
||||
if episodeNameUseful(ep.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
|
||||
}
|
||||
|
||||
@@ -1,12 +1,14 @@
|
||||
package torznab
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/xml"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"polaris/log"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
@@ -59,7 +61,6 @@ type Item struct {
|
||||
Name string `xml:"name,attr"`
|
||||
Value string `xml:"value,attr"`
|
||||
} `xml:"attr"`
|
||||
|
||||
}
|
||||
|
||||
func (i *Item) GetAttr(key string) string {
|
||||
@@ -75,12 +76,12 @@ func (r *Response) ToResults() []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")),
|
||||
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,
|
||||
Source: r.Channel.Title,
|
||||
}
|
||||
res = append(res, r)
|
||||
}
|
||||
@@ -96,7 +97,10 @@ func mustAtoI(key string) int {
|
||||
return i
|
||||
}
|
||||
func Search(torznabUrl, api, keyWord string) ([]Result, error) {
|
||||
req, err := http.NewRequest(http.MethodGet, torznabUrl, nil)
|
||||
ctx, cancel := context.WithTimeout(context.TODO(), 10*time.Second)
|
||||
defer cancel()
|
||||
|
||||
req, err := http.NewRequestWithContext(ctx, http.MethodGet, torznabUrl, nil)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "new request")
|
||||
}
|
||||
@@ -130,5 +134,5 @@ type Result struct {
|
||||
Seeders int
|
||||
Peers int
|
||||
Category int
|
||||
Source string
|
||||
Source string
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ import (
|
||||
"golang.org/x/sys/unix"
|
||||
)
|
||||
|
||||
func isASCII(s string) bool {
|
||||
func IsASCII(s string) bool {
|
||||
for _, c := range s {
|
||||
if c > unicode.MaxASCII {
|
||||
return false
|
||||
@@ -36,7 +36,7 @@ func VerifyPassword(password, hash string) bool {
|
||||
return err == nil
|
||||
}
|
||||
|
||||
func IsChineseChar(str string) bool {
|
||||
func ContainsChineseChar(str string) bool {
|
||||
|
||||
for _, r := range str {
|
||||
if unicode.Is(unicode.Han, r) || (regexp.MustCompile("[\u3002\uff1b\uff0c\uff1a\u201c\u201d\uff08\uff09\u3001\uff1f\u300a\u300b]").MatchString(string(r))) {
|
||||
@@ -61,7 +61,7 @@ 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.1
|
||||
return strutil.Similarity(name1, name2, metrics.NewHamming()) > 0.4
|
||||
}
|
||||
|
||||
func FindSeasonEpisodeNum(name string) (se int, ep int, err error) {
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"fmt"
|
||||
"polaris/ent"
|
||||
"polaris/ent/episode"
|
||||
"polaris/ent/history"
|
||||
"polaris/log"
|
||||
"polaris/pkg/utils"
|
||||
"strconv"
|
||||
@@ -18,9 +19,16 @@ type Activity struct {
|
||||
}
|
||||
|
||||
func (s *Server) GetAllActivities(c *gin.Context) (interface{}, error) {
|
||||
q := c.Query("status")
|
||||
his := s.db.GetHistories()
|
||||
var activities = make([]Activity, 0, len(his))
|
||||
for _, h := range his {
|
||||
if q == "active" && (h.Status != history.StatusRunning && h.Status != history.StatusUploading) {
|
||||
continue //active downloads
|
||||
} else if q == "archive" && (h.Status == history.StatusRunning || h.Status == history.StatusUploading) {
|
||||
continue //archived downloads
|
||||
}
|
||||
|
||||
a := Activity{
|
||||
History: h,
|
||||
}
|
||||
|
||||
@@ -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.Infof("url %v return: %+v", ctx.Request.URL, r)
|
||||
|
||||
ctx.JSON(200, Response{
|
||||
Code: 0,
|
||||
|
||||
@@ -3,46 +3,20 @@ package core
|
||||
import (
|
||||
"fmt"
|
||||
"polaris/db"
|
||||
"polaris/ent"
|
||||
"polaris/ent/media"
|
||||
"polaris/log"
|
||||
"polaris/pkg/metadata"
|
||||
"polaris/pkg/torznab"
|
||||
"polaris/pkg/utils"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
func SearchSeasonPackage(db1 *db.Client, seriesId, seasonNum int, checkResolution bool) ([]torznab.Result, error) {
|
||||
series := db1.GetMediaDetails(seriesId)
|
||||
if series == nil {
|
||||
return nil, fmt.Errorf("no tv series of id %v", seriesId)
|
||||
}
|
||||
q := fmt.Sprintf("%s S%02d", series.NameEn, seasonNum)
|
||||
|
||||
res := searchWithTorznab(db1, q)
|
||||
if len(res) == 0 {
|
||||
return nil, fmt.Errorf("no resource found")
|
||||
}
|
||||
var filtered []torznab.Result
|
||||
for _, r := range res {
|
||||
if !isNameAcceptable(r.Name, series.Media, seasonNum, -1) {
|
||||
continue
|
||||
}
|
||||
if checkResolution && !IsWantedResolution(r.Name, series.Resolution) {
|
||||
continue
|
||||
}
|
||||
|
||||
filtered = append(filtered, r)
|
||||
|
||||
}
|
||||
|
||||
if len(filtered) == 0 {
|
||||
return nil, errors.New("no resource found")
|
||||
}
|
||||
return filtered, nil
|
||||
return SearchEpisode(db1, seriesId, seasonNum, -1, checkResolution)
|
||||
}
|
||||
|
||||
func SearchEpisode(db1 *db.Client, seriesId, seasonNum, episodeNum int, checkResolution bool) ([]torznab.Result, error) {
|
||||
@@ -51,23 +25,30 @@ func SearchEpisode(db1 *db.Client, seriesId, seasonNum, episodeNum int, checkRes
|
||||
return nil, fmt.Errorf("no tv series of id %v", seriesId)
|
||||
}
|
||||
|
||||
q := fmt.Sprintf("%s S%02dE%02d", series.NameEn, seasonNum, episodeNum)
|
||||
res := searchWithTorznab(db1, q)
|
||||
if len(res) == 0 {
|
||||
return nil, fmt.Errorf("no resource found")
|
||||
}
|
||||
res := searchWithTorznab(db1, series.NameEn)
|
||||
resCn := searchWithTorznab(db1, series.NameCn)
|
||||
res = append(res, resCn...)
|
||||
|
||||
var filtered []torznab.Result
|
||||
for _, r := range res {
|
||||
if !isNameAcceptable(r.Name, series.Media, seasonNum, episodeNum) {
|
||||
meta := metadata.ParseTv(r.Name)
|
||||
if meta.Season != seasonNum {
|
||||
continue
|
||||
}
|
||||
if checkResolution && !IsWantedResolution(r.Name, series.Resolution) {
|
||||
if episodeNum != -1 && meta.Episode != episodeNum { //not season pack
|
||||
continue
|
||||
}
|
||||
if checkResolution && meta.Resolution != series.Resolution.String() {
|
||||
continue
|
||||
}
|
||||
if !utils.IsNameAcceptable(meta.NameEn, series.NameEn) && !utils.IsNameAcceptable(meta.NameCn, series.NameCn) {
|
||||
continue
|
||||
}
|
||||
|
||||
filtered = append(filtered, r)
|
||||
}
|
||||
if len(filtered) == 0 {
|
||||
return nil, errors.New("no resource found")
|
||||
}
|
||||
|
||||
return filtered, nil
|
||||
|
||||
@@ -89,10 +70,16 @@ func SearchMovie(db1 *db.Client, movieId int, checkResolution bool) ([]torznab.R
|
||||
}
|
||||
var filtered []torznab.Result
|
||||
for _, r := range res {
|
||||
if !isNameAcceptable(r.Name, movieDetail.Media, -1, -1) {
|
||||
meta := metadata.ParseMovie(r.Name)
|
||||
if !utils.IsNameAcceptable(meta.NameEn, movieDetail.NameEn) {
|
||||
continue
|
||||
}
|
||||
if checkResolution && !IsWantedResolution(r.Name, movieDetail.Resolution) {
|
||||
if checkResolution && meta.Resolution != movieDetail.Resolution.String() {
|
||||
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
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -111,14 +98,32 @@ func searchWithTorznab(db *db.Client, q string) []torznab.Result {
|
||||
|
||||
var res []torznab.Result
|
||||
allTorznab := db.GetAllTorznabInfo()
|
||||
resChan := make(chan []torznab.Result)
|
||||
var wg sync.WaitGroup
|
||||
|
||||
for _, tor := range allTorznab {
|
||||
resp, err := torznab.Search(tor.URL, tor.ApiKey, q)
|
||||
if err != nil {
|
||||
log.Errorf("search %s error: %v", tor.Name, err)
|
||||
continue
|
||||
}
|
||||
res = append(res, resp...)
|
||||
wg.Add(1)
|
||||
go func () {
|
||||
log.Debugf("search torznab %v with %v", tor.Name, q)
|
||||
defer wg.Done()
|
||||
resp, err := torznab.Search(tor.URL, tor.ApiKey, q)
|
||||
if err != nil {
|
||||
log.Errorf("search %s error: %v", tor.Name, err)
|
||||
return
|
||||
}
|
||||
resChan <- resp
|
||||
|
||||
}()
|
||||
}
|
||||
go func() {
|
||||
wg.Wait()
|
||||
close(resChan) // 在所有的worker完成后关闭Channel
|
||||
}()
|
||||
|
||||
for result := range resChan {
|
||||
res = append(res, result...)
|
||||
}
|
||||
|
||||
sort.Slice(res, func(i, j int) bool {
|
||||
var s1 = res[i]
|
||||
var s2 = res[j]
|
||||
@@ -127,53 +132,3 @@ func searchWithTorznab(db *db.Client, q string) []torznab.Result {
|
||||
|
||||
return res
|
||||
}
|
||||
|
||||
func isNameAcceptable(torrentName string, m *ent.Media, seasonNum, episodeNum int) bool {
|
||||
if !utils.IsNameAcceptable(torrentName, m.NameCn) && !utils.IsNameAcceptable(torrentName, m.NameEn) && !utils.IsNameAcceptable(torrentName, m.OriginalName){
|
||||
return false //name not match
|
||||
}
|
||||
|
||||
ss := strings.Split(m.AirDate, "-")[0]
|
||||
year, _ := strconv.Atoi(ss)
|
||||
if m.MediaType == media.MediaTypeMovie {
|
||||
if !strings.Contains(torrentName, strconv.Itoa(year)) && !strings.Contains(torrentName, strconv.Itoa(year+1)) && !strings.Contains(torrentName, strconv.Itoa(year-1)) {
|
||||
return false //not the same movie, if year is not correct
|
||||
}
|
||||
}
|
||||
|
||||
if m.MediaType == media.MediaTypeTv {
|
||||
if episodeNum != -1 {
|
||||
se := fmt.Sprintf("S%02dE%02d", seasonNum, episodeNum)
|
||||
if !utils.ContainsIgnoreCase(torrentName, se) {
|
||||
return false
|
||||
}
|
||||
} else {
|
||||
//season package
|
||||
if !utils.IsSeasonPackageName(torrentName) {
|
||||
return false
|
||||
}
|
||||
|
||||
seNum, err := utils.FindSeasonPackageInfo(torrentName)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
if seNum != seasonNum {
|
||||
return false
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func IsWantedResolution(name string, res media.Resolution) bool {
|
||||
switch res {
|
||||
case media.Resolution720p:
|
||||
return utils.ContainsIgnoreCase(name, "720p")
|
||||
case media.Resolution1080p:
|
||||
return utils.ContainsIgnoreCase(name, "1080p")
|
||||
case media.Resolution4k:
|
||||
return utils.ContainsIgnoreCase(name, "4k") || utils.ContainsIgnoreCase(name, "2160p")
|
||||
}
|
||||
return false
|
||||
}
|
||||
@@ -255,6 +255,9 @@ func (s *Server) SearchAvailableMovies(c *gin.Context) (interface{}, error) {
|
||||
|
||||
res, err := core.SearchMovie(s.db, id, false)
|
||||
if err != nil {
|
||||
if err.Error() == "no resource found" {
|
||||
return []TorznabSearchResult{}, nil
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -269,7 +272,7 @@ func (s *Server) SearchAvailableMovies(c *gin.Context) (interface{}, error) {
|
||||
})
|
||||
}
|
||||
if len(searchResults) == 0 {
|
||||
return nil, errors.New("no resource found")
|
||||
return []TorznabSearchResult{}, nil
|
||||
}
|
||||
return searchResults, nil
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ import (
|
||||
"polaris/pkg/storage"
|
||||
"polaris/pkg/utils"
|
||||
"polaris/server/core"
|
||||
"time"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
@@ -225,14 +226,6 @@ func (s *Server) downloadTvSeries() {
|
||||
if lastEpisode.Title != detail.LastEpisodeToAir.Name {
|
||||
s.db.UpdateEpiode(lastEpisode.ID, detail.LastEpisodeToAir.Name, detail.LastEpisodeToAir.Overview)
|
||||
}
|
||||
if lastEpisode.Status == episode.StatusMissing {
|
||||
name, err := s.searchAndDownload(series.ID, lastEpisode.SeasonNumber, lastEpisode.EpisodeNumber)
|
||||
if err != nil {
|
||||
log.Infof("cannot find resource to download for %s: %v", lastEpisode.Title, err)
|
||||
} else {
|
||||
log.Infof("begin download torrent resource: %v", name)
|
||||
}
|
||||
}
|
||||
|
||||
nextEpisode, err := s.db.GetEpisode(series.ID, detail.NextEpisodeToAir.SeasonNumber, detail.NextEpisodeToAir.EpisodeNumber)
|
||||
if err == nil {
|
||||
@@ -242,6 +235,28 @@ func (s *Server) downloadTvSeries() {
|
||||
}
|
||||
}
|
||||
|
||||
if lastEpisode.Status == episode.StatusMissing {
|
||||
if lastEpisode.AirDate != "" {
|
||||
t, err := time.ParseInLocation("2006-01-02", lastEpisode.AirDate, time.Local)
|
||||
if err != nil {
|
||||
log.Errorf("parse air date error: airdate %v, error %v",lastEpisode.AirDate, err)
|
||||
} else {
|
||||
if series.CreatedAt.Sub(t) > 24*time.Hour { //24h容错时间
|
||||
log.Infof("episode were aired 24h before monitoring, skipping: %v", lastEpisode.Title)
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
name, err := s.searchAndDownload(series.ID, lastEpisode.SeasonNumber, lastEpisode.EpisodeNumber)
|
||||
if err != nil {
|
||||
log.Infof("cannot find resource to download for %s: %v", lastEpisode.Title, err)
|
||||
} else {
|
||||
log.Infof("begin download torrent resource: %v", name)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"fmt"
|
||||
"polaris/db"
|
||||
"polaris/log"
|
||||
"polaris/pkg/storage"
|
||||
"polaris/pkg/utils"
|
||||
"strconv"
|
||||
"strings"
|
||||
@@ -23,6 +24,21 @@ func (s *Server) AddStorage(c *gin.Context) (interface{}, error) {
|
||||
return nil, errors.Wrap(err, "bind json")
|
||||
}
|
||||
|
||||
if in.Implementation == "webdav" {
|
||||
//test webdav
|
||||
wd := in.ToWebDavSetting()
|
||||
st, err := storage.NewWebdavStorage(wd.URL, wd.User, wd.Password, wd.TvPath, false)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "new webdav")
|
||||
}
|
||||
fs, err := st.ReadDir(".")
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "test read")
|
||||
}
|
||||
for _, f := range fs {
|
||||
log.Infof("file name: %v", f.Name())
|
||||
}
|
||||
}
|
||||
log.Infof("received add storage input: %v", in)
|
||||
err := s.db.AddStorage(&in)
|
||||
return nil, err
|
||||
@@ -62,7 +78,7 @@ func (s *Server) SuggestedSeriesFolderName(c *gin.Context) (interface{}, error)
|
||||
}
|
||||
name = fmt.Sprintf("%s %s", name, originalName)
|
||||
|
||||
if !utils.IsChineseChar(name) {
|
||||
if !utils.ContainsChineseChar(name) {
|
||||
name = originalName
|
||||
}
|
||||
if year != "" {
|
||||
|
||||
@@ -5,39 +5,88 @@ import 'package:ui/providers/activity.dart';
|
||||
import 'package:ui/utils.dart';
|
||||
import 'package:ui/widgets/progress_indicator.dart';
|
||||
|
||||
class ActivityPage extends ConsumerWidget {
|
||||
class ActivityPage extends ConsumerStatefulWidget {
|
||||
const ActivityPage({super.key});
|
||||
static const route = "/activities";
|
||||
|
||||
const ActivityPage({super.key});
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
var activitiesWatcher = ref.watch(activitiesDataProvider);
|
||||
_ActivityPageState createState() => _ActivityPageState();
|
||||
}
|
||||
|
||||
return activitiesWatcher.when(
|
||||
data: (activities) {
|
||||
return SingleChildScrollView(
|
||||
child: PaginatedDataTable(
|
||||
rowsPerPage: 10,
|
||||
columns: const [
|
||||
DataColumn(label: Text("#"), numeric: true),
|
||||
DataColumn(label: Text("名称")),
|
||||
DataColumn(label: Text("开始时间")),
|
||||
DataColumn(label: Text("状态")),
|
||||
DataColumn(label: Text("操作"))
|
||||
],
|
||||
source: ActivityDataSource(
|
||||
activities: activities, onDelete: onDelete(ref)),
|
||||
),
|
||||
);
|
||||
},
|
||||
error: (err, trace) => Text("$err"),
|
||||
loading: () => const MyProgressIndicator());
|
||||
class _ActivityPageState extends ConsumerState<ActivityPage>
|
||||
with TickerProviderStateMixin {
|
||||
late TabController _nestedTabController;
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_nestedTabController = new TabController(length: 2, vsync: this);
|
||||
}
|
||||
|
||||
Function(int) onDelete(WidgetRef ref) {
|
||||
@override
|
||||
void dispose() {
|
||||
super.dispose();
|
||||
_nestedTabController.dispose();
|
||||
}
|
||||
|
||||
int selectedTab = 0;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
TabBar(
|
||||
controller: _nestedTabController,
|
||||
isScrollable: true,
|
||||
onTap: (value) {
|
||||
setState(() {
|
||||
selectedTab = value;
|
||||
});
|
||||
},
|
||||
tabs: const <Widget>[
|
||||
Tab(
|
||||
text: "下载中",
|
||||
),
|
||||
Tab(
|
||||
text: "历史记录",
|
||||
),
|
||||
],
|
||||
),
|
||||
Builder(builder: (context) {
|
||||
var activitiesWatcher = ref.watch(activitiesDataProvider("active"));
|
||||
if (selectedTab == 1) {
|
||||
activitiesWatcher = ref.watch(activitiesDataProvider("archive"));
|
||||
}
|
||||
|
||||
return activitiesWatcher.when(
|
||||
data: (activities) {
|
||||
return SingleChildScrollView(
|
||||
child: PaginatedDataTable(
|
||||
rowsPerPage: 10,
|
||||
columns: const [
|
||||
DataColumn(label: Text("#"), numeric: true),
|
||||
DataColumn(label: Text("名称")),
|
||||
DataColumn(label: Text("开始时间")),
|
||||
DataColumn(label: Text("状态")),
|
||||
DataColumn(label: Text("操作"))
|
||||
],
|
||||
source: ActivityDataSource(
|
||||
activities: activities,
|
||||
onDelete: selectedTab == 0 ? onDelete() : null),
|
||||
),
|
||||
);
|
||||
},
|
||||
error: (err, trace) => Text("$err"),
|
||||
loading: () => const MyProgressIndicator());
|
||||
})
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Function(int) onDelete() {
|
||||
return (id) {
|
||||
ref
|
||||
.read(activitiesDataProvider.notifier)
|
||||
.read(activitiesDataProvider("active").notifier)
|
||||
.deleteActivity(id)
|
||||
.whenComplete(() => Utils.showSnakeBar("删除成功"))
|
||||
.onError((error, trace) => Utils.showSnakeBar("删除失败:$error"));
|
||||
@@ -47,8 +96,8 @@ class ActivityPage extends ConsumerWidget {
|
||||
|
||||
class ActivityDataSource extends DataTableSource {
|
||||
List<Activity> activities;
|
||||
Function(int) onDelete;
|
||||
ActivityDataSource({required this.activities, required this.onDelete});
|
||||
Function(int)? onDelete;
|
||||
ActivityDataSource({required this.activities, this.onDelete});
|
||||
|
||||
@override
|
||||
int get rowCount => activities.length;
|
||||
@@ -96,11 +145,13 @@ class ActivityDataSource extends DataTableSource {
|
||||
progressColor: Colors.green,
|
||||
);
|
||||
}()),
|
||||
DataCell(Tooltip(
|
||||
message: "删除任务",
|
||||
child: IconButton(
|
||||
onPressed: () => onDelete(activity.id!),
|
||||
icon: const Icon(Icons.delete))))
|
||||
onDelete != null
|
||||
? DataCell(Tooltip(
|
||||
message: "删除任务",
|
||||
child: IconButton(
|
||||
onPressed: () => onDelete!(activity.id!),
|
||||
icon: const Icon(Icons.delete))))
|
||||
: const DataCell(Text("-"))
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
@@ -225,6 +225,12 @@ class _NestedTabBarState extends ConsumerState<NestedTabBar>
|
||||
} else {
|
||||
return torrents.when(
|
||||
data: (v) {
|
||||
if (v.isEmpty) {
|
||||
return const Center(
|
||||
child: Text("无可用资源"),
|
||||
);
|
||||
}
|
||||
|
||||
return DataTable(
|
||||
columns: const [
|
||||
DataColumn(label: Text("名称")),
|
||||
|
||||
@@ -5,7 +5,7 @@ import 'package:ui/providers/APIs.dart';
|
||||
import 'package:ui/providers/server_response.dart';
|
||||
|
||||
var activitiesDataProvider =
|
||||
AsyncNotifierProvider.autoDispose<ActivityData, List<Activity>>(
|
||||
AsyncNotifierProvider.autoDispose.family<ActivityData, List<Activity>, String>(
|
||||
ActivityData.new);
|
||||
|
||||
var mediaHistoryDataProvider = FutureProvider.autoDispose.family(
|
||||
@@ -24,14 +24,18 @@ var mediaHistoryDataProvider = FutureProvider.autoDispose.family(
|
||||
},
|
||||
);
|
||||
|
||||
class ActivityData extends AutoDisposeAsyncNotifier<List<Activity>> {
|
||||
class ActivityData
|
||||
extends AutoDisposeFamilyAsyncNotifier<List<Activity>, String> {
|
||||
@override
|
||||
FutureOr<List<Activity>> build() async {
|
||||
Timer(
|
||||
const Duration(seconds: 5), ref.invalidateSelf); //Periodically Refresh
|
||||
FutureOr<List<Activity>> build(String arg) async {
|
||||
if (arg == "active") {
|
||||
//refresh active downloads
|
||||
Timer(const Duration(seconds: 5),
|
||||
ref.invalidateSelf); //Periodically Refresh
|
||||
}
|
||||
|
||||
final dio = await APIs.getDio();
|
||||
var resp = await dio.get(APIs.activityUrl);
|
||||
var resp = await dio.get(APIs.activityUrl, queryParameters: {"status": arg});
|
||||
final sp = ServerResponse.fromJson(resp.data);
|
||||
if (sp.code != 0) {
|
||||
throw sp.message;
|
||||
|
||||
@@ -45,7 +45,7 @@ class _TvDetailsPageState extends ConsumerState<TvDetailsPage> {
|
||||
DataCell(Text("${ep.title}")),
|
||||
DataCell(Opacity(
|
||||
opacity: 0.5,
|
||||
child: Text("${ep.airDate}"),
|
||||
child: Text(ep.airDate??"-"),
|
||||
)),
|
||||
DataCell(
|
||||
Opacity(
|
||||
@@ -198,7 +198,7 @@ class _TvDetailsPageState extends ConsumerState<TvDetailsPage> {
|
||||
),
|
||||
const Text(""),
|
||||
Text(
|
||||
details.overview!,
|
||||
details.overview??"",
|
||||
),
|
||||
],
|
||||
)),
|
||||
|
||||
Reference in New Issue
Block a user