Esempio n. 1
0
def main(argv):
	albumDB = albumDatabase.AlbumDatabase()

	for fnam in argv[1:]:
		fnam = os.path.abspath(fnam)
		image = findAlbumImage(fnam)
		if image:
			meta = getMetadata(fnam)
			if meta:
				artist, album = getMetadata(fnam)
				key = albumDatabase.computeKey(artist, album)
				albumDB.add(key, {"artist":artist, "album":album, "url":image})
				print "Set url[%r] = %r" % (fnam, image)
			else:
				print "Couldn't extract metadata from %r" % fnam
		else:
			print "Couldn't find image for %r" % fnam

	albumDB.save()
Esempio n. 2
0
	def do_GET(self):
		(scm, netloc, path, params, query, fragment) = urlparse.urlparse(
			self.path, 'http')

		if scm != 'http' or fragment or not netloc:
			self.send_error(400, "bad url %s" % self.path)
			return

		if (path.find('coverArtMatch') != -1):
			# This is called when we choose "Get Album Artwork" in iTunes.
			queryParts = cgi.parse_qs(query)
			if (("an" in queryParts and "pn" in queryParts) or ("a" in queryParts and "p" in queryParts)):
				if ("an" in queryParts):
					# Imported music
					artist = queryParts['an'][0];
					album = queryParts['pn'][0];
				else:
					# Music from iTunes Store
					artist = queryParts['a'][0];
					album = queryParts['p'][0];
				key = albumDatabase.computeKey(artist, album)
				record = albumDB.get(key)
				if record:
					# If we have selected a cover for this album, send a fake XML response
					# to iTunes, to tell it where to get the cover.
					# This response actually points back to our web UI's /serve URL.
					if "url" in record:
						print "Sending iTunes cover for %s / %s" % (artist, album)
						self.sendXML(self.COVER_INFO_XML % (CoverArtWebUIHandler.SERVER_HOST, CoverArtWebUIHandler.SERVER_PORT, urllib.quote_plus(key)))
					else: self.sendXML(self.NO_COVER_FOUND_XML)
					return
				else:
					# If we haven't selected a cover for this album, add it to our database.
					print "iTunes asked for %s / %s" % (artist, album)
					albumDBLock.acquire()
					albumDB.add(key, {"artist":artist, "album":album})
					albumDBLock.release()
					self.sendXML(self.NO_COVER_FOUND_XML)
					return

		# Otherwise, proxy the request to the real destination.
		soc = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
		self.proxyRequest(soc);