re-add album canonical url

This commit is contained in:
Shiny Nematoda
2023-08-06 10:51:29 +00:00
parent 34ac6a38a3
commit d2c8e0e7a8
4 changed files with 39 additions and 3 deletions
+1 -1
View File
@@ -20,5 +20,5 @@ require (
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasthttp v1.48.0 // indirect
github.com/valyala/tcplisten v1.0.0 // indirect
golang.org/x/sys v0.10.0 // indirect
golang.org/x/sys v0.11.0 // indirect
)
+2 -2
View File
@@ -31,5 +31,5 @@ github.com/valyala/tcplisten v1.0.0 h1:rBHj/Xf+E1tRGZyWIWwJDiRY0zc1Js+CV5DqwacVS
github.com/valyala/tcplisten v1.0.0/go.mod h1:T0xQ8SeCZGxckz9qRXTfG43PvQ/mcWh7FwZEA7Ioqkc=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.10.0 h1:SqMFp9UcQJZa+pmYuAKjd9xq1f0j5rLcDIk0mj4qAsA=
golang.org/x/sys v0.10.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.11.0 h1:eG7RXZHdqOJ1i+0lgLgCpSXAp6M3LYlAo6osgSi0xOM=
golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
+30
View File
@@ -0,0 +1,30 @@
package lib
import (
"net/url"
"codeberg.org/Hyperpipe/hyperpipe-backend/utils"
"github.com/tidwall/gjson"
)
func GetAlbumUrl(id string) (map[string]string, int) {
ctx := utils.TypeBrowsePage(id, "album")
raw, status := utils.FetchBrowse(ctx)
uri := gjson.Parse(raw).Get(
"microformat.microformatDataRenderer.urlCanonical",
).String()
u, err := url.Parse(uri)
if err != nil {
return map[string]string{
"error": "500",
"message": "failed to parse url",
}, 500
}
return map[string]string{
"id": u.Query().Get("list"),
}, status
}
+6
View File
@@ -63,6 +63,11 @@ func HandleLyrics(c *fiber.Ctx) error {
return c.Status(status).JSON(res)
}
func HandleAlbum(c *fiber.Ctx) error {
res, status := lib.GetAlbumUrl(c.Params("id"))
return c.Status(status).JSON(res)
}
func HandleArtist(c *fiber.Ctx) error {
res, status := lib.GetArtist(c.Params("id"))
@@ -112,6 +117,7 @@ func main() {
app.Get("/charts", HandleCharts)
app.Get("/next/:id", HandleNext)
app.Get("/lyrics/:id", HandleLyrics)
app.Get("/album/:id", HandleAlbum)
app.Get("/channel/:id", HandleArtist)
app.Get("/next/channel/:id/:params", HandleArtistNext)