diff --git a/gallery_dl/path.py b/gallery_dl/path.py index 21e1aa00..54cf126e 100644 --- a/gallery_dl/path.py +++ b/gallery_dl/path.py @@ -269,7 +269,7 @@ class PathFormat(): try: for fmt in self.directory_formatters: segment = fmt(kwdict).strip() - if strip and segment != "..": + if strip and segment not in {".", ".."}: # remove trailing dots and spaces (#647) segment = segment.rstrip(strip) if segment: diff --git a/gallery_dl/postprocessor/metadata.py b/gallery_dl/postprocessor/metadata.py index 3ef9fbce..cb6fac29 100644 --- a/gallery_dl/postprocessor/metadata.py +++ b/gallery_dl/postprocessor/metadata.py @@ -180,7 +180,10 @@ class MetadataPP(PostProcessor): pathfmt.directory_formatters = self._directory_formatters pathfmt.directory_conditions = () segments = pathfmt.build_directory(pathfmt.kwdict) - directory = pathfmt.clean_path(os.sep.join(segments) + os.sep) + if segments: + directory = pathfmt.clean_path(os.sep.join(segments) + os.sep) + else: + directory = "." + os.sep return os.path.join(self._base(pathfmt), directory) finally: pathfmt.directory_conditions = conditions diff --git a/test/test_postprocessor.py b/test/test_postprocessor.py index 2941b815..d3bff4a0 100644 --- a/test/test_postprocessor.py +++ b/test/test_postprocessor.py @@ -511,6 +511,17 @@ class MetadataTest(BasePostprocessorTest): path = self.pathfmt.realdirectory + "../json/12500/file.ext.json" m.assert_called_once_with(path, "w", encoding="utf-8") + def test_metadata_directory_empty(self): + self._create( + {"directory": []}, + ) + + with patch("builtins.open", mock_open()) as m: + self._trigger() + + path = self.pathfmt.realdirectory + "./file.ext.json" + m.assert_called_once_with(path, "w", encoding="utf-8") + def test_metadata_basedirectory(self): self._create({"base-directory": True})