Пример #1
0
 public static function contextify(SelectQuery $query)
 {
     $limit = self::$request->get("l")->filter(Filter::isNumber())->filter(Filter::isPositiveNumber());
     $offset = self::$request->get("o")->filter(Filter::isNumber())->filter(Filter::isPositiveNumber());
     $sort_field = self::$request->get("sf");
     $sort_order = self::$request->get("so");
     $max_limit = self::$settings->get("catalog", "items_per_request_limit");
     $limit->then([$query, "limit"]);
     $offset->then([$query, "offset"]);
     //        $query->limit($limit->filter(Filter::isLessThan($max_limit))->getOrElse($max_limit));
     //        $query->offset($offset->orZero());
 }
Пример #2
0
 /**
  * Reads audio file metadata and returns Metadata object.
  *
  * @param string $filename
  * @param string $original_filename
  * @return Some
  */
 public static function read($filename, $original_filename = null)
 {
     $escaped_filename = escapeshellarg($filename);
     $file_format = strtolower(pathinfo($original_filename, PATHINFO_EXTENSION));
     $command = sprintf(self::$settings->get("command_templates", "read_metadata"), self::$settings->get("tools", "ffprobe_cmd"), $escaped_filename);
     exec($command, $result, $status);
     if ($status != 0) {
         return Option::None();
     }
     /**
      * @var Option[] $metadata
      * @var Option[] $o_format
      * @var Option[] $o_tags
      */
     $metadata = Option::Some(json_decode(implode("", $result), true));
     $o_format = $metadata["format"];
     $o_tags = $o_format["tags"];
     $object = new Metadata();
     $object->format_name = $file_format;
     $object->filename = $o_format["filename"]->get();
     $object->duration = $o_format["duration"]->map(function ($value) {
         return intval($value * 1000);
     })->get();
     $object->size = $o_format["size"]->toInt()->get();
     $object->bitrate = $o_format["bit_rate"]->toInt()->get();
     $object->meta_artist = $o_tags["artist"]->orEmpty();
     $object->meta_title = $o_tags["title"]->orEmpty();
     $object->meta_genre = $o_tags["genre"]->orEmpty();
     $object->meta_date = $o_tags["date"]->orEmpty();
     $object->meta_album = $o_tags["album"]->orEmpty();
     $object->meta_track_number = $o_tags["track"]->toInt()->orNull();
     $object->meta_disc_number = $o_tags["disc"]->toInt()->orNull();
     $object->meta_album_artist = $o_tags["album_artist"]->orEmpty();
     $object->is_compilation = $o_tags["compilation"]->map("bool")->getOrElse("false");
     $object->meta_comment = $o_tags["comment"]->orEmpty();
     return Option::Some($object);
 }
Пример #3
0
 /**
  * Reads audio file record from database and generates audio preview.
  */
 public function preview()
 {
     Logger::printf("Requested preview for track %s", $this->track_id);
     if ($this->hasPreview()) {
         Logger::printf("Track preview is available (file_id is %s)", $this->track_data[TSongs::PREVIEW_ID]);
         FileServer::sendToClient($this->track_data[TSongs::PREVIEW_ID]);
         return;
     }
     Logger::printf("Track preview is unavailable");
     Logger::printf("Generating new track preview in real time");
     header("Content-Type: " . PREVIEW_MIME);
     $temp_file = TempFileProvider::generate("preview", ".mp3");
     $filename = FileServer::getFileUsingId($this->track_data[TSongs::FILE_ID]);
     $command_template = "%s -i %s -bufsize 256k -vn -ab 128k -ac 2 -acodec libmp3lame -f mp3 - | tee %s";
     $command = sprintf($command_template, $this->settings->get("tools", "ffmpeg_cmd"), escapeshellarg($filename), escapeshellarg($temp_file));
     passthru($command);
     $temp_file_id = FileServer::register($temp_file, PREVIEW_MIME);
     Logger::printf("New preview registered => %s", $temp_file_id);
     SongDao::updateSongUsingId($this->track_id, [TSongs::PREVIEW_ID => $temp_file_id]);
 }
Пример #4
0
<?php

/**
 * Database configuration file
 *
 * Created by PhpStorm
 * User: roman
 * Date: 16.07.15
 * Time: 20:17
 */
use app\core\db\DatabaseConfiguration;
use app\core\etc\Settings;
use app\core\modular\Event;
Event::addFilter("database.configure", function (DatabaseConfiguration $config) {
    $settings = Settings::getInstance();
    $config->setDsnLogin($settings->get("pdo", "login"));
    $config->setDsnPassword($settings->get("pdo", "password"));
    $config->setDsnUri($settings->get("pdo", "dsn"));
    return $config;
});
Пример #5
0
 /**
  * @param $hash
  * @return string
  */
 public static function hashToPath($hash)
 {
     $prefix = Settings::getInstance()->get("fs", "media");
     return sprintf("%s/%s/%s", $prefix, substr($hash, 0, 1), substr($hash, 1, 1));
 }