def onAction(self, action):
        # Cancel
        if (action.getId() in CANCEL_DIALOG
                or self.getFocusId() == BUTTON_CANCEL
                and action.getId() in SELECT_ITEM):
            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(),
                common.getstring(30623) % (common.smart_utf8(item.getLabel())),
                False)
            kb.doModal()
            if (kb.isConfirmed()):
                item.setLabel2(kb.getText())
                self.MPDB.set_tagtype_translation(
                    common.smart_unicode(item.getLabel()),
                    common.smart_unicode(item.getLabel2()))
                self.getControl(TAGS_LIST).setVisible(False)
                self.getControl(TAGS_LIST).setVisible(True)
예제 #2
0
    def listdir(self, path):

        try:
            return xbmcvfs.listdir(path)
        except:
            file_list = []
            dir_list  = []
            json_response = xbmc.executeJSONRPC('{ "jsonrpc" : "2.0" , "method" : "Files.GetDirectory" , "params" : { "directory" : "%s" , "sort" : { "method" : "file" } } , "id" : 1 }' % common.smart_utf8(path.replace('\\', '\\\\')))
            jsonobject = json.loads(json_response)

            try:
                if jsonobject['result']['files']:

                    for item in jsonobject['result']['files']:

                        filename = common.smart_utf8(item['label'])
                        if item['filetype'] == 'directory':
                            dir_list.append(filename)
                        else:
                            file_list.append(filename)
                            
            except Exception as msg:
                common.log("Scanner.listdir", 'Path "%s"'%path, xbmc.LOGERROR )
                common.log("Scanner.listdir", "%s - %s"%(Exception,msg), xbmc.LOGERROR )
                
            return dir_list, file_list
예제 #3
0
    def dispatcher(self, options):

        self.options = options

        if self.options.rootpath:
            self.options.rootpath = common.smart_utf8(unquote_plus( self.options.rootpath)).replace("\\\\", "\\").replace("\\\\", "\\").replace("\\'", "\'")
            common.log("VFSScanner.dispatcher", 'Adding path "%s"'%self.options.rootpath, xbmc.LOGNOTICE)
            self.scan = AddonScan()
            self.action = common.getstring(30244)#adding
            self.scan.create( common.getstring(30000) )
            self.current_root_entry = 1
            self.total_root_entries = 1
            self.scan.update(0,0,
                        common.getstring(30000)+" ["+common.getstring(30241)+"]",#MyPicture Database [preparing]
                        common.getstring(30247))#please wait...
            
            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 or self.options.refresh:
            paths = self.mpdb.get_all_root_folders()
            common.log("VFSScanner.dispatcher", "Database refresh started", xbmc.LOGNOTICE)
            self.action = common.getstring(30242)#Updating
            if paths:
                self.scan = AddonScan()
                self.scan.create( common.getstring(30000) )
                self.current_root_entry = 0
                self.total_root_entries = 0
                self.scan.update(0,0,
                            common.getstring(30000)+" ["+common.getstring(30241)+"]",#MyPicture Database [preparing]
                            common.getstring(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()

        # Set default translation for tag types
        self.mpdb.default_tagtypes_translation()
        self.mpdb.cleanup_keywords()

        # delete all entries with "sha is null"
        self.picsdeleted += self.mpdb.del_pics_wo_sha(self.scan_is_cancelled)

        common.log("VFSScanner.dispatcher", common.getstring(30248)%(self.picsscanned,self.picsadded,self.picsdeleted,self.picsupdated), xbmc.LOGNOTICE)
        common.show_notification(common.getstring(30000), common.getstring(30248)%(self.picsscanned,self.picsadded,self.picsdeleted,self.picsupdated) )
예제 #4
0
    def dispatcher(self, options):

        self.options = options

        if self.options.rootpath:
            self.options.rootpath = common.smart_utf8(unquote_plus( self.options.rootpath)).replace("\\\\", "\\").replace("\\\\", "\\").replace("\\'", "\'")
            common.log("VFSScanner.dispatcher", 'Adding path "%s"'%self.options.rootpath, xbmc.LOGNOTICE)
            self.scan = AddonScan()
            self.action = common.getstring(30244)#adding
            self.scan.create( common.getstring(30000) )
            self.current_root_entry = 1
            self.total_root_entries = 1
            self.scan.update(0,0,
                        common.getstring(30000)+" ["+common.getstring(30241)+"]",#MyPicture Database [preparing]
                        common.getstring(30247))#please wait...
            
            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 or self.options.refresh:
            paths = self.mpdb.get_all_root_folders()
            common.log("VFSScanner.dispatcher", "Database refresh started", xbmc.LOGNOTICE)
            self.action = common.getstring(30242)#Updating
            if paths:
                self.scan = AddonScan()
                self.scan.create( common.getstring(30000) )
                self.current_root_entry = 0
                self.total_root_entries = 0
                self.scan.update(0,0,
                            common.getstring(30000)+" ["+common.getstring(30241)+"]",#MyPicture Database [preparing]
                            common.getstring(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()

        # Set default translation for tag types
        self.mpdb.default_tagtypes_translation()
        self.mpdb.cleanup_keywords()

        # delete all entries with "sha is null"
        self.picsdeleted += self.mpdb.del_pics_wo_sha(self.scan_is_cancelled)

        common.show_notification(common.getstring(30000), common.getstring(30248)%(self.picsscanned,self.picsadded,self.picsdeleted,self.picsupdated) )
예제 #5
0
    def getlocalfile(self, filename):
        
        filename = common.smart_unicode(filename)
        
        # Windows NEEDS unicode but OpenElec utf-8
        try:
            exists = os.path.exists(filename)
        except:
            exists = os.path.exists(common.smart_utf8(filename))
        if exists:
            return filename, False
        else:
            tempdir     = xbmcvfs.translatePath('special://temp')
            basefilename    = self.getname(filename)
            destination = os.path.join(tempdir, basefilename)
            xbmcvfs.copy(filename, destination)

            return common.smart_unicode(destination), True
예제 #6
0
    def _addpath(self, path, parentfolderid, recursive, update):
        """
        try:
        """
        path = common.smart_unicode(path)

        common.log("VFSScanner._addpath", '"%s"' % common.smart_utf8(path))
        # Check excluded paths
        if path in self.exclude_folders:
            common.log(
                "VFSScanner._addpath",
                'Path in exclude folder: "%s"' % common.smart_utf8(path))
            self.picsdeleted = self.picsdeleted + self.mpdb.delete_paths_from_root(
                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 = common.smart_unicode(os.path.basename(path))
        if len(foldername) == 0:
            foldername = os.path.split(os.path.dirname(path))[1]

        folderid = self.mpdb.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 = self.mpdb.listdir(common.smart_unicode(path))

        # scan pictures and insert them into database
        if filenames:
            for pic in filenames:
                if self.scan.iscanceled():
                    self.scan_is_cancelled = True
                    common.log("VFSScanner._addpath", "Scanning canncelled",
                               xbmc.LOGNOTICE)
                    return

                if self._check_excluded_files(pic) == False:
                    continue

                self.picsscanned += 1

                filename = os.path.basename(pic)
                extension = os.path.splitext(pic)[1].upper()

                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":
                    "",
                    "Image Rating":
                    None
                }

                sqlupdate = False
                filesha = 0

                # get the meta tags. but only for pictures and only if they are new or modified.
                if extension in self.picture_extensions:

                    common.log(
                        "VFSScanner._addpath",
                        'Scanning picture "%s"' % common.smart_utf8(pic))

                    if pic in filesfromdb:  # then it's an update

                        filesfromdb.pop(filesfromdb.index(pic))

                        if self.options.refresh == True:  # this means that we only want to get new pictures.
                            if self.scan and self.totalfiles != 0 and self.total_root_entries != 0:
                                self.scan.update(
                                    int(100 * float(self.picsscanned) /
                                        float(self.totalfiles)),
                                    int(100 * float(self.current_root_entry) /
                                        float(self.total_root_entries)),
                                    common.smart_utf8(
                                        common.getstring(30000) +
                                        " [%s] (%0.2f%%)" %
                                        (self.action,
                                         100 * float(self.picsscanned) /
                                         float(self.totalfiles))
                                    ),  #"MyPicture Database [%s] (%0.2f%%)"
                                    common.smart_utf8(filename))

                            continue
                        else:
                            (localfile,
                             isremote) = self.filescanner.getlocalfile(pic)

                            filesha = self.mpdb.sha_of_file(localfile)
                            sqlupdate = True

                            if self.mpdb.stored_sha(
                                    path, filename
                            ) != filesha:  # picture was modified
                                self.picsupdated += 1
                                common.log(
                                    "VFSScanner._addpath",
                                    "Picture already exists and must be updated"
                                )

                                tags = self._get_metas(
                                    common.smart_unicode(localfile))
                                picentry.update(tags)

                                # if isremote == True then the file was copied to cache directory.
                                if isremote:
                                    self.filescanner.delete(localfile)

                            else:

                                common.log(
                                    "VFSScanner._addpath",
                                    "Picture already exists but not modified")

                                if self.scan and self.totalfiles != 0 and self.total_root_entries != 0:
                                    self.scan.update(
                                        int(100 * float(self.picsscanned) /
                                            float(self.totalfiles)),
                                        int(100 *
                                            float(self.current_root_entry) /
                                            float(self.total_root_entries)),
                                        common.smart_utf8(
                                            common.getstring(30000) +
                                            " [%s] (%0.2f%%)" %
                                            (self.action,
                                             100 * float(self.picsscanned) /
                                             float(self.totalfiles))
                                        ),  #"MyPicture Database [%s] (%0.2f%%)"
                                        common.smart_utf8(filename))

                                if isremote:
                                    self.filescanner.delete(localfile)

                                continue

                    else:  # it's a new picture

                        (localfile,
                         isremote) = self.filescanner.getlocalfile(pic)
                        filesha = self.mpdb.sha_of_file(localfile)
                        sqlupdate = False
                        common.log("VFSScanner._addpath",
                                   "New picture will be inserted into dB")
                        self.picsadded += 1

                        tags = self._get_metas(common.smart_unicode(localfile))
                        picentry.update(tags)

                        if isremote:
                            self.filescanner.delete(localfile)

                # videos aren't scanned and therefore never updated
                elif extension in self.video_extensions:
                    common.log(
                        "VFSScanner._addpath",
                        'Adding video file "%s"' % common.smart_utf8(pic))

                    if pic in filesfromdb:  # then it's an update
                        sqlupdate = True
                        filesfromdb.pop(filesfromdb.index(pic))
                        continue

                    else:
                        sqlupdate = False
                        self.picsadded += 1
                        moddate = self.filescanner.getfiledatetime(pic)
                        if moddate != "0000-00-00 00:00:00":
                            picentry["EXIF DateTimeOriginal"] = moddate

                else:
                    continue

                try:
                    self.mpdb.file_insert(path, filename, picentry, sqlupdate,
                                          filesha)
                except Exception, msg:
                    common.log("VFSScanner._addpath",
                               'Unable to insert picture "%s"' % pic,
                               xbmc.LOGERROR)
                    common.log("VFSScanner._addpath",
                               '"%s" - "%s"' % (Exception, msg), xbmc.LOGERROR)
                    continue

                if sqlupdate:
                    common.log("VFSScanner._addpath",
                               'Picture "%s" updated' % common.smart_utf8(pic))
                else:
                    common.log(
                        "VFSScanner._addpath",
                        'Picture "%s" inserted' % common.smart_utf8(pic))

                if self.scan and self.totalfiles != 0 and self.total_root_entries != 0:
                    self.scan.update(
                        int(100 * float(self.picsscanned) /
                            float(self.totalfiles)),
                        int(100 * float(self.current_root_entry) /
                            float(self.total_root_entries)),
                        common.smart_utf8(
                            common.getstring(30000) + " [%s] (%0.2f%%)" %
                            (self.action, 100 * float(self.picsscanned) /
                             float(self.totalfiles))
                        ),  #"MyPicture Database [%s] (%0.2f%%)"
                        common.smart_utf8(filename))
    def _addpath(self, path, parentfolderid, recursive, update):

        """
        try:
        """
        path = common.smart_unicode(path)

        common.log("VFSScanner._addpath", '"%s"'%common.smart_utf8(path) )
        # Check excluded paths
        if path in self.exclude_folders:
            common.log("VFSScanner._addpath", 'Path in exclude folder: "%s"'%common.smart_utf8(path) )
            self.picsdeleted = self.picsdeleted + self.mpdb.delete_paths_from_root(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 = common.smart_unicode(os.path.basename(path))
        if len(foldername)==0:
            foldername = os.path.split(os.path.dirname(path))[1]
        
        folderid = self.mpdb.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 = self.mpdb.listdir(common.smart_unicode(path))

        # scan pictures and insert them into database
        if filenames:
            for pic in filenames:
                if self.scan.iscanceled():
                    self.scan_is_cancelled = True
                    common.log( "VFSScanner._addpath", "Scanning canncelled", xbmc.LOGNOTICE)
                    return
                    
                if self._check_excluded_files(pic) == False:
                    continue
                
                self.picsscanned += 1
                
                filename = os.path.basename(pic)
                extension = os.path.splitext(pic)[1].upper()
                    
                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": "",
                             "Image Rating": "0"
                             }


                sqlupdate = False
                filesha   = 0
                
                # get the meta tags. but only for pictures and only if they are new or modified.
                if extension in self.picture_extensions:
                    
                    common.log( "VFSScanner._addpath", 'Scanning picture "%s"'%common.smart_utf8(pic))
                    
                    
                    if pic in filesfromdb: # then it's an update
                        
                        filesfromdb.pop(filesfromdb.index(pic))
                        
                        if self.options.refresh == True: # this means that we only want to get new pictures.
                                if self.scan and self.totalfiles!=0 and self.total_root_entries!=0:
                                    self.scan.update(int(100*float(self.picsscanned)/float(self.totalfiles)),
                                                  int(100*float(self.current_root_entry)/float(self.total_root_entries)),
                                                  common.smart_utf8(common.getstring(30000)+" [%s] (%0.2f%%)"%(self.action,100*float(self.picsscanned)/float(self.totalfiles))),#"MyPicture Database [%s] (%0.2f%%)"
                                                  common.smart_utf8(filename))
                                continue                            
                        else: 
                            (localfile, isremote) = self.filescanner.getlocalfile(pic)
                            
                            filesha = self.mpdb.sha_of_file(localfile) 
                            sqlupdate   = True
                            
                            if self.mpdb.stored_sha(path,filename) != filesha:  # picture was modified

                                self.picsupdated += 1
                                common.log( "VFSScanner._addpath", "Picture already exists and must be updated")
                                
                                tags = self._get_metas(common.smart_unicode(localfile))
                                picentry.update(tags)
            
                                # if isremote == True then the file was copied to cache directory.
                                if isremote:
                                    self.filescanner.delete(localfile)                            
    
                            else:

                                common.log( "VFSScanner._addpath", "Picture already exists but not modified")
    
                                if self.scan and self.totalfiles!=0 and self.total_root_entries!=0:
                                    self.scan.update(int(100*float(self.picsscanned)/float(self.totalfiles)),
                                                  int(100*float(self.current_root_entry)/float(self.total_root_entries)),
                                                  common.smart_utf8(common.getstring(30000)+" [%s] (%0.2f%%)"%(self.action,100*float(self.picsscanned)/float(self.totalfiles))),#"MyPicture Database [%s] (%0.2f%%)"
                                                  common.smart_utf8(filename))
    
                                if isremote:
                                    self.filescanner.delete(localfile)                            
    
                                continue

                    else: # it's a new picture

                        (localfile, isremote) = self.filescanner.getlocalfile(pic)
                        filesha = self.mpdb.sha_of_file(localfile)
                        sqlupdate  = False
                        common.log( "VFSScanner._addpath", "New picture will be inserted into dB")
                        self.picsadded   += 1

                        tags = self._get_metas(common.smart_unicode(localfile))
                        picentry.update(tags)

                        if isremote:
                            self.filescanner.delete(localfile)


                # videos aren't scanned and therefore never updated
                elif extension in self.video_extensions:
                    common.log( "VFSScanner._addpath", 'Adding video file "%s"'%common.smart_utf8(pic))
                    
                    if pic in filesfromdb:  # then it's an update
                        sqlupdate   = True
                        filesfromdb.pop(filesfromdb.index(pic))
                        continue

                    else:
                        sqlupdate  = False
                        self.picsadded   += 1
                        picentry["Image Rating"] = 5
                        moddate = self.filescanner.getfiledatetime(pic)
                        if moddate != "0000-00-00 00:00:00":
                            picentry["EXIF DateTimeOriginal"] = moddate

                else:
                    continue

                try:

                    self.mpdb.file_insert(path, filename, picentry, sqlupdate, filesha)
                except Exception, msg:
                    common.log("VFSScanner._addpath", 'Unable to insert picture "%s"'%pic, xbmc.LOGERROR)
                    common.log("VFSScanner._addpath", '"%s" - "%s"'%(Exception, msg), xbmc.LOGERROR)
                    continue

                if sqlupdate:
                    common.log( "VFSScanner._addpath", 'Picture "%s" updated'%common.smart_utf8(pic))
                else:
                    common.log( "VFSScanner._addpath", 'Picture "%s" inserted'%common.smart_utf8(pic))

                if self.scan and self.totalfiles!=0 and self.total_root_entries!=0:
                    self.scan.update(int(100*float(self.picsscanned)/float(self.totalfiles)),
                                  int(100*float(self.current_root_entry)/float(self.total_root_entries)),
                                  common.smart_utf8(common.getstring(30000)+" [%s] (%0.2f%%)"%(self.action,100*float(self.picsscanned)/float(self.totalfiles))),#"MyPicture Database [%s] (%0.2f%%)"
                                  common.smart_utf8(filename))
예제 #8
0
    def load_map(self):
        #google geolocalisation
        static_url = "http://maps.google.com/maps/api/staticmap?"
        param_dic = {#location parameters (http://gmaps-samples.googlecode.com/svn/trunk/geocoder/singlegeocode.html)
                     "center":"",       #(required if markers not present)
                     "zoom":self.zoomlevel,         # 0 to 21+ (req if no markers
                     #map parameters
                     "size":"640x640",  #widthxheight (required)
                     "format":"jpg",    #"png8","png","png32","gif","jpg","jpg-baseline" (opt)
                     "maptype":"hybrid",      #"roadmap","satellite","hybrid","terrain" (opt)
                     "language":"",
                     #Feature Parameters:
                     "markers" :"color:red|label:P|%s",#(opt)
                                        #markers=color:red|label:P|lyon|12%20rue%20madiraa|marseille|Lille
                                        #&markers=color:blue|label:P|Australie
                     "path" : "",       #(opt)
                     "visible" : "",    #(opt)
                     #Reporting Parameters:
                     "sensor" : "false", #is there a gps on system ? (req)
                     "key" : "AIzaSyDzctQqZnQFZ8iLovgYaJXeeccwpVQVTtk"
                     }

        param_dic["markers"]=param_dic["markers"]%self.place

        request_headers = { 'User-Agent': 'Mozilla/5.0 (Windows; U; Windows NT 6.1; fr; rv:1.9.2.10) Gecko/20100914 Firefox/3.6.10' }
        request = Request(static_url+urlencode(param_dic), None, request_headers)
        common.log("load_map", request, xbmc.LOGINFO)
        try:
            urlfile = urlopen(request)
        except:
            dialog = xbmcgui.Dialog()
            dialog.ok('XBMC Network Error', 'Google maps is not reachable')
            self.close()
            return
            
        extension = urlfile.info().getheader("Content-Type","").split("/")[1]
        filesize = int(urlfile.info().getheader("Content-Length",""))

        mappath = xbmcvfs.translatePath(self.datapath)
        mapfile = join(self.datapath,basename(self.filename).split(".")[0]+"_maps%s."%self.zoomlevel+extension)

        mapfile = xbmcvfs.translatePath(mapfile)

        # test existence of path
        if not os.path.exists(mappath):
            os.makedirs(mappath)
        
        label = self.getControl( LABEL_TEXT )
        if not isfile(mapfile):
            #mapfile is not downloaded yet, download it now...
            try:
                #f=open(unicode(mapfile, 'utf-8'),"wb")
                f=open(common.smart_unicode(mapfile), "wb")
            except:
                try:
                    f=open(common.smart_utf8(mapfile), "wb")
                except:
                    print_exc()
                #print "GEO Exception: "+mapfile
            for i in range(1+(filesize/10)):
                f.write(urlfile.read(10))
                label.setLabel(common.getstring(30221)%(100*(float(i*10)/filesize)))#getting map... (%0.2f%%)
            urlfile.close()
            #pDialog.close()
            try:
                f.close()
            except:
                print_exc()
        self.set_pic(self.filename)
        self.set_map(mapfile)
        label.setLabel(common.getstring(30222)%int(100*(float(self.zoomlevel)/self.zoom_max)))#Zoom level %s