Skip to content

Commit

Permalink
Simplified missing settings. Extensions not set through settings.
Browse files Browse the repository at this point in the history
  • Loading branch information
sabaatworld committed Jan 4, 2021
1 parent ff08532 commit d63a976
Show file tree
Hide file tree
Showing 5 changed files with 215 additions and 111 deletions.
124 changes: 122 additions & 2 deletions assets/mainwindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>990</width>
<height>630</height>
<height>794</height>
</rect>
</property>
<property name="windowTitle">
Expand Down Expand Up @@ -714,7 +714,7 @@
<property name="geometry">
<rect>
<x>840</x>
<y>590</y>
<y>760</y>
<width>141</width>
<height>32</height>
</rect>
Expand Down Expand Up @@ -792,6 +792,9 @@
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maxLength">
<number>5000</number>
</property>
</widget>
</item>
</layout>
Expand Down Expand Up @@ -825,6 +828,9 @@
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maxLength">
<number>5000</number>
</property>
</widget>
</item>
<item>
Expand Down Expand Up @@ -874,6 +880,9 @@
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maxLength">
<number>5000</number>
</property>
</widget>
</item>
<item>
Expand All @@ -897,6 +906,117 @@
</layout>
</widget>
</widget>
<widget class="QGroupBox" name="groupBox_10">
<property name="geometry">
<rect>
<x>10</x>
<y>590</y>
<width>971</width>
<height>171</height>
</rect>
</property>
<property name="title">
<string/>
</property>
<widget class="QLabel" name="Dirs_5">
<property name="geometry">
<rect>
<x>10</x>
<y>10</y>
<width>291</width>
<height>16</height>
</rect>
</property>
<property name="font">
<font>
<pointsize>10</pointsize>
</font>
</property>
<property name="text">
<string>Safelisted File Type Extensions</string>
</property>
</widget>
<widget class="QWidget" name="gridLayoutWidget_5">
<property name="geometry">
<rect>
<x>10</x>
<y>40</y>
<width>951</width>
<height>116</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout_5">
<item row="3" column="0">
<widget class="QLabel" name="label_15">
<property name="text">
<string>Raw Videos</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLineEdit" name="txtVideoExt">
<property name="maxLength">
<number>5000</number>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="txtImageExt">
<property name="maxLength">
<number>5000</number>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label_13">
<property name="text">
<string>Regular Images</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QLineEdit" name="txtVideoRawExt">
<property name="maxLength">
<number>5000</number>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_16">
<property name="text">
<string>Regular Videos</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_14">
<property name="text">
<string>Raw Images</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="txtImageRawExt">
<property name="maxLength">
<number>5000</number>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
</widget>
</widget>
<resources/>
Expand Down
76 changes: 2 additions & 74 deletions pie/core/index_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import logging
import os
from logging import Logger
from types import SimpleNamespace
from typing import Dict, List

from sqlalchemy import create_engine
Expand Down Expand Up @@ -69,7 +68,6 @@ def get_all_media_files_by_path(self) -> Dict[str, MediaFile]:

def get_settings(self):
settings_path = MiscUtils.get_settings_path()
save_record: bool = False
settings: Settings = None

if os.path.exists(settings_path) and os.path.isfile(settings_path):
Expand All @@ -78,83 +76,13 @@ def get_settings(self):
settings_dict = json.load(file)
settings = Settings()
for key in settings_dict:
settings.__dict__[key] = settings_dict[key]
if key in settings.__dict__: # Don't keep stale keys
settings.__dict__[key] = settings_dict[key]
except:
logging.exception("Failed to load settings from JSON file. Restoring defaults.")

if settings is None:
settings = Settings()
save_record = True

# Apply defaults if they are not already set
if settings.dirs_to_exclude is None:
settings.dirs_to_exclude = '[]'
save_record = True
if settings.output_dir_path_type is None:
settings.output_dir_path_type = "Use Original Paths"
save_record = True
if settings.unknown_output_dir_path_type is None:
settings.unknown_output_dir_path_type = "Use Original Paths"
save_record = True
if settings.skip_same_name_video is None:
settings.skip_same_name_video = True
save_record = True
if settings.skip_same_name_raw is None:
settings.skip_same_name_raw = True
save_record = True
if settings.convert_unknown is None:
settings.convert_unknown = False
save_record = True
if settings.overwrite_output_files is None:
settings.overwrite_output_files = False
save_record = True
if settings.indexing_workers is None:
settings.indexing_workers = MiscUtils.get_default_worker_count()
save_record = True
if settings.conversion_workers is None:
settings.conversion_workers = MiscUtils.get_default_worker_count()
save_record = True
if settings.gpu_workers is None:
settings.gpu_workers = 1
save_record = True
if settings.gpu_count is None:
settings.gpu_count = 0
save_record = True
if settings.image_compression_quality is None:
settings.image_compression_quality = 75
save_record = True
if settings.image_max_dimension is None:
settings.image_max_dimension = 1920
save_record = True
if settings.video_max_dimension is None:
settings.video_max_dimension = 1920
save_record = True
if settings.video_crf is None:
settings.video_crf = 28
save_record = True
if settings.video_nvenc_preset is None:
settings.video_nvenc_preset = "fast"
save_record = True
if settings.video_audio_bitrate is None:
settings.video_audio_bitrate = 128
save_record = True
if settings.path_ffmpeg is None:
settings.path_ffmpeg = "/usr/local/bin/ffmpeg" if not MiscUtils.is_platform_win() else "ffmpeg"
save_record = True
if settings.path_magick is None:
settings.path_magick = "/usr/local/bin/magick" if not MiscUtils.is_platform_win() else "magick"
save_record = True
if settings.path_exiftool is None:
settings.path_exiftool = "/usr/local/bin/exiftool" if not MiscUtils.is_platform_win() else "exiftool"
save_record = True
if settings.auto_update_check is None:
settings.auto_update_check = True
save_record = True
if settings.auto_show_log_window is None:
settings.auto_show_log_window = True
save_record = True

if save_record:
self.save_settings(settings)

return settings
Expand Down
17 changes: 15 additions & 2 deletions pie/core/indexing_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,22 @@ class IndexingHelper:

def __init__(self, indexing_task: IndexingTask, log_queue: Queue, indexing_stop_event: Event):
self.__indexing_task = indexing_task
self.__image_extensions: Set[str] = IndexingHelper.parse_file_type_extension_str(self.__indexing_task.settings.image_extensions)
self.__image_raw_extensions: Set[str] = IndexingHelper.parse_file_type_extension_str(self.__indexing_task.settings.image_raw_extensions)
self.__video_extensions: Set[str] = IndexingHelper.parse_file_type_extension_str(self.__indexing_task.settings.video_extensions)
self.__video_raw_extensions: Set[str] = IndexingHelper.parse_file_type_extension_str(self.__indexing_task.settings.video_raw_extensions)
self.__log_queue = log_queue
self.__indexing_stop_event = indexing_stop_event

@staticmethod
def parse_file_type_extension_str(comma_delimited_list: str) -> Set[str]:
ext_set = set()
for item in comma_delimited_list.split(','):
stripped_item = item.strip()
if len(stripped_item) > 0:
ext_set.add(stripped_item)
return ext_set

def lookup_already_indexed_files(self, indexDB: IndexDB, scanned_files: List[ScannedFile]):
IndexingHelper.__logger.info("BEGIN:: IndexDB lookup for indexed files")
total_scanned_files = len(scanned_files)
Expand Down Expand Up @@ -103,7 +116,7 @@ def __scan_dir(self, dir_path, file_names, scanned_files):
file_name_tuple = os.path.splitext(file_name)
file_name_without_extension = file_name_tuple[0]
extension = file_name_tuple[1].replace(".", "").upper()
(scanned_file_type, is_raw) = ScannedFileType.get_type(extension)
(scanned_file_type, is_raw) = ScannedFileType.get_type(self.__image_extensions, self.__image_raw_extensions, self.__video_extensions, self.__video_raw_extensions, extension)
file_path = os.path.join(dir_path, file_name)
if ScannedFileType.UNKNOWN != scanned_file_type:
creation_time = datetime.fromtimestamp(os.path.getctime(file_path))
Expand Down Expand Up @@ -156,7 +169,7 @@ def create_media_files(self, scanned_files: List[ScannedFile]) -> List[str]:
IndexingHelper.__logger.info("BEGIN:: Media file creation and indexing")
pool = PyProcessPool(pool_name="IndexingWorker", process_count=self.__indexing_task.settings.indexing_workers, log_queue=self.__log_queue,
target=IndexingHelper.indexing_process_exec, initializer=IndexDB.create_instance, terminator=IndexDB.destroy_instance, stop_event=self.__indexing_stop_event)
db_write_lock: Lock = Manager().Lock() # pylint: disable=maybe-no-member
db_write_lock: Lock = Manager().Lock() # pylint: disable=maybe-no-member
tasks = list(map(lambda scanned_file: (self.__indexing_task.indexing_time, self.__indexing_task.settings.output_dir,
self.__indexing_task.settings.unknown_output_dir, self.__indexing_task.settings.path_exiftool, scanned_file, db_write_lock), scanned_files))
saved_file_paths = pool.submit_and_wait(tasks)
Expand Down
Loading

0 comments on commit d63a976

Please sign in to comment.