Example #1
0
/**
 * getTheFullTrack function.
 *
 * @access public
 * @param mixed $w
 * @param mixed $track_uri
 * @param mixed $country_code
 * @return void
 */
function getTheFullTrack($w, $track_uri, $country_code)
{
    try {
        $tmp = explode(':', $track_uri);
        if ($tmp[1] == 'local') {
            // local track, look it up online
            // spotify:local:The+D%c3%b8:On+My+Shoulders+-+Single:On+My+Shoulders:318
            // spotify:local:Damien+Rice:B-Sides:Woman+Like+a+Man+%28Live%2c+Unplugged%29:284
            $query = 'track:' . urldecode(strtolower($tmp[4])) . ' artist:' . urldecode(strtolower($tmp[2]));
            $results = searchWebApi($w, $country_code, $query, 'track', 1);
            if (count($results) > 0) {
                // only one track returned
                $track = $results[0];
                return $track;
            } else {
                logMsg("Could not find track from uri: {$track_uri}");
                return false;
            }
        }
        $api = getSpotifyWebAPI($w);
        $track = $api->getTrack($tmp[2]);
        return $track;
    } catch (SpotifyWebAPI\SpotifyWebAPIException $e) {
        echo "Error(getTheFullTrack): (exception " . print_r($e) . ")";
        handleSpotifyWebAPIException($w, $e);
    }
    return false;
}
Example #2
0
/**
 * firstDelimiterSearchOnline function.
 *
 * @access public
 * @param mixed $w
 * @param mixed $query
 * @param mixed $settings
 * @param mixed $db
 * @param mixed $update_in_progress
 * @return void
 */
function firstDelimiterSearchOnline($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;
    //
    // Search online
    //
    $the_query = $words[1];
    if (mb_strlen($the_query) < 3) {
        if ($kind == "Search Online") {
            $w->result(null, 'help', "Search for playlists, artists, albums or tracks online, i.e not in your library", "Begin typing at least 3 characters to start search online. This is using slow Spotify API, be patient.", './images/info.png', 'no', null, '');
            $w->result(null, null, "Search for playlists only", array('This will search for playlists online, i.e not in your library', 'alt' => 'Not Available', 'cmd' => 'Not Available', 'shift' => 'Not Available', 'fn' => 'Not Available', 'ctrl' => 'Not Available'), './images/playlists.png', 'no', null, 'Search Playlists Online▹');
            $w->result(null, null, "Search for tracks only", array('This will search for tracks online, i.e not in your library', 'alt' => 'Not Available', 'cmd' => 'Not Available', 'shift' => 'Not Available', 'fn' => 'Not Available', 'ctrl' => 'Not Available'), './images/tracks.png', 'no', null, 'Search Tracks Online▹');
            $w->result(null, null, "Search for artists only", array('This will search for artists online, i.e not in your library', 'alt' => 'Not Available', 'cmd' => 'Not Available', 'shift' => 'Not Available', 'fn' => 'Not Available', 'ctrl' => 'Not Available'), './images/artists.png', 'no', null, 'Search Artists Online▹');
            $w->result(null, null, "Search for albums only", array('This will search for albums online, i.e not in your library', 'alt' => 'Not Available', 'cmd' => 'Not Available', 'shift' => 'Not Available', 'fn' => 'Not Available', 'ctrl' => 'Not Available'), './images/albums.png', 'no', null, 'Search Albums Online▹');
        } elseif ($kind == "Search Playlists Online") {
            $w->result(null, 'help', "Search playlists online, i.e not in your library", "Begin typing at least 3 characters to start search online. This is using slow Spotify API, be patient.", './images/info.png', 'no', null, '');
        } elseif ($kind == "Search Artists Online") {
            $w->result(null, 'help', "Search artists online, i.e not in your library", "Begin typing at least 3 characters to start search online. This is using slow Spotify API, be patient.", './images/info.png', 'no', null, '');
        } elseif ($kind == "Search Tracks Online") {
            $w->result(null, 'help', "Search tracks online, i.e not in your library", "Begin typing at least 3 characters to start search online. This is using slow Spotify API, be patient.", './images/info.png', 'no', null, '');
        } elseif ($kind == "Search Albums Online") {
            $w->result(null, 'help', "Search albums online, i.e not in your library", "Begin typing at least 3 characters to start search online. This is using slow Spotify API, be patient.", './images/info.png', 'no', null, '');
        }
    } else {
        $search_playlists = false;
        $search_artists = false;
        $search_albums = false;
        $search_tracks = false;
        if ($kind == "Search Online") {
            $search_playlists = true;
            $search_artists = true;
            $search_albums = true;
            $search_tracks = true;
            $search_playlists_limit = 8;
            $search_artists_limit = 5;
            $search_albums_limit = 5;
            $search_tracks_limit = 20;
        } elseif ($kind == "Search Playlists Online") {
            $search_playlists = true;
            $search_playlists_limit = $max_results <= 50 ? $max_results : 50;
        } elseif ($kind == "Search Artists Online") {
            $search_artists = true;
            $search_artists_limit = $max_results <= 50 ? $max_results : 50;
        } elseif ($kind == "Search Albums Online") {
            $search_albums = true;
            $search_albums_limit = $max_results <= 50 ? $max_results : 50;
        } elseif ($kind == "Search Tracks Online") {
            $search_tracks = true;
            $search_tracks_limit = $max_results <= 50 ? $max_results : 50;
        }
        $noresult = true;
        if ($search_artists == true) {
            // Search Artists
            //
            // call to web api, if it fails,
            // it displays an error in main window
            $query = 'artist:' . strtolower($the_query);
            $results = searchWebApi($w, $country_code, $query, 'artist', $search_artists_limit, false);
            foreach ($results as $artist) {
                if (checkIfResultAlreadyThere($w->results(), "👤 " . escapeQuery(ucfirst($artist->name))) == false) {
                    $noresult = false;
                    $w->result(null, '', "👤 " . escapeQuery(ucfirst($artist->name)), "Browse this artist", getArtistArtwork($w, $artist->name, false), 'no', null, "Online▹" . $artist->uri . '@' . escapeQuery($artist->name) . '▹');
                }
            }
        }
        if ($search_albums == true) {
            // Search Albums
            //
            // call to web api, if it fails,
            // it displays an error in main window
            $query = 'album:' . strtolower($the_query);
            $results = searchWebApi($w, $country_code, $query, 'album', $search_albums_limit, false);
            try {
                $api = getSpotifyWebAPI($w);
            } catch (SpotifyWebAPI\SpotifyWebAPIException $e) {
                $w->result(null, 'help', "Exception occurred", "" . $e->getMessage(), './images/warning.png', 'no', null, '');
                echo $w->toxml();
                return;
            }
            foreach ($results as $album) {
                if (checkIfResultAlreadyThere($w->results(), escapeQuery(ucfirst($album->name))) == false) {
                    $noresult = false;
                    try {
                        $full_album = $api->getAlbum($album->id);
                    } catch (SpotifyWebAPI\SpotifyWebAPIException $e) {
                        $w->result(null, 'help', "Exception occurred", "" . $e->getMessage(), './images/warning.png', 'no', null, '');
                        echo $w->toxml();
                        return;
                    }
                    $w->result(null, '', escapeQuery(ucfirst($album->name)) . ' (' . $full_album->tracks->total . ' tracks)', $album->album_type . ' by ' . escapeQuery($full_album->artists[0]->name), getTrackOrAlbumArtwork($w, $album->uri, false), 'no', null, 'Online▹' . $full_album->artists[0]->uri . '@' . escapeQuery($full_album->artists[0]->name) . '@' . $album->uri . '@' . escapeQuery($album->name) . '▹');
                }
            }
        }
        if ($search_playlists == true) {
            // Search Playlists
            //
            // call to web api, if it fails,
            // it displays an error in main window
            $query = 'playlist:' . strtolower($the_query);
            $results = searchWebApi($w, $country_code, $query, 'playlist', $search_playlists_limit, false);
            foreach ($results as $playlist) {
                $noresult = false;
                $w->result(null, '', "🎵" . escapeQuery($playlist->name), "by " . $playlist->owner->id . " ● " . $playlist->tracks->total . " tracks", getPlaylistArtwork($w, $playlist->uri, false), 'no', null, "Online Playlist▹" . $playlist->uri . '∙' . escapeQuery($playlist->name) . '▹');
            }
        }
        if ($search_tracks == true) {
            // Search Tracks
            //
            // call to web api, if it fails,
            // it displays an error in main window
            $query = 'track:' . strtolower($the_query);
            $results = searchWebApi($w, $country_code, $query, 'track', $search_tracks_limit, false);
            $first = true;
            foreach ($results as $track) {
                // if ($first == 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, '');
                // }
                // $first         = false;
                $noresult = false;
                $track_artwork = getTrackOrAlbumArtwork($w, $track->uri, false);
                $artists = $track->artists;
                $artist = $artists[0];
                $album = $track->album;
                $w->result(null, serialize(array($track->uri, $album->uri, $artist->uri, '', '', '', '', 'play_track_in_album_context', escapeQuery($artist->name), escapeQuery($track->name), escapeQuery($album->name), $track_artwork, '', '', '', '')), escapeQuery(ucfirst($artist->name)) . " ● " . escapeQuery($track->name), array(beautifyTime($track->duration_ms / 1000) . " ● " . escapeQuery($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, '');
            }
        }
        if ($noresult) {
            $w->result(null, 'help', "There is no result for this search", "", './images/warning.png', 'no', null, '');
        }
    }
}
Example #3
0
         }
     }
 } else {
     if ($setting[0] == "ADD_TO_YOUR_MUSIC") {
         if (file_exists($w->data() . '/update_library_in_progress')) {
             displayNotificationWithArtwork("Cannot modify library while update is in progress", './images/warning.png', 'Error!');
             return;
         }
         // add track to your music
         if ($track_uri != '') {
             $track_artwork_path = getTrackOrAlbumArtwork($w, $track_uri, true);
             $tmp = explode(':', $track_uri);
             if ($tmp[1] == 'local') {
                 // local track, look it up online
                 $query = 'track:' . strtolower($track_name) . ' artist:' . strtolower($artist_name);
                 $results = searchWebApi($w, $country_code, $query, 'track', 1);
                 if (count($results) > 0) {
                     // only one track returned
                     $track = $results[0];
                     $artists = $track->artists;
                     $artist = $artists[0];
                     logMsg("Unknown track {$track_uri} / {$track_name} / {$artist_name} replaced by track: {$track->uri} / {$track->name} / {$artist->name}");
                     $track_uri = $track->uri;
                     $tmp = explode(':', $track_uri);
                 } else {
                     logMsg("Could not find track: {$track_uri} / {$track_name} / {$artist_name}");
                     displayNotificationWithArtwork('Local track ' . $track_name . ' has not online match', './images/warning.png', 'Error!');
                     return;
                 }
             }
             $ret = addTracksToYourMusic($w, $tmp[2], false);