-
Notifications
You must be signed in to change notification settings - Fork 0
/
api.php.orig
215 lines (177 loc) · 4.8 KB
/
api.php.orig
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
<?php
require_once 'rdio-consumer-credentials.php' ;
require_once 'om.php';
require_once 'rdio.php';
$playback_token = "GBNQZzz3ACojA3J0ZHg0ZDZmcnBjY2syZWo4cXE2dTVjamxhYnMuZGllbWV0YWxsZS5jb22IqHrPSpIrOKtc7w7odJpI";
$rdio = authenticate();
<<<<<<< HEAD
//setUp();
//print getPlaybackToken(true);
//print json_encode(get_object_vars(getPlaybackToken(true)), true);
//print getSongQueue();
if(isset($_GET['command']))
{
getRouter();
}
=======
//print json_encode(get_object_vars(search("ellie goulding", "lights")), true);
//echo json_encode(array("returnValue"=>"Yay!"));
>>>>>>> 2a60cf60b53c3717b8cc5d39c70b7ddc6ed8a084
if(isset($_POST['command']))
{
//echo json_encode(array("returnValue"=>"Yay!"));
router();
}
function authenticate()
{
session_start();
# create an instance of the Rdio object with our consumer credentials
$rdio = new Rdio(array(RDIO_CONSUMER_KEY, RDIO_CONSUMER_SECRET));
# work out what our current URL is
$current_url = "http" . ((!empty($_SERVER['HTTPS'])) ? "s" : "") .
"://" . $_SERVER['SERVER_NAME'].$_SERVER['SCRIPT_NAME'];
if ($_SESSION['oauth_token'] && $_SESSION['oauth_token_secret']) {
# we have a token in our session, let's use it
$rdio->token = array($_SESSION['oauth_token'],
$_SESSION['oauth_token_secret']);
if ($_GET['oauth_verifier']) {
# we've been passed a verifier, that means that we're in the middle of
# authentication.
$rdio->complete_authentication($_GET['oauth_verifier']);
# save the new token in our session
$_SESSION['oauth_token'] = $rdio->token[0];
$_SESSION['oauth_token_secret'] = $rdio->token[1];
}
# make sure that we can in fact make an authenticated call
$currentUser = $rdio->call('currentUser');
if ($currentUser) {
/*
?><h1><?=$currentUser->result->firstName?>'s Playlists</h1>
<ul><?
$myPlaylists = $rdio->call('getPlaylists')->result->owned;
# list them
foreach ($myPlaylists as $playlist) {
?><li><a href="<?= $playlist->shortUrl?>"><?=$playlist->name?></a></li><?
}
?></ul><a href="?logout=1">Log out.</a><?
*/
} else {
# auth failure, clear session
session_destroy();
# and start again
//return json_encode(new array(success => false));
}
} else {
# we have no authentication tokens.
# ask the user to approve this app
$authorize_url = $rdio->begin_authentication($current_url);
# save the new token in our session
$_SESSION['oauth_token'] = $rdio->token[0];
$_SESSION['oauth_token_secret'] = $rdio->token[1];
header('Location: '.$authorize_url);
}
return $rdio;
}
function router()
{
$command = $_POST['command'];
switch($command){
case ('getPlaybackToken'):
return getPlaybackToken(false);
break;
case ('search'):
return search($_POST['keyword']);
break;
<<<<<<< HEAD
case ('songQueue'):
print getSongQueue();
break;
case ('getCurrentlyPlayingSong'):
print getNowPlayingInterface();
break;
default:
break;
}
}
function getRouter()
{
$command = $_GET['command'];
switch($command){
case ('getPlaybackToken'):
return getPlaybackToken(false);
break;
case ('search'):
return search($_GET['keyword']);
break;
case ('songQueue'):
print getSongQueue();
break;
case ('getCurrentlyPlayingSong'):
print getNowPlayingInterface();
break;
=======
>>>>>>> 2a60cf60b53c3717b8cc5d39c70b7ddc6ed8a084
default:
break;
}
}
function getPlaybackToken($new)
{
global $rdio, $playback_token;
if ($new){
$key = $rdio->call('getPlaybackToken', array("domain" => "labs.diemetalle.com"));
$playback_token = $key->result;
return $playback_token;
} else {
return $playback_token;
}
}
function getPlaylist()
{
global $rdio;
$playlist = reset($rdio->call('getPlaylists')->result->owned);
if($playlist != null){
return $playlist;
} else {
return createPlaylist();
}
}
function createPlaylist()
{
global $rdio;
$playlist = $rdio->call('createPlaylist', array(
"name"=>"default",
"description" => "default playlist",
"tracks" => ""));
return $playlist;
}
<<<<<<< HEAD
function removePlayedSong()
{
}
function getNowPlayingInterface()
{
return json_encode(get_object_vars(getNowPlaying()), true);
}
function getNowPlaying()
{
$playlist = getPlaylist("tracks");
$song = reset($playlist->tracks);
return $song;
}
=======
>>>>>>> 2a60cf60b53c3717b8cc5d39c70b7ddc6ed8a084
function search($key)
{
global $rdio;
if($key)
{
$results = $rdio->call('search', array("query" => $key, "types" => "Artist, Track"));
echo json_encode(array("returnValue"=>$results));
}
else
{
echo json_encode(array("returnValue"=>""));
}
}
?>