Better support logic for WebFM/web file needs
This commit is contained in:
parent
dc14cb4cfe
commit
2fa207f5fc
|
@ -57,12 +57,15 @@ class Icon(DesktopIconMixin, VideoIconMixin, MeshsIconMixin):
|
|||
|
||||
return self.get_generic_icon()
|
||||
|
||||
def create_blender_thumbnail(self, full_path):
|
||||
def create_blender_thumbnail(self, full_path, returnHashInstead=False):
|
||||
try:
|
||||
path_exists, hash_img_path = self.generate_hash_and_path(full_path)
|
||||
path_exists, img_hash, hash_img_path = self.generate_hash_and_path(full_path)
|
||||
if not path_exists:
|
||||
self.generate_blender_thumbnail(full_path, hash_img_path)
|
||||
|
||||
if returnHashInstead:
|
||||
return img_hash, hash_img_path
|
||||
|
||||
return self.create_scaled_image(hash_img_path, self.video_icon_wh)
|
||||
except IconException as e:
|
||||
print("Blender thumbnail generation issue:")
|
||||
|
@ -70,9 +73,9 @@ class Icon(DesktopIconMixin, VideoIconMixin, MeshsIconMixin):
|
|||
|
||||
return None
|
||||
|
||||
def create_video_thumbnail(self, full_path, scrub_percent = "65%", replace=False):
|
||||
def create_video_thumbnail(self, full_path, scrub_percent = "65%", replace=False, returnHashInstead=False):
|
||||
try:
|
||||
path_exists, hash_img_path = self.generate_hash_and_path(full_path)
|
||||
path_exists, img_hash, hash_img_path = self.generate_hash_and_path(full_path)
|
||||
if path_exists and replace:
|
||||
os.remove(hash_img_path)
|
||||
path_exists = False
|
||||
|
@ -80,6 +83,9 @@ class Icon(DesktopIconMixin, VideoIconMixin, MeshsIconMixin):
|
|||
if not path_exists:
|
||||
self.generate_video_thumbnail(full_path, hash_img_path, scrub_percent)
|
||||
|
||||
if returnHashInstead:
|
||||
return img_hash, hash_img_path
|
||||
|
||||
return self.create_scaled_image(hash_img_path, self.video_icon_wh)
|
||||
except IconException as e:
|
||||
print("Image/Video thumbnail generation issue:")
|
||||
|
@ -150,11 +156,11 @@ class Icon(DesktopIconMixin, VideoIconMixin, MeshsIconMixin):
|
|||
return GdkPixbuf.Pixbuf.new_from_file(self.DEFAULT_ICON)
|
||||
|
||||
def generate_hash_and_path(self, full_path):
|
||||
file_hash = self.fast_hash(full_path)
|
||||
hash_img_path = f"{self.ABS_THUMBS_PTH}/{file_hash}.jpg"
|
||||
img_hash = self.fast_hash(full_path)
|
||||
hash_img_path = f"{self.ABS_THUMBS_PTH}/{img_hash}.jpg"
|
||||
path_exists = True if isfile(hash_img_path) else False
|
||||
|
||||
return path_exists, 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):
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
# Python imports
|
||||
import os
|
||||
import hashlib
|
||||
import re
|
||||
from os import listdir
|
||||
|
@ -17,6 +18,23 @@ from .icons.icon import Icon
|
|||
from .path import Path
|
||||
|
||||
|
||||
try:
|
||||
get_file_size("/")
|
||||
except Exception as e:
|
||||
import os
|
||||
|
||||
def sizeof_fmt_def(num, suffix="B"):
|
||||
for unit in ["", "K", "M", "G", "T", "Pi", "Ei", "Zi"]:
|
||||
if abs(num) < 1024.0:
|
||||
return f"{num:3.1f} {unit}{suffix}"
|
||||
num /= 1024.0
|
||||
return f"{num:.1f} Yi{suffix}"
|
||||
|
||||
def _get_file_size(file):
|
||||
return "4K" if isdir(file) else sizeof_fmt_def(os.path.getsize(file))
|
||||
|
||||
get_file_size = _get_file_size
|
||||
|
||||
|
||||
|
||||
class Tab(Settings, FileHandler, Launcher, Icon, Path):
|
||||
|
@ -26,6 +44,7 @@ class Tab(Settings, FileHandler, Launcher, Icon, Path):
|
|||
|
||||
self._id: str = ""
|
||||
self._wid: str = None
|
||||
self.error_message: str = None
|
||||
self._dir_watcher = None
|
||||
self._hide_hidden: bool = self.HIDE_HIDDEN_FILES
|
||||
self._files: list = []
|
||||
|
@ -50,6 +69,7 @@ class Tab(Settings, FileHandler, Launcher, Icon, Path):
|
|||
self._files = []
|
||||
|
||||
if not isdir(path):
|
||||
self._set_error_message("Path can not be accessed.")
|
||||
self.set_to_home()
|
||||
return ""
|
||||
|
||||
|
@ -145,6 +165,15 @@ class Tab(Settings, FileHandler, Launcher, Icon, Path):
|
|||
}
|
||||
}
|
||||
|
||||
def get_video_icons(self) -> list:
|
||||
data = []
|
||||
dir = self.get_current_directory()
|
||||
for file in self._vids:
|
||||
img_hash, hash_img_path = self.create_video_thumbnail(full_path=f"{dir}/{file}", returnHashInstead=True)
|
||||
data.append([img_hash, hash_img_path])
|
||||
|
||||
return data
|
||||
|
||||
def get_pixbuf_icon_str_combo(self):
|
||||
data = []
|
||||
dir = self.get_current_directory()
|
||||
|
@ -154,7 +183,6 @@ class Tab(Settings, FileHandler, Launcher, Icon, Path):
|
|||
|
||||
return data
|
||||
|
||||
|
||||
def get_gtk_icon_str_combo(self) -> list:
|
||||
data = []
|
||||
dir = self.get_current_directory()
|
||||
|
@ -223,6 +251,12 @@ class Tab(Settings, FileHandler, Launcher, Icon, Path):
|
|||
def get_dir_watcher(self):
|
||||
return self._dir_watcher
|
||||
|
||||
def get_error_message(self):
|
||||
return self.error_message
|
||||
|
||||
def unset_error_message(self):
|
||||
self.error_message = None
|
||||
|
||||
def _atoi(self, text):
|
||||
return int(text) if text.isdigit() else text
|
||||
|
||||
|
@ -233,11 +267,15 @@ class Tab(Settings, FileHandler, Launcher, Icon, Path):
|
|||
return hashlib.sha256(str.encode(text)).hexdigest()[:18]
|
||||
|
||||
def _hash_set(self, arry: list) -> list:
|
||||
path = self.get_current_directory()
|
||||
data = []
|
||||
for arr in arry:
|
||||
data.append([arr, self._hash_text(arr)])
|
||||
file = f"{path}/{arr}"
|
||||
size = get_file_size(file)
|
||||
data.append([arr, self._hash_text(arr), size])
|
||||
return data
|
||||
|
||||
|
||||
def _random_with_N_digits(self, n: int) -> int:
|
||||
range_start = 10**(n-1)
|
||||
range_end = (10**n)-1
|
||||
|
@ -245,3 +283,6 @@ class Tab(Settings, FileHandler, Launcher, Icon, Path):
|
|||
|
||||
def _generate_id(self) -> str:
|
||||
self._id = str(self._random_with_N_digits(self._id_length))
|
||||
|
||||
def _set_error_message(self, text: str):
|
||||
self.error_message = text
|
||||
|
|
|
@ -12,9 +12,9 @@ import shutil
|
|||
class FileHandler:
|
||||
def create_file(self, nFile, type):
|
||||
try:
|
||||
if TYPE == "dir":
|
||||
if type == "dir":
|
||||
os.mkdir(nFile)
|
||||
elif TYPE == "file":
|
||||
elif type == "file":
|
||||
open(nFile, 'a').close()
|
||||
except Exception as e:
|
||||
print("An error occured creating the file/dir:")
|
||||
|
|
|
@ -56,9 +56,9 @@ class Settings:
|
|||
STEAM_CDN_URL = config["steam_cdn_url"]
|
||||
FFMPG_THUMBNLR = FFMPG_THUMBNLR if config["thumbnailer_path"] == "" else config["thumbnailer_path"]
|
||||
BLENDER_THUMBNLR = BLENDER_THUMBNLR if config["blender_thumbnailer_path"] == "" else config["blender_thumbnailer_path"]
|
||||
HIDE_HIDDEN_FILES = True if config["hide_hidden_files"] == "true" else False
|
||||
go_past_home = True if config["go_past_home"] == "" else config["go_past_home"]
|
||||
lock_folder = True if config["lock_folder"] == "true" else False
|
||||
HIDE_HIDDEN_FILES = True if config["hide_hidden_files"] in ["true", ""] else False
|
||||
go_past_home = True if config["go_past_home"] in ["true", ""] else False
|
||||
lock_folder = False if config["lock_folder"] in ["false", ""] else True
|
||||
locked_folders = config["locked_folders"].split("::::")
|
||||
mplayer_options = config["mplayer_options"].split()
|
||||
music_app = config["music_app"]
|
||||
|
@ -77,6 +77,7 @@ class Settings:
|
|||
|
||||
# Filters
|
||||
filters = settings["filters"]
|
||||
fmeshs = tuple(filters["meshs"])
|
||||
fcode = tuple(filters["code"])
|
||||
fvideos = tuple(filters["videos"])
|
||||
foffice = tuple(filters["office"])
|
||||
|
|
Loading…
Reference in New Issue