/**
  * @Route("/{id}", name="view", requirements={"id"="\d+"})
  */
 public function viewAction($id)
 {
     $artist = Artist::query()->where('id = ?', [$id])->related('album')->first();
     $request = App::request();
     if (is_null($artist)) {
         $request->getSession()->getFlashBag()->add('error', __('Tried to view an non-existing Artist'));
         return App::response()->redirect('@shoutzor/artist/index');
     }
     $topTracks = $artist->getTopMedia();
     return ['$view' => ['title' => 'Artist: ' . $artist->name, 'name' => 'shoutzor:views/artist/view.php'], 'image' => is_null($artist->image) || empty($artist->image) ? App::url()->getStatic('shoutzor:assets/images/profile-placeholder.png') : App::url()->getStatic('shoutzor:' . App::module('shoutzor')->config('shoutzor')['imageDir'] . '/' . $artist->image), 'summary' => empty($artist->summary) ? __('No summary for this artist is available') : $artist->summary, 'artist' => $artist, 'topTracks' => $topTracks, 'albums' => $artist->getAlbums()];
 }
Exemple #2
0
 /**
  * @Route("/search", name="search", methods="GET")
  * @Request({"q":"string", "page":"int"})
  */
 public function searchAction($q = "", $page = 1)
 {
     $query = Artist::query()->select('*');
     $request = App::request();
     if (empty($q)) {
         return ['$view' => ['title' => 'Search', 'name' => 'shoutzor:views/search_error.php']];
     }
     $query = Media::query()->select('m.*')->from('@shoutzor_media m')->leftJoin('@shoutzor_media_artist ma', 'ma.media_id = m.id')->leftJoin('@shoutzor_artist a', 'a.id = ma.artist_id')->where('m.status = :status AND (m.title LIKE :search OR a.name LIKE :search OR m.filename LIKE :search)', ['status' => Media::STATUS_FINISHED, 'search' => "%{$q}%"])->orderBy('m.title', 'DESC');
     $limit = 20;
     $count = $query->count();
     $total = ceil($count / $limit);
     $page = max(1, min($total, $page));
     $results = $query->offset(($page - 1) * $limit)->limit($limit)->orderBy('name', 'ASC')->related(['artist', 'album'])->get();
     return ['$view' => ['title' => 'Search', 'name' => 'shoutzor:views/search.php'], 'searchterm' => htmlspecialchars($q), 'page' => $page, 'totalPage' => $total, 'resultCount' => $count, 'results' => $results];
 }
Exemple #3
0
 public function addArtist(Media $media, $name)
 {
     $name = ucfirst(strtolower($name));
     $artist = Artist::query()->where('name = :name', ['name' => $name]);
     if ($artist->count() > 0) {
         $artist = $artist->first();
     } else {
         $info = true;
         //Check if the LastFM integration is enabled
         if ($this->lastfm->isEnabled()) {
             $data = $this->lastfm->getArtistInfo($name);
             if ($data === false) {
                 $info = false;
             } else {
                 $summary = $data['bio']['summary'];
                 $image = $this->downloadImage($data['image']);
                 if ($image === false) {
                     $image = '';
                 }
             }
         } else {
             $info = false;
         }
         if ($info === false) {
             $summary = '';
             $image = '';
         }
         $artist = Artist::create();
         $artist->save(['name' => $name, 'summary' => $summary, 'image' => $image]);
     }
     //Dirty hack to create an insert query
     App::db()->createQueryBuilder()->select('1; INSERT INTO @shoutzor_media_artist (media_id, artist_id) VALUES (' . $media->id . ', ' . $artist->id . ') ON DUPLICATE KEY UPDATE media_id=media_id;--')->execute();
     return $artist;
 }
Exemple #4
0
 /**
  * Handles the file uploads
  * @method request
  * @param id the ID from the media file thats requested
  */
 public function request($params)
 {
     if ($this->shoutzorRunning === false) {
         return $this->formatOutput(__('Shoutzor is currently not running or restarting, try again in a few seconds'), self::METHOD_NOT_AVAILABLE);
     }
     //Make sure file uploads are enabled
     if (!App::user()->hasAccess("shoutzor: add requests")) {
         return $this->formatOutput(__('You have no permission to request'), self::METHOD_NOT_AVAILABLE);
     }
     //Make sure file uploads are enabled
     if (App::module('shoutzor')->config('shoutzor.request') == 0) {
         return $this->formatOutput(__('File requests have been disabled'), self::METHOD_NOT_AVAILABLE);
     }
     //Validate the parameter value
     if (!is_numeric($params['id'])) {
         return $this->formatOutput(__('Not a valid numerical value provided for the media object ID'), self::INVALID_PARAMETER_VALUE);
     }
     //Check if the requested Music ID exists
     $media = Media::find($params['id']);
     if ($media == null || !$media) {
         return $this->formatOutput(__('No media object with the provided ID exists'), self::ITEM_NOT_FOUND);
     }
     //Check if the media file is in queue already
     $inQueue = Request::where('media_id = :id', ['id' => $media->id])->count() == 0 ? true : false;
     if ($inQueue === false) {
         return $this->formatOutput(__('This media file is already in the queue!'), self::ERROR_IN_REQUEST);
     }
     //Get the config options
     $config = App::module('shoutzor')->config('shoutzor');
     $canRequestDateTime = (new DateTime())->sub(new DateInterval('PT' . $config['mediaRequestDelay'] . 'M'))->format('Y-m-d H:i:s');
     //Check if the media file has been played too recently
     if (Media::isRecentlyPlayed($media->id, $canRequestDateTime)) {
         return $this->formatOutput(__('This media file has been requested too recently'), self::ERROR_IN_REQUEST);
     }
     $canRequestDateTime = (new DateTime())->sub(new DateInterval('PT' . $config['artistRequestDelay'] . 'M'))->format('Y-m-d H:i:s');
     //Fetch a list of all artist id's
     if (Artist::isRecentlyPlayed($media->id, $canRequestDateTime)) {
         return $this->formatOutput(__('This artist has been played too recently'), self::ERROR_IN_REQUEST);
     }
     $canRequestDateTime = (new DateTime())->sub(new DateInterval('PT' . $config['userRequestDelay'] . 'M'))->format('Y-m-d H:i:s');
     //Check if the user hasnt already recently requested a media file
     $canRequest = Request::where('requester_id = :user AND requesttime > :requesttime', ['user' => App::user()->id, 'requesttime' => $canRequestDateTime])->count() == 0 ? true : false;
     if ($canRequest === false) {
         return $this->formatOutput(__('You already recently requested a media file, try again in 10 minutes'), self::ERROR_IN_REQUEST);
     }
     try {
         $queueManager = new QueueManager();
         $queueManager->addToQueue($media);
     } catch (Exception $e) {
         return $this->formatOutput($e->getMessage(), self::ERROR_IN_REQUEST);
     }
     return $this->formatOutput(true);
 }