Skip to content

Commit

Permalink
增加warning统计
Browse files Browse the repository at this point in the history
  • Loading branch information
itouakirai authored Sep 15, 2024
1 parent 8391a8c commit c434fb0
Showing 1 changed file with 28 additions and 12 deletions.
40 changes: 28 additions & 12 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand All @@ -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
}
}
Expand Down Expand Up @@ -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
}
Expand All @@ -1714,19 +1724,21 @@ 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
}

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
Expand All @@ -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{
Expand Down Expand Up @@ -1808,23 +1822,26 @@ 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
}
}
if dl_atmos {
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)
}
}
Expand Down Expand Up @@ -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{}
}
}

Expand Down

0 comments on commit c434fb0

Please # to comment.