PageRenderTime 53ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/services/services/metadata/msnmusic.php

https://github.com/jinzora/jinzora3
PHP | 241 lines | 132 code | 40 blank | 69 comment | 19 complexity | ed4e7e42ea6f30a2d68b4b75278c6854 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. * - replaced MSN-code: X-Coder
  13. * - Web: http://www.jinzora.org
  14. * - Documentation: http://www.jinzora.org/docs
  15. * - Support: http://www.jinzora.org/forum
  16. * - Downloads: http://www.jinzora.org/downloads
  17. * - License: GNU GPL <http://www.gnu.org/copyleft/gpl.html>
  18. *
  19. * - Contributors -
  20. * Please see http://www.jinzora.org/team.html
  21. *
  22. * - Code Purpose -
  23. * - This is the leo's lyrics service.
  24. *
  25. * @since 01.14.05
  26. * @author Ross Carlson <ross@jinzora.org>
  27. * @author Ben Dodson <ben@jinzora.org>
  28. */
  29. $jzSERVICE_INFO = array();
  30. $jzSERVICE_INFO['name'] = "music.msn.com";
  31. $jzSERVICE_INFO['url'] = "http://music.msn.com";
  32. define('SERVICE_METADATA_msnmusic','true');
  33. /*
  34. * Gets the metadata for an album
  35. *
  36. * @author Ross Carlson
  37. * @version 1/15/05
  38. * @since 1/15/05
  39. * @param $node The current node we are looking at
  40. * @param $displayOutput Should we dispaly output (defaults to true)
  41. **/
  42. function SERVICE_GETALBUMMETADATA_msnmusic($node, $displayOutput = true, $return = false) {
  43. global $include_path;
  44. // Ok, now we need to see if we are reading a album or an artist
  45. $album = $node->getName();
  46. $parent = $node->getParent();
  47. $artist = $parent->getName();
  48. include_once($include_path. "lib/snoopy.class.php");
  49. // First let's get the artist page
  50. $snoopy = new Snoopy;
  51. $snoopy->fetch("http://music.msn.com/search/all/?ss=". urlencode($artist));
  52. $contents = $snoopy->results;
  53. unset($snoopy);
  54. $retVal=0;
  55. // Now let's fix up the name
  56. $albumName = str_replace("&","&amp;",$album);
  57. $artist = str_replace("&","&amp;",$artist);
  58. // Ok, now let's see if we got a direct hit or a link
  59. if (stristr($contents,$artist)){
  60. // Now let's see if we can get the right link
  61. $contents = substr($contents,strpos($contents,$artist. "</a>")-50);
  62. $link = substr($contents,strpos($contents,"href")+6);
  63. $link = substr($link,0,strpos($link,'"'));
  64. $idartist = substr($link,strpos($link,'=')+1);
  65. // Now let's go to the artist page to get the albums
  66. $snoopy = new Snoopy;
  67. $snoopy->fetch("http://music.msn.com/xml/getartistcontent.aspx?id_type=artist&id=". $idartist. "&contenttype=artistalbums&category=content");
  68. $contents = $snoopy->results;
  69. unset($snoopy);
  70. // Now let's find the album
  71. if (stristr($contents,'album name="'.$album)){
  72. // Now let's get the year
  73. $year = substr($contents,strpos($contents,"reldate=")+9);
  74. $year = substr($year,0,strpos($year,'" id='));
  75. //Album-ID
  76. $link = substr($contents,strpos($contents,'album name="'.$album)+12);
  77. $link = substr($link,strpos($link,'id="')+4);
  78. $idalbum = substr($link,0,strpos($link,'" pop'));
  79. // Now let's get that
  80. $snoopy = new Snoopy;
  81. $snoopy->fetch("http://music.msn.com/album/?album=". $idalbum);
  82. $contents = $snoopy->results;
  83. unset($snoopy);
  84. // Now let's get the album image
  85. $contents = substr($contents,strpos($contents,"http://images.windowsmedia.com"));
  86. $image = substr($contents,0,strpos($contents,'"'));
  87. if (!stristr($image,".jpg") or !stristr($image,"http://")){
  88. $image = "";
  89. }
  90. // Now let's get the rating
  91. $rating = substr($contents,strpos($contents,"AVG=")+4);
  92. $rating = str_replace("_",".",substr($rating,0,strpos($rating,">")));
  93. // Now let's get the review
  94. $snoopy = new Snoopy;
  95. $snoopy->fetch("http://music.msn.com/xml/getalbumcontent.aspx?id_type=album&id=". $idalbum. "&contenttype=review&category=content");
  96. $contents = $snoopy->results;
  97. unset($snoopy);
  98. $contents = "\n\n\n". substr($contents,strpos($contents,'<reviewtext>')+strlen('<reviewtext>'));
  99. $review = substr($contents,0,strpos($contents,"</reviewtext>"));
  100. // Now let's fix the links
  101. $review = str_replace('href=/artist/?','target="_blank" href=http://music.msn.com/artist/?',$review);
  102. $review =html_entity_decode($contents);
  103. // Now that we have all the data we should write it back out
  104. $albumart = $image;
  105. if (!$return){
  106. writeAlbumMetaData($node, $year, $image, false, $review, $rating, false, false, $displayOutput);
  107. } else {
  108. if ($return == "array"){
  109. $retArr['year'] = $year;
  110. $retArr['image'] = $image;
  111. $retArr['review'] = $review;
  112. $retArr['rating'] = $rating;
  113. return $retArr;
  114. } else {
  115. return $$return;
  116. }
  117. }
  118. }
  119. }
  120. return false;
  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_msnmusic($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://music.msn.com/search/all/?ss=". urlencode($artist));
  137. $contents = $snoopy->results;
  138. unset($snoopy);
  139. // Ok, now let's see if we got a direct hit or a link
  140. if (stristr($contents,$artist)){
  141. // Did we get the wrong page?
  142. if (stristr($contents, "Did you mean:")){
  143. $link = substr($contents,strpos($contents,"Did you mean:"));
  144. $link = substr($link,strpos($link,'href="')+6);
  145. $link = substr($link,0,strpos($link,'"'));
  146. $artist = substr($contents,strpos($contents,"Did you mean:"));
  147. $aritst = substr($artist,strpos($artist,'">')+2);
  148. $aritst = substr($aritst,0,strpos($aritst,'</a>'));
  149. // Now let's get that page back
  150. $snoopy = new Snoopy;
  151. $snoopy->fetch("http://music.msn.com". $link);
  152. $contents = $snoopy->results;
  153. unset($snoopy);
  154. }
  155. // Now let's see if we can get the right link
  156. $contents = substr($contents,strpos(strtolower($contents),strtolower($artist). "</a>")-50);
  157. $link = substr($contents,strpos($contents,"href")+6);
  158. $link = substr($link,0,strpos($link,'"'));
  159. if ($link == ""){
  160. return false;
  161. }
  162. // Now let's get that page back
  163. $snoopy = new Snoopy;
  164. $snoopy->fetch("http://music.msn.com". $link);
  165. $contents = $snoopy->results;
  166. unset($snoopy);
  167. // Now let's find the artist image
  168. $contents = substr($contents,strpos($contents,".jpg")-100);
  169. $image = substr($contents,strpos($contents,'src="')+5);
  170. $image = substr($image,0,strpos($image,'"'));
  171. if (!stristr($image,".jpg") or !stristr($image,"http://")){
  172. $image = "";
  173. }
  174. // Now what content?
  175. $idartist = substr($link,strpos($link,'=')+1);
  176. $snoopy = new Snoopy;
  177. $snoopy->fetch("http://music.msn.com/xml/getartistcontent.aspx?id_type=artist&id=". $idartist. '&contenttype=bio&category=content');
  178. $contents = $snoopy->results;
  179. unset($snoopy);
  180. //$contents = substr($contents,strpos($contents,'<td class="p10">')+strlen('<td class="p10">'));
  181. $bio = substr($contents,strpos($contents,'<bio>')+5);
  182. $bio = substr($bio,0,strpos($bio,'</bio>'));
  183. $bio = str_replace('href=/artist/?','target="_blank" href=http://music.msn.com/artist/?',$bio);
  184. $bio = html_entity_decode(str_replace('href=/album/?','target="_blank" href=http://music.msn.com/album/?',$bio));
  185. // Now let's write the data
  186. if ($return){
  187. if ($return == "array"){
  188. $retArr['bio'] = $bio;
  189. $retArr['image'] = $image;
  190. return $retArr;
  191. } else {
  192. return $$return;
  193. }
  194. return $$return;
  195. } else {
  196. $artReturn = writeArtistMetaData($node, $image, $bio, $displayOutput);
  197. }
  198. }
  199. return false;
  200. }
  201. ?>