]> Joshua Wise's Git repositories - patchfork.git/blame - player/metadata_cover.php
Fix bug in MPD/Common where playlist version numbers would not be properly returned...
[patchfork.git] / player / metadata_cover.php
CommitLineData
964dd0bc
JW
1<?php
2/*
3 Pitchfork Music Player Daemon Client
4 Copyright (C) 2007 Roger Bystrøm
5
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.
9
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.
14
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.
18*/
19
20 $amazon_cover_url = $amazon_base_url . "&Operation=ItemSearch&SearchIndex=Music&ResponseGroup=Images";
21 $cover_providers = array("directory_cover", "amazon_search_cover");
22
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;
29
30 function amazon_search_cover($artist, $album) {
31 global $amazon_cover_url, $metadata_dir;
32
33 $xml = amazon_album_query($amazon_cover_url, $artist, $album);
34 if($xml) {
35 if(isset($xml->Items[0])&&isset($xml->Items[0]->Item[0])) {
36 $item = $xml->Items[0]->Item[0];
37 $small = false;
38 $small_name = false;
39 $large = false;
40 $large_name = false;
41
42 if(isset($item->SmallImage[0])) {
43 $small = @file_get_contents($item->SmallImage[0]->URL[0]);
44 if($small) {
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)) {
47 $small = false;
48 }
49 }
50 }
51 if(isset($item->LargeImage[0])) {
52 $large = @file_get_contents($item->LargeImage[0]->URL[0]);
53 if($large) {
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)) {
56 $large = false;
57 }
58 }
59 }
60 else if(isset($item->MediumImage[0])) {
61 $large = @file_get_contents($item->MediumImage[0]->URL[0]);
62 if($large) {
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)) {
65 $large = false;
66 }
67 }
68 }
69 if($small && $large) {
70 $data = array();
71 $data['asin'] = $item->ASIN[0];
72 $data['thumbnail'] = $small_name;
73 $data['image'] = $large_name;
74 return $data;
75 }
76 }
77 }
78 return false;
79 }
80
81 function directory_cover($artist, $album) {
82 global $directory_search_url, $metadata_dir;
83
84 if(!$directory_search_url)
85 return false;
86
87 $artist = escape_name($artist);
88 $album = escape_name($album);
89
90 $name = sprintf($directory_search_url, $artist, $album);
91
92 return make_thumb_and_store_image($name, get_cover_base_name($artist, $album));
93 }
94
95 /* yay for me and function names */
96 function make_thumb_and_store_image($file, $store_bname) {
97 // only supports jpeg for now..
98 $max_size = 75;
99 $image = @imagecreatefromjpeg($file);
100 if(!$image)
101 return false;
102
103 $ix = imagesx($image);
104 $iy = imagesy($image);
105 $rx = $ry = $max_size;
106
107 $max_i = $ix>$iy?$ix:$iy;
108 $res = array();
109 $res['image'] = basename($store_bname . ".jpg");
110 if(!@imagejpeg($image, $store_bname . ".jpg", 90)) {
111 return false;
112 }
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)) {
121 return false;
122 }
123 }
124 else {
125 $res['thumb'] = $res['image'];
126 }
127 return $res;
128 }
129?>
This page took 0.031272 seconds and 4 git commands to generate.