add open on last.fm button

This commit is contained in:
Evert Prants 2020-01-12 15:49:18 +02:00
parent bcc708ded9
commit 4b92e46b57
Signed by: evert
GPG Key ID: 1688DA83D222D0B5
2 changed files with 16 additions and 0 deletions

View File

@ -73,6 +73,7 @@
<li><a class="ctx-item" data-action="queue">Queue Track</a></li> <li><a class="ctx-item" data-action="queue">Queue Track</a></li>
<li><a class="ctx-item" data-action="edit">Edit Metadata</a></li> <li><a class="ctx-item" data-action="edit">Edit Metadata</a></li>
<li><a class="ctx-item" data-action="download">Download</a></li> <li><a class="ctx-item" data-action="download">Download</a></li>
<li><a class="ctx-item" data-action="lastfm">View on Last.fm</a></li>
<li class="ctx-multi"><a class="ctx-item playlist-add" style="display: none;">Add to Playlist</a> <li class="ctx-multi"><a class="ctx-item playlist-add" style="display: none;">Add to Playlist</a>
<ul class="ctx-sub-items playlist-list" id="ctx-playlists"></ul> <ul class="ctx-sub-items playlist-list" id="ctx-playlists"></ul>
</li> </li>

View File

@ -294,6 +294,18 @@
}) })
} }
function lfmurl (i) {
return i.replace(/\s/g, '+')
}
function popLastFMPage (tid) {
httpGet('/api/track/' + tid).then(function (metadata) {
window.open('https://www.last.fm/music/' + lfmurl(metadata.artist) + '/_/' + lfmurl(metadata.title))
}, function (e) {
console.log(e)
})
}
function ctxHandle (el) { function ctxHandle (el) {
if (ctxState === 0) return if (ctxState === 0) return
let dt = el.getAttribute("data-action") let dt = el.getAttribute("data-action")
@ -310,6 +322,9 @@
case 'download': case 'download':
window.open('/api/serve/by-id/' + ctxState + '?dl=1', '_blank') window.open('/api/serve/by-id/' + ctxState + '?dl=1', '_blank')
break break
case 'lastfm':
popLastFMPage(ctxState)
break
case 'edit': case 'edit':
editTrack(ctxState) editTrack(ctxState)
break break