本文整理汇总了PHP中lastfmApi类的典型用法代码示例。如果您正苦于以下问题:PHP lastfmApi类的具体用法?PHP lastfmApi怎么用?PHP lastfmApi使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了lastfmApi类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: fopen
<?php
// Include the API
require '../../lastfmapi/lastfmapi.php';
// Get the session auth data
$file = fopen('../auth.txt', 'r');
// Put the auth data into an array
$authVars = array('apiKey' => trim(fgets($file)), 'secret' => trim(fgets($file)), 'username' => trim(fgets($file)), 'sessionKey' => trim(fgets($file)), 'subscriber' => trim(fgets($file)));
$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);
// Call for the album package class with auth data
$apiClass = new lastfmApi();
$artistClass = $apiClass->getPackage($auth, 'artist', $config);
// Setup the variables
$methodVars = array('artist' => 'Green Day');
if ($tags = $artistClass->getTags($methodVars)) {
echo '<b>Data Returned</b>';
echo '<pre>';
print_r($tags);
echo '</pre>';
} else {
die('<b>Error ' . $artistClass->error['code'] . ' - </b><i>' . $artistClass->error['desc'] . '</i>');
}
示例2: fopen
<?php
// Include the API
require '../../lastfmapi/lastfmapi.php';
// Get the session auth data
$file = fopen('../auth.txt', 'r');
// Put the auth data into an array
$authVars = array('apiKey' => trim(fgets($file)), 'secret' => trim(fgets($file)), 'username' => trim(fgets($file)), 'sessionKey' => trim(fgets($file)), 'subscriber' => trim(fgets($file)));
$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);
// Call for the album package class with auth data
$apiClass = new lastfmApi();
$albumClass = $apiClass->getPackage($auth, 'album', $config);
// Setup the variables
$methodVars = array('artist' => 'Green day', 'album' => 'Dookie', 'tags' => array('test', 'testing'));
// Call the method with the variables
if ($albumClass->addTags($methodVars)) {
// Method returned as a success
echo '<b>Tags added</b>';
} else {
// Method returned an error
die('<b>Error ' . $albumClass->error['code'] . ' - </b><i>' . $albumClass->error['desc'] . '</i>');
}
示例3: array
<?php
require 'config.php';
require 'class/lastfmapi/lastfmapi.php';
if (isset($_COOKIE['sessionkey']) && isset($_COOKIE['username']) && isset($_COOKIE['subscriber'])) {
$vars = array('apiKey' => $config['api_key'], 'secret' => $config['secret'], 'username' => $_COOKIE['username'], 'sessionKey' => $_COOKIE['sessionkey'], 'subscriber' => $_COOKIE['subscriber']);
$lastfmapi_auth = new lastfmApiAuth('setsession', $vars);
$lastfmapi = new lastfmApi();
$radioClass = $lastfmapi->getPackage($lastfmapi_auth, 'radio');
$methodVars = array();
if ($radio = $radioClass->getPlaylist($methodVars)) {
echo json_encode($radio);
} else {
echo 'error';
}
}
示例4: lastfmApiAuth
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with "Podes musikkmashup". If not, see <http://www.gnu.org/licenses/>.
Source code available from:
http://github.com/pode/musikkmashup/
*/
include_once '../config.php';
if (!$config['moduler']['artist']['aktiv']) {
exit;
}
include_once '../include/functions.php';
include_once '../lastfmapi/lastfmapi.php';
if (!empty($_GET['artist'])) {
$authVars['apiKey'] = $config['lastfm']['api_key'];
$auth = new lastfmApiAuth('setsession', $authVars);
$apiClass = new lastfmApi();
$artist = $apiClass->getPackage($auth, 'artist');
$methodVars = array('artist' => avinverter($_GET['artist']));
if ($art = $artist->getinfo($methodVars)) {
// Sjekk om det oppstod feil
if ($artist->error['code']) {
// Error: show which error and go no further.
echo '<b>Error ' . $artist->error['code'] . ' - </b><i>' . $artist->error['desc'] . '</i>';
exit;
}
if ($art['name']) {
echo '<p class="overskrift">' . $art['name'] . '</p>';
// Bilde
if ($art['image']['large']) {
echo '<p class="artistbilde"><img src="' . $art['image']['large'] . '" alt="' . $art['name'] . '" title="' . $art['name'] . '" /></p>';
}
示例5: lastfmApiAuth
<?php
// Include the header
include 'template/header.php';
// Check username was sent
if (!empty($_GET['username'])) {
// If so: carry no
// Include the API
require '../../lastfmapi/lastfmapi.php';
// Set the API key
$authVars['apiKey'] = 'fa3af76b9396d0091c9c41ebe3c63716';
// Pass the apiKey to the auth class to get a none fullAuth auth class
$auth = new lastfmApiAuth('setsession', $authVars);
// Call for the tasteometer package class with auth class
$apiClass = new lastfmApi();
$userClass = $apiClass->getPackage($auth, 'user');
// Create a list of tag's that we don't one
// Mainly ones that don't describe peoples musical taste
$badTags = array('good', 'seen live', 'favourite', 'favorites', 'favorite artists', 'favourite bands', 'favourites', 'want to see live', 'uk', 'whales', 'my music', 'amazing', 'awesome', 'english', 'fun', 'multiple artists under same name', 'a few of the bands ive seen', 'albums i own', 'music', 'rock gods');
// Setup the variables get get the users top artists
$methodVars = array('user' => $_GET['username']);
// Get the users top artist (with error check)
if ($artists = $userClass->getTopArtists($methodVars)) {
// Setup the results array
$results = array();
// Lopp through each of the users top artists
foreach ($artists as $artist) {
// Create an artists class to use
$artistClass = $apiClass->getPackage($auth, 'artist');
// Setup the variables for the artist call
$methodVars = array('artist' => $artist['name']);
示例6: getLovedTracksFor
static function getLovedTracksFor($lastFMUserName)
{
$strippedUserName = $lastFMUserName;
$strippedUserName = preg_replace("/[^a-zA-Z0-9]/", "", $strippedUserName);
if (strlen($strippedUserName) > 0) {
$myCache = new Caching("./MashupCache/LovedTracks/", $strippedUserName);
$tempLastFMAPI = new lastfmApi();
$tempLastFMAuthority = new lastfmApiAuth('setsession', musicCollection::$lastFMVariables);
$lastFMUser = $tempLastFMAPI->getPackage($tempLastFMAuthority, 'user', musicCollection::$lastFMConfig);
// Setup the variables
$methodVars = array('user' => $lastFMUserName);
if ($myCache->needToRenewData()) {
try {
// result is an array not a simpleXML Object
$result = $lastFMUser->getLovedTracks($methodVars);
} catch (Exception $e) {
echo $e->getMessage();
}
$reformatedResult = serialize($result);
$myCache->saveSerializedDataToFile($reformatedResult);
} else {
// It doesn't need to be renewed so use local copy of array
$result = $myCache->getUnserializedData();
}
}
return $result;
}
示例7: getMusic
function getMusic($music, $id, $band_id)
{
$authVars = array('apiKey' => '13846fb92c539b877ff2abc79ede2718', 'secret' => 'ce4450255eb766372b130f0784c15087', 'username' => 'hilkeros', 'sessionKey' => '671bbefd4f15d3ed2fdf524dea62212b', 'subscriber' => 0);
$auth = new lastfmApiAuth('setsession', $authVars);
$apiClass = new lastfmApi();
$artistClass = $apiClass->getPackage($auth, 'artist');
$trackClass = $apiClass->getPackage($auth, 'track');
$albumClass = $apiClass->getPackage($auth, 'album');
if ($music) {
$methodVars = array('artist' => $music);
$this->etime = time();
if ($artist = $artistClass->getInfo($methodVars)) {
$stat['Lfm']['url'] = $artist['url'];
$stat['Lfm']['lfm_m_id'] = $id;
$stat['Lfm']['executetime'] = $this->etime;
$stat['Lfm']['band_id'] = $band_id;
$this->Lfm->save($stat);
$stat = NULL;
$stat['Lfmlistener']['lfm_m_id'] = $id;
$stat['Lfmlistener']['listeners'] = $artist['stats']['listeners'];
$stat['Lfmlistener']['etime'] = $this->etime;
$this->Lfmlistener->create();
$this->Lfmlistener->save($stat);
}
if ($albums = $artistClass->getTopAlbums($methodVars)) {
foreach ($albums as $key => $val) {
$methodAlbumVars = array('artist' => $music, 'album' => $val['name'], 'mbid' => $val['mbid']);
if ($topAlbum = $albumClass->getinfo($methodAlbumVars)) {
$alb['Lfmalbum']['rank'] = $val['rank'];
$alb['Lfmalbum']['name'] = $val['name'];
$alb['Lfmalbum']['playcount'] = $topAlbum['playcount'];
$alb['Lfmalbum']['lfm_m_id'] = $id;
$alb['Lfmalbum']['etime'] = $this->etime;
$this->Lfmalbum->create();
$this->Lfmalbum->save($alb);
}
/* $qry = "insert into lfm_top_album(stat_id , rank , name , playcount) values ($stat_id,$rank,'$name',$playcount)";
$result = mysql_query($qry);
*/
// $TopAlbumCount ++ ;
}
}
if ($tracks = $artistClass->getTopTracks($methodVars)) {
foreach ($tracks as $key => $val) {
$methodTrackVars = array('artist' => $music, 'track' => $val['name']);
if ($toptrack = $trackClass->getinfo($methodTrackVars)) {
$trk['Lfmtrack']['lfm_m_id'] = $id;
$trk['Lfmtrack']['rank'] = $val['rank'];
$trk['Lfmtrack']['name'] = $val['name'];
$trk['Lfmtrack']['playcount'] = $toptrack['playcount'];
$trk['Lfmtrack']['etime'] = $this->etime;
$this->Lfmtrack->create();
$this->Lfmtrack->save($trk);
}
/*
$qry = "insert into lfm_top_tracks(stat_id , rank , name , playcount) values ($stat_id,$rank,'$name',$playcount)";
$result = mysql_query($qry);
*/
}
// foreach($tracks as $key => $val)
}
return true;
}
// if($music)
}
示例8: index
function index()
{
$program_start_time = microtime(true);
$this->etime = time();
$authVars = array('apiKey' => '13846fb92c539b877ff2abc79ede2718', 'secret' => 'ce4450255eb766372b130f0784c15087', 'username' => 'hilkeros', 'sessionKey' => '671bbefd4f15d3ed2fdf524dea62212b', 'subscriber' => 0);
$auth = new lastfmApiAuth('setsession', $authVars);
$apiClass = new lastfmApi();
$artistClass = $apiClass->getPackage($auth, 'artist');
$trackClass = $apiClass->getPackage($auth, 'track');
$albumClass = $apiClass->getPackage($auth, 'album');
$result = $this->Lfm->findAll();
if ($result) {
foreach ($result as $key => $lfmdata) {
$ptime = $lfmdata['Lfm']['executetime'];
if (date('Ymd', $ptime) != date('Ymd')) {
if ($lfmdata['Lfm']['music_group']) {
$methodVars = array('artist' => $lfmdata['Lfm']['music_group']);
// if($lfmdata['Lfm']['music_group'])
if ($artist = $artistClass->getInfo($methodVars)) {
// Update lfm_music table
$record['Lfm']['lfm_m_id'] = $lfmdata['Lfm']['lfm_m_id'];
$record['Lfm']['url'] = $artist['url'];
$record['Lfm']['executetime'] = $this->etime;
$this->Lfm->save($record);
$record = NULL;
// Insert latest listeners & time into lfmlisteners table
$record['Lfmlistener']['lfm_m_id'] = $lfmdata['Lfm']['lfm_m_id'];
$record['Lfmlistener']['listeners'] = $artist['stats']['listeners'];
$record['Lfmlistener']['etime'] = $this->etime;
$this->Lfmlistener->create();
$this->Lfmlistener->save($record);
$record = NULL;
//} // if($record)
}
// if ( $artist = $artistClass->getInfo($methodVars) )
if ($albums = $artistClass->getTopAlbums($methodVars)) {
foreach ($albums as $key => $val) {
$methodAlbumVars = array('artist' => $lfmdata['Lfm']['music_group'], 'album' => $val['name'], 'mbid' => $val['mbid']);
if ($topAlbum = $albumClass->getinfo($methodAlbumVars)) {
// Insert values into lfm_top_album table
$record['Lfmalbum']['lfm_m_id'] = $lfmdata['Lfm']['lfm_m_id'];
$record['Lfmalbum']['rank'] = $val['rank'];
$record['Lfmalbum']['name'] = $val['name'];
$record['Lfmalbum']['playcount'] = $topAlbum['playcount'];
$record['Lfmalbum']['etime'] = $this->etime;
$this->Lfmalbum->create();
$this->Lfmalbum->save($record);
$record = NULL;
}
}
// foreach($albums as $key => $val)
}
// if ( $albums = $artistClass->getTopAlbums($methodVars) ) {
if ($tracks = $artistClass->getTopTracks($methodVars)) {
foreach ($tracks as $key => $val) {
$methodTrackVars = array('artist' => $lfmdata['Lfm']['music_group'], 'track' => $val['name']);
if ($toptrack = $trackClass->getinfo($methodTrackVars)) {
// Insert values into lfm_top_tracks
$record['Lfmtrack']['lfm_m_id'] = $lfmdata['Lfm']['lfm_m_id'];
$record['Lfmtrack']['name'] = $val['name'];
$record['Lfmtrack']['rank'] = $val['rank'];
$record['Lfmtrack']['playcount'] = $toptrack['playcount'];
$record['Lfmtrack']['etime'] = $this->etime;
$this->Lfmtrack->create();
$this->Lfmtrack->save($record);
$record = NULL;
}
}
// foreach($tracks as $key => $val)
}
// if ( $tracks = $artistClass->getTopTracks($methodVars) ) {
}
// $lfmdata['Lfm']['music_group'
}
// if(date('Ymd',$ptime)!=date('Ymd'))
}
// foreach($result as $key => $lfmdata)
}
// if($result)
echo "Total execution time : " . (microtime(true) - $program_start_time) . " seconds<br />";
exit;
}
示例9: getInfo
public function getInfo(SSLTrack $track)
{
$vars = array();
$vars['apiKey'] = $this->config['api_key'];
$vars['secret'] = $this->config['api_secret'];
$auth = new lastfmApiAuth('setsession', $vars);
$lfm = new lastfmApi();
/* @var $trackP lastfmApiTrack */
/* @var $artistP lastfmApiArtist */
$trackP = $lfm->getPackage($auth, 'track');
$artistP = $lfm->getPackage($auth, 'artist');
//$track_info = $trackP->getInfo(array('artist' => $track->getArtist(), 'title' => $track->getTitle()));
$artist_info = $artistP->getInfo(array('artist' => $track->getArtist()));
$artist_images = $artistP->getImages(array('artist' => $track->getArtist()));
$all = array('artist' => $artist_info, 'images' => $artist_images);
return $all;
}