Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion namer/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def main():

arg1 = None if len(arg_list) == 0 else arg_list[0]
if arg1 == 'watchdog':
namer.watchdog.create_watcher(config).run()
namer.watchdog.main(config)
elif arg1 == 'rename':
namer.namer.main(arg_list[1:])
elif arg1 == 'suggest':
Expand Down
11 changes: 10 additions & 1 deletion namer/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ class NamerConfig:
a set of tags that indicates an individual video is vr.
"""

database_path: Path = Path(tempfile.gettempdir()) / 'namer'
database_path: Path = Path(tempfile.gettemp_dir()) / 'namer'
"""
Path where stores namer system data.
"""
Expand Down Expand Up @@ -510,6 +510,15 @@ def __init__(self):

self.re_cleanup = [re.compile(rf'\b{regex}\b', re.IGNORECASE) for regex in database.re_cleanup]

if hasattr(self, 'watch_dir'):
self.watch_dir = self.watch_dir.resolve()
if hasattr(self, 'work_dir'):
self.work_dir = self.work_dir.resolve()
if hasattr(self, 'dest_dir'):
self.dest_dir = self.dest_dir.resolve()
if hasattr(self, 'failed_dir'):
self.failed_dir = self.failed_dir.resolve()

def __str__(self):
config = self.to_dict()

Expand Down
2 changes: 1 addition & 1 deletion namer/metadataapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ def __get_metadataapi_net_info(url: str, name_parts: Optional[FileInfo], namer_c
if json_response and json_response.strip() != '':
# logger.debug("json_response: \n{}", json_response)
json_obj = orjson.loads(json_response)
formatted = orjson.dumps(orjson.loads(json_response), option=orjson.OPT_INDENT_2 | orjson.OPT_SORT_KEYS).decode('UTF-8')
formatted = orjson.dumps(json_obj, option=orjson.OPT_INDENT_2 | orjson.OPT_SORT_KEYS).decode('UTF-8')
file_infos = __metadataapi_response_to_data(json_obj, url, formatted, name_parts, namer_config)

return file_infos
Expand Down
29 changes: 21 additions & 8 deletions namer/watchdog.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,11 @@ def on_any_event(self, event: FileSystemEvent):
file_path = event.src_path

if file_path:
path = Path(file_path)
path = Path(file_path).resolve()
if not path.is_relative_to(self.__namer_config.watch_dir):
logger.error('file should be in watch dir {}', path)
return

relative_path = str(path.relative_to(self.__namer_config.watch_dir))
if not self.__namer_config.ignored_dir_regex.search(relative_path) and done_copying(path) and is_interesting_movie(path, self.__namer_config):
logger.info('watchdog process called for {}', relative_path)
Expand Down Expand Up @@ -249,10 +253,14 @@ def start(self):
# touch all existing movie files.
with suppress(FileNotFoundError):
for file in self.__namer_config.watch_dir.rglob('**/*.*'):
if file.is_file() and file.suffix.lower()[1:] in self.__namer_config.target_extensions:
relative_path = str(file.relative_to(self.__namer_config.watch_dir))
if not config.ignored_dir_regex.search(relative_path) and done_copying(file) and is_interesting_movie(file, self.__namer_config):
self.__event_handler.prepare_file_for_processing(file)
file = file.resolve()
if not file.is_relative_to(self.__namer_config.watch_dir):
logger.error('file should be in watch dir {}', file)
return

relative_path = str(file.relative_to(self.__namer_config.watch_dir))
if not self.__namer_config.ignored_dir_regex.search(relative_path) and done_copying(file) and is_interesting_movie(file, self.__namer_config):
self.__event_handler.prepare_file_for_processing(file)

def stop(self):
"""
Expand Down Expand Up @@ -302,9 +310,6 @@ def create_watcher(namer_watchdog_config: NamerConfig) -> MovieWatcher:
"""
Configure and start a watchdog looking for new Movies.
"""
level = 'DEBUG' if namer_watchdog_config.debug else 'INFO'
logger.add(sys.stdout, format=namer_watchdog_config.console_format, level=level, diagnose=namer_watchdog_config.diagnose_errors)

logger.info(namer_watchdog_config)

if not verify_configuration(namer_watchdog_config, PartialFormatter()):
Expand All @@ -322,3 +327,11 @@ def create_watcher(namer_watchdog_config: NamerConfig) -> MovieWatcher:
movie_watcher = MovieWatcher(namer_watchdog_config)

return movie_watcher


def main(config: NamerConfig):
level = 'DEBUG' if config.debug else 'INFO'
logger.add(sys.stdout, format=config.console_format, level=level, diagnose=config.diagnose_errors)

create_watcher(config).run()

16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@
},
"dependencies": {
"@popperjs/core": "^2.11.8",
"bootstrap": "^5.3.5",
"bootstrap-icons": "^1.11.3",
"bootstrap": "^5.3.6",
"bootstrap-icons": "^1.13.1",
"datatables.net": "^2.3.0",
"datatables.net-bs5": "^2.3.0",
"datatables.net-buttons": "^3.2.3",
"datatables.net-buttons-bs5": "^3.2.3",
"datatables.net-colreorder": "^2.0.4",
"datatables.net-colreorder-bs5": "^2.0.4",
"datatables.net-colreorder": "^2.1.0",
"datatables.net-colreorder-bs5": "^2.1.0",
"datatables.net-fixedheader": "^4.0.1",
"datatables.net-fixedheader-bs5": "^4.0.1",
"datatables.net-responsive": "^3.0.4",
Expand All @@ -30,7 +30,7 @@
},
"devDependencies": {
"@babel/core": "^7.27.1",
"@babel/preset-env": "^7.27.1",
"@babel/preset-env": "^7.27.2",
"@eslint/eslintrc": "^3.3.1",
"@eslint/js": "^9.26.0",
"babel-loader": "^10.0.0",
Expand All @@ -40,18 +40,18 @@
"eslint": "^9.26.0",
"eslint-config-standard": "^17.1.0",
"file-loader": "^6.2.0",
"globals": "^16.0.0",
"globals": "^16.1.0",
"html-minimizer-webpack-plugin": "^5.0.2",
"husky": "^9.1.7",
"lint-staged": "^15.5.1",
"lint-staged": "^15.5.2",
"mini-css-extract-plugin": "^2.9.2",
"postcss": "^8.5.3",
"postcss-loader": "^8.1.1",
"postcss-preset-env": "^10.1.6",
"sass": "^1.87.0",
"sass-loader": "^16.0.5",
"terser-webpack-plugin": "^5.3.14",
"webpack": "^5.99.7",
"webpack": "^5.99.8",
"webpack-cli": "^6.0.1"
},
"engines": {
Expand Down
Loading
Loading