-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4ae83b7
commit 80a9a06
Showing
4 changed files
with
105 additions
and
80 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,23 @@ | ||
FROM whipper/whipper | ||
FROM joelametta/whipper | ||
|
||
# required env variables for the script | ||
ENV BEETS_CONFIG=/config.albums-cover.yaml | ||
ENV LOG_DIR=/logs | ||
ENV OUTPUT_DIR=/output | ||
|
||
USER root | ||
|
||
# setup beets | ||
RUN pip install beets \ | ||
&& apt-get install -y python-requests \ | ||
&& mkdir /home/worker/.config/beets && chown worker: /home/worker/.config/beets | ||
COPY beets.yml /config.albums-cover.yaml | ||
RUN chown worker: /config.albums-cover.yaml \ | ||
&& mkdir $LOG_DIR && chown worker: $LOG_DIR | ||
VOLUME "$LOG_DIR" | ||
# setup beets, dependency munkres supports python2 up to 1.0.12 | ||
RUN pip install --quiet beets munkres==1.0.12 \ | ||
&& apt-get install -yqq python-requests \ | ||
&& mkdir /home/worker/.config/beets && chown worker: /home/worker/.config/beets \ | ||
&& mkdir -p -- "$LOG_DIR" \ | ||
&& chown worker: "$LOG_DIR" | ||
COPY --chown=worker:worker beets.yml /home/worker/.config/beets/config.yaml | ||
|
||
# setup script | ||
ENV SCRIPT_PATH=/auto-rip-audio-cd.sh | ||
COPY auto-rip-audio-cd.sh $SCRIPT_PATH | ||
RUN chmod +x $SCRIPT_PATH | ||
# add startup script | ||
COPY auto-rip-audio-cd.sh /auto-rip-audio-cd.sh | ||
RUN chmod +x /auto-rip-audio-cd.sh | ||
|
||
VOLUME "$LOG_DIR" | ||
USER worker | ||
|
||
ENTRYPOINT ["/auto-rip-audio-cd.sh"] |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,55 @@ | ||
#!/usr/bin/env bash | ||
#!/usr/bin/env sh | ||
# Automated rip process of an audio CD. | ||
set -u | ||
set -o nounset ## set -u : exit the script if you try to use an uninitialised variable | ||
|
||
log_dir=${LOG_DIR:-"$HOME/logs/audio-rip"} | ||
output_dir=${OUTPUT_DIR:-"$HOME/rip"} | ||
beets_config=${BEETS_CONFIG:-"$HOME/.config/beets/config.albums-cover.yaml"} | ||
beets_config=${BEETS_CONFIG:-"$HOME/.config/beets/config.yaml"} | ||
|
||
mkdir -p -- "$log_dir" | ||
log_file="${log_dir}/rip-$(date +%Y-%m-%dT%H-%M-%S).log" | ||
|
||
fn_log () { | ||
echo "### $*" | tee -a "$log_file" | ||
} | ||
|
||
fn_log "auto rip started" | ||
fn_log "starting rip process with whipper" | ||
|
||
# PYTHONIOENCODING: workaround for an issue: https://github.com/JoeLametta/whipper/issues/43 | ||
export PYTHONIOENCODING="utf-8" | ||
whipper cd rip --output-directory="$output_dir" -U >> "$log_file" 2>&1 | ||
whipper cd rip --unknown 2>&1 | tee -a "$log_file" | ||
sc_whipper=$? | ||
|
||
# grab the cover art | ||
if [ $sc_whipper == 0 ]; then | ||
fn_log "whipper rip finished" | ||
|
||
# replace the carriage returns with proper line breaks and search for the output pattern | ||
folder_line=$(tr '\015' "\n" < "$log_file" | grep "utput directory") | ||
if [ $sc_whipper = 0 ]; then | ||
# example line: | ||
# INFO:whipper.image.cue:parsing .cue file u'unknown/Unknown Artist - m3JTAxsMcVKGGAiW6CKcaYJ5TG8-/Unknown Artist - m3JTAxsMcVKGGAiW6CKcaYJ5TG8-.cue' | ||
pattern="INFO:whipper\.image\.cue:parsing \.cue file u'.*.cue'" | ||
|
||
if [ -z "$folder_line" ]; then | ||
fn_log "result: success (but couldn't find output folder for fetching cover art)" | ||
else | ||
# replace the carriage returns with proper line breaks and search for the output pattern | ||
if cue_file_line=$(tr '\015' "\n" < "$log_file" | grep -E "$pattern"); then | ||
# remove the search pattern | ||
output_path=${folder_line/Creating output directory /} | ||
cue_file=$(echo $cue_file_line | sed "s/.*'\(.*\)'/\1/") | ||
output_path=$(dirname "$cue_file") | ||
fn_log "output path: $output_path" | ||
|
||
# Use beets for image grabbing if it is available. | ||
# Can be removed once this is implemented: https://github.com/JoeLametta/whipper/issues/50 | ||
if type beet >/dev/null 2>&1; then | ||
fn_log "fetching cover art using beets" | ||
# -l: discard all additions to the library | ||
# -c: path to the config file | ||
# import: normally you import the file here and grab the cover alongside | ||
# -q: quiet - don't ask for user input. Either it works or forget about it | ||
echo a | beet -c "$beets_config" import "$output_path" >> "$log_file" | ||
sc_beets=$? | ||
fn_log "beet result: ${sc_beets}" | ||
exit $sc_beets | ||
exit $? | ||
else | ||
fn_log "failed to find beets to fetch the cover art" | ||
fi | ||
else | ||
fn_log "result: success (but couldn't find output folder for fetching cover art)" | ||
fi | ||
else | ||
fn_log "failed to rip: ${sc_whipper}" | ||
fn_log "whipper failed with status code ${sc_whipper}" | ||
exit $sc_whipper | ||
fi | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,5 @@ | ||
library: /dev/null | ||
|
||
import: | ||
copy: no | ||
write: no | ||
|
||
plugins: fetchart | ||
plugins: fetchart |