/** * 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'); } }
/** * secondDelimiterArtists function. * * @access public * @param mixed $w * @param mixed $query * @param mixed $settings * @param mixed $db * @param mixed $update_in_progress * @return void */ function secondDelimiterArtists($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; $is_public_playlists = $settings->is_public_playlists; $use_mopidy = $settings->use_mopidy; // // display tracks for selected artists // $tmp = explode('∙', $words[1]); $artist_uri = $tmp[0]; $artist_name = $tmp[1]; $track = $words[2]; $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 ' . $tmp[0], './images/warning.png', 'no', null, ''); echo $w->toxml(); return; } } if ($href[1] == 'local') { $artist_uri = getArtistUriFromSearch($w, $href[2], $country_code); if ($artist_uri == false) { $w->result(null, 'help', "The artist cannot be retrieved from local track uri", 'URI was ' . $tmp[0], './images/warning.png', 'no', null, ''); echo $w->toxml(); return; } } if (mb_strlen($track) < 3) { $artist_artwork_path = getArtistArtwork($w, $artist_name, false); $w->result(null, serialize(array('', '', $artist_uri, '', '', '', '', 'playartist', $artist_name, '', '', '', $artist_artwork_path, '', '', '')), "👤 " . $artist_name, 'Play artist', $artist_artwork_path, 'yes', null, ''); $w->result(null, serialize(array('', '', $artist_uri, '', '', '', '', 'lookup_artist', $artist_name, '', '', '', '', '', '', '')), "👤 " . $artist_name, '☁︎ Query all albums/tracks from this artist online..', './images/online_artist.png', '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) { $privacy_status = 'private'; if ($is_public_playlists) { $privacy_status = 'public'; } $w->result(null, serialize(array('', '', $artist_uri, '', '', '', '', 'radio_artist', $artist_name, '', '', '', '', '', '', '')), 'Create a Radio Playlist for ' . $artist_name, 'This will create a ' . $privacy_status . ' radio playlist with ' . $radio_number_tracks . ' tracks for the artist', './images/radio_artist.png', 'yes', null, ''); } if ($update_in_progress == false) { $privacy_status = 'private'; if ($is_public_playlists) { $privacy_status = 'public'; } $w->result(null, serialize(array('', '', $artist_uri, '', '', '', '', 'complete_collection_artist', $artist_name, '', '', '', '', '', '', '')), 'Create a Complete Collection Playlist for ' . $artist_name, 'This will create a ' . $privacy_status . ' playlist for the artist with all the albums and singles', './images/complete_collection.png', 'yes', null, ''); } if ($all_playlists == false || count($tmp) == 3) { $getTracks = "select yourmusic, popularity, uri, album_uri, artist_uri, track_name, album_name, artist_name, album_type, track_artwork_path, artist_artwork_path, album_artwork_path, playlist_name, playlist_uri, playable, added_at, duration, nb_times_played, local_track from tracks where yourmusic=1 and artist_uri=:artist_uri limit " . $max_results; } else { $getTracks = "select yourmusic, popularity, uri, album_uri, artist_uri, track_name, album_name, artist_name, album_type, track_artwork_path, artist_artwork_path, album_artwork_path, playlist_name, playlist_uri, playable, added_at, duration, nb_times_played, local_track from tracks where artist_uri=:artist_uri limit " . $max_results; } $stmt = $db->prepare($getTracks); $stmt->bindValue(':artist_uri', $artist_uri); } else { if ($all_playlists == false || count($tmp) == 3) { $getTracks = "select yourmusic, popularity, uri, album_uri, artist_uri, track_name, album_name, artist_name, album_type, track_artwork_path, artist_artwork_path, album_artwork_path, playlist_name, playlist_uri, playable, added_at, duration, nb_times_played, local_track from tracks where yourmusic=1 and (artist_uri=:artist_uri and track_name like :track)" . " limit " . $max_results; } else { $getTracks = "select yourmusic, popularity, uri, album_uri, artist_uri, track_name, album_name, artist_name, album_type, track_artwork_path, artist_artwork_path, album_artwork_path, playlist_name, playlist_uri, playable, added_at, duration, nb_times_played, local_track from tracks where artist_uri=:artist_uri and track_name like :track limit " . $max_results; } $stmt = $db->prepare($getTracks); $stmt->bindValue(':artist_uri', $artist_uri); $stmt->bindValue(':track', '%' . $track . '%'); } $tracks = $stmt->execute(); $noresult = true; while ($track = $stmt->fetch()) { // if ($noresult) { // $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; $subtitle = $track[6]; $added = ''; if ($track[18] == true) { if ($use_mopidy) { // skip local tracks if using Mopidy continue; } $added = '📌 '; } if (checkIfResultAlreadyThere($w->results(), $added . ucfirst($track[7]) . " ● " . $track[5]) == false) { if ($track[14] == true) { $w->result(null, serialize(array($track[2], $track[3], $track[4], '', '', '', '', '', $track[7], $track[5], $track[6], $track[9], $track[10], $track[11], '', '')), $added . ucfirst($track[7]) . " ● " . $track[5], array($track[16] . " ● " . $subtitle . getPlaylistsForTrack($db, $track[2]), 'alt' => 'Play album ' . $track[6] . ' in Spotify', 'cmd' => 'Play artist ' . $track[7] . ' in Spotify', 'fn' => 'Add track ' . $track[5] . ' to ...', 'shift' => 'Add album ' . $track[6] . ' to ...', 'ctrl' => 'Search artist ' . $track[7] . ' online'), $track[9], 'yes', null, ''); } else { $w->result(null, '', '🚫 ' . ucfirst($track[7]) . " ● " . $track[5], $track[16] . " ● " . $subtitle . getPlaylistsForTrack($db, $track[2]), $track[9], 'no', null, ''); } } } if ($noresult) { if (mb_strlen($track) < 3) { $w->result(null, 'help', "There is no track in your library for the artist " . escapeQuery($artist_name), "Choose one of the options above", './images/info.png', 'no', null, ''); } else { $w->result(null, 'help', "There is no result for your search", "", './images/warning.png', 'no', null, ''); } } if (!$use_mopidy) { $w->result(null, serialize(array('', '', '', '', 'activate (open location "spotify:search:' . $artist_name . '")', '', '', '', '', '', '', '', '', '', '', '')), "Search for " . $artist_name . " in Spotify", array('This will start a new search in Spotify', 'alt' => 'Not Available', 'cmd' => 'Not Available', 'shift' => 'Not Available', 'fn' => 'Not Available', 'ctrl' => 'Not Available'), './images/spotify.png', 'yes', 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'); } }