Beispiel #1
0
 public static function getList()
 {
     // get the list
     $result = Music::send('listallinfo');
     // return the values
     return Music::buildSongList($result['values']);
 }
Beispiel #2
0
 /**
  * Get all the songs for an artist
  * 
  * @param string $artist 
  * 
  * @return array
  */
 public static function getSongs($artist)
 {
     // query the MPD database
     $result = Music::send('search', 'artist', $artist);
     // get the list of songs
     return Music::buildSongList($result['values']);
 }
Beispiel #3
0
 public static function getSongs($playlist)
 {
     // send the command to MPD
     $results = Music::send('listplaylistinfo', $playlist);
     // return the list of songs
     return Music::buildSongList($results['values']);
 }
Beispiel #4
0
    $song = $song == 'shuffle' ? 'shuffle' : Music::decode($song);
    // clear the playlist
    Music::send('clear');
    // get the list of songs
    $songs = Album::getSongs($artist, $album);
    // load the playlist with the requested songs (and figure out the current
    // song position)
    $pos = 0;
    for ($i = 0; $i < count($songs); $i++) {
        // add the current song to the current playlist
        Music::send('add', $songs[$i]['file']);
        // see if the current song is the one the user selected
        if ($songs[$i]['file'] == $song) {
            $pos = $i;
        }
    }
    // turn off "shuffle"
    Music::shuffle(false);
    // is the current song "shuffle"
    if ($song == 'shuffle') {
        // choose a random song
        $pos = rand(0, count($songs) - 1);
        // turn on shuffle
        Music::shuffle(true);
    }
    // start playing the selected song
    Music::send('play', $pos);
    // redirect to "now playing"
    header('Location: /');
    die;
});
Beispiel #5
0
 /**
  * Get the list of songs for a genre, artist, and album
  *
  * @param string $genre
  * @param string $artist
  * @param string $album
  * @return array
  */
 public static function getSongs($genre, $artist, $album)
 {
     // query the MPD database
     if ($album) {
         $result = Music::send('search', 'genre', $genre, 'artist', $artist, 'album', $album);
     } else {
         $result = Music::send('search', 'genre', $genre, 'artist', $artist);
     }
     // get the list of songs
     return Music::buildSongList($result['values']);
 }
Beispiel #6
0
 /**
  * Build a list of artists from a query
  * 
  * @param array $query 
  * The URI, parsed into an array of elements
  * 
  * @return array
  */
 public static function query($query = array())
 {
     //		artist					- list of artist
     //				list: artist
     //		artist/1/album			- list of albums for artist=1
     //				search: artist, ID - extract album names
     //		artist/1/album/2/song	- list of songs for artist=1, album=2
     //				search: artist, ID, album, ID - extract song names
     //		artist/1/album/2/song/3	- load all songs for artist=1, album=2, play song=3, go to nowplaying
     //				search: artist, ID, album, ID, song, ID - get song info & start playing
     // 		artist/1/song			- list of all songs for artist=1
     //				search: artist, ID - get song titles
     // chop the array up into pairs of entries
     $query = array_chunk($query, 2);
     // start building the command
     $command = null;
     $args = null;
     // step through the chunks
     while (count($query) > 0) {
         $a = array_shift($query);
         // is it a single element array with the value 'artist'?
         if (count($a) == 1 && $a[0] == 'artist') {
             // Yes! update the command and exit the loop
             $command = 'list';
             $args = array('artist');
             break;
         }
         // No. add to the command
         $command = 'search';
         $args[] = $a[0];
         if (isset($a[1])) {
             $args[] = Music::decode($a[1]);
         }
         // $args[] = $a[1];
     }
     // at this point, the last item in the $args array tells us what kind
     // of list we want
     $list = array_pop($args);
     // is the $list values actually "song"?
     if ($list == 'song') {
         // Yes! We actually want the "title" tag from the results
         $list = 'title';
     }
     // run the command
     $result = Music::send($command, $args);
     Kint::dump($result['values']);
     // build the appropriate type of list
     return static::buildListOfKeys($list, $result['values']);
 }