mirror of
https://github.com/AynaLivePlayer/miaosic.git
synced 2025-12-06 13:02:48 +08:00
add json flag support for info/lyric/quality/search/url
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package cmds
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/AynaLivePlayer/miaosic"
|
||||
"github.com/spf13/cobra"
|
||||
@@ -31,6 +32,16 @@ var CmdInfo = &cobra.Command{
|
||||
fmt.Printf("Error getting media info: %v\n", err)
|
||||
return
|
||||
}
|
||||
result, _ := cmd.Flags().GetBool("json")
|
||||
if result {
|
||||
jsonBytes, err := json.Marshal(info)
|
||||
if err != nil {
|
||||
fmt.Printf("Error marshaling to JSON: %v\n", err)
|
||||
return
|
||||
}
|
||||
fmt.Println(string(jsonBytes))
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println("Title:", info.Title)
|
||||
fmt.Println("Artist:", info.Artist)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package cmds
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/AynaLivePlayer/miaosic"
|
||||
"github.com/spf13/cobra"
|
||||
@@ -73,6 +74,17 @@ var CmdLyric = &cobra.Command{
|
||||
return
|
||||
}
|
||||
|
||||
result, _ := cmd.Flags().GetBool("json")
|
||||
if result {
|
||||
jsonBytes, err := json.Marshal(lyrics)
|
||||
if err != nil {
|
||||
fmt.Printf("Error marshaling to JSON: %v\n", err)
|
||||
return
|
||||
}
|
||||
fmt.Println(string(jsonBytes))
|
||||
return
|
||||
}
|
||||
|
||||
var mediaInfo miaosic.MediaInfo
|
||||
if saveLyric && lyricOutput == "" {
|
||||
info, err := provider.GetMediaInfo(meta)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package cmds
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/AynaLivePlayer/miaosic"
|
||||
"github.com/spf13/cobra"
|
||||
@@ -26,6 +27,17 @@ var CmdQuality = &cobra.Command{
|
||||
return
|
||||
}
|
||||
|
||||
result, _ := cmd.Flags().GetBool("json")
|
||||
if result {
|
||||
jsonBytes, err := json.Marshal(qualities)
|
||||
if err != nil {
|
||||
fmt.Printf("Error marshaling to JSON: %v\n", err)
|
||||
return
|
||||
}
|
||||
fmt.Println(string(jsonBytes))
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Printf("Supported qualities for %s:\n", providerName)
|
||||
for i, quality := range qualities {
|
||||
fmt.Printf("%d. %s\n", i+1, quality)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package cmds
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/AynaLivePlayer/miaosic"
|
||||
"github.com/spf13/cobra"
|
||||
@@ -44,6 +45,17 @@ var CmdSearch = &cobra.Command{
|
||||
return
|
||||
}
|
||||
|
||||
result, _ := cmd.Flags().GetBool("json")
|
||||
if result {
|
||||
jsonBytes, err := json.Marshal(results)
|
||||
if err != nil {
|
||||
fmt.Printf("Error marshaling to JSON: %v\n", err)
|
||||
return
|
||||
}
|
||||
fmt.Println(string(jsonBytes))
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Printf("Page.%02d for \"%s\"\n", searchPage, keyword)
|
||||
for i, media := range results {
|
||||
fmt.Printf("%d. %s - %s - %s - %s\n",
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package cmds
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/AynaLivePlayer/miaosic"
|
||||
"github.com/spf13/cobra"
|
||||
@@ -36,6 +37,16 @@ var CmdUrl = &cobra.Command{
|
||||
fmt.Printf("Error getting media URLs: %v\n", err)
|
||||
return
|
||||
}
|
||||
result, _ := cmd.Flags().GetBool("json")
|
||||
if result {
|
||||
jsonBytes, err := json.Marshal(urls)
|
||||
if err != nil {
|
||||
fmt.Printf("Error marshaling to JSON: %v\n", err)
|
||||
return
|
||||
}
|
||||
fmt.Println(string(jsonBytes))
|
||||
return
|
||||
}
|
||||
|
||||
for i, url := range urls {
|
||||
fmt.Printf("URL %d:\n", i+1)
|
||||
|
||||
@@ -35,9 +35,11 @@ var rootCmd = &cobra.Command{
|
||||
}
|
||||
|
||||
var sessionFile string
|
||||
var outputJson bool
|
||||
|
||||
func init() {
|
||||
rootCmd.PersistentFlags().StringVarP(&sessionFile, "session-file", "s", "", "Session file path")
|
||||
rootCmd.PersistentFlags().BoolVarP(&outputJson, "json", "j", false, "output in json")
|
||||
rootCmd.AddCommand(cmds.CmdProviders)
|
||||
rootCmd.AddCommand(cmds.CmdSearch)
|
||||
rootCmd.AddCommand(cmds.CmdQrlogin)
|
||||
|
||||
Reference in New Issue
Block a user