Skip to content

Commit 27ebd36

Browse files
fix: allow deep scanning of audio-only files
At this time, deep scanning audio-only files is effectively a no-op, but in the future there may be information we want to extract from audio files during this step.
1 parent 3b14371 commit 27ebd36

2 files changed

Lines changed: 31 additions & 12 deletions

File tree

shared/packages/worker/src/worker/workers/windowsWorker/expectationHandlers/lib/scan.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,14 @@ import { FileShareAccessorHandle } from '../../../../accessorHandlers/fileShare'
1616
import { HTTPProxyAccessorHandle } from '../../../../accessorHandlers/httpProxy'
1717
import { HTTPAccessorHandle } from '../../../../accessorHandlers/http'
1818

19-
interface FFProbeScanResult {
19+
export interface FFProbeScanResultStream {
20+
index: number
21+
codec_type: string
22+
}
23+
24+
export interface FFProbeScanResult {
2025
// to be defined...
26+
streams?: FFProbeScanResultStream[]
2127
format?: {
2228
duration: number
2329
}

shared/packages/worker/src/worker/workers/windowsWorker/expectationHandlers/packageDeepScan.ts

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ import {
2222
} from '../../../accessorHandlers/accessor'
2323
import { IWorkInProgress, WorkInProgress } from '../../../lib/workInProgress'
2424
import { checkWorkerHasAccessToPackageContainersOnPackage, lookupAccessorHandles, LookupPackageContainer } from './lib'
25-
import { DeepScanResult } from './lib/coreApi'
25+
import { DeepScanResult, FieldOrder, ScanAnomaly } from './lib/coreApi'
2626
import { CancelablePromise } from '../../../lib/cancelablePromise'
27-
import { scanFieldOrder, scanMoreInfo, scanWithFFProbe } from './lib/scan'
27+
import { FFProbeScanResult, scanFieldOrder, scanMoreInfo, scanWithFFProbe } from './lib/scan'
2828
import { WindowsWorker } from '../windowsWorker'
2929

3030
/**
@@ -172,23 +172,36 @@ export const PackageDeepScan: ExpectationWindowsHandler = {
172172

173173
// Scan with FFProbe:
174174
currentProcess = scanWithFFProbe(sourceHandle)
175-
const ffProbeScan = await currentProcess
175+
const ffProbeScan: FFProbeScanResult = await currentProcess
176+
const hasVideoStream =
177+
ffProbeScan.streams && ffProbeScan.streams.some((stream) => stream.codec_type === 'video')
176178
workInProgress._reportProgress(sourceVersionHash, 0.1)
177179
currentProcess = undefined
178180

179181
// Scan field order:
180-
currentProcess = scanFieldOrder(sourceHandle, exp.endRequirement.version)
181-
const resultFieldOrder = await currentProcess
182+
let resultFieldOrder = FieldOrder.Unknown
183+
if (hasVideoStream) {
184+
currentProcess = scanFieldOrder(sourceHandle, exp.endRequirement.version)
185+
resultFieldOrder = await currentProcess
186+
currentProcess = undefined
187+
}
182188
workInProgress._reportProgress(sourceVersionHash, 0.2)
183-
currentProcess = undefined
184189

185190
// Scan more info:
186-
currentProcess = scanMoreInfo(sourceHandle, ffProbeScan, exp.endRequirement.version, (progress) => {
187-
workInProgress._reportProgress(sourceVersionHash, 0.21 + 0.77 * progress)
188-
})
189-
const { blacks: resultBlacks, freezes: resultFreezes, scenes: resultScenes } = await currentProcess
191+
let resultBlacks: ScanAnomaly[] = []
192+
let resultFreezes: ScanAnomaly[] = []
193+
let resultScenes: number[] = []
194+
if (hasVideoStream) {
195+
currentProcess = scanMoreInfo(sourceHandle, ffProbeScan, exp.endRequirement.version, (progress) => {
196+
workInProgress._reportProgress(sourceVersionHash, 0.21 + 0.77 * progress)
197+
})
198+
const result = await currentProcess
199+
resultBlacks = result.blacks
200+
resultFreezes = result.freezes
201+
resultScenes = result.scenes
202+
currentProcess = undefined
203+
}
190204
workInProgress._reportProgress(sourceVersionHash, 0.99)
191-
currentProcess = undefined
192205

193206
const deepScan: DeepScanResult = {
194207
field_order: resultFieldOrder,

0 commit comments

Comments
 (0)