Пример #1
0
	def metadata(self, filename, true_md=None, just_URI=False) :
		debug("Considering "+filename)
		mi = MusicInfo()
		try :
			lookup = MbzTrackLookup(filename,true_md)
			mbzuri = lookup.getMbzTrackURI()
			mbzconvert = MbzURIConverter(mbzuri)
			if just_URI:
				return mbzconvert.getURI()
			if (filename.startswith("http://")):
				af = AudioFile(filename)
			else:
				af = AudioFile(urlencode(os.path.basename(filename)))
			mbz = Track(mbzconvert.getURI())
			mbz.available_as = af
			mi.add(af); mi.add(mbz)
			self.succeeded+=1
		except MbzLookupException, e:
			error(" - " + e.message)
Пример #2
0
	def fpFile(self, filename):
		"""Looks up the MusicDNS PUID for the given filename using fingerprinting
		   and stores the resulting info in the given graph"""
		global genpuidbin, MusicDNSKey
		
		track = Track()
		audiofile = AudioFile(urlencode(os.path.basename(filename)))
		track.available_as = audiofile
		signal = Signal()
		signal.published_as = track
		mi = MusicInfo([track, audiofile, signal])
		
		filename = clean(filename)
		# TODO : If file isn't a WAV or MP3, use suitable decoder, and then pass the resulting wav to genpuid.
		res_xml = os.popen(genpuidbin + " " + MusicDNSKey + " -rmd=2 -xml -noanalysis \""+filename+"\"").readlines()
			
		retry_count=0
		while ("".join(res_xml).find("unanalyzable") > 0) and (retry_count < 5):
			warning("MusicDNS reports file is unanalyzable. Trying again...") # This can be caused by server hiccups
			retry_count+=1
			res_xml = os.popen(genpuidbin + " " + MusicDNSKey + " -rmd=2 -xml -noanalysis \""+filename+"\"").readlines()

		# parse results
		try:
			if (res_xml[0] == res_xml[1]):
				res_xml=res_xml[1:] # oddly, we see "<genpuid songs="1">\n" twice when the file is "unanalyzable"

			clean_xml = "".join(res_xml).replace("mip:","") # strip out unknown prefix so minidom can parse
			dom = xml.dom.minidom.parseString(clean_xml)
	
			root = dom.getElementsByTagName("genpuid")[0]

			if (root.hasAttribute("songs") == False) or (int(root.getAttribute("songs")) == 0):
				return MusicInfo()
			
			trackelem = root.getElementsByTagName("track")[0]
			
			if (trackelem.childNodes[0].nodeName=="#text") and (trackelem.childNodes[0].data == "unavailable"):
				info(" No PUID available for track : "+str(trackelem.childNodes[0].data))
				return MusicInfo()
			
			titles = trackelem.getElementsByTagName("title")
			if len(titles)>0:
				track.title = titles[0].childNodes[0].wholeText
			
			artists = trackelem.getElementsByTagName("artist")
			if len(artists)>0:
				artistobj=MusicArtist()
				artistobj.name = artists[0].getElementsByTagName("name")[0].childNodes[0].wholeText
				mi.add(artistobj)
				track.maker = artistobj
			
			puid_list = trackelem.getElementsByTagName("puid-list")
			puid_nodes = puid_list[0].getElementsByTagName("puid")
			puids = []
			
			for puid_node in puid_nodes:
				puids.append(puid_node.getAttribute("id"))
			if len(puids) == 0:
				info(" No PUID available for track : "+str(trackelem.childNodes[0].data))
				return MusicInfo()
		 	elif len(puids) > 1:
				warning("Multiple PUIDs returned for track !")
				
			puid = puids[0]
			signal.puid = puid
			

			# FIXME
			# years = trackelem.getElementsByTagName("first-release-date")
			# if len(years)>0:
			# 	year = years[0].childNodes[0].wholeText
			# else:
			# 	year = None

			# FIXME
			# release_dates = trackelem.getElementsByTagName("first-release_date")
			# if len(release_dates)>0:
			# 	release_date = release_dates[0]
			# else:
			# 	release_date = None
		
			# FIXME
			# genres = []
			# genre_lists = trackelem.getElementsByTagName("genre-list")
			# if len(genre_lists)>0:
			# 	for genre_list in genre_lists:
			# 		genre_nodes = genre_list.getElementsByTagName("genre")
			# 		for genre_node in genre_nodes:
			# 			genres.append(genre_node.getElementsByTagName("name")[0].childNodes[0].wholeText)
				
		except Exception, e:
			error("Failure while parsing results !")
			debug("xml :\n"+"".join(res_xml))
			error(str(e))
			return MusicInfo()