Skip to content

Commit

Permalink
fix windows support
Browse files Browse the repository at this point in the history
  • Loading branch information
freddy36 committed Jun 27, 2024
1 parent 4f59bc9 commit f0963f7
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion audiobookdl/output/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,23 @@ def convert_output(filenames: Sequence[str], output_format: str):
new_paths.append(new_path)
return new_paths

def get_max_name_length() -> int:
"""
Get the max length for file names supported by the OS
:returns: max length for file names
"""
try:
# should work on Linux/MacOS
return os.pathconf(".", "PC_NAME_MAX")
except:
try:
# Windows
from ctypes.wintypes import MAX_PATH
return MAX_PATH
except:
# default
return 255

def gen_output_location(template: str, metadata: AudiobookMetadata, remove_chars: str) -> str:
"""
Expand All @@ -110,7 +127,7 @@ def gen_output_location(template: str, metadata: AudiobookMetadata, remove_chars
:param remove_chars: List of characters to be removed from the final path
:returns: `template` with metadata inserted
"""
max_name_length = os.pathconf(".", 'PC_NAME_MAX')
max_name_length = get_max_name_length()

if metadata is None:
metadata = {}
Expand Down

0 comments on commit f0963f7

Please sign in to comment.