/** * getLovedSongs() * Gets user's loved songs. From cache file or from the feed. * * @return array $songs Returns formatted songs */ public static function getLovedSongs($username = '', $num_songs = 30) { if (!self::isValidUsername($username)) { return array(self::$error); } // Check Feeder and Cache classes are accessible if (!class_exists('Feeder')) { return array('Could not find Feeder.class.php.'); } if (!class_exists('Cache')) { return array('Could not find Cache.class.php.'); } self::$username = $username; self::$num_songs = $num_songs; $cache_filename = self::$username . '-loved-tracks.cache'; $cache_life = 86400; // 1 day Cache::init($cache_filename, $cache_life); if (Cache::cacheFileExists()) { return Cache::getCache(); } $song_data = Feeder::getItems(self::getLovedSongsFeed(), self::$num_songs, array('title', 'link')); if (!is_array($song_data)) { self::$error = "Last.fm loved tracks feed not found"; return array(self::$error); } $songs = self::formatSongData($song_data); Cache::setCache($songs); return $songs; }
/** * Library constructor. * * @param string $apiKey * @param string $apiSecret * @param string $sessionKey */ public function __construct($apiKey, $apiSecret, $sessionKey) { parent::__construct($apiKey, $apiSecret, $sessionKey); $this->__setSection('library'); }
Route::get('lastfm/connect', 'LastfmController@connect'); Route::post('lastfm/session-key', 'LastfmController@setSessionKey'); Route::get('lastfm/callback', ['as' => 'lastfm.callback', 'uses' => 'LastfmController@callback']); Route::delete('lastfm/disconnect', 'LastfmController@disconnect'); // YouTube-related routes if (YouTube::enabled()) { Route::get('youtube/search/song/{song}', 'YouTubeController@searchVideosRelatedToSong'); } // Download routes Route::group(['prefix' => 'download', 'namespace' => 'Download'], function () { Route::get('songs', 'SongController@download'); Route::get('album/{album}', 'AlbumController@download'); Route::get('artist/{artist}', 'ArtistController@download'); Route::get('playlist/{playlist}', 'PlaylistController@download'); Route::get('favorites', 'FavoritesController@download'); }); // Info routes if (Lastfm::used()) { Route::get('album/{album}/info', 'AlbumController@getInfo'); Route::get('artist/{artist}/info', 'ArtistController@getInfo'); } }); Route::group(['middleware' => 'os.auth', 'prefix' => 'os', 'namespace' => 'ObjectStorage'], function () { Route::group(['prefix' => 's3', 'namespace' => 'S3'], function () { Route::post('song', 'SongController@put'); // we follow AWS's convention here. Route::delete('song', 'SongController@remove'); // and here. }); }); });