Skip to content

Commit 3563581

Browse files
committed
Added support for automatic updates
Updated readme file Updated Spotify extension Added an autoloader Added new code libraries Updated search to use these new libraries Added an update and releases file
1 parent 2b2c201 commit 3563581

File tree

8 files changed

+59
-35
lines changed

8 files changed

+59
-35
lines changed

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ If you are looking for the Spotify Extension for Alfred Version 1, you can find
88

99
To install Spotify Controls in Alfred double click on `Spotify.alfredworkflow` or drag the workflow to the workflow window in Alfred.
1010

11+
## Using automatic updates
12+
The auto-updater is baked just for this extension. It will ping Github and get the last 5 releases of this extension. You can easily press `Enter` to install a new version, or downgrade to an older version. If you would like to view the release first, simply `Control + Enter` to be taken directly to the release page on Github. Yep that's it. No more downloading squat from here.
13+
1114
## Hotkeys
1215
Version 2.2.1 introduced the use of Hotkeys to invoke certain actions. All hotkeys are customizable in the workflow.
1316

@@ -52,6 +55,7 @@ spot repeat :: Toggle repeat (only available in 0.8.0 or above)
5255
spot help :: Open this help file
5356
spot dev :: My info
5457
spot clear :: Clears any artwork cache from you HDD
58+
spot update :: Gets the last 5 releases of the extension, enter to install, ctrl+enter to view release
5559
5660
Commands that also send a notification
5761
spot now :: Current track name, artist, album and duration (can also use i or current)
@@ -96,6 +100,7 @@ $ spot repeat
96100
$ spot help
97101
$ spot dev
98102
$ spot version
103+
$ spot update
99104
```
100105

101106
## Searching using the Hotkey (default to Command + Return)
@@ -135,6 +140,10 @@ Instead it calls out to the actual Spotify URL and scrapes the image from the pa
135140
### Creating a Radio Station from the current track
136141
Easy, just press the Hotkey command of `Option + Command + R` and the workflow will create a Spotify radio station from the current track playing. The Hotkey can be customized in the workflow to anything you would like.
137142

143+
144+
### Using automatic updates
145+
The auto-updater is baked just for this extension. It will ping Github and get the last 5 releases of this extension. You can easily press `Enter` to install a new version, or downgrade to an older version. If you would like to view the release first, simply `Control + Enter` to be taken directly to the release page on Github. Yep that's it. No more downloading squat from here.
146+
138147
## Contributors
139148

140149
* [Jeff Johns](https://github.com/phpfunk)
@@ -148,6 +157,11 @@ Easy, just press the Hotkey command of `Option + Command + R` and the workflow w
148157

149158
## Version History
150159

160+
### 2.2.2 - July 7, 2013
161+
* Added support for automatic updates
162+
* Updated Spotify icon
163+
* Updated codebase a bit
164+
151165
### 2.2.1 - July 3, 2013
152166
* Added hotkey support for searching
153167
* Added hotkey support for creating custom radio stations

Spotify.alfredworkflow

-4.55 KB
Binary file not shown.

autoload.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22

33
function __autoload($class)
44
{
5-
require 'libs/' . $class . '.php';
5+
require dirname(__FILE__) . '/libs/' . $class . '.php';
66
}

libs/Releases.php

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,22 @@ public static function get($repo, $release, $user='phpfunk', $max_releases=5)
2323
$current = str_replace('.', '', $release);
2424

2525
foreach ($arr as $n => $release) {
26-
if ($x < $max_releases) {
26+
if ($x <= $max_releases) {
2727

2828
$title = 'Version ' . $release;
2929
if ($current > $n) {
30-
$subtitle = 'Downgrade to version ' . $release . '. (Ctrl+Enter to view release)';
30+
$subtitle = 'Downgrade to version ' . $release . '. (Ctrl+Enter to view this release)';
3131
}
3232
elseif ($current < $n) {
33-
$subtitle = 'Upgrade to version ' . $release . '. (Ctrl+Enter to view release)';
33+
$subtitle = 'Upgrade to version ' . $release . '. (Ctrl+Enter to view this release)';
3434
}
3535
else {
3636
$title .= ' (Current Version)';
3737
$subtitle = 'This is the version you are currently running.';
3838
}
3939

4040
array_push($releases, array(
41+
'uid' => $release,
4142
'arg' => $release,
4243
'title' => $title,
4344
'subtitle' => $subtitle,
@@ -54,6 +55,7 @@ public static function get($repo, $release, $user='phpfunk', $max_releases=5)
5455
else {
5556
$release = array();
5657
array_push($releases, array(
58+
'uid' => 'error',
5759
'arg' => 'error',
5860
'title' => 'Error',
5961
'subtitle' => 'There was an error extracting the releases from Github.',
@@ -63,7 +65,31 @@ public static function get($repo, $release, $user='phpfunk', $max_releases=5)
6365
}
6466

6567
if (! empty($releases)) {
66-
print Tools::arrayToXML($releases);
67-
}
68+
print Tools::arrayToXML($releases);
69+
}
70+
}
71+
72+
public static function update($release)
73+
{
74+
$user_folder = explode('/', dirname(__FILE__));
75+
$user_folder = '/' . $user_folder[1] . '/' . $user_folder[2];
76+
$dl_locale = $user_folder . '/Downloads/Spotify.alfredworkflow';
77+
$workflow = 'https://github.com/phpfunk/alfred-spotify-controls/raw/' . $release . '/Spotify.alfredworkflow';
78+
$file = fopen($dl_locale, 'w');
79+
$ch = curl_init();
80+
curl_setopt($ch, CURLOPT_URL, $workflow);
81+
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
82+
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
83+
curl_setopt($ch, CURLOPT_FILE, $file);
84+
curl_exec($ch);
85+
curl_close($ch);
86+
fclose($file);
87+
88+
if (! file_exists($dl_locale)) {
89+
print 'Sorry, could NOT download the update :(';
90+
}
91+
else {
92+
shell_exec('open "' . $dl_locale . '"');
93+
}
6894
}
6995
}

libs/Spotify.php

Lines changed: 0 additions & 23 deletions
This file was deleted.

releases.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
<?php
2-
include 'autoload.php';
2+
include dirname(__FILE__) . '/autoload.php';
33
Releases::get('alfred-spotify-controls', '2.2.2');

search.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<?php
2-
include_once 'incl/functions.php';
3-
2+
include dirname(__FILE__) . '/autoload.php';
43
$query = $argv[2];
54
$show_images = (isset($argv[1]) && trim(strtolower($argv[1])) == 'yes') ? true : false;
65
$tmp = explode(' ', $query);
@@ -16,7 +15,7 @@
1615
exit(1);
1716
}
1817

19-
$json = fetch('http://ws.spotify.com/search/1/' . $type . '.json?q=' . urlencode($query));
18+
$json = Tools::fetch('http://ws.spotify.com/search/1/' . $type . '.json?q=' . urlencode($query));
2019
$results = array();
2120

2221
if (! empty($json)) {
@@ -47,7 +46,7 @@
4746
$thumb_path = $thumbs_path . '/' . $track_id . '.png';
4847

4948
if (! file_exists($thumb_path)) {
50-
$artwork = getTrackArtwork($type, $track_id);
49+
$artwork = Tools::getTrackArtwork($type, $track_id);
5150
if (! empty($artwork)) {
5251
shell_exec('curl -s ' . $artwork . ' -o ' . $thumb_path);
5352
}
@@ -74,5 +73,5 @@
7473
}
7574
}
7675

77-
print arrayToXML($results);
76+
print Tools::arrayToXML($results);
7877
}

update.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
include dirname(__FILE__) . '/autoload.php';
3+
if (isset($argv[1]) && ! empty($argv[1])) {
4+
Releases::update(trim($argv[1]));
5+
}
6+
else {
7+
print 'Could NOT find correct release to download and install';
8+
}

0 commit comments

Comments
 (0)