Exemple #1
0
$klein->respond('GET', '/album/[:album]/song', function ($request, $response) {
    // get the artist & album values
    list($artist, $album) = explode('|', Music::decode($request->param('album')));
    // get the list of songs
    $list = Album::getSongs($artist, $album);
    // walk the array and construct URLs
    // The encoded URL value is actually "artist name|album title". The artist
    // name is included to ensure that albums with the same name are not
    // conflated and the pipe character is a delimiter
    array_walk($list, function (&$v, $k) use($artist, $album) {
        $v = array('name' => $v['Title'], 'url' => '/album/' . Music::encode($artist . '|' . $album) . '/song/' . Music::encode($v['file']));
    });
    // build the "previous" link data
    $previous = array('path' => '/album', 'text' => 'Albums');
    // build the shuffle link
    $shuffle = '/album/' . Music::encode($artist . '|' . $album) . '/song/shuffle';
    return ListPage::render($album, $previous, $shuffle, false, $list);
});
//		album/1/song/2	- load all songs for album=1, play song=2, go to nowplaying
//
$klein->respond('GET', '/album/[:album]/song/[:song]', function ($request, $response) {
    // get the parameters
    // get the artist & album values
    list($artist, $album) = explode('|', Music::decode($request->param('album')));
    $song = $request->param('song');
    $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
Exemple #2
0
    // get the parameter
    $genre = Music::decode($request->param('genre'));
    $artist = Music::decode($request->param('artist'));
    // get the list
    $list = Genre::getSongs($genre, $artist, null);
    // walk the array and construct URLs
    // The encoded URL value is actually "artist name|album title". The artist
    // name is included to ensure that albums with the same name are not
    // conflated and the pipe character is a delimiter
    array_walk($list, function (&$v, $k) use($genre) {
        $v = array('name' => $v['Title'], 'url' => '/genre/' . Music::encode($genre) . '/artist/' . Music::encode($v['Artist']) . '/song/' . Music::encode($v['file']));
    });
    // build the "previous" link data
    $previous = array('path' => '/genre/' . $request->param('genre') . '/artist', 'text' => 'Artists');
    // build the shuffle link
    $shuffle = '/genre/' . Music::encode($genre) . '/artist/' . Music::encode($artist) . '/song/shuffle';
    return ListPage::render($album, $previous, $shuffle, false, $list);
});
$klein->respond('GET', '/genre/[:genre]/artist/[:artist]/song/[:song]', function ($request, $response) {
    // get the parameter
    $genre = Music::decode($request->param('genre'));
    $artist = Music::decode($request->param('artist'));
    $song = $request->param('song');
    $song = $song == 'shuffle' ? 'shuffle' : Music::decode($song);
    // clear the playlist
    Music::send('clear');
    // get the list
    $songs = Genre::getSongs($genre, $artist, null);
    // load the playlist with the requested songs (and figure out the current
    // song position)
    $pos = 0;
Exemple #3
0
$klein->respond('GET', '/playlist/[:playlist]/song', function ($request, $response) {
    // get the params
    $playlist = Music::decode($request->param('playlist'));
    // get the list of songs
    $list = Playlist::getSongs($playlist);
    // walk the array and construct URLs
    // The encoded URL value is actually "artist name|album title". The artist
    // name is included to ensure that albums with the same name are not
    // conflated and the pipe character is a delimiter
    array_walk($list, function (&$v, $k) use($playlist) {
        $v = array('name' => $v['Title'], 'url' => '/playlist/' . Music::encode($playlist) . '/song/' . Music::encode($v['file']));
    });
    // build the "previous" link data
    $previous = array('path' => '/playlist', 'text' => 'Playlists');
    // build the shuffle link
    $shuffle = '/playlist/' . Music::encode($playlist) . '/song/shuffle';
    return ListPage::render($playlist, $previous, $shuffle, false, $list);
});
//		playlist/1/song/2 	- load all songs for playlist=1, start playing song=2, go to nowplaying
//
$klein->respond('GET', '/playlist/[:playlist]/song/[:song]', function ($request, $response) {
    // get the params
    $playlist = Music::decode($request->param('playlist'));
    $song = $request->param('song');
    $song = $song == 'shuffle' ? 'shuffle' : Music::decode($song);
    // clear the playlist
    Music::send('clear');
    // get the list of songs
    $songs = Playlist::getSongs($playlist);
    // load the playlist with the requested songs (and figure out the current
    // song position)
Exemple #4
0
// Routes for song requests
//		song 	- list of all songs
//				page head='Songs', list head=null
//
//		song/1 	- load ALL songs, play song=1, go to nowplaying
//		song 	- list of all songs
//
$klein->respond('GET', '/song', function ($request, $response) {
    // get the list of songs
    $list = Song::getList();
    // walk the array and construct URLs
    // The encoded URL value is actually "artist name|album title". The artist
    // name is included to ensure that albums with the same name are not
    // conflated and the pipe character is a delimiter
    array_walk($list, function (&$v, $k) {
        $v = array('name' => $v['Title'], 'url' => '/song/' . Music::encode($v['file']));
    });
    $list = array_filter($list, function ($v) {
        return $v['name'] ? true : false;
    });
    usort($list, function ($a, $b) {
        if (array_key_exists('name', $a) && array_key_exists('name', $b)) {
            return $a['name'] < $b['name'] ? -1 : 1;
        }
        return 0;
    });
    // build the shuffle link
    $shuffle = '/song/shuffle';
    return ListPage::render('Songs', null, $shuffle, false, $list);
});
//		song/1 	- load ALL songs, play song=1, go to nowplaying