comparison simporter.nim @ 390:1727bec9ca2f

did: finish importing system
author Sam <sam@basx.dev>
date Wed, 06 Dec 2023 00:05:55 +0700
parents
children
comparison
equal deleted inserted replaced
389:ae8a6c6ff468 390:1727bec9ca2f
1 import std/os
2 import std/paths
3 import std/dirs
4 import std/osproc
5 import std/cmdline
6 import std/strutils
7 import std/strformat
8
9 import ./semicongine/core/audiotypes
10
11 proc import_meshes*(files: seq[(string, string)]) =
12 let converter_script = currentSourcePath.parentDir().joinPath("scripts/blender_gltf_converter.py")
13
14 var args = @["--background", "--python", converter_script, "--"]
15 for (input, output) in files:
16 args.add input
17 args.add output
18
19 let p = startProcess("blender", args=args, options={poStdErrToStdOut, poUsePath})
20 let exitCode = p.waitForExit()
21 p.close()
22 if exitCode != 0:
23 raise newException(OSError, &"blender had exit code {exitCode}")
24
25 proc import_audio*(files: seq[(string, string)]) =
26 for (input, output) in files:
27 let p = startProcess("ffmpeg", args=["-y", "-i", input, "-ar", $AUDIO_SAMPLE_RATE, output], options={poStdErrToStdOut, poUsePath})
28 let exitCode = p.waitForExit()
29 p.close()
30 if exitCode != 0:
31 raise newException(OSError, &"ffmpeg had exit code {exitCode}")
32
33 when isMainModule:
34 var meshfiles: seq[(string, string)]
35 var audiofiles: seq[(string, string)]
36
37 for arg in commandLineParams():
38 if arg.count(':') != 1:
39 raise newException(Exception, &"Argument {arg} requires exactly one colon to separate input from output, but it contains {arg.count(':')} colons.")
40 let
41 input_output = arg.split(':', 1)
42 input = input_output[0]
43 output = input_output[1]
44 if not input.fileExists:
45 raise newException(IOError, &"Not found: {input}")
46 if not output.fileExists or input.fileNewer(output):
47 echo &"{output} is outdated"
48 if input.endsWith("blend"):
49 meshfiles.add (input, output)
50 elif input.endsWith("mp3") or input.endsWith("ogg") or input.endsWith("wav"):
51 audiofiles.add (input, output)
52 else:
53 raise newException(Exception, &"unkown file type: {input}")
54 Path(output.parentDir()).createDir()
55 else:
56 echo &"{output} is up-to-date"
57
58 import_meshes meshfiles
59 import_audio audiofiles