Esempio n. 1
0
	def process(self):
		print "dir",self.dirname
		self.files = sort.sorted_dir(self.dirname)

		i = 1
		for file in self.files:
			tags = tag.read_tags(os.path.join(self.dirname,file))
			self.fileTags.append(tags)
			trck = tags[tag.TRACK_NUMBER]
			if "/" in trck:
				trck = trck.split("/")[0]
			trck = int(trck)
			if trck != i:
				print "%s Missing an expected track. Expected %d but got %d" % (dir, i, trck)
				fp = open(os.path.expanduser("~/musicproblems"), "a")
				fp.write("%s Missing an expected track. Expected %d but got %d" % (dir, i, trck))
				fp.close()
				return
			releaseid = u"http://musicbrainz.org/release/"+tags[tag.ALBUM_ID]
			i+=1
	
		self.l = Logger(self.dirname, releaseid)

		self.release = lookups.get_release_by_releaseid(releaseid)
		if len(self.files) != len(self.release.tracks):
			self.l.write("Fewer files than the release says (release: %d files %d)" % (len(self.release.tracks), len(self.files)))
			self.l.close()
			return
		
		i=0
		for file in self.files:
			self.test(i, os.path.join(self.dirname, file))
			i+=1

		self.l.close()
Esempio n. 2
0
def tag_sorted_list(list):
	""" Sort a list of files by the track number tag """
	deco = []
	for item in list:
		tags = tag.read_tags(item)
		if tag.TRACK_NUMBER not in tags:
			raise SortFailedException
		tracknum = tags[tag.TRACK_NUMBER]
		deco.append((item, tracknum))

	list = sorted(deco, key=operator.itemgetter(1), cmp=comparator)
	return [i for i, k in list]
Esempio n. 3
0
def tag_sorted_list(list):
    """ Sort a list of files by the track number tag """
    deco = []
    for item in list:
        tags = tag.read_tags(item)
        if tag.TRACK_NUMBER not in tags:
            raise SortFailedException
        tracknum = tags[tag.TRACK_NUMBER]
        deco.append((item, tracknum))

    list = sorted(deco, key=operator.itemgetter(1), cmp=comparator)
    return [i for i, k in list]
def get_metadata(filename):
    print os.path.basename(filename)
    try:
        trackid = tag.read_tags(filename)['MUSICBRAINZ_TRACKID']
    except:
        print "    Track has no tagged musicbrainz track id"
        return {}

    echoprint = echonest.fingerprint(filename)
    if echoprint:
        print "    %s:%s" % (trackid, echoprint)
        return {trackid:echoprint}
    else:
        print "    Not found in echoprint"
        return {}
Esempio n. 5
0
	def import_dir(self, dirname):
		"""Import a directory.  If the first item in this directory is a file
		then it is assumed that the directory is a single album.  Otherwise,
		directories are recursively scanned"""
		print "importing",dirname
		dir = os.listdir(dirname)
		for file in dir:
			fullpath = os.path.join(dirname,file)
			if os.path.isdir(fullpath):
				self.import_dir(fullpath)

			elif os.path.splitext(fullpath)[1].lower() in tag.supported_extensions:
				tags = tag.read_tags(fullpath)
				sql = "insert into best values (?,?,?,?,?,?,?,?)"
				args = self.get_args(tags, fullpath)
				self.conn.execute(sql, args)

		self.conn.commit()
Esempio n. 6
0
    def process(self):
        print "dir", self.dirname
        self.files = sort.sorted_dir(self.dirname)

        i = 1
        for file in self.files:
            tags = tag.read_tags(os.path.join(self.dirname, file))
            self.fileTags.append(tags)
            trck = tags[tag.TRACK_NUMBER]
            if "/" in trck:
                trck = trck.split("/")[0]
            trck = int(trck)
            if trck != i:
                print "%s Missing an expected track. Expected %d but got %d" % (
                    dir, i, trck)
                fp = open(os.path.expanduser("~/musicproblems"), "a")
                fp.write(
                    "%s Missing an expected track. Expected %d but got %d" %
                    (dir, i, trck))
                fp.close()
                return
            releaseid = u"http://musicbrainz.org/release/" + tags[tag.ALBUM_ID]
            i += 1

        self.l = Logger(self.dirname, releaseid)

        self.release = lookups.get_release_by_releaseid(releaseid)
        if len(self.files) != len(self.release.tracks):
            self.l.write(
                "Fewer files than the release says (release: %d files %d)" %
                (len(self.release.tracks), len(self.files)))
            self.l.close()
            return

        i = 0
        for file in self.files:
            self.test(i, os.path.join(self.dirname, file))
            i += 1

        self.l.close()
Esempio n. 7
0
	def _fetchmetadata(self):
		if self.metadata is None:
			self.metadata = tag.read_tags(self.fname)
Esempio n. 8
0
def find_albumart(srcpath, disc, options):
    imageurl = lookups.get_album_art_url_for_asin(disc.asin)
    images = []
    if imageurl is not None:
        print "Downloading album art from %s" % imageurl
        if not options.noact:
            try:
                (fd, tmpfile) = tempfile.mkstemp(suffix=".jpg")
                os.close(fd)
                (f, h) = urllib.urlretrieve(imageurl, tmpfile)
                if h.getmaintype() != "image":
                    print "WARNING: image url returned unexpected mimetype: %s" % h.gettype(
                    )
                    os.unlink(tmpfile)
                else:
                    imagemime = h.gettype()
                    imagepath = tmpfile
                    try:
                        import Image
                        i = Image.open(imagepath)
                        # Sometimes amazon will give us a 1x1 gif as an image.  Ignore.
                        if i.size[0] != 1:
                            images.append(
                                (imagepath, imagemime, True, "amazon"))
                    except ImportError, e:
                        # If the image library isn't there, check the filesize of the 1x1
                        if os.path.getsize(imagepath) != 807:
                            images.append(
                                (imagepath, imagemime, True, "amazon"))
            except:
                print "WARNING: Failed to retrieve coverart (%s)" % imageurl
    if os.path.exists(os.path.join(srcpath, "folder.jpg")):
        print "Found existing image file"
        imagemime = "image/jpeg"
        imagepath = os.path.join(srcpath, "folder.jpg")
        images.append((imagepath, imagemime, False, "local file"))

    dir = sort.sorted_dir(srcpath)
    filetags = tag.read_tags(dir[0])
    if tag.IMAGE in filetags:
        # Yuck
        tagdata = filetags[tag.IMAGE]
        if not isinstance(tagdata, list):
            tagdata = [tagdata]
        for image in tagdata:
            print "Found image embedded in file"
            if image['mime'] == "image/jpeg":
                suffix = ".jpg"
            elif image['mime'] == "image/png":
                suffix = ".png"
            else:
                print "Embeded Image is of unknown Mime Type"
                continue
            if image['pictype'] != 3:
                print "Embeded Image not coverart"
                continue
            (fd, tmpfile) = tempfile.mkstemp(suffix)
            os.write(fd, image['imagedata'])
            os.close(fd)
            images.append((tmpfile, image['mime'], True, "embedded tag"))

    best = find_best_image(images)[0]
    if best[0] is not None:
        util.report("Best cover image: %s (from %s)" % (best[0], best[3]))
    return best
Esempio n. 9
0
def find_albumart(srcpath,disc,options):
	imageurl = lookups.get_album_art_url_for_asin(disc.asin)
	images = []
	if imageurl is not None:
                print "Downloading album art from %s" % imageurl
		if not options.noact:
                        try:
                                (fd,tmpfile) = tempfile.mkstemp(suffix = ".jpg")
                                os.close(fd)
                                (f,h) = urllib.urlretrieve(imageurl, tmpfile)
                                if h.getmaintype() != "image":
                                        print "WARNING: image url returned unexpected mimetype: %s" % h.gettype()
                                        os.unlink(tmpfile)
                                else:
                                        imagemime = h.gettype()
                                        imagepath = tmpfile
					try:
						import Image
						i = Image.open(imagepath)
						# Sometimes amazon will give us a 1x1 gif as an image.  Ignore.
						if i.size[0] != 1:
							images.append((imagepath, imagemime, True, "amazon"))
					except ImportError, e:
						# If the image library isn't there, check the filesize of the 1x1
						if os.path.getsize(imagepath) != 807:
							images.append((imagepath, imagemime, True, "amazon"))
			except:
                                print "WARNING: Failed to retrieve coverart (%s)" % imageurl
	if os.path.exists(os.path.join(srcpath, "folder.jpg")):
		print "Found existing image file"
                imagemime="image/jpeg"
                imagepath = os.path.join(srcpath, "folder.jpg")
		images.append((imagepath, imagemime, False, "local file"))
	
	dir = sort.sorted_dir(srcpath)
	filetags = tag.read_tags(dir[0])
	if tag.IMAGE in filetags:
		# Yuck
		tagdata = filetags[tag.IMAGE]
		if not isinstance(tagdata, list):
			tagdata = [tagdata]
		for image in tagdata:
			print "Found image embedded in file"
			if image['mime'] == "image/jpeg":
				suffix = ".jpg"
			elif image['mime'] == "image/png":
				suffix = ".png"
			else:
				print "Embeded Image is of unknown Mime Type"
				continue
			if image['pictype'] != 3:
				print "Embeded Image not coverart"
				continue
			(fd,tmpfile) = tempfile.mkstemp(suffix)
			os.write(fd, image['imagedata'])
			os.close(fd)
			images.append((tmpfile, image['mime'], True, "embedded tag"))

	best = find_best_image(images)[0]
	if best[0] is not None:
		util.report("Best cover image: %s (from %s)" % (best[0], best[3]))
	return best
Esempio n. 10
0
 def _fetchmetadata(self):
     if self.metadata is None:
         self.metadata = tag.read_tags(self.fname)