Ejemplo n.º 1
0
 public function testSearch()
 {
     $types = array('album', 'artist');
     $options = array('limit' => 10);
     $expected = array('limit' => 10, 'q' => 'blur', 'type' => 'album,artist');
     $headers = array('Authorization' => 'Bearer ' . $this->accessToken);
     $return = array('body' => get_fixture('search-album'));
     $stub = $this->setupStub('GET', '/v1/search', $expected, $headers, $return);
     $api = new SpotifyWebAPI\SpotifyWebAPI($stub);
     $api->setAccessToken($this->accessToken);
     $response = $api->search('blur', $types, $options);
     $this->assertNotEmpty($response->albums);
 }
Ejemplo n.º 2
0
$api = new SpotifyWebAPI\SpotifyWebAPI();
$app = new Silex\Application();
$app['debug'] = true;
$app->register(new Silex\Provider\TwigServiceProvider(), array('twig.path' => __DIR__ . '/views'));
$app->register(new Silex\Provider\UrlGeneratorServiceProvider());
//$app['asset_path'] = 'C:\xampp\htdocs\gtunes';
//obtenir des infos de track par item 'track' et des mots clés
$app->get('/api/search/track/{name}', function ($name) use($app, $api) {
    session_start();
    if (empty($_SESSION['valid_userid'])) {
        header("location:loginerror.php");
        exit;
    }
    $name_user = $_SESSION['valid_username'];
    $id_user = $_SESSION['valid_userid'];
    $results = $api->search($name, 'track');
    return $app['twig']->render('result_by_track.html.twig', array('results' => $results, 'name_user' => $name_user, 'id_user' => $id_user));
});
////obtenir des infos d'artist par item 'artist' et des mots clés
$app->get('/api/search/artist/{name}', function ($name) use($api, $app) {
    session_start();
    if (empty($_SESSION['valid_userid'])) {
        header("location:loginerror.php");
        exit;
    }
    $name_user = $_SESSION['valid_username'];
    $id_user = $_SESSION['valid_userid'];
    $results = $api->search($name, 'artist');
    return $app['twig']->render('info_artist.html.twig', array('results' => $results, 'name_user' => $name_user));
});
//get artists top tracks by artist's id
Ejemplo n.º 3
0
 $content = getFile($link);
 //load qp with content fetched and initialise from body tag
 $htmlqp = @htmlqp($content, 'body');
 if ($htmlqp->length > 0) {
     //we have some data to parse.
     $tracks = $htmlqp->find('.track');
     foreach ($tracks as $track) {
         $title = $track->find('.buk-track-primary-title')->first()->text();
         $artist = $track->find('.buk-track-artists > a')->first()->text();
         $link_to_track = 'https://pro.beatport.com' . $track->find('.buk-track-title > a')->first()->attr('href');
         //CHECK IF ARTIST ALREADY EXIST IN DATABASE, PRIOR TO SEARCHING ON SPOTIFY
         $artist_spotify_id = $db->querySingle("select Artist_spotify_id from artist where Artist_name='" . SQLite3::escapeString($artist) . "'");
         //Like msq_realescape.
         if (!$artist_spotify_id) {
             // If not in database -- get id via Spotify API.
             $spotify_artist = $api->search($artist, 'artist');
             //Geting artist id via Spotify Api
             foreach ($spotify_artist->artists->items as $spotify_id) {
                 $artist_name = $spotify_id->name;
                 $artist_spotify_id_tmp = $spotify_id->id;
                 // store in temp var. Why did you store id as temporary variable? Got it. To use in a bottom loop.
                 if ($artist_name === $artist) {
                     $artist_spotify_id = $spotify_id->id;
                     //this is what we need
                     //echo '<br>';
                     //echo 'Artist name: ' . $artist_name;
                     //echo '<br>';
                 }
                 //will save all artist IDs in DB for caching
                 $db->exec('insert into artist ("Artist_name","Artist_spotify_id") values (' . "'" . SQLite3::escapeString($artist_name) . "','" . $artist_spotify_id_tmp . "')");
             }
Ejemplo n.º 4
0
// for debug
if (gethostname() === 'CodeBrauer.local') {
    include '../ref/ref.php';
}
$args->check();
list($url, $arg2) = $args->process();
// action start
if ($arg2 == 'only-uri') {
    ob_start();
}
$nextPageToken = null;
do {
    $playlistItemsResponse = $youtube->playlistItems->listPlaylistItems('snippet', array('playlistId' => rawurlencode($url), 'maxResults' => 50, 'pageToken' => $nextPageToken));
    foreach ($playlistItemsResponse['items'] as $playlistItem) {
        $trackName = str_ireplace($config['ignore_video_title'], '', $playlistItem['snippet']['title']);
        $search = $spotifyAPI->search(trim($trackName), 'track');
        if ($search->tracks->total > 0) {
            $spotifyURI = $spotifyAPI->search(trim($trackName), 'track')->tracks->items[0]->uri;
            $result[] = $spotifyURI;
            Output::put($trackName, 'success');
        } else {
            Output::put($trackName, 'fail');
        }
    }
    $nextPageToken = $playlistItemsResponse['nextPageToken'];
} while ($nextPageToken != null);
file_put_contents('spotify-uris.txt', implode("\n", $result));
if (stripos(php_uname(), 'darwin') !== false) {
    Output::blankLine();
    if ($arg2 == 'copy') {
        shell_exec('cat spotify-uris.txt | pbcopy');