3 Pitchfork Music Player Daemon Client
4 Copyright (C) 2007 Roger Bystrøm
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; version 2 of the License.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 $amazon_cover_url = $amazon_base_url . "&Operation=ItemSearch&SearchIndex=Music&ResponseGroup=Images";
21 $cover_providers = array("directory_cover", "amazon_search_cover");
23 /* If you want to use this you'll need php-gd as well */
24 /* first %s will be replaced by Artist and second %s will be replaced by Album */
25 /* can be local path or url (http://someserver/path/%s/%s/cover.jpg will become
26 e.g. http://someserver/path/Escape The Fate/Dying Is Your Latest Fashion/cover.jpg */
27 //$directory_search_url = "/path/to/somehere/%s/%s.jpg";
28 $directory_search_url = false;
30 function amazon_search_cover($artist, $album) {
31 global $amazon_cover_url, $metadata_dir;
33 $xml = amazon_album_query($amazon_cover_url, $artist, $album);
35 if(isset($xml->Items[0])&&isset($xml->Items[0]->Item[0])) {
36 $item = $xml->Items[0]->Item[0];
42 if(isset($item->SmallImage[0])) {
43 $small = @file_get_contents($item->SmallImage[0]->URL[0]);
45 $small_name = escape_name($artist) . "-" . escape_name($album) . basename($item->SmallImage[0]->URL[0]);
46 if(!@file_put_contents($metadata_dir . $small_name, $small)) {
51 if(isset($item->LargeImage[0])) {
52 $large = @file_get_contents($item->LargeImage[0]->URL[0]);
54 $large_name = escape_name($artist) . "-" . escape_name($album) . basename($item->LargeImage[0]->URL[0]);
55 if(!@file_put_contents($metadata_dir . $large_name, $large)) {
60 else if(isset($item->MediumImage[0])) {
61 $large = @file_get_contents($item->MediumImage[0]->URL[0]);
63 $large_name = escape_name($artist) . "-" . escape_name($album) . basename($item->MediumImage[0]->URL[0]);
64 if(!@file_put_contents($metadata_dir . $large_name, $large)) {
69 if($small && $large) {
71 $data['asin'] = $item->ASIN[0];
72 $data['thumbnail'] = $small_name;
73 $data['image'] = $large_name;
81 function directory_cover($artist, $album) {
82 global $directory_search_url, $metadata_dir;
84 if(!$directory_search_url)
87 $artist = escape_name($artist);
88 $album = escape_name($album);
90 $name = sprintf($directory_search_url, $artist, $album);
92 return make_thumb_and_store_image($name, get_cover_base_name($artist, $album));
95 /* yay for me and function names */
96 function make_thumb_and_store_image($file, $store_bname) {
97 // only supports jpeg for now..
99 $image = @imagecreatefromjpeg($file);
103 $ix = imagesx($image);
104 $iy = imagesy($image);
105 $rx = $ry = $max_size;
107 $max_i = $ix>$iy?$ix:$iy;
109 $res['image'] = basename($store_bname . ".jpg");
110 if(!@imagejpeg($image, $store_bname . ".jpg", 90)) {
113 if($max_i>$max_size) {
114 $ratio = (double)$max_i/(double)$max_size;
115 $rx = (int)((double)$ix/$ratio);
116 $ry = (int)((double)$iy/$ratio);
117 $thumb = imagecreatetruecolor($rx,$ry);
118 imagecopyresampled($thumb, $image, 0,0,0,0, $rx, $ry, $ix, $iy);
119 $res['thumbnail'] = basename($store_bname . "_thumb.jpg");
120 if(!@imagejpeg($thumb, $store_bname . "_thumb.jpg", 90)) {
125 $res['thumb'] = $res['image'];