Esempio n. 1
0
def listDisc(artistName):
	artists = Artist.selectBy(name=artistName)
	print "NumArtists=%d" % artists.count()
	for artist in artists:
		print "Artist: %s" % artist.name
		for album in artist.albums:
			print "Album: %s" % album.name
Esempio n. 2
0
def saveDisc(disc_info):
	category = disc_info["category"]
	disc_id = disc_info["disc_id"]
	title = disc_info["title"]
	(artistName, albumName) = disc_info["title"].split("/")
	artistName = artistName.strip()
	albumName = albumName.strip()
	
	#Search for existing artist
	artists = Artist.selectBy(name=artistName)
	if artists.count() == 0:
		#Create artist
		artist = Artist(name=artistName,category=category)
	else:
		#Use existing artist
		artist = artists[0]
		
	#Search for existing album
	albums = Album.selectBy(name=albumName)
	if albums.count() == 0:
		#Create album
		album = Album(disc_id=disc_id,name=albumName,artist=artist)
	
		#Create tracks
		(track_status, track_info) = CDDB.read(category, disc_id)
		tracks = {}
		for (k,v) in track_info.items():
			if k.find("TTITLE") != -1:
				num = int(k[len("TTITLE"):]) + 1
				tracks[num] = v
		
		tracks.items().sort()
		for (k,v) in tracks.items():
		     track = Track(num=k,name=v,album=album)
		     
		print "***Saved in catalogue***"
	else:
		print "***Already catalogued***"
	
	printDisc(disc_info)