Ejemplo n.º 1
0
def get_metas(dirname, picfile):
    picentry = {}
    ### chemin de la miniature
    extension = splitext(picfile)[1].upper()

    # si le fichier est une vidéo,
    if extension in vidsext:
        picentry.update(
            {"EXIF DateTimeOriginal": strftime("%Y-%m-%d %H:%M:%S", gmtime(stat(join(dirname, picfile)).st_mtime))}
        )
    # si le fichier est une image
    elif extension in picsext:
        thumbnails = Thumbnails()
        # picentry["Thumb"]=thumbnails.get_cached_picture_thumb( join(dirname,picfile) ).decode("utf8")

        ###############################
        #    getting  EXIF  infos     #
        ###############################
        # reading EXIF infos
        #   (file fields are creating if needed)

        try:
            exif = MPDB.get_exif(join(dirname, picfile))

            # EXIF infos are added to a dictionnary
            picentry.update(exif)
        except:
            print "Exception thrown from MPDB.get_exif"

        ###############################
        #    getting  IPTC  infos     #
        ###############################
        try:
            iptc = MPDB.get_iptc(dirname, picfile)

            # IPTC infos are added to a dictionnary
            picentry.update(iptc)
        except:
            print "Exception thrown from MPDB.get_iptc"

        ###############################
        #    getting  XMP infos       #
        ###############################
        try:
            xmp = MPDB.get_xmp(dirname, picfile)
            picentry.update(xmp)
        except:
            print "Exception thrown from MPDB.get_xmp"

    else:
        picentry = {}
        # this should never happen
        MPDB.log("file was neither of video type, nor picture type... Check the extensions in settings", LOGNOTICE)

    return picentry
 def onAction( self, action ):
     #try:
         # Cancel
         if ( action.getId() in CANCEL_DIALOG or self.getFocusId() == BUTTON_CANCEL and action.getId() in SELECT_ITEM ):
             array = []
             self.close()
         # Okay
         if ( self.getFocusId() == BUTTON_OK and action.getId() in SELECT_ITEM ):
             self.close()
         
         # Select or deselect item in list
         if ( action.getId() in SELECT_ITEM and self.getFocusId() == TAGS_LIST ):
             item = self.getControl( TAGS_LIST ).getSelectedItem()
             pos  = self.getControl( TAGS_LIST ).getSelectedPosition()
             
             kb = xbmc.Keyboard(item.getLabel2(),  _(30623)%( decoder.smart_utf8(item.getLabel())), False)
             kb.doModal()
             if (kb.isConfirmed()):
                 item.setLabel2(kb.getText())
                 MPDB.setTranslatedTagType(decoder.smart_unicode(item.getLabel()), decoder.smart_unicode(item.getLabel2()))
                 self.getControl( TAGS_LIST ).setVisible(False)
                 self.getControl( TAGS_LIST ).setVisible(True)
    def setup_all( self ):

        self.getControl( STATUS_LABEL ).setLabel( _(30620) )
        self.getControl( STATUS_LABEL2 ).setLabel( _(30622) )
        self.getControl( BUTTON_OK ).setLabel( _(30621) )
        self.getControl( TAGS_LIST ).reset()
        
        TagTypesAndTranslation =  MPDB.getTagTypesForTranslation()
        TotalTagTypes = len(TagTypesAndTranslation)
        i=0
        for TagTypeAndTranslation in TagTypesAndTranslation:
            listitem = xbmcgui.ListItem( label=TagTypeAndTranslation[0], label2=TagTypeAndTranslation[1]) 
            self.getControl( TAGS_LIST ).addItem( listitem )

        self.setFocus( self.getControl( TAGS_LIST ) )
        self.getControl( TAGS_LIST ).selectItem( 0 )
Ejemplo n.º 4
0
 def loadTagContentList(self, tagType) :
 
     self.getControl( TAGS_CONTENT_LIST ).reset()
     TagContents = [u"%s"%k  for k in MPDB.list_Tags(tagType)]
     TotalTagContents = len(TagContents)
     self.CurrentlySelectedTagType = tagType
     
     for TagContent in TagContents:
             
         TagContentItem = xbmcgui.ListItem( label=tagType, label2=TagContent) 
         TagContentItem.setProperty( "summary", TagContent )    
         
         if self.isContentChecked(tagType, TagContent) == 0:
             TagContentItem.setProperty( "checked", "transparent.png")
         else:
             TagContentItem.setProperty( "checked", "checkbutton.png")
         
         self.getControl( TAGS_CONTENT_LIST ).addItem( TagContentItem )
Ejemplo n.º 5
0
    def setup_all( self ):
        self.getControl( STATUS_LABEL ).setLabel( _(30610) )
        self.getControl( TAGS_COLUMN ).setLabel(  _(30601) )        
        self.getControl( CONTENT_COLUMN ).setLabel( _(30602) )        
        self.getControl( BUTTON_OK ).setLabel( _(30613) )
        self.getControl( BUTTON_CANCEL ).setLabel( _(30614) )
        self.getControl( BUTTON_MATCHALL ).setLabel( _(30615) )
        self.getControl( TAGS_LIST ).reset()

        
        self.TagTypes = [u"%s"%k  for k in MPDB.list_TagTypes()]
        self.CurrentlySelectedTagType = ''
        self.checkedTags = 0
        self.bAnd = False
        self.CheckTagNames = {}
        
        if self.checkedTags == 1:
            self.getControl( CHECKED_LABEL ).setLabel(  _(30611) )
        else:
            self.getControl( CHECKED_LABEL ).setLabel(  _(30612)% (self.checkedTags) )
        
        
        TotalTagTypes = len(self.TagTypes)
        i = 0
        for TagType in self.TagTypes:
            TagTypeItem = xbmcgui.ListItem( label=TagType)   
            TagTypeItem.setProperty( "checked", "transparent.png")
            self.getControl( TAGS_LIST ).addItem( TagTypeItem )

            if i == 0:
                self.loadTagContentList(TagType)
                i=1;

            self.setFocus( self.getControl( TAGS_LIST ) )
            self.getControl( TAGS_LIST ).selectItem( 0 )
            self.getControl( TAGS_CONTENT_LIST ).selectItem( 0 )
Ejemplo n.º 6
0
 def __init__(self, xml, cwd, default):
     xbmcgui.WindowXMLDialog.__init__(self)
     self.MPDB = MypicsDB.MyPictureDB()
Ejemplo n.º 7
0
def browse_folder(dirname,parentfolderID=None,recursive=True,updatepics=False,addpics=True,delpics=True,rescan=False,updatefunc=None,dateadded = strftime("%Y-%m-%d %H:%M:%S")):
    """Browse the root folder 'dirname'
    - 'recursive' : the scan is recursive. all the subfolders of 'dirname' are traversed for pics
    - 'updatepics' : enable to modify a picture entry if metas changed
    - 'rescan' : force the scan wheter pictures are already inside DB or not
    - 'addpics' :
    - 'delpics' :
    - 'dateadded' : the date when the pictures are scanned (useful for subfolders calls to keep the same date as the main root folder)
    - 'updatefunc' is a function called to show the progress of the scan. The parameters are : pourcentage(int),[ line1(str),line2(str),line3(str) ] )
    """
    global compte,comptenew,cptscanned,cptdelete,cptchanged,cptroots,iroots
    cpt=0
    #on liste les fichiers jpg du dossier
    listfolderfiles=[]
    sys_enc = sys.getfilesystemencoding()
    dirname = smart_unicode(dirname)

    #print "In browse_folder"

    #######
    # Pre STEP: cleanup keywords in database
    #######
    MPDB.DB_cleanup_keywords()

    #######
    # STEP 0 : dirname should not be one of those which are excluded from scan !
    #######
    # TODO : if the path was already scanned before, we need to remove previously added pictures AND subfolders
    if dirname in Exclude_folders:
        #print "dirname in Exclude_folders"
        cptdelete = cptdelete + MPDB.RemovePath(dirname)
        return
    #######
    # STEP 1 : list all files in directory
    #######

    # This conversion is important for windows to get filenames in utf-8 encoding!
    if type(dirname).__name__ == "str":
        dirname = unicode(dirname, 'utf-8')
    try:
        dirname = smart_unicode(dirname)
        try:
            listdir = oslistdir(dirname)
        except:
            listdir = oslistdir(dirname.encode('utf-8'))
        # pretty stupid, but is a must.
        for index in range(len(listdir)):
            listdir[index] = smart_unicode(listdir[index])

    except:
        print_exc()
        MPDB.log( "Error while trying to get directory content" )
        listdir=[]



    #######
    # STEP 2 : Keep only the files with extension...
    #######
    for f in listdir:
        if splitext(f)[1].upper() in listext:
            listfolderfiles.append(f)


    #on récupère la liste des fichiers entrées en BDD pour le dossier en cours
    listDBdir = MPDB.DB_listdir(dirname)# --> une requête pour tout le dossier

    #######
    # STEP 3 : If folder contains pictures, create folder in database
    #######
    #on ajoute dans la table des chemins le chemin en cours
    PFid = MPDB.DB_folder_insert(basename(dirname) or osdirname(dirname).split(separator)[-1],
                            dirname,
                            parentfolderID,
                            listfolderfiles and "1" or "0"#i
                            )
    if listfolderfiles:#si le dossier contient des fichiers jpg...
        #######
        # STEP 4 : browse all pictures
        #######
        #puis on parcours toutes les images du dossier en cours
        for picfile in listfolderfiles:#... on parcours tous les jpg du dossier
            extension = splitext(picfile)[1].upper()
            if extension in vidsext and Addon.getSetting("usevids") == "false":#si une video mais qu'on ne prend pas les vidéos
                if picfile in listDBdir:
                    listDBdir.pop(listDBdir.index(picfile))
                continue #alors on ne fait rien et on reprend la boucle

            if file_is_accessible(dirname, picfile):
                cptscanned = cptscanned+1
                cpt = cpt + 1
            else:
                MPDB.DB_del_pic(dirname,picfile)
                cptdelete=cptdelete+1

            ###if updatefunc and updatefunc.iscanceled(): return#dialog progress has been canceled
            #on enlève l'image traitée de listdir
            if len(listdir) > 0:
                listdir.pop(listdir.index(picfile))
                #print "Pop "
                #print smart_unicode(picfile).encode('utf-8')
            if not rescan: #si pas de rescan
                #les images ne sont pas à scanner de force
                if picfile in listDBdir: #si l'image est déjà en base
                    #l'image est déjà en base de donnée
                    if updatepics: #si le paramètre est configuré pour mettre à jour les metas d'une photo
                        #Il faut mettre à jour les images...
                        if extension in vidsext:
                            print "Video"
                            DoScan = True
                            update = True
                            straction = __language__(30242)#Updating
                            if file_is_accessible(dirname, picfile):
                                cptchanged = cptchanged + 1
                        elif not (MPDB.fileSHA(join(dirname,picfile))==MPDB.getFileSha(dirname,picfile)): #si l'image a changé depuis qu'elle est en base
                            print "No Video"
                            #Scan les metas et ajoute l'image avec un paramètre de mise à jour = true
                            DoScan = True
                            update = True
                            straction = __language__(30242)#Updating
                            if file_is_accessible(dirname, picfile):
                                cptchanged = cptchanged + 1                        
                        else:
                            DoScan = False
                            straction = __language__(30243)#"Passing"
                            #mais l'image n'a pas changée. Donc on passe
                    else:
                        DoScan = False
                        straction = __language__(30243)#"Passing"
                        #mais on ne met pas à jour les photos. Donc on passe
                else:
                    DoScan = True
                    update = False
                    straction = __language__(30244)#"Adding"
                    if file_is_accessible(dirname, picfile):
                        comptenew = comptenew + 1
                    #l'image n'est pas dans la base. On l'ajoute maintenant avec paramètre de mise à jour = false
            else:
                DoScan = True
                update = True
                straction = __language__(30245)#"Rescan"
                #on rescan les photos donc on ajoute l'image avec paramètre de mise à jour = true


            if updatefunc and totalfiles!=0 and cptroots!=0:
                updatefunc.update(int(100*float(cptscanned)/float(totalfiles)),#cptscanned-(cptscanned/100)*100,
                                  #cptscanned/100,
                                  int(100*float(iroots)/float(cptroots)),
                                  __language__(30000)+"[%s] (%0.2f%%)"%(straction,100*float(cptscanned)/float(totalfiles)),#"MyPicture Database [%s] (%0.2f%%)"
                                  picfile)
            if DoScan and file_is_accessible(dirname, picfile):
                try:
                    modifiedtime = str(stat(join(dirname,picfile)).st_mtime)
                except:
                    modifiedtime = str(stat(join(dirname.encode('utf-8'),picfile.encode('utf-8'))).st_mtime)

                picentry = { "idFolder":PFid,
                             "strPath":dirname,
                             "strFilename":picfile,
                             "UseIt":1,
                             "sha": extension in picsext and str(MPDB.fileSHA(join(dirname,picfile))) or extension in vidsext and "1" ,
                             #"DateAdded":dateadded,
                             "DateAdded":strftime("%Y-%m-%d %H:%M:%S"),
                             "mtime":modifiedtime,
                             "ftype": extension in picsext and "picture" or extension in vidsext and "video" or ""}




                # get the meta tags
                try:
                    if not extension in vidsext:
                        picentry.update(get_metas(dirname,picfile))
                    # insert picture into table files
                    try:
                        MPDB.DB_file_insert(dirname,picfile,picentry,update)
                    except MPDB.MyPictureDB:
                        pass
                except:
                    print_exc()




            if picfile in listDBdir:
                listDBdir.pop(listDBdir.index(picfile))

        #Now if the database contain some more pictures assign for this folder, we need to delete them if 'update' setting is true
        if listDBdir :#and updatepics: #à l'issu si listdir contient encore des fichiers, c'est qu'ils sont en base mais que le fichier n'existe plus physiquement.
            for f in listDBdir: #on parcours les images en DB orphelines
                cptdelete=cptdelete+1
                if updatefunc and totalfiles!=0 and cptroots!=0:
                    updatefunc.update(int(100*float(cptscanned)/float(totalfiles)),#cptscanned-(cptscanned/100)*100,
                                      #cptscanned/100,
                                      int(100*float(iroots)/float(cptroots)),
                                      __language__(30000)+"["+__language__(30246)+"]",#MyPicture Database [Removing]
                                      f)
                MPDB.DB_del_pic(dirname,f)
                MPDB.log( "\t%s has been deleted from database because the file does not exists in this folder. "%f)#f.decode(sys_enc))
            MPDB.log("")


    else:
        MPDB.log( "This folder does not contain any picture :")
        MPDB.log( dirname )
        MPDB.log( "" )

    if cpt:
        MPDB.log( "%s new pictures found in %s"%(str(cpt),dirname) )
        #unicode(info.data[k].encode("utf8").__str__(),"utf8")
        compte=compte+cpt
        cpt=0
    if recursive: #gestion de la recursivité. On rappel cette même fonction pour chaque dossier rencontré
        MPDB.log( "scan the subfolders of :")
        MPDB.log( dirname )
        for item in listdir:
            try:
                joineddir = join(dirname,item)
            except:
                joineddir = join(dirname.encode('utf-8'),item.encode('utf-8'))
                
            joineddir = smart_unicode(joineddir)

            try:
                isjoineddir = isdir(joineddir)
            except:
                isjoineddir = isdir(joineddir.encode('utf-8'))

            if isjoineddir :#un directory
                #browse_folder(dirname,parentfolderID=None,recursive=True,updatepics=False,rescan=False,updatefunc=None)
                browse_folder(joineddir,PFid,recursive,updatepics,addpics,delpics,rescan,updatefunc,dateadded)
            else:
                #listdir contenait un fichier mais pas un dossier
                # inutilisé... on passe pour le moment
                pass