From d61fb6011fb55a51f749384995203e8f93910ec2 Mon Sep 17 00:00:00 2001 From: itouakirai <85016486+itouakirai@users.noreply.github.com> Date: Wed, 1 May 2024 19:03:30 +0800 Subject: [PATCH 1/2] add m3u8txtfile support --- main.go | 39 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 3 deletions(-) diff --git a/main.go b/main.go index 7333ffd..43ec8c1 100644 --- a/main.go +++ b/main.go @@ -1,6 +1,7 @@ package main import ( + "bufio" "bytes" "encoding/binary" "encoding/json" @@ -47,6 +48,7 @@ type Config struct { } var config Config +var txtpath string var oktrackNum int = 0 var trackTotalnum int = 0 @@ -1174,6 +1176,27 @@ func rip(albumId string, token string, storefront string, userToken string) erro oktrackNum += 1 continue } + if txtpath != "" { + file, err := os.Open(txtpath) + if err != nil { + fmt.Println("cant open txt:", err) + } + defer file.Close() + scanner := bufio.NewScanner(file) + for scanner.Scan() { + line := scanner.Text() + if strings.HasPrefix(line, track.ID) { + parts := strings.SplitN(line, ",", 2) + if len(parts) == 2 { + manifest.Attributes.ExtendedAssetUrls.EnhancedHls=parts[1] + fmt.Println("Found m3u8 from txt") + } + } + } + if err := scanner.Err(); err != nil { + fmt.Println(err) + } + } trackUrl, keys, err := extractMedia(manifest.Attributes.ExtendedAssetUrls.EnhancedHls) if err != nil { fmt.Println("Failed to extract info from manifest.\n", err) @@ -1234,10 +1257,20 @@ func main() { for albumNum, url := range os.Args[1:] { fmt.Printf("Album %d of %d:\n", albumNum+1, albumTotal) var storefront, albumId string - if strings.Contains(url, "/playlist/") { - storefront, albumId = checkUrlPlaylist(url) + if strings.Contains(url, ".txt") { + txtpath = url + fileName := filepath.Base(url) + parts := strings.SplitN(fileName, "_", 3) + storefront = parts[0] + albumId = parts[1] } else { - storefront, albumId = checkUrl(url) + if strings.Contains(url, "/playlist/") { + storefront, albumId = checkUrlPlaylist(url) + txtpath = "" + } else { + storefront, albumId = checkUrl(url) + txtpath = "" + } } if albumId == "" { From 125ab56640297af44f6acbc9c002ced70945420c Mon Sep 17 00:00:00 2001 From: itouakirai <85016486+itouakirai@users.noreply.github.com> Date: Wed, 1 May 2024 19:23:55 +0800 Subject: [PATCH 2/2] Update README.md --- README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/README.md b/README.md index ceb98b2..906c641 100644 --- a/README.md +++ b/README.md @@ -7,8 +7,7 @@ 4. 自动内嵌封面和LRC歌词(需要media-user-token,获取方式看最后的说明) 5. 自动构建 可以到 [Actions](https://github.com/zhaarey/apple-music-alac-atmos-downloader/actions) 页面下载最新自动构建版本 可以直接`main.exe url` 6. main_select 支持手动填写m3u8,输入#号,比如#1 #2,支持txt读取m3u8,输入txt文件名 - - +7. main 支持使用 go run main.go "txt文件地址" txt文件名需要指定格式 例如 cn_1707581102_THE BOOK 3.txt 建议使用这个[Reqable 脚本代码](https://telegra.ph/Reqable-For-Apple-Music-05-01) 自动生成 # Apple Music ALAC / Dolby Atmos Downloader