66 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			JavaScript
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			66 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			JavaScript
		
	
	
		
			Executable File
		
	
	
	
	
| #!/usr/bin/zx
 | |
| 
 | |
| const label_file_path = process.argv.slice(-2)[0];
 | |
| const align_to = process.argv.slice(-2)[1];
 | |
| 
 | |
| const labels = (await $`cat ${label_file_path}`).stdout
 | |
|   .split("\n")
 | |
|   .filter((e) => e != "")
 | |
|   .map((l) => l.split("\t"))
 | |
|   .map(([start, stop, label]) => {
 | |
|     const suffix = label.match(/-[^-]+$/)[0];
 | |
|     const filename = label.replace(suffix, "");
 | |
|     return {
 | |
|       time: parseFloat(start),
 | |
|       label,
 | |
|       filename,
 | |
|       suffix: suffix.slice(1),
 | |
|     };
 | |
|   })
 | |
|   .reduce((acc, element) => {
 | |
|     if (!acc[element.filename]) {
 | |
|       acc[element.filename] = {
 | |
|         labels: {},
 | |
|       };
 | |
|     }
 | |
|     acc[element.filename].labels[element.suffix] = element.time;
 | |
|     return acc;
 | |
|   }, {});
 | |
| 
 | |
| for (let filename in labels) {
 | |
|   const filelabels = labels[filename].labels;
 | |
|   for (const suffix of ["A", "B"]) {
 | |
|     const duration =
 | |
|       filelabels[`end${suffix}`] - filelabels[`start${suffix}`] || null;
 | |
|     const key = `duration[${suffix}]`;
 | |
|     labels[filename][key] = duration;
 | |
|   }
 | |
| }
 | |
| 
 | |
| for (let filename1 in labels) {
 | |
|   for (let filename2 in labels) {
 | |
|     if (filename1 === filename2) {
 | |
|       continue;
 | |
|     }
 | |
|     for (const suffix of ["A", "B"]) {
 | |
|       const key = `duration[${suffix}]`;
 | |
| 
 | |
|       if (
 | |
|         labels[filename1][key] &&
 | |
|         labels[filename2][key] &&
 | |
|         filename2 == align_to
 | |
|       ) {
 | |
|         console.log(
 | |
|           "Aby dostosować",
 | |
|           filename1,
 | |
|           "do",
 | |
|           filename2,
 | |
|           "należy odpalić change-length z parametrem",
 | |
|           `${labels[filename2][key] / labels[filename1][key]}`
 | |
|         );
 | |
|         break;
 | |
|       }
 | |
|     }
 | |
|   }
 | |
| }
 |