plex-prerolls/modules/files.py
Nate Harris 5bf153e92f
[feat] Use glob patterns to auto-find local paths, translate to remote paths (#3)
- Advanced options: Use glob patterns to match local files, translate to remote paths
- Add optional file path to Unraid template
2024-02-03 20:57:50 -07:00

33 lines
1014 B
Python

import glob
import os
from typing import List
def get_all_files_matching_glob_pattern(directory: str, pattern: str) -> List[str]:
"""
Get all files matching a glob pattern in a directory.
Args:
directory (str): The directory to search in.
pattern (str): The glob pattern to search for.
Returns:
List[str]: A list of file paths that match the glob pattern.
"""
return [file for file in glob.glob(os.path.join(directory, pattern)) if os.path.isfile(file)]
def translate_local_path_to_remote_path(local_path: str, local_root_folder: str, remote_root_folder: str) -> str:
"""
Translate a local path to a remote path.
Args:
local_path (str): The local path to translate.
local_root_folder (str): The root folder of the local path.
remote_root_folder (str): The root folder of the remote path.
Returns:
str: The translated remote path.
"""
return local_path.replace(local_root_folder, remote_root_folder, 1)