feat(front): links to spotify/bandcamp + infos

Infos as artist and album are now provide and show in a table.
This commit is contained in:
rick 2021-09-01 00:34:07 +02:00
parent 014fb66867
commit a0f5500220
Signed by: Rick
GPG key ID: 2B593F087240EE99
2 changed files with 66 additions and 16 deletions

View file

@ -15,15 +15,26 @@ type BandcampAlbum struct {
url string
}
type UrlBandcamp struct {
Artiste string `json:"artist"`
Album string `json:"album"`
SpotifyUrl string `json:"spotifyurl"`
BandcampUrl string `json:"bandcampurl"`
}
func newUrlBandcamp(auteur, album, spo, band string) UrlBandcamp {
return UrlBandcamp{Artiste: auteur, Album: album, SpotifyUrl: spo, BandcampUrl: band}
}
type RespBandcamp struct {
Done int `json:"done"`
Todo int `json:"todo"`
Url []string `json:"url"`
Urls []UrlBandcamp `json:"urls"`
}
func (rp *RespBandcamp) Add(str string) []string {
rp.Url = append(rp.Url, str)
return rp.Url
func (rp *RespBandcamp) Add(tmp UrlBandcamp) []UrlBandcamp {
rp.Urls = append(rp.Urls, tmp)
return rp.Urls
}
var MyClient = &http.Client{}
@ -76,26 +87,31 @@ func getListPlaylist(id string) {
return
}
ree := &SpotifyPlaylist{}
playlist := &SpotifyPlaylist{}
defer res.Body.Close()
err = json.NewDecoder(res.Body).Decode(&ree)
err = json.NewDecoder(res.Body).Decode(&playlist)
if err != nil {
fmt.Printf("error:", err)
return
}
tmp := BandcampAlbum{}
MyResp.Todo = len(ree.Items)
MyResp.Todo = len(playlist.Items)
MyResp.Done = 0
for i := 0; i < len(ree.Items); i++ {
tmp = testBandcamp(ree.Items[i].Track.Album.Name,
ree.Items[i].Track.Album.Artists[0].Name)
for i := 0; i < len(playlist.Items); i++ {
tmp = testBandcamp(playlist.Items[i].Track.Album.Name,
playlist.Items[i].Track.Album.Artists[0].Name)
if tmp.find {
//fmt.Printf("Find !! url: %s\n", tmp.url)
//MyResp.url = append(MyResp.url, tmp.url)
//MyResp.url = append (MyResp.url, tmp.url)
MyResp.Add(tmp.url)
//MyResp.Add(tmp.url)
MyResp.Add(newUrlBandcamp(
playlist.Items[i].Track.Album.Artists[0].Name,
playlist.Items[i].Track.Album.Name,
playlist.Items[i].Track.Album.ExternalUrls.Spotify,
tmp.url))
//fmt.Printf("tmp %s \n", MyResp.url[0])
//fmt.Printf("len=%d cap=%d %v\n", len(MyResp.url), cap(MyResp.url), MyResp.url)
}
@ -148,7 +164,7 @@ func getNew(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusCreated)
json.NewEncoder(w).Encode(MyResp)
MyResp.Url = nil
MyResp.Urls = nil
}
func main() {

View file

@ -15,20 +15,54 @@
<p><a href="https://codepen.io/brunjo/pen/bNEWjV">Code Source du loader</a> sous <a href="https://blog.codepen.io/documentation/licensing/">licence MIT</a>.</p>
</div>
<div id="my-list">
<div>
<table id="my-list">
<tr>
<th>Artiste</th>
<th>Album</th>
<th>Spotify</th>
<th>Bandcamp</th>
</tr>
</table>
</div>
</body>
<script>
const spotifyText = document.createTextNode("Spotify");
const bandcampText = document.createTextNode("Bandcamp");
const tab = document.getElementById("my-list");
async function test() {
const data = await fetch('/refresh').then(response => response.json());
if (data != null) {
if (data.url != null) {
for (const elem of data.url) {
if (data.urls != null) {
var newRow, artist, album, tmpLink;
for (const elem of data.urls) {
artist = document.createTextNode(elem.artist);
album = document.createTextNode(elem.album);
tmpLink = document.createElement("a");
tmpLink.appendChild(spotifyText.cloneNode());
tmpLink.title = "Lien Spotify";
tmpLink.href = elem.spotifyurl;
/*
let tmp = document.createTextNode(elem);
let newP = document.createElement("p");
newP.appendChild(tmp);
document.getElementById("my-list").appendChild(newP);
*/
newRow = tab.insertRow(-1);
newRow.insertCell(0).appendChild(artist);
newRow.insertCell(1).appendChild(album);
newRow.insertCell(2).appendChild(tmpLink);
tmpLink = document.createElement("a");
tmpLink.appendChild(bandcampText.cloneNode());
tmpLink.title = "Lien Bandcamp";
tmpLink.href = elem.bandcampurl;
newRow.insertCell(3).appendChild(tmpLink);
}
}