Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Playlist search! #88

Merged
merged 20 commits into from
Jun 4, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
can now play playlists, though you see all of them and can't update
  • Loading branch information
citelao committed Mar 19, 2017
commit 82925b7886b62bbbd113be05e7dd8c30f43478c9
4 changes: 2 additions & 2 deletions callback.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
$success = !array_key_exists('error', $_GET);

if($success) {
$session->requestToken($_GET['code']);
$session->requestAccessToken($_GET['code']);

// Save the tokens
$alfred->options("spotify_access_token", $session->getAccessToken());
$alfred->options("spotify_refresh_token", $session->getRefreshToken());
$alfred->options("spotify_access_token_expires", time() + $session->getExpires());
$alfred->options("spotify_access_token_expires", time() + $session->getTokenExpiration());

$alfred->options('registered_scopes', $alfred->options('desired_scopes'));
}
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
}
},
"require": {
"jwilsson/spotify-web-api-php": "0.6.*"
"jwilsson/spotify-web-api-php": "^1.0.0"
}
}
26 changes: 14 additions & 12 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 9 additions & 1 deletion src/citelao/OhAlfred/OhAlfred.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,15 @@ public function plist($plist, $setting, $value = -1) {
// Uncache plist on write
unset($this->plists[$plist]);

return exec("defaults write '$plist' '$setting' '$value'");
if(!is_string($value)) {
$value = '"' . str_replace('"', '\"', str_replace('\"', '\\\"', json_encode($value))) . '"';
}

$escaped_plist = escapeshellarg($plist);
$escaped_setting = escapeshellarg($setting);
$escaped_value = escapeshellarg($value);
// print("defaults write $escaped_plist $escaped_setting $escaped_value");
return exec("defaults write $escaped_plist $escaped_setting $escaped_value");
}

// Read the workflow .plist file.
Expand Down
19 changes: 19 additions & 0 deletions src/citelao/Spotifious/Menus/Search.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,21 @@ public function __construct($query, $alfred, $api) {
}
}

// Add playlists to result
$playlists_json = $this->alfred->options('playlists');
if($playlists_json !== '') {
$playlists = json_decode($playlists_json);

foreach ($playlists as $playlist) {
$this->search[] = array(
'type' => 'playlist',
'uri' => $playlist->uri,
'title' => $playlist->name,
'popularity' => 0
);
}
}

if(!empty($this->search))
usort($this->search, array($this, 'popularitySort'));
}
Expand All @@ -130,6 +145,10 @@ public function output() {
$valid = true;
$arg = "spotify⟩play track \"{$current['uri']}\"";
$autocomplete = '';
} else if($current['type'] == 'playlist') {
$valid = true;
$arg = "spotify⟩play track \"{$current['uri']}\"";
$autocomplete = '';
} else {
$valid = false;
$arg = '';
Expand Down
2 changes: 1 addition & 1 deletion src/citelao/Spotifious/Menus/Setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function output() {
if($this->applicationPreviouslyLinked) {
$results[] = array(
'title' => '3. Relink your Spotify application',
'subtitle' => "We've added new features to Spotifious, but you need to login to your Spotify app again.",
'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⟩',
'valid' => $this->applicationCreated ? true : false
Expand Down
24 changes: 20 additions & 4 deletions src/citelao/Spotifious/Spotifious.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ public function run($query) {
$this->alfred->options('track_notifications', 'true');
}

if($this->alfred->options('desired_scopes') != '') {
$this->alfred->options('desired_scopes', '');
$scopes = 'playlist-read-private';
if($this->alfred->options('desired_scopes') != $scopes) {
$this->alfred->options('desired_scopes', $scopes);
}

if($this->alfred->options('lookup_current_song') == '') {
Expand Down Expand Up @@ -86,6 +87,21 @@ public function run($query) {
// attempt refresh
// if failed, prompt for relogin

// Fetch playlists on a first run...
if($api && $this->alfred->options('playlists') == '') {
$playlists = $api->getMyPlaylists();
$search_data = array();
foreach ($playlists->items as $playlist) {
$search_data[] = array(
'id' => $playlist->id,
'name' => $playlist->name,
'uri' => $playlist->uri
);
}
// print_r($search_data);
$this->alfred->options('playlists', $search_data);
}

if (mb_strlen($query) <= 3) {
if(mb_strlen($query) > 0 && ($query[0] == "c" || $query[0] == "C")) {
$menu = new Control($query);
Expand Down Expand Up @@ -336,9 +352,9 @@ protected function getSpotifyApi() {
if ($this->alfred->options('spotify_access_token_expires') < time()) {
$session = new Session($this->alfred->options('spotify_client_id'), $this->alfred->options('spotify_secret'), 'http:https://localhost:11114/callback.php');
$session->setRefreshToken($this->alfred->options('spotify_refresh_token'));
$session->refreshToken();
$session->refreshAccessToken();

$this->alfred->options('spotify_access_token_expires', time() + $session->getExpires());
$this->alfred->options('spotify_access_token_expires', time() + $session->getTokenExpiration());
$this->alfred->options('spotify_access_token', $session->getAccessToken());
}

Expand Down
2 changes: 1 addition & 1 deletion vendor/autoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

// autoload.php @generated by Composer

require_once __DIR__ . '/composer' . '/autoload_real.php';
require_once __DIR__ . '/composer/autoload_real.php';

return ComposerAutoloaderInitd7270918ba4f2fa5e6e70be71bc482ee::getLoader();
88 changes: 73 additions & 15 deletions vendor/composer/ClassLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@
namespace Composer\Autoload;

/**
* ClassLoader implements a PSR-0 class loader
*
* See https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-0.md
* ClassLoader implements a PSR-0, PSR-4 and classmap class loader.
*
* $loader = new \Composer\Autoload\ClassLoader();
*
Expand All @@ -39,6 +37,8 @@
*
* @author Fabien Potencier <[email protected]>
* @author Jordi Boggiano <[email protected]>
* @see http:https://www.php-fig.org/psr/psr-0/
* @see http:https://www.php-fig.org/psr/psr-4/
*/
class ClassLoader
{
Expand All @@ -53,6 +53,9 @@ class ClassLoader

private $useIncludePath = false;
private $classMap = array();
private $classMapAuthoritative = false;
private $missingClasses = array();
private $apcuPrefix;

public function getPrefixes()
{
Expand Down Expand Up @@ -145,7 +148,7 @@ public function add($prefix, $paths, $prepend = false)
* appending or prepending to the ones previously set for this namespace.
*
* @param string $prefix The prefix/namespace, with trailing '\\'
* @param array|string $paths The PSR-0 base directories
* @param array|string $paths The PSR-4 base directories
* @param bool $prepend Whether to prepend the directories
*
* @throws \InvalidArgumentException
Expand Down Expand Up @@ -248,6 +251,47 @@ public function getUseIncludePath()
return $this->useIncludePath;
}

/**
* Turns off searching the prefix and fallback directories for classes
* that have not been registered with the class map.
*
* @param bool $classMapAuthoritative
*/
public function setClassMapAuthoritative($classMapAuthoritative)
{
$this->classMapAuthoritative = $classMapAuthoritative;
}

/**
* Should class lookup fail if not found in the current class map?
*
* @return bool
*/
public function isClassMapAuthoritative()
{
return $this->classMapAuthoritative;
}

/**
* APCu prefix to use to cache found/not-found classes, if the extension is enabled.
*
* @param string|null $apcuPrefix
*/
public function setApcuPrefix($apcuPrefix)
{
$this->apcuPrefix = function_exists('apcu_fetch') && ini_get('apc.enabled') ? $apcuPrefix : null;
}

/**
* The APCu prefix in use, or null if APCu caching is not enabled.
*
* @return string|null
*/
public function getApcuPrefix()
{
return $this->apcuPrefix;
}

/**
* Registers this instance as an autoloader.
*
Expand Down Expand Up @@ -290,26 +334,34 @@ public function loadClass($class)
*/
public function findFile($class)
{
// work around for PHP 5.3.0 - 5.3.2 https://bugs.php.net/50731
if ('\\' == $class[0]) {
$class = substr($class, 1);
}

// class map lookup
if (isset($this->classMap[$class])) {
return $this->classMap[$class];
}
if ($this->classMapAuthoritative || isset($this->missingClasses[$class])) {
return false;
}
if (null !== $this->apcuPrefix) {
$file = apcu_fetch($this->apcuPrefix.$class, $hit);
if ($hit) {
return $file;
}
}

$file = $this->findFileWithExtension($class, '.php');

// Search for Hack files if we are running on HHVM
if ($file === null && defined('HHVM_VERSION')) {
if (false === $file && defined('HHVM_VERSION')) {
$file = $this->findFileWithExtension($class, '.hh');
}

if ($file === null) {
if (null !== $this->apcuPrefix) {
apcu_add($this->apcuPrefix.$class, $file);
}

if (false === $file) {
// Remember that this class does not exist.
return $this->classMap[$class] = false;
$this->missingClasses[$class] = true;
}

return $file;
Expand All @@ -322,9 +374,13 @@ private function findFileWithExtension($class, $ext)

$first = $class[0];
if (isset($this->prefixLengthsPsr4[$first])) {
foreach ($this->prefixLengthsPsr4[$first] as $prefix => $length) {
if (0 === strpos($class, $prefix)) {
foreach ($this->prefixDirsPsr4[$prefix] as $dir) {
$subPath = $class;
while (false !== $lastPos = strrpos($subPath, '\\')) {
$subPath = substr($subPath, 0, $lastPos);
$search = $subPath.'\\';
if (isset($this->prefixDirsPsr4[$search])) {
foreach ($this->prefixDirsPsr4[$search] as $dir) {
$length = $this->prefixLengthsPsr4[$first][$search];
if (file_exists($file = $dir . DIRECTORY_SEPARATOR . substr($logicalPathPsr4, $length))) {
return $file;
}
Expand Down Expand Up @@ -373,6 +429,8 @@ private function findFileWithExtension($class, $ext)
if ($this->useIncludePath && $file = stream_resolve_include_path($logicalPathPsr0)) {
return $file;
}

return false;
}
}

Expand Down
21 changes: 21 additions & 0 deletions vendor/composer/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@

Copyright (c) Nils Adermann, Jordi Boggiano

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is furnished
to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

Loading