Skip to content

Instantly share code, notes, and snippets.

@msaulohenrique
Created January 23, 2020 18:33
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save msaulohenrique/bc56887f33aaa3d1414513b99cecc32d to your computer and use it in GitHub Desktop.
Save msaulohenrique/bc56887f33aaa3d1414513b99cecc32d to your computer and use it in GitHub Desktop.
Get artist info and track image (iTunes)
<!doctype html>
<html>
<head>
<title>Get artist and track image</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
</head>
<body>
<?php
$search = 'drowning pool 37 stitches'; // user input 'term' in a form
$term = urlencode($search); // user input 'term' in a form
$json = file_get_contents('http://itunes.apple.com/search?term='.$term.'&limit=1&media=music&entity=song');
$array = json_decode($json, true);
/* Artwork sizes available from iTunes (as of 10 November 2014)
30x30
40x40
60x60
80x80
100x100
110x110
130x130
150x150
160x160
170x170
190x190
200x200
220x220
230x230
240x240
250x250
340x340
400x400
440x440
450x450
460x460
480x480
600x600
1200x1200
1400x1400
*/
foreach($array['results'] as $value)
{
echo '<p>';
echo 'Artista: ' .$value['artistName'].'<br />';
echo 'Música: ' .$value['trackName'].'<br />';
$cover = str_replace('100x100', '340x340', $value['artworkUrl100']); //change 100x100 to 340x340
echo 'Capa: <img src="' .$cover.'" /><br />';
echo 'País: ' .$value['country'].'<br />';
echo 'Prévia: <audio controls><source src="' .$value['previewUrl'].'" type="audio/wav"></audio><br />';
echo 'iTunes (Perfil Artista): ' .$value['artistViewUrl'].'<br />';
echo 'iTunes (Albúm): ' .$value['collectionViewUrl'].'<br />';
echo 'iTunes (Música): ' .$value['trackViewUrl'].'<br />';
echo 'Genêro: ' .$value['primaryGenreName'];
echo '</p>';
}
?>
</body>
</html>
@msaulohenrique
Copy link
Author

msaulohenrique commented Jan 23, 2020

Imgur

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment