-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest.py
executable file
·65 lines (50 loc) · 1.74 KB
/
test.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/python3
'''
Created on 3 May 2018
@author: julianporter
'''
import pcm2mp3
import traceback
import sys
import re
import os
if __name__ == '__main__':
TRANSCODE=re.match('^[tT]',sys.argv[1]) if len(sys.argv)>1 else 0
try:
os.remove('test.mp3')
except Exception as e:
print(f"Couldn't remove test.mp3: {e}")
try:
id3=pcm2mp3.ID3(pcm2mp3.ID3.ID3v2)
id3[pcm2mp3.ID3.copyright]='All hail Lore Lixenberg!'
id3[pcm2mp3.ID3.title]='The test of tests'
id3.rate=32
if TRANSCODE:
print('Using transcode')
with open('test.wav','rb') as infile:
print('Starting transcoding')
out=pcm2mp3.transcode(infile.read(),id3)
print('Transcoding completed')
with open('test.mp3','wb') as outfile:
outfile.write(out)
else:
print('Using MP3 Object')
with open('test.wav','rb') as infile:
pcm=pcm2mp3.PCM(infile.read())
mp3=pcm2mp3.MP3(pcm,id3)
with open('test.mp3','wb') as outfile:
outfile.write(mp3.data())
print('Successful conversion')
result=pcm2mp3.mp3Check('test.mp3')
if result:
print('Output file verifies as MP3: success')
else:
print('Output file is not a valid MP3: failure')
except:
ety,ev,etr= sys.exc_info()
print(f"There was an error : {ety}, {ev}")
stack=traceback.extract_tb(etr)
for line in stack:
print(f'{line.filename} : {line.lineno} - {line.name} : {line.line}')
finally:
print('Completion')