!feat(categories): add 3 categories for artists
- albums: album found - artists: found the artist, not the album - notfound: not found on bandcamp (or limited by api) API on refresh changes. Use a extern script instead of write it in html page.
This commit is contained in:
parent
ad1556dbc0
commit
5e7e5051be
5 changed files with 187 additions and 69 deletions
46
server.go
46
server.go
|
@ -17,7 +17,7 @@ var MyResp = &RespBandcamp{}
|
|||
check artist and album
|
||||
items[x].track.album.name et items[x].track.album.artists[0].name
|
||||
*/
|
||||
func testBandcamp(album string, artist string) BandcampAlbum{
|
||||
func searchAlbumBandcamp(album string, artist string) BandcampAlbum{
|
||||
bandcampClient := bandcamp.NewClient()
|
||||
|
||||
results, err := bandcampClient.Search(album)
|
||||
|
@ -33,6 +33,22 @@ func testBandcamp(album string, artist string) BandcampAlbum{
|
|||
}
|
||||
}
|
||||
|
||||
func searchArtistBandcamp(artist string) BandcampAlbum {
|
||||
bandcampClient := bandcamp.NewClient()
|
||||
|
||||
results, err := bandcampClient.Search(artist)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return BandcampAlbum{false, ""}
|
||||
}
|
||||
|
||||
if strings.Compare(results[0].Artist, artist) == 0 {
|
||||
return BandcampAlbum{true, strings.Split(results[0].URL, "/album/")[0]}
|
||||
} else {
|
||||
return BandcampAlbum{false, ""}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
id de la playlist
|
||||
*/
|
||||
|
@ -73,25 +89,41 @@ func getListPlaylist(id string) {
|
|||
MyResp.Done = 0
|
||||
|
||||
for i := 0; i < len(playlist.Items); i++ {
|
||||
tmp = testBandcamp(playlist.Items[i].Track.Album.Name,
|
||||
tmp = searchAlbumBandcamp(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(newUrlBandcamp(
|
||||
MyResp.AddAlbum(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)
|
||||
} else {
|
||||
tmp = searchArtistBandcamp(playlist.Items[i].Track.Album.Artists[0].Name)
|
||||
if tmp.find {
|
||||
MyResp.AddArtist(newUrlBandcamp(
|
||||
playlist.Items[i].Track.Album.Artists[0].Name,
|
||||
playlist.Items[i].Track.Album.Name,
|
||||
playlist.Items[i].Track.Album.ExternalUrls.Spotify,
|
||||
tmp.url))
|
||||
} else {
|
||||
MyResp.AddNotfound(newUrlWoBandcamp(
|
||||
playlist.Items[i].Track.Album.Artists[0].Name,
|
||||
playlist.Items[i].Track.Album.Name,
|
||||
playlist.Items[i].Track.Album.ExternalUrls.Spotify))
|
||||
}
|
||||
if i % 25 == 0 {
|
||||
}
|
||||
|
||||
MyResp.Done++
|
||||
|
||||
if i % 10 == 0 {
|
||||
time.Sleep(5 * time.Second)
|
||||
}
|
||||
MyResp.Done++
|
||||
}
|
||||
fmt.Printf("\nFinish\n")
|
||||
}
|
||||
|
@ -125,7 +157,9 @@ 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.Urls = nil
|
||||
MyResp.Albums = nil
|
||||
MyResp.Artists = nil
|
||||
MyResp.Notfound = nil
|
||||
}
|
||||
|
||||
func main() {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
h1 {
|
||||
color: red;
|
||||
color: green;
|
||||
}
|
||||
|
||||
td, th {
|
||||
|
@ -14,3 +14,7 @@ footer {
|
|||
display: grid;
|
||||
grid-template-columns: 1fr 1fr 1fr;
|
||||
}
|
||||
|
||||
.only-artist {
|
||||
color: red;
|
||||
}
|
||||
|
|
|
@ -16,7 +16,8 @@
|
|||
</div>
|
||||
|
||||
<div>
|
||||
<table id="my-list">
|
||||
<h2>Albums trouvés</h2>
|
||||
<table id="found">
|
||||
<tr>
|
||||
<th>Artiste</th>
|
||||
<th>Album</th>
|
||||
|
@ -24,6 +25,25 @@
|
|||
<th>Bandcamp</th>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<h2>Artistes trouvés</h2>
|
||||
<table id="artist-found">
|
||||
<tr>
|
||||
<th>Artiste</th>
|
||||
<th>Album</th>
|
||||
<th>Spotify</th>
|
||||
<th>Bandcamp</th>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<h2>Artistes non trouvés</h2>
|
||||
<table id="notfound">
|
||||
<tr>
|
||||
<th>Artiste</th>
|
||||
<th>Album</th>
|
||||
<th>Spotify</th>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
<hr />
|
||||
<footer>
|
||||
|
@ -31,60 +51,5 @@
|
|||
<p>Ce site est en aucun cas affilié avec Bandcamp ou Spotify.</p>
|
||||
</footer>
|
||||
</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.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);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
document.getElementById("nb-fait").textContent = data.done;
|
||||
document.getElementById("nb-total").textContent = data.todo;
|
||||
|
||||
if (data.done === data.todo) {
|
||||
document.getElementById("inf-loader").remove();
|
||||
clearInterval(refreshList);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
window.onbeforeunload = function() {
|
||||
return "Vous perdrez tous les artistes trouvés en rafraichissant la page."
|
||||
}
|
||||
|
||||
const refreshList = setInterval(test, 3000);
|
||||
</script>
|
||||
<script src="/script.js"></script>
|
||||
<html>
|
||||
|
|
98
static/script.js
Normal file
98
static/script.js
Normal file
|
@ -0,0 +1,98 @@
|
|||
const spotifyText = document.createTextNode("Spotify");
|
||||
const bandcampText = document.createTextNode("Bandcamp");
|
||||
//const tab = document.getElementById("my-list");
|
||||
|
||||
async function addCell(id, elem) {
|
||||
let tab = document.getElementById(id), tmpLink, artist, album, newRow;
|
||||
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;
|
||||
|
||||
newRow = tab.insertRow(-1);
|
||||
newRow.insertCell(0).appendChild(artist);
|
||||
newRow.insertCell(1).appendChild(album);
|
||||
newRow.insertCell(2).appendChild(tmpLink);
|
||||
|
||||
tmpLink = document.createElement("a");
|
||||
switch (id) {
|
||||
case "artist-found":
|
||||
tmpLink.classList.add("only-artist")
|
||||
case "found":
|
||||
tmpLink.appendChild(bandcampText.cloneNode());
|
||||
tmpLink.title = "Lien Bandcamp";
|
||||
tmpLink.href = elem.bandcampurl;
|
||||
newRow.insertCell(3).appendChild(tmpLink);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
async function test() {
|
||||
const data = await fetch('/refresh').then(response => response.json());
|
||||
if (data != null) {
|
||||
document.getElementById("nb-fait").textContent = data.done;
|
||||
document.getElementById("nb-total").textContent = data.todo;
|
||||
|
||||
if (data.albums != null) {
|
||||
for (const elem of data.albums) {
|
||||
addCell("found", elem);
|
||||
}
|
||||
}
|
||||
|
||||
if (data.artists != null) {
|
||||
for (const elem of data.artists) {
|
||||
addCell("artist-found", elem);
|
||||
}
|
||||
}
|
||||
|
||||
if (data.notfound != null) {
|
||||
for (const elem of data.notfound) {
|
||||
addCell("notfound", elem);
|
||||
}
|
||||
}
|
||||
/*
|
||||
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);
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
if (data.done === data.todo) {
|
||||
document.getElementById("inf-loader").remove();
|
||||
clearInterval(refreshList);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
window.onbeforeunload = function() {
|
||||
return "Vous perdrez tous les artistes trouvés en rafraichissant la page."
|
||||
}
|
||||
|
||||
const refreshList = setInterval(test, 5000);
|
25
struct.go
25
struct.go
|
@ -18,15 +18,32 @@ func newUrlBandcamp(auteur, album, spo, band string) UrlBandcamp {
|
|||
return UrlBandcamp{Artiste: auteur, Album: album, SpotifyUrl: spo, BandcampUrl: band}
|
||||
}
|
||||
|
||||
func newUrlWoBandcamp(auteur, album, spo string) UrlBandcamp {
|
||||
return UrlBandcamp{Artiste: auteur, Album: album, SpotifyUrl: spo, BandcampUrl: ""}
|
||||
}
|
||||
|
||||
type RespBandcamp struct {
|
||||
Done int `json:"done"`
|
||||
Todo int `json:"todo"`
|
||||
Urls []UrlBandcamp `json:"urls"`
|
||||
Albums []UrlBandcamp `json:"albums"`
|
||||
Artists []UrlBandcamp `json:"artists"`
|
||||
Notfound []UrlBandcamp `json:"notfound"`
|
||||
|
||||
}
|
||||
|
||||
func (rp *RespBandcamp) Add(tmp UrlBandcamp) []UrlBandcamp {
|
||||
rp.Urls = append(rp.Urls, tmp)
|
||||
return rp.Urls
|
||||
func (rp *RespBandcamp) AddAlbum(tmp UrlBandcamp) []UrlBandcamp {
|
||||
rp.Albums = append(rp.Albums, tmp)
|
||||
return rp.Albums
|
||||
}
|
||||
|
||||
func (rp *RespBandcamp) AddArtist(tmp UrlBandcamp) []UrlBandcamp {
|
||||
rp.Artists = append(rp.Artists, tmp)
|
||||
return rp.Artists
|
||||
}
|
||||
|
||||
func (rp *RespBandcamp) AddNotfound(tmp UrlBandcamp) []UrlBandcamp {
|
||||
rp.Notfound = append(rp.Notfound, tmp)
|
||||
return rp.Notfound
|
||||
}
|
||||
|
||||
type SpotifyItem struct {
|
||||
|
|
Loading…
Reference in a new issue