From 019689bfe7ed48afd198e4f3aedbc4e439cc6341 Mon Sep 17 00:00:00 2001 From: zhaarey <157944548+zhaarey@users.noreply.github.com> Date: Thu, 30 May 2024 21:17:33 +0800 Subject: [PATCH] add select Sampling rate --- config.yaml | 2 ++ main.go | 17 ++++++++++++----- main_atmos.go | 19 ++++++++++++++----- main_select.go | 17 ++++++++++++----- 4 files changed, 40 insertions(+), 15 deletions(-) diff --git a/config.yaml b/config.yaml index 62ba637..94776ec 100644 --- a/config.yaml +++ b/config.yaml @@ -9,3 +9,5 @@ atmos-save-folder: AM-DL-Atmos downloads check: "" force-api: false get-m3u8-from-device: false +alac-max: 192000 #192000 96000 48000 44100 +atmos-max: 2768 #2768 2448 diff --git a/main.go b/main.go index 9a12145..38b253e 100644 --- a/main.go +++ b/main.go @@ -48,6 +48,7 @@ type Config struct { ForceApi bool `yaml:"force-api"` Check string `yaml:"check"` GetM3u8FromDevice bool `yaml:"get-m3u8-from-device"` + AlacMax int `yaml:"alac-max"` } var config Config @@ -1495,13 +1496,19 @@ func extractMedia(b string) (string, []string, error) { if variant.Codecs == "alac" { split := strings.Split(variant.Audio, "-") length := len(split) - fmt.Printf("%s-bit / %s Hz\n", split[length-1], split[length-2]) - streamUrlTemp, err := masterUrl.Parse(variant.URI) + length_int,err := strconv.Atoi(split[length-2]) if err != nil { - panic(err) + return "", nil, err + } + if length_int <= config.AlacMax{ + fmt.Printf("%s-bit / %s Hz\n", split[length-1], split[length-2]) + streamUrlTemp, err := masterUrl.Parse(variant.URI) + if err != nil { + panic(err) + } + streamUrl = streamUrlTemp + break } - streamUrl = streamUrlTemp - break } } if streamUrl == nil { diff --git a/main_atmos.go b/main_atmos.go index b99094f..3703ea1 100644 --- a/main_atmos.go +++ b/main_atmos.go @@ -44,6 +44,7 @@ type Config struct { CoverFormat string `yaml:"cover-format"` AlacSaveFolder string `yaml:"alac-save-folder"` AtmosSaveFolder string `yaml:"atmos-save-folder"` + AtmosMax int `yaml:"atmos-max"` } var config Config @@ -1363,13 +1364,21 @@ func extractMedia(b string) (string, []string, error) { }) for _, variant := range master.Variants { if variant.Codecs == "ec-3" { - fmt.Printf("%s\n", variant.Audio) - streamUrlTemp, err := masterUrl.Parse(variant.URI) + split := strings.Split(variant.Audio, "-") + length := len(split) + length_int,err := strconv.Atoi(split[length-1]) if err != nil { - panic(err) + return "", nil, err + } + if length_int <= config.AtmosMax{ + fmt.Printf("%s\n", variant.Audio) + streamUrlTemp, err := masterUrl.Parse(variant.URI) + if err != nil { + panic(err) + } + streamUrl = streamUrlTemp + break } - streamUrl = streamUrlTemp - break } } if streamUrl == nil { diff --git a/main_select.go b/main_select.go index 6358c24..a05d19f 100644 --- a/main_select.go +++ b/main_select.go @@ -45,6 +45,7 @@ type Config struct { CoverFormat string `yaml:"cover-format"` AlacSaveFolder string `yaml:"alac-save-folder"` AtmosSaveFolder string `yaml:"atmos-save-folder"` + AlacMax int `yaml:"alac-max"` } var config Config @@ -1415,13 +1416,19 @@ func extractMedia(b string) (string, []string, error) { if variant.Codecs == "alac" { split := strings.Split(variant.Audio, "-") length := len(split) - fmt.Printf("%s-bit / %s Hz\n", split[length-1], split[length-2]) - streamUrlTemp, err := masterUrl.Parse(variant.URI) + length_int,err := strconv.Atoi(split[length-2]) if err != nil { - panic(err) + return "", nil, err + } + if length_int <= config.AlacMax{ + fmt.Printf("%s-bit / %s Hz\n", split[length-1], split[length-2]) + streamUrlTemp, err := masterUrl.Parse(variant.URI) + if err != nil { + panic(err) + } + streamUrl = streamUrlTemp + break } - streamUrl = streamUrlTemp - break } } if streamUrl == nil {