Support for moreButton in artist page (Hyperpipe/Hyperpipe#34)

This commit is contained in:
Shiny Nematoda
2023-03-23 18:01:10 +00:00
parent e0683b1be7
commit 4d1e04a1ec
9 changed files with 152 additions and 52 deletions
+75 -1
View File
@@ -7,6 +7,29 @@ import (
"github.com/tidwall/gjson"
)
type Items struct {
Songs []Item `json:"songs"`
Albums []Item `json:"albums"`
Singles []Item `json:"singles"`
Artists []Item `json:"recommendedArtists"`
}
type MoreItem struct {
Params string `json:"params"`
Click string `json:"click"`
Visit string `json:"visit"`
}
type ArtistMore struct {
Album MoreItem `json:"album"`
Singles MoreItem `json:"singles"`
}
type ArtistNext struct {
Title string `json:"title"`
Items []Item `json:"items"`
}
type Artist struct {
Title string `json:"title"`
Description string `json:"description,omitempty"`
@@ -15,6 +38,17 @@ type Artist struct {
SubscriberCount string `json:"subscriberCount,omitempty"`
Thumbnails []Thumbnail `json:"thumbnails"`
Items Items `json:"items"`
More ArtistMore `json:"more"`
}
func parseMoreButton(raw, v gjson.Result) MoreItem {
nav := raw.Get("header.musicCarouselShelfBasicHeaderRenderer.moreContentButton.buttonRenderer.navigationEndpoint")
return MoreItem{
Params: nav.Get("browseEndpoint.params").String(),
Click: nav.Get("clickTrackingParams").String(),
Visit: v.String(),
}
}
func parseArtist(raw string) (string, error) {
@@ -61,6 +95,32 @@ func parseArtist(raw string) (string, error) {
Singles: TwoRowItemRenderer(m.Get("contents"), true),
Artists: TwoRowItemRenderer(u.Get("contents"), false),
},
More: ArtistMore{
Album: parseMoreButton(a, j.Get("responseContext.visitorData")),
Singles: parseMoreButton(m, j.Get("responseContext.visitorData")),
},
}
res, err := json.Marshal(val)
if err != nil {
return "", err
}
return string(res), nil
}
func parseArtistNext(raw string) (string, error) {
j := gjson.Parse(raw)
val := ArtistNext{
Title: RunsText(j.Get("header.musicHeaderRenderer.title")),
Items: TwoRowItemRenderer(
j.Get(
"contents.singleColumnBrowseResultsRenderer.tabs.0.tabRenderer.content.sectionListRenderer.contents.0.gridRenderer.items",
),
true,
),
}
res, err := json.Marshal(val)
@@ -73,7 +133,7 @@ func parseArtist(raw string) (string, error) {
func GetArtist(id string) (string, int) {
context := utils.TypeBrowse("artist", id, "", "")
context := utils.TypeBrowsePage(id, "artist")
raw, status := utils.FetchBrowse(context)
@@ -84,3 +144,17 @@ func GetArtist(id string) (string, int) {
return res, status
}
func GetArtistNext(id, params, ct, v string) (string, int) {
context := utils.TypeBrowse(id, params, []string{ct, v})
raw, status := utils.FetchBrowse(context)
res, err := parseArtistNext(raw)
if err != nil {
return utils.ErrMsg(err), 500
}
return res, status
}
+1 -1
View File
@@ -62,7 +62,7 @@ func parseCharts(raw string) (string, error) {
func GetCharts(params, code string) (string, int) {
context := utils.TypeBrowse("", "FEmusic_charts", params, code)
context := utils.TypeBrowseForm("FEmusic_charts", params, code)
raw, status := utils.FetchBrowse(context)
-7
View File
@@ -25,13 +25,6 @@ type Item struct {
Thumbnails []Thumbnail `json:"thumbnails,omitempty"`
}
type Items struct {
Songs []Item `json:"songs"`
Albums []Item `json:"albums"`
Singles []Item `json:"singles"`
Artists []Item `json:"recommendedArtists"`
}
func RunsText(j gjson.Result) string {
var s []string
+1 -1
View File
@@ -52,7 +52,7 @@ func parseExplore(raw string) (string, error) {
func GetExplore() (string, int) {
context := utils.TypeBrowse("", "FEmusic_explore", "", "")
context := utils.TypeBrowse("FEmusic_explore", "", []string{})
raw, status := utils.FetchBrowse(context)
+1 -1
View File
@@ -50,7 +50,7 @@ func parseGenre(raw string) (string, error) {
func GetGenre(param string) (string, int) {
context := utils.TypeBrowse("", "FEmusic_moods_and_genres_category", param, "")
context := utils.TypeBrowse("FEmusic_moods_and_genres_category", param, []string{})
raw, status := utils.FetchBrowse(context)
+1 -1
View File
@@ -40,7 +40,7 @@ func parseGenres(raw string) (string, error) {
func GetGenres() (string, int) {
context := utils.TypeBrowse("", "FEmusic_moods_and_genres", "", "")
context := utils.TypeBrowse("FEmusic_moods_and_genres", "", []string{})
raw, status := utils.FetchBrowse(context)
+1 -1
View File
@@ -36,7 +36,7 @@ func parseLyrics(raw string) (string, error) {
func GetLyrics(id string) (string, int) {
context := utils.TypeBrowse("lyrics", id, "", "")
context := utils.TypeBrowsePage(id, "lyrics")
raw, status := utils.FetchBrowse(context)