Skip to content

Commit

Permalink
Merge pull request #84 from citelao/dev
Browse files Browse the repository at this point in the history
Maintaining my projects
  • Loading branch information
citelao authored Mar 13, 2017
2 parents 1c94f21 + 77e1174 commit b65e70e
Show file tree
Hide file tree
Showing 26 changed files with 475 additions and 180 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
# my private data
*.sublime-workspace

# build cruft
build/
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
# Changelog #

## v0.13.2 #
- Added: Use JSON output when possible
- Added: Exceptions appear in debugger for actions
- Changed: Search uses API with auth
- Changed: Album pages use API with auth
- Changed: Album pages load faster
- Changed: Info loads much faster (but may break in edge cases)
- Changed: Popularity boxes look pretty now (thanks, danielma!)
- Changed: Build size is much smaller
- Fixed: Single-digit seconds are now prefixed with a 0
- Fixed: Add Homebrew to path if needed (thanks, mieubrisse!)
- Fixed: Setup in Alfred 3 works
- Fixed: The UK shows up at the top of country selection

## v0.13.1 ##
- Fixed: Alfred 3 compatibility
- Fixed: America appears first in country selection
Expand Down
14 changes: 11 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.PHONY = all init clean build
.PHONY = all init clean build.intermediates build.images build

all: clean build

Expand All @@ -7,7 +7,15 @@ init:

clean:
-rm -r dist/
-rm -r build/

build:
build.intermediates:
mkdir build/
@echo "TODO BUILD IN BUILD DIRECTORY"

build.images:
@echo "TODO COMPILE IMAGES"

build: build.intermediates build.images
mkdir dist/
zip -x '*.git*' '*include/images/psd*' '*.psd' -r dist/Spotifious.alfredworkflow ./
zip -q -x '*.git*' '*include/images/psd*' '*include/screenshots*' '*.psd' -r dist/Spotifious.alfredworkflow ./
21 changes: 14 additions & 7 deletions action.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,25 @@
// thanks to http://www.alfredforum.com/topic/1788-prevent-flash-of-no-result
mb_internal_encoding("UTF-8");
date_default_timezone_set('America/New_York');
ini_set("display_errors", "stderr");

use OhAlfred\OhAlfred;
use Spotifious\Spotifious;
require 'vendor/autoload.php';

$spotifious = new Spotifious();
$alfred = new OhAlfred();
try{
$spotifious = new Spotifious($alfred);

$action = $argv[1];
$results = $spotifious->process($action);
$action = $argv[1];
$results = $spotifious->process($action);

// For debugging
// print_r($action);
// print("\n");
// For debugging
// print_r($action);
// print("\n");

print_r($results);
print_r($results);
} catch(Exception $e) {
$alfred->exceptionify($e, false);
throw $e;
}
Binary file modified dist/Spotifious.alfredworkflow
Binary file not shown.
37 changes: 33 additions & 4 deletions info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,10 @@
<key>runningsubtext</key>
<string>Getting Spotifious data...</string>
<key>script</key>
<string>php -d display_errors='stderr' -f main.php -- "{query}"
<string># Add Homebrew to path for those who need :)
export PATH="/usr/local/bin:${PATH}"
php -f main.php -- "{query}"
# In case you are experiencing unsolveable issues,
# you can generate a log file to help me. Modify the
Expand Down Expand Up @@ -297,6 +300,10 @@
<integer>0</integer>
<key>argument</key>
<integer>0</integer>
<key>focusedappvariable</key>
<false/>
<key>focusedappvariablename</key>
<string></string>
<key>hotkey</key>
<integer>36</integer>
<key>hotmod</key>
Expand Down Expand Up @@ -325,7 +332,10 @@
<key>escaping</key>
<integer>4</integer>
<key>script</key>
<string>php -f action.php -- "{query}"
<string># Add Homebrew to path for those who need :)
export PATH="/usr/local/bin:${PATH}"
php -f action.php -- "{query}"
# In case you are experiencing unsolveable issues,
# you can generate a log file to help me. Modify the
Expand Down Expand Up @@ -388,6 +398,10 @@
<integer>3</integer>
<key>argumenttext</key>
<string>playpause⟩</string>
<key>focusedappvariable</key>
<false/>
<key>focusedappvariablename</key>
<string></string>
<key>hotkey</key>
<integer>49</integer>
<key>hotmod</key>
Expand Down Expand Up @@ -438,6 +452,10 @@
<integer>3</integer>
<key>argumenttext</key>
<string>next⟩</string>
<key>focusedappvariable</key>
<false/>
<key>focusedappvariablename</key>
<string></string>
<key>hotkey</key>
<integer>124</integer>
<key>hotmod</key>
Expand Down Expand Up @@ -488,6 +506,10 @@
<integer>3</integer>
<key>argumenttext</key>
<string>previous⟩</string>
<key>focusedappvariable</key>
<false/>
<key>focusedappvariablename</key>
<string></string>
<key>hotkey</key>
<integer>123</integer>
<key>hotmod</key>
Expand Down Expand Up @@ -538,6 +560,10 @@
<integer>3</integer>
<key>argumenttext</key>
<string>volup⟩</string>
<key>focusedappvariable</key>
<false/>
<key>focusedappvariablename</key>
<string></string>
<key>hotkey</key>
<integer>126</integer>
<key>hotmod</key>
Expand Down Expand Up @@ -588,6 +614,10 @@
<integer>3</integer>
<key>argumenttext</key>
<string>voldown⟩</string>
<key>focusedappvariable</key>
<false/>
<key>focusedappvariablename</key>
<string></string>
<key>hotkey</key>
<integer>125</integer>
<key>hotmod</key>
Expand All @@ -611,7 +641,6 @@
</array>
<key>readme</key>
<string># Spotifious
# v0.13.1
I’ve worked a long time on it to make it as good as it can be, and if you have any ideas to make it better or if you need to complain, leave me a note on my GitHub page or on the forum threads, linked below.
Expand Down Expand Up @@ -743,7 +772,7 @@ This code’s license can be found in LICENSE.md</string>
</dict>
</dict>
<key>version</key>
<string></string>
<string>0.13.2</string>
<key>webaddress</key>
<string>https://github.com/citelao/Spotify-for-Alfred</string>
</dict>
Expand Down
14 changes: 9 additions & 5 deletions main.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// thanks to http://www.alfredforum.com/topic/1788-prevent-flash-of-no-result
mb_internal_encoding("UTF-8");
date_default_timezone_set('America/New_York');
ini_set("display_errors", "stderr");

use OhAlfred\OhAlfred;
use Spotifious\Spotifious;
Expand All @@ -14,12 +15,15 @@
**/

$alfred = new OhAlfred();
$spotifious = new Spotifious();

set_exception_handler(array($alfred, 'exceptionify'));
set_error_handler(array($alfred, 'errorify'), E_ALL);
try {
$spotifious = new Spotifious($alfred);

$query = $argv[1];
$results = $spotifious->run($query);
$query = $argv[1];
$results = $spotifious->run($query);

$alfred->alfredify($results);
$alfred->alfredify($results);
} catch(Exception $e) {
$alfred->exceptionify($e);
}
12 changes: 4 additions & 8 deletions src/citelao/OhAlfred/Exceptions/StatefulException.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,11 @@ class StatefulException extends \Exception implements IStatefulException {
protected $throwState;

// List of things that should never be written to debug files.
protected $forbidden = array("_POST", "_SERVER", "_GET", "_FILES", "_COOKIE");
protected $forbidden = array("_POST", "_SERVER", "_GET", "_FILES", "_COOKIE", "api");

function __construct($message, $vars = '') {
if($vars == '') {
$this->throwState = get_defined_vars();
} else {
$vars = array_diff_key($vars, array_flip($this->forbidden)); // Take out all private things.
$this->throwState = $vars;
}
function __construct($message, $vars = []) {
$all_vars = array_merge(get_defined_vars(), $vars);
$this->throwState = array_diff_key($all_vars, array_flip($this->forbidden)); // Take out all private things.

parent::__construct($message);
}
Expand Down
5 changes: 2 additions & 3 deletions src/citelao/OhAlfred/HTTP/Fetcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,10 @@ public function run() {
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
$page = curl_exec($ch);
$info = curl_getinfo($ch);
$page = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);


if($info['http_code'] != '200') {
if ($info['http_code'] == '0') {
throw new StatefulException("Could not access $this->url. Try searching again");
Expand Down
12 changes: 5 additions & 7 deletions src/citelao/OhAlfred/HTTP/JsonFetcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,24 @@
namespace OhAlfred\HTTP;

use OhAlfred\HTTP\Fetcher;
use OhAlfred\HTTP\JsonParser;
use OhAlfred\Exceptions\StatefulException;

class JsonFetcher {
protected $fetcher;
protected $url;

public function __construct($url) {
$this->url = $url;
$this->fetcher = new Fetcher($url);
}

public function run() {
$json = $this->fetcher->run();

if(empty($json))
throw new StatefulException("No JSON returned from " . $url);
throw new StatefulException("No JSON returned from " . $this->url);

$json = json_decode($json);

if($json == null)
throw new StatefulException("JSON error: " . json_last_error());

return $json;
return JsonParser::parse($json);
}
}
16 changes: 16 additions & 0 deletions src/citelao/OhAlfred/HTTP/JsonParser.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php
namespace OhAlfred\HTTP;

use OhAlfred\HTTP\Fetcher;
use OhAlfred\Exceptions\StatefulException;

class JsonParser {
static public function parse($json) {
$json = json_decode($json);

if($json == null)
throw new StatefulException("JSON error: " . json_last_error(), array('json' => $json));

return $json;
}
}
Loading

0 comments on commit b65e70e

Please sign in to comment.