-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmpgConvert.py
More file actions
executable file
·46 lines (39 loc) · 1.26 KB
/
mpgConvert.py
File metadata and controls
executable file
·46 lines (39 loc) · 1.26 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
#!/usr/local/bin/python
# Maintained at: git@github.com:dareni/shellscripts.git
import os
from sys import argv
def displayError():
print 'Usage: mpgConvert.py [infile]|[indir] outdir [bitrate]'
print 'Example: mpgConvert.py ./song.mp3 /tmp 64k'
print 'Example: mpgConvert.py /songs /tmp/songs 64k'
print 'Default bitrate=128k'
if len(argv) < 3 or len(argv) > 4:
displayError()
raise Exception('Incorrect usage, please specify parameters.')
target = argv[1]
outdir = argv[2]
bitrate = '128k'
print len(argv)
if len(argv) == 4:
bitrate = argv[3]
files = []
if os.path.isfile(target):
files = [target]
elif os.path.isdir(target):
files = os.listdir(target)
adjFiles = []
for song in files:
adjFiles.append(target + '/' + song)
files = adjFiles
if not os.path.isdir(outdir):
displayError()
raise Exception('Outdir is not a directory.')
for targetfile in files:
filename = os.path.basename(targetfile)
name, extension = os.path.splitext(filename)
cmd = 'avconv -i "' + targetfile + '" -b "' + bitrate + '" -f mp3 "' + \
outdir + '/' + name + '.mp3"'
print cmd
os.system(cmd)
#avconv -i in.wma -acodec mp2 -f mp2 out/file.mp3
#avconv -i in.wma -acodec libvorbis -f ogg -b 128k out/file.ogg