diff --git a/src/shellfm/windows/tabs/icons/icon.py b/src/shellfm/windows/tabs/icons/icon.py index c06e2be..d303a2f 100644 --- a/src/shellfm/windows/tabs/icons/icon.py +++ b/src/shellfm/windows/tabs/icons/icon.py @@ -35,11 +35,11 @@ class Icon(DesktopIconMixin, VideoIconMixin, MeshsIconMixin): def get_icon_image(self, dir, file, full_path): try: - thumbnl = self._get_system_thumbnail_gtk_thread(full_path, self.sys_icon_wh[0]) + thumbnl = None if file.lower().endswith(self.fmeshs): # 3D Mesh icon ... - if file.lower().endswith(self.fvideos): # Video icon + elif file.lower().endswith(self.fvideos): # Video icon thumbnl = self.create_video_thumbnail(full_path) elif file.lower().endswith(self.fimages): # Image Icon thumbnl = self.create_scaled_image(full_path) @@ -49,7 +49,10 @@ class Icon(DesktopIconMixin, VideoIconMixin, MeshsIconMixin): thumbnl = self.find_thumbnail_from_desktop_file(full_path) if not thumbnl: - raise IconException("No known icons found.") + thumbnl = self._get_system_thumbnail_gtk_thread(full_path, self.sys_icon_wh[0]) + if not thumbnl: + raise IconException("No known icons found.") + return thumbnl except IconException: @@ -163,14 +166,15 @@ class Icon(DesktopIconMixin, VideoIconMixin, MeshsIconMixin): return path_exists, img_hash, hash_img_path - def fast_hash(self, filename, hash_factory=hashlib.md5, chunk_num_blocks=128, i=1): + def fast_hash(self, filename: str, hash_factory: callable = hashlib.md5, chunk_num_blocks: int = 128, i: int = 1) -> str: h = hash_factory() with open(filename,'rb') as f: + # NOTE: Jump to middle of file f.seek(0, 2) mid = int(f.tell() / 2) f.seek(mid, 0) - while chunk := f.read(chunk_num_blocks*h.block_size): + while chunk := f.read(chunk_num_blocks * h.block_size): h.update(chunk) if (i == 12): break diff --git a/src/shellfm/windows/tabs/tab.py b/src/shellfm/windows/tabs/tab.py index 6a05f28..e6ce749 100644 --- a/src/shellfm/windows/tabs/tab.py +++ b/src/shellfm/windows/tabs/tab.py @@ -49,9 +49,9 @@ class Tab(Settings, FileHandler, Launcher, Icon, Path): self._hide_hidden: bool = self.HIDE_HIDDEN_FILES self._files: list = [] self._dirs: list = [] - self._vids: list = [] + self._videos: list = [] self._images: list = [] - self._desktop: list = [] + self._desktops: list = [] self._ungrouped: list = [] self._hidden: list = [] @@ -61,9 +61,9 @@ class Tab(Settings, FileHandler, Launcher, Icon, Path): def load_directory(self) -> None: path = self.get_path() self._dirs = [] - self._vids = [] + self._videos = [] self._images = [] - self._desktop = [] + self._desktops = [] self._ungrouped = [] self._hidden = [] self._files = [] @@ -74,32 +74,35 @@ class Tab(Settings, FileHandler, Launcher, Icon, Path): return "" for f in listdir(path): - file = join(path, f) + file = join(path, f) + # content = {"name": f, hash: self._hash_text(f)} + content = f + if self._hide_hidden: if f.startswith('.'): - self._hidden.append(f) + self._hidden.append(content) continue if isfile(file): lowerName = file.lower() if lowerName.endswith(self.fvideos): - self._vids.append(f) + self._videos.append(content) elif lowerName.endswith(self.fimages): - self._images.append(f) + self._images.append(content) elif lowerName.endswith((".desktop",)): - self._desktop.append(f) + self._desktops.append(content) else: - self._ungrouped.append(f) + self._ungrouped.append(content) else: - self._dirs.append(f) + self._dirs.append(content) - self._dirs.sort(key=self._natural_keys) - self._vids.sort(key=self._natural_keys) - self._images.sort(key=self._natural_keys) - self._desktop.sort(key=self._natural_keys) - self._ungrouped.sort(key=self._natural_keys) + self._dirs.sort(key = self._natural_keys) + self._videos.sort(key = self._natural_keys) + self._images.sort(key = self._natural_keys) + self._desktops.sort(key = self._natural_keys) + self._ungrouped.sort(key = self._natural_keys) - self._files = self._dirs + self._vids + self._images + self._desktop + self._ungrouped + self._files = self._dirs + self._videos + self._images + self._desktops + self._ungrouped def is_folder_locked(self, hash): if self.lock_folder: @@ -121,9 +124,9 @@ class Tab(Settings, FileHandler, Launcher, Icon, Path): def get_not_hidden_count(self) -> int: return len(self._files) + \ len(self._dirs) + \ - len(self._vids) + \ + len(self._videos) + \ len(self._images) + \ - len(self._desktop) + \ + len(self._desktops) + \ len(self._ungrouped) def get_hidden_count(self) -> int: @@ -148,7 +151,7 @@ class Tab(Settings, FileHandler, Launcher, Icon, Path): dirs = self._hash_set(self._dirs), videos = self.get_videos(), images = self._hash_set(self._images), - desktops = self._hash_set(self._desktop), + desktops = self._hash_set(self._desktops), ungrouped = self._hash_set(self._ungrouped) hidden = self._hash_set(self._hidden) @@ -168,7 +171,7 @@ class Tab(Settings, FileHandler, Launcher, Icon, Path): def get_video_icons(self) -> list: data = [] dir = self.get_current_directory() - for file in self._vids: + for file in self._videos: img_hash, hash_img_path = self.create_video_thumbnail(full_path=f"{dir}/{file}", returnHashInstead=True) data.append([img_hash, hash_img_path]) @@ -222,13 +225,13 @@ class Tab(Settings, FileHandler, Launcher, Icon, Path): return self._hash_set(self._dirs) def get_videos(self) -> list: - return self._hash_set(self._vids) + return self._hash_set(self._videos) def get_images(self) -> list: return self._hash_set(self._images) - def get_desktops(self) -> list: - return self._hash_set(self._desktop) + def get_desktopss(self) -> list: + return self._hash_set(self._desktops) def get_ungrouped(self) -> list: return self._hash_set(self._ungrouped) @@ -285,4 +288,4 @@ class Tab(Settings, FileHandler, Launcher, Icon, Path): self._id = str(self._random_with_N_digits(self._id_length)) def _set_error_message(self, text: str): - self.error_message = text + self.error_message = text \ No newline at end of file diff --git a/src/shellfm/windows/tabs/utils/filehandler.py b/src/shellfm/windows/tabs/utils/filehandler.py index 750ed2c..487781d 100644 --- a/src/shellfm/windows/tabs/utils/filehandler.py +++ b/src/shellfm/windows/tabs/utils/filehandler.py @@ -34,14 +34,14 @@ class FileHandler: return True - def delete_file(self, toDeleteFile): + def delete_file(self, to_delete_file): try: - print(f"Deleting: {toDeleteFile}") - if os.path.exists(toDeleteFile): - if os.path.isfile(toDeleteFile): - os.remove(toDeleteFile) - elif os.path.isdir(toDeleteFile): - shutil.rmtree(toDeleteFile) + print(f"Deleting: {to_delete_file}") + if os.path.exists(to_delete_file): + if os.path.isfile(to_delete_file): + os.remove(to_delete_file) + elif os.path.isdir(to_delete_file): + shutil.rmtree(to_delete_file) else: print("An error occured deleting the file:") return False @@ -73,7 +73,7 @@ class FileHandler: return True - def copy_file(self,fFile, tFile, symlinks=False, ignore=None): + def copy_file(self, fFile, tFile, symlinks = False, ignore = None): try: if os.path.isdir(fFile): shutil.copytree(fFile, tFile, symlinks, ignore) diff --git a/src/shellfm/windows/tabs/utils/launcher.py b/src/shellfm/windows/tabs/utils/launcher.py index 8b6fd86..c8a55a3 100644 --- a/src/shellfm/windows/tabs/utils/launcher.py +++ b/src/shellfm/windows/tabs/utils/launcher.py @@ -89,6 +89,23 @@ class Launcher: return True + def handbrake_remux_video(self, hash, file): + remux_vid_pth = f"{self.REMUX_FOLDER}/{hash}.mp4" + self.logger.debug(remux_vid_pth) + + if not os.path.isfile(remux_vid_pth): + self.check_remux_space() + + command = ["HandBrakeCLI", "-i", file, "-e", "nvenc_h264", "-f", "av_mp4", "-O", "-o", remux_vid_pth] + try: + proc = subprocess.Popen(command) + proc.wait() + except Exception as e: + self.logger.debug(e) + return False + + return True + def check_remux_space(self): limit = self.remux_folder_max_disk_usage try: