不完整音频自动删除

This commit is contained in:
itouakirai 2024-10-19 11:10:52 +08:00 committed by GitHub
parent 370f71cb21
commit d39dd28762
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

27
main.go
View File

@ -1873,14 +1873,26 @@ func rip(albumId string, token string, storefront string, userToken string) erro
} }
} }
if dl_atmos { if dl_atmos {
fmt.Printf("Deleting original EC3 file: %s\n", filepath.Base(trackPath)) //fmt.Printf("Deleting original EC3 file: %s\n", filepath.Base(trackPath))
if err := os.Remove(trackPath); err != nil { if err := os.Remove(trackPath); err != nil {
fmt.Printf("Error deleting file: %v\n", err) fmt.Printf("Error deleting file: %v\n", err)
counter.Error++ counter.Error++
continue continue
} }
fmt.Printf("Successfully processed and deleted %s\n", filepath.Base(trackPath)) fmt.Printf("Successfully processed and deleted %s\n", filepath.Base(trackPath))
trackPath = m4atrackPath
} }
if !(checkSongIntegrity(trackPath, manifest.Attributes.DurationInMillis)) {
fmt.Println("Audio Integrity : Bad")
if err := os.Remove(trackPath); err != nil {
fmt.Printf("Error deleting file: %v\n", err)
counter.Error++
continue
}
counter.Error++
continue
}
fmt.Println("Audio Integrity : OK")
counter.Success++ counter.Success++
okDict[albumId] = append(okDict[albumId], trackNum) okDict[albumId] = append(okDict[albumId], trackNum)
} }
@ -1991,6 +2003,18 @@ func main() {
} }
} }
func checkSongIntegrity(songPath string, duration int) bool {
duration = duration / 1000
starttime := strconv.Itoa(duration - 2)
command := "ffmpeg"
args := []string{"-y", "-v", "error", "-ss", starttime, "-i", songPath, "-map", "0:a", "-c:a", "pcm_s16le", "-f", "null", "NUL"}
cmd := exec.Command(command, args...)
var stderr bytes.Buffer
cmd.Stderr = &stderr
err := cmd.Run()
return err == nil && stderr.Len() == 0
}
func conventSyllableTTMLToLRC(ttml string) (string, error) { func conventSyllableTTMLToLRC(ttml string) (string, error) {
parsedTTML := etree.NewDocument() parsedTTML := etree.NewDocument()
err := parsedTTML.ReadFromString(ttml) err := parsedTTML.ReadFromString(ttml)
@ -2692,6 +2716,7 @@ type SongAttributes struct {
AlbumName string `json:"albumName"` AlbumName string `json:"albumName"`
TrackNumber int `json:"trackNumber"` TrackNumber int `json:"trackNumber"`
ComposerName string `json:"composerName"` ComposerName string `json:"composerName"`
DurationInMillis int `json:"durationInMillis"`
} }
type AlbumAttributes struct { type AlbumAttributes struct {