Skip to content

Commit

Permalink
Merge pull request #114 from citelao/dev
Browse files Browse the repository at this point in the history
Check for installed Spotify and add some hotkeys
  • Loading branch information
citelao committed Jan 4, 2018
2 parents 3c276a5 + 8789aca commit 8955b8e
Show file tree
Hide file tree
Showing 9 changed files with 170 additions and 17 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog #

## v0.13.5 #
- Added: Now checks for installed Spotify on startup
- Added: New hotkeys for playing albums and artists directly from search
- Changed: @philihp clarrified where build location is

## v0.13.4 #
- Fixed: Compilation albums now have an icon
- Fixed: Can now add playlists with `\` in their titles
Expand Down Expand Up @@ -86,7 +91,6 @@
- Changed: prevent breakage if no track playing.

## v0.9 ##

- Added: created changelog
- Added: error reporting
- Added: context-based searching
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Spotifious uses Packal to make sure you always have the latest version. It gives

## Download & Install ##

Latest version: [v0.13.4](https://github.com/citelao/Spotify-for-Alfred/archive/master.zip) | Latest dev build: [v0.13.4](https://github.com/citelao/Spotify-for-Alfred/archive/dev.zip)
Latest version: [v0.13.5](https://github.com/citelao/Spotify-for-Alfred/archive/master.zip) | Latest dev build: [v0.13.5](https://github.com/citelao/Spotify-for-Alfred/archive/dev.zip)

An in-depth [installation guide](http:https://ben.stolovitz.com/Spotify-for-Alfred/download/) is available on the Spotifious website.

Expand Down
68 changes: 68 additions & 0 deletions info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,29 @@
<key>modifiersubtext</key>
<string></string>
<key>vitoclose</key>
<true/>
</dict>
<dict>
<key>destinationuid</key>
<string>2EA4FBDD-4717-4E37-9067-C93FE29A48F4</string>
<key>modifiers</key>
<integer>0</integer>
<key>modifiersubtext</key>
<string></string>
<key>vitoclose</key>
<false/>
</dict>
</array>
<key>2EA4FBDD-4717-4E37-9067-C93FE29A48F4</key>
<array>
<dict>
<key>destinationuid</key>
<string>605E53E5-EBF3-4D6E-A934-DA94EC49C1CF</string>
<key>modifiers</key>
<integer>0</integer>
<key>modifiersubtext</key>
<string></string>
<key>vitoclose</key>
<false/>
</dict>
</array>
Expand Down Expand Up @@ -316,6 +339,8 @@
<dict>
<key>alfredfiltersresults</key>
<false/>
<key>alfredfiltersresultsmatchmode</key>
<integer>0</integer>
<key>argumenttrimmode</key>
<integer>0</integer>
<key>argumenttype</key>
Expand Down Expand Up @@ -439,6 +464,33 @@ php -f action.php -- "{query}"
<key>version</key>
<integer>1</integer>
</dict>
<dict>
<key>config</key>
<dict>
<key>inputstring</key>
<string>{var:keepalive}</string>
<key>matchcasesensitive</key>
<true/>
<key>matchmode</key>
<integer>1</integer>
<key>matchstring</key>
<string>true</string>
</dict>
<key>type</key>
<string>alfred.workflow.utility.filter</string>
<key>uid</key>
<string>2EA4FBDD-4717-4E37-9067-C93FE29A48F4</string>
<key>version</key>
<integer>1</integer>
</dict>
<dict>
<key>type</key>
<string>alfred.workflow.utility.hidealfred</string>
<key>uid</key>
<string>605E53E5-EBF3-4D6E-A934-DA94EC49C1CF</string>
<key>version</key>
<integer>1</integer>
</dict>
<dict>
<key>config</key>
<dict>
Expand Down Expand Up @@ -847,6 +899,15 @@ This code’s license can be found in LICENSE.md</string>
<key>ypos</key>
<real>10</real>
</dict>
<key>2EA4FBDD-4717-4E37-9067-C93FE29A48F4</key>
<dict>
<key>note</key>
<string>(If we ask to keep the window alive, don't hide)</string>
<key>xpos</key>
<integer>520</integer>
<key>ypos</key>
<integer>290</integer>
</dict>
<key>30E2AA18-937F-4B5D-B685-7852B9717F34</key>
<dict>
<key>xpos</key>
Expand All @@ -868,6 +929,13 @@ This code’s license can be found in LICENSE.md</string>
<key>ypos</key>
<integer>980</integer>
</dict>
<key>605E53E5-EBF3-4D6E-A934-DA94EC49C1CF</key>
<dict>
<key>xpos</key>
<integer>630</integer>
<key>ypos</key>
<integer>290</integer>
</dict>
<key>6792E8E4-6892-467C-A207-2FBF2877E3C6</key>
<dict>
<key>note</key>
Expand Down
10 changes: 8 additions & 2 deletions src/citelao/OhAlfred/Command/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,18 @@

class Command {
protected $script;
protected $return_status = 0;

public function __construct($command) {
$this->script = $command;
}

public function run() {
return exec($this->script);
$unused;
return exec($this->script, $unused, $this->return_status);
}
}

public function status() {
return $this->return_status;
}
}
2 changes: 1 addition & 1 deletion src/citelao/Spotifious/Actions/Applescript.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ public function __construct($options, $alfred, $api) {
public function run() {
$this->action->run();
}
}
}
16 changes: 12 additions & 4 deletions src/citelao/Spotifious/Menus/Main.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ public function output() {
),
// 'mods' => array(
// 'alt' => array(
// 'subtitle' => "Browse to artist ($this->currentArtist)..."
// 'subtitle' => "Browse to artist ($this->currentArtist)...",
// 'arg' => '{"action": "spotifious", "options": { "command": "artist:' . $this->currentArtist . '" }}'
// ),
// 'ctrl' => array(
// 'subtitle' => "Browse to album ($this->currentAlbum)..."
Expand Down Expand Up @@ -81,12 +82,19 @@ public function output() {
'ctrl' => array(
'valid' => true,
'subtitle' => 'Open controls...',
'arg' => '{"action": "spotifious", "options": { "command": "c" }}'
'arg' => '{"action": "spotifious", "options": { "command": "c" }}',
'variables' => array(
'keepalive' => 'true'
)
),
'cmd' => array(
'valid' => true,
'subtitle' => 'Open settings...',
'arg' => '{"action": "spotifious", "options": { "command": "s" }}'
'arg' => '{"action": "spotifious", "options": { "command": "s" }}',
'icon' => array('path' => "include/images/configuration.png"),
'variables' => array(
'keepalive' => 'true'
)
),
'shift' => array(
'valid' => true,
Expand Down Expand Up @@ -129,4 +137,4 @@ protected function now() {

return $array;
}
}
}
48 changes: 46 additions & 2 deletions src/citelao/Spotifious/Menus/Search.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ public function output() {
if($current['type'] == 'playlist') {
$mods = array(
'ctrl' => array(
'subtitle' => 'Play playlist immediately',
'subtitle' => 'Play this playlist',
'valid' => true,
'arg' => "spotify⟩play track \"{$current['uri']}\"",
'autocomplete' => ''
Expand All @@ -188,6 +188,50 @@ public function output() {
// 'subtitle' => 'Queue playlist'
// )
);
} else if($current['type'] == 'artist') {
$mods = array(
'ctrl' => array(
'subtitle' => 'Play this artist',
'valid' => true,
'arg' => "spotify⟩play track \"{$current['uri']}\"",
'autocomplete' => ''
)
// 'cmd' => array( 'subtitle' => 'Queue this artist' ),
// 'shift' => array( 'subtitle' => 'Open in Spotify' )
);
} else if($current['type'] == 'album') {
$mods = array(
'ctrl' => array(
'subtitle' => 'Play this album',
'valid' => true,
'arg' => "spotify⟩play track \"{$current['uri']}\"",
'autocomplete' => ''
)
// 'cmd' => array( 'subtitle' => 'Queue this album' ),
// 'shift' => array( 'subtitle' => 'Open in Spotify' ),
// 'alt' => array('subtitle' => 'Browse to artist'),
);
} else if($current['type'] == 'single') {
$mods = array(
'ctrl' => array(
'subtitle' => 'Play this single',
'valid' => true,
'arg' => "spotify⟩play track \"{$current['uri']}\"",
'autocomplete' => ''
)
// 'cmd' => array( 'subtitle' => 'Queue this single' ),
// 'shift' => array( 'subtitle' => 'Open in Spotify' ),
// 'alt' => array('subtitle' => 'Browse to artist'),
);
} else if($current['type'] == 'track') {
// Unimplemented since we have no good way of changing
// autocomplete strings.
$mods = array(
// 'cmd' => array( 'subtitle' => 'Queue this song' ),
// 'shift' => array( 'subtitle' => 'Open in Spotify' ),
// 'alt' => array('subtitle' => 'Browse to artist'),
// 'ctrl' => array( 'subtitle' => 'Browse to album' ),
);
}

$currentResult['title'] = $current['title'];
Expand Down Expand Up @@ -228,4 +272,4 @@ protected function popularitySort($a, $b) {
protected function contains($stack, $needle) {
return (strpos($stack, $needle) !== false);
}
}
}
19 changes: 14 additions & 5 deletions src/citelao/Spotifious/Menus/Setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@ class Setup implements Menu {
protected $applicationCreated;
protected $applicationLinked;
protected $applicationPreviouslyLinked;
protected $hasInstalledSpotify;

public function __construct($query, $alfred, $api=null) {
$this->alfred = $alfred;

$this->wasOptOut = $this->alfred->options('spotify_app_opt_out') == 'true';
$this->hasInstalledSpotify = $this->alfred->options('has_installed_spotify') == 'true';

$this->countryCodeConfigured = !($this->alfred->options('country') == '');
$this->applicationCreated = !($this->alfred->options('spotify_client_id') == '' || $this->alfred->options('spotify_secret') == '');
Expand Down Expand Up @@ -45,23 +47,30 @@ public function output() {
}

$results[] = array(
'title' => '1. Set your country code',
'title' => '1. Download & install Spotify',
'subtitle' => 'Spotifious only works with the Spotify desktop app.',
'icon' => array('path' => $this->hasInstalledSpotify ? 'include/images/checked.png' : 'include/images/unchecked.png'),
'arg' => '{"action":"command", "options": {"command": "open https://www.spotify.com/us/download/mac/"}}',
);

$results[] = array(
'title' => '2. Set your country code',
'subtitle' => 'Choosing the correct country code makes sure you can play songs you select.',
'icon' => array('path' => $this->countryCodeConfigured ? 'include/images/checked.png' : 'include/images/unchecked.png'),
'autocomplete' => 'Country Code ⟩',
'valid' => false
);

$results[] = array(
'title' => '2. Create a Spotify application',
'title' => '3. Create a Spotify application',
'subtitle' => 'Set up a Spotify application so you can search playlists!',
'icon' => array('path' => $this->applicationCreated ? 'include/images/checked.png' : 'include/images/unchecked.png'),
'arg' => 'appsetup⟩'
);

if($this->applicationPreviouslyLinked) {
$results[] = array(
'title' => '3. Relink your Spotify application',
'title' => '4. Relink your Spotify application',
'subtitle' => "We've added new features to Spotifious, but you need to login again to use them.",
'icon' => array('path' => $this->applicationCreated ? $this->applicationLinked ? 'include/images/checked.png' : 'include/images/unchecked.png' : 'include/images/disabled.png'),
'arg' => 'applink⟩',
Expand All @@ -70,7 +79,7 @@ public function output() {

} else {
$results[] = array(
'title' => '3. Link your Spotify application',
'title' => '4. Link your Spotify application',
'subtitle' => 'Connect your Spotify application to Spotifious to search your playlists.',
'icon' => array('path' => $this->applicationCreated ? $this->applicationLinked ? 'include/images/checked.png' : 'include/images/unchecked.png' : 'include/images/disabled.png'),
'arg' => 'applink⟩',
Expand All @@ -87,4 +96,4 @@ public function output() {

return $results;
}
}
}
16 changes: 15 additions & 1 deletion src/citelao/Spotifious/Spotifious.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use OhAlfred\OhAlfred;
use OhAlfred\Applescript\ApplicationApplescript;
use OhAlfred\Command\Timeout;
use OhAlfred\Command\Command;
use OhAlfred\Exceptions\StatefulException;
use OhAlfred\HTTP\JsonParser;

Expand Down Expand Up @@ -45,9 +46,17 @@ public function run($query) {
$this->alfred->options('lookup_current_song', 'true');
}

if($this->alfred->options('has_installed_spotify') == '' || $this->alfred->options('has_installed_spotify') == 'false') {
$detector = new Command('open -Ra "Spotify"');
$detector->run();
$spotify_installed = !$detector->status();
$this->alfred->options('has_installed_spotify', $spotify_installed);
}

// Display the setup menu if the app isn't setup.
// Or the "options" menu if the S key is pressed
if($this->alfred->options('country') == '' ||
$this->alfred->options('has_installed_spotify') == 'false' ||
$this->alfred->options('spotify_client_id') == '' ||
$this->alfred->options('spotify_secret') == '' ||
$this->optedOut() ||
Expand Down Expand Up @@ -182,6 +191,11 @@ public function process($action) {
$action = null;
if($json->action == "applescript") {
$action = new Applescript($options, $this->alfred, $api);
} else if($json->action == "command") {
if(!isset($options->command)) {
throw new StatefulException("You have to have a command to run!");
}
$action = new Command($options->command);
} else if($json->action == "spotifious") {
$v = $this->alfred->version()[0];
$command = ($options->command)
Expand Down Expand Up @@ -397,4 +411,4 @@ protected function update_playlists_cache($api) {
$this->alfred->options('playlists_cache_date', $datetime->format("@U"));
$this->alfred->options('playlists', $search_data);
}
}
}

0 comments on commit 8955b8e

Please sign in to comment.