From 89087790dff0211a65e9a7f5120c3aea073a983a Mon Sep 17 00:00:00 2001 From: itouakirai <85016486+itouakirai@users.noreply.github.com> Date: Sun, 15 Sep 2024 04:35:38 +0800 Subject: [PATCH 2/7] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E9=87=8D=E8=AF=95?= =?UTF-8?q?=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.go | 65 +++++++++++++++++++++++++++++++++++---------------------- 1 file changed, 40 insertions(+), 25 deletions(-) diff --git a/main.go b/main.go index 90b8e71..6ea43da 100644 --- a/main.go +++ b/main.go @@ -1594,6 +1594,12 @@ func rip(albumId string, token string, storefront string, userToken string) erro } for trackNum, track := range meta.Data[0].Relationships.Tracks.Data { trackNum++ + if isInArray(okDict[albumId], trackNum) { + //fmt.Println("已完成直接跳过.\n") + trackTotalnum += 1 + oktrackNum += 1 + continue + } if isInArray(selected, trackNum) { trackTotalnum += 1 fmt.Printf("Track %d of %d:\n", trackNum, trackTotal) @@ -1875,36 +1881,45 @@ func main() { os.Args = newArgs } albumTotal := len(os.Args) - for albumNum, url := range os.Args { - fmt.Printf("Album %d of %d:\n", albumNum+1, albumTotal) - var storefront, albumId string - if strings.Contains(url, ".txt") { - txtpath = url - fileName := filepath.Base(url) - parts := strings.SplitN(fileName, "_", 3) - storefront = parts[0] - albumId = parts[1] - } else { - if strings.Contains(url, "/playlist/") { - storefront, albumId = checkUrlPlaylist(url) - txtpath = "" + for { + for albumNum, url := range os.Args { + fmt.Printf("Album %d of %d:\n", albumNum+1, albumTotal) + var storefront, albumId string + 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) - txtpath = "" + if strings.Contains(url, "/playlist/") { + storefront, albumId = checkUrlPlaylist(url) + txtpath = "" + } else { + storefront, albumId = checkUrl(url) + txtpath = "" + } + } + if albumId == "" { + fmt.Printf("Invalid URL: %s\n", url) + continue + } + err = rip(albumId, token, storefront, config.MediaUserToken) + if err != nil { + fmt.Println("Album failed.") + fmt.Println(err) } } - - if albumId == "" { - fmt.Printf("Invalid URL: %s\n", url) - continue - } - err = rip(albumId, token, storefront, config.MediaUserToken) - if err != nil { - fmt.Println("Album failed.") - fmt.Println(err) + fmt.Printf("======= Completed %d/%d ###### %d errors!! =======\n", oktrackNum, trackTotalnum, trackTotalnum-oktrackNum) + if trackTotalnum-oktrackNum == 0 { + break } + fmt.Println("Error detected, press Enter to try again...") + fmt.Scanln() + fmt.Println("Start trying again...") + oktrackNum = 0 + trackTotalnum = 0 } - fmt.Printf("======= Completed %d/%d ###### %d errors!! =======\n", oktrackNum, trackTotalnum, trackTotalnum-oktrackNum) } func conventSyllableTTMLToLRC(ttml string) (string, error) { From 0a2f35c4db6aa3b56500a03edf6c766073ecd6b5 Mon Sep 17 00:00:00 2001 From: itouakirai <85016486+itouakirai@users.noreply.github.com> Date: Sun, 15 Sep 2024 04:46:07 +0800 Subject: [PATCH 3/7] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E9=87=8D=E8=AF=95?= =?UTF-8?q?=E5=8A=9F=E8=83=BD=E5=B0=8Fbug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.go | 1 + 1 file changed, 1 insertion(+) diff --git a/main.go b/main.go index 6ea43da..ae30d1d 100644 --- a/main.go +++ b/main.go @@ -86,6 +86,7 @@ var config Config var txtpath string var oktrackNum int = 0 var trackTotalnum int = 0 +var okDict = make(map[string][]int) type SampleInfo struct { data []byte From fd5b449db9acb4926a6dced412b2352ee116382c Mon Sep 17 00:00:00 2001 From: itouakirai <85016486+itouakirai@users.noreply.github.com> Date: Sun, 15 Sep 2024 09:22:39 +0800 Subject: [PATCH 4/7] Update main.go --- main.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/main.go b/main.go index ae30d1d..9233dd0 100644 --- a/main.go +++ b/main.go @@ -1705,6 +1705,7 @@ func rip(albumId string, token string, storefront string, userToken string) erro if exists { fmt.Println("Track already exists locally.") oktrackNum += 1 + okDict[albumId] = append(okDict[albumId], trackNum) continue } m4aexists, err := fileExists(m4atrackPath) @@ -1714,6 +1715,7 @@ func rip(albumId string, token string, storefront string, userToken string) erro if m4aexists { fmt.Println("Track already exists locally.") oktrackNum += 1 + okDict[albumId] = append(okDict[albumId], trackNum) continue } @@ -1823,6 +1825,7 @@ func rip(albumId string, token string, storefront string, userToken string) erro fmt.Printf("Successfully processed and deleted %s\n", filepath.Base(trackPath)) } oktrackNum += 1 + okDict[albumId] = append(okDict[albumId], trackNum) } } return err From 3861a8c0227747975d3117ff1f7e7e085dbd7db2 Mon Sep 17 00:00:00 2001 From: itouakirai <85016486+itouakirai@users.noreply.github.com> Date: Sun, 15 Sep 2024 09:31:04 +0800 Subject: [PATCH 5/7] Update go.yml --- .github/workflows/go.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 15879c2..47a881b 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -27,7 +27,7 @@ jobs: cp README.md alac/ cp main.exe alac/ - name: Upload apple-music-alac-atmos-downloader - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v4 with: name: apple-music-alac-atmos-downloader-windows path: alac/* @@ -51,7 +51,7 @@ jobs: cp README.md alac/ cp main alac/ - name: Upload apple-music-alac-atmos-downloader - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v4 with: name: apple-music-alac-atmos-downloader-linux path: alac/* From 8391a8cd92e5ef008129dc813b655a637fa8bc90 Mon Sep 17 00:00:00 2001 From: itouakirai <85016486+itouakirai@users.noreply.github.com> Date: Sun, 15 Sep 2024 09:50:56 +0800 Subject: [PATCH 6/7] Update go.yml --- .github/workflows/go.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 47a881b..7ac8729 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -11,9 +11,9 @@ jobs: build-windows: runs-on: windows-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Set up Go - uses: actions/setup-go@v4 + uses: actions/setup-go@v5 with: go-version: '1.20' - name: Build @@ -35,9 +35,9 @@ jobs: build-linux: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Set up Go - uses: actions/setup-go@v4 + uses: actions/setup-go@v5 with: go-version: '1.20' - name: Build From c434fb0517f4579d5d5eb1fc6e6a16ac375b2574 Mon Sep 17 00:00:00 2001 From: itouakirai <85016486+itouakirai@users.noreply.github.com> Date: Mon, 16 Sep 2024 00:12:46 +0800 Subject: [PATCH 7/7] =?UTF-8?q?=E5=A2=9E=E5=8A=A0warning=E7=BB=9F=E8=AE=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.go | 40 ++++++++++++++++++++++++++++------------ 1 file changed, 28 insertions(+), 12 deletions(-) diff --git a/main.go b/main.go index 9233dd0..630995f 100644 --- a/main.go +++ b/main.go @@ -84,8 +84,15 @@ type Config struct { var config Config var txtpath string -var oktrackNum int = 0 -var trackTotalnum int = 0 +//统计结果 +var counter Counter +type Counter struct { + Unavailable int + NotSong int + Error int + Success int + Total int +} var okDict = make(map[string][]int) type SampleInfo struct { @@ -1597,20 +1604,22 @@ func rip(albumId string, token string, storefront string, userToken string) erro trackNum++ if isInArray(okDict[albumId], trackNum) { //fmt.Println("已完成直接跳过.\n") - trackTotalnum += 1 - oktrackNum += 1 + counter.Total++ + counter.Success++ continue } if isInArray(selected, trackNum) { - trackTotalnum += 1 + counter.Total++ fmt.Printf("Track %d of %d:\n", trackNum, trackTotal) manifest, err := getInfoFromAdam(track.ID, token, storefront) if err != nil { fmt.Println("Failed to get manifest.\n", err) + counter.NotSong++ continue } if manifest.Attributes.ExtendedAssetUrls.EnhancedHls == "" { fmt.Println("Unavailable.") + counter.Unavailable++ continue } needCheck := false @@ -1635,6 +1644,7 @@ func rip(albumId string, token string, storefront string, userToken string) erro Quality, err = extractMediaQuality(manifest.Attributes.ExtendedAssetUrls.EnhancedHls) if err != nil { fmt.Println("Failed to extract quality from manifest.\n", err) + counter.Error++ continue } } @@ -1704,7 +1714,7 @@ func rip(albumId string, token string, storefront string, userToken string) erro } if exists { fmt.Println("Track already exists locally.") - oktrackNum += 1 + counter.Success++ okDict[albumId] = append(okDict[albumId], trackNum) continue } @@ -1714,7 +1724,7 @@ func rip(albumId string, token string, storefront string, userToken string) erro } if m4aexists { fmt.Println("Track already exists locally.") - oktrackNum += 1 + counter.Success++ okDict[albumId] = append(okDict[albumId], trackNum) continue } @@ -1722,11 +1732,13 @@ func rip(albumId string, token string, storefront string, userToken string) erro trackUrl, keys, err := extractMedia(manifest.Attributes.ExtendedAssetUrls.EnhancedHls) if err != nil { fmt.Println("Failed to extract info from manifest.\n", err) + counter.Error++ continue } info, err := extractSong(trackUrl) if err != nil { fmt.Println("Failed to extract track.", err) + counter.Error++ continue } samplesOk := true @@ -1743,11 +1755,13 @@ func rip(albumId string, token string, storefront string, userToken string) erro break } if !samplesOk { + counter.Error++ continue } err = decryptSong(info, keys, meta, trackPath, trackNum, trackTotal) if err != nil { fmt.Println("Failed to decrypt track.\n", err) + counter.Error++ continue } tags := []string{ @@ -1808,11 +1822,13 @@ func rip(albumId string, token string, storefront string, userToken string) erro } if err := cmd.Run(); err != nil { fmt.Printf("Embed failed: %v\n", err) + counter.Error++ continue } if strings.Contains(albumId, "pl.") && config.DlAlbumcoverForPlaylist { if err := os.Remove(fmt.Sprintf("%s/%s.%s", sanAlbumFolder, track.ID, config.CoverFormat)); err != nil { fmt.Printf("Error deleting file: %s/%s.%s\n", sanAlbumFolder, track.ID, config.CoverFormat) + counter.Error++ continue } } @@ -1820,11 +1836,12 @@ func rip(albumId string, token string, storefront string, userToken string) erro fmt.Printf("Deleting original EC3 file: %s\n", filepath.Base(trackPath)) if err := os.Remove(trackPath); err != nil { fmt.Printf("Error deleting file: %v\n", err) + counter.Error++ continue } fmt.Printf("Successfully processed and deleted %s\n", filepath.Base(trackPath)) } - oktrackNum += 1 + counter.Success++ okDict[albumId] = append(okDict[albumId], trackNum) } } @@ -1914,15 +1931,14 @@ func main() { fmt.Println(err) } } - fmt.Printf("======= Completed %d/%d ###### %d errors!! =======\n", oktrackNum, trackTotalnum, trackTotalnum-oktrackNum) - if trackTotalnum-oktrackNum == 0 { + fmt.Printf("======= [\u2714 ] Completed: %d/%d | [\u26A0 ] Warnings: %d | [\u2716 ] Errors: %d =======\n", counter.Success, counter.Total, counter.Unavailable+counter.NotSong, counter.Error) + if counter.Error == 0 { break } fmt.Println("Error detected, press Enter to try again...") fmt.Scanln() fmt.Println("Start trying again...") - oktrackNum = 0 - trackTotalnum = 0 + counter = Counter{} } }