jinzora3 /services/services/metadata/yahoo.php

Language PHP Lines 202
MD5 Hash 914684d113c8c28f74b46e0d65a55991
Repository https://github.com/jinzora/jinzora3.git View Raw File View Project SPDX
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
<?php if (!defined(JZ_SECURE_ACCESS)) die ('Security breach detected.');
	/**
	 * - JINZORA | Web-based Media Streamer -  
	 * 
	 * Jinzora is a Web-based media streamer, primarily desgined to stream MP3s 
	 * (but can be used for any media file that can stream from HTTP). 
	 * Jinzora can be integrated into a CMS site, run as a standalone application, 
	 * or integrated into any PHP website.  It is released under the GNU GPL.
	 * 
	 * - Resources -
	 * - Jinzora Author: Ross Carlson <ross@jasbone.com>
	 * - Web: http://www.jinzora.org
	 * - Documentation: http://www.jinzora.org/docs	
	 * - Support: http://www.jinzora.org/forum
	 * - Downloads: http://www.jinzora.org/downloads
	 * - License: GNU GPL <http://www.gnu.org/copyleft/gpl.html>
	 * 
	 * - Contributors -
	 * Please see http://www.jinzora.org/team.html
	 * 
	 * - Code Purpose -
	 * - This is the leo's lyrics service.
	 *
	 * @since 01.14.05
	 * @author Ross Carlson <ross@jinzora.org>
	 * @author Ben Dodson <ben@jinzora.org>
	 */
	
	$jzSERVICE_INFO = array();
	$jzSERVICE_INFO['name'] = "music.msn.com";
	$jzSERVICE_INFO['url'] = "http://music.msn.com";

	define('SERVICE_METADATA_yahoo','true');

	/*
	 * Gets the metadata for an album
	 * 
	 * @author Ross Carlson
	 * @version 1/15/05
	 * @since 1/15/05
	 * @param $node The current node we are looking at
	 * @param $displayOutput Should we dispaly output (defaults to true)
	 **/	
	function SERVICE_GETALBUMMETADATA_yahoo($node, $displayOutput = true, $return = false) {
		global $include_path;
		
		// Ok, now we need to see if we are reading a album or an artist
	 	$album = $node->getName(); 
		$parent = $node->getParent();
		$artist = $parent->getName();
				
		include_once($include_path. "lib/snoopy.class.php");
		
		// First let's get the artist page
		$snoopy = new Snoopy;
		$snoopy->fetch("http://search.music.yahoo.com/search/?m=album&x=15&y=7&p=". urlencode($album));
		$contents = $snoopy->results;
		unset($snoopy);
		
		// Did we get anything?
		if (stristr($contents,"no matches found")){
			return false;
		}
		
		// Now let's fix up the name
		$albumName = str_replace("&","&amp;",$album);
		$artist = str_replace("&","&amp;",$artist);
		
		// Ok, now let's see if we got a direct hit or a link
		if (!stristr($contents,$artist) or !stristr($contents,$album)){
			// Ok, we missed let's try to mangle the name and try again?
			$album = trim(substr($album,0,strpos($album," -")));
			$snoopy = new Snoopy;
			$snoopy->fetch("http://search.music.yahoo.com/search/?m=album&x=15&y=7&p=". urlencode($album));
			$contents = $snoopy->results;
			unset($snoopy);
		}
		if (!stristr($contents,$artist) or !stristr($contents,$album)){
			// Ok, we missed let's try to mangle the name and try again?
			$album = trim(substr($album,0,strpos($album,"[")));
			$snoopy = new Snoopy;
			$snoopy->fetch("http://search.music.yahoo.com/search/?m=album&x=15&y=7&p=". urlencode($album));
			$contents = $snoopy->results;
			unset($snoopy);
		}
		if (!stristr($contents,$artist) or !stristr($contents,$album)){
			// Ok, we missed let's try to mangle the name and try again?
			$album = trim(substr($album,0,strpos($album,"(")));
			$snoopy = new Snoopy;
			$snoopy->fetch("http://search.music.yahoo.com/search/?m=album&x=15&y=7&p=". urlencode($album));
			$contents = $snoopy->results;
			unset($snoopy);
		}
		if (!stristr($contents,$artist) or !stristr($contents,$album)){
			return false;
		}

		// Now let's move up to the artist and back
		$link = substr($contents,strpos($contents,$artist)-300);
		$link = substr($link,strpos($link,"<a href=http://music.yahoo.com/release")+8);
		$link = substr($link,0,strpos($link,' '));
		if (stristr($link,">")){
			$link = substr($link,0,strpos($link,'>'));
		}
		
		// Now let's get that page
		$contents = @file_get_contents($link);
		
		// Now let's get the image
		$contents = substr($contents,strpos($contents,'onClick="ext_link'));
		$contents = substr($contents,strpos($contents,'Album Release Date')-400);
		$image = substr($contents,strpos($contents,'<img src="http://')+10);
		$image = substr($image,0,strpos($image,'"'));
		
		if (!stristr($image,".jpg") or !stristr($image,"http://")){
			$image = "";
		}
		
		// Now let's get the release year
		$year = substr($contents,strpos($contents,'Album Release Date:&nbsp;')+strlen('Album Release Date:&nbsp;'));
		$year = substr($year,0,strpos($year,'</td>'));
		
		if (!$return){
			writeAlbumMetaData($node, $year, $image, false, false, false, false, false, $displayOutput);
		} else {
			if ($return == "array"){
				$retArr['year'] = $year;
				$retArr['image'] = $image;
				$retArr['review'] = false;
				$retArr['rating'] = false;
				
				return $retArr;
			} else {
				return $$return;
			}
		}
	}

	/*
	 * Gets the metadata for an artist
	 * 
	 * @author Ross Carlson
	 * @version 1/15/05
	 * @since 1/15/05
	 * @param $node The current node we are looking at
	 **/	
	function SERVICE_GETARTISTMETADATA_yahoo($node, $displayOutput, $return = false){
		global $include_path;
		
		// let's set the artist we're looking at
		$artist = $node->getName();
		
		include_once($include_path. "lib/snoopy.class.php");

		$snoopy = new Snoopy;
		$snoopy->fetch("http://search.music.yahoo.com/search/?m=artist&x=23&y=10&p=". urlencode($artist));
		$contents = $snoopy->results;
		unset($snoopy);
		
		// Did we get anything?
		if (stristr($contents,"no matches found")){
			return false;
		}
		
		// Ok, now let's see if we got a direct hit or a link
		if (stristr($contents,$artist)){			
			// Now let's see if we can get the right link
			$contents = substr($contents,strpos($contents,'<a href=http://music.yahoo.com/') + 8);
			$link = trim(substr($contents,0,strpos($contents,">")));
			$link = str_replace("---","-bio--",$link);
			
			// Now let's get the bio back
			$contents = @file_get_contents($link);
			$bio = substr($contents,strpos($contents,'width="401">'));
			$bio = substr($bio,strpos($bio,'<td>')+4);
			$bio = substr($bio,0,strpos($bio,'</td>'));
			
			// Now let's get the artist image
			$image = substr($contents,strpos($contents,'<img src="http://')+10);
			$image = substr($image,0,strpos($image,'"'));
			if (!stristr($image,".jpg") or !stristr($image,"http://")){
				$image = "";
			}
			
			// Now let's write the data
			if ($return){
				if ($return == "array"){
					$retArr['bio'] = $bio;
					$retArr['image'] = $image;					
					return $retArr;
				} else {
					return $$return;
				}
				return $$return;
			} else {
				$artReturn = writeArtistMetaData($node, $image, $bio, $displayOutput);
			}
		}
		return false;	
	}
?>
Back to Top