Skip to content

Commit 7b1a384

Browse files
committed
fix windows support
1 parent 4f59bc9 commit 7b1a384

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

audiobookdl/output/output.py

+18-1
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,23 @@ def convert_output(filenames: Sequence[str], output_format: str):
100100
new_paths.append(new_path)
101101
return new_paths
102102

103+
def get_max_name_length() -> int:
104+
"""
105+
Get the max length for file names supported by the OS
106+
107+
:returns: max length for file names
108+
"""
109+
try:
110+
# should work on Linux/MacOS
111+
return os.pathconf(".", "PC_NAME_MAX")
112+
except:
113+
try:
114+
# Windows
115+
from ctypes.wintypes import MAX_PATH
116+
return MAX_PATH
117+
except:
118+
# default
119+
return 255
103120

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

115132
if metadata is None:
116133
metadata = {}

0 commit comments

Comments
 (0)