Ejemplo n.º 1
0
/**
 * firstDelimiterPlayQueue function.
 *
 * @access public
 * @param mixed $w
 * @param mixed $query
 * @param mixed $settings
 * @param mixed $db
 * @param mixed $update_in_progress
 * @return void
 */
function firstDelimiterPlayQueue($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;
    $use_mopidy = $settings->use_mopidy;
    if ($use_mopidy) {
        $playqueue = $w->read('playqueue.json');
        if ($playqueue == false) {
            $w->result(null, 'help', "There is no track in the play queue", "Make sure to always use the workflow to launch tracks, playlists, etc..Internet connectivity is also required", './images/warning.png', 'no', null, '');
            $w->result(null, serialize(array('', '', '', '', '', '', 'Open▹' . 'http://alfred-spotify-mini-player.com/articles/play-queue/', '', '', '', '', '', '', '', '', '')), 'Learn more about Play Queue', "Find out all information about Play Queue on alfred-spotify-mini-player.com", './images/website.png', 'yes', null, '');
            echo $w->toxml();
            return;
        }
        $tl_tracks = invokeMopidyMethod($w, "core.tracklist.get_tl_tracks", array());
        $current_tl_track = invokeMopidyMethod($w, "core.playback.get_current_tl_track", array());
        $isShuffleEnabled = invokeMopidyMethod($w, "core.tracklist.get_random", array());
        if ($isShuffleEnabled) {
            $w->result(null, 'help', "Shuffle is enabled", "The order of tracks presented below is not relevant", './images/warning.png', 'no', null, '');
        }
        $noresult = true;
        $firstTime = true;
        $nb_tracks = 0;
        $track_name = '';
        $album_name = '';
        $playlist_name = '';
        $current_track_found = false;
        $current_track_index = 0;
        foreach ($tl_tracks as $tl_track) {
            $current_track_index++;
            if ($current_track_found == false && $tl_track->tlid == $current_tl_track->tlid) {
                $current_track_found = true;
            }
            if ($current_track_found == false && $tl_track->tlid != $current_tl_track->tlid) {
                continue;
            }
            if ($firstTime == true) {
                $added = '🔈 ';
                if ($playqueue->type == 'playlist') {
                    $playlist_name = $playqueue->name;
                } elseif ($playqueue->type == 'album') {
                    $album_name = $playqueue->name;
                } elseif ($playqueue->type == 'track') {
                    $track_name = $playqueue->name;
                }
                $w->result(null, 'help', "Playing from: " . ucfirst($playqueue->type) . ' ' . $playqueue->name, 'Track ' . $current_track_index . ' on ' . count($tl_tracks) . ' tracks queued', './images/play_queue.png', 'no', null, '');
                // $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, '');
            }
            $firstTime = false;
            $max_tracks_displayed = 150;
            if ($nb_tracks >= $max_tracks_displayed) {
                $w->result(null, 'help', "[...] " . (count($tl_tracks) - $max_tracks_displayed) . " additional tracks are in the queue", "A maximum of " . $max_tracks_displayed . " tracks is displayed.", './images/info.png', 'no', null, '');
                break;
            }
            $track_name = '';
            if (isset($tl_track->track->name)) {
                $track_name = $tl_track->track->name;
            }
            $artist_name = '';
            if (isset($tl_track->track->artists[0]->name)) {
                $artist_name = $tl_track->track->artists[0]->name;
            }
            $album_name = '';
            if (isset($tl_track->track->album->name)) {
                $album_name = $tl_track->track->album->name;
            }
            $duration = 'na';
            if (isset($tl_track->track->length)) {
                $duration = beautifyTime($tl_track->track->length / 1000);
            }
            $track_artwork = getTrackOrAlbumArtwork($w, $tl_track->track->uri, false);
            if (strpos($track_name, '[unplayable]') !== false) {
                $track_name = str_replace('[unplayable]', '', $track_name);
                $w->result(null, '', '🚫 ' . escapeQuery(ucfirst($artist_name)) . " ● " . escapeQuery($track_name), $duration . " ● " . $album_name, $track_artwork, 'no', null, '');
            } else {
                $w->result(null, serialize(array($tl_track->track->uri, '', '', '', '', '', '', 'play_track_from_play_queue', escapeQuery($artist_name), escapeQuery($track_name), escapeQuery($album_name), $track_artwork, '', '', $playlist_name, '')), $added . escapeQuery($artist_name) . " ● " . escapeQuery($track_name), array($duration . " ● " . 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, '');
            }
            $noresult = false;
            $added = '';
            $nb_tracks += 1;
        }
        if ($noresult) {
            $w->result(null, 'help', "There is no track in the play queue from Mopidy", "Make sure to always use the workflow to launch tracks, playlists, etc..Internet connectivity is also required", './images/warning.png', 'no', null, '');
            $w->result(null, serialize(array('', '', '', '', '', '', 'Open▹' . 'http://alfred-spotify-mini-player.com/articles/play-queue/', '', '', '', '', '', '', '', '', '')), 'Learn more about Play Queue', "Find out all information about Play Queue on alfred-spotify-mini-player.com", './images/website.png', 'yes', null, '');
            echo $w->toxml();
        }
    } else {
        $playqueue = $w->read('playqueue.json');
        if ($playqueue == false) {
            $w->result(null, 'help', "There is no track in the play queue", "Make sure to always use the workflow to launch tracks, playlists, etc..Internet connectivity is also required", './images/warning.png', 'no', null, '');
            $w->result(null, serialize(array('', '', '', '', '', '', 'Open▹' . 'http://alfred-spotify-mini-player.com/articles/play-queue/', '', '', '', '', '', '', '', '', '')), 'Learn more about Play Queue', "Find out all information about Play Queue on alfred-spotify-mini-player.com", './images/website.png', 'yes', null, '');
            echo $w->toxml();
            return;
        }
        $command_output = exec("osascript -e '\n        tell application \"Spotify\"\n        if shuffling enabled is true then\n            if shuffling is true then\n                return \"enabled\"\n            else\n                return \"disabled\"\n            end if\n        else\n            return \"disabled\"\n        end if\n        end tell'");
        if ($command_output == "enabled") {
            $w->result(null, 'help', "Shuffle is enabled", "The order of tracks presented below is not relevant", './images/warning.png', 'no', null, '');
        }
        $noresult = true;
        $nb_tracks = 0;
        $track_name = '';
        $album_name = '';
        $playlist_name = '';
        for ($i = $playqueue->current_track_index; $i < count($playqueue->tracks); $i++) {
            $track = $playqueue->tracks[$i];
            if ($noresult == true) {
                $added = '🔈 ';
                if ($playqueue->type == 'playlist') {
                    $playlist_name = $playqueue->name;
                } elseif ($playqueue->type == 'album') {
                    $album_name = $playqueue->name;
                } elseif ($playqueue->type == 'track') {
                    $track_name = $playqueue->name;
                }
                $w->result(null, 'help', "Playing from: " . ucfirst($playqueue->type) . ' ' . $playqueue->name, 'Track ' . ($playqueue->current_track_index + 1) . ' on ' . count($playqueue->tracks) . ' tracks queued', './images/play_queue.png', 'no', null, '');
                // $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, '');
            }
            $max_tracks_displayed = 150;
            if ($nb_tracks >= $max_tracks_displayed) {
                $w->result(null, 'help', "[...] " . (count($playqueue->tracks) - $max_tracks_displayed) . " additional tracks are in the queue", "A maximum of " . $max_tracks_displayed . " tracks is displayed.", './images/info.png', 'no', null, '');
                break;
            }
            $track_name = '';
            if (isset($track->name)) {
                $track_name = $track->name;
            }
            $artist_name = '';
            if (isset($track->artists[0]->name)) {
                $artist_name = $track->artists[0]->name;
            }
            $album_name = '';
            if (isset($track->album->name)) {
                $album_name = $track->album->name;
            }
            $duration = 'na';
            if (isset($track->duration_ms)) {
                $duration = beautifyTime($track->duration_ms / 1000);
            }
            if (isset($track->duration)) {
                $duration = $track->duration;
            }
            $track_artwork = getTrackOrAlbumArtwork($w, $track->uri, false);
            $w->result(null, serialize(array($track->uri, '', '', '', '', '', '', 'play_track_from_play_queue', escapeQuery($artist_name), escapeQuery($track_name), escapeQuery($album_name), $track_artwork, '', '', $playlist_name, '')), $added . escapeQuery($artist_name) . " ● " . escapeQuery($track_name), array($duration . " ● " . 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, '');
            $noresult = false;
            $added = '';
            $nb_tracks += 1;
        }
        if ($noresult) {
            $w->result(null, 'help', "There is no track in the play queue", "Make sure to always use the workflow to launch tracks, playlists, etc..Internet connectivity is also required", './images/warning.png', 'no', null, '');
            $w->result(null, serialize(array('', '', '', '', '', '', 'Open▹' . 'http://alfred-spotify-mini-player.com/articles/play-queue/', '', '', '', '', '', '', '', '', '')), 'Learn more about Play Queue', "Find out all information about Play Queue on alfred-spotify-mini-player.com", './images/website.png', 'yes', null, '');
            echo $w->toxml();
        }
    }
}
Ejemplo n.º 2
0
         # To remove once Spotify fixes the issue.
         exec("osascript -e 'tell application \"Spotify\" to playpause'");
         exec("osascript -e 'tell application \"Spotify\" to playpause'");
         $command_output = exec("osascript -e 'tell application \"Spotify\"\n\t                if sound volume is less than or equal to 0 then\n\t                    set sound volume to 100\n\t                    return \"Spotify volume is unmuted.\"\n\t                else\n\t                    set sound volume to 0\n\t                    return \"Spotify volume is muted.\"\n\t                end if\n\t            end tell'");
     }
     displayNotificationWithArtwork($command_output, './images/mute.png', 'Mute');
     return;
 } else {
     if ($other_action == "shuffle") {
         if ($use_mopidy) {
             $isShuffleEnabled = invokeMopidyMethod($w, "core.tracklist.get_random", array());
             if ($isShuffleEnabled) {
                 invokeMopidyMethod($w, "core.tracklist.set_random", array('value' => false));
                 $command_output = "Shuffle is now disabled.";
             } else {
                 invokeMopidyMethod($w, "core.tracklist.set_random", array('value' => true));
                 $command_output = "Shuffle is now enabled.";
             }
         } else {
             $command_output = exec("osascript -e '\n\t    \ttell application \"Spotify\"\n\t    \tif shuffling enabled is true then\n\t    \t\tif shuffling is true then\n\t\t\t\t\tset shuffling to false\n\t\t\t\t\treturn \"Shuffle is now disabled.\"\n\t\t\t\telse\n\t\t\t\t\tset shuffling to true\n\t\t\t\t\treturn \"Shuffle is now enabled.\"\n\t\t\t\tend if\n\t\t\telse\n\t\t\t\treturn \"Shuffle is not currently enabled.\"\n\t\t\tend if\n\t\t\tend tell'");
         }
         displayNotificationWithArtwork($command_output, './images/shuffle.png', 'Shuffle');
         return;
     } else {
         if ($other_action == "radio_artist") {
             if (file_exists($w->data() . '/update_library_in_progress')) {
                 displayNotificationWithArtwork("Cannot modify library while update is in progress", './images/warning.png', 'Error!');
                 return;
             }
             createRadioArtistPlaylist($w, $artist_name);
             if ($userid != 'vdesabou') {
Ejemplo n.º 3
0
/**
 * playTrackInContextWithMopidy function.
 *
 * @access public
 * @param mixed $w
 * @param mixed $track_uri
 * @param mixed $context_uri
 * @return void
 */
function playTrackInContextWithMopidy($w, $track_uri, $context_uri)
{
    invokeMopidyMethod($w, "core.tracklist.clear", array());
    invokeMopidyMethod($w, "core.tracklist.add", array('uri' => $context_uri, 'at_position' => 0));
    $tl_tracks = invokeMopidyMethod($w, "core.tracklist.get_tl_tracks", array());
    // loop to find track_uri
    $i = 0;
    foreach ($tl_tracks as $tl_track) {
        if ($tl_track->track->uri == $track_uri) {
            // found the track move it to position 0
            invokeMopidyMethod($w, "core.tracklist.move", array('start' => $i, 'end' => $i, 'to_position' => 0));
        }
        $i++;
    }
    $tl_tracks = invokeMopidyMethod($w, "core.tracklist.get_tl_tracks", array());
    invokeMopidyMethod($w, "core.playback.play", array('tl_track' => $tl_tracks[0]));
}
Ejemplo n.º 4
0
if (!file_exists(exec('pwd') . "/packal/package.xml")) {
    $output = $output . "The file " . exec('pwd') . "/packal/package.xml is not present\n";
} else {
    copy(exec('pwd') . "/packal/package.xml", $w->home() . "/Downloads/spot_mini_debug/package.xml");
}
//
// Read settings from JSON
//
$settings = getSettings($w);
$use_mopidy = $settings->use_mopidy;
$output = $output . exec("uname -a");
$output = $output . "\n";
$output = $output . exec("sw_vers -productVersion");
$output = $output . "\n";
$output = $output . exec("sysctl hw.memsize");
$output = $output . "\n";
if (!$use_mopidy) {
    $output = $output . exec("osascript -e 'tell application \"Spotify\" to version'");
} else {
    $output = $output . "Mopidy version is " . invokeMopidyMethod($w, "core.get_version", array(), false);
}
$output = $output . "\n";
file_put_contents($w->home() . "/Downloads/spot_mini_debug/debug.log", $output);
exec("cd ~/Downloads;tar cfz spot_mini_debug.tgz spot_mini_debug");
$w->result(null, serialize(array('', '', '', '', '', '', 'Reveal▹' . $w->home() . '/Downloads/spot_mini_debug.tgz', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '')), 'Browse to generated tgz file', "This will reveal the tgz file in Finder", 'fileicon:' . $w->home() . '/Downloads/spot_mini_debug.tgz', 'yes', null, '');
$w->result(null, serialize(array('', '', '', '', '', '', 'Open▹' . 'mailto:alfred.spotify.mini.player@gmail.com', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '')), 'Send an email to the author', "This will open your default mail application, please attach the generated spot_mini_debug.tgz file.", './images/mail.png', 'yes', null, '');
$w->result(null, '', 'Quick access to workflow folders:', '', './images/info.png', 'no', null, '');
$w->result(null, serialize(array('', '', '', '', '', '', 'Open▹' . $w->data(), '', '', '', '', '', '', '', '', '', '', '', '', '', '', '')), 'Browse to App Support Folder', "This will open the folder in Finder", 'fileicon:' . $w->data(), 'yes', null, '');
$w->result(null, serialize(array('', '', '', '', '', '', 'Open▹' . $w->cache(), '', '', '', '', '', '', '', '', '', '', '', '', '', '', '')), 'Browse to Workflow Cache Folder', "This will open the folder in Finder", 'fileicon:' . $w->cache(), 'yes', null, '');
$w->result(null, serialize(array('', '', '', '', '', '', 'Open▹' . exec('pwd'), '', '', '', '', '', '', '', '', '', '', '', '', '', '', '')), 'Browse to Alfred workflow folder', "This will open the folder in Finder", 'fileicon:' . exec('pwd'), 'yes', null, '');
echo $w->toxml();