weakRise.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. const { createWriteStream, readdir, readFile } = require('fs')
  2. const { join } = require('path')
  3. const { promisify } = require('util')
  4. const { parseString } = require('xml2js')
  5. !async function (){
  6. const logs = createWriteStream(join(__dirname, 'logs.txt'))
  7. // console.log(logs.write)
  8. const files = await promisify(readdir)(join(__dirname, 'colexiu-xmls'))
  9. for (const file of files) {
  10. if (file.endsWith('.xml')) {
  11. try {
  12. console.log(file)
  13. const content = await promisify(readFile)(join(__dirname, 'colexiu-xmls', file))
  14. const json = await promisify(parseString)(content.toString())
  15. let times = []
  16. for (let i = 0; i < json['score-partwise'].part[0].measure.length; i++) {
  17. if (i > 1) {
  18. break
  19. }
  20. const measure = json['score-partwise'].part[0].measure[i]
  21. let time = 0
  22. for (let j = 0; j < measure.note.length; j++) {
  23. time = time + +measure.note[j].duration[0]
  24. }
  25. times.push(time)
  26. }
  27. if (times[0] !== times[1]) {
  28. logs.write(`${file} 是弱起\n`)
  29. }
  30. console.log(times)
  31. } catch (error) {
  32. logs.write(`${file} 解析失败\n`)
  33. }
  34. }
  35. }
  36. }()