From d71620dfd819fe22308b6ef9d9457651bf1dc14c Mon Sep 17 00:00:00 2001 From: lalka2018 <99399973+lalka2016@users.noreply.github.com> Date: Tue, 17 Oct 2023 16:02:28 +0300 Subject: [PATCH] =?UTF-8?q?Make=20shuffle=20and=20"=D0=BD=D0=B0=D1=83?= =?UTF-8?q?=D1=88=D0=BD=D0=B8=D0=BA=D0=B8"=20buttons=20work,=20add=20f...?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit avicons when playing audio, save some values (like volume and last played track) to localstorage, add ability to toggle time type in player, fix uploading audios with cover (maybe) and add dragndrop to upload page --- Web/Models/Entities/Audio.php | 6 +- Web/Models/shell/processAudio.ps1 | 2 +- Web/Presenters/AudioPresenter.php | 7 +- Web/Presenters/templates/Audio/Upload.xml | 21 +++ Web/Presenters/templates/Audio/bigplayer.xml | 3 +- Web/Presenters/templates/Audio/player.xml | 14 +- Web/Presenters/templates/Audio/tabs.xml | 10 +- .../templates/Photos/UploadPhoto.xml | 2 +- Web/Presenters/templates/_includeCSS.xml | 2 +- Web/static/css/audios.css | 5 +- Web/static/img/favicons/favicon24_paused.png | Bin 0 -> 1050 bytes Web/static/img/favicons/favicon24_playing.png | Bin 0 -> 1275 bytes Web/static/js/al_music.js | 176 ++++++++++++++++-- 13 files changed, 207 insertions(+), 41 deletions(-) create mode 100644 Web/static/img/favicons/favicon24_paused.png create mode 100644 Web/static/img/favicons/favicon24_playing.png diff --git a/Web/Models/Entities/Audio.php b/Web/Models/Entities/Audio.php index cdcc73e3..4c11f0a7 100644 --- a/Web/Models/Entities/Audio.php +++ b/Web/Models/Entities/Audio.php @@ -14,7 +14,6 @@ class Audio extends Media { protected $tableName = "audios"; protected $fileExtension = "mpd"; - // protected $fileExtension = "mp3"; # Taken from winamp :D const genres = [ @@ -63,7 +62,10 @@ class Audio extends Media throw new \DomainException("$filename does not contain any audio streams"); $vstreams = Shell::ffprobe("-i", $filename, "-show_streams", "-select_streams v", "-loglevel error")->execute($error); - if(!empty($vstreams) && !ctype_space($vstreams)) + + # check if audio has cover (attached_pic) + preg_match("%attached_pic=([0-1])%", $vstreams, $hasCover); + if(!empty($vstreams) && !ctype_space($vstreams) && ((int)($hasCover[1]) !== 1)) throw new \DomainException("$filename is a video"); $durations = []; diff --git a/Web/Models/shell/processAudio.ps1 b/Web/Models/shell/processAudio.ps1 index dd1db9ad..5404857a 100644 --- a/Web/Models/shell/processAudio.ps1 +++ b/Web/Models/shell/processAudio.ps1 @@ -23,7 +23,7 @@ Set-Location -Path $temp Move-Item $filename $audioFile ffmpeg -i $audioFile -f dash -encryption_scheme cenc-aes-ctr -encryption_key $key ` - -encryption_kid $keyID -map 0 -c:a aac -ar 44100 -seg_duration $seg ` + -encryption_kid $keyID -map 0:a -c:a aac -ar 44100 -seg_duration $seg ` -use_timeline 1 -use_template 1 -init_seg_name ($fileHash + '_fragments/0_0.$ext$') ` -media_seg_name ($fileHash + '_fragments/chunk$Number%06d$_$RepresentationID$.$ext$') -adaptation_sets 'id=0,streams=a' ` "$fileHash.mpd" diff --git a/Web/Presenters/AudioPresenter.php b/Web/Presenters/AudioPresenter.php index 454b0605..0811ecd2 100644 --- a/Web/Presenters/AudioPresenter.php +++ b/Web/Presenters/AudioPresenter.php @@ -236,10 +236,9 @@ final class AudioPresenter extends OpenVKPresenter $audio = $this->audios->get($id); if ($audio && !$audio->isDeleted() && !$audio->isWithdrawn()) { - $audio->listen($this->user->identity); + $listen = $audio->listen($this->user->identity); + $this->returnJson(["success" => $listen]); } - - $this->returnJson(["response" => true]); } } @@ -458,8 +457,6 @@ final class AudioPresenter extends OpenVKPresenter function renderApiGetContext() { - $this->assertUserLoggedIn(); - if ($_SERVER["REQUEST_METHOD"] !== "POST") { header("HTTP/1.1 405 Method Not Allowed"); exit(""); diff --git a/Web/Presenters/templates/Audio/Upload.xml b/Web/Presenters/templates/Audio/Upload.xml index d1628d55..51dee7c0 100644 --- a/Web/Presenters/templates/Audio/Upload.xml +++ b/Web/Presenters/templates/Audio/Upload.xml @@ -149,5 +149,26 @@ document.querySelector("#audio_upload > form").submit(); }) + + $(document).on("dragover drop", (e) => { + e.preventDefault() + + return false; + }) + + $(".container_gray").on("drop", (e) => { + e.originalEvent.dataTransfer.dropEffect = 'move'; + e.preventDefault() + + let file = e.originalEvent.dataTransfer.files[0] + + if(!file.type.startsWith('audio/')) { + MessageBox(tr("error"), tr("only_audios_accepted", escapeHtml(file.name)), [tr("ok")], [() => Function.noop]) + return; + } + + document.getElementById("audio_input").files = e.originalEvent.dataTransfer.files + u("#audio_input").trigger("change") + }) {/block} diff --git a/Web/Presenters/templates/Audio/bigplayer.xml b/Web/Presenters/templates/Audio/bigplayer.xml index 3a22a841..a18132b3 100644 --- a/Web/Presenters/templates/Audio/bigplayer.xml +++ b/Web/Presenters/templates/Audio/bigplayer.xml @@ -17,7 +17,8 @@
00:00 - -00:00 + / + -00:00
diff --git a/Web/Presenters/templates/Audio/player.xml b/Web/Presenters/templates/Audio/player.xml index 558a1aea..da226dab 100644 --- a/Web/Presenters/templates/Audio/player.xml +++ b/Web/Presenters/templates/Audio/player.xml @@ -3,8 +3,8 @@ {php $id = $audio->getId() . rand(0, 1000)} {php $isWithdrawn = $audio->isWithdrawn()} -{php $editable = $audio->canBeModifiedBy($thisUser)} -
+{php $editable = isset($thisUser) && $audio->canBeModifiedBy($thisUser)} +