#!/bin/sh # Chaptarr Connect → Custom Script ("CWA ingest"), On Import + On Upgrade. # # Chaptarr keeps its own ebook copy in /ebooks (= /storage1/Media/Ebooks) so it can see what # it already has. This hands CWA a *hardlink* of each newly imported ebook through the ingest # folder. CWA deletes its link once it has added the book to Calibre, and chaptarr's file is # left alone. [ "$Chaptarr_EventType" = "Download" ] || exit 0 # also covers the "Test" button INGEST=/storage1/complete/books-ingest IFS='|' for p in $Chaptarr_AddedBookPaths $Chaptarr_BookFile_Path; do case "$p" in /ebooks/*) rel=${p#/ebooks/} ;; /storage1/Media/Ebooks/*) rel=${p#/storage1/Media/Ebooks/} ;; *) continue ;; # audiobooks etc. esac [ -f "$p" ] || continue author=${rel%%/*} dest="$INGEST/$author/$(basename "$p")" [ -e "$dest" ] && continue # already queued (path listed twice) mkdir -p "$INGEST/$author" ln "$p" "$dest" 2>/dev/null || cp "$p" "$dest" echo "cwa-ingest: queued $p" done exit 0