Skip to content

Commit

Permalink
add get-m3u8-mode
Browse files Browse the repository at this point in the history
  • Loading branch information
zhaarey committed Sep 7, 2024
1 parent 433c962 commit 4e04d96
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 6 deletions.
2 changes: 2 additions & 0 deletions config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ force-api: false
decrypt-m3u8-port: "127.0.0.1:10020"
get-m3u8-port: "127.0.0.1:20020"
get-m3u8-from-device: true
#set 'all' to retrieve all m3u8, and set 'hires' to only detect hires m3u8.
get-m3u8-mode: hires # all hires
alac-max: 192000 #192000 96000 48000 44100
atmos-max: 2768 #2768 2448
limit-max: 200
Expand Down
42 changes: 36 additions & 6 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ type Config struct {
Check string `yaml:"check"`
DecryptM3u8Port string `yaml:"decrypt-m3u8-port"`
GetM3u8Port string `yaml:"get-m3u8-port"`
GetM3u8Mode string `yaml:"get-m3u8-mode"`
GetM3u8FromDevice bool `yaml:"get-m3u8-from-device"`
AlacMax int `yaml:"alac-max"`
AtmosMax int `yaml:"atmos-max"`
Expand Down Expand Up @@ -1353,6 +1354,15 @@ func writeLyrics(sanAlbumFolder, filename string, lrc string) error {
return nil
}

func contains(slice []string, item string) bool {
for _, v := range slice {
if v == item {
return true
}
}
return false
}

func rip(albumId string, token string, storefront string, userToken string) error {
var Codec string
if dl_atmos {
Expand Down Expand Up @@ -1405,9 +1415,19 @@ func rip(albumId string, token string, storefront string, userToken string) erro
if manifest1.Attributes.ExtendedAssetUrls.EnhancedHls == "" {
fmt.Println("Unavailable.\n")
} else {
EnhancedHls_m3u8, err := checkM3u8(meta.Data[0].Relationships.Tracks.Data[0].ID, "album")
if strings.HasSuffix(EnhancedHls_m3u8, ".m3u8") {
manifest1.Attributes.ExtendedAssetUrls.EnhancedHls = EnhancedHls_m3u8
needCheck := false

if config.GetM3u8Mode == "all" {
needCheck = true
} else if config.GetM3u8Mode == "hires" && contains(meta.Data[0].Relationships.Tracks.Data[0].Attributes.AudioTraits, "hi-res-lossless") {
needCheck = true
}
var EnhancedHls_m3u8 string
if needCheck {
EnhancedHls_m3u8, err = checkM3u8(meta.Data[0].Relationships.Tracks.Data[0].ID, "album")
if strings.HasSuffix(EnhancedHls_m3u8, ".m3u8") {
manifest1.Attributes.ExtendedAssetUrls.EnhancedHls = EnhancedHls_m3u8
}
}
Quality, err = extractMediaQuality(manifest1.Attributes.ExtendedAssetUrls.EnhancedHls)
if err != nil {
Expand Down Expand Up @@ -1567,9 +1587,19 @@ func rip(albumId string, token string, storefront string, userToken string) erro
fmt.Println("Unavailable.")
continue
}
EnhancedHls_m3u8, err := checkM3u8(track.ID, "song")
if strings.HasSuffix(EnhancedHls_m3u8, ".m3u8") {
manifest.Attributes.ExtendedAssetUrls.EnhancedHls = EnhancedHls_m3u8
needCheck := false

if config.GetM3u8Mode == "all" {
needCheck = true
} else if config.GetM3u8Mode == "hires" && contains(track.Attributes.AudioTraits, "hi-res-lossless") {
needCheck = true
}
var EnhancedHls_m3u8 string
if needCheck {
EnhancedHls_m3u8, err = checkM3u8(track.ID, "song")
if strings.HasSuffix(EnhancedHls_m3u8, ".m3u8") {
manifest.Attributes.ExtendedAssetUrls.EnhancedHls = EnhancedHls_m3u8
}
}
var Quality string
if strings.Contains(config.SongFileFormat, "Quality") {
Expand Down

0 comments on commit 4e04d96

Please sign in to comment.