drone-path 1.0.0-rc1 → 1.0.0
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.
- package/dist/archive-cli.d.ts +1 -0
- package/dist/archive-cli.js +50 -0
- package/dist/archive-query-cli.d.ts +3 -0
- package/dist/archive-query-cli.js +128 -0
- package/dist/cli.js +12 -5
- package/package.json +4 -3
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function runArchive(argv: string[]): Promise<void>;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import { Command } from 'commander';
|
|
3
|
+
import { scanArchive } from 'drone-path-archive/indexed-scan';
|
|
4
|
+
import { archiveDbPath } from 'drone-path-archive/paths';
|
|
5
|
+
import { requireFfmpegTools } from 'drone-path-core/ffmpeg';
|
|
6
|
+
import { resolveFfmpegTools } from 'drone-path-core/ffmpeg-tools';
|
|
7
|
+
import { addArchiveQueries, archiveCommand } from './archive-query-cli.js';
|
|
8
|
+
export async function runArchive(argv) {
|
|
9
|
+
const program = new Command('drone-path archive')
|
|
10
|
+
.description('Inspect a library of drone recordings.')
|
|
11
|
+
.exitOverride();
|
|
12
|
+
const scan = archiveCommand(program.command('scan'))
|
|
13
|
+
.description('Scan folders for drone recordings.')
|
|
14
|
+
.argument('<dirs...>', 'folders to scan for recordings')
|
|
15
|
+
.option('--recurse', 'include subfolders')
|
|
16
|
+
.option('--prune', 'remove missing recordings from the index')
|
|
17
|
+
.option('--json', 'write one JSON record per clip to stdout')
|
|
18
|
+
.action(async (dirs) => {
|
|
19
|
+
const { recurse, json, archiveDb, prune } = scan.opts();
|
|
20
|
+
const controller = new AbortController();
|
|
21
|
+
const interrupt = () => controller.abort(new Error('archive scan canceled'));
|
|
22
|
+
process.on('SIGINT', interrupt);
|
|
23
|
+
try {
|
|
24
|
+
const records = await scanArchive(dirs, {
|
|
25
|
+
db: archiveDbPath(archiveDb), recurse, prune, signal: controller.signal,
|
|
26
|
+
getTools: async () => {
|
|
27
|
+
const tools = resolveFfmpegTools({ ffmpeg: null, ffprobe: null });
|
|
28
|
+
await requireFfmpegTools(tools, controller.signal);
|
|
29
|
+
return tools;
|
|
30
|
+
},
|
|
31
|
+
onRecord: (record) => {
|
|
32
|
+
process.stderr.write(`[drone-path] ${record.status}: ${record.path}\n`);
|
|
33
|
+
},
|
|
34
|
+
});
|
|
35
|
+
if (json)
|
|
36
|
+
for (const record of records)
|
|
37
|
+
fs.writeSync(1, JSON.stringify(record) + '\n');
|
|
38
|
+
process.stderr.write(`[drone-path] scanned ${records.length} recording(s)\n`);
|
|
39
|
+
}
|
|
40
|
+
catch (error) {
|
|
41
|
+
controller.signal.throwIfAborted();
|
|
42
|
+
throw error;
|
|
43
|
+
}
|
|
44
|
+
finally {
|
|
45
|
+
process.off('SIGINT', interrupt);
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
addArchiveQueries(program);
|
|
49
|
+
await program.parseAsync(argv, { from: 'user' });
|
|
50
|
+
}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { Option } from 'commander';
|
|
2
|
+
import { exportArchiveMap, exportArchiveTracks } from 'drone-path-archive/export';
|
|
3
|
+
import { archiveDbPath } from 'drone-path-archive/paths';
|
|
4
|
+
import { DEFAULT_RADIUS_M, listArchive, listArchiveFlights, nearArchive, parseDateBound } from 'drone-path-archive/query';
|
|
5
|
+
function decimal(text) {
|
|
6
|
+
const value = text.trim();
|
|
7
|
+
return /^[+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?$/iu.test(value) ? Number(value) : NaN;
|
|
8
|
+
}
|
|
9
|
+
function meters(text) {
|
|
10
|
+
const value = decimal(text);
|
|
11
|
+
if (!Number.isFinite(value) || value < 0)
|
|
12
|
+
throw new Error('expected a nonnegative distance in meters');
|
|
13
|
+
return value;
|
|
14
|
+
}
|
|
15
|
+
function availability(text) {
|
|
16
|
+
if (text !== 'online' && text !== 'offline')
|
|
17
|
+
throw new Error('expected online or offline status');
|
|
18
|
+
return text;
|
|
19
|
+
}
|
|
20
|
+
function point(text) {
|
|
21
|
+
const [lat, lon, extra] = text.split(',').map(decimal);
|
|
22
|
+
if (!(Math.abs(lat) <= 90 && Math.abs(lon) <= 180) || extra !== undefined) {
|
|
23
|
+
throw new Error('expected a latitude,longitude pair within ±90 and ±180 degrees');
|
|
24
|
+
}
|
|
25
|
+
return { lat, lon };
|
|
26
|
+
}
|
|
27
|
+
function bbox(text) {
|
|
28
|
+
const parts = text.split(',');
|
|
29
|
+
if (parts.length !== 4)
|
|
30
|
+
throw new Error('expected a bounding box as south,west,north,east');
|
|
31
|
+
const southWest = point(parts.slice(0, 2).join(','));
|
|
32
|
+
const northEast = point(parts.slice(2).join(','));
|
|
33
|
+
if (southWest.lat > northEast.lat)
|
|
34
|
+
throw new Error('expected south latitude at or below north latitude');
|
|
35
|
+
return { minLat: southWest.lat, minLon: southWest.lon, maxLat: northEast.lat, maxLon: northEast.lon };
|
|
36
|
+
}
|
|
37
|
+
function writeJson(value) {
|
|
38
|
+
process.stdout.write(JSON.stringify(value) + '\n');
|
|
39
|
+
}
|
|
40
|
+
function listOptions(options) {
|
|
41
|
+
const { inBbox, after, before, minDist, status } = options;
|
|
42
|
+
if (after !== undefined && before !== undefined && after > before) {
|
|
43
|
+
throw new Error('expected --after at or before --before');
|
|
44
|
+
}
|
|
45
|
+
return { bbox: inBbox, afterMs: after, beforeMs: before, minDistanceM: minDist, availability: status };
|
|
46
|
+
}
|
|
47
|
+
export function archiveCommand(command) {
|
|
48
|
+
return command
|
|
49
|
+
.option('--archive-db <path>', 'override the per-user archive database path')
|
|
50
|
+
.exitOverride();
|
|
51
|
+
}
|
|
52
|
+
function queryOptions(command) {
|
|
53
|
+
return archiveCommand(command).option('--json', 'write a JSON array to stdout');
|
|
54
|
+
}
|
|
55
|
+
function listFilters(command) {
|
|
56
|
+
return command.option('--in-bbox <s,w,n,e>', 'filter clips by a viewport bounding box', bbox)
|
|
57
|
+
.option('--after <date>', 'earliest camera date or timestamp, inclusive', parseDateBound)
|
|
58
|
+
.option('--before <date>', 'latest camera date or timestamp, exclusive', parseDateBound)
|
|
59
|
+
.option('--min-dist <m>', 'minimum track distance in meters', meters)
|
|
60
|
+
.option('--status <state>', 'filter by online or offline availability', availability);
|
|
61
|
+
}
|
|
62
|
+
function exportOptions(command) {
|
|
63
|
+
return archiveCommand(listFilters(command))
|
|
64
|
+
.option('--redact-launch <m>', 'exclude geometry near the first and last indexed fix of each flight', meters);
|
|
65
|
+
}
|
|
66
|
+
export function addArchiveQueries(program) {
|
|
67
|
+
listFilters(queryOptions(program.command('list').description('List indexed recordings.')))
|
|
68
|
+
.addOption(new Option('--group-by <kind>', 'group matching clips into flights').choices(['flight']))
|
|
69
|
+
.action((options) => {
|
|
70
|
+
const db = archiveDbPath(options.archiveDb);
|
|
71
|
+
const filters = listOptions(options);
|
|
72
|
+
if (options.groupBy === 'flight') {
|
|
73
|
+
const flights = listArchiveFlights(db, filters);
|
|
74
|
+
if (options.json)
|
|
75
|
+
writeJson(flights);
|
|
76
|
+
else
|
|
77
|
+
for (const { flightId, clips } of flights) {
|
|
78
|
+
process.stdout.write(`Flight ${flightId}\n`);
|
|
79
|
+
for (const clip of clips) {
|
|
80
|
+
const continuation = clip.splitFromKey === null ? '' : ' (split continuation)';
|
|
81
|
+
process.stdout.write(` [${clip.availability}] ${clip.path}${continuation}\n`);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
const clips = listArchive(db, filters);
|
|
87
|
+
if (options.json)
|
|
88
|
+
writeJson(clips);
|
|
89
|
+
else
|
|
90
|
+
for (const clip of clips)
|
|
91
|
+
process.stdout.write(`[${clip.availability}] ${clip.path}\n`);
|
|
92
|
+
});
|
|
93
|
+
queryOptions(program.command('near'))
|
|
94
|
+
.description('Find where indexed recordings pass near a location.')
|
|
95
|
+
// Commander treats a negative coordinate pair as an option, but the
|
|
96
|
+
// required argument parser still rejects anything besides a coordinate.
|
|
97
|
+
.allowUnknownOption()
|
|
98
|
+
.argument('<lat,lon>', 'query latitude and longitude', point)
|
|
99
|
+
.option('--radius <m>', 'search radius in meters', meters, DEFAULT_RADIUS_M)
|
|
100
|
+
.option('--include-gaze', 'also match points inside estimated camera ground footprints')
|
|
101
|
+
.action((location, options) => {
|
|
102
|
+
const hits = nearArchive(archiveDbPath(options.archiveDb), location, options.radius, options.includeGaze);
|
|
103
|
+
if (options.json)
|
|
104
|
+
writeJson(hits);
|
|
105
|
+
else
|
|
106
|
+
for (const hit of hits) {
|
|
107
|
+
const label = hit.matchType === 'gaze' ? 'in camera view' : `${hit.distanceM.toFixed(1)} m`;
|
|
108
|
+
process.stdout.write(`${label} at ${hit.tSec.toFixed(2)} s [${hit.clip.availability}] ${hit.clip.path}\n`);
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
exportOptions(program.command('export-map'))
|
|
112
|
+
.description('Write a standalone HTML map of matching flights.')
|
|
113
|
+
.argument('<out.html>', 'output HTML file')
|
|
114
|
+
.option('--include-gaze', 'show estimated camera ground footprints')
|
|
115
|
+
.action((output, options) => {
|
|
116
|
+
exportArchiveMap(archiveDbPath(options.archiveDb), output, {
|
|
117
|
+
filters: listOptions(options), redactLaunchM: options.redactLaunch, includeGaze: options.includeGaze,
|
|
118
|
+
});
|
|
119
|
+
});
|
|
120
|
+
exportOptions(program.command('export-tracks'))
|
|
121
|
+
.description('Write matching flight tracks in GPX, GeoJSON, KML, or KMZ format.')
|
|
122
|
+
.argument('<out>', 'output .gpx, .geojson, .kml, or .kmz file')
|
|
123
|
+
.action((output, options) => {
|
|
124
|
+
exportArchiveTracks(archiveDbPath(options.archiveDb), output, {
|
|
125
|
+
filters: listOptions(options), redactLaunchM: options.redactLaunch,
|
|
126
|
+
});
|
|
127
|
+
});
|
|
128
|
+
}
|
package/dist/cli.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import fs from 'node:fs';
|
|
2
2
|
import { Command, Option } from 'commander';
|
|
3
3
|
import { ERROR_PREFIX, errorMessage } from 'drone-path-core/errors';
|
|
4
|
+
import { runArchive } from './archive-cli.js';
|
|
4
5
|
import { VERSION } from './version.js';
|
|
5
6
|
import { CONFIG_FILE_OPTION, CONFIG_OPTIONS, OVERRIDE_NORMALIZERS, TELEMETRY_JSON_ALIAS, cliDefaultOf, } from 'drone-path-engine/config';
|
|
6
7
|
import { resolveConfig } from 'drone-path-engine/configfile';
|
|
@@ -28,7 +29,7 @@ export function buildProgram() {
|
|
|
28
29
|
}
|
|
29
30
|
program.addOption(new Option(TELEMETRY_JSON_ALIAS.flags, TELEMETRY_JSON_ALIAS.help));
|
|
30
31
|
program.option(CONFIG_FILE_OPTION.flags, CONFIG_FILE_OPTION.help);
|
|
31
|
-
return program;
|
|
32
|
+
return program.addHelpText('after', '\nLibrary inventory: drone-path archive scan --help');
|
|
32
33
|
}
|
|
33
34
|
function givenOnCommandLine(program, name) {
|
|
34
35
|
return program.getOptionValueSource(name) === 'cli';
|
|
@@ -47,18 +48,20 @@ function collectOverrides(program, onDeprecated) {
|
|
|
47
48
|
const raw = row.cli.parse ? row.cli.parse(opts[row.key]) : opts[row.key];
|
|
48
49
|
Object.assign(cli, row.normalize(raw, flag));
|
|
49
50
|
}
|
|
51
|
+
const hasAlias = givenOnCommandLine(program, TELEMETRY_JSON_ALIAS.inputKey);
|
|
52
|
+
const hasCanonical = givenOnCommandLine(program, TELEMETRY_JSON_ALIAS.key);
|
|
50
53
|
// The deprecated alias lands on the same trackOut override key; both
|
|
51
54
|
// spellings at once is ambiguous and rejected.
|
|
52
|
-
if (
|
|
53
|
-
if (
|
|
55
|
+
if (hasAlias) {
|
|
56
|
+
if (hasCanonical) {
|
|
54
57
|
throw new Error(`${longFlagOf(TELEMETRY_JSON_ALIAS.flags)} and --track-out cannot be combined (use --track-out)`);
|
|
55
58
|
}
|
|
56
59
|
onDeprecated(TELEMETRY_JSON_ALIAS.cliWarning);
|
|
57
60
|
Object.assign(cli, OVERRIDE_NORMALIZERS.trackOut(opts[TELEMETRY_JSON_ALIAS.inputKey], longFlagOf(TELEMETRY_JSON_ALIAS.flags)));
|
|
58
61
|
}
|
|
59
|
-
const trackOutSpelling =
|
|
62
|
+
const trackOutSpelling = hasAlias
|
|
60
63
|
? 'telemetry-json'
|
|
61
|
-
:
|
|
64
|
+
: hasCanonical
|
|
62
65
|
? 'track-out'
|
|
63
66
|
: null;
|
|
64
67
|
return { cli, trackOutSpelling };
|
|
@@ -130,6 +133,10 @@ async function runPipeline(invocation, log) {
|
|
|
130
133
|
}
|
|
131
134
|
export async function main(argv = process.argv) {
|
|
132
135
|
try {
|
|
136
|
+
if (argv[2] === 'archive') {
|
|
137
|
+
await runArchive(argv.slice(3));
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
133
140
|
const invocation = resolveInvocation(argv);
|
|
134
141
|
// Deprecation warnings are not progress output: they print even with --quiet.
|
|
135
142
|
for (const warning of invocation.deprecationWarnings) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "drone-path",
|
|
3
|
-
"version": "1.0.0
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"description": "Render flight-path map overlay videos (exactly the source frame rate and frame count) from DJI drone recordings - telemetry from the embedded CAM-meta (DVTM) stream or the .SRT sidecar.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -51,7 +51,8 @@
|
|
|
51
51
|
},
|
|
52
52
|
"dependencies": {
|
|
53
53
|
"commander": "~15.1.0",
|
|
54
|
-
"drone-path-
|
|
55
|
-
"drone-path-
|
|
54
|
+
"drone-path-archive": "~1.0.0",
|
|
55
|
+
"drone-path-core": "~1.0.0",
|
|
56
|
+
"drone-path-engine": "~1.0.0"
|
|
56
57
|
}
|
|
57
58
|
}
|