/** * 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, ''); } } } }
/** * playCurrentArtist function. * * @access public * @param mixed $w * @return void */ function playCurrentArtist($w) { // // Read settings from JSON // $settings = getSettings($w); $use_mopidy = $settings->use_mopidy; $country_code = $settings->country_code; if ($use_mopidy) { $retArr = array(getCurrentTrackInfoWithMopidy($w)); } else { // get info on current song exec("./src/track_info.ksh 2>&1", $retArr, $retVal); if ($retVal != 0) { displayNotificationWithArtwork('AppleScript Exception: ' . htmlspecialchars($retArr[0]) . ' use spot_mini_debug command', './images/warning.png', 'Error!'); exec("osascript -e 'tell application \"Alfred 2\" to search \"spot_mini_debug AppleScript Exception: " . htmlspecialchars($retArr[0]) . "\"'"); return; } } if (isset($retArr[0]) && substr_count($retArr[0], '▹') > 0) { $results = explode('▹', $retArr[0]); $tmp = explode(':', $results[4]); if (isset($tmp[1]) && $tmp[1] == 'local') { $artist_uri = getArtistUriFromSearch($w, $results[1]); } else { $artist_uri = getArtistUriFromTrack($w, $results[4]); } if ($artist_uri == false) { displayNotificationWithArtwork("Cannot get current artist", './images/warning.png', 'Error!'); return; } if ($use_mopidy) { playUriWithMopidy($w, $artist_uri); } else { exec("osascript -e 'tell application \"Spotify\" to play track \"{$artist_uri}\"'"); addArtistToPlayQueue($w, $artist_uri, escapeQuery($results[1]), $country_code); } displayNotificationWithArtwork('🔈 Artist ' . escapeQuery($results[1]), getArtistArtwork($w, $artist_uri, $results[1], true), 'Play Current Artist'); } else { displayNotificationWithArtwork("No artist is playing", './images/warning.png'); } }
/** * playCurrentArtist function. * * @access public * @param mixed $w * @return void */ function playCurrentArtist($w) { // get info on current song exec("./src/track_info.ksh 2>&1", $retArr, $retVal); if ($retVal != 0) { displayNotificationWithArtwork('AppleScript Exception: ' . htmlspecialchars($retArr[0]) . ' use spot_mini_debug command', './images/warning.png', 'Error!'); exec("osascript -e 'tell application \"Alfred 2\" to search \"spot_mini_debug AppleScript Exception: " . htmlspecialchars($retArr[0]) . "\"'"); return; } if (isset($retArr[0]) && substr_count($retArr[0], '▹') > 0) { $results = explode('▹', $retArr[0]); $tmp = explode(':', $results[4]); if ($tmp[1] == 'local') { $artist_uri = getArtistUriFromSearch($w, $results[1]); } else { $artist_uri = getArtistUriFromTrack($w, $results[4]); } if ($artist_uri == false) { displayNotificationWithArtwork("Cannot get current artist", './images/warning.png', 'Error!'); return; } exec("osascript -e 'tell application \"Spotify\" to play track \"{$artist_uri}\"'"); displayNotificationWithArtwork('🔈 Artist ' . escapeQuery($results[1]), getArtistArtwork($w, $results[1], true), 'Play Current Artist'); } else { displayNotificationWithArtwork("No artist is playing", './images/warning.png'); } }
displayNotificationWithArtwork("No history yet", './images/warning.png', 'Error!'); } $query = array_pop($history); // pop twice $query = array_pop($history); $w->write($history, 'history.json'); exec("osascript -e 'tell application \"Alfred 2\" to search \"spot_mini {$query}\"'"); return; } else { if ($other_action == "lookup_artist") { if (!$w->internet()) { displayNotificationWithArtwork("No internet connection", './images/warning.png', 'Error!'); return; } if ($artist_uri == "") { $artist_uri = getArtistUriFromTrack($w, $track_uri); } exec("osascript -e 'tell application \"Alfred 2\" to search \"spot_mini Onlineâ–¹" . $artist_uri . "@" . escapeQuery($artist_name) . 'â–¹' . "\"'"); if ($userid != 'vdesabou') { stathat_ez_count('AlfredSpotifyMiniPlayer', 'lookup online', 1); } return; } else { if ($other_action == "playartist") { $artist_artwork_path = getArtistArtwork($w, $artist_uri, $artist_name, true); $mopidy_arg = ""; if ($use_mopidy) { $mopidy_arg = "MOPIDY"; } exec("./src/spotify_mini_player_notifications.ksh -d \"" . $w->data() . "\" -a start -m \"" . $mopidy_arg . "\" >> \"" . $w->cache() . "/action.log\" 2>&1 & "); if (!$use_mopidy) {