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 walk(self, path, recursive = False, types = None): filenames = [] dirnames = [] files_to_return = [] dirs_to_return = [] if path.startswith('multipath://'): common.log("Scanner.walk", 'multipath "%s"'%path) dirs = path[12:-1].split('/') for item in dirs: dirnames1, filenames1 = self._walk(urllib.pars.unquote_plus(item), recursive, types) for dirname in dirnames1: dirnames.append(dirname) for filename in filenames1: filenames.append(filename) else: common.log("Scanner.walk", 'path "%s"'%path) dirnames, filenames = self._walk(path, recursive, types) # Make sure everything is a unicode for filename in filenames: files_to_return.append(common.smart_unicode(filename)) for dirname in dirnames: dirs_to_return.append(common.smart_unicode(dirname)) return dirs_to_return, files_to_return
def is_content_checked(self, tagType, tagContent): key = common.smart_unicode(tagType) + '||' + common.smart_unicode(tagContent) if key in self.active_tags : checked = self.active_tags[ key ] else: self.active_tags[ key ] = 0 checked = 0 return checked
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
def __init__(self): self.exclude_folders = [] self.all_extensions = [] self.picture_extensions = [] self.video_extensions = [] self.lists_separator = "||" self.scan_is_cancelled = False 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 self.mpdb = MypicsDB.MyPictureDB() for path, _, _, exclude in self.mpdb.get_all_root_folders(): if exclude: common.log( "", 'Exclude path "%s" found ' % common.smart_unicode(path[:len(path) - 1])) self.exclude_folders.append( common.smart_unicode(path[:len(path) - 1])) for ext in common.getaddon_setting("picsext").split("|"): self.picture_extensions.append("." + ext.replace(".", "").upper()) for ext in common.getaddon_setting("vidsext").split("|"): self.video_extensions.append("." + ext.replace(".", "").upper()) self.use_videos = common.getaddon_setting("usevids") self.all_extensions.extend(self.picture_extensions) self.all_extensions.extend(self.video_extensions) self.filescanner = Scanner()
def __init__(self): self.exclude_folders = [] self.all_extensions = [] self.picture_extensions = [] self.video_extensions = [] self.lists_separator = "||" self.scan_is_cancelled = False 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 self.mpdb = MypicsDB.MyPictureDB() for path,_,_,exclude in self.mpdb.get_all_root_folders(): if exclude: common.log("", 'Exclude path "%s" found '%common.smart_unicode(path[:len(path)-1])) self.exclude_folders.append(common.smart_unicode(path[:len(path)-1])) for ext in common.getaddon_setting("picsext").split("|"): self.picture_extensions.append("." + ext.replace(".","").upper()) for ext in common.getaddon_setting("vidsext").split("|"): self.video_extensions.append("." + ext.replace(".","").upper()) self.use_videos = common.getaddon_setting("usevids") self.all_extensions.extend(self.picture_extensions) self.all_extensions.extend(self.video_extensions) self.filescanner = Scanner()
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 _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))
common.log("VFSScanner._get_iptc", "%s - %s"%(Exception,msg) ) return {} iptc = {} if len(info.data) < 2: return iptc try: for k in info.data.keys(): if k in IPTC_FIELDS: try: if isinstance(info.data[k],unicode): try: iptc[IPTC_FIELDS[k]] = info.data[k] except UnicodeDecodeError: iptc[IPTC_FIELDS[k]] = common.smart_unicode(info.data[k]) #unicode(info.data[k].encode("utf8").__str__(),"utf8") elif isinstance(info.data[k],list): iptc[IPTC_FIELDS[k]] = common.smart_unicode(self.lists_separator.join([i for i in info.data[k]])) elif isinstance(info.data[k],str): iptc[IPTC_FIELDS[k]] = common.smart_unicode(info.data[k]) else: common.log("VFSScanner._get_iptc", "%s"%fullpath ) common.log("VFSScanner._get_iptc", "WARNING : type returned by iptc field is not handled :" ) common.log("VFSScanner._get_iptc", repr(type(info.data[k])) ) except: common.log("VFSScanner._get_iptc","failure") pass
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
def getname(self, filename): filename = common.smart_unicode(filename) return os.path.basename(filename)