Exemplo n.º 1
0
    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)
                                                    )
                             )
Exemplo n.º 2
0
def main2():
    #get active window
    import optparse
    global cptroots,iroots
    parser = optparse.OptionParser()
    parser.enable_interspersed_args()
    parser.add_option("--database","-d",action="store_true", dest="database",default=False)
    #parser.add_option("--help","-h")
    parser.add_option("-p","--rootpath",action="store", type="string", dest="rootpath")
    parser.add_option("-r","--recursive",action="store_true", dest="recursive", default=False)
    parser.add_option("-u","--update",action="store_true", dest="update", default=True)
    (options, args) = parser.parse_args()

    #dateadded = strftime("%Y-%m-%d %H:%M:%S")#pour inscrire la date de scan des images dans la base
    if options.rootpath:
        #print "options.rootpath = " + smart_unicode(options.rootpath).encode('utf-8')
        scan = AddonScan()
        scan.create( __language__(30000) )
        cptroots = 1
        iroots = 1
        scan.update(0,0,
                    __language__(30000)+" ["+__language__(30241)+"]",#MyPicture Database [preparing]
                    __language__(30247))#please wait...
        count_files(unquote_plus(options.rootpath),recursive = options.recursive)
        try:
            #browse_folder(dirname,parentfolderID=None,recursive=True,updatepics=False,addpics=True,delpics=True,rescan=False,updatefunc=None)
            #browse_folder(unquote_plus(options.rootpath),parentfolderID=None,recursive=options.recursive,updatepics=options.update,addpics=True,delpics=True,rescan=False,updatefunc=scan,dateadded = dateadded )
            browse_folder(unquote_plus(options.rootpath),parentfolderID=None,recursive=options.recursive,updatepics=True,addpics=True,delpics=True,rescan=False,updatefunc=scan,dateadded = strftime("%Y-%m-%d %H:%M:%S"))#dateadded )
        except:
            print_exc()
        scan.close()


    if options.database:
        #print "options.database"
        listofpaths = MPDB.RootFolders()
        if listofpaths:
            scan = AddonScan()#xbmcgui.getCurrentWindowId()
            scan.create( __language__(30000) )#MyPicture Database
            scan.update(0,0,
                        __language__(30000)+" ["+__language__(30241)+"]",#MyPicture Database [preparing]
                        __language__(30247))#please wait...
            #comptage des fichiers et des dossiers à parcourir
            for path,recursive,update,exclude in listofpaths:
                if exclude==0:
                    cptroots = cptroots + 1
                    count_files(unquote_plus(path),False)
            #print "cptroots"
            #print cptroots
            for path,recursive,update,exclude in listofpaths:
                if exclude==0:
                    #count_files(unquote_plus(path))
                    try:
                        #browse_folder(dirname,parentfolderID=None,recursive=True,updatepics=False,rescan=False,updatefunc=None)
                        iroots=iroots+1
                        browse_folder(unquote_plus(path),parentfolderID=None,recursive=recursive==1,updatepics=update==1,addpics=True,delpics=True,rescan=False,updatefunc=scan,dateadded = strftime("%Y-%m-%d %H:%M:%S"))#dateadded)
                    except:
                        print_exc()

            scan.close()
Exemplo n.º 3
0
class VFSScanner:

    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()
        

    LOGDEBUG = 0
    LOGINFO = 1
    LOGNOTICE = 2
    LOGWARNING = 3
    LOGERROR = 4
    LOGSEVERE = 5
    LOGFATAL = 6
    LOGNONE = 7

    def log(self, msg, level=LOGDEBUG):
        if type(msg).__name__=='unicode':
            msg = msg.encode('utf-8')

        xbmc.log(str("MyPicsDB >> %s"%msg.__str__()), level)


    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 _countfiles(self, path, reset = True, recursive = True):
        if reset:
            self.totalfiles = 0
        
        (dirs, files) = self.filescanner.walk(path, recursive, self.picture_extensions if self.use_videos == "false" else self.all_extensions)
        self.totalfiles += len(files)

        return self.totalfiles


    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)
                
        # all pics left in list filesfromdb weren't found in file system.
        # therefore delete them from db
        if filesfromdb:
            for pic in filesfromdb:
                mpdb.DB_del_pic(path, pic)
                self.picsdeleted += 1

        if recursive:
            for dir in dirnames:
                self._addpath(dir, folderid, True, update)