Add media info filters
This commit is contained in:
@@ -9,6 +9,7 @@ import (
|
||||
|
||||
"github.com/debridmediamanager/zurg/pkg/logutil"
|
||||
"github.com/debridmediamanager/zurg/pkg/utils"
|
||||
"gopkg.in/vansante/go-ffprobe.v2"
|
||||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
|
||||
@@ -96,7 +97,7 @@ func (z *ZurgConfigV1) GetGroupMap() map[string][]string {
|
||||
return result
|
||||
}
|
||||
|
||||
func (z *ZurgConfigV1) MeetsConditions(directory, torrentName string, torrentSize int64, torrentIDs, fileNames []string, fileSizes []int64) bool {
|
||||
func (z *ZurgConfigV1) MeetsConditions(directory, torrentName string, torrentSize int64, torrentIDs, fileNames []string, fileSizes []int64, mediaInfos []*ffprobe.ProbeData) bool {
|
||||
if directory == ALL_TORRENTS {
|
||||
return true
|
||||
}
|
||||
@@ -104,14 +105,14 @@ func (z *ZurgConfigV1) MeetsConditions(directory, torrentName string, torrentSiz
|
||||
return false
|
||||
}
|
||||
for _, filter := range z.Directories[directory].Filters {
|
||||
if z.matchFilter(torrentName, torrentSize, torrentIDs, fileNames, fileSizes, filter) {
|
||||
if z.matchFilter(torrentName, torrentSize, torrentIDs, fileNames, fileSizes, mediaInfos, filter) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (z *ZurgConfigV1) matchFilter(torrentName string, torrentSize int64, torrentIDs, fileNames []string, fileSizes []int64, filter *FilterConditionsV1) bool {
|
||||
func (z *ZurgConfigV1) matchFilter(torrentName string, torrentSize int64, torrentIDs, fileNames []string, fileSizes []int64, mediaInfos []*ffprobe.ProbeData, filter *FilterConditionsV1) bool {
|
||||
if filter.ID != "" {
|
||||
for _, torrentID := range torrentIDs {
|
||||
if torrentID == filter.ID {
|
||||
@@ -160,7 +161,7 @@ func (z *ZurgConfigV1) matchFilter(torrentName string, torrentSize int64, torren
|
||||
if len(filter.And) > 0 {
|
||||
andResult := true
|
||||
for _, andFilter := range filter.And {
|
||||
andResult = andResult && z.matchFilter(torrentName, torrentSize, torrentIDs, fileNames, fileSizes, andFilter)
|
||||
andResult = andResult && z.matchFilter(torrentName, torrentSize, torrentIDs, fileNames, fileSizes, mediaInfos, andFilter)
|
||||
if !andResult {
|
||||
return false
|
||||
}
|
||||
@@ -169,7 +170,7 @@ func (z *ZurgConfigV1) matchFilter(torrentName string, torrentSize int64, torren
|
||||
}
|
||||
if len(filter.Or) > 0 {
|
||||
for _, orFilter := range filter.Or {
|
||||
if z.matchFilter(torrentName, torrentSize, torrentIDs, fileNames, fileSizes, orFilter) {
|
||||
if z.matchFilter(torrentName, torrentSize, torrentIDs, fileNames, fileSizes, mediaInfos, orFilter) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
@@ -292,6 +293,195 @@ func (z *ZurgConfigV1) matchFilter(torrentName string, torrentSize int64, torren
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// media info filters
|
||||
if filter.MediaInfoResolution != "" {
|
||||
for _, mediaInfo := range mediaInfos {
|
||||
for _, stream := range mediaInfo.Streams {
|
||||
if stream.CodecType != "video" || stream.Level <= 0 {
|
||||
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" {
|
||||
return true
|
||||
} else if (stream.Width >= 1920 || stream.Height >= 1080) && filter.MediaInfoResolution == "1080p" {
|
||||
return true
|
||||
} else if (stream.Width >= 1280 || stream.Height >= 720) && filter.MediaInfoResolution == "720p" {
|
||||
return true
|
||||
} else if (stream.Width >= 854 || stream.Height >= 480) && filter.MediaInfoResolution == "480p" {
|
||||
return true
|
||||
} else if (stream.Width >= 640 || stream.Height >= 360) && filter.MediaInfoResolution == "360p" {
|
||||
return true
|
||||
} else if (stream.Width >= 426 || stream.Height >= 240) && filter.MediaInfoResolution == "240p" {
|
||||
return true
|
||||
} else if (stream.Width >= 256 || stream.Height >= 144) && filter.MediaInfoResolution == "144p" {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
if filter.MediaInfoBitRateGreaterThanOrEqual > 0 {
|
||||
for _, mediaInfo := range mediaInfos {
|
||||
bitrate, err := strconv.ParseInt(mediaInfo.Format.BitRate, 10, 64)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
if bitrate >= filter.MediaInfoBitRateGreaterThanOrEqual {
|
||||
return true
|
||||
}
|
||||
}
|
||||
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 {
|
||||
if stream.CodecType != "video" || stream.Level <= 0 {
|
||||
continue
|
||||
}
|
||||
bitrate, err := strconv.ParseInt(stream.BitRate, 10, 64)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
if bitrate >= filter.MediaInfoVideoBitRateGreaterThanOrEqual {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
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 {
|
||||
if stream.CodecType != "audio" {
|
||||
continue
|
||||
}
|
||||
bitrate, err := strconv.ParseInt(stream.BitRate, 10, 64)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
if bitrate >= filter.MediaInfoAudioBitRateGreaterThanOrEqual {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
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 {
|
||||
return true
|
||||
}
|
||||
}
|
||||
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 {
|
||||
if stream.CodecType != "audio" {
|
||||
continue
|
||||
}
|
||||
if strings.EqualFold(stream.Tags.Language, filter.MediaInfoWithAudioLanguage) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
if filter.MediaInfoWithoutAudioLanguage != "" {
|
||||
for _, mediaInfo := range mediaInfos {
|
||||
for _, stream := range mediaInfo.Streams {
|
||||
if stream.CodecType != "audio" {
|
||||
continue
|
||||
}
|
||||
if strings.EqualFold(stream.Tags.Language, filter.MediaInfoWithoutAudioLanguage) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
if filter.MediaInfoWithSubtitleLanguage != "" {
|
||||
for _, mediaInfo := range mediaInfos {
|
||||
for _, stream := range mediaInfo.Streams {
|
||||
if stream.CodecType != "subtitle" {
|
||||
continue
|
||||
}
|
||||
if strings.EqualFold(stream.Tags.Language, filter.MediaInfoWithSubtitleLanguage) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
if filter.MediaInfoWithoutSubtitleLanguage != "" {
|
||||
for _, mediaInfo := range mediaInfos {
|
||||
for _, stream := range mediaInfo.Streams {
|
||||
if stream.CodecType != "subtitle" {
|
||||
continue
|
||||
}
|
||||
if strings.EqualFold(stream.Tags.Language, filter.MediaInfoWithoutSubtitleLanguage) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user