def get_file_without_tags(self,fileid,flags): """ Get a file without any tags from the index. Uses `fileid` to find the file and only flags contained in the list of flags `flags` will be added to this file. """ q = u''' SELECT s.id AS id, s.path AS path, s.name AS name, s.ext AS ext ''' for flag in flags: if flag=='puid': q += u',p.value AS puid' elif flag=='md5': q += u',m.value AS md5' elif flag=='fingerprint': q += u',f.value AS fingerprint' else: q += u','+flag q += u'''\nFROM files AS s LEFT OUTER JOIN puids AS p ON s.puidid = p.id LEFT OUTER JOIN md5s AS m ON s.md5id = m.id LEFT OUTER JOIN fingerprints AS f ON s.fingerprintid = f.id WHERE s.id = %s; ''' self._cursor.execute(q,(fileid,)) res = self._cursor.fetchall() if res==(): return None # now we need to transform the flat db structure # into an object oriented medel file_ = IndexedFile(res[0][0],res[0][1],res[0][2],res[0][3]) i = 4 for flag in flags: file_.flags[flag] = res[0][i] i=i+1 return file_
def parse_file(db,fullname,path,filename,count): print "Indexing file '%s'" % filename print '\tPath:',path print '\tTime:',datetime.now().strftime("%H:%M:%S") name, ext = os.path.splitext(filename) if db.is_file_added(path,name,ext): print "Already added to the database." return count #count isn't incremented # calc the values md5hash, size = calc_md5_and_size(fullname) fingerprint,puid,taggroups,online,playable,duration = musicip.generate_fingerprint_and_lookup_tags_if_online(fullname) taggroups.extend(filetags.guess_from_path_and_name(path,name)) taggroups.extend(metatags.get_from_file(fullname,ext)) musictype = None if playable: if is_file_mp3(fullname): musictype = 'mp3' else: musictype = 'other' # print what we found print '\tPlay:',playable print '\tType:',musictype print '\tOnln:',online print '\tSize:',size/1024/1024,"mb" print '\tMd5 :',md5hash print '\tLen :',duration,'ms' if fingerprint!=None: print '\tPrnt:',fingerprint[:25]+"..."+fingerprint[-25:] if puid!=None: print '\tPUID:',puid print '\tTags:',taggroups # add values to db md5id = db.add_md5(md5hash) puidid = db.add_puid(puid) fingerprintid = db.add_fingerprint(fingerprint) f = IndexedFile(None,path,name,ext) f.flags['size'] = size f.flags['puidid'] = puidid f.flags['md5id'] = md5id f.flags['fingerprintid'] = fingerprintid f.flags['musictype'] = musictype f.flags['musicip_online'] = online f.flags['duration'] = duration f.taggroups = taggroups db.add_file(f) count+=1 print 'Added succesfully with id %s.'%str(count) opts.print_sep() return count