def get_folder_content(self, folder_name, store_folder_name=True, load_images=True): """ Return the list representing folder content :param folder_name: folder name :param store_folder_name: remember folder name :return: """ files = [] if not os.path.exists(folder_name): return if folder_name.endswith(":") and WINDOWS in self.platform: folder_name += "\\" if store_folder_name: self.current_folder = folder_name if folder_name == self.ROOT and WINDOWS in self.platform: disks = self.get_windows_disks() for d in disks: state = State() state.folder = folder_name state.file_type = FOLDER state.file_name = d state.url = d files.append(state) return files for f in os.listdir(folder_name): file_path = os.path.join(folder_name, f) real_path = os.path.realpath(file_path) state = State() state.folder = folder_name state.file_type = FOLDER state.file_name = f state.url = real_path if os.path.isdir(file_path) and not re.match( RE_HIDDEN_FOLDER_PREFIXES, f): # folder try: folder_image_path = self.util.get_folder_image_path( real_path) if folder_image_path: state.file_type = FOLDER_WITH_ICON state.file_image_path = folder_image_path files.append(state) except PermissionError: pass elif os.path.isfile(file_path) and not f.startswith("."): # file if self.is_audio_file(f): state.file_type = FILE_AUDIO if load_images and self.image_util.get_image_from_audio_file( file_path): state.has_embedded_image = True else: state.has_embedded_image = False files.append(state) elif self.is_playlist_file(f): # had issues using cue playlists and vlc python binding p = self.config[AUDIO][CLIENT_NAME] if p == VLC and f.endswith(".cue"): continue state.file_type = FILE_PLAYLIST files.append(state) if self.config[SORT_BY_TYPE]: files = sorted(files, key=attrgetter("file_type"), reverse=True) else: files = sorted(files, key=attrgetter("file_name"), reverse=False) for n, f in enumerate(files): f.comparator_item = n return files
def get_folder_content(self, folder_name): """ Return the list representing folder content :param folder_name: folder name :return: """ files = [] if not os.path.exists(folder_name): return if folder_name.endswith(":") and WINDOWS in self.platform: folder_name += "\\" self.current_folder = folder_name if folder_name == self.ROOT and WINDOWS in self.platform: disks = self.get_windows_disks() for d in disks: state = State() state.folder = self.current_folder state.file_type = FOLDER state.file_name = d state.url = d files.append(state) return files for f in os.listdir(folder_name): file_path = os.path.join(folder_name, f) real_path = os.path.realpath(file_path) state = State() state.folder = self.current_folder state.file_type = FOLDER state.file_name = f state.url = real_path if os.path.isdir(file_path) and not re.match( RE_HIDDEN_FOLDER_PREFIXES, f): # folder try: folder_image_path = self.get_folder_image_path(real_path) if folder_image_path: state.file_type = FOLDER_WITH_ICON state.file_image_path = folder_image_path files.append(state) except PermissionError: pass elif os.path.isfile(file_path) and not f.startswith("."): # file if self.is_audio_file(f): state.file_type = FILE_AUDIO if self.util.get_image_from_audio_file(file_path): state.has_embedded_image = True else: state.has_embedded_image = False files.append(state) elif self.is_playlist_file(f): # had issues with mplayer and cue files: # https://en.wikipedia.org/wiki/Talk%3ACue_sheet_(computing)#mplayer_have_more_faults # had also issues using cue playlists and vlc python binding p = self.config[AUDIO][CLIENT_NAME] if (p == MPLAYER or p == VLC) and f.endswith(".cue"): continue state.file_type = FILE_PLAYLIST files.append(state) files.sort(key=lambda x: [ int(n) if n.isdigit() else n.lower() for n in split(self.cre, x.file_name) ]) for n, f in enumerate(files): f.comparator_item = n return files