优化表格输出
This commit is contained in:
parent
6e97d1e96c
commit
1bac36fe92
2
go.mod
2
go.mod
@ -51,6 +51,7 @@ require (
|
|||||||
github.com/klauspost/pgzip v1.2.6 // indirect
|
github.com/klauspost/pgzip v1.2.6 // indirect
|
||||||
github.com/kr/pretty v0.2.1 // indirect
|
github.com/kr/pretty v0.2.1 // indirect
|
||||||
github.com/libdns/libdns v0.2.2 // indirect
|
github.com/libdns/libdns v0.2.2 // indirect
|
||||||
|
github.com/mattn/go-runewidth v0.0.9 // indirect
|
||||||
github.com/mholt/acmez/v3 v3.0.0 // indirect
|
github.com/mholt/acmez/v3 v3.0.0 // indirect
|
||||||
github.com/mholt/archives v0.1.0 // indirect
|
github.com/mholt/archives v0.1.0 // indirect
|
||||||
github.com/miekg/dns v1.1.62 // indirect
|
github.com/miekg/dns v1.1.62 // indirect
|
||||||
@ -93,6 +94,7 @@ require (
|
|||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/beevik/etree v1.3.0
|
github.com/beevik/etree v1.3.0
|
||||||
|
github.com/olekukonko/tablewriter v0.0.5
|
||||||
github.com/zhaarey/go-mp4tag v0.0.0-20250210094042-22578afc09bf
|
github.com/zhaarey/go-mp4tag v0.0.0-20250210094042-22578afc09bf
|
||||||
gopkg.in/yaml.v2 v2.2.8
|
gopkg.in/yaml.v2 v2.2.8
|
||||||
)
|
)
|
||||||
|
4
go.sum
4
go.sum
@ -166,6 +166,8 @@ github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
|
|||||||
github.com/libdns/libdns v0.2.2 h1:O6ws7bAfRPaBsgAYt8MDe2HcNBGC29hkZ9MX2eUSX3s=
|
github.com/libdns/libdns v0.2.2 h1:O6ws7bAfRPaBsgAYt8MDe2HcNBGC29hkZ9MX2eUSX3s=
|
||||||
github.com/libdns/libdns v0.2.2/go.mod h1:4Bj9+5CQiNMVGf87wjX4CY3HQJypUHRuLvlsfsZqLWQ=
|
github.com/libdns/libdns v0.2.2/go.mod h1:4Bj9+5CQiNMVGf87wjX4CY3HQJypUHRuLvlsfsZqLWQ=
|
||||||
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
|
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
|
||||||
|
github.com/mattn/go-runewidth v0.0.9 h1:Lm995f3rfxdpd6TSmuVCHVb/QhupuXlYr8sCI/QdE+0=
|
||||||
|
github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
|
||||||
github.com/mholt/acmez/v3 v3.0.0 h1:r1NcjuWR0VaKP2BTjDK9LRFBw/WvURx3jlaEUl9Ht8E=
|
github.com/mholt/acmez/v3 v3.0.0 h1:r1NcjuWR0VaKP2BTjDK9LRFBw/WvURx3jlaEUl9Ht8E=
|
||||||
github.com/mholt/acmez/v3 v3.0.0/go.mod h1:L1wOU06KKvq7tswuMDwKdcHeKpFFgkppZy/y0DFxagQ=
|
github.com/mholt/acmez/v3 v3.0.0/go.mod h1:L1wOU06KKvq7tswuMDwKdcHeKpFFgkppZy/y0DFxagQ=
|
||||||
github.com/mholt/archives v0.1.0 h1:FacgJyrjiuyomTuNA92X5GyRBRZjE43Y/lrzKIlF35Q=
|
github.com/mholt/archives v0.1.0 h1:FacgJyrjiuyomTuNA92X5GyRBRZjE43Y/lrzKIlF35Q=
|
||||||
@ -181,6 +183,8 @@ github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9G
|
|||||||
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
|
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
|
||||||
github.com/nwaples/rardecode/v2 v2.0.1 h1:3MN6/R+Y4c7e+21U3yhWuUcf72sYmcmr6jtiuAVSH1A=
|
github.com/nwaples/rardecode/v2 v2.0.1 h1:3MN6/R+Y4c7e+21U3yhWuUcf72sYmcmr6jtiuAVSH1A=
|
||||||
github.com/nwaples/rardecode/v2 v2.0.1/go.mod h1:yntwv/HfMc/Hbvtq9I19D1n58te3h6KsqCf3GxyfBGY=
|
github.com/nwaples/rardecode/v2 v2.0.1/go.mod h1:yntwv/HfMc/Hbvtq9I19D1n58te3h6KsqCf3GxyfBGY=
|
||||||
|
github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec=
|
||||||
|
github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY=
|
||||||
github.com/onsi/ginkgo/v2 v2.22.2 h1:/3X8Panh8/WwhU/3Ssa6rCKqPLuAkVY2I0RoyDLySlU=
|
github.com/onsi/ginkgo/v2 v2.22.2 h1:/3X8Panh8/WwhU/3Ssa6rCKqPLuAkVY2I0RoyDLySlU=
|
||||||
github.com/onsi/ginkgo/v2 v2.22.2/go.mod h1:oeMosUL+8LtarXBHu/c0bx2D/K9zyQ6uX3cTyztHwsk=
|
github.com/onsi/ginkgo/v2 v2.22.2/go.mod h1:oeMosUL+8LtarXBHu/c0bx2D/K9zyQ6uX3cTyztHwsk=
|
||||||
github.com/onsi/gomega v1.36.2 h1:koNYke6TVk6ZmnyHrCXba/T/MoLBXFjeC1PtvYgw0A8=
|
github.com/onsi/gomega v1.36.2 h1:koNYke6TVk6ZmnyHrCXba/T/MoLBXFjeC1PtvYgw0A8=
|
||||||
|
62
main.go
62
main.go
@ -20,18 +20,17 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/spf13/pflag"
|
|
||||||
"github.com/zhaarey/go-mp4tag"
|
|
||||||
|
|
||||||
"gopkg.in/yaml.v2"
|
|
||||||
|
|
||||||
"github.com/beevik/etree"
|
|
||||||
"github.com/grafov/m3u8"
|
|
||||||
|
|
||||||
"main/utils/runv2"
|
"main/utils/runv2"
|
||||||
"main/utils/structs"
|
"main/utils/structs"
|
||||||
|
|
||||||
"main/utils/runv3"
|
"main/utils/runv3"
|
||||||
|
|
||||||
|
"github.com/spf13/pflag"
|
||||||
|
"github.com/zhaarey/go-mp4tag"
|
||||||
|
"gopkg.in/yaml.v2"
|
||||||
|
"github.com/beevik/etree"
|
||||||
|
"github.com/grafov/m3u8"
|
||||||
|
"github.com/olekukonko/tablewriter"
|
||||||
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -185,10 +184,10 @@ func getUrlArtistName(artistUrl string, token string) (string, string, error) {
|
|||||||
func checkArtist(artistUrl string, token string, relationship string) ([]string, error) {
|
func checkArtist(artistUrl string, token string, relationship string) ([]string, error) {
|
||||||
storefront, artistId := checkUrlArtist(artistUrl)
|
storefront, artistId := checkUrlArtist(artistUrl)
|
||||||
Num := 0
|
Num := 0
|
||||||
|
id := 1
|
||||||
var args []string
|
var args []string
|
||||||
var urls []string
|
var urls []string
|
||||||
var options []string
|
var options [][]string
|
||||||
for {
|
for {
|
||||||
req, err := http.NewRequest("GET", fmt.Sprintf("https://amp-api.music.apple.com/v1/catalog/%s/artists/%s/%s?limit=100&offset=%d&l=%s", storefront, artistId, relationship, Num, Config.Language), nil)
|
req, err := http.NewRequest("GET", fmt.Sprintf("https://amp-api.music.apple.com/v1/catalog/%s/artists/%s/%s?limit=100&offset=%d&l=%s", storefront, artistId, relationship, Num, Config.Language), nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -212,22 +211,30 @@ func checkArtist(artistUrl string, token string, relationship string) ([]string,
|
|||||||
}
|
}
|
||||||
for _, album := range obj.Data {
|
for _, album := range obj.Data {
|
||||||
urls = append(urls, album.Attributes.URL)
|
urls = append(urls, album.Attributes.URL)
|
||||||
options = append(options, fmt.Sprintf("%s(%s)", album.Attributes.Name, album.ID))
|
//strings.Join(album.Attributes.AudioTraits, ";")
|
||||||
|
options = append(options, []string{fmt.Sprintf("%d", id), album.Attributes.Name, album.Attributes.ReleaseDate, album.ID})
|
||||||
|
id += 1
|
||||||
}
|
}
|
||||||
Num = Num + 100
|
Num = Num + 100
|
||||||
if len(obj.Next) == 0 {
|
if len(obj.Next) == 0 {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for i, option := range options {
|
|
||||||
fmt.Printf("%02d: %s\n", i+1, option)
|
table := tablewriter.NewWriter(os.Stdout)
|
||||||
}
|
table.SetHeader([]string{"", "Name", "Date", "Album ID"})
|
||||||
|
//table.SetFooter([]string{"", "", "Total", "$146.93"})
|
||||||
|
//table.SetAutoMergeCells(true)
|
||||||
|
//table.SetAutoMergeCellsByColumnIndex([]int{1,2,3})
|
||||||
|
table.SetRowLine(true)
|
||||||
|
table.AppendBulk(options)
|
||||||
|
table.Render()
|
||||||
if artist_select {
|
if artist_select {
|
||||||
fmt.Println("You have selected all options:")
|
fmt.Println("You have selected all options:")
|
||||||
return urls, nil
|
return urls, nil
|
||||||
}
|
}
|
||||||
reader := bufio.NewReader(os.Stdin)
|
reader := bufio.NewReader(os.Stdin)
|
||||||
fmt.Println("Please select from the following " + relationship + " options (multiple options separated by commas, ranges supported, or type 'all' to select all)")
|
fmt.Println("Please select from the " + relationship + " options above (multiple options separated by commas, ranges supported, or type 'all' to select all)")
|
||||||
fmt.Print("Enter your choice: ")
|
fmt.Print("Enter your choice: ")
|
||||||
input, _ := reader.ReadString('\n')
|
input, _ := reader.ReadString('\n')
|
||||||
|
|
||||||
@ -714,7 +721,12 @@ func rip(albumId string, token string, storefront string, mediaUserToken string,
|
|||||||
needCheck = true
|
needCheck = true
|
||||||
}
|
}
|
||||||
if needCheck {
|
if needCheck {
|
||||||
m3u8Url, err = checkM3u8(track.ID, "song")
|
fullM3u8Url, err := checkM3u8(track.ID, "song")
|
||||||
|
if err == nil && strings.HasSuffix(fullM3u8Url, ".m3u8"){
|
||||||
|
m3u8Url = fullM3u8Url
|
||||||
|
} else {
|
||||||
|
fmt.Println("Failed to get best quality m3u8 from device m3u8 port, will use m3u8 from Web API")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_, _, err = extractMedia(m3u8Url, true)
|
_, _, err = extractMedia(m3u8Url, true)
|
||||||
@ -1677,12 +1689,20 @@ func extractMedia(b string, more_mode bool) (string, string, error) {
|
|||||||
})
|
})
|
||||||
if debug_mode && more_mode {
|
if debug_mode && more_mode {
|
||||||
fmt.Println("\nDebug: All Available Variants:")
|
fmt.Println("\nDebug: All Available Variants:")
|
||||||
fmt.Println("-----------------------------")
|
var data [][]string
|
||||||
for _, variant := range master.Variants {
|
for _, variant := range master.Variants {
|
||||||
fmt.Printf("Codec: %s, Audio: %s, Bandwidth: %d\n",
|
data = append(data, []string{variant.Codecs, variant.Audio, fmt.Sprint(variant.Bandwidth)})
|
||||||
variant.Codecs, variant.Audio, variant.Bandwidth)
|
//fmt.Printf("Codec: %s, Audio: %s, Bandwidth: %d\n",
|
||||||
|
//variant.Codecs, variant.Audio, variant.Bandwidth)
|
||||||
}
|
}
|
||||||
fmt.Println("-----------------------------")
|
table := tablewriter.NewWriter(os.Stdout)
|
||||||
|
table.SetHeader([]string{"Codec", "Audio", "Bandwidth"})
|
||||||
|
//table.SetFooter([]string{"", "", "Total", "$146.93"})
|
||||||
|
table.SetAutoMergeCells(true)
|
||||||
|
//table.SetAutoMergeCellsByColumnIndex([]int{1,2,3})
|
||||||
|
table.SetRowLine(true)
|
||||||
|
table.AppendBulk(data)
|
||||||
|
table.Render()
|
||||||
|
|
||||||
var hasAAC, hasLossless, hasHiRes, hasAtmos, hasDolbyAudio bool
|
var hasAAC, hasLossless, hasHiRes, hasAtmos, hasDolbyAudio bool
|
||||||
var aacQuality, losslessQuality, hiResQuality, atmosQuality, dolbyAudioQuality string
|
var aacQuality, losslessQuality, hiResQuality, atmosQuality, dolbyAudioQuality string
|
||||||
|
Loading…
x
Reference in New Issue
Block a user