Skip to content

Commit 500423d

Browse files
committed
Merge branch '2.2.2'
2 parents 7b35bc0 + 3563581 commit 500423d

File tree

9 files changed

+185
-54
lines changed

9 files changed

+185
-54
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: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?php
2+
3+
function __autoload($class)
4+
{
5+
require dirname(__FILE__) . '/libs/' . $class . '.php';
6+
}

incl/functions.php

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

libs/Releases.php

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
<?php
2+
3+
class Releases {
4+
5+
6+
public static function get($repo, $release, $user='phpfunk', $max_releases=5)
7+
{
8+
$releases = json_decode(Tools::fetch('https://api.github.com/repos/' . $user . '/' . $repo . '/tags'));
9+
$arr = array();
10+
11+
// If good-to-go, do it
12+
if (json_last_error() == JSON_ERROR_NONE && ! empty($releases) && ! isset($releases->message)) {
13+
foreach ($releases as $k => $obj) {
14+
$version = str_replace('.', '', $obj->name);
15+
if (is_numeric($version)) {
16+
$arr[$version] = $obj->name;
17+
}
18+
}
19+
krsort($arr);
20+
21+
$releases = array();
22+
$x = 1;
23+
$current = str_replace('.', '', $release);
24+
25+
foreach ($arr as $n => $release) {
26+
if ($x <= $max_releases) {
27+
28+
$title = 'Version ' . $release;
29+
if ($current > $n) {
30+
$subtitle = 'Downgrade to version ' . $release . '. (Ctrl+Enter to view this release)';
31+
}
32+
elseif ($current < $n) {
33+
$subtitle = 'Upgrade to version ' . $release . '. (Ctrl+Enter to view this release)';
34+
}
35+
else {
36+
$title .= ' (Current Version)';
37+
$subtitle = 'This is the version you are currently running.';
38+
}
39+
40+
array_push($releases, array(
41+
'uid' => $release,
42+
'arg' => $release,
43+
'title' => $title,
44+
'subtitle' => $subtitle,
45+
'icon' => 'icon.png',
46+
'autocomplete' => $release
47+
));
48+
$x += 1;
49+
}
50+
else {
51+
break;
52+
}
53+
}
54+
}
55+
else {
56+
$release = array();
57+
array_push($releases, array(
58+
'uid' => 'error',
59+
'arg' => 'error',
60+
'title' => 'Error',
61+
'subtitle' => 'There was an error extracting the releases from Github.',
62+
'icon' => 'icon.png',
63+
'autocomplete' => 'error'
64+
));
65+
}
66+
67+
if (! empty($releases)) {
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+
}
94+
}
95+
}

libs/Tools.php

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?php
2+
3+
class Tools {
4+
5+
public static function arrayToXML($a)
6+
{
7+
if (! is_array($a)) {
8+
return false;
9+
}
10+
11+
$items = new SimpleXMLElement("<items></items>");
12+
13+
foreach($a as $b) {
14+
$c = $items->addChild('item');
15+
$c_keys = array_keys($b);
16+
foreach($c_keys as $key) {
17+
if ($key == 'uid') {
18+
$c->addAttribute('uid', $b[$key]);
19+
}
20+
elseif ($key == 'arg') {
21+
$c->addAttribute('arg', $b[$key]);
22+
}
23+
else {
24+
$c->addChild($key, $b[$key]);
25+
}
26+
}
27+
}
28+
29+
return $items->asXML();
30+
}
31+
32+
public static function fetch($url)
33+
{
34+
$ch = curl_init($url);
35+
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
36+
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
37+
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
38+
curl_setopt($ch, CURLOPT_HTTPGET, 1);
39+
curl_setopt($ch, CURLOPT_USERAGENT, 'Easy Fetch by Jeff Johns @phpfunk');
40+
$page = curl_exec($ch);
41+
$info = curl_getinfo($ch);
42+
curl_close($ch);
43+
return ($info['http_code'] == '200') ? $page : null;
44+
}
45+
46+
public static function getTrackArtwork($type, $id)
47+
{
48+
$html = fetch('http://open.spotify.com/' . $type . '/' . $id);
49+
if (! empty($html)) {
50+
preg_match_all('/.*?og:image.*?content="(.*?)">.*?/is', $html, $m);
51+
return (isset($m[1][0])) ? $m[1][0] : '';
52+
}
53+
return '';
54+
}
55+
}

releases.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<?php
2+
include dirname(__FILE__) . '/autoload.php';
3+
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)