webmusic/Pages/Index.cshtml

108 lines
4.1 KiB
Plaintext
Raw Normal View History

@page
2020-12-21 21:31:18 +01:00
@using System.IO
2023-06-01 01:57:21 +02:00
@using System.Web
@model IndexModel
@{
2023-06-01 01:56:42 +02:00
if (Model.LogConditionsMet)
2023-11-05 14:13:04 +01:00
ViewData["Title"] = $"{Model.LogDisplay} ~ webmusic on .NET {Environment.Version}";
2023-06-01 01:56:42 +02:00
else
2023-06-01 01:57:55 +02:00
ViewData["Title"] = $"{Model.Displaypath} ~ webmusic on .NET {Environment.Version}";
}
2020-12-21 20:42:29 +01:00
@if (Model.Path.Contains("/..")) {
return;
}
2020-12-21 20:42:29 +01:00
@if (Model.Path.EndsWith(".lrc")) {
2021-06-25 15:01:44 +02:00
Layout = "Shared/_LayoutNojs";
2020-12-21 20:42:29 +01:00
<h3>@Model.Path</h3>
<p>@Html.Raw((await System.IO.File.ReadAllTextAsync("music" + Model.Path)).Replace("\n", "<br/>"))</p>
2019-08-12 20:16:33 +02:00
}
2020-12-21 20:42:29 +01:00
else {
<h2>
more modern js, more keyboard-controls (#5) webmusic.js: prevent default action for keydown events webmusic.js: check for playable content webmusic.js: hide selector when track selected webmusic.js: ignore keyboard controls if ctrl or alt is pressed webmusic.js: seeking in track with number keys webmusic.js: use single quotes everywhere webmusic.js: use arrow functions everywhere webmusic.js: use const for audioplayer and variable element in function playSong webmusic.js: use strict mode webmusic.js: add classes needed for previous 2 commits webmusic.js: use classes for buttons webmusic.js: navigating through files/folders with arrowkeys/enter webmusic.js: removed debug prints, better player handling webmusic.js: bind to audioplayer-events just once webmusic.js: renamed gstate to playerState webmusic.js: renamed setState to setPlayerState and updateState to updatePlayerState webmusic.css: replaced spaces with tabs needed changes on template and css to make previous commit work webmusic.js: refactor continuous- and repeat-button handling webmusic.js: general code improvements webmusic.js: rename variable 'sound' to 'audioPlayer' remove howler.core.js webmusic.js: replace howler with the native Audio() element webmusic.js: set onclick-event on state element just once webmusic.js: skip folders needed changes on template to make previous commit work webmusic.js: navigate through files more smartly webmusic.js: code improovements webmusic.js: replace spaces with tabs webmusic.js: replace ifs with switch Co-authored-by: Leah (ctucx) <leah@ctu.cx> Co-authored-by: Isabelle <hi@f2k1.de> Co-authored-by: ctucx <c@ctu.cx> Reviewed-on: https://git.zotan.services/zotan/webmusic/pulls/5 Co-Authored-By: Leah <leah@ctu.cx> Co-Committed-By: Leah <leah@ctu.cx>
2021-03-21 18:04:15 +01:00
@Model.Displaypath <span id="state"></span> <span id="flags">[<span id="repeatButton">R</span><span id="continuousButton">C</span>]</span>
2020-12-21 20:42:29 +01:00
</h2>
<a class="action-muted">[..]</a>
2021-05-27 16:15:56 +02:00
<a href="?@IndexModel.Encode(Model.PathOneup)" id="back" class="entry-muted cfont"> Go back</a>
2023-04-07 21:02:14 +02:00
<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>
2023-04-07 21:02:14 +02:00
<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>
}
2020-12-21 20:42:29 +01:00
<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>
2020-12-21 20:42:29 +01:00
}
@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)) {
2023-05-27 03:45:36 +02:00
<a class="action" href="/lyrics/?@Html.Raw(IndexModel.Encode(Model.Path + "/" + lrcfile))" target="_blank">[LRC]</a>
}
2023-04-07 21:02:14 +02:00
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>
2020-12-21 20:42:29 +01:00
}
}
2022-11-21 02:03:01 +01:00
<script>
2023-04-07 21:02:14 +02:00
function log_playback(url) {
2022-11-21 02:03:01 +01:00
fetch(url).then(function(response) {
2022-11-21 02:06:43 +01:00
return response.text();
}).then(function(text) {
2023-04-07 21:02:14 +02:00
document.getElementById('log').innerText = 'Log playback (' + text + ')';
2022-11-21 02:03:01 +01:00
});
}
2023-04-07 21:02:14 +02:00
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() {
2023-04-13 15:28:22 +02:00
copyToClipboard('[#np](@Html.Raw(Log.NowPlayingUrl)) @Html.Raw(Model.CopyArtist) - @Html.Raw(Model.CopyAlbum)');
2023-04-07 21:02:14 +02:00
reset_copy_labels();
document.getElementById('copy_hash_np').innerText = 'Copy #np (Copied!)';
}
function copy_journal_full() {
2023-04-13 15:28:22 +02:00
copyToClipboard('[@Html.Raw(Model.CopyArtist)](' + getUrl('@Html.Raw(Model.LogArtist)') + ') - [@Html.Raw(Model.CopyAlbum)](' + getUrl('@Html.Raw(Model.LogArtist)', '@Html.Raw(Model.LogAlbum)') + ')')
2023-04-07 21:02:14 +02:00
reset_copy_labels();
document.getElementById('copy_journal_full').innerText = 'Copy journal (full) (Copied!)';
}
function copy_journal_album() {
2023-04-13 15:28:22 +02:00
copyToClipboard(', [@Html.Raw(Model.CopyAlbum)](' + getUrl('@Html.Raw(Model.LogArtist)', '@Html.Raw(Model.LogAlbum)') + ')')
2023-04-07 21:02:14 +02:00
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;
}
2022-11-21 02:03:01 +01:00
</script>