# Unattended import on docker

**URL:** <https://discourse.beets.io/t/unattended-import-on-docker/2635>\
**Category:** Help\
**Created:** [September 15, 2024, 2:50pm UTC](https://discourse.beets.io/t/unattended-import-on-docker/2635 "2024-09-15T14:50:56Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![tubasolo](https://avatars.discourse-cdn.com/v4/letter/t/58956e/32.png) [@tubasolo](https://discourse.beets.io/u/tubasolo)\
**Post date:** [September 15, 2024, 2:50pm UTC](https://discourse.beets.io/t/unattended-import-on-docker/2635/1 "2024-09-15T14:50:56Z")

</div>

I’m looking for some help to get my beets docker installation to auto-detect and import new music files and folders in my /downloads to my /music folder. I want new tracks from exisiting albums to merge with that album.

I saw that drop2beets only works with singles, but I download mostly albums. So with the help of ChatGPT I set up a script that checks recursively for each new track and runs an beets import command.

I’m not only failing miserably at importing (Track not found) but also at merging (Album already exists). I would really appreciate some help with:

- the recommended way for an unattended auto-import of new music
- the rcemmended yaml options to achieve this.

Thank you!

Here now my stump script and my yaml:

Import-Script:  
#!/bin/sh

DOWNLOADS\_DIR=“/mnt/media/media/nicotine-downs/downloads”  
BEETS\_DOCKER\_CONTAINER=“beets” # Replace with your Docker container name  
LOG\_FILE=“/home/tom/beets/beets\_watcher.log” # Log file location

# Function to write log entries

log() {  
echo “$(date ‘+%Y-%m-%d %H:%M:%S’) - $1” \>\> “$LOG\_FILE”  
}

inotifywait -mr -e create -e moved\_to --format ‘%w%f’ “$DOWNLOADS\_DIR” | while read NEW\_FILE  
do  
if [-f “$NEW\_FILE”]; then  
log “New file detected: $NEW\_FILE”

```
    # Small delay to ensure file is fully written
    sleep 1

    # Replace the bare-metal path with the container path, assuming they are mounted correctly
    CONTAINER_PATH="${NEW_FILE/$DOWNLOADS_DIR/\/downloads}"

    log "Attempting to import file from container path: $CONTAINER_PATH"

    # Check if the file exists inside the Docker container
    docker exec "$BEETS_DOCKER_CONTAINER" test -f "$CONTAINER_PATH"
    if [$? -eq 0]; then
        docker exec "$BEETS_DOCKER_CONTAINER" beet import "$CONTAINER_PATH" >> "$LOG_FILE" 2>&1
        if [$? -eq 0]; then
            log "Import complete for: $CONTAINER_PATH"
        else
            log "Error importing: $CONTAINER_PATH"
        fi
    else
        log "File not found in Docker container: $CONTAINER_PATH"
    fi
fi

```

done

Yaml:  
plugins: fetchart embedart convert scrub replaygain lastgenre chroma web duplicates  
directory: /music  
library: /config/musiclibrary.blb  
art\_filename: albumart  
threaded: yes  
original\_date: no  
per\_disc\_numbering: no

duplicates:  
merge: yes  
action: remove # This removes the lower quality files  
tiebreak:  
items: [bitrate, samplerate] # Prioritize higher bitrate and sample rate  
full: true # This ensures the full comparison is made

import:  
write: yes  
copy: no  
move: yes  
resume: yes  
quiet: yes  
incremental: no  
incremental\_skip\_later: no  
quiet\_fallback: asis  
timid: no  
log: /config/beet.log

convert:  
auto: no  
ffmpeg: /usr/bin/ffmpeg  
opts: -ab 320k -ac 2 -ar 48000  
max\_bitrate: 320  
threads: 1

paths:  
default: $albumartist/$album%aunique{}/$track - $title  
singleton: Non-Album/$artist - $title  
comp: Compilations/$album%aunique{}/$track - $title  
albumtype\_soundtrack: Soundtracks/$album/$track $title

match:  
strong\_rec\_thresh: 0.16  
medium\_rec\_thresh: 0.25  
rec\_gap\_thresh: 0.25

lastgenre:  
auto: yes  
source: album

embedart:  
auto: yes

fetchart:  
auto: yes  
art\_filename: cover.jpg  
minwidth: 500

replaygain:  
auto: no

scrub:  
auto: yes

replace:  
‘^.’: \_  
‘[\x00-\x1f]’: \_  
‘[\<\>:"?\*|]’: \_  
‘[\xE8-\xEB]’: e  
‘[\xEC-\xEF]’: i  
‘[\xE2-\xE6]’: a  
‘[\xF2-\xF6]’: o  
‘[\xF8]’: o  
‘.$’: \_  
‘\s+$’: ‘’

web:  
host: 0.0.0.0  
port: 8337

the:  
a: yes  
the: yes
