mapillary-downloader 0.6.1__py3-none-any.whl → 0.7.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- mapillary_downloader/tar_sequences.py +29 -28
- mapillary_downloader/worker.py +15 -5
- {mapillary_downloader-0.6.1.dist-info → mapillary_downloader-0.7.0.dist-info}/METADATA +24 -10
- {mapillary_downloader-0.6.1.dist-info → mapillary_downloader-0.7.0.dist-info}/RECORD +7 -7
- {mapillary_downloader-0.6.1.dist-info → mapillary_downloader-0.7.0.dist-info}/WHEEL +0 -0
- {mapillary_downloader-0.6.1.dist-info → mapillary_downloader-0.7.0.dist-info}/entry_points.txt +0 -0
- {mapillary_downloader-0.6.1.dist-info → mapillary_downloader-0.7.0.dist-info}/licenses/LICENSE.md +0 -0
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"""Tar sequence directories for efficient Internet Archive uploads."""
|
|
2
2
|
|
|
3
3
|
import logging
|
|
4
|
+
import re
|
|
4
5
|
import tarfile
|
|
5
6
|
from pathlib import Path
|
|
6
7
|
from mapillary_downloader.utils import format_size
|
|
@@ -9,7 +10,9 @@ logger = logging.getLogger("mapillary_downloader")
|
|
|
9
10
|
|
|
10
11
|
|
|
11
12
|
def tar_sequence_directories(collection_dir):
|
|
12
|
-
"""Tar all
|
|
13
|
+
"""Tar all date directories in a collection for faster IA uploads.
|
|
14
|
+
|
|
15
|
+
Organizes by capture date (YYYY-MM-DD) for incremental archive.org uploads.
|
|
13
16
|
|
|
14
17
|
Args:
|
|
15
18
|
collection_dir: Path to collection directory (e.g., mapillary-user-quality/)
|
|
@@ -23,44 +26,44 @@ def tar_sequence_directories(collection_dir):
|
|
|
23
26
|
logger.error(f"Collection directory not found: {collection_dir}")
|
|
24
27
|
return 0, 0
|
|
25
28
|
|
|
26
|
-
# Find all
|
|
27
|
-
#
|
|
29
|
+
# Find all date directories (skip special dirs)
|
|
30
|
+
# Date format: YYYY-MM-DD or unknown-date
|
|
28
31
|
skip_dirs = {".meta", "__pycache__"}
|
|
29
|
-
|
|
32
|
+
date_dirs = []
|
|
30
33
|
|
|
31
34
|
for item in collection_dir.iterdir():
|
|
32
35
|
if item.is_dir() and item.name not in skip_dirs:
|
|
33
|
-
# Check if this is a
|
|
34
|
-
if
|
|
35
|
-
|
|
36
|
+
# Check if this is a date dir (YYYY-MM-DD) or unknown-date
|
|
37
|
+
if re.match(r"\d{4}-\d{2}-\d{2}$", item.name) or item.name == "unknown-date":
|
|
38
|
+
date_dirs.append(item)
|
|
36
39
|
|
|
37
|
-
if not
|
|
38
|
-
logger.info("No
|
|
40
|
+
if not date_dirs:
|
|
41
|
+
logger.info("No date directories to tar")
|
|
39
42
|
return 0, 0
|
|
40
43
|
|
|
41
|
-
# Sort
|
|
42
|
-
|
|
44
|
+
# Sort date directories chronologically (YYYY-MM-DD sorts naturally)
|
|
45
|
+
date_dirs = sorted(date_dirs, key=lambda x: x.name)
|
|
43
46
|
|
|
44
|
-
logger.info(f"Tarring {len(
|
|
47
|
+
logger.info(f"Tarring {len(date_dirs)} date directories...")
|
|
45
48
|
|
|
46
49
|
tarred_count = 0
|
|
47
50
|
total_files = 0
|
|
48
51
|
total_tar_bytes = 0
|
|
49
52
|
|
|
50
|
-
for
|
|
51
|
-
|
|
52
|
-
tar_path = collection_dir / f"{
|
|
53
|
+
for date_dir in date_dirs:
|
|
54
|
+
date_name = date_dir.name
|
|
55
|
+
tar_path = collection_dir / f"{date_name}.tar"
|
|
53
56
|
|
|
54
|
-
# Count files in
|
|
55
|
-
files_to_tar = sorted([f for f in
|
|
57
|
+
# Count files in date directory
|
|
58
|
+
files_to_tar = sorted([f for f in date_dir.rglob("*") if f.is_file()], key=lambda x: str(x))
|
|
56
59
|
file_count = len(files_to_tar)
|
|
57
60
|
|
|
58
61
|
if file_count == 0:
|
|
59
|
-
logger.warning(f"Skipping empty
|
|
62
|
+
logger.warning(f"Skipping empty date directory: {date_name}")
|
|
60
63
|
continue
|
|
61
64
|
|
|
62
65
|
try:
|
|
63
|
-
logger.info(f"Tarring
|
|
66
|
+
logger.info(f"Tarring date '{date_name}' ({file_count} files)...")
|
|
64
67
|
|
|
65
68
|
# Create reproducible uncompressed tar (WebP already compressed)
|
|
66
69
|
with tarfile.open(tar_path, "w") as tar:
|
|
@@ -87,36 +90,34 @@ def tar_sequence_directories(collection_dir):
|
|
|
87
90
|
tar_size = tar_path.stat().st_size
|
|
88
91
|
total_tar_bytes += tar_size
|
|
89
92
|
|
|
90
|
-
# Remove original
|
|
91
|
-
for file in
|
|
93
|
+
# Remove original date directory
|
|
94
|
+
for file in date_dir.rglob("*"):
|
|
92
95
|
if file.is_file():
|
|
93
96
|
file.unlink()
|
|
94
97
|
|
|
95
98
|
# Remove empty subdirs and main dir
|
|
96
|
-
for subdir in list(
|
|
99
|
+
for subdir in list(date_dir.rglob("*")):
|
|
97
100
|
if subdir.is_dir():
|
|
98
101
|
try:
|
|
99
102
|
subdir.rmdir()
|
|
100
103
|
except OSError:
|
|
101
104
|
pass # Not empty yet
|
|
102
105
|
|
|
103
|
-
|
|
106
|
+
date_dir.rmdir()
|
|
104
107
|
|
|
105
108
|
tarred_count += 1
|
|
106
109
|
total_files += file_count
|
|
107
110
|
|
|
108
|
-
logger.info(f"Tarred
|
|
111
|
+
logger.info(f"Tarred date '{date_name}': {file_count:,} files, {format_size(tar_size)}")
|
|
109
112
|
else:
|
|
110
113
|
logger.error(f"Tar file empty or not created: {tar_path}")
|
|
111
114
|
if tar_path.exists():
|
|
112
115
|
tar_path.unlink()
|
|
113
116
|
|
|
114
117
|
except Exception as e:
|
|
115
|
-
logger.error(f"Error tarring
|
|
118
|
+
logger.error(f"Error tarring date {date_name}: {e}")
|
|
116
119
|
if tar_path.exists():
|
|
117
120
|
tar_path.unlink()
|
|
118
121
|
|
|
119
|
-
logger.info(
|
|
120
|
-
f"Tarred {tarred_count} sequences ({total_files:,} files, {format_size(total_tar_bytes)} total tar size)"
|
|
121
|
-
)
|
|
122
|
+
logger.info(f"Tarred {tarred_count} dates ({total_files:,} files, {format_size(total_tar_bytes)} total tar size)")
|
|
122
123
|
return tarred_count, total_files
|
mapillary_downloader/worker.py
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
import os
|
|
4
4
|
import signal
|
|
5
5
|
import tempfile
|
|
6
|
+
from datetime import datetime
|
|
6
7
|
from pathlib import Path
|
|
7
8
|
import requests
|
|
8
9
|
from mapillary_downloader.exif_writer import write_exif_to_image
|
|
@@ -69,16 +70,25 @@ def download_and_convert_image(image_data, output_dir, quality, convert_webp, se
|
|
|
69
70
|
if not image_url:
|
|
70
71
|
return (image_id, 0, False, f"No {quality} URL")
|
|
71
72
|
|
|
72
|
-
# Determine final output directory - organize by
|
|
73
|
+
# Determine final output directory - organize by capture date
|
|
73
74
|
output_dir = Path(output_dir)
|
|
74
75
|
sequence_id = image_data.get("sequence")
|
|
76
|
+
|
|
77
|
+
# Extract date from captured_at timestamp (milliseconds since epoch)
|
|
78
|
+
captured_at = image_data.get("captured_at")
|
|
79
|
+
if captured_at:
|
|
80
|
+
# Convert to UTC date string (YYYY-MM-DD)
|
|
81
|
+
date_str = datetime.utcfromtimestamp(captured_at / 1000).strftime("%Y-%m-%d")
|
|
82
|
+
else:
|
|
83
|
+
# Fallback for missing timestamp (should be rare per API docs)
|
|
84
|
+
date_str = "unknown-date"
|
|
85
|
+
|
|
75
86
|
if sequence_id:
|
|
76
|
-
|
|
77
|
-
first_char = sequence_id[0]
|
|
78
|
-
img_dir = output_dir / first_char / sequence_id
|
|
87
|
+
img_dir = output_dir / date_str / sequence_id
|
|
79
88
|
img_dir.mkdir(parents=True, exist_ok=True)
|
|
80
89
|
else:
|
|
81
|
-
img_dir = output_dir
|
|
90
|
+
img_dir = output_dir / date_str
|
|
91
|
+
img_dir.mkdir(parents=True, exist_ok=True)
|
|
82
92
|
|
|
83
93
|
# If converting to WebP, use /tmp for intermediate JPEG
|
|
84
94
|
# Otherwise write JPEG directly to final location
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: mapillary_downloader
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.7.0
|
|
4
4
|
Summary: Archive user data from Mapillary
|
|
5
5
|
Author-email: Gareth Davidson <gaz@bitplane.net>
|
|
6
6
|
Requires-Python: >=3.10
|
|
@@ -100,21 +100,28 @@ mapillary-downloader --no-webp USERNAME
|
|
|
100
100
|
|
|
101
101
|
## Tarballs
|
|
102
102
|
|
|
103
|
-
Images are organized by
|
|
104
|
-
sequence to reduce directory count:
|
|
103
|
+
Images are organized by capture date (YYYY-MM-DD) for incremental archiving:
|
|
105
104
|
|
|
106
105
|
```
|
|
107
106
|
mapillary-username-quality/
|
|
108
|
-
|
|
107
|
+
2024-01-15/
|
|
109
108
|
abc123/
|
|
110
109
|
image1.webp
|
|
111
110
|
image2.webp
|
|
111
|
+
bcd456/
|
|
112
|
+
image3.webp
|
|
113
|
+
2024-01-16/
|
|
114
|
+
def789/
|
|
115
|
+
image4.webp
|
|
112
116
|
```
|
|
113
117
|
|
|
114
|
-
By default, these
|
|
115
|
-
(resulting in `
|
|
116
|
-
|
|
117
|
-
|
|
118
|
+
By default, these date directories are automatically tarred after download
|
|
119
|
+
(resulting in `2024-01-15.tar`, `2024-01-16.tar`, etc.). This date-based
|
|
120
|
+
organization enables:
|
|
121
|
+
|
|
122
|
+
- **Incremental uploads** - Upload each day's tar as soon as it's ready
|
|
123
|
+
- **Manageable file counts** - ~365 days/year × 10 years = 3,650 tars max
|
|
124
|
+
- **Chronological organization** - Natural sorting and progress tracking
|
|
118
125
|
|
|
119
126
|
To keep individual files instead of creating tars, use the `--no-tar` flag.
|
|
120
127
|
|
|
@@ -128,8 +135,15 @@ See inlay for details:
|
|
|
128
135
|
|
|
129
136
|
* [📀 rip](https://bitplane.net/dev/sh/rip)
|
|
130
137
|
|
|
138
|
+
## 📊 Stats
|
|
139
|
+
|
|
140
|
+
To see overall project progress, or an estimate, use `--stats`
|
|
141
|
+
|
|
142
|
+
```bash
|
|
143
|
+
mapillary-downloader --stats
|
|
144
|
+
```
|
|
131
145
|
|
|
132
|
-
## Development
|
|
146
|
+
## 🚧 Development
|
|
133
147
|
|
|
134
148
|
```bash
|
|
135
149
|
make dev # Setup dev environment
|
|
@@ -138,7 +152,7 @@ make dist # Build the distribution
|
|
|
138
152
|
make help # See other make options
|
|
139
153
|
```
|
|
140
154
|
|
|
141
|
-
## Links
|
|
155
|
+
## 🔗 Links
|
|
142
156
|
|
|
143
157
|
* [🏠 home](https://bitplane.net/dev/python/mapillary_downloader)
|
|
144
158
|
* [📖 pydoc](https://bitplane.net/dev/python/mapillary_downloader/pydoc)
|
|
@@ -8,13 +8,13 @@ mapillary_downloader/ia_meta.py,sha256=78rcybHIPnQDsF02KGj6RYmDXzYzrU8sdVx4Q9Y0s
|
|
|
8
8
|
mapillary_downloader/ia_stats.py,sha256=TSVCoaCcGFDPTYqxikGdvMo7uWtExRniYABjQQS26fw,7302
|
|
9
9
|
mapillary_downloader/logging_config.py,sha256=Z-wNq34nt7aIhJWdeKc1feTY46P9-Or7HtiX7eUFjEI,2324
|
|
10
10
|
mapillary_downloader/metadata_reader.py,sha256=Re-HN0Vfc7Hs1eOut7uOoW7jWJ2PIbKoNzC7Ak3ah5o,4933
|
|
11
|
-
mapillary_downloader/tar_sequences.py,sha256=
|
|
11
|
+
mapillary_downloader/tar_sequences.py,sha256=UchKvvajBr5uaoE8xDHgyiFTkjh08EK7pPhtwkyCQXU,4416
|
|
12
12
|
mapillary_downloader/utils.py,sha256=VgcwbC8yb2XlTGerTNwHBU42K2IN14VU7P-I52Vb01c,2947
|
|
13
13
|
mapillary_downloader/webp_converter.py,sha256=vYLLQxDmdnqRz0nm7wXwRUd4x9mQZNah-DrncpA8sNs,1901
|
|
14
|
-
mapillary_downloader/worker.py,sha256=
|
|
14
|
+
mapillary_downloader/worker.py,sha256=K2DkQgFzALKs20TsG1KibNUdFiWN_v8MtVnBX_0xVyc,5162
|
|
15
15
|
mapillary_downloader/worker_pool.py,sha256=iGRq5uFwBNNVQnI4vEjbKHkbKTaEVCdmvMvXcRGuDMg,8203
|
|
16
|
-
mapillary_downloader-0.
|
|
17
|
-
mapillary_downloader-0.
|
|
18
|
-
mapillary_downloader-0.
|
|
19
|
-
mapillary_downloader-0.
|
|
20
|
-
mapillary_downloader-0.
|
|
16
|
+
mapillary_downloader-0.7.0.dist-info/entry_points.txt,sha256=PdYtxOXHMJrUhmiPO4G-F98VuhUI4MN9D_T4KPrVZ5w,75
|
|
17
|
+
mapillary_downloader-0.7.0.dist-info/licenses/LICENSE.md,sha256=7_BIuQ-veOrsF-WarH8kTkm0-xrCLvJ1PFE1C4Ebs64,146
|
|
18
|
+
mapillary_downloader-0.7.0.dist-info/WHEEL,sha256=G2gURzTEtmeR8nrdXUJfNiB3VYVxigPQ-bEQujpNiNs,82
|
|
19
|
+
mapillary_downloader-0.7.0.dist-info/METADATA,sha256=Ftc--29thU8dc-J_11_NlBUnf6SsOlvQP4r28nclsnk,5540
|
|
20
|
+
mapillary_downloader-0.7.0.dist-info/RECORD,,
|
|
File without changes
|
{mapillary_downloader-0.6.1.dist-info → mapillary_downloader-0.7.0.dist-info}/entry_points.txt
RENAMED
|
File without changes
|
{mapillary_downloader-0.6.1.dist-info → mapillary_downloader-0.7.0.dist-info}/licenses/LICENSE.md
RENAMED
|
File without changes
|