-
Notifications
You must be signed in to change notification settings - Fork 0
/
AutoQC_With_AutoFix.js.txt
932 lines (799 loc) · 36.5 KB
/
AutoQC_With_AutoFix.js.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
try {our_clq = document.location.href
.split("=")[1].split(":")[2]
}
catch (e) {
alert(
"You must be in a started, saved Originator task!");
throw new Error
}
LANG = "EN"
document.addEventListener("keypress", promptSettings, {once:true})
function promptSettings (){
LANG = prompt("Enter language code")
console.log("Custom user-defined LANG is "+LANG)
}
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ?
module.exports = factory() :
typeof define === 'function' && define.amd ? define(
factory) :
(global.runAutoQC = factory());
}(this, (function () {
'use strict';
function runAutoQC() {
var our_clq = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
document.removeEventListener("keypress",promptSettings)
LANG = LANG.toUpperCase()
console.log("Running with LANG: "+LANG)
var line_limit = 0
var max_cps = 0
var normal_cps = 0
switch (LANG) {
case "RU":
line_limit = 39
normal_cps = 17
max_cps = 22.1
break;
case "GR":
case "FR":
case "PT-BR":
case "EN":
default:
line_limit = 42
normal_cps = 20
max_cps = 26
}
// try {our_clq = document.location.href
// .toString()
// .split("=")[1].split(":")[2]
// }
// catch (e) {
// alert(
// "You must be in a started, saved Originator task!");
// return null
// }
var clq_pattern = new RegExp(
'^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$'
, 'i');
if (!our_clq || !clq_pattern.test(our_clq)) {
alert(
"You must be in a started, saved Originator task!");
return null
}
if (!clq_pattern.test(our_clq)) {
alert("The CLQ is invalid: " + our_clq +
"\n" +
"Please report me to the developer.");
return null
}
var shotChanges = localStorage.getItem("shotChanges:"+our_clq)
try { shotChanges = shotChanges.split(",");console.log("Shot change info found!") } catch(e) {var shotChanges = undefined; console.log("Proceeding without shot change info")}
var reportHtml =
'<head><meta charset="utf-8"><script>var z=function(q){var s=document.getElementsByClassName(q);for(x of s){x.className === q ? (x.className=q+" of0"):(x.setAttribute("class",q))}};</script><style>body{background-color:#212121}.of0{visibility:hidden;color:#000!important;}.cSpace{color:#00fa00;visibility:visible;}.StyledTextEditor{font-family:Netflix-Sans;line-height:1.3;margin:2px;white-space:nowrap;overflow:hidden;font-variant-ligatures:none;position:relative;pointer-events:none}.StyledTextEditor .ltr{unicode-bidi:embed;direction:ltr}.TimedTextEvent{font-family:Netflix-Sans;font-size:1.3rem;font-weight:400;line-height:2rem;margin-top:.5rem;display:-webkit-box;display:-moz-box;display:-webkit-flex;display:-ms-flexbox;display:box;display:flex;-webkit-box-orient:vertical;-moz-box-orient:vertical;-o-box-orient:vertical;-webkit-flex-direction:column;-ms-flex-direction:column;flex-direction:column;border:1px solid transparent;-webkit-transition:height 250ms ease,border 150ms ease;-moz-transition:height 250ms ease,border 150ms ease;-o-transition:height 250ms ease,border 150ms ease;-ms-transition:height 250ms ease,border 150ms ease;transition:height 250ms ease,border 150ms ease}.TimedTextEvent .details{padding-top:.5rem;padding-left:1rem;padding-right:1rem;display:-webkit-box;display:-moz-box;display:-webkit-flex;display:-ms-flexbox;display:box;display:flex;-webkit-box-orient:horizontal;-moz-box-orient:horizontal;-o-box-orient:horizontal;-webkit-flex-direction:row;-ms-flex-direction:row;flex-direction:row}.TimedTextEvent .details .timing{-webkit-flex-shrink:0;flex-shrink:0;display:-webkit-box;display:-moz-box;display:-webkit-flex;display:-ms-flexbox;display:box;display:flex;-webkit-box-orient:vertical;-moz-box-orient:vertical;-o-box-orient:vertical;-webkit-flex-direction:column;-ms-flex-direction:column;flex-direction:column;width:8rem}.issue{font-size:16;vertical-align:middle;font-family:Netflix-Sans;position:relative;top:-1px}.TimedTextEvent .details .timing .TimeCode{color:rgba(255,255,255,.54);padding:0 .5rem;border-radius:1rem;white-space:nowrap}.TimedTextEvent .details .content{-webkit-box-flex:1;-moz-box-flex:1;-o-box-flex:1;-ms-box-flex:1;box-flex:1;-webkit-flex-grow:1;flex-grow:1;display:-webkit-box;display:-moz-box;display:-webkit-flex;display:-ms-flexbox;display:box;display:flex;-webkit-box-orient:vertical;-moz-box-orient:vertical;-o-box-orient:vertical;-webkit-flex-direction:column;-ms-flex-direction:column;flex-direction:column;padding-left:2rem;padding-bottom:.5rem;width:24rem}.TimedTextEvent .details .content .header{display:-webkit-box;display:-moz-box;display:-webkit-flex;display:-ms-flexbox;display:box;display:flex;-webkit-box-orient:horizontal;-moz-box-orient:horizontal;-o-box-orient:horizontal;-webkit-flex-direction:row;-ms-flex-direction:row;flex-direction:row}.TimedTextEvent .details .content .header .index{color:rgba(255,255,255,.66)}.TimedTextEvent .details .content .header .duration{color:rgba(255,255,255,.54);margin-left:auto;border-radius:1rem}.TimedTextEvent .details .content .StyledTextEditor{color:rgba(255,255,255,.87);min-height:3.2rem;margin-top:.3rem}img{display:table-cell;vertical-align:middle}.TimedTextEvent .footer{height:.5rem;border-bottom:2px solid rgba(0,0,0,.77);margin-left:1rem;margin-right:1rem}.outline{color:#000;position:relative;left:350%;} button{background-color:black;color:#39ff1a;opacity:0.5;} i{ font-style: italic!important; font-family: serif!important}#feedback{height:0;width:65px;position:fixed;right:0;top:50%;z-index:1000;transform:rotate(-90deg);-webkit-transform:rotate(-90deg);-moz-transform:rotate(-90deg);-o-transform:rotate(-90deg)}#feedback a{display:block;background:#06c;height:15px;width:165px;padding:8px 16px;color:#fff;font-family:Arial,sans-serif;font-size:17px;font-weight:700;text-decoration:none;border-bottom:solid 1px #333;border-left:solid 1px #333;border-right:solid 1px #fff}#feedback a:hover{background:#ccc}</style><body><div id="stick" style="position:relative;left:300px;"><button type="button" class="f" onclick="z(\'cSpace\')" alt="Toggle layout">🟩</button><button type="button" class="f" onclick="z(\'minor_issue\') ">⚠️</button><button type="button" class="f" onclick="z(\'major_issue\')">🚫</button><button type="button" onclick="z(\'shot_change_issue\') ">🎞</button>DLFIXSRTTOKEN</div>';
var lsJson = localStorage["clq:origination:" +
our_clq]
if (!lsJson) {
alert("Timed text events not found in localStorage\nfor CLQ: " +
our_clq + "\n" +
"If the CLQ is correct and" + "\n" +
"\"Save to local storage\" is enabled in Settings," +
"\n" + "save the task and try again.");
return null
}
var json_obj = JSON.parse(lsJson)
var src = json_obj["events"]
var fps_ = json_obj["meta"]["fps"];
var fps = fps_.split("_")[1] / 100
//From {"fps":"FPS_2500"}
//var proposed_fps = prompt("Framerate set to: " + fps + " fps.\n\nEnter new value like 2997, 2500 or 23976023976023978:");
try {
if (proposed_fps) {
var int_fps = proposed_fps.substring(0,
2);
var decimal_fps = proposed_fps.substring(
2, proposed_fps
.length);
fps_ = "FPS" + "_" + int_fps + decimal_fps
fps = (int_fps + "." + decimal_fps) * 1;
}
}
catch (e) {}
var frms = 1000 / fps
function srtName(suffix = "", extension =
".srt") {
var s = document
.getElementsByClassName(
"cpe-page-menu-label")[0]
.innerText
var srtName = (s.replace(/[ ]/g
, '_')
.replace(/[^a-z0-9_]/gi
, '') + "_" + suffix + extension
) //This gets rid of all punctuation, spaces and non-English letters
.trim() //resulting in a name like 14545_El_Burrito_A_Breaking_Fat_Movie_FPS_2500.srt
if (!srtName) srtName = our_clq +
"_" + suffix +
extension //Fallback measure. Useful for debugging later
return srtName
}
function frames2tcf(framenumber, framerate =
fps) { //frames to 00:01:02:24 format
var seconds_float = framenumber / framerate
var seconds_int = Math.floor(seconds_float)
var seconds_frac = seconds_float - seconds_int
var frames = Math.round(seconds_frac *
framerate) + ''
var date = new Date(0);
date.setSeconds(seconds_int);
try {var timeString = date.toISOString()
.substr(11, 8)
if (frames.length == 1) frames = "0" + frames
var timecodef = timeString + ":" + frames
} catch(e) {var timecodef = 'ERROR'}
return timecodef
}
function frames2timecode(
frames) { //frames to 00:01:02,000 format
var milliseconds = Math.round(
frames * frms)
var srt_timecode = TimeConversion(
milliseconds)
return srt_timecode
}
function array2srt(events_object) {
var ordered_events = []
for (var id in events_object) {
try {
var type_fn = events_object[id][
"type"]
if (type_fn === "fn") {
events_object[id]["txt"] +=
"<b></b>";
}
}
catch (e) {}
ordered_events.push([
events_object[id]
["start"]
, events_object[id]
["end"], events_object[id]
["txt"]
, events_object[id]
["styles"]
, events_object[id]
["rgn"]
])
}
ordered_events.sort(function (a
, b) {
return a[0] - b[0];
}); //Array sorted by in_cues, sequentially
var index = 0
var srt_txt = ''
for (event of ordered_events) {
index++
var start = frames2timecode(
event[0])
var end = frames2timecode(event[
1])
var content = event[2]
try {
if (typeof event[3][0]["type"] !==
"undefined") {
if (event[3][0]["type"] ==
"italic") {
content = italicize(content,
event[3])
}
}
}
catch (e) {}
try {
if (typeof event[4] !== "undefined") {
if (event[4] == "top") {
content = "{\\an8}" + content
}
}
}
catch (e) {}
try {
if (event["type"] == "fn") {
content += '<b></b>'
}
}
catch (e) {}
console.log(content)
var current_event = index +
"\n" + start + " --> " +
end +
"\n" + content + "\n"
srt_txt += current_event + "\n"
}
return srt_txt
}
function parsed2srt(parsedSRT) {
var srt_txt = ''
for(let event of parsedSRT){
let text_event = event["id"] + "\n" + event["start"] + " --> " + event["end"] + "\n" + event["text"] + "\n\n"
srt_txt += text_event
}
return srt_txt.trim()
}
function italicize(content, italics_array) {
position_offset = 0
for (var italic of italics_array) {
var position_from = italic["from"] +
position_offset;
position_offset += 3
content = [content.slice(0,
position_from), "<i>", content
.slice(position_from)
].join('')
var position_to = italic["to"] +
position_offset;
position_offset += 4
content = [content.slice(0, position_to),
"</i>", content
.slice(position_to)
].join('')
}
return content
}
function download(filename, text) {
var element = document
.createElement('a');
element.setAttribute('href'
, 'data:text/plain;charset=utf-8,' +
encodeURIComponent(text));
element.setAttribute('download'
, filename);
element.style.display = 'none';
document.body.appendChild(element);
element.click();
document.body.removeChild(element);
}
function TimeConversion(duration) {
let time = parseDuration(duration)
return formatTimeHMSS(time)
}
function parseDuration(duration) {
let remain = duration
let hours = Math.floor(remain / (
1000 * 60 * 60))
remain = remain % (1000 * 60 * 60)
let minutes = Math.floor(remain / (
1000 * 60))
remain = remain % (1000 * 60)
let seconds = Math.floor(remain / (
1000))
remain = remain % (1000)
let milliseconds = remain
return {
hours
, minutes
, seconds
, milliseconds
}
}
function formatTimeHMSS(o) {
let hours = o.hours.toString()
if (hours.length === 1) hours =
'0' + hours
let minutes = o.minutes.toString()
if (minutes.length === 1) minutes =
'0' + minutes
let seconds = o.seconds.toString()
if (seconds.length === 1) seconds =
'0' + seconds
let milliseconds = o.milliseconds
.toString()
if (milliseconds.length === 1)
milliseconds = '00' +
milliseconds
if (milliseconds.length === 2)
milliseconds = '0' +
milliseconds
return hours + ":" + minutes + ":" +
//Example: 00:01:02,999 -- note that the SRT spec calls for a comma, not a period!
seconds + "," +
milliseconds
}
function isBetween(distance,a,b){
var left_lim = a; var right_lim = b;
if(a>b) {left_lim = b; right_lim = a}
if(distance >= left_lim && distance <= right_lim) {return true}
return false
}
function validateScE(distance, framesE, sc) {
var violation = false
var V = {}
var css_cs1='<span class="shot_change_issue">';
var css_cs2='</span>';
var oldTcf = frames2tcf(framesE)
var scTcf = frames2tcf(sc)
if (isBetween(distance,5,11))
{
var moveTo = 12 - distance
var newFramesE = framesE+moveTo
var newTcf = frames2tcf(newFramesE)
moveTo=moveToSigned(moveTo)
violation = '🎞 Move out-cue right to +12 frames after shot change<br><font style="color: #7DFDFE; font-family: monospace">[OUT ' + oldTcf + ' ' + moveTo + ' | SC at '+scTcf+']</font>'
}
if ( isBetween(distance,-1,4) ) {
var moveTo = -2 - distance
var newFramesE = framesE+moveTo
var newTcf = frames2tcf(newFramesE)
moveTo=moveToSigned(moveTo)
violation = '🎞 Move out-cue left to -2 before shot change<br><font style="color: #7DFDFE; font-family: monospace">[OUT ' + oldTcf + ' ' + moveTo + ' | SC at '+scTcf+']</font>'
}
if ( isBetween(distance,-3,-7)) {
var moveTo = -2 - distance
var newFramesE = framesE+moveTo
var newTcf = frames2tcf(newFramesE)
moveTo=moveToSigned(moveTo)
violation = '🎞 Move out-cue right to -2 before shot change<br><font style="color: #7DFDFE; font-family: monospace">[OUT ' + oldTcf + ' ' + moveTo + ' | SC at '+scTcf+']</font>'
}
if(violation) { V = {violation:css_cs1+violation+css_cs2,
start: undefined,
end: frames2timecode(newFramesE)
}
return V;
}
return false
}
function moveToSigned(moveTo){
var frames = " frames"
if(Math.abs(moveTo) == 1) {var frames = " frame"}
if(moveTo <= 0) { return moveTo+frames } else {return '+'+moveTo+frames}
}
function validateScS(distance,framesE,sc) {
var violation = false
var V = {}
var css_cs1='<span class="shot_change_issue">';
var css_cs2='</span>';
var oldTcf = frames2tcf(framesE)
var scTcf = frames2tcf(sc)
if (isBetween(distance,1,4) ) {
var moveTo = 0 - distance
var newFramesE = framesE+moveTo
var newTcf = frames2tcf(newFramesE)
moveTo=moveToSigned(moveTo)
violation = '🎞 Move in-cue left to snap it to shot change<br><font style="color: #7FFFD4; font-family: monospace">[IN ' + oldTcf + ' ' + moveTo + ' | SC at '+scTcf+']</font>'
}
if (isBetween(distance,5,7) ) {
var moveTo = 8 - distance
var newFramesE = framesE+moveTo
var newTcf = frames2tcf(newFramesE)
moveTo=moveToSigned(moveTo)
violation = '🎞 Move in-cue right to 8 frames after shot change<br><font style="color: #7FFFD4; font-family: monospace">[IN ' + oldTcf + ' ' + moveTo + ' | SC at '+scTcf+']</font>'
}
if ( isBetween(distance,-11,-7) )
{
var moveTo = -12 - distance
var newFramesE = framesE+moveTo
var newTcf = frames2tcf(newFramesE)
moveTo=moveToSigned(moveTo)
violation = '🎞 Move in-cue left to -12 frames before shot change<br><font style="color: #7FFFD4; font-family: monospace">[IN ' + oldTcf + ' ' + moveTo + ' | SC at '+scTcf+']</font>'
}
if ( isBetween(distance,-6,-1))
{
var moveTo = 0 - distance
var newFramesE = framesE+moveTo
var newTcf = frames2tcf(newFramesE)
moveTo=moveToSigned(moveTo)
violation = '🎞 Move in-cue right to snap it to shot change<br><font style="color: #7FFFD4; font-family: monospace">[IN ' + oldTcf + ' ' + moveTo + ' | SC at '+scTcf+']</font>'
}
if(violation) { V = {
violation:css_cs1+violation+css_cs2,
start: frames2timecode(newFramesE),
end: undefined
}
return V;
debugger;
}
return false
}
//returns distance in frames from a given frame to the nearest shot change
function getNearestShotchange(frame) {
if(!shotChanges) { return false } else {
var smallestDist = Number.POSITIVE_INFINITY
var bestCandidate = 0
for (let shotChange of shotChanges) {
var distance = Math.abs(frame -
shotChange)
if (distance < smallestDist) {
smallestDist = distance
bestCandidate = shotChange
}
}
return bestCandidate
}
}
function leftFillNum(num, targetLength) {
return num.toString()
.padStart(targetLength, 0);
}
var SRT = parseSRT(array2srt(json_obj["events"]));
var fSRT = SRT
var issues = []
var events_detected = 0
for (event of SRT) {
var start_time = event["start"]
var end_time = event["end"]
var delta = end_time - start_time
var start_frames = Math.round(start_time *
fps)
var end_frames = Math.round(end_time * fps)
var start_tcf = frames2tcf(start_frames)
var end_tcf = frames2tcf(end_frames)
var id = event["id"]
var srtId = id-1;
var _id = leftFillNum(id, 4)
var eventIssue = []
var eventTxt = event["text"]
var eventOriginalTxt = event["text"]
var eventFixedTxt = event["text"]
var eventIsFn = false
var scS = getNearestShotchange(start_frames)
var scE = getNearestShotchange(end_frames)
var scSD = start_frames - scS
var scED = end_frames - scE
var scStcf = frames2tcf(scS)
var scEtcf = frames2tcf(scE)
var violS = validateScS(scSD, start_frames, scS)
var violE = validateScE(scED, end_frames, scE)
if (violS) {
eventIssue.push(violS["violation"])
fSRT[srtId]["start"] = violS["start"];
} else {fSRT[srtId]["start"] = frames2timecode(Math.round( fSRT[srtId]["start"] * fps )) }
if (violE) {
eventIssue.push(violE["violation"])
fSRT[srtId]["end"] = violE["end"];
} else {fSRT[srtId]["end"] = frames2timecode(Math.round( fSRT[srtId]["end"] * fps )) }
if (eventTxt.indexOf("<b></b>") !== -1) {
eventIsFn = true;
_id +=
'<span class="outline" style="color: purple; position: relative; top: 0px; left: 137px;">🅵🅽</span>'
}
eventTxt = eventTxt.replace(/(<([^>]+)>)/ig,
"");
eventTxt = eventTxt.replace(/{.an.}/ig, "");
if (eventTxt.indexOf("\n") !== -1 &&
eventTxt.indexOf("\n-") == -1 &&
eventTxt.replace("\n", " ")
.length <= line_limit && !eventIsFn) {
eventIssue.push("<span class=\"major_issue\">🚫 Can fit on one line");
eventFixedTxt = eventFixedTxt.replace("\n"," ").replace(" "," ");
}
if (eventTxt.indexOf("...") !== -1) {
eventIssue.push(
"<span class=\"minor_issue\">⚠️ Legacy ellipsis not required. Consider using U+2026: …"
);
eventFixedTxt = eventFixedTxt.replace(/\.\.\./g,"…")
}
if (eventTxt.indexOf("!?") !== -1) {
eventIssue.push(
"<span class=\"minor_issue\">⚠️ Unconventional punctuation detected. Did you mean to use '?!'"
)
}
if (eventTxt.indexOf(" - ") !== -1) {
eventIssue.push(
"<span class=\"minor_issue\">⚠️ Instead of hyphen, consider en or em dash: – or —"
)
}
var eventSpecial = false
var hasSpace = /\s$|^\s/;
var eventTxt_lines = eventTxt.split("\n");
var nPos = eventTxt.lastIndexOf("\n");
var hasSpaceIssue = nPos && (typeof eventTxt[
nPos + 1] ==
"undefined")
var overLineLimit = false
var hasDoubleSpace = eventTxt.replace("\n",
"")
.split(/\s\s/)
.length - 1
var hasThreeLines = typeof eventTxt_lines[
2] !== "undefined"
for (var line of eventTxt_lines) {
hasSpaceIssue = (hasSpace.test(line) ||
hasSpaceIssue)
if (line.length > line_limit) {
eventSpecial = line
overLineLimit = true
}
}
if (hasDoubleSpace) {
eventIssue.push(
"<span class=\"minor_issue>\"<span class=\"minor_issue\">⚠️ Double spaces detected, replace with single space</span>"
);
}
if (hasThreeLines) {
eventIssue.push(
"<span class=\"major_issue\">🚫 Three lines detected in this event"
);
}
if (hasSpaceIssue) {
if (eventTxt.length > 1) {
eventIssue.push(
"<span class=\"minor_issue\">⚠️ One of the lines begins or ends with whitespace"
);
try {
eventFixedTxt = (eventFixedTxt.split("\n")[0].trim() + "\n" + eventFixedTxt.split("\n")[1].trim()).trim()
} catch(e){ eventFixedTxt = eventFixedTxt.trim() }
}
else {
eventIssue.push(
"<span class=\"major_issue\">🚫 Empty event detected!");
eventSpecial =
"<span style='color:red;'><text cannot be empty></span>"
}
}
if (overLineLimit) {
eventIssue.push(
"<span class=\"major_issue\">🚫 Line over max limit of " +
line_limit)
eventSpecial = [eventSpecial.slice(0,
line_limit)
, "<span style='color: red; text-overflow: fade;'>"
, eventSpecial.slice(
line_limit)
].join('')
}
var totalLength = eventTxt.length
if (delta * delta > 49) {
eventIssue.push(
"<span class=\"major_issue\">🚫 Maximum duration exceeded for current FPS!"
);
}
// var halfLength = totalLength - Contrary to official statement,
// ( eventTxt.replace(/[ ]/g, '') Originator does not count
// .replace(/[^a-z0-9]/gi Western punctuation and spaces
// , '').length); as 0.5 characters for CPS.*/
//
// totalLength += (halfLength/(-2))
var cps = (Math.round((totalLength / delta) *
100)) / 100
var round_int_cps = Math.round(cps + 0.005);
var html_cps = ''
if (cps > (normal_cps + 0.5) && cps < (
max_cps + 0.5)) {
eventIssue.push(
"<span class=\"minor_issue\">⚠️ Reading speed slightly over norm; consider adjusting timings?"
)
html_cps =
'<div><span style="color: gold;">  ' +
round_int_cps + ' c/s</span></div>'
}
else if (cps > (max_cps + 0.5)) {
eventIssue.push(
"<span class=\"major_issue\">🚫 Reading speed above maximum! Either truncate text or extend timings!"
)
html_cps =
'<div><span style="color:red;">  ' +
round_int_cps + ' c/s</span></div>'
}
else {
html_cps =
'<div><span style="color:silver;">  ' +
round_int_cps + ' c/s</span></div>'
}
var dur_tcf = frames2tcf(delta * fps)
.substr(6)
var eventLines = eventTxt.split("\n")
if (typeof eventIssue !== "undefined" &&
eventIssue.length > 0) {
events_detected++;
var log_event = (start_tcf + " " +
eventTxt_lines[0].slice(0
, line_limit)
.padEnd(line_limit + 4, " ") + _id
)
.padEnd(line_limit + 10, " ")
if (typeof eventTxt_lines[1] !==
"undefined") {
log_event += "\n" + end_tcf + " " +
eventTxt_lines[1]
.padEnd(line_limit + 8, " ")
}
else {
log_event += "\n" + end_tcf +
" " + " ".padEnd(
line_limit + 6
, " ")
}
// console.log('%c' + log_event
// , 'background: #12343b; color: #66ff00')
//console.log((+_id+"\n"+start_tcf+"\n"+end_tcf+"\n"+eventTxt).padEnd(50), 'background: #222; color: #bada55');
// console.log(('%c' + eventIssue.join("\n"))
// .padEnd(50)
// , 'background: #FFF; color: #FF0000; font-style: italic; border:solid 1px #000;'
//)
//console.log("┉".repeat(63))
var issue = {
id: _id
, issues: eventIssue
, content: eventTxt
, contentO: eventOriginalTxt
, start_tcf: start_tcf
, end_tcf: end_tcf
, start_frames: start_frames
, end_frames: end_frames
, start_time: start_time
, end_time: end_time
, duration: delta
, cps: cps
, html_cps: html_cps
, dur_tcf: dur_tcf
, special: eventSpecial
}
htmlize(issue)
if(eventFixedTxt !== eventOriginalTxt){ fSRT[srtId]["text"] = eventFixedTxt }
}
}
if (!events_detected) {
console.log('%c' + "No issues detected"
, 'background: #12343b; color: #66ff00'
)
}
function htmlize(issue) {
try {
var original = issue.contentO.replace(
'<b></b>', '')
.replace(/{.an.}/g, '')
var lines = original
}
catch (e) {
var lines = issue.content;
}
lines = lines.replace(/\n/g, '⏎');
lines = lines.replace(/\s/g,
"<span class='cSpace'>⎵</span>");
lines = lines.replace(/⏎/g
, "<span class='cSpace' style=\"color: #00fa00;\">⏎</span>\n"
);
lines = lines.split("\n");
if (issue.special) {
var check_length = lines[0].length;
lines[0] = issue.special
if (check_length > line_limit) {
var save_l0 = issue.special.substring(
line_limit - 1)
lines[0] = issue.special.substring(0,
line_limit - 1)
.replace(/\s/g,
"<span class='cSpace'>⎵</span>"
) +
save_l0
}
}
var timedTextEvent =
'<div class="TimedTextEvent" style="width: 700px; max-width: 100%;">' +
'<div class="details">' +
'<div class="timing"><span class="TimeCode">' +
issue
.start_tcf + '</span>' +
'<span class="TimeCode">' + issue
.end_tcf +
'</span></div><div class="content"><div class="header">' +
'<span class="index">' + issue.id +
'</span>' + issue.html_cps +
'<span class="duration"><span class="TimeCode">' +
issue.dur_tcf + '</span></span>' +
'</div><div class="StyledTextEditor" dir="ltr" style="position:relative; top:-20px;">' +
'<pre><span>' + lines[0];
if (typeof lines[1] == "undefined") {
lines[1] = ""
}
timedTextEvent += '</span><div><span>' +
lines[1] +
'</span></div>'
if (typeof lines[2] !== "undefined") {
timedTextEvent +=
'<div><span style="color:red;">' +
lines[
2] + '</span></div></pre>'
}
else {
timedTextEvent += "</pre>"
}
for (var each_issue of issue.issues) {
var issueWithImg =
'<div style="vertical-align:middle;float:left;">' +
"<span class='issue'>" + each_issue +
"</span></span></div>"
timedTextEvent += issueWithImg + "<br />"
}
reportHtml += timedTextEvent +
"</div></div></div></div></div>"
}
var withSC = ''
if(shotChanges) {withSC = "_withSC"}
var fixesFilename = srtName("Fixes_"+LANG+"_"+fps_+withSC)
var suggestedFixesTxt = '<a download="'+fixesFilename+'" href="data:text/plain;charset=utf-8,'+encodeURIComponent(parsed2srt(fSRT))+'"><button>✎</button></a>'
reportHtml = reportHtml.replace("DLFIXSRTTOKEN",suggestedFixesTxt)
download(srtName("Auto_QC_Log_"+LANG+'_'+fps_+withSC, ".html"),
reportHtml)
}
return runAutoQC;
})));
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ?
module.exports = factory() :
typeof define === 'function' && define.amd ? define(
factory) :
(global.parseSRT = factory());
}(this, (function () {
'use strict';
function toSeconds(time) {
var t = time.split(':');
try {
var s = t[2].split(',');
if (s.length === 1) {
s = t[2].split('.');
}
return parseFloat(t[0], 10) * 3600 +
parseFloat(t[1], 10) * 60 + parseFloat(s[
0], 10) + parseFloat(s[1], 10) / 1000;
}
catch (e) {
return 0;
}
}
function nextNonEmptyLine(linesArray, position) {
var idx = position;
while (!linesArray[idx]) {
idx++;
}
return idx;
}
function lastNonEmptyLine(linesArray) {
var idx = linesArray.length - 1;
while (idx >= 0 && !linesArray[idx]) {
idx--;
}
return idx;
}
function parseSRT() {
var data = arguments.length > 0 && arguments[
0] !== undefined ? arguments[0] : '';
var subs = [];
var lines = data.split(/(?:\r\n|\r|\n)/gm);
var endIdx = lastNonEmptyLine(lines) + 1;
var idx = 0;
var time = void 0;
var text = void 0;
var sub = void 0;
for (var i = 0; i < endIdx; i++) {
sub = {};
text = [];
i = nextNonEmptyLine(lines, i);
sub.id = parseInt(lines[i++], 10);
time = lines[i++].split(/[\t ]*-->[\t ]*/);
sub.start = toSeconds(time[0]);
idx = time[1].indexOf(' ');
if (idx !== -1) {
time[1] = time[1].substr(0, idx);
}
sub.end = toSeconds(time[1]);
while (i < endIdx && lines[i]) {
text.push(lines[i++]);
}
sub.text = text.join('\\N').replace(/{.an8}/,'POSToppyTAG')
.replace(
/\{(\\[\w]+\(?([\w\d]+,?)+\)?)+\}/gi
, '');
sub.text = sub.text.replace(/</g, '<')
.replace(/>/g, '>');
sub.text = sub.text.replace(
/<(\/?(font|b|u|i|s))((\s+(\w|\w[\w\-]*\w)(\s*=\s*(?:".*?"|'.*?'|[^'">\s]+))?)+\s*|\s*)(\/?)>/gi
, '<$1$3$7>');
sub.text = sub.text.replace(/\\N/gi, "\n");
sub.text = sub.text.replace('POSToppyTAG','{\\an8}')
subs.push(sub);
}
return subs;
}
return parseSRT;
})));
setTimeout(runAutoQC,3000,our_clq)