Last active
July 3, 2018 12:50
-
-
Save m4xp1/d6d575133b4d6d8e3dd0181d3de7d003 to your computer and use it in GitHub Desktop.
Bash script for recording musical album from audio card output (using record scripts)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Setup album data | |
artist="Steven Solveig" | |
album="Beginning of the End - Trailer Underscores" | |
year=2017 | |
# Setup album songs | |
declare -a name; declare -a time; | |
name+=("Dark Awakening"); time+=("01:43") | |
name+=("At the Edge"); time+=("02:25") | |
name+=("New Order"); time+=("01:32") | |
name+=("Fallen Heroes"); time+=("02:07") | |
name+=("Beginning of the End"); time+=("02:27") | |
name+=("Nothing Left"); time+=("02:05") | |
name+=("From the Dark"); time+=("02:02") | |
name+=("Time Is Relative"); time+=("02:46") | |
name+=("Long Journey"); time+=("01:42") | |
name+=("Conflict Order"); time+=("02:09") | |
name+=("Locked In"); time+=("01:39") | |
name+=("Come to Get You"); time+=("02:03") | |
name+=("Awake"); time+=("01:45") | |
name+=("District Zone"); time+=("01:44") | |
name+=("The End"); time+=("01:48") | |
# Setup global settings | |
dir=~/Загрузки | |
extension="mp3" | |
# Create folder | |
dirPath=$dir/$artist | |
mkdir -p "$dirPath" | |
# Start record for each song | |
sleep 1 | |
for i in "${!name[@]}"; do | |
time="${time[$i]}" | |
filePath="$dirPath/$artist - "${name[$i]}".$extension" | |
record -m "${time%:*}" -s "${time##*:}" -o "$filePath" -a --album "$album" --year $year --count $(($i + 1)) | |
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Show manual | |
if [[ $# -eq 0 ]] ; then | |
echo 'usage: record --min 1 --sec 45 --out file.mp3 --atrs --count 1 --album "Name" --year 1989' | |
echo "in first time check monitor variable in this script" | |
exit 0 | |
fi | |
# For find your device monitor use this command: pacmd list | grep "\.monitor" | |
monitor="alsa_output.pci-0000_00_1b.0.analog-stereo.monitor" | |
# Read arguments | |
while [[ $# -gt 0 ]] | |
do | |
case $1 in | |
-m|--min) | |
min="$2" | |
shift # past argument | |
shift # past value | |
;; | |
-s|--sec) | |
sec="$2" | |
shift # past argument | |
shift # past value | |
;; | |
-o|--out) | |
out="$2" | |
shift # past argument | |
shift # past value | |
;; | |
-a|--atrs) | |
atrs="yes" | |
shift # past argument | |
;; | |
--count) | |
count="$2" | |
shift # past argument | |
shift # past value | |
;; | |
--album) | |
album="$2" | |
shift # past argument | |
shift # past value | |
;; | |
--year) | |
year="$2" | |
shift # past argument | |
shift # past value | |
;; | |
*) # unknown option | |
shift # past argument | |
;; | |
esac | |
done | |
# Check arguments | |
let "timeout = $[10#$min-0] * 60 + $[10#$sec-0]" | |
if [[ $timeout -eq 0 ]]; then | |
exit 0 | |
fi | |
if [[ -z $out ]]; then | |
echo "Output file: $out don't specified" | |
exit 0 | |
fi | |
if [[ -f $out ]]; then | |
echo "Output file: $out already exist, please rename or delete it" | |
exit 0 | |
fi | |
# Start recording | |
echo "recording to file: $out" | |
parec --format=s16le -d $monitor | lame -r --quiet -q 3 --lowpass 17 --abr 192 - "$out" > /dev/null &1>/dev/null | |
# Wait recording and stop | |
sleep "$timeout.65" | |
killall -q parec lame | |
# Set mp3 attributes | |
if [[ $atrs == "yes" ]]; then | |
fullname=$(basename "$out") | |
filename="${fullname%.*}" | |
if [[ -z $year ]]; then | |
id3tool -c "${count-""}" -t "${filename#*- }" -a "${album-""}" -r "${filename%% -*}" "$out" | |
else | |
id3tool -c "${count-""}" -t "${filename#*- }" -a "${album-""}" -r "${filename%% -*}" -y "$year" "$out" | |
fi | |
fi | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment