Fix resolution check on media info filter

This commit is contained in:
Ben Adrian Sarmiento
2024-06-20 05:27:41 +02:00
parent 6e07701f9e
commit bc04737ca7
4 changed files with 14 additions and 66 deletions

View File

@@ -33,6 +33,7 @@ type ConfigInterface interface {
GetUsername() string
GetVersion() string
MeetsConditions(directory, torrentName string, torrentSize int64, torrentIDs, fileNames []string, fileSizes []int64, mediaInfos []*ffprobe.ProbeData) bool
ShouldAutoAnalyzeNewTorrents() bool
ShouldForceIPv6() bool
ShouldIgnoreRenames() bool
ShouldServeFromRclone() bool
@@ -43,6 +44,7 @@ type ZurgConfig struct {
Token string `yaml:"token" json:"-"`
ApiTimeoutSecs int `yaml:"api_timeout_secs" json:"api_timeout_secs"`
AutoAnalyzeNewTorrents bool `yaml:"auto_analyze_new_torrents" json:"auto_analyze_new_torrents"`
CanRepair bool `yaml:"enable_repair" json:"enable_repair"`
DownloadsEveryMins int `yaml:"downloads_every_mins" json:"downloads_every_mins"`
DownloadTimeoutSecs int `yaml:"download_timeout_secs" json:"download_timeout_secs"`
@@ -220,3 +222,7 @@ func (z *ZurgConfig) GetNumberOfHosts() int {
}
return z.NumberOfHosts
}
func (z *ZurgConfig) ShouldAutoAnalyzeNewTorrents() bool {
return z.AutoAnalyzeNewTorrents
}

View File

@@ -305,19 +305,19 @@ func (z *ZurgConfigV1) matchFilter(torrentName string, torrentSize int64, torren
continue
} else if (stream.Width >= 7680 || stream.Height >= 4320) && filter.MediaInfoResolution == "8k" {
return true
} else if (stream.Width >= 3840 || stream.Height >= 2160) && filter.MediaInfoResolution == "4k" {
} else if ((stream.Width < 7680 && stream.Width >= 3840) || (stream.Height < 4320 && stream.Height >= 2160)) && filter.MediaInfoResolution == "4k" {
return true
} else if (stream.Width >= 1920 || stream.Height >= 1080) && filter.MediaInfoResolution == "1080p" {
} else if ((stream.Width < 3840 && stream.Width >= 1920) || (stream.Height < 2160 && stream.Height >= 1080)) && filter.MediaInfoResolution == "1080p" {
return true
} else if (stream.Width >= 1280 || stream.Height >= 720) && filter.MediaInfoResolution == "720p" {
} else if ((stream.Width < 1920 && stream.Width >= 1280) || (stream.Height < 1080 && stream.Height >= 720)) && filter.MediaInfoResolution == "720p" {
return true
} else if (stream.Width >= 854 || stream.Height >= 480) && filter.MediaInfoResolution == "480p" {
} else if ((stream.Width < 1280 && stream.Width >= 854) || (stream.Height < 720 && stream.Height >= 480)) && filter.MediaInfoResolution == "480p" {
return true
} else if (stream.Width >= 640 || stream.Height >= 360) && filter.MediaInfoResolution == "360p" {
} else if ((stream.Width < 854 && stream.Width >= 640) || (stream.Height < 480 && stream.Height >= 360)) && filter.MediaInfoResolution == "360p" {
return true
} else if (stream.Width >= 426 || stream.Height >= 240) && filter.MediaInfoResolution == "240p" {
} else if ((stream.Width < 640 && stream.Width >= 426) || (stream.Height < 360 && stream.Height >= 240)) && filter.MediaInfoResolution == "240p" {
return true
} else if (stream.Width >= 256 || stream.Height >= 144) && filter.MediaInfoResolution == "144p" {
} else if ((stream.Width < 426 && stream.Width >= 256) || (stream.Height < 240 && stream.Height >= 144)) && filter.MediaInfoResolution == "144p" {
return true
}
}
@@ -336,18 +336,6 @@ func (z *ZurgConfigV1) matchFilter(torrentName string, torrentSize int64, torren
}
return false
}
if filter.MediaInfoBitRateLessThanOrEqual > 0 {
for _, mediaInfo := range mediaInfos {
bitrate, err := strconv.ParseInt(mediaInfo.Format.BitRate, 10, 64)
if err != nil {
continue
}
if bitrate <= filter.MediaInfoBitRateLessThanOrEqual {
return true
}
}
return false
}
if filter.MediaInfoVideoBitRateGreaterThanOrEqual > 0 {
for _, mediaInfo := range mediaInfos {
for _, stream := range mediaInfo.Streams {
@@ -365,23 +353,6 @@ func (z *ZurgConfigV1) matchFilter(torrentName string, torrentSize int64, torren
}
return false
}
if filter.MediaInfoVideoBitRateLessThanOrEqual > 0 {
for _, mediaInfo := range mediaInfos {
for _, stream := range mediaInfo.Streams {
if stream.CodecType != "video" || stream.Level <= 0 {
continue
}
bitrate, err := strconv.ParseInt(stream.BitRate, 10, 64)
if err != nil {
continue
}
if bitrate <= filter.MediaInfoVideoBitRateLessThanOrEqual {
return true
}
}
}
return false
}
if filter.MediaInfoAudioBitRateGreaterThanOrEqual > 0 {
for _, mediaInfo := range mediaInfos {
for _, stream := range mediaInfo.Streams {
@@ -399,23 +370,6 @@ func (z *ZurgConfigV1) matchFilter(torrentName string, torrentSize int64, torren
}
return false
}
if filter.MediaInfoAudioBitRateLessThanOrEqual > 0 {
for _, mediaInfo := range mediaInfos {
for _, stream := range mediaInfo.Streams {
if stream.CodecType != "audio" {
continue
}
bitrate, err := strconv.ParseInt(stream.BitRate, 10, 64)
if err != nil {
continue
}
if bitrate <= filter.MediaInfoAudioBitRateLessThanOrEqual {
return true
}
}
}
return false
}
if filter.MediaInfoDurationGreaterThanOrEqual > 0 {
for _, mediaInfo := range mediaInfos {
if int64(mediaInfo.Format.DurationSeconds) >= filter.MediaInfoDurationGreaterThanOrEqual {
@@ -424,14 +378,6 @@ func (z *ZurgConfigV1) matchFilter(torrentName string, torrentSize int64, torren
}
return false
}
if filter.MediaInfoDurationLessThanOrEqual > 0 {
for _, mediaInfo := range mediaInfos {
if int64(mediaInfo.Format.DurationSeconds) <= filter.MediaInfoDurationLessThanOrEqual {
return true
}
}
return false
}
if filter.MediaInfoWithAudioLanguage != "" {
for _, mediaInfo := range mediaInfos {
for _, stream := range mediaInfo.Streams {

View File

@@ -45,13 +45,9 @@ type FilterConditionsV1 struct {
MediaInfoResolution string `yaml:"media_info_resolution"` // possible values: 8k 4k 1080p 720p 480p 360p 240p 144p
MediaInfoBitRateGreaterThanOrEqual int64 `yaml:"media_info_bit_rate_gte"` // bytes per second
MediaInfoBitRateLessThanOrEqual int64 `yaml:"media_info_bit_rate_lte"` // bytes per second
MediaInfoVideoBitRateGreaterThanOrEqual int64 `yaml:"media_info_video_bit_rate_gte"` // bytes per second
MediaInfoVideoBitRateLessThanOrEqual int64 `yaml:"media_info_video_bit_rate_lte"` // bytes per second
MediaInfoAudioBitRateGreaterThanOrEqual int64 `yaml:"media_info_audio_bit_rate_gte"` // bytes per second
MediaInfoAudioBitRateLessThanOrEqual int64 `yaml:"media_info_audio_bit_rate_lte"` // bytes per second
MediaInfoDurationGreaterThanOrEqual int64 `yaml:"media_info_duration_gte"` // seconds
MediaInfoDurationLessThanOrEqual int64 `yaml:"media_info_duration_lte"` // seconds
MediaInfoWithAudioLanguage string `yaml:"media_info_with_audio_language"` // 3 char language code
MediaInfoWithoutAudioLanguage string `yaml:"media_info_without_audio_language"` // 3 char language code
MediaInfoWithSubtitleLanguage string `yaml:"media_info_with_subtitle_language"` // 3 char language code

View File

@@ -90,7 +90,7 @@ func (t *TorrentManager) refreshTorrents(initialRun bool) {
// new torrents
t.workerPool.Submit(func() {
if !t.hasFFprobe {
if !t.hasFFprobe || !t.Config.ShouldAutoAnalyzeNewTorrents() {
return
}
freshAccessKeys.Difference(oldKeys).Each(func(accessKey string) bool {