diff --git a/root/scripts/ERA.sh b/root/scripts/ERA.sh index b21763d..3ef145f 100644 --- a/root/scripts/ERA.sh +++ b/root/scripts/ERA.sh @@ -1,33 +1,24 @@ #!/usr/bin/env bash -scriptVersion="1.0.6" +scriptVersion="1.1.0" agent="ERA ( https://github.com/Makario1337/ExtendedReleaseAdder )" -ArtistsJSON=$(jq '.artists[]' /config/artists.json) + +### DEBUG ### +DEBUG=0 +### DEBUG end ### log () { m_time=`date "+%F %T"` echo $m_time" :: Extended Release Adder :: "$1 } -# auto-clean up log file to reduce space usage -if [ -f "/config/logs/ExtendedReleaseAdder.txt" ]; then - find /config/logs -type f -name "ExtendedReleaseAdder.txt" -size +1024k -delete -fi - -exec &>> "/config/logs/ExtendedReleaseAdder.txt" -chmod 666 "/config/logs/ExtendedReleaseAdder.txt" - -if [ -z "$lidarrUrl" ] || [ -z "$lidarrApiKey" ]; then - lidarrUrlBase="$(cat /config/config.xml | xq | jq -r .Config.UrlBase)" - if [ "$lidarrUrlBase" = "null" ]; then - lidarrUrlBase="" - else - lidarrUrlBase="/$(echo "$lidarrUrlBase" | sed "s/\///g")" - fi - lidarrApiKey="$(cat /config/config.xml | xq | jq -r .Config.ApiKey)" - lidarrPort="$(cat /config/config.xml | xq | jq -r .Config.Port)" - lidarrUrl="http://127.0.0.1:${lidarrPort}${lidarrUrlBase}" -fi - +### Start ### +start () { +if [[ $DEBUG -ne 1 ]]; then + if [ -f "/config/logs/ExtendedReleaseAdder.txt" ]; then + find /config/logs -type f -name "ExtendedReleaseAdder.txt" -size +1024k -delete + fi + exec &>> "/config/logs/ExtendedReleaseAdder.txt" + chmod 666 "/config/logs/ExtendedReleaseAdder.txt" log "-----------------------------------------------------------------------------" log " |\/| _ | _ ._o _ '|~/~/~/" log " | |(_||<(_|| |(_) |_)_)/ " @@ -50,21 +41,21 @@ log "4"; sleep 1 log "3"; sleep 1 log "2"; sleep 1 log "1"; sleep 1 - -if [ ! -d "$lidarrAudiobookRootFolder" ]; then - log "ERROR :: Audiobooks \"$lidarrAudiobookRootFolder\" folder doesn't exist... " - log "ERROR :: Check your Docker path mappings..." - log "ERROR :: Exiting ERA..." - exit fi -lidarrAudiobookRootFolderCheck=$(curl -s GET "$lidarrUrl/api/v1/rootFolder" -H "X-Api-Key: ${lidarrApiKey}" | grep "$lidarrAudiobookRootFolder") -if [ -z "$lidarrAudiobookRootFolderCheck" ]; then - log "ERROR :: Audiobooks \"$lidarrAudiobookRootFolder\" is not added to Lidarr as a root folder... " - log "ERROR :: Add \"$lidarrAudiobookRootFolder\" to Lidarr as a root folder" - log "ERROR :: Exiting ERA..." - exit -fi - +if [ -z "$lidarrUrl" ] || [ -z "$lidarrApiKey" ]; then + lidarrUrlBase="$(cat /config/config.xml | xq | jq -r .Config.UrlBase)" + if [ "$lidarrUrlBase" = "null" ]; then + lidarrUrlBase="" + else + lidarrUrlBase="/$(echo "$lidarrUrlBase" | sed "s/\///g")" + fi + lidarrApiKey="$(cat /config/config.xml | xq | jq -r .Config.ApiKey)" + lidarrPort="$(cat /config/config.xml | xq | jq -r .Config.Port)" + lidarrUrl="http://127.0.0.1:${lidarrPort}${lidarrUrlBase}" +fi +} +start +### Start end ### AddReleaseToLidarr() { lidarrAlbumSearch=$(curl -s -X GET "$lidarrUrl/api/v1/album/lookup?term="lidarr%3A%20$1"" -H "accept: */*" -H "X-Api-Key: "$lidarrApiKey"" | jq '.') CheckIfAlreadyAdded=$(echo $lidarrAlbumSearch | tr -d ' ' | sed 's/^.*,"grabbed":*false,"id"://g' | sed 's/}]//g' ) @@ -75,63 +66,71 @@ AddReleaseToLidarr() { sed 's/"monitored": false/"monitored": true/g'| sed 's/"qualityProfileId": 0/"qualityProfileId": 1/g' | sed 's/"metadataProfileId": 0/"metadataProfileId": 1/g' | - sed "s%\"metadataProfileId\": 1%\"metadataProfileId\": 1,\"rootFolderPath\": \"$lidarrAudiobookRootFolder/\" %g" | + sed "s%\"metadataProfileId\": 1%\"metadataProfileId\": 1,\"rootFolderPath\": \"\" %g" | sed 's/"metadataProfileId": 1/"metadataProfileId": 1,\"addOptions": {"monitor": "all","searchForMissingAlbums": false}/g' | sed 's/"grabbed": false/"grabbed": false,\"addOptions": {"searchForNewAlbum": false}/g'| jq '.' | cut -c 2- | - head -c -2) - curl -X POST "$lidarrUrl/api/v1/album?apikey="$lidarrApiKey"" -H "accept: text/plain" -H "Content-Type: application/json" -d "$lidarrAlbumSearch" + head -c -2) + curl -s -X POST "$lidarrUrl/api/v1/album?apikey="$lidarrApiKey"" -H "accept: text/plain" -H "Content-Type: application/json" -d "$lidarrAlbumSearch" log "Adding :: $2 :: $3 :: Release Added..." fi } - -SearchRelease(){ - ReleaseName=$(wget -U "$agent" --timeout=0 -q -O - "https://musicbrainz.org/ws/2/release-group/$1" | grep -o "