@@ -208,29 +208,56 @@ const timestampsArrayValidator = array(
208
208
) . test ( ( values , context ) => {
209
209
if ( ! values ) return true ;
210
210
211
- // first timestamp validation
211
+ // Per https://support.google.com/youtube/answer/9884579?hl=en
212
+
213
+ // At least 3 timestamps are required
214
+ if ( values . length > 0 && values . length < 3 ) {
215
+ return context . createError ( {
216
+ message : 'At least 3 timestamps are required'
217
+ } ) ;
218
+ }
219
+
220
+ // first timestamp should be `0:00`
212
221
if ( values . length > 0 && timestampToSeconds ( values [ 0 ] . time ) !== 0 ) {
213
222
return context . createError ( {
214
223
message : 'The first timestamp should be `0:00`'
215
224
} ) ;
216
225
}
217
226
218
- // sequential timestamps
219
- let errors = [ ] ;
227
+ // Timestamps should be sequential and at least 10 seconds apart from each other
228
+ const sequenceErrors = [ ] ;
229
+ const lengthErrors = [ ] ;
220
230
let previousTime = - 1 ;
221
231
222
232
for ( const value of values ) {
223
233
const currentTime = timestampToSeconds ( value . time ) ;
224
- if ( currentTime <= previousTime ) errors . push ( value ) ;
234
+
235
+ if ( currentTime <= previousTime ) sequenceErrors . push ( value ) ;
236
+ if ( currentTime > 0 && currentTime - previousTime < 10 )
237
+ lengthErrors . push ( value ) ;
238
+
225
239
previousTime = currentTime ;
226
240
}
227
241
228
- if ( errors . length > 0 ) {
229
- const details = errors . map ( ( v ) => `${ v . time } - ${ v . title } ` ) . join ( ' | ' ) ;
230
- const plural = errors . length > 1 ? 's are' : ' is' ;
242
+ if ( sequenceErrors . length > 0 ) {
243
+ const details = sequenceErrors
244
+ . map ( ( v ) => `${ v . time } - ${ v . title } ` )
245
+ . join ( ' | ' ) ;
246
+ const plural = sequenceErrors . length > 1 ? 's are' : ' is' ;
247
+
248
+ return context . createError ( {
249
+ message : `${ sequenceErrors . length } timestamp${ plural } not in sequential order | ${ details } `
250
+ } ) ;
251
+ }
252
+
253
+ if ( lengthErrors . length > 0 ) {
254
+ const details = lengthErrors
255
+ . map ( ( v ) => `${ v . time } - ${ v . title } ` )
256
+ . join ( ' | ' ) ;
257
+ const plural = lengthErrors . length > 1 ? 's are' : ' is' ;
231
258
232
259
return context . createError ( {
233
- message : `${ errors . length } timestamp${ plural } not in sequential order | ${ details } `
260
+ message : `${ lengthErrors . length } timestamp${ plural } are less than 10 seconds after the previous one | ${ details } `
234
261
} ) ;
235
262
}
236
263
0 commit comments