Skip to content

Commit

Permalink
Update complete codebase
Browse files Browse the repository at this point in the history
Added new autocomplete for commands action
Added commands file
Added execute file
Removed most of the workflow and put into PHP/OSA files in workflow folder to keep things clean
Update releases for new release
Removed applescript.txt file since you can see commands in code now
  • Loading branch information
phpfunk committed Jul 8, 2013
1 parent 903f877 commit 59de824
Show file tree
Hide file tree
Showing 6 changed files with 225 additions and 2 deletions.
Binary file modified Spotify.alfredworkflow
Binary file not shown.
1 change: 0 additions & 1 deletion applescript.txt

This file was deleted.

26 changes: 26 additions & 0 deletions autocomplete.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php
include dirname(__FILE__) . '/autoload.php';
include dirname(__FILE__) . '/shared/commands.php';

$query = (isset($argv[1])) ? trim(strtolower($argv[1])) : null;
$tmp = explode(' ', $query);
$c = $tmp[0];
$len = strlen($c);

$results = array();
foreach ($commands as $key => $arr) {
if (empty($query) || substr($key, 0, $len) == $c) {
array_push($results, array(
'uid' => $key,
'arg' => $query,
'title' => $arr['title'],
'subtitle' => $arr['subtitle'],
'icon' => 'icon.png',
'autocomplete' => $key
));
}
}

if (! empty($results)) {
print Tools::arrayToXML($results);
}
33 changes: 33 additions & 0 deletions execute.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php
include dirname(__FILE__) . '/autoload.php';
include dirname(__FILE__) . '/shared/commands.php';

$app_dir = dirname(__FILE__) . '/applescripts/';
$query = (isset($argv[1])) ? trim(strtolower($argv[1])) : null;
$tmp = explode(' ', $query);
$key = $tmp[0];
$query = trim(str_replace($key, '', $query));

if (array_key_exists($key, $commands)) {
if (isset($commands[$key]['bash'])) {
$command = $commands[$key]['bash'];
}
else {
$command = str_replace('{query}', $query, $commands[$key]['command']);
if (stristr($command, '.scpt')) {
$command = 'q=' . $query . ' osascript "' . $app_dir . $command . '"';
}
else {
$command = 'osascript -e \'tell application "Spotify"' . "\n" . $command . "\n" . 'end tell\'';
}
}

$output = trim(shell_exec($command));

if (! empty($output)) {
print $output;
}
}
else {
print "Command not found.";
}
2 changes: 1 addition & 1 deletion releases.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<?php
include dirname(__FILE__) . '/autoload.php';
Releases::get('alfred-spotify-controls', '2.2.2');
Releases::get('alfred-spotify-controls', '2.2.3');
165 changes: 165 additions & 0 deletions shared/commands.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
<?php
$commands = array(
'<' => array(
'title' => 'Replay Track',
'subtitle' => 'Replay the current track',
'command' => 'previous track'
),
'<<' => array(
'title' => 'Previous Track',
'subtitle' => 'Play the previous track',
'command' => 'previous track' . "\n" . 'previous track'
),
'>' => array(
'title' => 'Next Track',
'subtitle' => 'Play the next track',
'command' => 'next track'
),
'play' => array(
'title' => 'Toggle Play/Pause',
'subtitle' => 'Toggle between play and pause state',
'command' => 'playpause'
),
'quit' => array(
'title' => 'Quit',
'subtitle' => 'Quit &amp; close Spotify',
'command' => 'quit'
),
'open' => array(
'title' => 'Open',
'subtitle' => 'Quit Spotify',
'command' => 'activate'
),
'mute' => array(
'title' => 'Toggle Mute/Unmute',
'subtitle' => 'Toggle between muting and unmuting',
'command' => 'mute.scpt'
),
'now' => array(
'title' => 'Show Current Track Information',
'subtitle' => 'Track, artist and album name',
'command' => 'return "Now Playing: " & name of current track & " by " & artist of current track & " on " & album of current track'
),
'album' => array(
'title' => 'Current Album Name',
'subtitle' => 'Show the current album name',
'command' => 'album.scpt'
),
'disc' => array(
'title' => 'Get Disc Number',
'subtitle' => 'Get the disk number of the curren track',
'command' => 'disc.scpt'
),
'artist' => array(
'title' => 'Current Artist',
'subtitle' => 'Show the current artist name',
'command' => 'artist.scpt'
),
'time' => array(
'title' => 'Show the Track\'s Duration',
'subtitle' => 'Get the total time of the current track',
'command' => 'duration.scpt'
),
'count' => array(
'title' => 'Total Plays',
'subtitle' => 'Show the total plays of the current track',
'command' => 'return "Play Count: " & (played count of current track as string)'
),
'track' => array(
'title' => 'Current Track',
'subtitle' => 'Show the name of the current track',
'command' => 'track.scpt'
),
'starred' => array(
'title' => 'Is This Starred?',
'subtitle' => 'Check if the current track is starred',
'command' => 'starred.scpt'
),
'popularity' => array(
'title' => 'Is This Popular?',
'subtitle' => 'Check the popularity of the current track',
'command' => 'return "Popularity: " & (popularity of current track as string) & " out of 100"'
),
'id' => array(
'title' => 'ID of Current Track',
'subtitle' => 'Get the Spotify ID of the current track',
'command' => 'set the clipboard to id of current track' . "\n" . 'return "ID: " & id of current track'
),
'url' => array(
'title' => 'Public URL of Current Track',
'subtitle' => 'Get the external Spotify URL of the current track',
'command' => 'url.scpt'
),
'appurl' => array(
'title' => 'Get Internal URL',
'subtitle' => 'Get the internal Spotify URL of the current track',
'command' => 'set the clipboard to spotify url of current track' . "\n" . 'return "Spotify URL: " & spotify url of current track'
),
'shuffle' => array(
'title' => 'Toggle Shuffle',
'subtitle' => 'Toggle shuffling',
'command' => 'shuffle.scpt'
),
'repeat' => array(
'title' => 'Toggle Repeat',
'subtitle' => 'Toggle repeating',
'command' => 'repeat.scpt'
),
'dev' => array(
'title' => 'Developer Information',
'subtitle' => 'Get the developer\'s information',
'command' => 'return "Jeff Johns | http://phpfunk.me | @phpfunk"'
),
'version' => array(
'title' => 'Get Application Version',
'subtitle' => 'Get the version of Spotify you are running',
'command' => 'set the clipboard to version' . "\n" . 'return "Spotfy Version: " & version'
),
'volume' => array(
'title' => 'Set Volume',
'subtitle' => 'Set the volume level (0 - 100)',
'command' => 'volume.scpt'
),
'app' => array(
'title' => 'Open a Spotify Application',
'subtitle' => 'Type the name of a Spotify application to open',
'command' => 'app.scpt'
),
'new' => array(
'title' => 'View New Releases',
'subtitle' => 'Browse Spotify new releases',
'bash' => 'open spotify:search:tag:new'
),
'help' => array(
'title' => 'Get Help',
'subtitle' => 'Read the help file for this workflow',
'bash' => 'open "https://github.com/phpfunk/alfred-spotify-controls/blob/master/README.md"'
)
);

$clones = array(
'prev' => '<',
'next' => '>',
'pause' => 'play',
'stop' => 'play',
'exit' => 'quit',
'kill' => 'quit',
'start' => 'open',
'init' => 'open',
'unmute' => 'mute',
'current' => 'now',
'i' => 'now',
'duration' => 'time',
'plays' => 'count',
'name' => 'track',
'song' => 'track',
'fav' => 'starred',
'rank' => 'popularity',
'?' => 'help'
);

foreach ($clones as $command => $parent) {
$commands[$command] = $commands[$parent];
}

ksort($commands);

0 comments on commit 59de824

Please sign in to comment.