- Add support for virtual folders
- Fix minor bug fixes
This commit is contained in:
@@ -67,21 +67,6 @@ type Auth struct {
|
||||
Password string `json:"password,omitempty"`
|
||||
}
|
||||
|
||||
type WebDav struct {
|
||||
TorrentsRefreshInterval string `json:"torrents_refresh_interval,omitempty"`
|
||||
DownloadLinksRefreshInterval string `json:"download_links_refresh_interval,omitempty"`
|
||||
Workers int `json:"workers,omitempty"`
|
||||
AutoExpireLinksAfter string `json:"auto_expire_links_after,omitempty"`
|
||||
|
||||
// Folder
|
||||
FolderNaming string `json:"folder_naming,omitempty"`
|
||||
|
||||
// Rclone
|
||||
RcUrl string `json:"rc_url,omitempty"`
|
||||
RcUser string `json:"rc_user,omitempty"`
|
||||
RcPass string `json:"rc_pass,omitempty"`
|
||||
}
|
||||
|
||||
type Config struct {
|
||||
// server
|
||||
BindAddress string `json:"bind_address,omitempty"`
|
||||
@@ -212,7 +197,7 @@ func (c *Config) GetMinFileSize() int64 {
|
||||
if c.MinFileSize == "" {
|
||||
return 0
|
||||
}
|
||||
s, err := parseSize(c.MinFileSize)
|
||||
s, err := ParseSize(c.MinFileSize)
|
||||
if err != nil {
|
||||
return 0
|
||||
}
|
||||
@@ -224,7 +209,7 @@ func (c *Config) GetMaxFileSize() int64 {
|
||||
if c.MaxFileSize == "" {
|
||||
return 0
|
||||
}
|
||||
s, err := parseSize(c.MaxFileSize)
|
||||
s, err := ParseSize(c.MaxFileSize)
|
||||
if err != nil {
|
||||
return 0
|
||||
}
|
||||
@@ -307,6 +292,19 @@ func (c *Config) updateDebrid(d Debrid) Debrid {
|
||||
if d.AutoExpireLinksAfter == "" {
|
||||
d.AutoExpireLinksAfter = cmp.Or(c.WebDav.AutoExpireLinksAfter, "3d") // 2 days
|
||||
}
|
||||
|
||||
// Merge debrid specified directories with global directories
|
||||
|
||||
directories := c.WebDav.Directories
|
||||
if directories == nil {
|
||||
directories = make(map[string]WebdavDirectories)
|
||||
}
|
||||
|
||||
for name, dir := range d.Directories {
|
||||
directories[name] = dir
|
||||
}
|
||||
d.Directories = directories
|
||||
|
||||
d.RcUrl = cmp.Or(d.RcUrl, c.WebDav.RcUrl)
|
||||
d.RcUser = cmp.Or(d.RcUser, c.WebDav.RcUser)
|
||||
d.RcPass = cmp.Or(d.RcPass, c.WebDav.RcPass)
|
||||
|
||||
@@ -50,7 +50,7 @@ func getDefaultExtensions() []string {
|
||||
return unique
|
||||
}
|
||||
|
||||
func parseSize(sizeStr string) (int64, error) {
|
||||
func ParseSize(sizeStr string) (int64, error) {
|
||||
sizeStr = strings.ToUpper(strings.TrimSpace(sizeStr))
|
||||
|
||||
// Absolute size-based cache
|
||||
|
||||
24
internal/config/webdav.go
Normal file
24
internal/config/webdav.go
Normal file
@@ -0,0 +1,24 @@
|
||||
package config
|
||||
|
||||
type WebdavDirectories struct {
|
||||
Filters map[string]string `json:"filters,omitempty"`
|
||||
//SaveStrms bool `json:"save_streams,omitempty"`
|
||||
}
|
||||
|
||||
type WebDav struct {
|
||||
TorrentsRefreshInterval string `json:"torrents_refresh_interval,omitempty"`
|
||||
DownloadLinksRefreshInterval string `json:"download_links_refresh_interval,omitempty"`
|
||||
Workers int `json:"workers,omitempty"`
|
||||
AutoExpireLinksAfter string `json:"auto_expire_links_after,omitempty"`
|
||||
|
||||
// Folder
|
||||
FolderNaming string `json:"folder_naming,omitempty"`
|
||||
|
||||
// Rclone
|
||||
RcUrl string `json:"rc_url,omitempty"`
|
||||
RcUser string `json:"rc_user,omitempty"`
|
||||
RcPass string `json:"rc_pass,omitempty"`
|
||||
|
||||
// Directories
|
||||
Directories map[string]WebdavDirectories `json:"directories,omitempty"`
|
||||
}
|
||||
@@ -382,29 +382,13 @@ func JSONResponse(w http.ResponseWriter, data interface{}, code int) {
|
||||
}
|
||||
}
|
||||
|
||||
func Gzip(body []byte, pool *sync.Pool) []byte {
|
||||
func Gzip(body []byte) []byte {
|
||||
if len(body) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
var (
|
||||
buf *bytes.Buffer
|
||||
ok bool
|
||||
)
|
||||
|
||||
// Check if the pool is nil
|
||||
if pool == nil {
|
||||
buf = bytes.NewBuffer(make([]byte, 0, len(body)))
|
||||
} else {
|
||||
buf, ok = pool.Get().(*bytes.Buffer)
|
||||
|
||||
if !ok || buf == nil {
|
||||
buf = bytes.NewBuffer(make([]byte, 0, len(body)))
|
||||
} else {
|
||||
buf.Reset()
|
||||
}
|
||||
defer pool.Put(buf)
|
||||
}
|
||||
buf := bytes.NewBuffer(make([]byte, 0, len(body)))
|
||||
|
||||
gz, err := gzip.NewWriterLevel(buf, gzip.BestSpeed)
|
||||
if err != nil {
|
||||
|
||||
@@ -20,6 +20,10 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
var (
|
||||
hexRegex = regexp.MustCompile("^[0-9a-fA-F]{40}$")
|
||||
)
|
||||
|
||||
type Magnet struct {
|
||||
Name string
|
||||
InfoHash string
|
||||
@@ -188,7 +192,6 @@ func ExtractInfoHash(magnetDesc string) string {
|
||||
|
||||
func processInfoHash(input string) (string, error) {
|
||||
// Regular expression for a valid 40-character hex infohash
|
||||
hexRegex := regexp.MustCompile("^[0-9a-fA-F]{40}$")
|
||||
|
||||
// If it's already a valid hex infohash, return it as is
|
||||
if hexRegex.MatchString(input) {
|
||||
|
||||
@@ -7,14 +7,19 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
VIDEOMATCH = "(?i)(\\.)(webm|m4v|3gp|nsv|ty|strm|rm|rmvb|m3u|ifo|mov|qt|divx|xvid|bivx|nrg|pva|wmv|asf|asx|ogm|ogv|m2v|avi|bin|dat|dvr-ms|mpg|mpeg|mp4|avc|vp3|svq3|nuv|viv|dv|fli|flv|wpl|img|iso|vob|mkv|mk3d|ts|wtv|m2ts)$"
|
||||
MUSICMATCH = "(?i)(\\.)(mp2|mp3|m4a|m4b|m4p|ogg|oga|opus|wma|wav|wv|flac|ape|aif|aiff|aifc)$"
|
||||
videoMatch = "(?i)(\\.)(webm|m4v|3gp|nsv|ty|strm|rm|rmvb|m3u|ifo|mov|qt|divx|xvid|bivx|nrg|pva|wmv|asf|asx|ogm|ogv|m2v|avi|bin|dat|dvr-ms|mpg|mpeg|mp4|avc|vp3|svq3|nuv|viv|dv|fli|flv|wpl|img|iso|vob|mkv|mk3d|ts|wtv|m2ts)$"
|
||||
musicMatch = "(?i)(\\.)(mp2|mp3|m4a|m4b|m4p|ogg|oga|opus|wma|wav|wv|flac|ape|aif|aiff|aifc)$"
|
||||
sampleMatch = `(?i)(^|[\s/\\])(sample|trailer|thumb|special|extras?)s?[-/]|(\((sample|trailer|thumb|special|extras?)s?\))|(-\s*(sample|trailer|thumb|special|extras?)s?)`
|
||||
)
|
||||
|
||||
var SAMPLEMATCH = `(?i)(^|[\s/\\])(sample|trailer|thumb|special|extras?)s?[-/]|(\((sample|trailer|thumb|special|extras?)s?\))|(-\s*(sample|trailer|thumb|special|extras?)s?)`
|
||||
var (
|
||||
videoRegex = regexp.MustCompile(videoMatch)
|
||||
musicRegex = regexp.MustCompile(musicMatch)
|
||||
mediaRegex = regexp.MustCompile(videoMatch + "|" + musicMatch)
|
||||
sampleRegex = regexp.MustCompile(sampleMatch)
|
||||
)
|
||||
|
||||
func RegexMatch(regex string, value string) bool {
|
||||
re := regexp.MustCompile(regex)
|
||||
func RegexMatch(re *regexp.Regexp, value string) bool {
|
||||
return re.MatchString(value)
|
||||
}
|
||||
|
||||
@@ -37,10 +42,7 @@ func RemoveInvalidChars(value string) string {
|
||||
}
|
||||
|
||||
func RemoveExtension(value string) string {
|
||||
re := regexp.MustCompile(VIDEOMATCH + "|" + MUSICMATCH)
|
||||
|
||||
// Find the last index of the matched extension
|
||||
loc := re.FindStringIndex(value)
|
||||
loc := mediaRegex.FindStringIndex(value)
|
||||
if loc != nil {
|
||||
return value[:loc[0]]
|
||||
} else {
|
||||
@@ -49,13 +51,12 @@ func RemoveExtension(value string) string {
|
||||
}
|
||||
|
||||
func IsMediaFile(path string) bool {
|
||||
mediaPattern := VIDEOMATCH + "|" + MUSICMATCH
|
||||
return RegexMatch(mediaPattern, path)
|
||||
return RegexMatch(mediaRegex, path)
|
||||
}
|
||||
|
||||
func IsSampleFile(path string) bool {
|
||||
if strings.HasSuffix(strings.ToLower(path), "sample.mkv") {
|
||||
return true
|
||||
}
|
||||
return RegexMatch(SAMPLEMATCH, path)
|
||||
return RegexMatch(sampleRegex, path)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user