예제 #1
0
 public function getRandomTrack($autoForce = true, $forced = false)
 {
     if ($forced === true) {
         return Media::query()->orderBy('rand()')->first();
     } else {
         $list = array();
     }
     $config = App::module('shoutzor')->config('shoutzor');
     $requestHistoryTime = (new DateTime())->sub(new DateInterval('PT' . $config['mediaRequestDelay'] . 'M'))->format('Y-m-d H:i:s');
     $artistHistoryTime = (new DateTime())->sub(new DateInterval('PT' . $config['artistRequestDelay'] . 'M'))->format('Y-m-d H:i:s');
     //Build a list of media id's that are available to play, next, randomly pick one
     $q = Media::query()->select('DISTINCT m.*')->from('@shoutzor_media m')->leftJoin('@shoutzor_requestlist q', 'q.media_id = m.id')->where('q.media_id IS NULL')->where('m.id NOT IN (
                   SELECT h.media_id
                   FROM @shoutzor_history h
                   LEFT JOIN @shoutzor_requestlist tq ON tq.media_id = h.media_id
                   WHERE h.played_at > :maxTime
               )', ['maxTime' => $requestHistoryTime])->where('m.id NOT IN (
               SELECT tma.media_id
               FROM @shoutzor_media_artist tma
               WHERE tma.artist_id IN (
                   SELECT ma.artist_id
                   FROM @shoutzor_media_artist ma
                   WHERE ma.media_id IN (
                       SELECT th.media_id
                       FROM @shoutzor_history th
                       LEFT JOIN @shoutzor_requestlist tq ON tq.media_id = th.media_id
                       WHERE th.played_at > :maxTime
                     )
                   )
               )', ['maxTime' => $artistHistoryTime])->groupBy('m.id')->orderBy('rand(' . microtime(true) . ')');
     if ($q->count() === 0) {
         return $autoForce === true ? $this->getRandomTrack(true, true) : false;
     }
     return $q->first();
 }
예제 #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];
 }
예제 #3
0
 /**
  * Checks if the provided instance is unique
  * @return false|Music
  */
 public function exists(Media $media)
 {
     $obj = Media::where('crc = :crc AND status = :status', ['crc' => $media->crc, 'status' => Media::STATUS_FINISHED]);
     if ($obj->count() == 0) {
         return false;
     }
     return $obj->first();
 }
예제 #4
0
 /**
  * Gets the track that is currently playing
  * @method nowplaying
  */
 public function nowplaying($params)
 {
     $history = Media::getNowplaying();
     return $this->formatOutput($history);
 }
예제 #5
0
 public static function isRecentlyPlayed($id, $canRequestDateTime)
 {
     $q = Media::query()->select('m.id')->from('@shoutzor_media m')->where('(m.id IN (SELECT h.media_id FROM @shoutzor_history h WHERE h.media_id IN (SELECT tma.media_id FROM @shoutzor_media_artist tma WHERE tma.artist_id IN (SELECT ttma.artist_id FROM @shoutzor_media_artist ttma WHERE ttma.media_id = :id)) AND h.played_at > :maxTime)) OR (m.id IN (SELECT q.media_id FROM @shoutzor_requestlist q WHERE q.media_id IN (SELECT tma.media_id FROM @shoutzor_media_artist tma WHERE tma.artist_id IN (SELECT ttma.artist_id FROM @shoutzor_media_artist ttma WHERE ttma.media_id = :id))))', ['id' => $id, 'maxTime' => $canRequestDateTime]);
     return $q->count() == 0 ? false : true;
 }
예제 #6
0
파일: Album.php 프로젝트: xorinzor/Shoutzor
 public function getMedia()
 {
     $topTracks = Media::query()->select('m.*')->from('@shoutzor_media m')->leftJoin('@shoutzor_media_album ma', 'ma.album_id = ' . $this->id)->where('m.id = ma.media_id')->orderBy('m.title', 'ASC')->related(['artist', 'album'])->get();
     return $topTracks;
 }
예제 #7
0
파일: Media.php 프로젝트: xorinzor/Shoutzor
 public static function getNowplaying()
 {
     $history = Media::query()->select('m.*, h.played_at as played_at')->from('@shoutzor_media m')->leftJoin('@shoutzor_history h', 'h.media_id = m.id')->where('h.media_id = m.id')->orderBy('h.played_at', 'DESC')->limit(1)->related(['artist', 'album'])->first();
     return $history;
 }