1.0.3 - Use Variable for paths, no hardcode

- Change: LidarrAudiobookRootFolder -> lidarrAudiobookRootFolder for consistency
- Add spacing to make easier to read
- Adjust error checking process
pull/80/head
RandomNinjaAtk 2 years ago committed by GitHub
parent 9f4dfd5d57
commit 26b527fb01
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1,5 +1,5 @@
#!/usr/bin/env bash #!/usr/bin/env bash
scriptVersion="1.0.2" scriptVersion="1.0.3"
agent="ERA ( https://github.com/Makario1337/ExtendedReleaseAdder )" agent="ERA ( https://github.com/Makario1337/ExtendedReleaseAdder )"
ArtistsJSON=$(jq '.artists[]' /config/artists.json) ArtistsJSON=$(jq '.artists[]' /config/artists.json)
@ -20,7 +20,7 @@ if [ -z "$lidarrUrl" ] || [ -z "$lidarrApiKey" ]; then
lidarrUrl="http://127.0.0.1:${lidarrPort}${lidarrUrlBase}" lidarrUrl="http://127.0.0.1:${lidarrPort}${lidarrUrlBase}"
fi fi
LidarrAudiobookRootFolder=$(curl -s GET "$lidarrUrl/api/v1/rootFolder" -H "X-Api-Key: ${lidarrApiKey}" | grep '\/audiobooks\/')
log "-----------------------------------------------------------------------------" log "-----------------------------------------------------------------------------"
log " |\/| _ | _ ._o _ '|~/~/~/" log " |\/| _ | _ ._o _ '|~/~/~/"
log " | |(_||<(_|| |(_) |_)_)/ " log " | |(_||<(_|| |(_) |_)_)/ "
@ -44,33 +44,35 @@ log "3"; sleep 1
log "2"; sleep 1 log "2"; sleep 1
log "1"; sleep 1 log "1"; sleep 1
if [ -z "$LidarrAudiobookRootFolder" ]; then if [ ! -d "$lidarrAudiobookRootFolder" ]; then
log "ERROR :: Audiobooks folder doesn't exist... " log "ERROR :: Audiobooks \"$lidarrAudiobookRootFolder\" folder doesn't exist... "
log "ERROR :: Check your Docker path mappings..." log "ERROR :: Check your Docker path mappings..."
log "ERROR :: Exiting ERA..." log "ERROR :: Exiting ERA..."
exit exit
fi fi
if [ ! -d "/audiobooks" ]; then lidarrAudiobookRootFolderCheck=$(curl -s GET "$lidarrUrl/api/v1/rootFolder" -H "X-Api-Key: ${lidarrApiKey}" | grep "$lidarrAudiobookRootFolder")
log "ERROR :: Audiobooks folder doesn't exist... "
log "ERROR :: Check your Docker path mappings..." 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..." log "ERROR :: Exiting ERA..."
exit exit
fi fi
AddReleaseToLidarr() { AddReleaseToLidarr() {
lidarrAlbumSearch=$(curl -X GET "$lidarrUrl/api/v1/album/lookup?term="lidarr%3A%20$1"" -H "accept: */*" -H "X-Api-Key: "$lidarrApiKey"" | jq '.') lidarrAlbumSearch=$(curl -X GET "$lidarrUrl/api/v1/album/lookup?term="lidarr%3A%20$1"" -H "accept: */*" -H "X-Api-Key: "$lidarrApiKey"" | jq '.')
lidarrAlbumSearch=$(echo $lidarrAlbumSearch | lidarrAlbumSearch=$(echo $lidarrAlbumSearch |
sed 's/"monitored": false/"monitored": true/g'| sed 's/"monitored": false/"monitored": true/g'|
sed 's/"qualityProfileId": 0/"qualityProfileId": 1/g' | sed 's/"qualityProfileId": 0/"qualityProfileId": 1/g' |
sed 's/"metadataProfileId": 0/"metadataProfileId": 2/g' | sed 's/"metadataProfileId": 0/"metadataProfileId": 2/g' |
sed 's/"metadataProfileId": 2/"metadataProfileId": 2,\"rootFolderPath": "\/audiobooks\/" /g'| sed 's/"metadataProfileId": 2/"metadataProfileId": 2,\"rootFolderPath": "\/audiobooks\/" /g'|
sed 's/"metadataProfileId": 2/"metadataProfileId": 2,\"addOptions": {"monitor": "all","searchForMissingAlbums": false}/g' | sed 's/"metadataProfileId": 2/"metadataProfileId": 2,\"addOptions": {"monitor": "all","searchForMissingAlbums": false}/g' |
sed 's/"grabbed": false/"grabbed": false,\"addOptions": {"searchForNewAlbum": false}/g'| sed 's/"grabbed": false/"grabbed": false,\"addOptions": {"searchForNewAlbum": false}/g'|
jq '.' | jq '.' |
cut -c 2- | cut -c 2- |
head -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" curl -X POST "$lidarrUrl/api/v1/album?apikey="$lidarrApiKey"" -H "accept: text/plain" -H "Content-Type: application/json" -d "$lidarrAlbumSearch"
} }
SearchRelease(){ SearchRelease(){
ReleaseName=$(wget -U "$agent" --timeout=0 -q -O - "https://musicbrainz.org/ws/2/release-group/$1" | grep -o "<title>.*</title>" | sed 's/<title>//g' | head -c -9 | sed 's/\&amp;/\&/g' | sed 's/???/???/g') ReleaseName=$(wget -U "$agent" --timeout=0 -q -O - "https://musicbrainz.org/ws/2/release-group/$1" | grep -o "<title>.*</title>" | sed 's/<title>//g' | head -c -9 | sed 's/\&amp;/\&/g' | sed 's/???/???/g')
@ -78,35 +80,36 @@ SearchRelease(){
AddReleaseToLidarr $1 &> /dev/null AddReleaseToLidarr $1 &> /dev/null
} }
SearchAllReleasesForArtist() { SearchAllReleasesForArtist() {
offset=0 offset=0
while [ $offset -le 500 ] while [ $offset -le 500 ]
do do
offset=$(( $offset + 100 )) offset=$(( $offset + 100 ))
sleep 1.5 sleep 1.5
SearchAllReleasesForArtist=$(wget -U "$agent" --timeout=0 -q -O - "https://musicbrainz.org/ws/2/release-group/?artist="$1"&limit=100&offset=$offset&fmt=json&type=other&secondary_type="audio%20drama"") SearchAllReleasesForArtist=$(wget -U "$agent" --timeout=0 -q -O - "https://musicbrainz.org/ws/2/release-group/?artist="$1"&limit=100&offset=$offset&fmt=json&type=other&secondary_type="audio%20drama"")
lines=$(echo $SearchAllReleasesForArtist | jq '."release-groups"[]."id"') lines=$(echo $SearchAllReleasesForArtist | jq '."release-groups"[]."id"')
if [ -z "$lines" ] if [ -z "$lines" ]
then then
log "ERROR :: Did not find matching release , skipping... " log "ERROR :: Did not find matching release , skipping... "
log "ERROR :: Make sure the wanted items are listed under Other + Audio Drama on Musicbrainz" log "ERROR :: Make sure the wanted items are listed under Other + Audio Drama on Musicbrainz"
offset=$(( $offset + 1337 )) offset=$(( $offset + 1337 ))
else else
for line in $lines for line in $lines
do do
trim=$(echo $line | cut -c 2- | head -c -2) trim=$(echo $line | cut -c 2- | head -c -2)
SearchRelease $trim SearchRelease $trim
sleep 1.5 sleep 1.5
done done
fi fi
done done
} }
ArtistLookup() { ArtistLookup() {
search=$(echo $1 | sed 's/\"//g') search=$(echo $1 | sed 's/\"//g')
artist=$(wget -U "$agent" --timeout=0 -q -O - "https://musicbrainz.org/ws/2/artist/$search" | grep -o "<name>.*</name>" | sed 's/<name>//' | sed 's/<\/name>.*//' | sed 's/???/???/g' ) artist=$(wget -U "$agent" --timeout=0 -q -O - "https://musicbrainz.org/ws/2/artist/$search" | grep -o "<name>.*</name>" | sed 's/<name>//' | sed 's/<\/name>.*//' | sed 's/???/???/g' )
log "Adding :: $artist" log "Adding :: $artist"
sleep 1.5 sleep 1.5
SearchAllReleasesForArtist $search SearchAllReleasesForArtist $search
} }
if [ -z "$ArtistsJSON" ] if [ -z "$ArtistsJSON" ]
then then
log "ERROR :: Did not find /config/artists.json or no artists in file... " log "ERROR :: Did not find /config/artists.json or no artists in file... "
@ -115,4 +118,4 @@ else
for str in ${ArtistsJSON[@]}; do for str in ${ArtistsJSON[@]}; do
ArtistLookup $str ArtistLookup $str
done done
fi fi

Loading…
Cancel
Save