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

/services/services/metadata/rs.php

https://github.com/jinzora/jinzora3
PHP | 278 lines | 169 code | 31 blank | 78 comment | 31 complexity | 8c41eb547f076d1b9bdb7c465aea1585 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'] = "Rollingstone.com";
  30. $jzSERVICE_INFO['url'] = "http://www.rollingstone.com";
  31. define('SERVICE_METADATA_rs','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_rs($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->getAncestor("artist");
  46. $artist = $parent->getName();
  47. include_once($include_path. "lib/snoopy.class.php");
  48. $snoopy = new Snoopy;
  49. $snoopy->fetch("http://www.rollingstone.com/?searchtype=RSAlbum&query=". urlencode($album));
  50. $contents = $snoopy->results;
  51. unset($snoopy);
  52. $retVal=0;
  53. // Now let's fix up the name
  54. $albumName = str_replace("&","&amp;",$album);
  55. $artist = str_replace("&","&amp;",$artist);
  56. // Ok, let's see if we got the exact album or a page of possibles
  57. $link = false;
  58. if (strpos($contents,$artist)){
  59. // Ok, we found the album (or we think) now let's move to it
  60. $contents = substr($contents,strpos($contents,'"<strong>')+10);
  61. $contents = substr($contents,strpos($contents,'<tr>')+4);
  62. // Now let's build an array so we can find the right link
  63. $linkArray = explode("</tr>",$contents);
  64. for ($i=0; $i < count($linkArray); $i++){
  65. // Now let's see if this one has our artist
  66. if (stristr($linkArray[$i],$artist)){
  67. // Ok, we've got our block, let's get the link
  68. $link = substr($linkArray[$i],strpos($linkArray[$i],'href="')+6);
  69. $link = substr($link,0,strpos($link,'"'));
  70. break;
  71. }
  72. }
  73. }
  74. // Ok, did we find a link?
  75. if ($link){
  76. $snoopy = new Snoopy;
  77. $snoopy->fetch($link. "?rnd=1107178952184&has-player=true&version=6.0.12.1040");
  78. $contents = $snoopy->results;
  79. unset($snoopy);
  80. // Alright, now let's parse this out
  81. if (strlen($contents) > 0 && strlen($artist) > 0 && stristr($contents, $artist) and stristr($contents,$album)){
  82. // First let's get the album art
  83. $image = substr($contents,strpos($contents,"http://image.listen.com"));
  84. $image = substr($image,0,strpos($image,'"'));
  85. // Now let's get the year
  86. $year = substr($contents,strpos($contents,"Originally released:")+strlen("Originally released:"));
  87. $year = trim(substr($year,0,strpos($year,"<")));
  88. // Now let's get the tracks
  89. $tracks = substr($contents,strpos($contents,"Track List"));
  90. $tracks = substr($tracks,0,strpos($tracks,"Download</a> this album"));
  91. $tArray = explode("</table>",$tracks);
  92. $e=0;
  93. for ($i=0; $i < count($tArray); $i++){
  94. // Let's get the track number
  95. $tNum = substr($tArray[$i],strpos($tArray[$i],"<td"));
  96. $tNum = substr($tNum,strpos($tNum,'">')+2);
  97. $tNum = substr($tNum,0,strpos($tNum,'</'));
  98. // Let's get the track name
  99. $tName = substr($tArray[$i],strpos($tArray[$i],'alt="Audio')+10);
  100. $tName = substr($tName,strpos($tName,'<a')+2);
  101. $tName = substr($tName,strpos($tName,'">')+2);
  102. $tName = substr($tName,0,strpos($tName,'</'));
  103. $trackArray[$e]['number'] = $tNum;
  104. $trackArray[$e]['name'] = $tName;
  105. $e++;
  106. }
  107. // Now let's get the rating
  108. $rating=false;
  109. if (!stristr($contents,"http://i.rollingstone.com/rs/images/ratings/notrated_left_small.gif")){
  110. $rating = substr($contents,strpos($contents,"http://i.rollingstone.com/rs/images/ratings")+strlen("http://i.rollingstone.com/rs/images/ratings")+1);
  111. $rating = substr($rating,0,strpos($rating,'"'));
  112. $rating = (substr($rating,0,1) / 2);
  113. }
  114. // Now let's get the review
  115. $review = substr($contents,strpos($contents,'<div id="storyContainer">')+strlen('<div id="storyContainer">'));
  116. $review = substr($review,strpos($review,'<p>')+3);
  117. $review = trim(substr($review,0,strpos($review,' (RS')));
  118. $review = str_replace("</p>","",$review);
  119. $review = str_replace("<p>","<br><br>",$review);
  120. if ($review == ""){$review=false;}
  121. // Now that we have all the data we should write it back out
  122. if (!$return){
  123. writeAlbumMetaData($node, $year, $image, $trackArray, $review, $rating, false, false, $displayOutput);
  124. return true;
  125. } else {
  126. if ($return == "array"){
  127. $retArr['year'] = $year;
  128. $retArr['image'] = $image;
  129. $retArr['review'] = $review;
  130. $retArr['rating'] = $rating;
  131. return $retArr;
  132. } else {
  133. return $$return;
  134. }
  135. }
  136. }
  137. }
  138. if ($displayOutput) {
  139. ?>
  140. <SCRIPT LANGUAGE=JAVASCRIPT><!--\
  141. als.innerHTML = 'Status: Album not found';
  142. -->
  143. </SCRIPT>
  144. <?php
  145. flushdisplay();
  146. }
  147. return false;
  148. }
  149. /*
  150. * Gets the metadata for an artist
  151. *
  152. * @author Ross Carlson
  153. * @version 1/15/05
  154. * @since 1/15/05
  155. * @param $node The current node we are looking at
  156. * @param $return should we return or write data (defaults to write),
  157. * and if return what do we return (image = binaryImageData, genre, description)
  158. **/
  159. function SERVICE_GETARTISTMETADATA_rs($node = false, $return = false, $artistName = false){
  160. global $include_path;
  161. // Let's up the max execution time...
  162. ini_set('max_execution_time','600');
  163. // let's set the artist we're looking at
  164. if ($node){
  165. $artist = $node->getName();
  166. } else {
  167. $artist = $artistName;
  168. }
  169. include_once($include_path. "lib/snoopy.class.php");
  170. // Now let's open it up
  171. $snoopy = new Snoopy;
  172. $snoopy->fetch("http://www.rollingstone.com/?searchtype=RSArtist&query=". urlencode($artist));
  173. $contents = $snoopy->results;
  174. unset($snoopy);
  175. // Now let's fix up the name
  176. $albumName = str_replace("&","&amp;",$album);
  177. $artist = str_replace("&","&amp;",$artist);
  178. // Ok, let's see if we got the exact album or a page of possibles
  179. $link = false;
  180. if (strpos($contents,$artist)){
  181. // Ok, we found the album (or we think) now let's move to it
  182. $contents = substr($contents,strpos($contents,'"<strong>')+10);
  183. $contents = substr($contents,strpos($contents,'<tr>')+4);
  184. // Now let's build an array so we can find the right link
  185. $linkArray = explode("</tr>",$contents);
  186. for ($i=0; $i < count($linkArray); $i++){
  187. // Now let's see if this one has our artist
  188. if (stristr($linkArray[$i],$artist)){
  189. // Ok, we've got our block, let's get the link
  190. $link = substr($linkArray[$i],strpos($linkArray[$i],'href="')+6);
  191. $link = substr($link,0,strpos($link,'"'));
  192. break;
  193. }
  194. }
  195. }
  196. // Ok, did we find a link?
  197. if ($link){
  198. $snoopy = new Snoopy;
  199. $snoopy->fetch($link. "?rnd=1107178952184&has-player=true&version=6.0.12.1040");
  200. $contents = $snoopy->results;
  201. unset($snoopy);
  202. // First let's get the artist image
  203. $image = substr($contents,strpos($contents,'class="artistName">')+20);
  204. $image = substr($image,strpos($image,'src="')+5);
  205. $image = substr($image,0,strpos($image,'"'));
  206. // Now let's get the bio from that link
  207. $bioLink = substr($contents,strpos($contents,'/artist/bio/'));
  208. $bioLink = "http://www.rollingstone.com". substr($bioLink,0,strpos($bioLink,'"'));
  209. $snoopy = new Snoopy;
  210. $snoopy->fetch($bioLink);
  211. $contents = $snoopy->results;
  212. unset($snoopy);
  213. // Now let's get the bio
  214. $bio = substr($contents,strpos($contents,'<div class="bio">')+strlen('<div class="bio">'));
  215. $bio = substr($bio,0,strpos($bio,"</"));
  216. // Now let's find the similar artists
  217. $similar = substr($contents,strpos($contents,'contemporaries.gif')+30);
  218. $similar = substr($similar,strpos($similar,'</td>')+5);
  219. $simArray = explode("</tr>",$similar);
  220. for ($i=0; $i < count($simArray); $i++){
  221. if (stristr($simArray[$i],"title=") and !stristr($simArray[$i],"<img class")){
  222. $sim = substr($simArray[$i],strpos($simArray[$i],'<a')+2);
  223. $sim = substr($sim,strpos($sim,'">')+2);
  224. $sim = substr($sim,0,strpos($sim,'</'));
  225. }
  226. }
  227. // Now let's get the genre
  228. $genre = substr($contents, strpos($contents,"Genre:")+7);
  229. $genre = substr($genre,strpos($genre,'">')+2);
  230. $genre = substr($genre,0,strpos($genre,','));
  231. // Now let's write the data
  232. if ($return){
  233. if ($return == "array"){
  234. $retArr['bio'] = $bio;
  235. $retArr['image'] = $image;
  236. $retArr['genre'] = $genre;
  237. return $retArr;
  238. } else {
  239. return $$return;
  240. }
  241. } else {
  242. $artReturn = writeArtistMetaData($image, $bio, $genre, $node, $return);
  243. }
  244. }
  245. return false;
  246. }
  247. ?>