mirror of
https://github.com/crunchy-labs/crunchy-cli.git
synced 2026-01-21 12:12:00 -06:00
Added 'worst' and 'best' resolution filter to GetFormat(...)
This commit is contained in:
parent
1c3de9ea93
commit
c557486089
1 changed files with 24 additions and 0 deletions
24
episode.go
24
episode.go
|
|
@ -4,6 +4,8 @@ import (
|
|||
"encoding/json"
|
||||
"fmt"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
|
|
@ -147,11 +149,33 @@ func (e *Episode) GetFormat(resolution string, subtitle LOCALE, hardsub bool) (*
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var res *Format
|
||||
for _, format := range formats {
|
||||
if resolution == "worst" || resolution == "best" {
|
||||
curSplitRes := strings.SplitN(format.Video.Resolution, "x", 1)
|
||||
curResX, _ := strconv.Atoi(curSplitRes[0])
|
||||
curResY, _ := strconv.Atoi(curSplitRes[1])
|
||||
|
||||
resSplitRes := strings.SplitN(res.Video.Resolution, "x", 1)
|
||||
resResX, _ := strconv.Atoi(resSplitRes[0])
|
||||
resResY, _ := strconv.Atoi(resSplitRes[1])
|
||||
|
||||
if resolution == "worst" && curResX+curResY < resResX+resResY {
|
||||
res = format
|
||||
} else if resolution == "best" && curResX+curResY > resResX+resResY {
|
||||
res = format
|
||||
}
|
||||
}
|
||||
|
||||
if format.Video.Resolution == resolution {
|
||||
return format, nil
|
||||
}
|
||||
}
|
||||
|
||||
if res != nil {
|
||||
return res, nil
|
||||
}
|
||||
|
||||
return nil, fmt.Errorf("no matching resolution found")
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue