def dispatcher(self, options): self.options = options if self.options.rootpath: self.scan = AddonScan() self.scan.create( __language__(30000) ) self.current_root_entry = 1 self.total_root_entries = 1 self.scan.update(0,0, __language__(30000)+" ["+__language__(30241)+"]",#MyPicture Database [preparing] __language__(30247))#please wait... self.options.rootpath = smart_utf8(unquote_plus( self.options.rootpath)).replace("\\\\", "\\").replace("\\\\", "\\").replace("\\'", "\'") self._countfiles(self.options.rootpath) self.total_root_entries = 1 self._addpath(self.options.rootpath, None, self.options.recursive, True) self.scan.close() elif self.options.database: paths = mpdb.RootFolders() if paths: self.scan = AddonScan() self.scan.create( __language__(30000) ) self.current_root_entry = 0 self.total_root_entries = 0 self.scan.update(0,0, __language__(30000)+" ["+__language__(30241)+"]",#MyPicture Database [preparing] __language__(30247))#please wait... for path,recursive,update,exclude in paths: if exclude==0: self.total_root_entries += 1 self._countfiles(path,False) for path,recursive,update,exclude in paths: if exclude==0: try: self.current_root_entry += 1 self._addpath(path, None, recursive, update) except: print_exc() self.scan.close() xbmc.executebuiltin( "Notification(%s,%s)"%(__language__(30000).encode("utf8"), __language__(30248).encode("utf8")%(self.picsscanned,self.picsadded,self.picsdeleted,self.picsupdated) ) )
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)