PageRenderTime 47ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/services/services/metadata/amazon.php

https://github.com/jinzora/jinzora3
PHP | 265 lines | 171 code | 27 blank | 67 comment | 35 complexity | 161fb253afba68e82193eeb85385b6a4 MD5 | raw file
  1. <?php if (!defined(JZ_SECURE_ACCESS)) die ('Security breach detected.');
  2. /**
  3. * - JINZORA | Web-based Media Streamer -
  4. *
  5. * Jinzora is a Web-based media streamer, primarily desgined to stream MP3s
  6. * (but can be used for any media file that can stream from HTTP).
  7. * Jinzora can be integrated into a CMS site, run as a standalone application,
  8. * or integrated into any PHP website. It is released under the GNU GPL.
  9. *
  10. * - Resources -
  11. * - Jinzora Author: Ross Carlson <ross@jasbone.com>
  12. * - Web: http://www.jinzora.org
  13. * - Documentation: http://www.jinzora.org/docs
  14. * - Support: http://www.jinzora.org/forum
  15. * - Downloads: http://www.jinzora.org/downloads
  16. * - License: GNU GPL <http://www.gnu.org/copyleft/gpl.html>
  17. *
  18. * - Contributors -
  19. * Please see http://www.jinzora.org/team.html
  20. *
  21. * - Code Purpose -
  22. * - Retrieves meta data from Amazon Web Services
  23. *
  24. * @since 01.14.05
  25. * @author Ross Carlson <ross@jinzora.org>
  26. */
  27. $jzSERVICE_INFO = array();
  28. $jzSERVICE_INFO['name'] = "Allmusic.com";
  29. $jzSERVICE_INFO['url'] = "http://www.allmusic.com";
  30. define('SERVICE_METADATA_amazon','true');
  31. /*
  32. * Gets the metadata for an album
  33. *
  34. * @author Ross Carlson
  35. * @version 1/15/05
  36. * @since 1/15/05
  37. * @param $node The current node we are looking at
  38. * @param $displayOutput Should we dispaly output (defaults to true)
  39. **/
  40. function SERVICE_GETALBUMMETADATA_amazon($node, $displayOutput = true, $return = false) {
  41. global $include_path;
  42. // Ok, now we need to see if we are reading a album or an artist
  43. $album = $node->getName();
  44. $parent = $node->getParent();
  45. $artist = $parent->getName();
  46. // Now let's clean that up some
  47. if (stristr($album,"(")){$album = trim(substr($album,0,strpos($album,"(")));}
  48. if (stristr($album,"[")){$album = trim(substr($album,0,strpos($album,"[")));}
  49. $album = str_replace("_"," ",$album);
  50. $amazon_key = "19B1FW4R5ABSKBWNV582";
  51. include_once($include_path. "lib/snoopy.class.php");
  52. $snoopy = new Snoopy;
  53. $snoopy->fetch("http://xml.amazon.com/onca/xml3?KeywordSearch=". urlencode($album). "&dev-t=". $amazon_key. "&f=xml&locale=us&mode=music&page=1&t=chipdir&type=heavy");
  54. $contents = $snoopy->results;
  55. unset($snoopy);
  56. // Now let's move to the results
  57. $contents = substr($contents,strpos($contents,"</TotalPages>")+strlen("</TotalPages>"));
  58. // Ok, now let's make sure the search we did returned the right album
  59. if (!stristr($contents,$album) or !stristr($contents,"<Artist>". $artist) or stristr($contents,"There are no exact matches for the search.")){
  60. // Now let's try doing it with adding the artist to the query
  61. $snoopy = new Snoopy;
  62. $snoopy->fetch("http://xml.amazon.com/onca/xml3?KeywordSearch=". urlencode($album. " ". $artist). "&dev-t=". $amazon_key. "&f=xml&locale=us&mode=music&page=1&t=chipdir&type=heavy");
  63. $contents = $snoopy->results;
  64. unset($snoopy);
  65. // Now let's move to the results
  66. $contents = substr($contents,strpos($contents,"</TotalPages>")+strlen("</TotalPages>"));
  67. }
  68. if (stristr($contents,$album) and stristr($contents,"<Artist>". $artist) and !stristr($contents,"There are no exact matches for the search.")){
  69. $contents = substr($contents,strpos($contents,$artist));
  70. // Ok, we got it, let's get the data
  71. $ReleaseDate="";$ImageUrlLarge="";$Tracks="";$ProductDescription="";$AvgCustomerRating="";$ListPrice="";$BrowseName="";
  72. $searchVals = "ReleaseDate|ImageUrlLarge|Tracks|ProductDescription|AvgCustomerRating|ListPrice|BrowseName";
  73. $searchArray = explode("|",$searchVals);
  74. for ($e=0; $e < count($searchArray); $e++){
  75. if (stristr($contents,$searchArray[$e])){
  76. $$searchArray[$e] = str_replace("]]>","",str_replace("<![CDATA[","",substr($contents,strpos($contents,"<". $searchArray[$e]. ">")+ strlen("<". $searchArray[$e]. ">"),strpos($contents,"</". $searchArray[$e]. ">") - (strpos($contents,"<". $searchArray[$e]. ">") + strlen("<". $searchArray[$e]. ">")))));
  77. }
  78. }
  79. // Now let's fix up the tracks
  80. $tArray = explode("\n",$Tracks);
  81. $i=0;
  82. for ($e=0; $e < count($tArray); $e++){
  83. $track = substr($tArray[$e],strpos($tArray[$e],"<Track>")+strlen("<Track>"));
  84. $track = substr($track,0,strpos($track,"</Track>"));
  85. $tracks[$i] = $track;
  86. $i++;
  87. }
  88. $genre = $BrowseName;
  89. $ProductDescription = str_replace("&lt;I>","",$ProductDescription);
  90. $ProductDescription = str_replace("&lt;i>","",$ProductDescription);
  91. $ProductDescription = str_replace("&lt;/I>","",$ProductDescription);
  92. $ProductDescription = str_replace("&lt;/i>","",$ProductDescription);
  93. // Now let's clean up the release date
  94. $year = trim(substr($ReleaseDate,strpos($ReleaseDate,", ")+2));
  95. // Now let's get the ID number for the Amazon site
  96. $id = substr($ImageUrlLarge,strlen("http://images.amazon.com/images/P/"));
  97. $id = substr($id,0,strpos($id,"."));
  98. // Now let's write this data IF they wanted to
  99. $image = $ImageUrlLarge;
  100. $review = $ProductDescription;
  101. $rating = $AvgCustomerRating;
  102. if (!$return){
  103. writeAlbumMetaData($node, $year, $image, $tracks, $review, $rating, $ListPrice, $genre, $displayOutput);
  104. return true;
  105. } else {
  106. if ($return == "array"){
  107. $retArr['year'] = $year;
  108. $retArr['image'] = $image;
  109. $retArr['review'] = $review;
  110. $retArr['rating'] = $rating;
  111. $retArr['id'] = $id;
  112. $retArr['genre'] = $genre;
  113. return $retArr;
  114. } else {
  115. return $$return;
  116. }
  117. }
  118. } else {
  119. if ($displayOutput){
  120. ?>
  121. <SCRIPT LANGUAGE=JAVASCRIPT><!--\
  122. als.innerHTML = 'Album not found!';
  123. -->
  124. </SCRIPT>
  125. <?php
  126. flushdisplay();
  127. }
  128. return false;
  129. }
  130. }
  131. /*
  132. * Gets the metadata for an artist
  133. *
  134. * @author Ross Carlson
  135. * @version 1/15/05
  136. * @since 1/15/05
  137. * @param $node The current node we are looking at
  138. * @param $return should we return or write data (defaults to write),
  139. * and if return what do we return (image = binaryImageData, genre, description)
  140. **/
  141. function SERVICE_GETARTISTMETADATA_amazon($node = false, $return = false, $artistName = false){
  142. global $include_path;
  143. // Is this a node or specific artist?
  144. if (is_object($node)){
  145. // Ok, now we need to see if we are reading a album or an artist
  146. $album = $node->getName();
  147. $parent = $node->getParent();
  148. $artist = $parent->getName();
  149. // Now let's clean that up some
  150. if (stristr($album,"(")){$album = trim(substr($album,0,strpos($album,"(")));}
  151. if (stristr($album,"[")){$album = trim(substr($album,0,strpos($album,"[")));}
  152. $album = str_replace("_"," ",$album);
  153. } else {
  154. $artist = $node['artist'];
  155. $album = $node['album'];
  156. }
  157. $amazon_key = "19B1FW4R5ABSKBWNV582";
  158. include_once($include_path. "lib/snoopy.class.php");
  159. $snoopy = new Snoopy;
  160. $snoopy->fetch("http://xml.amazon.com/onca/xml3?KeywordSearch=". urlencode($album). "&dev-t=". $amazon_key. "&f=xml&locale=us&mode=music&page=1&t=chipdir&type=heavy");
  161. $contents = $snoopy->results;
  162. unset($snoopy);
  163. // Now let's move to the results
  164. $contents = substr($contents,strpos($contents,"</TotalPages>")+strlen("</TotalPages>"));
  165. // Ok, now let's make sure the search we did returned the right album
  166. if (!stristr($contents,$album) or !stristr($contents,"<Artist>". $artist) or stristr($contents,"There are no exact matches for the search.")){
  167. // Now let's try doing it with adding the artist to the query
  168. $snoopy = new Snoopy;
  169. $snoopy->fetch("http://xml.amazon.com/onca/xml3?KeywordSearch=". urlencode($album. " ". $artist). "&dev-t=". $amazon_key. "&f=xml&locale=us&mode=music&page=1&t=chipdir&type=heavy");
  170. $contents = $snoopy->results;
  171. unset($snoopy);
  172. // Now let's move to the results
  173. $contents = substr($contents,strpos($contents,"</TotalPages>")+strlen("</TotalPages>"));
  174. }
  175. if (stristr($contents,$album) and stristr($contents,"<Artist>". $artist) and !stristr($contents,"There are no exact matches for the search.")){
  176. $contents = substr($contents,strpos($contents,$artist));
  177. // Ok, we got it, let's get the data
  178. $ReleaseDate="";$ImageUrlLarge="";$Tracks="";$ProductDescription="";$AvgCustomerRating="";$ListPrice="";$BrowseName="";
  179. $searchVals = "ReleaseDate|ImageUrlLarge|Tracks|ProductDescription|AvgCustomerRating|ListPrice|BrowseName";
  180. $searchArray = explode("|",$searchVals);
  181. for ($e=0; $e < count($searchArray); $e++){
  182. if (stristr($contents,$searchArray[$e])){
  183. $$searchArray[$e] = str_replace("]]>","",str_replace("<![CDATA[","",substr($contents,strpos($contents,"<". $searchArray[$e]. ">")+ strlen("<". $searchArray[$e]. ">"),strpos($contents,"</". $searchArray[$e]. ">") - (strpos($contents,"<". $searchArray[$e]. ">") + strlen("<". $searchArray[$e]. ">")))));
  184. }
  185. }
  186. // Now let's fix up the tracks
  187. $tArray = explode("\n",$Tracks);
  188. $i=0;
  189. for ($e=0; $e < count($tArray); $e++){
  190. $track = substr($tArray[$e],strpos($tArray[$e],"<Track>")+strlen("<Track>"));
  191. $track = substr($track,0,strpos($track,"</Track>"));
  192. $tracks[$i] = $track;
  193. $i++;
  194. }
  195. $genre = $BrowseName;
  196. $ProductDescription = str_replace("&lt;I>","",$ProductDescription);
  197. $ProductDescription = str_replace("&lt;i>","",$ProductDescription);
  198. $ProductDescription = str_replace("&lt;/I>","",$ProductDescription);
  199. $ProductDescription = str_replace("&lt;/i>","",$ProductDescription);
  200. // Now let's clean up the release date
  201. $year = trim(substr($ReleaseDate,strpos($ReleaseDate,", ")+2));
  202. // Now let's get the ID number for the Amazon site
  203. $id = substr($ImageUrlLarge,strlen("http://images.amazon.com/images/P/"));
  204. $id = substr($id,0,strpos($id,"."));
  205. // Now let's write this data IF they wanted to
  206. $image = $ImageUrlLarge;
  207. $review = $ProductDescription;
  208. $rating = $AvgCustomerRating;
  209. if (!$return){
  210. writeAlbumMetaData($node, $year, $image, $tracks, $review, $rating, $ListPrice, $genre, $displayOutput);
  211. return true;
  212. } else {
  213. if ($return == "array"){
  214. $retArr['year'] = $year;
  215. $retArr['image'] = $image;
  216. $retArr['review'] = $review;
  217. $retArr['rating'] = $rating;
  218. $retArr['id'] = $id;
  219. $retArr['genre'] = $genre;
  220. return $retArr;
  221. } else {
  222. return $$return;
  223. }
  224. }
  225. } else {
  226. if ($displayOutput){
  227. ?>
  228. <SCRIPT LANGUAGE=JAVASCRIPT><!--\
  229. als.innerHTML = 'Album not found!';
  230. -->
  231. </SCRIPT>
  232. <?php
  233. flushdisplay();
  234. }
  235. return false;
  236. }
  237. }
  238. ?>