Skip to content

Commit a0716c0

Browse files
authored
WIP: add API v4 support (#393)
* feat: add API v4 support * do not require MAPSettingsUserKey * fix mime * add back MAPSettingsUserKey as required * sort images by captured_at * refactor * v4 login support * handle null cluster id * fix config path * fix types * fix path in windows * fix the vertical path in windows * read captured_at from mapillary_image_description.json instead of EXIF * refactor logins * refactor login again * default api version to v4 * delete send_videos_for_processing * delete download commands * bump version to 0.7 * update README * remove master key * format * update the endpoints
1 parent 44dc2f2 commit a0716c0

23 files changed

+408
-1313
lines changed

README.md

Lines changed: 1 addition & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,6 @@ password?" link on the Mapillary sign-in screen.
4646
To upload images to Mapillary, image `GPS` and `capture time` are minimally required. More
4747
information [here](https://help.mapillary.com/hc/en-us/articles/115001717829-Geotagging-images).
4848

49-
### Videos
50-
51-
To upload videos to Mapillary, videos are sampled into images and tagged with image `GPS` and `capture time`. Use
52-
the [`send_videos_for_processing`](#direct-upload-recommended) command for Blackvue cameras. For all other models
53-
use [Video Sampling and Upload](#video-sampling-and-upload)
54-
5549
## Installation
5650

5751
### Python 3
@@ -204,7 +198,6 @@ Available commands for advanced usage:
204198
- interpolate
205199
- authenticate
206200
- post_process
207-
- download
208201

209202
### Geotag and Upload
210203

@@ -625,66 +618,10 @@ gps data in a set of otherwise geotagged images.
625618
`post_process` provides functionalities to help summarize and organize the results of the `process` and/or `upload`
626619
commands.
627620

628-
#### `download`
629-
630-
There are few ways to download blurred originals of private images from Mapillary: by import path or by image key.
631-
632-
##### Downloading by import path
633-
634-
`download` (by import path) will download blurred originals of private images on Mapillary for a certain `import_path`.
635-
The import path is specified as a folder where you have the images you've uploaded to Mapillary as private imagery. They
636-
need to have the Mapillary image description field in EXIF (which gets added during capture with our mobile apps or
637-
processing with our command line tools). Matching images will be downloaded to the output folder you specify.
638-
639-
```bash
640-
mapillary_tools download --advanced --import_path "path/to/images" --output_folder "path/to/output_folder"
641-
```
642-
643-
##### Downloading by image key
644-
645-
You can download any images which belong to an organization (whether private or public) by using this command. This
646-
command downloads **private images by default**, to download publicly uploaded images from the given organization you
647-
need to pass `--private=false` flag. There are some access restrictions when it comes to downloading the data: you have
648-
to be authenticated as an organization admin/member to download the imagery. Contributors don't have access to this
649-
command. Attempting to download an organization image (whether public/private) as a contributor will yield
650-
an `You don't have sufficient organization access to download this image` error.
651-
652-
```bash
653-
mapillary_tools download --advanced --by_property key \
654-
--import_path /dev/null \
655-
--output_folder "path/to/output_folder" \
656-
--organization_keys "org_key1" "org_key2" \
657-
--user_name "mapillary_username"
658-
```
659-
660-
The command above specifies will attempt to download all privately blurred images for the organization `org_key`. These
661-
are all flags the command supports:
662-
663-
- `organization_keys` - what are the keys of organizations which own the images
664-
- `private` - download private/non-private images (default is `--private=true`)
665-
- `user_name` - the username of the authenticate user (see `authenticate` section)
666-
- `import_path` - it's ignored in this script
667-
- `output_folder` - where to download the images to
668-
- `start_time` - the beginning of the time range, `YYYY-MM-DD`
669-
- `end_time` - the end of the time range, `YYYY-MM-DD`
670-
671621
## Camera specific
672622

673623
### BlackVue
674-
675-
#### Direct Upload (Recommended)
676-
677-
- Upload videos located in `path/to/videos` directly to Mapillary. Videos are moved to `path/to/videos/uploaded` folder
678-
after upload. Videos that do not contain valid imagery are not uploaded to minimize bandwitdh usage. Sampling is
679-
performed in the cloud so no extra disk space is required. This command supports the front camera video from the
680-
Blackvue DR900s (1-channel and 2-channel) models.
681-
682-
```bash
683-
mapillary_tools send_videos_for_processing --advanced --video_import_path "path/to/videos" \
684-
--user_name "mapillary_username"
685-
```
686-
687-
#### Local sampling (Deprecated)
624+
#### Local sampling
688625

689626
- Sample one or more Blackvue videos in directory `path/to/videos` into import path `path/to/images` at a sampling rate
690627
0.2 seconds, ie 5 frames every second and process resulting video frames for user `mapillary_user`, reading geotag

mapillary_tools/__init__.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,9 @@
1-
VERSION = "0.6.0"
1+
import os
2+
3+
VERSION = "0.7.0"
4+
5+
MAPILLARY_API_VERSION = os.getenv("MAPILLARY_API_VERSION", "v4")
6+
assert MAPILLARY_API_VERSION in [
7+
"v3",
8+
"v4",
9+
], "MAPILLARY_API_VERSION must be either v3 or v4"

mapillary_tools/api_v3.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,17 @@
44
from .error import print_error
55

66
API_ENDPOINT = os.getenv("API_PROXY_HOST", "https://a.mapillary.com")
7-
CLIENT_ID = os.getenv(
7+
MAPILLARY_WEB_CLIENT_ID = os.getenv(
88
"MAPILLARY_WEB_CLIENT_ID", "MkJKbDA0bnZuZlcxeTJHTmFqN3g1dzo1YTM0NjRkM2EyZGU5MzBh"
99
)
1010

1111

1212
def get_user(jwt):
1313
headers = {"Authorization": f"Bearer {jwt}"}
1414
resp = requests.get(
15-
f"{API_ENDPOINT}/v3/me", params={"client_id": CLIENT_ID}, headers=headers
15+
f"{API_ENDPOINT}/v3/me",
16+
params={"client_id": MAPILLARY_WEB_CLIENT_ID},
17+
headers=headers,
1618
)
1719
resp.raise_for_status()
1820
return resp.json()
@@ -22,7 +24,7 @@ def fetch_user_organizations(user_key, auth_token):
2224
headers = {"Authorization": f"Bearer {auth_token}"}
2325
resp = requests.get(
2426
f"{API_ENDPOINT}/v3/users/{user_key}/organizations",
25-
params={"client_id": CLIENT_ID},
27+
params={"client_id": MAPILLARY_WEB_CLIENT_ID},
2628
headers=headers,
2729
)
2830
resp.raise_for_status()
@@ -32,7 +34,9 @@ def fetch_user_organizations(user_key, auth_token):
3234
def get_upload_token(mail, pwd):
3335
payload = {"email": mail, "password": pwd}
3436
resp = requests.post(
35-
f"{API_ENDPOINT}/v2/ua/login", params={"client_id": CLIENT_ID}, json=payload
37+
f"{API_ENDPOINT}/v2/ua/login",
38+
params={"client_id": MAPILLARY_WEB_CLIENT_ID},
39+
json=payload,
3640
)
3741
if resp.status_code == 401:
3842
return None
@@ -43,7 +47,7 @@ def get_upload_token(mail, pwd):
4347
def get_user_key(user_name):
4448
resp = requests.get(
4549
f"{API_ENDPOINT}/v3/users",
46-
params={"client_id": CLIENT_ID, "usernames": user_name},
50+
params={"client_id": MAPILLARY_WEB_CLIENT_ID, "usernames": user_name},
4751
)
4852
resp.raise_for_status()
4953
resp = resp.json()

mapillary_tools/api_v4.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import os
2+
import requests
3+
4+
MAPILLARY_WEB_CLIENT_ID = os.getenv(
5+
"MAPILLARY_WEB_CLIENT_ID", "MLY|5675152195860640|6b02c72e6e3c801e5603ab0495623282"
6+
)
7+
MAPILLARY_GRAPH_API_ENDPOINT = os.getenv(
8+
"MAPILLARY_GRAPH_API_ENDPOINT", "https://graph.mapillary.com"
9+
)
10+
11+
12+
def get_upload_token(email: str, password: str) -> dict:
13+
resp = requests.post(
14+
f"{MAPILLARY_GRAPH_API_ENDPOINT}/login",
15+
params={"access_token": MAPILLARY_WEB_CLIENT_ID},
16+
json={"email": email, "password": password},
17+
)
18+
resp.raise_for_status()
19+
return resp.json()

mapillary_tools/commands/__init__.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
from . import authenticate
2-
from . import download
32
from . import exif_insert
43
from . import extract_geotag_data
54
from . import extract_import_meta_data
@@ -12,7 +11,6 @@
1211
from . import process_and_upload
1312
from . import process_csv
1413
from . import sample_video
15-
from . import send_videos_for_processing
1614
from . import upload
1715
from . import video_process
1816
from . import video_process_and_upload
@@ -31,8 +29,6 @@
3129
authenticate,
3230
interpolate,
3331
post_process,
34-
download,
35-
send_videos_for_processing,
3632
]
3733

3834
mapillary_tools_commands = [process, upload, process_and_upload]
@@ -73,7 +69,6 @@ def add_general_arguments(parser, command):
7369
"video_process",
7470
"video_process_and_upload",
7571
"sample_video",
76-
"send_videos_for_processing",
7772
]:
7873
required = False
7974

mapillary_tools/commands/authenticate.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class Command:
88
def add_basic_arguments(self, parser):
99
parser.add_argument(
1010
"--config_file",
11-
help="Full path to the config file to be edited. Default is ~/.config/mapillary/configs/MkJKbDA0bnZuZlcxeTJHTmFqN3g1dzo1YTM0NjRkM2EyZGU5MzBh",
11+
help="Full path to the config file to be edited. Default is ~/.config/mapillary/configs/MLY_CLIENT_ID",
1212
default=None,
1313
required=False,
1414
)

mapillary_tools/commands/download.py

Lines changed: 0 additions & 86 deletions
This file was deleted.

mapillary_tools/commands/send_videos_for_processing.py

Lines changed: 0 additions & 86 deletions
This file was deleted.

0 commit comments

Comments
 (0)