def set_filter_date(self): dialog = xbmcgui.Dialog() if self.start_date == '': self.start_date = str(datetime.datetime.now())[:10] if self.end_date == '': self.end_date = str(datetime.datetime.now())[:10] try: d = dialog.numeric(1, common.getstring(30117) ,strftime("%d/%m/%Y",strptime(self.start_date,"%Y-%m-%d")) ) if d != '': self.start_date = strftime("%Y-%m-%d",strptime(d.replace(" ","0"),"%d/%m/%Y")) else: self.start_date ='' common.log('', str(self.start_date)) d = dialog.numeric(1, common.getstring(30118) ,strftime("%d/%m/%Y",strptime(self.end_date,"%Y-%m-%d")) ) if d != '': self.end_date = strftime("%Y-%m-%d",strptime(d.replace(" ","0"),"%d/%m/%Y")) else: self.end_date ='' common.log('', str(self.end_date)) except: pass if self.start_date != '' or self.end_date != '': self.getControl( BUTTON_DATE ).setLabel( self.start_date + ' ... ' + self.end_date ) else: self.getControl( BUTTON_DATE ).setLabel( common.getstring(30164) ) self.getControl( BUTTON_DATE ).setVisible(False) self.getControl( BUTTON_DATE ).setVisible(True)
def save_filter_settings(self): # Display a list of already saved filters to give the possibility to override a filter filters = [] filters.append( common.getstring(30653) ) filters = filters + self.MPDB.filterwizard_list_filters() try: filters.remove(self.last_used_filter_name) except: pass dialog = xbmcgui.Dialog() ret = dialog.select(common.getstring(30608), filters) if ret > 0: self.MPDB.filterwizard_save_filter(filters[ret], self.active_tags, self.use_and, self.start_date, self.end_date) if ret == 0: kb = xbmc.Keyboard() kb.setHeading(common.getstring(30609)) kb.doModal() filtersettings = "" if (kb.isConfirmed()): filtersettings = kb.getText() self.MPDB.filterwizard_save_filter(filtersettings, self.active_tags, self.use_and, self.start_date, self.end_date) if filtersettings != '': self.getControl( FILTER_NAME ).setLabel( common.getstring(30652) +' '+filtersettings) else: self.getControl( FILTER_NAME ).setLabel( '' ) self.getControl( FILTER_NAME ).setVisible(False) self.getControl( FILTER_NAME ).setVisible(True)
def delete_filter_settings(self): filters = self.MPDB.filterwizard_list_filters() # don't delete the last used filter filters.remove(self.last_used_filter_name) dialog = xbmcgui.Dialog() ret = dialog.select(common.getstring(30608), filters) if ret > -1: if dialog.yesno(common.getstring(30250), common.getstring(30251)%filters[ret]) : self.MPDB.filterwizard_delete_filter(filters[ret])
def setup_all( self, filtersettings = ""): self.getControl( LABEL_TEXT ).setLabel( common.getstring(30220) ) self.getControl( BUTTON_CLOSE ).setLabel( common.getstring(30224) ) self.getControl( BUTTON_ZOOM_IN ).setLabel( common.getstring(30225) ) self.getControl( BUTTON_ZOOM_OUT ).setLabel( common.getstring(30226) ) self.zoomlevel = 15 self.zoom_max = 21 self.zoom_min = 0 self.load_map()
def onInit(self): self.getControl(STATUS_LABEL).setLabel(common.getstring(30620)) self.getControl(STATUS_LABEL2).setLabel(common.getstring(30622)) self.getControl(BUTTON_OK).setLabel(common.getstring(30621)) self.getControl(TAGS_LIST).reset() tagtypes_translations = self.MPDB.get_tagtypes_translation() for tagtype_translation in tagtypes_translations: listitem = xbmcgui.ListItem(label=tagtype_translation[0], label2=tagtype_translation[1]) self.getControl(TAGS_LIST).addItem(listitem) self.setFocus(self.getControl(TAGS_LIST)) self.getControl(TAGS_LIST).selectItem(0)
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)
def clear_settings(self): self.active_tags.clear() self.checked_tags = 0 self.use_and = 0 self.getControl( BUTTON_MATCHALL ).setSelected(0) self.load_tag_content_list(self.tag_types[0]) self.getControl( CHECKED_LABEL ).setLabel( common.getstring(30612)% (self.checked_tags) ) self.getControl( CHECKED_LABEL ).setVisible(False) self.getControl( CHECKED_LABEL ).setVisible(True) self.getControl( BUTTON_DATE ).setLabel( common.getstring(30164) ) self.getControl( BUTTON_DATE ).setVisible(False) self.getControl( BUTTON_DATE ).setVisible(True) self.getControl( FILTER_NAME ).setLabel( '' ) self.getControl( FILTER_NAME ).setVisible(False) self.getControl( FILTER_NAME ).setVisible(True)
def onAction( self, action ): # Cancel if ( action.getId() in CANCEL_DIALOG or self.getFocusId() == BUTTON_CANCEL and action.getId() in SELECT_ITEM ): arraytrue = [] arrayfalse = [] self.filter (arraytrue,arrayfalse,0,'','') self.close() # Okay elif ( self.getFocusId() == BUTTON_OK and action.getId() in SELECT_ITEM ): common.log("FilterWizard.onAction", "OK") arraytrue = [] arrayfalse = [] for key, value in self.active_tags.items(): if value == 1: arraytrue.append( key) if value == -1: arrayfalse.append( key) arraytrue.sort() arrayfalse.sort() self.filter (arraytrue, arrayfalse, self.use_and, self.start_date, self.end_date ) self.getControl( BUTTON_OK ).setEnabled(False) self.getControl( BUTTON_CANCEL ).setEnabled(False) self.getControl( BUTTON_MATCHALL ).setEnabled(False) self.getControl( LOAD_FILTER ).setEnabled(False) self.getControl( SAVE_FILTER ).setEnabled(False) self.getControl( CLEAR_FILTER ).setEnabled(False) self.getControl( DELETE_FILTER ).setEnabled(False) self.getControl( TAGS_LIST ).setEnabled(False) self.getControl( TAGS_CONTENT_LIST ).setEnabled(False) common.log("FilterWizard.onAction", "OK ") self.MPDB.filterwizard_save_filter( self.last_used_filter_name, self.active_tags, self.use_and, self.start_date, self.end_date) self.close() # Match all button elif ( action.getId() in SELECT_ITEM and self.getFocusId() == BUTTON_MATCHALL ): if self.use_and == 1: self.use_and = 0 else: self.use_and = 1 # Load filter settings elif ( action.getId() in SELECT_ITEM and self.getFocusId() == LOAD_FILTER ): self.show_filter_settings() # Save filter settings elif ( action.getId() in SELECT_ITEM and self.getFocusId() == SAVE_FILTER ): self.save_filter_settings() # Clear filter settings elif ( action.getId() in SELECT_ITEM and self.getFocusId() == CLEAR_FILTER ): self.clear_settings() # Delete filter settings elif ( action.getId() in SELECT_ITEM and self.getFocusId() == DELETE_FILTER ): self.delete_filter_settings() # Set start and end date elif ( action.getId() in SELECT_ITEM and self.getFocusId() == BUTTON_DATE ): self.set_filter_date() # Select or deselect item in TagTypes list elif ( action.getId() in SELECT_ITEM and self.getFocusId() == TAGS_LIST ): item = self.getControl( TAGS_LIST ).getSelectedItem() pos = self.getControl( TAGS_LIST ).getSelectedPosition() if self.currently_selected_tagtypes != self.tag_types[pos]: self.load_tag_content_list(self.tag_types[pos]) # Select or deselect item in TagContents list elif ( action.getId() in SELECT_ITEM and self.getFocusId() == TAGS_CONTENT_LIST ): # get selected item item = self.getControl( TAGS_CONTENT_LIST ).getSelectedItem() pos = self.getControl( TAGS_CONTENT_LIST ).getSelectedPosition() if pos != -1 and item != None: checked = item.getProperty("checked") key = common.smart_unicode(self.currently_selected_tagtypes) + '||' + common.smart_unicode(item.getLabel2()) if checked == "checkbutton.png": self.check_gui_tag_content(item, -1) self.active_tags[ key ] = -1 elif checked == "uncheckbutton.png": self.check_gui_tag_content(item, 0) self.active_tags[ key ] = 0 else : self.check_gui_tag_content(item, 1) self.active_tags[ key ] = 1 if self.checked_tags == 1: self.getControl( CHECKED_LABEL ).setLabel( common.getstring(30611) ) else: self.getControl( CHECKED_LABEL ).setLabel( common.getstring(30612)% (self.checked_tags) ) self.getControl( CHECKED_LABEL ).setVisible(False) self.getControl( CHECKED_LABEL ).setVisible(True)
def show_filter_settings(self): filters = self.MPDB.filterwizard_list_filters() dialog = xbmcgui.Dialog() ret = dialog.select(common.getstring(30608), filters) if ret > -1: self.setup_all(filters[ret])
def setup_all( self, filtersettings = ""): self.getControl( STATUS_LABEL ).setLabel( common.getstring(30610) ) #self.getControl( FILTER_LABEL ).setLabel( common.getstring(30652) ) self.getControl( TAGS_COLUMN ).setLabel( common.getstring(30601) ) self.getControl( CONTENT_COLUMN ).setLabel( common.getstring(30602) ) self.getControl( BUTTON_OK ).setLabel( common.getstring(30613) ) self.getControl( BUTTON_CANCEL ).setLabel( common.getstring(30614) ) self.getControl( BUTTON_MATCHALL ).setLabel( common.getstring(30615) ) self.getControl( LOAD_FILTER ).setLabel( common.getstring(30616) ) self.getControl( SAVE_FILTER ).setLabel( common.getstring(30617) ) self.getControl( CLEAR_FILTER ).setLabel( common.getstring(30618) ) self.getControl( DELETE_FILTER ).setLabel( common.getstring(30619) ) self.getControl( BUTTON_DATE ).setLabel( common.getstring(30164) ) if filtersettings != '': self.getControl( FILTER_NAME ).setLabel( common.getstring(30652) +' '+filtersettings) else: self.getControl( FILTER_NAME ).setLabel( '' ) self.getControl( TAGS_LIST ).reset() self.tag_types = [u"%s"%k for k in self.MPDB.list_TagTypes()] self.currently_selected_tagtypes = '' self.checked_tags = 0 self.use_and = 0 self.start_date = '' self.end_date = '' self.active_tags = {} self.last_used_filter_name = " " + common.getstring(30607) self.getControl( TAGS_CONTENT_LIST ).reset() self.getControl( TAGS_LIST ).reset() # load last filter settings if filtersettings != "": self.active_tags, self.use_and, self.start_date, self.end_date = self.MPDB.filterwizard_load_filter(filtersettings) if self.use_and == 1: self.getControl( BUTTON_MATCHALL ).setSelected(1) if self.start_date is None: self.start_date = "" if self.end_date is None: self.end_date = "" if str(self.start_date) != "" or str(self.end_date) != "": self.getControl( BUTTON_DATE ).setLabel( self.start_date + ' ... ' + self.end_date ) else: self.getControl( BUTTON_DATE ).setLabel( common.getstring(30164) ) self.getControl( BUTTON_DATE ).setVisible(False) self.getControl( BUTTON_DATE ).setVisible(True) for key in self.active_tags: if self.active_tags[key] != 0: self.checked_tags += 1 if self.checked_tags == 1: self.getControl( CHECKED_LABEL ).setLabel( common.getstring(30611) ) else: self.getControl( CHECKED_LABEL ).setLabel( common.getstring(30612)% (self.checked_tags) ) self.init_tags()
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))
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 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) )
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))
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