Example #1
0
/**
 * secondDelimiterFollowOrUnfollow function.
 *
 * @access public
 * @param mixed $w
 * @param mixed $query
 * @param mixed $settings
 * @param mixed $db
 * @param mixed $update_in_progress
 * @return void
 */
function secondDelimiterFollowOrUnfollow($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) {
        //
        // Follow / Unfollow actions
        //
        $tmp = $words[1];
        $words = explode('@', $tmp);
        $artist_uri = $words[0];
        $tmp_uri = explode(':', $artist_uri);
        $artist_name = $words[1];
        if ($kind == "Follow") {
            $follow = true;
        } else {
            $follow = false;
        }
        try {
            $api = getSpotifyWebAPI($w);
            if ($follow) {
                $ret = $api->followArtistsOrUsers('artist', $tmp_uri[2]);
            } else {
                $ret = $api->unfollowArtistsOrUsers('artist', $tmp_uri[2]);
            }
            if ($ret) {
                if ($follow) {
                    displayNotificationWithArtwork('You are now following the artist ' . $artist_name, './images/follow.png', 'Follow');
                    exec("osascript -e 'tell application \"Alfred 2\" to search \"spot_mini Artist▹" . $artist_uri . "∙" . escapeQuery($artist_name) . '▹' . "\"'");
                } else {
                    displayNotificationWithArtwork('You are no more following the artist ' . $artist_name, './images/follow.png', 'Unfollow');
                    exec("osascript -e 'tell application \"Alfred 2\" to search \"spot_mini Artist▹" . $artist_uri . "∙" . escapeQuery($artist_name) . '▹' . "\"'");
                }
            } else {
                $w->result(null, '', 'Error!', 'An error happened, try again or report to the author', './images/warning.png', 'no', null, '');
            }
        } catch (SpotifyWebAPI\SpotifyWebAPIException $e) {
            $w->result(null, 'help', "Exception occurred", "" . $e->getMessage(), './images/warning.png', 'no', null, '');
            echo $w->toxml();
            return;
        }
    }
}
Example #2
0
/**
 * getSettings function.
 *
 * @access public
 * @param mixed $w
 * @return void
 */
function getSettings($w)
{
    if (file_exists($w->data() . '/settings.db') && !file_exists($w->data() . '/settings.json')) {
        // migrate settings.db to settings.json
        //
        // Read settings from DB
        //
        $getSettings = 'select all_playlists,is_spotifious_active,is_alfred_playlist_active,radio_number_tracks,is_lyrics_active,max_results, alfred_playlist_uri,alfred_playlist_name,country_code,theme,last_check_update_time,oauth_client_id,oauth_client_secret,oauth_redirect_uri,oauth_access_token,oauth_expires,oauth_refresh_token,display_name,userid,echonest_api_key from settings';
        $dbsettingsfile = $w->data() . '/settings.db';
        try {
            $dbsettings = new PDO("sqlite:{$dbsettingsfile}", "", "", array(PDO::ATTR_PERSISTENT => true));
            $dbsettings->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
            $dbsettings->query("PRAGMA synchronous = OFF");
            $dbsettings->query("PRAGMA journal_mode = OFF");
            $dbsettings->query("PRAGMA temp_store = MEMORY");
            $dbsettings->query("PRAGMA count_changes = OFF");
            $dbsettings->query("PRAGMA PAGE_SIZE = 4096");
            $dbsettings->query("PRAGMA default_cache_size=700000");
            $dbsettings->query("PRAGMA cache_size=700000");
            $dbsettings->query("PRAGMA compile_options");
            $stmt = $dbsettings->prepare($getSettings);
            $settings = $stmt->execute();
            $setting = $stmt->fetch();
            $migrated = array('all_playlists' => $setting[0], 'is_alfred_playlist_active' => $setting[2], 'radio_number_tracks' => $setting[3], 'now_playing_notifications' => 1, 'max_results' => $setting[5], 'alfred_playlist_uri' => $setting[6], 'alfred_playlist_name' => $setting[7], 'country_code' => $setting[8], 'last_check_update_time' => $setting[10], 'oauth_client_id' => $setting[11], 'oauth_client_secret' => $setting[12], 'oauth_redirect_uri' => 'http://localhost:15298/callback.php', 'oauth_access_token' => $setting[14], 'oauth_expires' => $setting[15], 'oauth_refresh_token' => $setting[16], 'display_name' => $setting[17], 'userid' => $setting[18], 'echonest_api_key' => '5EG94BIZEGFEY9AL9', 'is_public_playlists' => 0);
            $ret = $w->write($migrated, 'settings.json');
        } catch (PDOException $e) {
            logMsg("Error(getSettings): (exception " . print_r($e) . ")");
        }
        deleteTheFile($w->data() . '/settings.db');
    }
    $settings = $w->read('settings.json');
    if ($settings == false) {
        $default = array('all_playlists' => 1, 'is_alfred_playlist_active' => 1, 'radio_number_tracks' => 30, 'now_playing_notifications' => 1, 'max_results' => 50, 'alfred_playlist_uri' => '', 'alfred_playlist_name' => '', 'country_code' => '', 'last_check_update_time' => 0, 'oauth_client_id' => '', 'oauth_client_secret' => '', 'oauth_redirect_uri' => 'http://localhost:15298/callback.php', 'oauth_access_token' => '', 'oauth_expires' => 0, 'oauth_refresh_token' => '', 'display_name' => '', 'userid' => '', 'echonest_api_key' => '5EG94BIZEGFEY9AL9', 'is_public_playlists' => 0, 'quick_mode' => 0);
        $ret = $w->write($default, 'settings.json');
        displayNotificationWithArtwork("Settings have been set to default", './images/info.png', 'Settings reset');
        $settings = $w->read('settings.json');
    }
    // add quick_mode if needed
    if (!isset($settings->quick_mode)) {
        updateSetting($w, 'quick_mode', 0);
        $settings = $w->read('settings.json');
    }
    return $settings;
}
Example #3
0
<?php

require './vendor/autoload.php';
require './src/functions.php';
require_once './src/workflows.php';
$w = new Workflows('com.vdesabou.spotify.mini.player');
//
// Read settings from JSON
//
$settings = getSettings($w);
$oauth_client_id = $settings->oauth_client_id;
$oauth_client_secret = $settings->oauth_client_secret;
$oauth_redirect_uri = $settings->oauth_redirect_uri;
try {
    $session = new SpotifyWebAPI\Session($oauth_client_id, $oauth_client_secret, $oauth_redirect_uri);
    // Get the authorization URL and send the user there
    header('Location: ' . $session->getAuthorizeUrl(array('scope' => array('user-library-read', 'user-read-email', 'user-read-private', 'user-library-modify', 'user-follow-modify', 'user-follow-read', 'playlist-read-private', 'playlist-modify-public', 'playlist-modify-private', 'playlist-read-collaborative'), 'show_dialog' => true)));
} catch (SpotifyWebAPI\SpotifyWebAPIException $e) {
    echo "There was an error during the authentication flow (exception " . $e . ")";
    displayNotificationWithArtwork("Web server killed", './images/warning.png', 'Error!');
    exec("kill -9 \$(ps -efx | grep \"php -S localhost:15298\"  | grep -v grep | awk '{print \$2}')");
    return;
}
Example #4
0
                         return;
                     } else {
                         if ($other_action == "update_library") {
                             if (file_exists($w->data() . '/update_library_in_progress')) {
                                 displayNotificationWithArtwork("Cannot modify library while update is in progress", './images/warning.png', 'Error!');
                                 return;
                             }
                             updateLibrary($w);
                             if ($userid != 'vdesabou') {
                                 stathat_ez_count('AlfredSpotifyMiniPlayer', 'update library', 1);
                             }
                             return;
                         } else {
                             if ($other_action == "refresh_library") {
                                 if (file_exists($w->data() . '/update_library_in_progress')) {
                                     displayNotificationWithArtwork("Cannot modify library while update is in progress", './images/warning.png', 'Error!');
                                     return;
                                 }
                                 refreshLibrary($w);
                                 if ($userid != 'vdesabou') {
                                     stathat_ez_count('AlfredSpotifyMiniPlayer', 'update library', 1);
                                 }
                                 return;
                             }
                         }
                     }
                 }
             }
         }
     }
 }