webmusic/Pages/Index.cshtml

108 lines
4.1 KiB
Plaintext

@page
@using System.IO
@using System.Web
@model IndexModel
@{
if (Model.LogConditionsMet)
ViewData["Title"] = $"{Model.LogDisplay} ~ webmusic on .NET {Environment.Version}";
else
ViewData["Title"] = $"{Model.Displaypath} ~ webmusic on .NET {Environment.Version}";
}
@if (Model.Path.Contains("/..")) {
return;
}
@if (Model.Path.EndsWith(".lrc")) {
Layout = "Shared/_LayoutNojs";
<h3>@Model.Path</h3>
<p>@Html.Raw((await System.IO.File.ReadAllTextAsync("music" + Model.Path)).Replace("\n", "<br/>"))</p>
}
else {
<h2>
@Model.Displaypath <span id="state"></span> <span id="flags">[<span id="repeatButton">R</span><span id="continuousButton">C</span>]</span>
</h2>
<a class="action-muted">[..]</a>
<a href="?@IndexModel.Encode(Model.PathOneup)" id="back" class="entry-muted cfont"> Go back</a>
<br/>
<a class="action-muted">[--]</a>
<a href="/playlist/@(Request.QueryString).m3u" class="entry-muted cfont"> Download playlist</a>
@if (Model.LogConditionsMet) {
<br/>
<a class="action-muted">[--]</a>
<span id="log" onclick="log_playback('/log?artist=@Model.LogArtist&album=@Model.LogAlbum&url=@Model.LogUrl')" class="entry-muted cfont" style="cursor: pointer">Log playback</span>
<span class="action-muted">/</span>
<span id="copy_hash_np" onclick="copy_hash_np()" class="entry-muted cfont" style="cursor: pointer">Copy #np</span>
<span class="action-muted">/</span>
<span id="copy_journal_full" onclick="copy_journal_full()" class="entry-muted cfont" style="cursor: pointer">Copy journal (full)</span>
<span class="action-muted">/</span>
<span id="copy_journal_album" onclick="copy_journal_album()" class="entry-muted cfont" style="cursor: pointer">Copy journal (album only)</span>
}
<br/>
<br/>
@foreach (var dir in Model.Dirs) {
<li>
<a class="action" href="#">[--]</a>
<a class="dir" href="?@IndexModel.Encode(Model.Path + "/" + dir)"> @dir</a>
</li>
}
@foreach (var file in Model.Files) {
var basename = System.IO.Path.GetFileNameWithoutExtension(file);
var lrcfile = basename + ".lrc";
var lrcpath = System.IO.Path.Combine(Model.Fullpath, lrcfile);
<li>
<a class="action" href="@Html.Raw(IndexModel.Encode(Model.Fullpath + "/" + file))" download>[DL]</a>
@if (System.IO.File.Exists(lrcpath)) {
<a class="action" href="/lyrics/?@Html.Raw(IndexModel.Encode(Model.Path + "/" + lrcfile))" target="_blank">[LRC]</a>
}
else if (Directory.GetFiles(Model.Fullpath, "*.lrc").Length != 0) {
<a class="action">[---]</a>
}
<a class="file" href="@Html.Raw(IndexModel.Encode(Model.Fullpath + "/" + file))"> @file</a>
</li>
}
}
<script>
function log_playback(url) {
fetch(url).then(function(response) {
return response.text();
}).then(function(text) {
document.getElementById('log').innerText = 'Log playback (' + text + ')';
});
}
function reset_copy_labels() {
document.getElementById('copy_hash_np').innerText = 'Copy #np';
document.getElementById('copy_journal_full').innerText = 'Copy journal (full)';
document.getElementById('copy_journal_album').innerText = 'Copy journal (album only)';
}
function copy_hash_np() {
copyToClipboard('[#np](@Html.Raw(Log.NowPlayingUrl)) @Html.Raw(Model.CopyArtist) - @Html.Raw(Model.CopyAlbum)');
reset_copy_labels();
document.getElementById('copy_hash_np').innerText = 'Copy #np (Copied!)';
}
function copy_journal_full() {
copyToClipboard('[@Html.Raw(Model.CopyArtist)](' + getUrl('@Html.Raw(Model.LogArtist)') + ') - [@Html.Raw(Model.CopyAlbum)](' + getUrl('@Html.Raw(Model.LogArtist)', '@Html.Raw(Model.LogAlbum)') + ')')
reset_copy_labels();
document.getElementById('copy_journal_full').innerText = 'Copy journal (full) (Copied!)';
}
function copy_journal_album() {
copyToClipboard(', [@Html.Raw(Model.CopyAlbum)](' + getUrl('@Html.Raw(Model.LogArtist)', '@Html.Raw(Model.LogAlbum)') + ')')
reset_copy_labels();
document.getElementById('copy_journal_album').innerText = 'Copy journal (album only) (Copied!)';
}
function getUrl(artist, album) {
let url = location.protocol + '//' + location.host + '/?/' + artist;
if (album) {
url += '/' + album;
}
return url;
}
</script>