To change the filename format so that it omits the beginning part of the codec string (like 56766089_A1461478401_), you need to rename both the .ec3 and the .m4a files accordingly. This can be achieved by adjusting the filename and m4afilename generation in the rip function.
Here's a focused part of the rip function where the filenames are generated and need adjusting:
go
User
ok this is working and can you do one more help ?
Assistant
Of course! I'd be happy to help. Let me know what additional assistance you need.
type SongLyrics struct {
Data []struct {
Id string json:"id"
Type string json:"type"
Attributes struct {
Ttml string json:"ttml"
PlayParams struct {
Id string json:"id"
Kind string json:"kind"
CatalogId string json:"catalogId"
DisplayType int json:"displayType"
} json:"playParams"
} json:"attributes"
} json:"data"
}
Available audio streams:
[0] Codec: mp4a.40.2, Average Bandwidth: 257622, URI: P856766089_A1461478401_audio_en_gr256_mp4a-40-2.m3u8
[1] Codec: mp4a.40.2, Average Bandwidth: 260453, URI: P856766089_A1461478401_audio_en_gr256_mp4a-40-2_dm.m3u8
[2] Codec: mp4a.40.2, Average Bandwidth: 257826, URI: P856766089_A1461478401_audio_en_gr256_mp4a-40-2_bm.m3u8
[3] Codec: ec-3, Average Bandwidth: 770148, URI: P856766089_A1461478401_audio_en_gr2768_mp4a-A6.m3u8
[4] Codec: ec-3, Average Bandwidth: 450148, URI: P856766089_A1461478401_audio_en_gr2448_mp4a-A6.m3u8
[5] Codec: alac, Average Bandwidth: 1674736, URI: P856766089_A1461478401_audio_en_gr2116_alac.m3u8
[6] Codec: mp4a.40.2, Average Bandwidth: 131505, URI: P856766089_A1461478401_audio_en_gr128_mp4a-40-2_dm.m3u8
[7] Codec: mp4a.40.2, Average Bandwidth: 130805, URI: P856766089_A1461478401_audio_en_gr128_mp4a-40-2_bm.m3u8
[8] Codec: mp4a.40.2, Average Bandwidth: 130527, URI: P856766089_A1461478401_audio_en_gr128_mp4a-40-2.m3u8
[9] Codec: mp4a.40.5, Average Bandwidth: 69489, URI: P856766089_A1461478401_audio_en_gr64_mp4a-40-2_dm.m3u8
[10] Codec: mp4a.40.5, Average Bandwidth: 68934, URI: P856766089_A1461478401_audio_en_gr64_mp4a-40-2.m3u8
[11] Codec: mp4a.40.5, Average Bandwidth: 69257, URI: P856766089_A1461478401_audio_en_gr64_mp4a-40-2_bm.m3u8
Enter the number of the audio stream you want to download: 3
codecSuffix: P856766089_A1461478401_audio_en_gr2768_mp4a-A6
newCodecSuffix: 56766089_A1461478401_audio_en_gr2768_mp4a-A6
Downloading...
Downloaded.
Extracting samples.
Samples extracted successfully.
Decrypt start.
Sample size: 3072
Encapsulating 01. Sucker [56765898_A1461478389_audio_en_gr2768_mp4a-A6].ec3 into 01. Sucker [56765898_A1461478389_audio_en_gr2768_mp4a-A6].m4a
Deleting original EC3 file: 01. Sucker [56765898_A1461478389_audio_en_gr2768_mp4a-A6].ec3
Successfully processed and deleted 01. Sucker [56765898_A1461478389_audio_en_gr2768_mp4a-A6].ec3
I need rename like this 01. Sucker [audio_en_gr2768_mp4a-A6].ec3
fix the code and give me part of where to change and what
dont give full function
...
// This part generates the codec suffix
newCodecSuffix := strings.SplitN(codecSuffix, "_", 3)[2] // Adjusted splitting method
fmt.Println("newCodecSuffix: ", newCodecSuffix)
// Generate the filenames after adjusting the codec suffix
filename := fmt.Sprintf("%02d. %s [%s].ec3", trackNum, forbiddenNames.ReplaceAllString(track.Attributes.Name, ""), newCodecSuffix)
m4afilename := fmt.Sprintf("%02d. %s [%s].m4a", trackNum, forbiddenNames.ReplaceAllString(track.Attributes.Name, ""), newCodecSuffix)
...
In the original code, newCodecSuffix is obtained by splitting the codec string into parts based on underscores (_) and then selecting the required substring. Notice the use of "_", 3 in strings.SplitN(codecSuffix, "_", 3).
"_", 3 ensures the string is split into three parts, and [2] picks up just the latter part (omits the first two parts).
In short, adjust the filename and m4afilename as shown above to meet your requirement. This snippet should be inserted within the original rip function where the filenames for the tracks file are being determined.
This adjustment will provide a new suffix string starting from where you desire and rename the files properly without the initial unwanted part.
type SongLyrics struct {
Data []struct {
Id string json:"id"
Type string json:"type"
Attributes struct {
Ttml string json:"ttml"
PlayParams struct {
Id string json:"id"
Kind string json:"kind"
CatalogId string json:"catalogId"
DisplayType int json:"displayType"
} json:"playParams"
} json:"attributes"
} json:"data"
}
Available audio streams:
[0] Codec: mp4a.40.2, Average Bandwidth: 261619, URI: P856766005_A1461478402_audio_en_gr256_mp4a-40-2_dm.m3u8
[1] Codec: mp4a.40.2, Average Bandwidth: 259337, URI: P856766005_A1461478402_audio_en_gr256_mp4a-40-2.m3u8
[2] Codec: mp4a.40.2, Average Bandwidth: 259175, URI: P856766005_A1461478402_audio_en_gr256_mp4a-40-2_bm.m3u8
[3] Codec: ec-3, Average Bandwidth: 770174, URI: P856766005_A1461478402_audio_en_gr2768_mp4a-A6.m3u8
[4] Codec: ec-3, Average Bandwidth: 450174, URI: P856766005_A1461478402_audio_en_gr2448_mp4a-A6.m3u8
[5] Codec: alac, Average Bandwidth: 1705099, URI: P856766005_A1461478402_audio_en_gr2116_alac.m3u8
[6] Codec: mp4a.40.2, Average Bandwidth: 130750, URI: P856766005_A1461478402_audio_en_gr128_mp4a-40-2_dm.m3u8
[7] Codec: mp4a.40.2, Average Bandwidth: 132535, URI: P856766005_A1461478402_audio_en_gr128_mp4a-40-2.m3u8
[8] Codec: mp4a.40.2, Average Bandwidth: 129750, URI: P856766005_A1461478402_audio_en_gr128_mp4a-40-2_bm.m3u8
[9] Codec: mp4a.40.5, Average Bandwidth: 69375, URI: P856766005_A1461478402_audio_en_gr64_mp4a-40-2_bm.m3u8
[10] Codec: mp4a.40.5, Average Bandwidth: 69660, URI: P856766005_A1461478402_audio_en_gr64_mp4a-40-2.m3u8
[11] Codec: mp4a.40.5, Average Bandwidth: 69769, URI: P856766005_A1461478402_audio_en_gr64_mp4a-40-2_dm.m3u8
If i select codec's like other than ec-3 , then i dont need to
Decrypt finished.
Encapsulating 02. Cool [audio_en_gr2768_mp4a-A6].ec3 into 02. Cool [audio_en_gr2768_mp4a-A6].m4a
Deleting original EC3 file: 02. Cool [audio_en_gr2768_mp4a-A6].ec3
Successfully processed and deleted 02. Cool [audio_en_gr2768_mp4a-A6].ec3
even though i select other codec other than ec-3 it is processing as ec3 and convert to m4a
instead if i select other codec other than ec3 it must just download m4a and skip encapsuating, deleting original file, successfully and deleted
To handle the different processing paths based on the codec selected, you need to determine the codec type and decide whether to decrypt, encapsulate, and delete based on this information.
Here's what you need to change and where:
Track the selected codec and type:
Modify the extractMedia function to return the codec and type along with other information.
Add conditional checks based on the selected codec before performing actions specific to EC-3:
Check if the selected codec is ec-3 before performing decryption, encapsulation, and deletion.
Updated Code
Add the selected codec information in extractMedia:
go
func extractMedia(b string) (string, []string, string, string, error) {
// Existing code...
// Display available codecs to the user
fmt.Println("Available audio streams:")
for i, variant := range variants {
fmt.Printf("[%d] Codec: %s, Average Bandwidth: %d, URI: %s\n", i, variant.Codecs, variant.AverageBandwidth, variant.URI)
}
// Existing user input code...
selectedCodec := selectedVariant.Codecs
streamUrl, err := masterUrl.Parse(selectedVariant.URI)
if err != nil {
return "", nil, "", "", err
}
// Creating codec suffix and keys (unchanged)
codecSuffix := strings.TrimSuffix(filepath.Base(selectedVariant.URI), ".m3u8")
fmt.Println("codecSuffix:", codecSuffix)
return streamUrl.String(), keys, codecSuffix, selectedCodec, nil
}
Update the rip function to handle different codecs:
go
func rip(albumId string, token string, storefront string, userToken string, albumURL string) error {
// Existing code...
for trackNum, track := range meta.Data[0].Relationships.Tracks.Data {
// Existing track processing pre-checks...
// Updated call to extractMedia to capture selectedCodec
trackUrl, keys, codecSuffix, selectedCodec, err := extractMedia(manifest.Attributes.ExtendedAssetUrls.EnhancedHls)
if err != nil {
fmt.Println("Failed to extract info from manifest.\n", err)
continue
}
// Filename generation remains same
newCodecSuffix := strings.SplitN(codecSuffix, "_", 3)[2]
filename := fmt.Sprintf("%02d. %s [%s].%s", trackNum, forbiddenNames.ReplaceAllString(track.Attributes.Name, ""), newCodecSuffix, strings.Split(selectedCodec, ".")[0])
trackPath := filepath.Join(sanAlbumFolder, filename)
m4atrackPath := strings.Replace(trackPath, "."+strings.Split(selectedCodec, ".")[0], ".m4a", 1) // Generate m4a path
// Check if the codec is ec-3 for further processing
if selectedCodec == "ec-3" {
// Decrypt the song and encapsulate/decrypt
err = decryptSong(info, keys, meta, trackPath, trackNum, trackTotal)
if err != nil {
fmt.Println("Failed to decrypt track.\n", err)
continue
}
// Existing conversion and delete code
tags := generateTags(meta, track, lrc, sanAlbumFolder, trackNum, trackTotal) // helper function for tags
tagsString := strings.Join(tags, ":")
cmd := exec.Command("MP4Box", "-add", trackPath, "-name", fmt.Sprintf("1=%s", track.Attributes.Name), "-itags", tagsString, "-brand", "mp42", "-ab", "dby1", m4atrackPath)
fmt.Printf("Encapsulating %s into %s\n", filepath.Base(trackPath), filepath.Base(m4atrackPath))
if err := cmd.Run(); err != nil {
fmt.Printf("Error encapsulating file: %v\n", err)
continue
}
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)
continue
}
fmt.Printf("Successfully processed and deleted %s\n", filepath.Base(trackPath))
} else {
// If codec is not the ec-3:
resp, err := http.Get(trackUrl)
if err != nil {
fmt.Println("Failed to download track.")
continue
}
defer resp.Body.Close()
f, err := os.Create(m4atrackPath)
if err != nil {
fmt.Printf("Error creating file %s: %v\n", m4atrackPath, err)
continue
}
defer f.Close()
_, err = io.Copy(f, resp.Body)
if err != nil {
fmt.Printf("Error saving file %s: %v\n", m4atrackPath, err)
continue
}
fmt.Println("Successfully downloaded and saved track as m4a.")
}
oktrackNum += 1
}
return err
}
Helper function for tags generation:
To clean up the rip function, you might want to add the following helper function for tag generation:
With these changes, if a user selects a codec other than ec-3, the track will be directly downloaded and saved as .m4a. If the codec is ec-3, it will go through the decryption, encapsulation, and deletion process as before.
command-line-arguments
.\atms.go:1168:3: m4afilename declared and not used
.\atms.go:1254:9: no new variables on left side of :=
.\atms.go:1296:47: undefined: TrackData
.\atms.go:1413:23: not enough return values
have (string, nil, string, error)
want (string, []string, string, string, error)
.\atms.go:1417:23: not enough return values
have (string, nil, string, error)
want (string, []string, string, string, error)
.\atms.go:1421:23: not enough return values
have (string, nil, string, error)
want (string, []string, string, string, error)
.\atms.go:1425:23: not enough return values
have (string, nil, string, error)
want (string, []string, string, string, error)
.\atms.go:1430:23: not enough return values
have (string, nil, string, error)
want (string, []string, string, string, error)
.\atms.go:1446:23: not enough return values
have (string, nil, string, error)
want (string, []string, string, string, error)
.\atms.go:1451:23: not enough return values
have (string, nil, string, error)
want (string, []string, string, string, error)
.\atms.go:1451:23: too many errors