@@ -149,7 +149,7 @@ def it_parses_darwin_images_correctly(tmp_path):
149149 assert annotation_file .path == import_file
150150 assert annotation_file .filename == "P49-RediPad-ProPlayLEFTY_442.jpg"
151151 assert annotation_file .dataset_name == None
152- assert annotation_file .version == dt .AnnotationFileVersion (major = 1 , minor = 0 , suffix = '' )
152+ assert annotation_file .version == dt .AnnotationFileVersion (major = 1 , minor = 0 , suffix = "" )
153153
154154 assert len (annotation_file .annotations ) == 2
155155 assert len (annotation_file .annotation_classes ) == 2
@@ -236,7 +236,7 @@ def it_parses_darwin_videos_correctly(tmp_path):
236236 assert annotation_file .path == import_file
237237 assert annotation_file .filename == "above tractor.mp4"
238238 assert annotation_file .dataset_name == None
239- assert annotation_file .version == dt .AnnotationFileVersion (major = 1 , minor = 0 , suffix = '' )
239+ assert annotation_file .version == dt .AnnotationFileVersion (major = 1 , minor = 0 , suffix = "" )
240240
241241 assert len (annotation_file .annotations ) == 1
242242 assert len (annotation_file .annotation_classes ) == 1
@@ -272,7 +272,7 @@ def it_parses_darwin_videos_correctly(tmp_path):
272272 )
273273 ]
274274
275- def it_parses_darwin_v2_correctly (tmp_path ):
275+ def it_parses_darwin_v2_images_correctly (tmp_path ):
276276 content = """
277277 {
278278 "version": "2.0",
@@ -355,19 +355,135 @@ def it_parses_darwin_v2_correctly(tmp_path):
355355 assert annotation_file .path == import_file
356356 assert annotation_file .filename == "item-0.jpg"
357357 assert annotation_file .dataset_name == "Dataset 0"
358- assert annotation_file .version == dt .AnnotationFileVersion (major = 2 , minor = 0 , suffix = '' )
358+ assert annotation_file .item_id == "0185c280-bbad-6117-71a7-a6853a6e3f2e"
359+ assert annotation_file .version == dt .AnnotationFileVersion (major = 2 , minor = 0 , suffix = "" )
359360
360361 assert len (annotation_file .annotations ) == 1
361362 assert len (annotation_file .annotation_classes ) == 1
363+ assert annotation_file .annotations [0 ].id == "f8f5f235-bd47-47be-b4fe-07d49e0177a7"
362364 assert not annotation_file .is_video
363365 assert annotation_file .image_width == 123
364366 assert annotation_file .image_height == 456
365- assert annotation_file .image_url == "http://example.com/fake-api-url/v2/teams/v7/uploads/43a83276-1abf-483b-877e-6e61349f2d1f"
366- assert annotation_file .workview_url == "http://example.com/workview?dataset=545&item=0185c280-bbad-6117-71a7-a6853a6e3f2e"
367+ assert (
368+ annotation_file .image_url
369+ == "http://example.com/fake-api-url/v2/teams/v7/uploads/43a83276-1abf-483b-877e-6e61349f2d1f"
370+ )
371+ assert (
372+ annotation_file .workview_url
373+ == "http://example.com/workview?dataset=545&item=0185c280-bbad-6117-71a7-a6853a6e3f2e"
374+ )
367375 assert not annotation_file .seq
368376 assert not annotation_file .frame_urls
369377 assert annotation_file .remote_path == "/path-0/folder"
370378
379+ def it_parses_darwin_v2_videos_correctly (tmp_path ):
380+ content = """
381+ {
382+ "version": "2.0",
383+ "schema_ref": "https://darwin-public.s3.eu-west-1.amazonaws.com/darwin_json_2_0.schema.json",
384+ "item": {
385+ "name": "item-0.mp4",
386+ "path": "/path-0/folder",
387+ "source_info": {
388+ "dataset": {
389+ "name": "Dataset 0",
390+ "slug": "dataset-0",
391+ "dataset_management_url": "http://example.com/datasets/545/dataset-management"
392+ },
393+ "item_id": "0185c280-bbad-6117-71a7-a6853a6e3f2e",
394+ "team": {
395+ "name": "Team 0",
396+ "slug": "team-0"
397+ },
398+ "workview_url": "http://example.com/workview?dataset=545&item=0185c280-bbad-6117-71a7-a6853a6e3f2e"
399+ },
400+ "slots": [
401+ {
402+ "type": "video",
403+ "slot_name": "0",
404+ "width": 123,
405+ "height": 456,
406+ "thumbnail_url": "http://example.com/fake-api-url/v2/teams/v7/files/71857eb3-6feb-428a-8fc6-0c8a895ea611/thumbnail",
407+ "frame_urls": [
408+ "http://example.com/fake-api-url/v2/teams/v7/files/71857eb3-6feb-428a-8fc6-0c8a895ea611/frames/1",
409+ "http://example.com/fake-api-url/v2/teams/v7/files/71857eb3-6feb-428a-8fc6-0c8a895ea611/frames/2"
410+ ],
411+ "frame_count": 2,
412+ "source_files": [
413+ {
414+ "file_name": "file-0",
415+ "url": "http://example.com/fake-api-url/v2/teams/v7/uploads/43a83276-1abf-483b-877e-6e61349f2d1f"
416+ }
417+ ]
418+ }
419+ ]
420+ },
421+ "annotations": [
422+ {
423+ "frames": {
424+ "3": {
425+ "bounding_box": {
426+ "h": 2,
427+ "w": 1,
428+ "x": 1,
429+ "y": 1
430+ },
431+ "polygon": {
432+ "paths": [
433+ [
434+ { "x": 1, "y": 1 },
435+ { "x": 2, "y": 2 },
436+ { "x": 1, "y": 3 }
437+ ]
438+ ]
439+ }
440+ }
441+ },
442+ "id": "f8f5f235-bd47-47be-b4fe-07d49e0177a7",
443+ "interpolate_algorithm": "linear-1.1",
444+ "interpolated": true,
445+ "name": "polygon",
446+ "ranges": [ [ 0, 1 ] ],
447+ "slot_names": [
448+ "1"
449+ ]
450+ }
451+ ]
452+ }
453+ """
454+
455+ directory = tmp_path / "imports"
456+ directory .mkdir ()
457+ import_file = directory / "darwin-file.json"
458+ import_file .write_text (content )
459+
460+ annotation_file : dt .AnnotationFile = parse_darwin_json (import_file , None )
461+
462+ assert annotation_file .path == import_file
463+ assert annotation_file .filename == "item-0.mp4"
464+ assert annotation_file .dataset_name == "Dataset 0"
465+ assert annotation_file .item_id == "0185c280-bbad-6117-71a7-a6853a6e3f2e"
466+ assert annotation_file .version == dt .AnnotationFileVersion (major = 2 , minor = 0 , suffix = "" )
467+
468+ assert len (annotation_file .annotations ) == 1
469+ assert len (annotation_file .annotation_classes ) == 1
470+ assert annotation_file .annotations [0 ].id == "f8f5f235-bd47-47be-b4fe-07d49e0177a7"
471+ assert list (annotation_file .annotations [0 ].frames .keys ()) == [3 ]
472+ assert annotation_file .annotations [0 ].frames [3 ].id == "f8f5f235-bd47-47be-b4fe-07d49e0177a7"
473+ assert annotation_file .is_video
474+ assert annotation_file .image_width == 123
475+ assert annotation_file .image_height == 456
476+ assert (
477+ annotation_file .image_url
478+ == "http://example.com/fake-api-url/v2/teams/v7/uploads/43a83276-1abf-483b-877e-6e61349f2d1f"
479+ )
480+ assert (
481+ annotation_file .workview_url
482+ == "http://example.com/workview?dataset=545&item=0185c280-bbad-6117-71a7-a6853a6e3f2e"
483+ )
484+ assert not annotation_file .seq
485+ assert len (annotation_file .frame_urls ) == 2
486+ assert annotation_file .remote_path == "/path-0/folder"
371487
372488 def it_returns_None_if_no_annotations_exist (tmp_path ):
373489 content = """
0 commit comments