mirror of
https://codeberg.org/Hyperpipe/hyperpipe-backend
synced 2024-12-06 19:26:30 +01:00
Added Support for Charts
This commit is contained in:
+65
@@ -135,6 +135,42 @@ func ResponsiveListItemRenderer(s gjson.Result) []Item {
|
||||
return r
|
||||
}
|
||||
|
||||
func ResponsiveListItemRendererCH(s gjson.Result) []Item {
|
||||
|
||||
r := []Item{}
|
||||
|
||||
wg := sync.WaitGroup{}
|
||||
|
||||
s.ForEach(
|
||||
func(_, v gjson.Result) bool {
|
||||
|
||||
wg.Add(1)
|
||||
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
|
||||
j := v.Get("musicResponsiveListItemRenderer")
|
||||
flex := j.Get("flexColumns.#.musicResponsiveListItemFlexColumnRenderer" +
|
||||
".text.runs.0.text")
|
||||
|
||||
r = append(r, Item{
|
||||
Id: j.Get("navigationEndpoint.browseEndpoint.browseId").String(),
|
||||
Title: flex.Get("0").String() + " • " + flex.Get("1").String(),
|
||||
Thumbnails: GetThumbnails(j.Get("thumbnail.musicThumbnailRenderer" +
|
||||
".thumbnail.thumbnails")),
|
||||
})
|
||||
|
||||
}()
|
||||
|
||||
wg.Wait()
|
||||
|
||||
return true
|
||||
},
|
||||
)
|
||||
|
||||
return r
|
||||
}
|
||||
|
||||
func NavigationButton(s gjson.Result) []Item {
|
||||
|
||||
r := []Item{}
|
||||
@@ -168,3 +204,32 @@ func NavigationButton(s gjson.Result) []Item {
|
||||
|
||||
return r
|
||||
}
|
||||
|
||||
func MultiSelectMenuItemRenderer(j gjson.Result) []Item {
|
||||
|
||||
r := []Item{}
|
||||
|
||||
wg := sync.WaitGroup{}
|
||||
|
||||
j.ForEach(
|
||||
func(_, v gjson.Result) bool {
|
||||
|
||||
wg.Add(1)
|
||||
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
|
||||
r = append(r, Item{
|
||||
Id: v.Get("selectedCommand.commandExecutorCommand.commands.#(musicBrowseFormBinderCommand).musicBrowseFormBinderCommand.browseEndpoint.params").String(),
|
||||
Title: RunsText(v.Get("title")),
|
||||
})
|
||||
}()
|
||||
|
||||
wg.Wait()
|
||||
|
||||
return true
|
||||
},
|
||||
)
|
||||
|
||||
return r
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ func Fetch(path string, data []byte) (string, int, error) {
|
||||
return string(body), resp.StatusCode, nil
|
||||
}
|
||||
|
||||
func FetchBrowse(id string, browse BrowseData) (string, int) {
|
||||
func FetchBrowse(browse BrowseData) (string, int) {
|
||||
|
||||
data, err := json.Marshal(browse)
|
||||
if err != nil {
|
||||
@@ -66,7 +66,7 @@ func FetchExplore() (string, int) {
|
||||
|
||||
context := GetTypeBrowse("", id, "")
|
||||
|
||||
raw, status := FetchBrowse(id, context)
|
||||
raw, status := FetchBrowse(context)
|
||||
|
||||
res, err := ParseExplore(raw)
|
||||
if err != nil {
|
||||
@@ -82,7 +82,7 @@ func FetchGenres() (string, int) {
|
||||
|
||||
context := GetTypeBrowse("", id, "")
|
||||
|
||||
raw, status := FetchBrowse(id, context)
|
||||
raw, status := FetchBrowse(context)
|
||||
|
||||
res, err := ParseGenres(raw)
|
||||
if err != nil {
|
||||
@@ -98,7 +98,7 @@ func FetchGenre(param string) (string, int) {
|
||||
|
||||
context := GetTypeBrowse("", id, param)
|
||||
|
||||
raw, status := FetchBrowse(id, context)
|
||||
raw, status := FetchBrowse(context)
|
||||
|
||||
res, err := ParseGenre(raw)
|
||||
if err != nil {
|
||||
@@ -108,11 +108,27 @@ func FetchGenre(param string) (string, int) {
|
||||
return res, status
|
||||
}
|
||||
|
||||
func FetchCharts(params string) (string, int) {
|
||||
|
||||
id := "FEmusic_charts"
|
||||
|
||||
context := GetTypeBrowse("", id, params)
|
||||
|
||||
raw, status := FetchBrowse(context)
|
||||
|
||||
res, err := ParseCharts(raw)
|
||||
if err != nil {
|
||||
return ErrorMessage(err), 500
|
||||
}
|
||||
|
||||
return res, status
|
||||
}
|
||||
|
||||
func FetchArtist(id string) (string, int) {
|
||||
|
||||
context := GetTypeBrowse("artist", id, "")
|
||||
|
||||
raw, status := FetchBrowse(id, context)
|
||||
raw, status := FetchBrowse(context)
|
||||
|
||||
res, err := ParseArtist(raw)
|
||||
if err != nil {
|
||||
@@ -126,7 +142,7 @@ func FetchLyrics(id string) (string, int) {
|
||||
|
||||
context := GetTypeBrowse("lyrics", id, "")
|
||||
|
||||
raw, status := FetchBrowse(id, context)
|
||||
raw, status := FetchBrowse(context)
|
||||
|
||||
res, err := ParseLyrics(raw)
|
||||
if err != nil {
|
||||
@@ -140,7 +156,7 @@ func FetchAlbum(id string) (string, int) {
|
||||
|
||||
context := GetTypeBrowse("album", id, "")
|
||||
|
||||
raw, status := FetchBrowse(id, context)
|
||||
raw, status := FetchBrowse(context)
|
||||
|
||||
url := gjson.Parse(raw).Get("microformat.microformatDataRenderer.urlCanonical").String()
|
||||
|
||||
|
||||
@@ -56,6 +56,14 @@ func HandleGenre(c *fiber.Ctx) error {
|
||||
return c.Status(status).SendString(res)
|
||||
}
|
||||
|
||||
func HandleCharts(c *fiber.Ctx) error {
|
||||
defer calc()()
|
||||
|
||||
res, status := FetchCharts(c.Params("id"))
|
||||
|
||||
return c.Status(status).SendString(res)
|
||||
}
|
||||
|
||||
func HandleBrowse(c *fiber.Ctx) error {
|
||||
defer calc()()
|
||||
|
||||
@@ -98,6 +106,7 @@ func main() {
|
||||
app.Get("/explore", HandleExplore)
|
||||
app.Get("/genres", HandleGenres)
|
||||
app.Get("/genres/:id", HandleGenre)
|
||||
app.Get("/charts/:id", HandleCharts)
|
||||
app.Get("/next/:id", HandleNext)
|
||||
app.Get("/browse/:id", HandleBrowse)
|
||||
app.Get("/channel/:id", HandleArtist)
|
||||
|
||||
@@ -42,17 +42,24 @@ func ParseExplore(raw string) (string, error) {
|
||||
|
||||
j := gjson.Parse(raw)
|
||||
|
||||
c := j.Get("contents.singleColumnBrowseResultsRenderer.tabs.0.tabRenderer.content" +
|
||||
".sectionListRenderer.contents.#.musicCarouselShelfRenderer")
|
||||
m := j.Get("contents.singleColumnBrowseResultsRenderer.tabs.0" +
|
||||
".tabRenderer.content.sectionListRenderer.contents")
|
||||
|
||||
c := m.Get("#.musicCarouselShelfRenderer")
|
||||
|
||||
a := c.Get("#(header.musicCarouselShelfBasicHeaderRenderer" +
|
||||
".title.runs.0.text == New albums & singles)")
|
||||
t := c.Get("#(header.musicCarouselShelfBasicHeaderRenderer" +
|
||||
".title.runs.0.text == Trending)")
|
||||
|
||||
charts := m.Get("#(gridRenderer).gridRenderer.items.#" +
|
||||
".musicNavigationButtonRenderer").Get("#(buttonText" +
|
||||
".runs.0.text == Charts)")
|
||||
|
||||
val := Explore{
|
||||
TrendingId: t.Get("header.musicCarouselShelfBasicHeaderRenderer" +
|
||||
".title.runs.0.navigationEndpoint.browseEndpoint.browseId").String(),
|
||||
ChartsId: charts.Get("clickCommand.browseEndpoint.params").String(),
|
||||
Albums: TwoRowItemRenderer("album", a.Get("contents")),
|
||||
Trending: ResponsiveListItemRenderer(t.Get("contents")),
|
||||
}
|
||||
@@ -114,6 +121,33 @@ func ParseGenre(raw string) (string, error) {
|
||||
return string(res), nil
|
||||
}
|
||||
|
||||
func ParseCharts(raw string) (string, error) {
|
||||
|
||||
j := gjson.Parse(raw)
|
||||
|
||||
c := j.Get("contents.singleColumnBrowseResultsRenderer.tabs.0.tabRenderer.content.sectionListRenderer.contents")
|
||||
|
||||
o := c.Get("0.musicShelfRenderer.subheaders.0.musicSideAlignedItemRenderer.startItems.0.musicSortFilterButtonRenderer")
|
||||
a := c.Get("#(musicCarouselShelfRenderer.header.musicCarouselShelfBasicHeaderRenderer.title.runs.0.text == Top artists).musicCarouselShelfRenderer.contents")
|
||||
t := c.Get("#(musicCarouselShelfRenderer.header.musicCarouselShelfBasicHeaderRenderer.title.runs.0.text == Trending).musicCarouselShelfRenderer.contents")
|
||||
|
||||
val := Charts{
|
||||
Options: Options{
|
||||
Default: RunsText(o.Get("title")),
|
||||
All: MultiSelectMenuItemRenderer(o.Get("menu.musicMultiSelectMenuRenderer.options.#.musicMultiSelectMenuItemRenderer")),
|
||||
},
|
||||
Artists: ResponsiveListItemRendererCH(a),
|
||||
Trending: ResponsiveListItemRenderer(t),
|
||||
}
|
||||
|
||||
res, err := json.Marshal(val)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return string(res), nil
|
||||
}
|
||||
|
||||
func ParseArtist(raw string) (string, error) {
|
||||
|
||||
j := gjson.Parse(raw)
|
||||
|
||||
+14
-2
@@ -1,6 +1,6 @@
|
||||
package main
|
||||
|
||||
/* Parsers */
|
||||
// Parsers
|
||||
type Thumbnail struct {
|
||||
Height int64 `json:"height"`
|
||||
Width int64 `json:"width"`
|
||||
@@ -24,6 +24,7 @@ type Items struct {
|
||||
|
||||
type Explore struct {
|
||||
TrendingId string `json:"trendingId"`
|
||||
ChartsId string `json:"chartsId"`
|
||||
Albums []Item `json:"albums_and_singles"`
|
||||
Trending []Item `json:"trending"`
|
||||
}
|
||||
@@ -40,6 +41,17 @@ type Genre struct {
|
||||
Community []Item `json:"community"`
|
||||
}
|
||||
|
||||
type Options struct {
|
||||
Default string `json:"default"`
|
||||
All []Item `json:"all"`
|
||||
}
|
||||
|
||||
type Charts struct {
|
||||
Options Options `json:"options"`
|
||||
Artists []Item `json:"artists"`
|
||||
Trending []Item `json:"trending"`
|
||||
}
|
||||
|
||||
type Artist struct {
|
||||
Title string `json:"title"`
|
||||
Description string `json:"description,omitempty"`
|
||||
@@ -66,7 +78,7 @@ type Lyrics struct {
|
||||
Source string `json:"source"`
|
||||
}
|
||||
|
||||
/* Structs and Types */
|
||||
// Structs and Types
|
||||
type Client struct {
|
||||
Name string `json:"clientName,omitempty"`
|
||||
Version string `json:"clientVersion,omitempty"`
|
||||
|
||||
Reference in New Issue
Block a user