PageRenderTime 41ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/services/services/metadata/yahoo.php

https://github.com/jinzora/jinzora3
PHP | 201 lines | 114 code | 25 blank | 62 comment | 21 complexity | 914684d113c8c28f74b46e0d65a55991 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. * - This is the leo's lyrics service.
  23. *
  24. * @since 01.14.05
  25. * @author Ross Carlson <ross@jinzora.org>
  26. * @author Ben Dodson <ben@jinzora.org>
  27. */
  28. $jzSERVICE_INFO = array();
  29. $jzSERVICE_INFO['name'] = "music.msn.com";
  30. $jzSERVICE_INFO['url'] = "http://music.msn.com";
  31. define('SERVICE_METADATA_yahoo','true');
  32. /*
  33. * Gets the metadata for an album
  34. *
  35. * @author Ross Carlson
  36. * @version 1/15/05
  37. * @since 1/15/05
  38. * @param $node The current node we are looking at
  39. * @param $displayOutput Should we dispaly output (defaults to true)
  40. **/
  41. function SERVICE_GETALBUMMETADATA_yahoo($node, $displayOutput = true, $return = false) {
  42. global $include_path;
  43. // Ok, now we need to see if we are reading a album or an artist
  44. $album = $node->getName();
  45. $parent = $node->getParent();
  46. $artist = $parent->getName();
  47. include_once($include_path. "lib/snoopy.class.php");
  48. // First let's get the artist page
  49. $snoopy = new Snoopy;
  50. $snoopy->fetch("http://search.music.yahoo.com/search/?m=album&x=15&y=7&p=". urlencode($album));
  51. $contents = $snoopy->results;
  52. unset($snoopy);
  53. // Did we get anything?
  54. if (stristr($contents,"no matches found")){
  55. return false;
  56. }
  57. // Now let's fix up the name
  58. $albumName = str_replace("&","&amp;",$album);
  59. $artist = str_replace("&","&amp;",$artist);
  60. // Ok, now let's see if we got a direct hit or a link
  61. if (!stristr($contents,$artist) or !stristr($contents,$album)){
  62. // Ok, we missed let's try to mangle the name and try again?
  63. $album = trim(substr($album,0,strpos($album," -")));
  64. $snoopy = new Snoopy;
  65. $snoopy->fetch("http://search.music.yahoo.com/search/?m=album&x=15&y=7&p=". urlencode($album));
  66. $contents = $snoopy->results;
  67. unset($snoopy);
  68. }
  69. if (!stristr($contents,$artist) or !stristr($contents,$album)){
  70. // Ok, we missed let's try to mangle the name and try again?
  71. $album = trim(substr($album,0,strpos($album,"[")));
  72. $snoopy = new Snoopy;
  73. $snoopy->fetch("http://search.music.yahoo.com/search/?m=album&x=15&y=7&p=". urlencode($album));
  74. $contents = $snoopy->results;
  75. unset($snoopy);
  76. }
  77. if (!stristr($contents,$artist) or !stristr($contents,$album)){
  78. // Ok, we missed let's try to mangle the name and try again?
  79. $album = trim(substr($album,0,strpos($album,"(")));
  80. $snoopy = new Snoopy;
  81. $snoopy->fetch("http://search.music.yahoo.com/search/?m=album&x=15&y=7&p=". urlencode($album));
  82. $contents = $snoopy->results;
  83. unset($snoopy);
  84. }
  85. if (!stristr($contents,$artist) or !stristr($contents,$album)){
  86. return false;
  87. }
  88. // Now let's move up to the artist and back
  89. $link = substr($contents,strpos($contents,$artist)-300);
  90. $link = substr($link,strpos($link,"<a href=http://music.yahoo.com/release")+8);
  91. $link = substr($link,0,strpos($link,' '));
  92. if (stristr($link,">")){
  93. $link = substr($link,0,strpos($link,'>'));
  94. }
  95. // Now let's get that page
  96. $contents = @file_get_contents($link);
  97. // Now let's get the image
  98. $contents = substr($contents,strpos($contents,'onClick="ext_link'));
  99. $contents = substr($contents,strpos($contents,'Album Release Date')-400);
  100. $image = substr($contents,strpos($contents,'<img src="http://')+10);
  101. $image = substr($image,0,strpos($image,'"'));
  102. if (!stristr($image,".jpg") or !stristr($image,"http://")){
  103. $image = "";
  104. }
  105. // Now let's get the release year
  106. $year = substr($contents,strpos($contents,'Album Release Date:&nbsp;')+strlen('Album Release Date:&nbsp;'));
  107. $year = substr($year,0,strpos($year,'</td>'));
  108. if (!$return){
  109. writeAlbumMetaData($node, $year, $image, false, false, false, false, false, $displayOutput);
  110. } else {
  111. if ($return == "array"){
  112. $retArr['year'] = $year;
  113. $retArr['image'] = $image;
  114. $retArr['review'] = false;
  115. $retArr['rating'] = false;
  116. return $retArr;
  117. } else {
  118. return $$return;
  119. }
  120. }
  121. }
  122. /*
  123. * Gets the metadata for an artist
  124. *
  125. * @author Ross Carlson
  126. * @version 1/15/05
  127. * @since 1/15/05
  128. * @param $node The current node we are looking at
  129. **/
  130. function SERVICE_GETARTISTMETADATA_yahoo($node, $displayOutput, $return = false){
  131. global $include_path;
  132. // let's set the artist we're looking at
  133. $artist = $node->getName();
  134. include_once($include_path. "lib/snoopy.class.php");
  135. $snoopy = new Snoopy;
  136. $snoopy->fetch("http://search.music.yahoo.com/search/?m=artist&x=23&y=10&p=". urlencode($artist));
  137. $contents = $snoopy->results;
  138. unset($snoopy);
  139. // Did we get anything?
  140. if (stristr($contents,"no matches found")){
  141. return false;
  142. }
  143. // Ok, now let's see if we got a direct hit or a link
  144. if (stristr($contents,$artist)){
  145. // Now let's see if we can get the right link
  146. $contents = substr($contents,strpos($contents,'<a href=http://music.yahoo.com/') + 8);
  147. $link = trim(substr($contents,0,strpos($contents,">")));
  148. $link = str_replace("---","-bio--",$link);
  149. // Now let's get the bio back
  150. $contents = @file_get_contents($link);
  151. $bio = substr($contents,strpos($contents,'width="401">'));
  152. $bio = substr($bio,strpos($bio,'<td>')+4);
  153. $bio = substr($bio,0,strpos($bio,'</td>'));
  154. // Now let's get the artist image
  155. $image = substr($contents,strpos($contents,'<img src="http://')+10);
  156. $image = substr($image,0,strpos($image,'"'));
  157. if (!stristr($image,".jpg") or !stristr($image,"http://")){
  158. $image = "";
  159. }
  160. // Now let's write the data
  161. if ($return){
  162. if ($return == "array"){
  163. $retArr['bio'] = $bio;
  164. $retArr['image'] = $image;
  165. return $retArr;
  166. } else {
  167. return $$return;
  168. }
  169. return $$return;
  170. } else {
  171. $artReturn = writeArtistMetaData($node, $image, $bio, $displayOutput);
  172. }
  173. }
  174. return false;
  175. }
  176. ?>