-
Notifications
You must be signed in to change notification settings - Fork 0
/
GetTopTracks1.php
123 lines (106 loc) · 3.68 KB
/
GetTopTracks1.php
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
<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<html>
<head>
<title>Top Tracks</title>
</head>
<body>
<?php
session_start();
echo "The selected user name is: ".$_SESSION["username"];
// Include the API
require 'lastfmapi/lastfmapi.php';
// Put the auth data into an array
$authVars = array(
'apiKey' => 'c8f21998ab06ac98bf163a9223592a82',
'secret' => '76092b16a23a0160bd29ee42e9339fdb',
'username' => 'dakshinai',
'sessionKey' => 'test',
'subscriber' => 'dakshinai'
);
$config = array(
'enabled' => true,
'path' => 'lastfmapi/',
'cache_length' => 1800
);
// Pass the array to the auth class to eturn a valid auth
$auth = new lastfmApiAuth('setsession', $authVars);
$apiClass = new lastfmApi();
$userClass = $apiClass->getPackage($auth, 'user', $config);
// Setup the variables
$methodVars = array(
'user' => $_SESSION["username"]
);
//if ($_GET['q'] && $_GET['maxResults']) {
// Call set_include_path() as needed to point to your client library.
require_once 'google-api-php-client-0.6.7/google-api-php-client/src/Google_Client.php';
require_once 'google-api-php-client-0.6.7/google-api-php-client/src/contrib/Google_YouTubeService.php';
/* Set $DEVELOPER_KEY to the "API key" value from the "Access" tab of the
Google APIs Console <http://code.google.com/apis/console#access>
Please ensure that you have enabled the YouTube Data API for your project. */
$DEVELOPER_KEY = 'AIzaSyCsfz-K3dcECSBoyn-eYn0d3p2y3vdh6Ds';
$client = new Google_Client();
$client->setDeveloperKey($DEVELOPER_KEY);
$youtube = new Google_YoutubeService($client);
if ( $tracks = $userClass->getTopTracks($methodVars) ) {
//echo '<b>Data Returned</b>';
//echo '<pre>';
//print_r($tracks);
//echo '</pre>';?>
<?php foreach ($tracks as $track) { ?>
<p>
Title: <?= $track['name'] ?><br />
Artist: <?= $track['artist']['name'] ?><br />
link: <a href=<?= $track['url']?>>LINK </a> <br/>
<?php try {
$searchResponse = $youtube->search->listSearch('id,snippet', array(
'q' => $track['name'],
'maxResults' => 1,
));
$videos = '';
$channels = '';
$playlists = '';
foreach ($searchResponse['items'] as $searchResult) {
switch ($searchResult['id']['kind']) {
case 'youtube#video':
$videos .= sprintf('<li>%s (%s)</li>', $searchResult['snippet']['title'],
$searchResult['id']['videoId']);
$url=('//www.youtube.com/embed/'.$searchResult['id']['videoId']);
// print_r($url);
break;
case 'youtube#channel':
$channels .= sprintf('<li>%s (%s)</li>', $searchResult['snippet']['title'],
$searchResult['id']['channelId']);
$url=('//www.youtube.com/embed/'.$searchResult['id']['channelId']);
// print_r($url);
break;
case 'youtube#playlist':
$playlists .= sprintf('<li>%s (%s)</li>', $searchResult['snippet']['title'],
$searchResult['id']['playlistId']);
break;
}
}
} catch (Google_ServiceException $e) {
$htmlBody .= sprintf('<p>A service error occurred: <code>%s</code></p>',
htmlspecialchars($e->getMessage()));
} catch (Google_Exception $e) {
$htmlBody .= sprintf('<p>An client error occurred: <code>%s</code></p>',
htmlspecialchars($e->getMessage()));
}?>
<form action="youtubevideo.php" method="post">
<input type="hidden" name="xx" value=<?=$url?>/>
<input type="submit" value="youtube video!"/>
</form>
</p>
<?php }
}
else {
die('<b>Error '.$userClass->error['code'].' - </b><i>'.$userClass->error['desc'].'</i>');
}
?>
</body>
</html>