-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_similar_tracks.php
137 lines (110 loc) · 3.34 KB
/
get_similar_tracks.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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
<?php
include('custom_helper.php');
$br = '<br>';
// http://ws.audioscrobbler.com/2.0/?method=track.getsimilar&artist=cher&track=believe&api_key=b25b959554ed76058ac220b7b2e0a026
$api = 'b25b959554ed76058ac220b7b2e0a026';
$artist = 'rammstein';
$track = 'sonne';
$limit = 10;
$size_cover = 1;
$show_youtube = false;
$artist = clear_name($_POST['artist']);
$track = clear_name($_POST['track']);
$limit = (int) $_POST['limit'];
if( (int)$_POST['show_youtube'] > 0 )
$show_youtube = true;
if( isset($_POST['size_cover']) )
$size_cover = (int)$_POST['size_cover'];
if( $limit < 1 )
die('Você não deseja exibir nada.');
$url_string = 'http://ws.audioscrobbler.com/2.0/?method=track.getsimilar&artist=%s&track=%s&limit=%s&api_key=%s';
// last.fnm
$url = sprintf($url_string, $artist, $track, $limit, $api);
//echo $url;
// youtube
$url_youtube = 'http://gdata.youtube.com/feeds/api/videos?q='.$artist.'-'.$track.'&start-index=21&max-results=10&v=2';
// getting list on last.fm
$xml_lastfm = file_get_contents( $url );
//echo '<pre>';
//print_r($xml_lastfm);
$lastfm = simplexml_load_string( $xml_lastfm );
//print_r($lastfm);
$i = 0;
?>
<?php if( count($lastfm->similartracks->track) > 0 ): ?>
<table class="lastfm">
<tr class="tbl_header">
<td>Nome da Musica</td>
<td>Artista</td>
<td>Duração</td>
<td>Capa</td>
<td>Youtube</td>
</tr>
<?php foreach( $lastfm->similartracks->track as $track ): ?>
<?php /*print_r($track);*/ ?>
<?php
$class_bg = '';
if( $i % 2 == 0 )
$class_bg = 'class=".bg_line"';
else
$class_bg = '' ;
$i++;
switch ($size_cover) {
case 0:
$img_w = ' width="34"';
$img_h = ' height="34"';
break;
case 1:
$img_w = ' width="64"';
$img_h = ' height="64"';
break;
case 2:
$img_w = ' width="126"';
$img_h = ' height="126"';
break;
case 3:
$img_w = ' width="300"';
$img_h = ' height="300"';
break;
default:
$img_w = ' width="64"';
$img_h = ' height="64"';
break;
}
?>
<tr>
<td <?php echo $class_bg; ?>><?php echo $track->name; ?></td>
<td <?php echo $class_bg; ?>><?php echo $track->artist->name; ?></td>
<td <?php echo $class_bg; ?>><?php echo get_duration($track->duration); ?></td>
<td <?php echo $class_bg; ?>>
<img src="<?php echo get_image_src($track->image[$size_cover]); ?>" alt="<?php echo $track->artist->name ; ?>" <?php echo $img_w.$img_h; ?> />
</td>
<td <?php echo $class_bg; ?>>
<?php if( $show_youtube ): ?>
<?php $youtube_url = get_youtube_url($track->artist->name, $track->name); ?>
<a href="<?php echo $youtube_url; ?>" target="_blank">
<img src="<?php echo video_image($youtube_url, true); ?> " alt="" <?php echo $w_h; ?> />
</a>
<?php else: ?>
Não exibido
<?php endif; ?>
</td>
</tr>
<?php endforeach; ?>
</table>
<?php else: ?>
<span class="msg msg_error">Nenhum conteúdo encontrado.</span>
<?php endif; ?>
<?php
//$file_xml = 'youtube_return.xml';
//$xml = simplexml_load_file($file_xml);
//print_r($xml);
//foreach ($xml->entry as $entry) {
//echo $entry->title. ' ('.$entry->title.') ';
//echo $entry->content['type'], $entry->content['src'];
//echo $entry->link[0]['href'];
//echo video_image($entry->link[0]['href'], true);
//echo '<br>';
# code...
///}
?>