diff --git a/internal/config/types.go b/internal/config/types.go index 23c0cbd..b1b0672 100644 --- a/internal/config/types.go +++ b/internal/config/types.go @@ -30,40 +30,38 @@ type ConfigInterface interface { GetRateLimitSleepSecs() int ShouldDeleteRarFiles() bool GetDownloadsEveryMins() int + GetPlayableExtensions() []string } type ZurgConfig struct { Version string `yaml:"zurg" json:"-"` Token string `yaml:"token" json:"-"` - Host string `yaml:"host" json:"host"` - Port string `yaml:"port" json:"port"` - Username string `yaml:"username" json:"username"` - Password string `yaml:"password" json:"password"` - Proxy string `yaml:"proxy" json:"proxy"` - NumOfWorkers int `yaml:"concurrent_workers" json:"concurrent_workers"` - RefreshEverySecs int `yaml:"check_for_changes_every_secs" json:"check_for_changes_every_secs"` - RepairEveryMins int `yaml:"repair_every_mins" json:"repair_every_mins"` - DownloadsEveryMins int `yaml:"downloads_every_mins" json:"downloads_every_mins"` - - IgnoreRenames bool `yaml:"ignore_renames" json:"ignore_renames"` - RetainRDTorrentName bool `yaml:"retain_rd_torrent_name" json:"retain_rd_torrent_name"` - RetainFolderNameExtension bool `yaml:"retain_folder_name_extension" json:"retain_folder_name_extension"` - - CanRepair bool `yaml:"enable_repair" json:"enable_repair"` - DeleteRarFiles bool `yaml:"auto_delete_rar_torrents" json:"auto_delete_rar_torrents"` - - ApiTimeoutSecs int `yaml:"api_timeout_secs" json:"api_timeout_secs"` - DownloadTimeoutSecs int `yaml:"download_timeout_secs" json:"download_timeout_secs"` - DownloadMount bool `yaml:"enable_download_mount" json:"enable_download_mount"` - RateLimitSleepSecs int `yaml:"rate_limit_sleep_secs" json:"rate_limit_sleep_secs"` - RetriesUntilFailed int `yaml:"retries_until_failed" json:"retries_until_failed"` - NetworkBufferSize int `yaml:"network_buffer_size" json:"network_buffer_size"` - ServeFromRclone bool `yaml:"serve_from_rclone" json:"serve_from_rclone"` - VerifyDownloadLink bool `yaml:"verify_download_link" json:"verify_download_link"` - ForceIPv6 bool `yaml:"force_ipv6" json:"force_ipv6"` - - OnLibraryUpdate string `yaml:"on_library_update" json:"on_library_update"` + ApiTimeoutSecs int `yaml:"api_timeout_secs" json:"api_timeout_secs"` + CanRepair bool `yaml:"enable_repair" json:"enable_repair"` + DeleteRarFiles bool `yaml:"auto_delete_rar_torrents" json:"auto_delete_rar_torrents"` + DownloadMount bool `yaml:"enable_download_mount" json:"enable_download_mount"` + DownloadsEveryMins int `yaml:"downloads_every_mins" json:"downloads_every_mins"` + DownloadTimeoutSecs int `yaml:"download_timeout_secs" json:"download_timeout_secs"` + ForceIPv6 bool `yaml:"force_ipv6" json:"force_ipv6"` + Host string `yaml:"host" json:"host"` + IgnoreRenames bool `yaml:"ignore_renames" json:"ignore_renames"` + NetworkBufferSize int `yaml:"network_buffer_size" json:"network_buffer_size"` + NumOfWorkers int `yaml:"concurrent_workers" json:"concurrent_workers"` + OnLibraryUpdate string `yaml:"on_library_update" json:"on_library_update"` + Password string `yaml:"password" json:"password"` + PlayableExtensions []string `yaml:"addl_playable_extensions" json:"addl_playable_extensions"` + Port string `yaml:"port" json:"port"` + Proxy string `yaml:"proxy" json:"proxy"` + RateLimitSleepSecs int `yaml:"rate_limit_sleep_secs" json:"rate_limit_sleep_secs"` + RefreshEverySecs int `yaml:"check_for_changes_every_secs" json:"check_for_changes_every_secs"` + RepairEveryMins int `yaml:"repair_every_mins" json:"repair_every_mins"` + RetainFolderNameExtension bool `yaml:"retain_folder_name_extension" json:"retain_folder_name_extension"` + RetainRDTorrentName bool `yaml:"retain_rd_torrent_name" json:"retain_rd_torrent_name"` + RetriesUntilFailed int `yaml:"retries_until_failed" json:"retries_until_failed"` + ServeFromRclone bool `yaml:"serve_from_rclone" json:"serve_from_rclone"` + Username string `yaml:"username" json:"username"` + VerifyDownloadLink bool `yaml:"verify_download_link" json:"verify_download_link"` } func (z *ZurgConfig) GetConfig() ZurgConfig { @@ -202,3 +200,10 @@ func (z *ZurgConfig) GetRateLimitSleepSecs() int { func (z *ZurgConfig) ShouldDeleteRarFiles() bool { return z.DeleteRarFiles } + +func (z *ZurgConfig) GetPlayableExtensions() []string { + if len(z.PlayableExtensions) == 0 { + return []string{} + } + return z.PlayableExtensions +} diff --git a/internal/config/v1.go b/internal/config/v1.go index 46a42d7..bdf73e0 100644 --- a/internal/config/v1.go +++ b/internal/config/v1.go @@ -319,14 +319,14 @@ func checkArithmeticSequenceInFilenames(files []string) bool { } r := regexp.MustCompile(`\d+`) for _, file := range files { - if !utils.IsStreamable(file) { + if !utils.IsPlayable(file) { continue } matches := r.FindAllStringIndex(file, -1) for _, match := range matches { numSet := make(map[int]struct{}) for _, file := range files { - if !utils.IsStreamable(file) { + if !utils.IsPlayable(file) { continue } if match[0] >= 0 && match[1] <= len(file) { diff --git a/internal/torrent/rclone mount flags.txt b/internal/torrent/rclone mount flags.txt new file mode 100644 index 0000000..9b130e6 --- /dev/null +++ b/internal/torrent/rclone mount flags.txt @@ -0,0 +1 @@ +dir-cache-time=10s --vfs-cache-mode full --vfs-read-chunk-size 64M --vfs-read-chunk-size-limit 2G --buffer-size 52M --vfs-cache-max-age 150h --vfs-cache-max-size 370G --vfs-fast-fingerprint diff --git a/internal/torrent/refresh.go b/internal/torrent/refresh.go index 10852ae..a830240 100644 --- a/internal/torrent/refresh.go +++ b/internal/torrent/refresh.go @@ -321,7 +321,7 @@ func (t *TorrentManager) assignedDirectoryCb(tor *Torrent, cb func(string)) { tor.SelectedFiles.IterCb(func(key string, file *File) { filenames = append(filenames, filepath.Base(file.Path)) fileSizes = append(fileSizes, file.Bytes) - if unplayable && utils.IsStreamable(file.Path) { + if unplayable && (utils.IsPlayable(file.Path) || t.IsPlayable(file.Path)) { unplayable = false } }) @@ -343,3 +343,14 @@ func (t *TorrentManager) assignedDirectoryCb(tor *Torrent, cb func(string)) { } } } + +func (t *TorrentManager) IsPlayable(filePath string) bool { + filePath = strings.ToLower(filePath) + playableExts := t.Config.GetPlayableExtensions() + for _, ext := range playableExts { + if strings.HasSuffix(filePath, fmt.Sprintf(".%s", ext)) { + return true + } + } + return false +} diff --git a/pkg/utils/playable.go b/pkg/utils/playable.go new file mode 100644 index 0000000..7ec6350 --- /dev/null +++ b/pkg/utils/playable.go @@ -0,0 +1,15 @@ +package utils + +import "strings" + +func IsPlayable(filePath string) bool { + filePath = strings.ToLower(filePath) + return strings.HasSuffix(filePath, ".avi") || + strings.HasSuffix(filePath, ".m2ts") || + strings.HasSuffix(filePath, ".m4v") || + strings.HasSuffix(filePath, ".mkv") || + strings.HasSuffix(filePath, ".mp4") || + strings.HasSuffix(filePath, ".mpg") || + strings.HasSuffix(filePath, ".ts") || + strings.HasSuffix(filePath, ".wmv") +} diff --git a/pkg/utils/streamable.go b/pkg/utils/streamable.go deleted file mode 100644 index bb02cd5..0000000 --- a/pkg/utils/streamable.go +++ /dev/null @@ -1,13 +0,0 @@ -package utils - -import "strings" - -func IsStreamable(filePath string) bool { - filePath = strings.ToLower(filePath) - return strings.HasSuffix(filePath, ".mkv") || - strings.HasSuffix(filePath, ".mp4") || - strings.HasSuffix(filePath, ".avi") || - strings.HasSuffix(filePath, ".wmv") || - strings.HasSuffix(filePath, ".m4v") || - strings.HasSuffix(filePath, ".ts") -}