Beispiel #1
0
/**
 * secondDelimiterNewReleases function.
 *
 * @access public
 * @param mixed $w
 * @param mixed $query
 * @param mixed $settings
 * @param mixed $db
 * @param mixed $update_in_progress
 * @return void
 */
function secondDelimiterNewReleases($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;
    $country = $words[1];
    if ($country == 'Choose a Country') {
        // list taken from http://charts.spotify.com/docs
        $spotify_country_codes = array("ar", "at", "au", "be", "bg", "ch", "cl", "co", "cr", "cz", "de", "dk", "ec", "ee", "es", "fi", "fr", "gb", "gr", "gt", "hk", "hu", "ie", "is", "it", "li", "lt", "lu", "lv", "mx", "my", "nl", "no", "nz", "pe", "pl", "pt", "se", "sg", "sk", "sv", "tr", "tw", "us", "uy");
        foreach ($spotify_country_codes as $spotify_country_code) {
            if (strtoupper($spotify_country_code) != 'US' && strtoupper($spotify_country_code) != 'GB' && strtoupper($spotify_country_code) != strtoupper($country_code)) {
                $w->result(null, '', getCountryName(strtoupper($spotify_country_code)), 'Browse the new album releases in ' . getCountryName(strtoupper($spotify_country_code)), './images/new_releases.png', 'no', null, 'New Releases▹' . strtoupper($spotify_country_code) . '▹');
            }
        }
    } else {
        if (substr_count($query, '@') == 0) {
            //
            // Get New Releases Online
            //
            // call to web api, if it fails,
            // it displays an error in main window
            $albums = getTheNewReleases($w, $country, $max_results);
            $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 " . $album->artists[0]->name . ' ● Release date: ' . $album->release_date . $genre, getTrackOrAlbumArtwork($w, $album->uri, false), 'no', null, "New Releases▹" . $country . '▹' . $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, '@') == 1) {
            //
            // Search Album Online
            //
            $tmp = $words[2];
            $words = explode('@', $tmp);
            $album_uri = $words[0];
            $album_name = $words[1];
            $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, '');
                // }
                // $noresult           = false;
                $track_artwork_path = getTrackOrAlbumArtwork($w, $track->uri, false);
                $w->result(null, serialize(array($track->uri, $album_uri, $track->artists[0]->uri, '', '', '', '', 'play_track_in_album_context', $track->artists[0]->name, $track->name, $album_name, $track_artwork_path, '', '', '', '')), escapeQuery(ucfirst($track->artists[0]->name)) . " ● " . escapeQuery($track->name), array(beautifyTime($track->duration_ms / 1000) . " ● " . $album_name, 'alt' => 'Play album ' . escapeQuery($album_name) . ' in Spotify', 'cmd' => 'Play artist ' . escapeQuery($track->artists[0]->name) . ' in Spotify', 'fn' => 'Add track ' . escapeQuery($track->name) . ' to ...', 'shift' => 'Add album ' . escapeQuery($album_name) . ' to ...', 'ctrl' => 'Search artist ' . escapeQuery($track->artists[0]->name) . ' online'), $track_artwork_path, 'yes', null, '');
            }
        }
    }
}
Beispiel #2
0
     } else {
         $currentResultNumber = 1;
         foreach ($json as $item) {
             if ($currentResultNumber > $max_results) {
                 break;
             }
             if (strpos(strtolower($item['data']['album']['name']), strtolower($album)) !== false && strpos(strtolower($item['data']['name']), strtolower($track)) !== false) {
                 // Figure out search rank
                 $popularity = $item['data']['popularity'];
                 $popularity /= 100;
                 // Convert popularity to stars
                 $stars = floor($popularity * 5);
                 $starString = str_repeat("⭑", $stars) . str_repeat("⭒", 5 - $stars);
                 $subtitle = $item['data']['album']['name'] . " - <alt> play album, <cmd> play artist";
                 $subtitle = "{$starString} {$subtitle}";
                 if (checkIfResultAlreadyThere($w->results(), ucfirst($item['data']['album']['artist']['name']) . " - " . $item['data']['name']) == false) {
                     $w->result("spotify_mini-spotify-track-" . $item['data']['name'], $item['data']['uri'] . "|" . $item['data']['album']['uri'] . "|" . $item['data']['album']['artist']['uri'] . "|||||", ucfirst($item['data']['album']['artist']['name']) . " - " . $item['data']['name'], $subtitle, getTrackArtwork($item['data']['uri'], true), 'yes', '');
                 }
                 $currentResultNumber++;
             }
         }
         $w->result('', "||||activate (open location \"spotify:search:" . $track . "\")|||", "Search for " . $track . " with Spotify", "This will start a new search in Spotify", 'fileicon:/Applications/Spotify.app', 'yes', '');
         if ($is_spotifious_active == true) {
             $w->result('', "|||||" . "{$track}" . "||", "Search for " . $track . " with Spotifious", "Spotifious workflow must be installed", './images/spotifious.png', 'yes', '');
         }
     }
 } elseif ($kind == "Playlist") {
     //
     // display tracks for selected playlist
     //
     $playlist = $words[1];