예제 #1
0
class AudioCollection :

	def __init__(self) :
		self.rdf = RdfFile()
		self.processed = 0
		self.succeeded = 0
		
	def walk(self, commandName, filepath):
		if os.path.isdir(filepath):
			dcount=0; fcount=0
			for root,dirs,files in os.walk(filepath) :
				info("Considering "+root)
				dcount+=1
				if self.rdf.open(os.path.join(root,"info_"+commandName+".rdf")):
					for name in files :
						filename = os.path.join(root,name)
						if (re.match(excludeRE, name) == None):
							mi = getattr(self, commandName)(filename)
							self.rdf.addMusicInfo(mi)
							fcount+=1
					self.rdf.write()
					self.rdf.clear()
					
			info("Succeeded for %d/%d files across %d directories.", self.succeeded, fcount, dcount)
		else:
			error("Filepath given is not a directory ! "+filepath)

	def clean(self, filepath):
		if os.path.isdir(filepath):
			dcount=0; fcount=0
			for root,dirs,files in os.walk(filepath) :
				dcount+=1
				for f in files:
					if f.find("info_") != -1 and f.find(".rdf") != -1:
						os.remove(os.path.join(root,f))
						fcount+=1
			info("Removed %d files across %d directories.", fcount, dcount)
		elif os.path.exists(filepath) and filepath.find("info_") != -1 and filepath.find(".rdf") != -1:
			os.remove(filepath)
		else:
			error("Filepath given is not a directory or an rdf file ! "+filepath)		
	
	def metadata(self, filename) :
		debug("Considering "+filename)
		mi = MusicInfo()
		try :
			lookup = MbzTrackLookup(filename)
			mbzuri = lookup.getMbzTrackURI()
			mbzconvert = MbzURIConverter(mbzuri)
			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)
		except FileTypeException, e:
			error(" - " + e.message)
예제 #2
0
 def __init__(self):
     self.rdf = RdfFile()
     self.processed = 0
     self.succeeded = 0
예제 #3
0
class AudioCollection:
    def __init__(self):
        self.rdf = RdfFile()
        self.processed = 0
        self.succeeded = 0

    def walk(self, commandName, filepath):
        if os.path.isdir(filepath):
            dcount = 0
            fcount = 0
            for root, dirs, files in os.walk(filepath):
                info("Considering " + root)
                dcount += 1
                if self.rdf.open(
                        os.path.join(root, "info_" + commandName + ".rdf")):
                    for name in files:
                        filename = os.path.join(root, name)
                        if (re.match(excludeRE, name) == None):
                            mi = getattr(self, commandName)(filename)
                            self.rdf.addMusicInfo(mi)
                            fcount += 1
                    self.rdf.write()
                    self.rdf.clear()

            info("Succeeded for %d/%d files across %d directories.",
                 self.succeeded, fcount, dcount)
        else:
            error("Filepath given is not a directory ! " + filepath)

    def clean(self, filepath):
        if os.path.isdir(filepath):
            dcount = 0
            fcount = 0
            for root, dirs, files in os.walk(filepath):
                dcount += 1
                for f in files:
                    if f.find("info_") != -1 and f.find(".rdf") != -1:
                        os.remove(os.path.join(root, f))
                        fcount += 1
            info("Removed %d files across %d directories.", fcount, dcount)
        elif os.path.exists(filepath) and filepath.find(
                "info_") != -1 and filepath.find(".rdf") != -1:
            os.remove(filepath)
        else:
            error("Filepath given is not a directory or an rdf file ! " +
                  filepath)

    def metadata(self, filename):
        debug("Considering " + filename)
        mi = MusicInfo()
        try:
            lookup = MbzTrackLookup(filename)
            mbzuri = lookup.getMbzTrackURI()
            mbzconvert = MbzURIConverter(mbzuri)
            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)
        except FileTypeException, e:
            error(" - " + e.message)
예제 #4
0
	def __init__(self) :
		self.rdf = RdfFile()
		self.processed = 0
		self.succeeded = 0
예제 #5
0
class AudioCollection :

	def __init__(self) :
		self.rdf = RdfFile()
		self.processed = 0
		self.succeeded = 0
		
	def walk(self, commandName, filepath, CSVoutput=False, singleOut=False):
		dcount=0; fcount=0
		if os.path.isdir(filepath):
			if singleOut:
				if self.rdf.open(os.path.join(filepath,"info_"+commandName+".rdf")):
					for root,dirs,files in os.walk(filepath) :
						info("Considering "+root)
						dcount+=1
						for name in files :
							filename = os.path.join(root,name)
							if (re.match(excludeRE, name) == None):
								mi = getattr(self, commandName)(filename)
								self.rdf.addMusicInfo(mi)
								fcount+=1
					self.rdf.write()
					self.rdf.clear()
			else:
				for root,dirs,files in os.walk(filepath) :
					info("Considering "+root)
					dcount+=1
					if self.rdf.open(os.path.join(root,"info_"+commandName+".rdf")):
						for name in files :
							filename = os.path.join(root,name)
							if (re.match(excludeRE, name) == None):
								mi = getattr(self, commandName)(filename)
								self.rdf.addMusicInfo(mi)
								fcount+=1
						self.rdf.write()
						self.rdf.clear()
		else:
			if filepath.endswith('.csv') and commandName == "metadata":
				f=open(filepath)
				if CSVoutput:
					f_out=open('info_metadata.csv','w')
				else:
					if not self.rdf.open("info_"+commandName+".rdf"):
						error("Existing info_"+commandName+".rdf file found !")
						raise Exception("Couldn't create output file !")
				try:
					for line in f:
						fields = parse_csv(line)
						res = self.metadata(fields["URI"], fields, just_URI=CSVoutput)
						if CSVoutput:
							f_out.write(fields["URI"]+","+res+"\n")
						else:
							self.rdf.addMusicInfo(res)
						fcount+=1
					if not CSVoutput:
						self.rdf.write()
						self.rdf.clear()
				except Exception, e:
					error("Malformed CSV !")
					raise
			else: