Merge pull request #3 from itouakirai/main

Update main.go
pull/4/head
zhaarey 7 months ago committed by GitHub
commit 3743e8f2b6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 6
      README.md
  2. 22
      main.go
  3. 13
      main_atmos.go
  4. 20
      main_select.go

@ -1,10 +1,10 @@
### !!封装杜比全景声必须先安装[MP4Box](https://gpac.io/downloads/gpac-nightly-builds/),并确认[MP4Box](https://gpac.io/downloads/gpac-nightly-builds/)已正确添加到环境变量 ### !!必须先安装[MP4Box](https://gpac.io/downloads/gpac-nightly-builds/),并确认[MP4Box](https://gpac.io/downloads/gpac-nightly-builds/)已正确添加到环境变量
### 添加功能 ### 添加功能
1. 调用外部MP4Box自动封装ec3为m4a 1. 调用外部MP4Box自动封装ec3为m4a
2. 更改目录结构为 歌手名\专辑名 ;Atmos下载文件则另外移动到AM-DL-Atmos downloads,并更改目录结构为 歌手名\专辑名 [Atmos] 2. 更改目录结构为 歌手名\专辑名 ;Atmos下载文件则另外移动到AM-DL-Atmos downloads,并更改目录结构为 歌手名\专辑名 [Atmos]
3. 运行结束后显示总体完成情况 3. 运行结束后显示总体完成情况
4. 下载LRC歌词 4. 自动内嵌封面和LRC歌词(需要media-user-token,获取方式看最后的说明)
@ -32,4 +32,4 @@ Original script by Sorrow. Modified by me to include some fixes and improvements
3. Find the cookie named `media-user-token` and copy its value 3. Find the cookie named `media-user-token` and copy its value
4. Create a file named `media-user-token.txt` in the project root directory 4. Create a file named `media-user-token.txt` in the project root directory
5. Paste the cookie value obtained in step 3 into the file and save it 5. Paste the cookie value obtained in step 3 into the file and save it
6. Start the script as usual 6. Start the script as usual

@ -13,6 +13,7 @@ import (
"net/http" "net/http"
"net/url" "net/url"
"os" "os"
"os/exec"
"path/filepath" "path/filepath"
"regexp" "regexp"
"sort" "sort"
@ -1103,21 +1104,16 @@ func rip(albumId string, token string, storefront string, userToken string) erro
continue continue
} }
filename := fmt.Sprintf("%02d. %s.m4a", trackNum, forbiddenNames.ReplaceAllString(track.Attributes.Name, "_")) filename := fmt.Sprintf("%02d. %s.m4a", trackNum, forbiddenNames.ReplaceAllString(track.Attributes.Name, "_"))
lrcFilename := fmt.Sprintf("%02d. %s.lrc", trackNum, forbiddenNames.ReplaceAllString(track.Attributes.Name, "_"))
trackPath := filepath.Join(sanAlbumFolder, filename) trackPath := filepath.Join(sanAlbumFolder, filename)
var lrc string = ""
if userToken != "" { if userToken != "" {
ttml, err := getSongLyrics(track.ID, storefront, token, userToken) ttml, err := getSongLyrics(track.ID, storefront, token, userToken)
if err != nil { if err != nil {
fmt.Println("Failed to get lyrics") fmt.Println("Failed to get lyrics")
} else { } else {
lrc, err := conventTTMLToLRC(ttml) lrc, err = conventTTMLToLRC(ttml)
if err != nil { if err != nil {
fmt.Printf("Failed to parse lyrics: %s \n", err) fmt.Printf("Failed to parse lyrics: %s \n", err)
} else {
err := writeLyrics(sanAlbumFolder, lrcFilename, lrc)
if err != nil {
fmt.Printf("Failed to write lyrics")
}
} }
} }
} }
@ -1153,11 +1149,21 @@ func rip(albumId string, token string, storefront string, userToken string) erro
if !samplesOk { if !samplesOk {
continue continue
} }
// err = decryptSong(info, keys, meta, trackPath, trackNum, trackTotal) err = decryptSong(info, keys, meta, trackPath, trackNum, trackTotal)
if err != nil { if err != nil {
fmt.Println("Failed to decrypt track.\n", err) fmt.Println("Failed to decrypt track.\n", err)
continue continue
} }
tags := []string{
fmt.Sprintf("lyrics=%s", lrc),
fmt.Sprintf("cover=%s/cover.jpg", sanAlbumFolder),
}
tagsString := strings.Join(tags, ":")
cmd := exec.Command("MP4Box","-itags", tagsString, trackPath)
if err := cmd.Run(); err != nil {
fmt.Printf("Embed failed: %v\n", err)
continue
}
oktrackNum += 1 oktrackNum += 1
} }
return err return err

@ -1111,7 +1111,7 @@ func rip(albumId string, token string, storefront string, userToken string) erro
} }
filename := fmt.Sprintf("%02d. %s.ec3", trackNum, forbiddenNames.ReplaceAllString(track.Attributes.Name, "_")) filename := fmt.Sprintf("%02d. %s.ec3", trackNum, forbiddenNames.ReplaceAllString(track.Attributes.Name, "_"))
m4afilename := fmt.Sprintf("%02d. %s.m4a", trackNum, forbiddenNames.ReplaceAllString(track.Attributes.Name, "_")) m4afilename := fmt.Sprintf("%02d. %s.m4a", trackNum, forbiddenNames.ReplaceAllString(track.Attributes.Name, "_"))
lrcFilename := fmt.Sprintf("%02d. %s.lrc", trackNum, forbiddenNames.ReplaceAllString(track.Attributes.Name, "_")) //lrcFilename := fmt.Sprintf("%02d. %s.lrc", trackNum, forbiddenNames.ReplaceAllString(track.Attributes.Name, "_"))
trackPath := filepath.Join(sanAlbumFolder, filename) trackPath := filepath.Join(sanAlbumFolder, filename)
m4atrackPath := filepath.Join(sanAlbumFolder, m4afilename) m4atrackPath := filepath.Join(sanAlbumFolder, m4afilename)
exists, err := fileExists(trackPath) exists, err := fileExists(trackPath)
@ -1127,19 +1127,15 @@ func rip(albumId string, token string, storefront string, userToken string) erro
oktrackNum += 1 oktrackNum += 1
continue continue
} }
var lrc string = ""
if userToken != "" { if userToken != "" {
ttml, err := getSongLyrics(track.ID, storefront, token, userToken) ttml, err := getSongLyrics(track.ID, storefront, token, userToken)
if err != nil { if err != nil {
fmt.Println("Failed to get lyrics") fmt.Println("Failed to get lyrics")
} else { } else {
lrc, err := conventTTMLToLRC(ttml) lrc, err = conventTTMLToLRC(ttml)
if err != nil { if err != nil {
fmt.Printf("Failed to parse lyrics: %s \n", err) fmt.Printf("Failed to parse lyrics: %s \n", err)
} else {
err := writeLyrics(sanAlbumFolder, lrcFilename, lrc)
if err != nil {
fmt.Printf("Failed to write lyrics")
}
} }
} }
} }
@ -1174,6 +1170,9 @@ func rip(albumId string, token string, storefront string, userToken string) erro
index := trackNum - 1 index := trackNum - 1
tags := []string{ tags := []string{
"tool=", "tool=",
fmt.Sprintf("lyrics=%s", lrc),
fmt.Sprintf("cover=%s/cover.jpg", sanAlbumFolder),
fmt.Sprintf("album=%s", meta.Data[0].Attributes.Name),
fmt.Sprintf("title=%s", meta.Data[0].Relationships.Tracks.Data[index].Attributes.Name), fmt.Sprintf("title=%s", meta.Data[0].Relationships.Tracks.Data[index].Attributes.Name),
fmt.Sprintf("album=%s", meta.Data[0].Attributes.Name), fmt.Sprintf("album=%s", meta.Data[0].Attributes.Name),
fmt.Sprintf("artist=%s", meta.Data[0].Relationships.Tracks.Data[index].Attributes.ArtistName), fmt.Sprintf("artist=%s", meta.Data[0].Relationships.Tracks.Data[index].Attributes.ArtistName),

@ -15,6 +15,7 @@ import (
"net/http" "net/http"
"net/url" "net/url"
"os" "os"
"os/exec"
"path/filepath" "path/filepath"
"regexp" "regexp"
"sort" "sort"
@ -1139,21 +1140,16 @@ func rip(albumId string, token string, storefront string, userToken string) erro
continue continue
} }
filename := fmt.Sprintf("%02d. %s.m4a", trackNum, forbiddenNames.ReplaceAllString(track.Attributes.Name, "_")) filename := fmt.Sprintf("%02d. %s.m4a", trackNum, forbiddenNames.ReplaceAllString(track.Attributes.Name, "_"))
lrcFilename := fmt.Sprintf("%02d. %s.lrc", trackNum, forbiddenNames.ReplaceAllString(track.Attributes.Name, "_"))
trackPath := filepath.Join(sanAlbumFolder, filename) trackPath := filepath.Join(sanAlbumFolder, filename)
var lrc string = ""
if userToken != "" { if userToken != "" {
ttml, err := getSongLyrics(track.ID, storefront, token, userToken) ttml, err := getSongLyrics(track.ID, storefront, token, userToken)
if err != nil { if err != nil {
fmt.Println("Failed to get lyrics") fmt.Println("Failed to get lyrics")
} else { } else {
lrc, err := conventTTMLToLRC(ttml) lrc, err = conventTTMLToLRC(ttml)
if err != nil { if err != nil {
fmt.Printf("Failed to parse lyrics: %s \n", err) fmt.Printf("Failed to parse lyrics: %s \n", err)
} else {
err := writeLyrics(sanAlbumFolder, lrcFilename, lrc)
if err != nil {
fmt.Printf("Failed to write lyrics")
}
} }
} }
} }
@ -1193,6 +1189,16 @@ func rip(albumId string, token string, storefront string, userToken string) erro
fmt.Println("Failed to decrypt track.\n", err) fmt.Println("Failed to decrypt track.\n", err)
continue continue
} }
tags := []string{
fmt.Sprintf("lyrics=%s", lrc),
fmt.Sprintf("cover=%s/cover.jpg", sanAlbumFolder),
}
tagsString := strings.Join(tags, ":")
cmd := exec.Command("MP4Box","-itags", tagsString, trackPath)
if err := cmd.Run(); err != nil {
fmt.Printf("Embed failed: %v\n", err)
continue
}
} }
} }
return err return err

Loading…
Cancel
Save