fixes for file naming
formatting_check / formatting_check (push) Failing after 6s
Python Test / test (.sh, ubuntu-latest, 3.9) (push) Failing after 16s
Python Test / test (.ps1, windows-latest, 3.9) (push) Has been cancelled
Python Test / test (.sh, macos-latest, 3.9) (push) Has been cancelled
formatting_check / formatting_check (push) Failing after 6s
Python Test / test (.sh, ubuntu-latest, 3.9) (push) Failing after 16s
Python Test / test (.ps1, windows-latest, 3.9) (push) Has been cancelled
Python Test / test (.sh, macos-latest, 3.9) (push) Has been cancelled
This commit is contained in:
@@ -26,6 +26,7 @@ _common_options = [
|
||||
click.option("--file-scheme", default=None, type=str),
|
||||
click.option("--filename-restriction-scheme", type=click.Choice(("linux", "windows")), default=None),
|
||||
click.option("--folder-scheme", default=None, type=str),
|
||||
click.option("--strip-unicode/--no-strip-unicode", default=None, help="Strip Unicode characters that cause Windows SMB issues (default: enabled)"),
|
||||
click.option("--ignore-user", type=str, multiple=True, default=None),
|
||||
click.option("--include-id-file", multiple=True, default=None),
|
||||
click.option("--log", type=str, default=None),
|
||||
|
||||
@@ -1234,6 +1234,15 @@ class BDFRManager:
|
||||
config.saved = saved
|
||||
config.no_dupes = no_dupes
|
||||
config.simple_check = simple_check
|
||||
|
||||
# Set authentication if token is available for this manager instance
|
||||
if self.auth_token:
|
||||
config.authenticate = True
|
||||
config.auth_token = self.auth_token
|
||||
logger.info(f"[DEBUG] Authentication enabled for user download with token")
|
||||
else:
|
||||
config.authenticate = False
|
||||
logger.info(f"[DEBUG] No authentication token available for user download")
|
||||
|
||||
download_id = self.create_download(
|
||||
DownloadType.USER,
|
||||
|
||||
@@ -25,6 +25,7 @@ class Configuration(Namespace):
|
||||
self.file_scheme: str = "{REDDITOR}_{TITLE}_{POSTID}"
|
||||
self.filename_restriction_scheme = None
|
||||
self.folder_scheme: str = "{SUBREDDIT}"
|
||||
self.strip_unicode: bool = True
|
||||
self.ignore_user = []
|
||||
self.include_id_file = []
|
||||
self.limit: Optional[int] = None
|
||||
|
||||
+1
-1
@@ -441,7 +441,7 @@ class RedditConnector(metaclass=ABCMeta):
|
||||
|
||||
def create_file_name_formatter(self) -> FileNameFormatter:
|
||||
return FileNameFormatter(
|
||||
self.args.file_scheme, self.args.folder_scheme, self.args.time_format, self.args.filename_restriction_scheme
|
||||
self.args.file_scheme, self.args.folder_scheme, self.args.time_format, self.args.filename_restriction_scheme, self.args.strip_unicode
|
||||
)
|
||||
|
||||
def create_time_filter(self) -> RedditTypes.TimeType:
|
||||
|
||||
@@ -36,6 +36,7 @@ class FileNameFormatter:
|
||||
directory_format_string: str,
|
||||
time_format_string: str,
|
||||
restriction_scheme: Optional[str] = None,
|
||||
strip_unicode: bool = True,
|
||||
):
|
||||
if not self.validate_string(file_format_string):
|
||||
raise BulkDownloaderException(f'"{file_format_string}" is not a valid format string')
|
||||
@@ -43,6 +44,7 @@ class FileNameFormatter:
|
||||
self.directory_format_string: list[str] = directory_format_string.split("/")
|
||||
self.time_format_string = time_format_string
|
||||
self.restiction_scheme = restriction_scheme.lower().strip() if restriction_scheme else None
|
||||
self.strip_unicode = strip_unicode
|
||||
if self.restiction_scheme == "windows":
|
||||
self.max_path = self.WINDOWS_MAX_PATH_LENGTH
|
||||
else:
|
||||
@@ -65,12 +67,22 @@ class FileNameFormatter:
|
||||
|
||||
result = result.replace("/", "")
|
||||
|
||||
# Strip Unicode characters that cause Windows SMB issues if enabled
|
||||
if self.strip_unicode:
|
||||
result = FileNameFormatter._strip_unicode_chars(result)
|
||||
|
||||
if self.restiction_scheme is None:
|
||||
if platform.system() == "Windows":
|
||||
result = FileNameFormatter._format_for_windows(result)
|
||||
# Strip emojis on Windows if strip_unicode is enabled (for backward compatibility)
|
||||
if self.strip_unicode:
|
||||
result = FileNameFormatter._strip_emojis(result)
|
||||
elif self.restiction_scheme == "windows":
|
||||
logger.debug("Forcing Windows-compatible filenames")
|
||||
result = FileNameFormatter._format_for_windows(result)
|
||||
# Strip emojis when forcing Windows compatibility if strip_unicode is enabled
|
||||
if self.strip_unicode:
|
||||
result = FileNameFormatter._strip_emojis(result)
|
||||
return result
|
||||
|
||||
@staticmethod
|
||||
@@ -219,9 +231,33 @@ class FileNameFormatter:
|
||||
invalid_characters = r'<>:"\/|?*'
|
||||
for char in invalid_characters:
|
||||
input_string = input_string.replace(char, "")
|
||||
input_string = FileNameFormatter._strip_emojis(input_string)
|
||||
return input_string
|
||||
|
||||
@staticmethod
|
||||
def _strip_unicode_chars(input_string: str) -> str:
|
||||
"""Strip Unicode characters that cause Windows SMB to create 8.3 short names"""
|
||||
import unicodedata
|
||||
|
||||
# Remove emoji and symbols that cause Windows SMB issues
|
||||
result = []
|
||||
for char in input_string:
|
||||
# Keep ASCII characters
|
||||
if ord(char) < 0x80:
|
||||
result.append(char)
|
||||
# Keep common Unicode letters, numbers, and punctuation
|
||||
elif unicodedata.category(char) in ['Lu', 'Ll', 'Lt', 'Lm', 'Lo', 'Nd', 'Nl', 'No', 'Pc', 'Pd', 'Ps', 'Pe', 'Pi', 'Pf', 'Po']:
|
||||
result.append(char)
|
||||
# Strip emoji, symbols, and other special characters that cause 8.3 names
|
||||
elif unicodedata.category(char).startswith(('S', 'So', 'Sk', 'Sm')): # Symbols
|
||||
continue
|
||||
elif ord(char) > 0x1F000: # High Unicode ranges often contain emoji
|
||||
continue
|
||||
else:
|
||||
# Keep other Unicode characters that are generally safe
|
||||
result.append(char)
|
||||
|
||||
return ''.join(result)
|
||||
|
||||
@staticmethod
|
||||
def _strip_emojis(input_string: str) -> str:
|
||||
result = input_string.encode("ascii", errors="ignore").decode("utf-8")
|
||||
|
||||
Reference in New Issue
Block a user