def __init__(self): self.exclude_folders = [] self.all_extensions = [] self.picture_extensions = [] self.video_extensions = [] self.lists_separator = "||" self.picsdeleted = 0 self.picsupdated = 0 self.picsadded = 0 self.picsscanned = 0 self.current_root_entry = 0 self.total_root_entries = 0 self.totalfiles = 0 for path,recursive,update,exclude in mpdb.RootFolders(): if exclude: self.exclude_folders.append(smart_unicode(path)) for ext in Addon.getSetting("picsext").split("|"): self.picture_extensions.append("." + ext.replace(".","").upper()) for ext in Addon.getSetting("vidsext").split("|"): self.video_extensions.append("." + ext.replace(".","").upper()) self.use_videos = Addon.getSetting("usevids") self.all_extensions.extend(self.picture_extensions) self.all_extensions.extend(self.video_extensions) self.filescanner = Scanner()
def _addpath(self, path, parentfolderid, recursive, update): dirnames = [] filenames = [] fullpath = [] uniquedirnames = [] olddir = '' path = smart_unicode(path) # Check excluded paths if path in self.exclude_folders: self.picsdeleted = self.picsdeleted + mpdb.RemovePath(path) return (dirnames, filenames) = self.filescanner.walk(path, False, self.picture_extensions if self.use_videos == "false" else self.all_extensions) # insert the new path into database foldername = smart_unicode(os.path.basename(path)) if len(foldername)==0: foldername = os.path.split(os.path.dirname(path))[1] folderid = mpdb.DB_folder_insert(foldername, path, parentfolderid, 1 if len(filenames)>0 else 0 ) # get currently stored files for 'path' from database. # needed for 'added', 'updated' or 'deleted' decision filesfromdb = mpdb.DB_listdir(smart_unicode(path)) # scan pictures and insert them into database if filenames: for pic in filenames: self.picsscanned += 1 filename = smart_unicode(os.path.basename(pic)) extension = os.path.splitext(pic)[1].upper() if filename in filesfromdb: if update: sqlupdate = True self.picsupdated += 1 filesfromdb.pop(filesfromdb.index(filename)) else: filesfromdb.pop(filesfromdb.index(filename)) continue else: sqlupdate = False self.picsadded += 1 picentry = { "idFolder": folderid, "strPath": path, "strFilename": filename, "ftype": extension in self.picture_extensions and "picture" or extension in self.video_extensions and "video" or "", "DateAdded": strftime("%Y-%m-%d %H:%M:%S"), "Thumb": "", "ImageRating": None } # get the meta tags. but only for pictures try: if extension in self.picture_extensions: (file, isremote) = self.filescanner.getlocalfile(pic) self.log("Scanning file %s"%smart_utf8(file)) tags = self._get_metas(smart_unicode(file)) picentry.update(tags) # if isremote == True then the file was copied to cache directory. if isremote: self.filescanner.delete(file) except Exception,msg: print msg pass mpdb.DB_file_insert(path, filename, picentry, sqlupdate) straction = __language__(30242)#Updating if self.scan and self.totalfiles!=0 and self.total_root_entries!=0: self.scan.update(int(100*float(self.picsscanned)/float(self.totalfiles)),#cptscanned-(cptscanned/100)*100, #cptscanned/100, int(100*float(self.current_root_entry)/float(self.total_root_entries)), __language__(30000)+"[%s] (%0.2f%%)"%(straction,100*float(self.picsscanned)/float(self.totalfiles)),#"MyPicture Database [%s] (%0.2f%%)" filename)