-
Notifications
You must be signed in to change notification settings - Fork 0
/
flac2mp3.sh
executable file
·60 lines (51 loc) · 2.02 KB
/
flac2mp3.sh
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
#!/bin/bash
# FLAC to MP3 converter script originally by
# erdnuesse https://github.com/erdnuesse
# adapted for use by me
## - The IFS takes care of spaces in file and dirnames
## - your folders may vary
## - what you mount to the folders does not matter
## - in RELDIR, the f5 most likely MUST be edited,
## since its responsible, how many leading directories
## will be removed from the directory structure in order
## to append that exact path to the outfile
## - the commented echos are still in place in order to give
## you the variables for testing, before running.
## just comment the ffmpeg / avconv command with a #
## - on my raspberry I could only use avconv, not ffmpeg.
## choose, whatever suits you best
IFS=$'\n'
## the paths given here contain my Directory structure, that I want to keep
## source=/mnt/music/FLAC/ARTIST/ALBUM/FLACFILE.flac
## local=/mnt/1tb/mp3/ARTIST/ALBUM/MP3FILE.mp3
source=$HOME/Music/
dest=$HOME/Music/Mobile
for i in $(find $source -type f -iname '*.flac' );
do
## SET VARIABLES for PATHS and FILENAMES
fullfile=$i
filename="${i##*/}"
filename="${filename%.*}.mp3"
fulldir=$(dirname "${i}")
reldir="$(echo $fulldir | cut -d'/' -f5-)"
reldir=${reldir//flac}
outdir="$dest/$reldir"
outfile="$outdir/$filename"
# is that working?
# outfile='$local/""$(echo $(dirname "${i}") | cut -d'/' -f5-)"//flac"/"${i##*/}"'
# echo 'output file: ' "$outfile"
## SHOW ME THE CONTENTS of the VARIABLES
# echo 'File found:' "$i"
# echo 'Relative dir: ' "$reldir"
# echo 'directory will be created: ' "$outdir"
# echo 'Filename: ' "$filename"
# echo 'FileExt: ' "$extension"
# echo 'output file: ' "$outfile"
## CREATE Output Folders
mkdir -p "$outdir"
## RUN
ffmpeg -n -loglevel info -i "$fullfile" -codec:a libmp3lame -qscale:a 0 "$outfile"
# avconv -n -nostats -loglevel info -i "$fullfile" -codec:a libmp3lame -qscale:a 0 "$outfile"
## just for testing
# sleep 1
done