forked from devsnd/python-audiotranscode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_transcode.py
More file actions
78 lines (70 loc) · 2.61 KB
/
Copy pathtest_transcode.py
File metadata and controls
78 lines (70 loc) · 2.61 KB
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
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/usr/bin/python3
#
# CherryMusic - a standalone music server
# Copyright (c) 2012 Tom Wallroth & Tilman Boerner
#
# Project page:
# http://fomori.org/cherrymusic/
# Sources on github:
# http://github.com/devsnd/cherrymusic/
#
# CherryMusic is based on
# jPlayer (GPL/MIT license) http://www.jplayer.org/
# CherryPy (BSD license) http://www.cherrypy.org/
#
# licensed under GNU GPL version 3 (or later)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>
#
import unittest
import os
from nose.tools import *
import audiotranscode as transcode
transcoder = transcode.AudioTranscode(debug=True)
testdir = os.path.dirname(__file__)
testfiles = {
'mp3' : os.path.join(testdir,'test.mp3'),
'ogg' : os.path.join(testdir,'test.ogg'),
'flac': os.path.join(testdir,'test.flac'),
'wav': os.path.join(testdir,'test.wav'),
'm4a': os.path.join(testdir,'test.m4a'),
}
outputpath = os.path.join(testdir,'output')
if not os.path.exists(outputpath):
os.mkdir(outputpath)
def generictestfunc(filepath, newformat, encoder, decoder):
ident = "%s_%s_to_%s_%s" % (
decoder.command[0],
os.path.basename(filepath),
encoder.command[0],
newformat
)
#print(ident)
outdata = b''
for data in transcoder.transcode_stream(filepath, newformat, encoder=encoder, decoder=decoder):
outdata += data
ok_(len(outdata)>0, 'No data received: '+ident)
with open(os.path.join(outputpath,ident+'.'+newformat),'wb') as outfile:
outfile.write(outdata)
def test_generator():
for enc in transcoder.Encoders:
if not enc.filetype in transcoder.available_encoder_formats():
print('Encoder %s not installed!'%enc.command[0])
continue
for dec in transcoder.Decoders:
if not dec.filetype in transcoder.available_decoder_formats():
print('Encoder %s not installed!'%dec.command[0])
continue
if dec.filetype in testfiles:
yield generictestfunc, testfiles[dec.filetype], enc.filetype, enc, dec