コード例 #1
0
ファイル: menu.php プロジェクト: jfloff/.dotfiles
/**
 * secondDelimiterOnline function.
 *
 * @access public
 * @param mixed $w
 * @param mixed $query
 * @param mixed $settings
 * @param mixed $db
 * @param mixed $update_in_progress
 * @return void
 */
function secondDelimiterOnline($w, $query, $settings, $db, $update_in_progress)
{
    $words = explode('▹', $query);
    $kind = $words[0];
    $all_playlists = $settings->all_playlists;
    $is_alfred_playlist_active = $settings->is_alfred_playlist_active;
    $radio_number_tracks = $settings->radio_number_tracks;
    $now_playing_notifications = $settings->now_playing_notifications;
    $max_results = $settings->max_results;
    $alfred_playlist_uri = $settings->alfred_playlist_uri;
    $alfred_playlist_name = $settings->alfred_playlist_name;
    $country_code = $settings->country_code;
    $last_check_update_time = $settings->last_check_update_time;
    $oauth_client_id = $settings->oauth_client_id;
    $oauth_client_secret = $settings->oauth_client_secret;
    $oauth_redirect_uri = $settings->oauth_redirect_uri;
    $oauth_access_token = $settings->oauth_access_token;
    $oauth_expires = $settings->oauth_expires;
    $oauth_refresh_token = $settings->oauth_refresh_token;
    $display_name = $settings->display_name;
    $userid = $settings->userid;
    $echonest_api_key = $settings->echonest_api_key;
    if (substr_count($query, '@') == 1) {
        //
        // Search Artist Online
        //
        $tmp = $words[1];
        $words = explode('@', $tmp);
        $artist_uri = $words[0];
        $tmp_uri = explode(':', $artist_uri);
        $artist_name = $words[1];
        $artist_artwork_path = getArtistArtwork($w, $artist_name, false);
        $w->result(null, serialize(array('', '', $artist_uri, '', '', '', '', 'playartist', $artist_name, '', '', '', $artist_artwork_path, '', '', '')), "👤 " . escapeQuery($artist_name), 'Play artist', $artist_artwork_path, 'yes', null, '');
        $w->result(null, '', "Display biography", "This will display the artist biography, twitter and official website", './images/biography.png', 'no', null, "Biography▹" . $artist_uri . '∙' . escapeQuery($artist_name) . '▹');
        $w->result(null, '', 'Follow/Unfollow Artist', 'Display options to follow/unfollow the artist', './images/follow.png', 'no', null, "Follow/Unfollow▹" . $artist_uri . "@" . $artist_name . '▹');
        $w->result(null, '', 'Related Artists', 'Browse related artists', './images/related.png', 'no', null, "OnlineRelated▹" . $artist_uri . "@" . $artist_name . '▹');
        if ($update_in_progress == false) {
            $w->result(null, serialize(array('', '', $artist_uri, '', '', '', '', 'radio_artist', $artist_name, '', '', '', '', '', '', '')), 'Create a Radio Playlist for ' . $artist_name, 'This will create a radio playlist with ' . $radio_number_tracks . ' tracks for the artist', './images/radio_artist.png', 'yes', null, '');
        }
        // call to web api, if it fails,
        // it displays an error in main window
        $albums = getTheArtistAlbums($w, $artist_uri, $country_code);
        $w->result(null, 'help', "Select an album below to browse it", 'singles and compilations are also displayed', './images/info.png', 'no', null, '');
        $noresult = true;
        foreach ($albums as $album) {
            if (checkIfResultAlreadyThere($w->results(), ucfirst($album->name) . ' (' . count($album->tracks->items) . ' tracks)') == false) {
                $noresult = false;
                $genre = count($album->genres) > 0 ? ' ● Genre: ' . implode('|', $album->genres) : '';
                $tracks = $album->tracks;
                $w->result(null, '', ucfirst($album->name) . ' (' . count($album->tracks->items) . ' tracks)', $album->album_type . " by " . $artist_name . ' ● Release date: ' . $album->release_date . $genre, getTrackOrAlbumArtwork($w, $album->uri, false), 'no', null, "Online▹" . $artist_uri . "@" . $artist_name . "@" . $album->uri . "@" . $album->name . '▹');
            }
        }
        if ($noresult) {
            $w->result(null, 'help', "There is no album for this artist", "", './images/warning.png', 'no', null, '');
        }
    } elseif (substr_count($query, '@') == 3) {
        //
        // Search Album Online
        //
        $tmp = $words[1];
        $words = explode('@', $tmp);
        $artist_uri = $words[0];
        $artist_name = $words[1];
        $album_uri = $words[2];
        $album_name = $words[3];
        $href = explode(':', $album_uri);
        if ($href[1] == 'track' || $href[1] == 'local') {
            $track_uri = $album_uri;
            $album_uri = getAlbumUriFromTrack($w, $track_uri);
            if ($album_uri == false) {
                $w->result(null, 'help', "The album cannot be retrieved from track uri", 'URI was ' . $track_uri, './images/warning.png', 'no', null, '');
                echo $w->toxml();
                return;
            }
        }
        $href = explode(':', $artist_uri);
        if ($href[1] == 'track') {
            $track_uri = $artist_uri;
            $artist_uri = getArtistUriFromTrack($w, $track_uri);
            if ($artist_uri == false) {
                $w->result(null, 'help', "The artist cannot be retrieved from track uri", 'URI was ' . $track_uri, './images/warning.png', 'no', null, '');
                echo $w->toxml();
                return;
            }
        }
        $album_artwork_path = getTrackOrAlbumArtwork($w, $album_uri, false);
        $w->result(null, serialize(array('', $album_uri, '', '', '', '', '', 'playalbum', '', '', $album_name, '', '', $album_artwork_path, '', '')), "💿 " . escapeQuery($album_name), 'Play album', $album_artwork_path, 'yes', null, '');
        if ($update_in_progress == false) {
            $w->result(null, '', 'Add album ' . escapeQuery($album_name) . ' to...', 'This will add the album to Your Music or a playlist you will choose in next step', './images/add.png', 'no', null, 'Add▹' . $album_uri . '∙' . escapeQuery($album_name) . '▹');
        }
        // call to web api, if it fails,
        // it displays an error in main window
        $tracks = getTheAlbumFullTracks($w, $album_uri);
        $noresult = true;
        foreach ($tracks as $track) {
            // if ($noresult == true) {
            //     $subtitle = "⌥ (play album) ⌘ (play artist) ctrl (lookup online)";
            //     $subtitle = "$subtitle fn (add track to ...) ⇧ (add album to ...)";
            //     $w->result(null, 'help', "Select a track below to play it (or choose alternative described below)", $subtitle, './images/info.png', 'no', null, '');
            // }
            $track_artwork = getTrackOrAlbumArtwork($w, $track->uri, false);
            if (isset($track->is_playable) && $track->is_playable) {
                $noresult = false;
                $w->result(null, serialize(array($track->uri, $album_uri, $artist_uri, '', '', '', '', 'play_track_in_album_context', $artist_name, $track->name, $album_name, $track_artwork, '', '', '', '')), escapeQuery(ucfirst($artist_name)) . " ● " . escapeQuery($track->name), array(beautifyTime($track->duration_ms / 1000) . " ● " . $album_name, 'alt' => 'Play album ' . escapeQuery($album_name) . ' in Spotify', 'cmd' => 'Play artist ' . escapeQuery($artist_name) . ' in Spotify', 'fn' => 'Add track ' . escapeQuery($track->name) . ' to ...', 'shift' => 'Add album ' . escapeQuery($album_name) . ' to ...', 'ctrl' => 'Search artist ' . escapeQuery($artist_name) . ' online'), $track_artwork, 'yes', null, '');
            } else {
                $w->result(null, '', '🚫 ' . escapeQuery(ucfirst($artist_name)) . " ● " . escapeQuery($track->name), beautifyTime($track->duration_ms / 1000) . " ● " . $album_name, $track_artwork, 'no', null, '');
            }
        }
    }
}
コード例 #2
0
ファイル: functions.php プロジェクト: jfloff/.dotfiles
/**
 * createCompleteCollectionArtistPlaylist function.
 *
 * @access public
 * @param mixed $w
 * @param mixed $artist_name
 * @return void
 */
function createCompleteCollectionArtistPlaylist($w, $artist_name, $artist_uri)
{
    //
    // Read settings from JSON
    //
    $settings = getSettings($w);
    $userid = $settings->userid;
    $country_code = $settings->country_code;
    $is_public_playlists = $settings->is_public_playlists;
    $public = false;
    if ($is_public_playlists) {
        $public = true;
    }
    $newplaylisttracks = array();
    // call to web api, if it fails,
    // it displays an error in main window
    $albums = getTheArtistAlbums($w, $artist_uri, $country_code, true, false);
    foreach ($albums as $album) {
        // call to web api, if it fails,
        // it displays an error in main window
        $tracks = getTheAlbumFullTracks($w, $album->uri, true);
        foreach ($tracks as $track) {
            $tmp = explode(':', $track->uri);
            $newplaylisttracks[] = $tmp[2];
        }
    }
    if (count($newplaylisttracks) > 0) {
        try {
            $api = getSpotifyWebAPI($w);
            $json = $api->createUserPlaylist($userid, array('name' => 'Complete Collection for ' . escapeQuery($artist_name), 'public' => $public));
        } catch (SpotifyWebAPI\SpotifyWebAPIException $e) {
            logMsg("Error(createCompleteCollectionArtistPlaylist): Complete Collection " . $artist_name . " (exception " . print_r($e) . ")");
            handleSpotifyWebAPIException($w, $e);
            return false;
        }
        $ret = addTracksToPlaylist($w, $newplaylisttracks, $json->uri, $json->name, false, false);
        if (is_numeric($ret) && $ret > 0) {
            refreshLibrary($w);
            return;
        } elseif (is_numeric($ret) && $ret == 0) {
            displayNotificationWithArtwork('Playlist ' . $json->name . ' cannot be added', './images/warning.png', 'Error!');
            return;
        }
    } else {
        displayNotificationWithArtwork('No track was found for artist ' . $artist_name, './images/warning.png', 'Error!');
        return false;
    }
    return true;
}