Example #1
0
/**
 * displayNotificationForCurrentTrack function.
 *
 * @access public
 * @param mixed $w
 * @return void
 */
function displayNotificationForCurrentTrack($w)
{
    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]);
        displayNotificationWithArtwork('🔈 ' . escapeQuery($results[0]) . ' by ' . escapeQuery($results[1]) . ' in album ' . escapeQuery($results[2]), getTrackOrAlbumArtwork($w, $results[4], true), 'Now Playing ' . floatToStars($results[6] / 100) . ' (' . beautifyTime($results[5]) . ')');
    } else {
        displayNotificationWithArtwork("Cannot get current track", './images/warning.png', 'Error!');
    }
}
Example #2
0
/**
 * firstDelimiterCurrentTrack function.
 *
 * @access public
 * @param mixed $w
 * @param mixed $query
 * @param mixed $settings
 * @param mixed $db
 * @param mixed $update_in_progress
 * @return void
 */
function firstDelimiterCurrentTrack($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;
    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) {
            $w->result(null, 'help', "AppleScript execution failed!", "Message: " . htmlspecialchars($retArr[0]), './images/warning.png', 'no', null, '');
            $w->result(null, serialize(array('', '', '', '', '', '', 'Open▹' . 'http://alfred-spotify-mini-player.com/blog/issue-with-latest-spotify-update/', '', '', '', '', '', '', '', '', '')), 'Maybe you have an issue with a Broken Spotify version?', "Go to the article to get more information", './images/website.png', 'yes', null, '');
            return;
        }
    }
    if (isset($retArr[0]) && substr_count($retArr[0], '▹') > 0) {
        $results = explode('▹', $retArr[0]);
        if ($results[1] == '' || $results[2] == '') {
            $w->result(null, 'help', "Current track is not valid: Artist or Album name is missing", "Fill missing information in Spotify and retry again", './images/warning.png', 'no', null, '');
            echo $w->toxml();
            return;
        }
        $href = explode(':', $results[4]);
        $added = '';
        if ($href[1] == 'local') {
            $added = '📌 ';
        }
        $currentArtistArtwork = getArtistArtwork($w, $results[1], false);
        $subtitle = "⌥ (play album) ⌘ (play artist) ctrl (lookup online)";
        $subtitle = "{$subtitle} fn (add track to ...) ⇧ (add album to ...)";
        if ($results[3] == "playing") {
            $w->result(null, serialize(array($results[4], '', '', '', '', '', '', 'pause', escapeQuery($results[1]), escapeQuery($results[0]), escapeQuery($results[2]), '', '', '', '', '')), $added . escapeQuery($results[0]) . " ● " . escapeQuery($results[1]) . " ● " . escapeQuery($results[2]) . " ● " . floatToStars($results[6] / 100) . ' (' . beautifyTime($results[5]) . ')', array($subtitle, 'alt' => 'Play album ' . escapeQuery($results[2]) . ' in Spotify', 'cmd' => 'Play artist ' . escapeQuery($results[1]) . ' in Spotify', 'fn' => 'Add track ' . escapeQuery($results[0]) . ' to ...', 'shift' => 'Add album ' . escapeQuery($results[2]) . ' to ...', 'ctrl' => 'Search artist ' . escapeQuery($results[1]) . ' online'), $results[3] == "playing" ? './images/pause.png' : './images/play.png', 'yes', null, '');
        } else {
            $w->result(null, serialize(array($results[4], '', '', '', '', '', '', 'play', escapeQuery($results[1]), escapeQuery($results[0]), escapeQuery($results[2]), '', '', '', '', '')), $added . escapeQuery($results[0]) . " ● " . escapeQuery($results[1]) . " ● " . escapeQuery($results[2]) . " ● " . floatToStars($results[6] / 100) . ' (' . beautifyTime($results[5]) . ')', array($subtitle, 'alt' => 'Play album ' . escapeQuery($results[2]) . ' in Spotify', 'cmd' => 'Play artist ' . escapeQuery($results[1]) . ' in Spotify', 'fn' => 'Add track ' . escapeQuery($results[0]) . ' to ...', 'shift' => 'Add album ' . escapeQuery($results[2]) . ' to ...', 'ctrl' => 'Search artist ' . escapeQuery($results[1]) . ' online'), $results[3] == "playing" ? './images/pause.png' : './images/play.png', 'yes', null, '');
        }
        $getTracks = "select artist_name,artist_uri from tracks where artist_name=:artist_name limit " . 1;
        try {
            $stmt = $db->prepare($getTracks);
            $stmt->bindValue(':artist_name', escapeQuery($results[1]));
            $tracks = $stmt->execute();
        } catch (PDOException $e) {
            handleDbIssuePdoXml($db);
            return;
        }
        // check if artist is in library
        $noresult = true;
        while ($track = $stmt->fetch()) {
            if ($track[1] != '') {
                $artist_uri = $track[1];
                $noresult = false;
            }
        }
        if ($noresult == false) {
            $w->result(null, '', "👤 " . ucfirst(escapeQuery($results[1])), "Browse this artist", $currentArtistArtwork, 'no', null, "Artist▹" . $artist_uri . '∙' . escapeQuery($results[1]) . "▹");
        } else {
            // artist is not in library
            $w->result(null, '', "👤 " . ucfirst(escapeQuery($results[1])), "Browse this artist", $currentArtistArtwork, 'no', null, "Artist▹" . $results[4] . '∙' . escapeQuery($results[1]) . "▹");
        }
        // use track uri here
        $album_artwork_path = getTrackOrAlbumArtwork($w, $results[4], false);
        $w->result(null, serialize(array($results[4], '', '', '', '', '', '', 'playalbum', '', '', escapeQuery($results[2]), '', '', $album_artwork_path, '', '')), "💿 " . escapeQuery($results[2]), 'Play album', $album_artwork_path, 'yes', null, '');
        // use track uri here
        $w->result(null, '', "💿 " . ucfirst(escapeQuery($results[2])), '☁︎ Query all tracks from this album online..', './images/online_album.png', 'no', null, "Online▹" . $results[4] . '@' . escapeQuery($results[1]) . '@' . $results[4] . '@' . escapeQuery($results[2]) . '▹');
        $w->result(null, '', "Get Lyrics for track " . escapeQuery($results[0]), "This will fetch lyrics online", './images/lyrics.png', 'no', null, "Lyrics▹" . $results[4] . "∙" . escapeQuery($results[1]) . '∙' . escapeQuery($results[0]));
        if ($update_in_progress == false) {
            $w->result(null, '', 'Add track ' . escapeQuery($results[0]) . ' to...', 'This will add current track to Your Music or a playlist you will choose in next step', './images/add.png', 'no', null, 'Add▹' . $results[4] . '∙' . escapeQuery($results[0]) . '▹');
            $w->result(null, '', 'Remove track ' . escapeQuery($results[0]) . ' from...', 'This will remove current track from Your Music or a playlist you will choose in next step', './images/remove.png', 'no', null, 'Remove▹' . $results[4] . '∙' . escapeQuery($results[0]) . '▹');
            $privacy_status = 'private';
            if ($is_public_playlists) {
                $privacy_status = 'public';
            }
            $w->result(null, serialize(array('', '', '', '', '', '', '', 'current_track_radio', '', '', '', '', '', '', '', '')), "Create a Song Radio Playlist based on " . escapeQuery($results[0]), array('This will create a ' . $privacy_status . ' song radio playlist with ' . $radio_number_tracks . ' tracks for the current track', 'alt' => 'Not Available', 'cmd' => 'Not Available', 'shift' => 'Not Available', 'fn' => 'Not Available', 'ctrl' => 'Not Available'), './images/radio_song.png', 'yes', null, '');
        }
        if ($all_playlists == true) {
            $getTracks = "select playlist_uri from tracks where uri=:uri limit " . $max_results;
            try {
                $stmtgetTracks = $db->prepare($getTracks);
                $stmtgetTracks->bindValue(':uri', $results[4]);
                $stmtgetTracks->execute();
            } catch (PDOException $e) {
                handleDbIssuePdoXml($db);
                return;
            }
            while ($track = $stmtgetTracks->fetch()) {
                if ($track[0] == '') {
                    // The track is in Your Music
                    $w->result(null, '', 'In "Your Music"', "The track is in Your Music", './images/yourmusic.png', 'no', null, "Your Music▹Tracks▹" . escapeQuery($results[0]));
                } else {
                    $getPlaylists = "select uri,name,nb_tracks,author,username,playlist_artwork_path,ownedbyuser,nb_playable_tracks,duration_playlist,collaborative,public from playlists where uri=:uri";
                    try {
                        $stmtGetPlaylists = $db->prepare($getPlaylists);
                        $stmtGetPlaylists->bindValue(':uri', $track[0]);
                        $playlists = $stmtGetPlaylists->execute();
                    } catch (PDOException $e) {
                        handleDbIssuePdoXml($db);
                        return;
                    }
                    while ($playlist = $stmtGetPlaylists->fetch()) {
                        $added = ' ';
                        if (startswith($playlist[1], 'Artist radio for')) {
                            $added = '📻 ';
                        }
                        if (checkIfResultAlreadyThere($w->results(), "🎵" . $added . "In playlist " . ucfirst($playlist[1])) == false) {
                            if ($playlist[9]) {
                                $public_status = 'collaborative';
                            } else {
                                if ($playlist[10]) {
                                    $public_status = 'public';
                                } else {
                                    $public_status = 'private';
                                }
                            }
                            $w->result(null, '', "🎵" . $added . "In playlist " . ucfirst($playlist[1]), $public_status . " playlist by " . $playlist[3] . " ● " . $playlist[7] . " tracks ● " . $playlist[8], $playlist[5], 'no', null, "Playlist▹" . $playlist[0] . "▹");
                        }
                    }
                }
            }
        }
    } else {
        $w->result(null, 'help', "There is no track currently playing", "Launch a track and come back here", './images/warning.png', 'no', null, '');
    }
}
Example #3
0
/**
 * displayNotificationForCurrentTrack function.
 *
 * @access public
 * @param mixed $w
 * @return void
 */
function displayNotificationForCurrentTrack($w)
{
    //
    // Read settings from JSON
    //
    $settings = getSettings($w);
    $use_mopidy = $settings->use_mopidy;
    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]);
        displayNotificationWithArtwork('🔈 ' . escapeQuery($results[0]) . ' by ' . escapeQuery($results[1]) . ' in album ' . escapeQuery($results[2]), getTrackOrAlbumArtwork($w, $results[4], true), 'Now Playing ' . floatToStars($results[6] / 100) . ' (' . beautifyTime($results[5] / 1000) . ')');
    }
}