-
Notifications
You must be signed in to change notification settings - Fork 0
/
encode.py
50 lines (44 loc) · 959 Bytes
/
encode.py
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
import os
import shutil
import io
import ffmpeg
import sys
import json
import subprocess
header = b'MDFPWM\003'
luaPath = shutil.which("lua")
if len(sys.argv) > 1:
luaPath = sys.argv[1]
elif luaPath == None:
luaPath = "C:\\ffmpeg\\bin\\lua.exe"
a = open("output.mdfpwm", "wb")
data = b''
os.system("convert.sh")
l = open("left.dfpwm", "rb")
r = open("right.dfpwm", "rb")
ld = l.read(6000)
rd = r.read(6000)
while ld and rd:
data = data+ld
data = data+rd
ld = l.read(6000)
rd = r.read(6000)
l.close()
r.close()
aa = open("meta.json","r")
loaded = json.loads(aa.read())
aa.close()
length = sys.getsizeof(data)
artist = loaded["artist"]
title = loaded["title"]
album = loaded["album"]
subprocess.run([luaPath,"pack.lua",str(length),artist,title,album], shell=True)
temp = open("headers.bin","rb")
songinfo = temp.read()
temp.close()
print(songinfo)
a.write(header)
a.write(songinfo)
a.write(data)
a.close()
os.remove("headers.bin")