Get rid of music

Co-authored-by: Celestine <34442450+rem-pai@users.noreply.github.com>
This commit is contained in:
Alma Armas 2021-01-07 16:15:34 +00:00
parent 10f71889ad
commit 9132eb8d98
7 changed files with 0 additions and 360 deletions

View file

@ -1,65 +0,0 @@
<?php declare(strict_types=1);
namespace openvk\Web\Models\Entities;
use Nette\InvalidStateException as ISE;
use BoyHagemann\Wave\Wave;
define("AUDIOS_FRIENDLY_ERROR", "Audio uploads are disabled on this instance :<", false);
class Audio extends Media
{
protected $tableName = "audios";
protected $fileExtension = "mpeg3";
protected function saveFile(string $filename, string $hash): bool
{
if(!is_dir($dirId = OPENVK_ROOT . "/storage/" . substr($hash, 0, 2)))
mkdir($dirId);
try {
$getID3 = new \getID3;
$meta = $getID3->analyze($filename);
if(isset($meta["error"]))
throw new ISE(implode(", ", $meta["error"]));
$this->setPerformer("Неизвестно");
$this->setName("Без названия");
} catch(\Exception $ex) {
exit("Хакеры? Интересно...");
}
return rename($filename, OPENVK_ROOT . "/storage/" . substr($hash, 0, 2) . "/$hash.mpeg3");
}
function getName(): string
{
return $this->getRecord()->name;
}
function getPerformer(): string
{
return $this->getRecord()->performer;
}
function getGenre(): string
{
return $this->getRecord()->genre;
}
function getLyrics(): ?string
{
return $this->getRecord()->lyrics;
}
function getCanonicalName(): string
{
return $this->getRecord()->performer . "" . $this->getRecord()->name;
}
function wire(): void
{
\Chandler\Database\DatabaseConnection::i()->getContext()->table("audio_relations")->insert([
"user" => $this->getRecord()->owner,
"audio" => $this->getId(),
]);
}
}

View file

@ -1,38 +0,0 @@
<?php declare(strict_types=1);
namespace openvk\Web\Models\Repositories;
use openvk\Web\Models\Entities\User;
use openvk\Web\Models\Entities\Audio;
use Chandler\Database\DatabaseConnection;
class Audios
{
private $context;
private $audios;
function __construct()
{
$this->context = DatabaseConnection::i()->getContext();
$this->audios = $this->context->table("audios");
$this->rels = $this->context->table("audio_relations");
}
function get(int $id): ?Video
{
$videos = $this->videos->get($id);
if(!$videos) return NULL;
return new Audio($videos);
}
function getByUser(User $user, int $page = 1, ?int $perPage = NULL): \Traversable
{
$perPage = $perPage ?? OPENVK_DEFAULT_PER_PAGE;
foreach($this->rels->where("user", $user->getId())->page($page, $perPage) as $rel)
yield $this->get($rel->audio);
}
function getUserAudiosCount(User $user): int
{
return sizeof($this->rels->where("user", $user->getId()));
}
}

View file

@ -1,118 +0,0 @@
<?php declare(strict_types=1);
namespace openvk\Web\Presenters;
use openvk\Web\Models\Entities\Audio;
use openvk\Web\Models\Repositories\Users;
use openvk\Web\Models\Repositories\Audios;
use Nette\InvalidStateException as ISE;
class AudiosPresenter extends OpenVKPresenter
{
private $music;
function __construct(Audios $music)
{
$this->music = $music;
parent::__construct();
}
function renderApp(int $user = 0): void
{
$this->assertUserLoggedIn();
$user = (new Users)->get($user === 0 ? $this->user->id : $user);
if(!$user)
$this->notFound();
$this->template->user = $user;
}
function renderUpload(): void
{
$this->assertUserLoggedIn();
$this->willExecuteWriteAction();
if($_SERVER["REQUEST_METHOD"] === "POST") {
if(!isset($_FILES["blob"]))
$this->flashFail("err", "Нету файла", "Выберите файл.");
try {
$audio = new Audio;
$audio->setFile($_FILES["blob"]);
$audio->setOwner($this->user->id);
$audio->setCreated(time());
if(!empty($this->postParam("name")))
$audio->setName($this->postParam("name"));
if(!empty($this->postParam("performer")))
$audio->setPerformer($this->postParam("performer"));
if(!empty($this->postParam("lyrics")))
$audio->setLyrics($this->postParam("lyrics"));
if(!empty($this->postParam("genre")))
$audio->setGenre($this->postParam("genre"));
} catch(ISE $ex) {
$this->flashFaile("err", "Произшла ошибка", "Файл повреждён или имеет неверный формат.");
}
$audio->save();
$audio->wire();
$this->redirect("/audios" . $this->user->id, static::REDIRECT_TEMPORARY);
}
}
function renderApiList(int $user, int $page = 1): void
{
$this->assertUserLoggedIn();
header("Content-Type: application/json");
$owner = (new Users)->get($user);
if(!$owner) {
header("HTTP/1.1 404 Not Found");
exit(json_encode([
"result" => "error",
"response" => [
"error" => [
"code" => 2 << 4,
"desc" => "No user with id = $user",
],
],
]));
}
$music = [];
foreach($this->music->getByUser($owner, $page) as $audio) {
$music[] = [
"id" => $audio->getId(),
"name" => [
"actual" => $audio->getName(),
"full" => $audio->getCanonicalName(),
],
"performer" => $audio->getPerformer(),
"genre" => $audio->getGenre(),
"lyrics" => $audio->getLyrics(),
"meta" => [
"available_formats" => ["mp3"],
"user_unique_id" => $audio->getVirtualId(),
"created" => (string) $audio->getPublicationTime(),
],
"files" => [
[
"format" => "mp3",
"url" => $audio->getURL(),
],
],
];
}
exit(json_encode([
"result" => "success",
"method" => "list",
"response" => [
"count" => $this->music->getUserAudiosCount($owner),
"music" => $music,
"page" => $page,
],
]));
}
}

View file

@ -1,52 +0,0 @@
{extends "../@layout.xml"}
{block title}Аудиопроигрыватель{/block}
{block header}
<a href="{$user->getURL()}">{$user->getCanonicalName()}</a>
»
Аудиозаписи
{/block}
{block content}
<div id="page_act">
<a href="javascript:void(0)">
<b><span>-1</span> аудиозапись</b>
</a>
&nbsp;|&nbsp;
<a href="/audios/upload">Новая аудиозапись</a>
</div>
<div class="music-app">
<div class="music-app--player">
<button class="play">
</button>
<div class="info">
<div class="song-name">
<span><b>Track</b> - <span>not selected</span></span>
<time>--:--</time>
</div>
<div class="track">
<div class="inner-track"></div>
</div>
</div>
</div>
<div class="music-app--gallery">
<div class="song">
<button class="play">
</button>
<div class="info">
<div class="song-name" style="margin-top: 7px;">
<span><b>Track</b> - <span>not selected</span></span>
</div>
</div>
</div>
</div>
</div>
{/block}

View file

@ -1,79 +0,0 @@
{extends "../@layout.xml"}
{block title}Загрузить аудиозапись{/block}
{block header}
<a href="{$thisUser->getURL()}">{$thisUser->getCanonicalName()}</a>
»
<a href="/audios{$thisUser->getId()}">Аудиозаписи</a>
»
Загрузить
{/block}
{block content}
<form method="post" enctype="multipart/form-data">
<table cellspacing="6">
<tbody>
<tr>
<td width="120" valign="top"><span class="nobold">Исполнитель:</span></td>
<td><input type="text" name="performer" /></td>
</tr>
<tr>
<td width="120" valign="top"><span class="nobold">Название песни:</span></td>
<td><input type="text" name="name" /></td>
</tr>
<tr>
<td width="120" valign="top"><span class="nobold">Название песни:</span></td>
<td>
<select name="genre">
<optgroup label="Pop">
<option value="Pop">Pop</option>
<option value="Indie-pop">Indie-pop</option>
<option value="K-POP">капоп</option>
<option value="J-POP">J-POP</option>
<option value="Disco">Electropop/Disco</option>
</optgroup>
<optgroup label="Easy listening">
<option value="Easy listening">Easy listening</option>
<option value="Speech">Speech/Podcast</option>
</optgroup>
<optgroup label="Jazz">
<option value="Jazz">Jazz</option>
<option value="Blues">Blues</option>
</optgroup>
<optgroup label="Acoustinc">
<option value="Acoustic and Vocal">Acoustic and Vocal</option>
<option value="Chanson">Chanson</option>
</optgroup>
<optgroup label="EDM">
<option value="Dance">Dance</option>
<option value="Electronic">Electronic</option>
<option value="Drum and Bass">Drum&Bass</option>
<option value="Dubstep">Dubstep</option>
<option value="Trance">Trance</option>
</optgroup>
<option value="Alternative">Alternative</option>
<option value="Rock">Rock</option>
<option value="Metal">Metal</option>
<option value="Other">Other</option>
</select>
</td>
</tr>
<tr>
<td width="120" valign="top"><span class="nobold">Текст песни:</span></td>
<td><textarea style="margin: 0px; height: 50px; width: 159px; resize: none;" name="lyrics"></textarea></td>
</tr>
<tr>
<td width="120" valign="top"><span class="nobold">Аудиозапись:</span></td>
<td><input type="file" name="blob" accept="audio/mpeg" /></td>
</tr>
<tr>
<td width="120" valign="top"></td>
<td>
<input type="hidden" name="hash" value="{$csrfToken}" />
<input type="submit" class="button" name="submit" value="Загрузить" />
</td>
</tr>
</tbody>
</table>
</form>
{/block}

View file

@ -7,7 +7,6 @@ services:
- openvk\Web\Presenters\CommentPresenter - openvk\Web\Presenters\CommentPresenter
- openvk\Web\Presenters\PhotosPresenter - openvk\Web\Presenters\PhotosPresenter
- openvk\Web\Presenters\VideosPresenter - openvk\Web\Presenters\VideosPresenter
- openvk\Web\Presenters\AudiosPresenter
- openvk\Web\Presenters\BlobPresenter - openvk\Web\Presenters\BlobPresenter
- openvk\Web\Presenters\GroupPresenter - openvk\Web\Presenters\GroupPresenter
- openvk\Web\Presenters\SearchPresenter - openvk\Web\Presenters\SearchPresenter
@ -28,7 +27,6 @@ services:
- openvk\Web\Models\Repositories\Clubs - openvk\Web\Models\Repositories\Clubs
- openvk\Web\Models\Repositories\Videos - openvk\Web\Models\Repositories\Videos
- openvk\Web\Models\Repositories\Notes - openvk\Web\Models\Repositories\Notes
- openvk\Web\Models\Repositories\Audios
- openvk\Web\Models\Repositories\Tickets - openvk\Web\Models\Repositories\Tickets
- openvk\Web\Models\Repositories\Messages - openvk\Web\Models\Repositories\Messages
- openvk\Web\Models\Repositories\Restores - openvk\Web\Models\Repositories\Restores

View file

@ -133,12 +133,6 @@ routes:
handler: "Videos->edit" handler: "Videos->edit"
- url: "/video{num}_{num}/remove" - url: "/video{num}_{num}/remove"
handler: "Videos->remove" handler: "Videos->remove"
- url: "/audios{num}"
handler: "Audios->app"
- url: "/audios/upload"
handler: "Audios->upload"
- url: "/audios/api/list{num}/{num}.json"
handler: "Audios->apiList"
- url: "/{?!club}{num}" - url: "/{?!club}{num}"
handler: "Group->view" handler: "Group->view"
placeholders: placeholders: