|
1 | 1 | """This module takes care of downloading WEBKNOSSOS datasets.""" |
2 | 2 |
|
| 3 | +import re |
3 | 4 | from typing import Any, List, Optional |
4 | 5 |
|
5 | 6 | import typer |
6 | 7 | from typing_extensions import Annotated |
7 | 8 |
|
8 | | -from ..annotation import Annotation |
| 9 | +from ..annotation.annotation import _ANNOTATION_URL_REGEX, Annotation |
9 | 10 | from ..client import webknossos_context |
10 | | -from ..dataset import Dataset |
| 11 | +from ..client._resolve_short_link import resolve_short_link |
| 12 | +from ..dataset.dataset import _DATASET_URL_REGEX, Dataset |
11 | 13 | from ..geometry import BoundingBox, Mag |
12 | 14 | from ._utils import parse_bbox, parse_mag, parse_path |
13 | 15 |
|
@@ -72,15 +74,24 @@ def main( |
72 | 74 |
|
73 | 75 | layers = layer if layer else None |
74 | 76 | mags = mag if mag else None |
| 77 | + url = resolve_short_link(url) |
75 | 78 |
|
76 | 79 | with webknossos_context(token=token): |
77 | | - try: |
| 80 | + if re.match(_DATASET_URL_REGEX, url): |
78 | 81 | Dataset.download( |
79 | 82 | dataset_name_or_url=url, |
80 | 83 | path=target, |
81 | 84 | bbox=bbox, |
82 | 85 | layers=layers, |
83 | 86 | mags=mags, |
84 | 87 | ) |
85 | | - except AssertionError: |
| 88 | + elif re.match(_ANNOTATION_URL_REGEX, url): |
86 | 89 | Annotation.download(annotation_id_or_url=url).save(target) |
| 90 | + else: |
| 91 | + raise RuntimeError( |
| 92 | + "The provided URL does not lead to a dataset or annotation." |
| 93 | + ) |
| 94 | + |
| 95 | + |
| 96 | +if __name__ == "__main__": |
| 97 | + typer.run(main) |
0 commit comments