-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmp3Convert.py
More file actions
executable file
·50 lines (36 loc) · 1.5 KB
/
mp3Convert.py
File metadata and controls
executable file
·50 lines (36 loc) · 1.5 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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
###############################################################################
# mp3Convert
#
# Converts audio files to mp3 using a fixed set of parameters
# - ensures that a set of mp3 (or aac) files are converted to a set mp3 profile
###############################################################################
import fire
from ffmpy import FFmpeg
import os
from pathlib import Path
def mp3convert(src_dir, dest_dir, dry_run=False):
# 44khz stereo at 64kb
conversion_params = '-acodec libmp3lame -vn -ar 44100 -ac 2 -ab 64k -filter:a "volume=1.5" -f mp3'
for input_file in list(Path(src_dir).rglob("*.[mMa][pPa][3c]")):
# We found at least one file to convert, ensure the output directory exists
if not os.path.exists(dest_dir):
os.makedirs(dest_dir)
# Ensure the final file extension for the target is lowercase mp3
output_file = os.path.join(dest_dir, input_file.stem + '.mp3')
if Path(output_file).exists():
print(f'{output_file} already exists in destination path skipping...')
continue
ff = FFmpeg(
inputs={os.path.join(src_dir, input_file): None},
outputs={output_file: conversion_params})
print(f'Command line : {ff.cmd}')
if dry_run is False:
ff.run()
def main():
# Fire exposes the input parameters to the convert method via the command
# line
fire.Fire(mp3convert)
if __name__ == '__main__':
main()