renamed some parts; restructured some logic for potential ease of switchup in use

This commit is contained in:
itdominator 2024-02-04 14:51:50 -06:00
parent 2029fbbca9
commit 25a8aa2a2e
4 changed files with 62 additions and 38 deletions

View File

@ -35,11 +35,11 @@ class Icon(DesktopIconMixin, VideoIconMixin, MeshsIconMixin):
def get_icon_image(self, dir, file, full_path): def get_icon_image(self, dir, file, full_path):
try: 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.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) thumbnl = self.create_video_thumbnail(full_path)
elif file.lower().endswith(self.fimages): # Image Icon elif file.lower().endswith(self.fimages): # Image Icon
thumbnl = self.create_scaled_image(full_path) thumbnl = self.create_scaled_image(full_path)
@ -48,9 +48,12 @@ class Icon(DesktopIconMixin, VideoIconMixin, MeshsIconMixin):
elif full_path.lower().endswith( ('.desktop',) ): # .desktop file parsing elif full_path.lower().endswith( ('.desktop',) ): # .desktop file parsing
thumbnl = self.find_thumbnail_from_desktop_file(full_path) thumbnl = self.find_thumbnail_from_desktop_file(full_path)
if not thumbnl:
thumbnl = self._get_system_thumbnail_gtk_thread(full_path, self.sys_icon_wh[0])
if not thumbnl: if not thumbnl:
raise IconException("No known icons found.") raise IconException("No known icons found.")
return thumbnl return thumbnl
except IconException: except IconException:
... ...
@ -163,14 +166,15 @@ class Icon(DesktopIconMixin, VideoIconMixin, MeshsIconMixin):
return path_exists, img_hash, hash_img_path 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() h = hash_factory()
with open(filename,'rb') as f: with open(filename,'rb') as f:
# NOTE: Jump to middle of file
f.seek(0, 2) f.seek(0, 2)
mid = int(f.tell() / 2) mid = int(f.tell() / 2)
f.seek(mid, 0) 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) h.update(chunk)
if (i == 12): if (i == 12):
break break

View File

@ -49,9 +49,9 @@ class Tab(Settings, FileHandler, Launcher, Icon, Path):
self._hide_hidden: bool = self.HIDE_HIDDEN_FILES self._hide_hidden: bool = self.HIDE_HIDDEN_FILES
self._files: list = [] self._files: list = []
self._dirs: list = [] self._dirs: list = []
self._vids: list = [] self._videos: list = []
self._images: list = [] self._images: list = []
self._desktop: list = [] self._desktops: list = []
self._ungrouped: list = [] self._ungrouped: list = []
self._hidden: list = [] self._hidden: list = []
@ -61,9 +61,9 @@ class Tab(Settings, FileHandler, Launcher, Icon, Path):
def load_directory(self) -> None: def load_directory(self) -> None:
path = self.get_path() path = self.get_path()
self._dirs = [] self._dirs = []
self._vids = [] self._videos = []
self._images = [] self._images = []
self._desktop = [] self._desktops = []
self._ungrouped = [] self._ungrouped = []
self._hidden = [] self._hidden = []
self._files = [] self._files = []
@ -75,31 +75,34 @@ class Tab(Settings, FileHandler, Launcher, Icon, Path):
for f in listdir(path): 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 self._hide_hidden:
if f.startswith('.'): if f.startswith('.'):
self._hidden.append(f) self._hidden.append(content)
continue continue
if isfile(file): if isfile(file):
lowerName = file.lower() lowerName = file.lower()
if lowerName.endswith(self.fvideos): if lowerName.endswith(self.fvideos):
self._vids.append(f) self._videos.append(content)
elif lowerName.endswith(self.fimages): elif lowerName.endswith(self.fimages):
self._images.append(f) self._images.append(content)
elif lowerName.endswith((".desktop",)): elif lowerName.endswith((".desktop",)):
self._desktop.append(f) self._desktops.append(content)
else: else:
self._ungrouped.append(f) self._ungrouped.append(content)
else: else:
self._dirs.append(f) self._dirs.append(content)
self._dirs.sort(key=self._natural_keys) self._dirs.sort(key = self._natural_keys)
self._vids.sort(key=self._natural_keys) self._videos.sort(key = self._natural_keys)
self._images.sort(key=self._natural_keys) self._images.sort(key = self._natural_keys)
self._desktop.sort(key=self._natural_keys) self._desktops.sort(key = self._natural_keys)
self._ungrouped.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): def is_folder_locked(self, hash):
if self.lock_folder: if self.lock_folder:
@ -121,9 +124,9 @@ class Tab(Settings, FileHandler, Launcher, Icon, Path):
def get_not_hidden_count(self) -> int: def get_not_hidden_count(self) -> int:
return len(self._files) + \ return len(self._files) + \
len(self._dirs) + \ len(self._dirs) + \
len(self._vids) + \ len(self._videos) + \
len(self._images) + \ len(self._images) + \
len(self._desktop) + \ len(self._desktops) + \
len(self._ungrouped) len(self._ungrouped)
def get_hidden_count(self) -> int: def get_hidden_count(self) -> int:
@ -148,7 +151,7 @@ class Tab(Settings, FileHandler, Launcher, Icon, Path):
dirs = self._hash_set(self._dirs), dirs = self._hash_set(self._dirs),
videos = self.get_videos(), videos = self.get_videos(),
images = self._hash_set(self._images), images = self._hash_set(self._images),
desktops = self._hash_set(self._desktop), desktops = self._hash_set(self._desktops),
ungrouped = self._hash_set(self._ungrouped) ungrouped = self._hash_set(self._ungrouped)
hidden = self._hash_set(self._hidden) hidden = self._hash_set(self._hidden)
@ -168,7 +171,7 @@ class Tab(Settings, FileHandler, Launcher, Icon, Path):
def get_video_icons(self) -> list: def get_video_icons(self) -> list:
data = [] data = []
dir = self.get_current_directory() 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) img_hash, hash_img_path = self.create_video_thumbnail(full_path=f"{dir}/{file}", returnHashInstead=True)
data.append([img_hash, hash_img_path]) data.append([img_hash, hash_img_path])
@ -222,13 +225,13 @@ class Tab(Settings, FileHandler, Launcher, Icon, Path):
return self._hash_set(self._dirs) return self._hash_set(self._dirs)
def get_videos(self) -> list: def get_videos(self) -> list:
return self._hash_set(self._vids) return self._hash_set(self._videos)
def get_images(self) -> list: def get_images(self) -> list:
return self._hash_set(self._images) return self._hash_set(self._images)
def get_desktops(self) -> list: def get_desktopss(self) -> list:
return self._hash_set(self._desktop) return self._hash_set(self._desktops)
def get_ungrouped(self) -> list: def get_ungrouped(self) -> list:
return self._hash_set(self._ungrouped) return self._hash_set(self._ungrouped)

View File

@ -34,14 +34,14 @@ class FileHandler:
return True return True
def delete_file(self, toDeleteFile): def delete_file(self, to_delete_file):
try: try:
print(f"Deleting: {toDeleteFile}") print(f"Deleting: {to_delete_file}")
if os.path.exists(toDeleteFile): if os.path.exists(to_delete_file):
if os.path.isfile(toDeleteFile): if os.path.isfile(to_delete_file):
os.remove(toDeleteFile) os.remove(to_delete_file)
elif os.path.isdir(toDeleteFile): elif os.path.isdir(to_delete_file):
shutil.rmtree(toDeleteFile) shutil.rmtree(to_delete_file)
else: else:
print("An error occured deleting the file:") print("An error occured deleting the file:")
return False return False
@ -73,7 +73,7 @@ class FileHandler:
return True return True
def copy_file(self,fFile, tFile, symlinks=False, ignore=None): def copy_file(self, fFile, tFile, symlinks = False, ignore = None):
try: try:
if os.path.isdir(fFile): if os.path.isdir(fFile):
shutil.copytree(fFile, tFile, symlinks, ignore) shutil.copytree(fFile, tFile, symlinks, ignore)

View File

@ -89,6 +89,23 @@ class Launcher:
return True 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): def check_remux_space(self):
limit = self.remux_folder_max_disk_usage limit = self.remux_folder_max_disk_usage
try: try: