Ejemplo n.º 1
0
function getArtistArtwork($artist, $fetchIfNotPresent)
{
    $parsedArtist = urlencode($artist);
    $w = new Workflows();
    if (!file_exists($w->data() . "/artwork")) {
        exec("mkdir '" . $w->data() . "/artwork'");
    }
    $currentArtwork = $w->data() . "/artwork/{$parsedArtist}.png";
    if (!file_exists($currentArtwork)) {
        if ($fetchIfNotPresent == true) {
            $artwork = getArtistArtworkURL($artist);
            // if return 0, it is a 404 error, no need to fetch
            if (!empty($artwork) || is_numeric($artwork) && $artwork != 0) {
                $fp = fopen($currentArtwork, 'w+');
                $options = array(CURLOPT_FILE => $fp);
                $w->request("{$artwork}", $options);
                if (filesize($currentArtwork) == 0) {
                    unlink($currentArtwork);
                    return "images/default_artist.png";
                }
            }
        } else {
            return "images/default_artist.png";
        }
    }
    if (is_numeric($artwork) && $artwork == 0) {
        return "images/default_artist.png";
    } else {
        return $currentArtwork;
    }
}
Ejemplo n.º 2
0
 function __construct($a = "database.db")
 {
     require_once 'workflows.php';
     $w = new Workflows();
     $this->cache = $w->cache();
     $this->data = $w->data();
     $this->bundle = $w->bundle();
     $this->path = $w->path();
     $this->home = $w->home();
     if (file_exists($this->data . '/' . $a)) {
         $a = $this->data . '/' . $a;
     } elseif (file_exists($this->cache . '/' . $a)) {
         $a = $this->cache . '/' . $a;
     } elseif (file_exists($this->path . '/' . $a)) {
         $a = $this->path . '/' . $a;
     } elseif (file_exists($a)) {
         // do nothing.
     } else {
         $a = $this->data . '/' . $a;
     }
     $this->open($a);
 }
<?php

require_once 'workflows.php';
$w = new Workflows();
ini_set('memory_limit', '512M');
//
// Create the library_starred_playlist.json
//
if (!file_exists($w->data() . "/library_starred_playlist.json")) {
    $array_starred_items = array();
    if (file_exists($w->data() . "/library.json")) {
        $json = file_get_contents($w->data() . "/library.json");
        $json = json_decode($json, true);
        foreach ($json as $item) {
            if ($item['data']['starred'] == true) {
                array_push($array_starred_items, $item);
            }
        }
        $w->write($array_starred_items, 'library_starred_playlist.json');
    }
}
//
// Create the playlists.json
//
if (!file_exists($w->data() . "/playlists-tmp.json")) {
    exec('mdfind -name guistate', $results);
    $theUser = "";
    $theGuiStateFile = "";
    foreach ($results as $guistateFile) {
        if (strpos($guistateFile, "Spotify/Users") !== false) {
            $theGuiStateFile = $guistateFile;
<?php

include_once 'functions.php';
require_once 'workflows.php';
$w = new Workflows();
$ret = $w->get('all_playlists', 'settings.plist');
if ($ret == 'true') {
    $all_playlists = true;
} else {
    $all_playlists = false;
}
# increase memory_limit
ini_set('memory_limit', '512M');
if (file_exists($w->data() . "/library.json")) {
    $json = file_get_contents($w->data() . "/library.json");
    $json = json_decode($json, true);
    foreach ($json as $item) {
        if ($all_playlists == false && $item['data']['starred'] == true || $all_playlists == true) {
            getTrackArtwork($item['data']['uri'], true);
            getArtistArtwork($item['data']['album']['artist']['name'], true);
            getTrackArtwork($item['data']['album']['uri'], true);
        }
    }
}
//
// playlists
//
// retrieve playlist uri from playlist name
if (file_exists($w->data() . "/playlists.json")) {
    $json = file_get_contents($w->data() . "/playlists.json");
    $json = json_decode($json, true);
Ejemplo n.º 5
0
        $w->result(uniqid(), serialize(array('', '', '', '', '', '', '', 'update_library', '', '', '', '', '', '', '', '', '', '')), "Re-Create Library", "when done you'll receive a notification. you can check progress by invoking the workflow again", './images/update.png', 'yes', null, '');
    } elseif (startsWith($query, 'AppleScript Exception')) {
        $w->result(null, 'help', "AppleScript execution failed!", "Message: " . $query, './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, '');
    } elseif (startsWith($query, 'Mopidy Exception')) {
        $w->result(null, 'help', "Mopidy execution failed!", "Message: " . $query, './images/warning.png', 'no', null, '');
        $w->result(null, serialize(array('', '', '', '', '', '', 'Open▹' . 'http://alfred-spotify-mini-player.com/articles/mopidy/', '', '', '', '', '', '', '', '', '')), 'Is Mopidy correctly installed and running?', "Go to the article to get more information", './images/website.png', 'yes', null, '');
    } else {
        $w->result(null, '', 'Exception occurred: ' . $query, 'Use the Send an email to the author option below to send generated spot_mini_debug.tgz', './images/warning.png', 'no', null, '');
    }
}
exec("mkdir -p ~/Downloads/spot_mini_debug");
$output = "DEBUG: ";
//
// check for library update in progress
if (file_exists($w->data() . "/update_library_in_progress")) {
    $w->result('', '', "Library update in progress", "", 'fileicon:' . $w->data() . '/update_library_in_progress', 'no', null, '');
    $output = $output . "Library update in progress: " . "the file" . $w->data() . "/update_library_in_progress is present\n";
}
if (!file_exists($w->data() . "/settings.json")) {
    $output = $output . "The file " . $w->data() . "/settings.json is not present\n";
} else {
    copy($w->data() . "/settings.json", $w->home() . "/Downloads/spot_mini_debug/settings.json");
}
copyDirectory($w->cache(), $w->home() . "/Downloads/spot_mini_debug/cache");
if (!file_exists($w->data() . "/fetch_artworks.db")) {
    $output = $output . "The file " . $w->data() . "/fetch_artworks.db is not present\n";
} else {
    copy($w->data() . "/fetch_artworks.db", $w->home() . "/Downloads/spot_mini_debug/fetch_artworks.db");
}
if (!file_exists($w->data() . "/library.db")) {
Ejemplo n.º 6
0
<?php

// Almost all of this code is from Spoticious workflow (http://www.alfredforum.com/topic/1644-spotifious-a-natural-spotify-controller-for-alfred/)
// Thanks citelao https://github.com/citelao/Spotify-for-Alfred
// Thanks Jeff Johns <http://phpfunk.me/>; this is identical to his `clear.php`
require_once 'workflows.php';
$w = new Workflows();
$folder = $w->data() . "/artwork";
$bytes = 0;
$total = 0;
if ($handle = opendir($folder)) {
    while (false !== ($file = readdir($handle))) {
        if (stristr($file, '.png')) {
            unlink($folder . '/' . $file);
        }
    }
    closedir($handle);
}
echo "All Artworks were cleared";
Ejemplo n.º 7
0
Archivo: main.php Proyecto: bycEEE/env
require './src/functions.php';
require './src/menu.php';
require_once './src/workflows.php';
// $begin_time = computeTime();
// Report all PHP errors
//error_reporting(E_ALL);
error_reporting(0);
$w = new Workflows('com.vdesabou.spotify.mini.player');
$query = escapeQuery($argv[1]);
// thanks to http://www.alfredforum.com/topic/1788-prevent-flash-of-no-result
$query = iconv('UTF-8-MAC', 'UTF-8', $query);
//
// check for library update in progress
$update_in_progress = false;
if (file_exists($w->data() . '/update_library_in_progress')) {
    $in_progress_data = $w->read('update_library_in_progress');
    $update_library_in_progress_words = explode('▹', $in_progress_data);
    $elapsed_time = time() - $update_library_in_progress_words[3];
    $update_in_progress = true;
    if (!file_exists($w->data() . '/library_old.db')) {
        if (startsWith($update_library_in_progress_words[0], 'Init')) {
            if ($elapsed_time < 1800) {
                $w->result(null, $w->data() . '/update_library_in_progress', 'Initialization phase since ' . beautifyTime($elapsed_time, true) . ' : ' . floatToSquares(0), 'Waiting for Spotify servers to return required data, it may take time depending on your library', './images/update_in_progress.png', 'no', null, '');
            } else {
                $w->result(null, '', 'There is a problem, the initialization phase took more than 30 minutes', 'Choose kill update library below, and report to the author', './images/warning.png', 'no', null, '');
                $w->result(null, serialize(array('', '', '', '', '', '', '', 'kill_update', $alfred_playlist_uri, '', '', '', '', '', '', '', '', $alfred_playlist_name, $now_playing_notifications, $is_alfred_playlist_active, $country_code, $userid)), 'Kill update library', 'This will stop the library update', './images/kill.png', 'yes', '');
            }
        } else {
            if ($update_library_in_progress_words[0] == 'Refresh Library') {
                $type = 'playlists';
<?php

require './src/functions.php';
require_once './src/workflows.php';
$w = new Workflows('com.vdesabou.spotify.mini.player');
$query = $argv[1];
if (mb_strlen($query) > 1) {
    if (startsWith($query, 'DB Exception')) {
        $w->result(null, '', 'DB Exception occurred: ' . $query, 'Try to re-create library as explained below.', './images/warning.png', 'no', null, '');
        $w->result(uniqid(), '', 'There is a problem with the library, try to re-create it.', 'Select Re-Create Library library below', './images/warning.png', 'no', null, '');
        $w->result(uniqid(), serialize(array('', '', '', '', '', '', '', 'update_library', '', '', '', '', '', '', '', '', '', '')), "Re-Create Library", "when done you'll receive a notification. you can check progress by invoking the workflow again", './images/update.png', 'yes', null, '');
    } elseif (startsWith($query, 'AppleScript Exception')) {
        $w->result(null, 'help', "AppleScript execution failed!", "Message: " . $query, './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, '');
    } elseif (startsWith($query, 'Mopidy Exception')) {
        $w->result(null, 'help', "Mopidy execution failed!", "Message: " . $query, './images/warning.png', 'no', null, '');
        $w->result(null, serialize(array('', '', '', '', '', '', 'Open▹' . 'http://alfred-spotify-mini-player.com/articles/mopidy/', '', '', '', '', '', '', '', '', '')), 'Is Mopidy correctly installed and running?', "Go to the article to get more information", './images/website.png', 'yes', null, '');
    } else {
        $w->result(null, '', 'Exception occurred: ' . $query, 'Use the Send an email to the author option below to send generated spot_mini_debug.tgz', './images/warning.png', 'no', null, '');
    }
}
$w->result(null, serialize(array('', '', '', '', '', '', '', 'spot_mini_debug', '', '', '', '', '', '', '', '')), 'Send an email to the author with a link to generated spot_mini_debug.tgz file', "This will open your default mail application, with all needed information for troubleshooting.", './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();
Ejemplo n.º 9
0
<?php

require_once 'workflows.php';
$w = new Workflows();
$created = false;
if (file_exists($w->data() . "/library.json")) {
    $created = true;
}
putenv('LANG=fr_FR.UTF-8');
ini_set('memory_limit', '512M');
//try to decode it
$json = json_decode(exec('pbpaste'));
if (json_last_error() === JSON_ERROR_NONE) {
    $fp = fopen($w->data() . "/library.json", 'w+');
    fwrite($fp, exec('pbpaste'));
    fclose($fp);
    if ($created == true) {
        echo "Library has been updated";
    } else {
        echo "Library has been created";
    }
} else {
    //it's not JSON. Log error
    echo "ERROR: JSON data is not valid!";
    unlink($w->data() . "/library.json");
}
Ejemplo n.º 10
0
Archivo: debug.php Proyecto: bycEEE/env
    if (startsWith($query, 'DB Exception')) {
        $w->result(null, '', 'DB Exception occurred: ' . $query, 'Try to re-create library as explained below.', './images/warning.png', 'no', null, '');
        $w->result(uniqid(), '', 'There is a problem with the library, try to re-create it.', 'Select Re-Create Library library below', './images/warning.png', 'no', null, '');
        $w->result(uniqid(), serialize(array('', '', '', '', '', '', '', 'update_library', '', '', '', '', '', '', '', '', '', '')), "Re-Create Library", "when done you'll receive a notification. you can check progress by invoking the workflow again", './images/update.png', 'yes', null, '');
    } elseif (startsWith($query, 'AppleScript Exception')) {
        $w->result(null, 'help', "AppleScript execution failed!", "Message: " . $query, './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, '');
    } else {
        $w->result(null, '', 'Exception occurred: ' . $query, 'Use the Send an email to the author option below to send generated spot_mini_debug.tgz', './images/warning.png', 'no', null, '');
    }
}
exec("mkdir -p ~/Downloads/spot_mini_debug");
$output = "DEBUG: ";
//
// check for library update in progress
if (file_exists($w->data() . "/update_library_in_progress")) {
    $w->result('', '', "Library update in progress", "", 'fileicon:' . $w->data() . '/update_library_in_progress', 'no', null, '');
    $output = $output . "Library update in progress: " . "the file" . $w->data() . "/update_library_in_progress is present\n";
}
if (!file_exists($w->data() . "/settings.json")) {
    $output = $output . "The file " . $w->data() . "/settings.json is not present\n";
} else {
    copy($w->data() . "/settings.json", $w->home() . "/Downloads/spot_mini_debug/settings.json");
}
copy_directory($w->cache(), $w->home() . "/Downloads/spot_mini_debug/cache");
if (!file_exists($w->data() . "/fetch_artworks.db")) {
    $output = $output . "The file " . $w->data() . "/fetch_artworks.db is not present\n";
} else {
    copy($w->data() . "/fetch_artworks.db", $w->home() . "/Downloads/spot_mini_debug/fetch_artworks.db");
}
if (!file_exists($w->data() . "/library.db")) {