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
138
139
140
141
142
143
144
145
146
147
148
149
|
<?php
/*
Copyright 2001 - 2007 Ampache.org
All Rights Reserved
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; version 2
of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/**
* metadata class
* This class is a abstraction layer for getting
* meta data for any object in Ampache, this includes
* album art, lyrics, id3tags, recommendations etc
* it makes use of Object::construct_from_array() as needed
*/
class metadata {
/**
* constructor
* We don't use this, as its really a static class
*/
private function __construct() {
// Rien a faire
} // constructor
/**
* recommend_similar
* This takes the input and returns an array of objects construct_from_array()'d
*/
public static function recommend_similar($type,$id,$limit='') {
// For now it's only mystrands
OpenStrands::set_auth_token(Config::get('mystrands_developer_key'));
$openstrands = new OpenStrands($GLOBALS['user']->prefs['mystrands_user'],$GLOBALS['user']->prefs['mystrands_pass']);
// Make sure auth worked
if (!$openstrands) { return false; }
switch ($type) {
case 'artist':
$artist = new Artist($id);
$seed = array('name'=>array($artist->name));
$results = $openstrands->recommend_artists($seed,$limit);
break;
}
$objects = array();
foreach ($results as $item) {
switch ($type) {
case 'artist':
$data['name'] = $item['ArtistName'];
$data['uid'] = $item['__attributes']['ArtistID'];
$data['mystrands_url'] = $item['URI'];
$data['links'] = "<a target=\"_blank\" href=\"" . $item['URI'] . "\">" . get_user_icon('world_link','MyStrands Link') . "</a>";
// Do a search for this artist in our instance
$artist_id = Catalog::check_artist($data['name'],1);
if ($artist_id) {
$artist = new Artist($artist_id);
$artist->format();
$data['links'] .= "<a href=\"$artist->f_link\">" . get_user_icon('ampache','Ampache') . "</a>";
}
$objects[] = Artist::construct_from_array($data);
break;
} // end switch on type
} // end foreach
return $objects;
} // recommend_similar
/**
* find_missing_tracks
* This returns an array of song objects using the construct_from_array() that are
* not in the specified album.
*/
public static function find_missing_tracks($album_id) {
// Build our object
$album = new Album($album_id);
$album->format();
$objects = array();
// For now it's only mystrands
OpenStrands::set_auth_token(Config::get('mystrands_developer_key'));
$openstrands = new OpenStrands($GLOBALS['user']->prefs['mystrands_user'],$GLOBALS['user']->prefs['mystrands_pass']);
if (!$openstrands) { return false; }
// Setup the string we're going to pass
if ($album->artist_count == '1') { $artist_name = $album->artist_name; }
else { $artist_name = "Various"; }
$data[] = array('artist'=>$artist_name,'album'=>$album->full_name);
// First find the album on mystrands
$result = $openstrands->match_albums($data);
if (!$result) { return false; }
$mystrands_id = $result['0']['__attributes']['AlbumId'];
if (!$mystrands_id) { return false; }
$tracks = $openstrands->lookup_album_tracks($mystrands_id,Openstrands::$alias);
$object = array();
// Recurse the data we've found and check the local album
foreach ($tracks as $track) {
if (!$album->has_track($track['TrackName'])) {
$data['title'] = $track['TrackName'];
$data['track'] = $track['TrackNumber'];
$data['disc'] = $track['DiscNumber'];
$data['artist'] = $track['ArtistName'];
$data['links'] = "<a target=\"_blank\" href=\"" . $track['URI'] . "\">" . get_user_icon('world_link','MyStrands') . "</a>";
// If we've got a purchase URL
if ($track['UserPurchaseURI']) {
$data['links'] .= "<a target=\"_blank\" href=\"" . $track['UserPurchaseURI'] . "\">" . get_user_icon('money',_('Buy Track from MyStrands')) . "</a>";
}
$objects[] = Album::construct_from_array($data);
}
} // end foreach
return $objects;
} // find_missing_tracks
} // metadata
?>
|