Skip to content

Commit

Permalink
Solve problems related with clashing on items selection...
Browse files Browse the repository at this point in the history
...and also double quotes in artist, album or song names.
  • Loading branch information
rafael-santiago committed Jun 30, 2024
1 parent 5f76ed3 commit 0cccb32
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 5 deletions.
7 changes: 6 additions & 1 deletion src/internal/actions/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ func getMetaRecordInfoFromSelectionId(selectionId string, offset int) string {
startOff += endOff + 1
}
}
return selectionId[startOff:endOff]
info := selectionId[startOff:endOff]
eutpidIndex := strings.Index(info, "-eutpid_")
if eutpidIndex > -1 {
info = info[:eutpidIndex]
}
return info
}

4 changes: 4 additions & 0 deletions src/internal/mplayer/songinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,11 @@ func normalizeStr(str string) string {

func normalizeSongInfo(songInfo *SongInfo) {
songInfo.Artist = strings.Replace(songInfo.Artist, "/", "-", -1)
songInfo.Artist = strings.Replace(songInfo.Artist, "\"", "'", -1)
songInfo.Album = strings.Replace(songInfo.Album, "/", "-", -1)
songInfo.Album = strings.Replace(songInfo.Album, "\"", "'", -1)
songInfo.Title = strings.Replace(songInfo.Title, "/", "-", -1)
songInfo.Title = strings.Replace(songInfo.Title, "\"", "'", -1)
songInfo.Artist = strings.ToLower(normalizeStr(songInfo.Artist))
songInfo.Album = strings.ToLower(normalizeStr(songInfo.Album))
songInfo.Title = strings.ToLower(normalizeStr(songInfo.Title))
Expand Down
10 changes: 8 additions & 2 deletions src/internal/renders/collection_render.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"internal/vars"
"internal/mplayer"
"strings"
"fmt"
)

func CollectionRender(templatedInput string, eutherpeVars *vars.EutherpeVars) string {
Expand All @@ -23,6 +24,7 @@ func CollectionRender(templatedInput string, eutherpeVars *vars.EutherpeVars) st
}

func renderCollectionListing(collection mplayer.MusicCollection) string {
var idNr uint64
collectionHTML := "<ul id=\"eutherpeUL\">"
artists := mplayer.GetArtistsFromCollection(collection)
for _, artist := range artists {
Expand All @@ -31,12 +33,16 @@ func renderCollectionListing(collection mplayer.MusicCollection) string {
collectionHTML += "<ul class=\"nested\">"
albums := mplayer.GetAlbumsFromArtist(artist, collection)
for _, album := range albums {
albumId := fmt.Sprintf("%s/%s-eutpid_%d", artist, album, idNr)
idNr++
collectionHTML += "<li>"
collectionHTML += "<input type=\"checkbox\" onclick=\"flush_child(this);\" id=\"" + artist + "/" + album + "\" class=\"CollectionAlbum\"><span class=\"caret\">" + album + "</span>"
collectionHTML += "<input type=\"checkbox\" onclick=\"flush_child(this);\" id=\"" + albumId + "\" class=\"CollectionAlbum\"><span class=\"caret\">" + album + "</span>"
collectionHTML += "<ul class=\"nested\">"
tracks := collection[artist][album]
for _, track := range tracks {
collectionHTML += "<li><input type=\"checkbox\" onclick=\"flush_child(this);\" id=\"" + artist + "/" + album + "/" + track.Title + ":" + track.FilePath + "\" class=\"CollectionSong\">" + track.Title + "</li>"
trackId := fmt.Sprintf("%s-eutpid_%d", track.Title, idNr)
idNr++
collectionHTML += "<li><input type=\"checkbox\" onclick=\"flush_child(this);\" id=\"" + albumId + "/" + trackId + ":" + track.FilePath + "\" class=\"CollectionSong\">" + track.Title + "</li>"
}
collectionHTML += "</ul></li>"
}
Expand Down
3 changes: 2 additions & 1 deletion src/internal/renders/collection_render_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ func TestCollectionRender(t *testing.T) {
}
templatedInput := fmt.Sprintf("%s", vars.EutherpeTemplateNeedleCollection)
output := CollectionRender(templatedInput, eutherpeVars)
if output != "<ul id=\"eutherpeUL\"><li><input type=\"checkbox\" onclick=\"flush_child(this);\" id=\"Motorhead\" class=\"CollectionArtist\"><span class=\"caret\">Motorhead</span><ul class=\"nested\"><li><input type=\"checkbox\" onclick=\"flush_child(this);\" id=\"Motorhead/Overkill\" class=\"CollectionAlbum\"><span class=\"caret\">Overkill</span><ul class=\"nested\"><li><input type=\"checkbox\" onclick=\"flush_child(this);\" id=\"Motorhead/Overkill/Overkill:overkill.mp3\" class=\"CollectionSong\">Overkill</li><li><input type=\"checkbox\" onclick=\"flush_child(this);\" id=\"Motorhead/Overkill/Stay Clean:stay-clean.mp3\" class=\"CollectionSong\">Stay Clean</li><li><input type=\"checkbox\" onclick=\"flush_child(this);\" id=\"Motorhead/Overkill/(I Won't) Pay Your Price:pay-your-price.mp3\" class=\"CollectionSong\">(I Won't) Pay Your Price</li></ul></li><li><input type=\"checkbox\" onclick=\"flush_child(this);\" id=\"Motorhead/Bomber\" class=\"CollectionAlbum\"><span class=\"caret\">Bomber</span><ul class=\"nested\"><li><input type=\"checkbox\" onclick=\"flush_child(this);\" id=\"Motorhead/Bomber/Dead Men Tell No Tales:dead_men_tell_no_tales.mp3\" class=\"CollectionSong\">Dead Men Tell No Tales</li></ul></li></ul></li><li><input type=\"checkbox\" onclick=\"flush_child(this);\" id=\"Queens Of The Stone Age\" class=\"CollectionArtist\"><span class=\"caret\">Queens Of The Stone Age</span><ul class=\"nested\"><li><input type=\"checkbox\" onclick=\"flush_child(this);\" id=\"Queens Of The Stone Age/Queens Of The Stone Age\" class=\"CollectionAlbum\"><span class=\"caret\">Queens Of The Stone Age</span><ul class=\"nested\"><li><input type=\"checkbox\" onclick=\"flush_child(this);\" id=\"Queens Of The Stone Age/Queens Of The Stone Age/Regular John:regular-john.mp3\" class=\"CollectionSong\">Regular John</li></ul></li></ul></li><li><input type=\"checkbox\" onclick=\"flush_child(this);\" id=\"The Cramps\" class=\"CollectionArtist\"><span class=\"caret\">The Cramps</span><ul class=\"nested\"><li><input type=\"checkbox\" onclick=\"flush_child(this);\" id=\"The Cramps/Songs The Lord Taught Us\" class=\"CollectionAlbum\"><span class=\"caret\">Songs The Lord Taught Us</span><ul class=\"nested\"><li><input type=\"checkbox\" onclick=\"flush_child(this);\" id=\"The Cramps/Songs The Lord Taught Us/Fever:fever.mp3\" class=\"CollectionSong\">Fever</li></ul></li></ul></li></ul>" {
fmt.Println(output)
if output != "<ul id=\"eutherpeUL\"><li><input type=\"checkbox\" onclick=\"flush_child(this);\" id=\"Motorhead\" class=\"CollectionArtist\"><span class=\"caret\">Motorhead</span><ul class=\"nested\"><li><input type=\"checkbox\" onclick=\"flush_child(this);\" id=\"Motorhead/Overkill-eutpid_0\" class=\"CollectionAlbum\"><span class=\"caret\">Overkill</span><ul class=\"nested\"><li><input type=\"checkbox\" onclick=\"flush_child(this);\" id=\"Motorhead/Overkill-eutpid_0/Overkill-eutpid_1:overkill.mp3\" class=\"CollectionSong\">Overkill</li><li><input type=\"checkbox\" onclick=\"flush_child(this);\" id=\"Motorhead/Overkill-eutpid_0/Stay Clean-eutpid_2:stay-clean.mp3\" class=\"CollectionSong\">Stay Clean</li><li><input type=\"checkbox\" onclick=\"flush_child(this);\" id=\"Motorhead/Overkill-eutpid_0/(I Won't) Pay Your Price-eutpid_3:pay-your-price.mp3\" class=\"CollectionSong\">(I Won't) Pay Your Price</li></ul></li><li><input type=\"checkbox\" onclick=\"flush_child(this);\" id=\"Motorhead/Bomber-eutpid_4\" class=\"CollectionAlbum\"><span class=\"caret\">Bomber</span><ul class=\"nested\"><li><input type=\"checkbox\" onclick=\"flush_child(this);\" id=\"Motorhead/Bomber-eutpid_4/Dead Men Tell No Tales-eutpid_5:dead_men_tell_no_tales.mp3\" class=\"CollectionSong\">Dead Men Tell No Tales</li></ul></li></ul></li><li><input type=\"checkbox\" onclick=\"flush_child(this);\" id=\"Queens Of The Stone Age\" class=\"CollectionArtist\"><span class=\"caret\">Queens Of The Stone Age</span><ul class=\"nested\"><li><input type=\"checkbox\" onclick=\"flush_child(this);\" id=\"Queens Of The Stone Age/Queens Of The Stone Age-eutpid_6\" class=\"CollectionAlbum\"><span class=\"caret\">Queens Of The Stone Age</span><ul class=\"nested\"><li><input type=\"checkbox\" onclick=\"flush_child(this);\" id=\"Queens Of The Stone Age/Queens Of The Stone Age-eutpid_6/Regular John-eutpid_7:regular-john.mp3\" class=\"CollectionSong\">Regular John</li></ul></li></ul></li><li><input type=\"checkbox\" onclick=\"flush_child(this);\" id=\"The Cramps\" class=\"CollectionArtist\"><span class=\"caret\">The Cramps</span><ul class=\"nested\"><li><input type=\"checkbox\" onclick=\"flush_child(this);\" id=\"The Cramps/Songs The Lord Taught Us-eutpid_8\" class=\"CollectionAlbum\"><span class=\"caret\">Songs The Lord Taught Us</span><ul class=\"nested\"><li><input type=\"checkbox\" onclick=\"flush_child(this);\" id=\"The Cramps/Songs The Lord Taught Us-eutpid_8/Fever-eutpid_9:fever.mp3\" class=\"CollectionSong\">Fever</li></ul></li></ul></li></ul>" {
t.Errorf("CollectionRender() seems not to be working accordingly. : '%s'\n", output)
}
}
2 changes: 1 addition & 1 deletion src/internal/renders/test-data/expected-eutherpe.html
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ <h2 class="info-banner">&#x1F9A5; Wait... &#x23F3;</h2>
<h3>&#x1F3B6; Collection</h3>
<hr>
<div class="scrollbox">
<ul id="eutherpeUL"><li><input type="checkbox" onclick="flush_child(this);" id="Motorhead" class="CollectionArtist"><span class="caret">Motorhead</span><ul class="nested"><li><input type="checkbox" onclick="flush_child(this);" id="Motorhead/Overkill" class="CollectionAlbum"><span class="caret">Overkill</span><ul class="nested"><li><input type="checkbox" onclick="flush_child(this);" id="Motorhead/Overkill/Overkill:overkill.mp3" class="CollectionSong">Overkill</li><li><input type="checkbox" onclick="flush_child(this);" id="Motorhead/Overkill/Stay Clean:stay-clean.mp3" class="CollectionSong">Stay Clean</li><li><input type="checkbox" onclick="flush_child(this);" id="Motorhead/Overkill/(I Won't) Pay Your Price:pay-your-price.mp3" class="CollectionSong">(I Won't) Pay Your Price</li></ul></li><li><input type="checkbox" onclick="flush_child(this);" id="Motorhead/Bomber" class="CollectionAlbum"><span class="caret">Bomber</span><ul class="nested"><li><input type="checkbox" onclick="flush_child(this);" id="Motorhead/Bomber/Dead Men Tell No Tales:dead_men_tell_no_tales.mp3" class="CollectionSong">Dead Men Tell No Tales</li></ul></li></ul></li><li><input type="checkbox" onclick="flush_child(this);" id="Queens Of The Stone Age" class="CollectionArtist"><span class="caret">Queens Of The Stone Age</span><ul class="nested"><li><input type="checkbox" onclick="flush_child(this);" id="Queens Of The Stone Age/Queens Of The Stone Age" class="CollectionAlbum"><span class="caret">Queens Of The Stone Age</span><ul class="nested"><li><input type="checkbox" onclick="flush_child(this);" id="Queens Of The Stone Age/Queens Of The Stone Age/Regular John:regular-john.mp3" class="CollectionSong">Regular John</li></ul></li></ul></li><li><input type="checkbox" onclick="flush_child(this);" id="The Cramps" class="CollectionArtist"><span class="caret">The Cramps</span><ul class="nested"><li><input type="checkbox" onclick="flush_child(this);" id="The Cramps/Songs The Lord Taught Us" class="CollectionAlbum"><span class="caret">Songs The Lord Taught Us</span><ul class="nested"><li><input type="checkbox" onclick="flush_child(this);" id="The Cramps/Songs The Lord Taught Us/Fever:fever.mp3" class="CollectionSong">Fever</li></ul></li></ul></li></ul>
<ul id="eutherpeUL"><li><input type="checkbox" onclick="flush_child(this);" id="Motorhead" class="CollectionArtist"><span class="caret">Motorhead</span><ul class="nested"><li><input type="checkbox" onclick="flush_child(this);" id="Motorhead/Overkill-eutpid_0" class="CollectionAlbum"><span class="caret">Overkill</span><ul class="nested"><li><input type="checkbox" onclick="flush_child(this);" id="Motorhead/Overkill-eutpid_0/Overkill-eutpid_1:overkill.mp3" class="CollectionSong">Overkill</li><li><input type="checkbox" onclick="flush_child(this);" id="Motorhead/Overkill-eutpid_0/Stay Clean-eutpid_2:stay-clean.mp3" class="CollectionSong">Stay Clean</li><li><input type="checkbox" onclick="flush_child(this);" id="Motorhead/Overkill-eutpid_0/(I Won't) Pay Your Price-eutpid_3:pay-your-price.mp3" class="CollectionSong">(I Won't) Pay Your Price</li></ul></li><li><input type="checkbox" onclick="flush_child(this);" id="Motorhead/Bomber-eutpid_4" class="CollectionAlbum"><span class="caret">Bomber</span><ul class="nested"><li><input type="checkbox" onclick="flush_child(this);" id="Motorhead/Bomber-eutpid_4/Dead Men Tell No Tales-eutpid_5:dead_men_tell_no_tales.mp3" class="CollectionSong">Dead Men Tell No Tales</li></ul></li></ul></li><li><input type="checkbox" onclick="flush_child(this);" id="Queens Of The Stone Age" class="CollectionArtist"><span class="caret">Queens Of The Stone Age</span><ul class="nested"><li><input type="checkbox" onclick="flush_child(this);" id="Queens Of The Stone Age/Queens Of The Stone Age-eutpid_6" class="CollectionAlbum"><span class="caret">Queens Of The Stone Age</span><ul class="nested"><li><input type="checkbox" onclick="flush_child(this);" id="Queens Of The Stone Age/Queens Of The Stone Age-eutpid_6/Regular John-eutpid_7:regular-john.mp3" class="CollectionSong">Regular John</li></ul></li></ul></li><li><input type="checkbox" onclick="flush_child(this);" id="The Cramps" class="CollectionArtist"><span class="caret">The Cramps</span><ul class="nested"><li><input type="checkbox" onclick="flush_child(this);" id="The Cramps/Songs The Lord Taught Us-eutpid_8" class="CollectionAlbum"><span class="caret">Songs The Lord Taught Us</span><ul class="nested"><li><input type="checkbox" onclick="flush_child(this);" id="The Cramps/Songs The Lord Taught Us-eutpid_8/Fever-eutpid_9:fever.mp3" class="CollectionSong">Fever</li></ul></li></ul></li></ul>
</div>
<center>
<hr>
Expand Down

0 comments on commit 0cccb32

Please sign in to comment.