jorenn92 / Maintainerr

Looks and smells like Overseerr, does the opposite. Maintenance tool for the Plex ecosystem
https://maintainerr.info
MIT License
778 stars 14 forks source link

a rule to re-sync requests #500

Closed i-am-at0m closed 11 months ago

i-am-at0m commented 1 year ago

Is your feature request related to a problem? Please describe. I've got an issue where I have things flagged as requested in Overseerr but the items aren't in my Sonarr library because the files didn't exist and my database got deleted. I'd like to be able to either delete those requests in Overseerr or re-push them to Sonarr and was hoping this could do that.

Describe the solution you'd like Maybe another rule setting for things being requested in overseerr, or a rule action of either being able to clear the thing in overseerr or re-add it and monitor it in sonarr

Describe alternatives you've considered the people running overseerr told me to figure out how to craft a script to use the api to do this but there;s no way i;m the only one who needs this feature

Additional context Add any other context or screenshots about the feature request here.

jorenn92 commented 1 year ago

I'm not entirely sure if I understand this issue. Syncing your Overseerr & Starr application's isn't really what Maintainerr is about.

Is Maintainerr misbehaving because it can't find the corresponding Sonarr record? I could imagine there might be some log warnings. But I think it should still remove files & sync Overseerr, is it not?

If the media file isn't available at all and therefore Plex doesn't know about it, then that's a different story, Maintainerr won't be able to function in that scenario.

If the files are still available, you could try some rule combinations (& manual exclusions) to fetch & process the records you want.

Perhaps with:

Or perhaps by using 'Sonarr - date added'. I'm not sure if this would work, but the Sonarr api might return a 000-0-0 value when it's not in its library. I haven't tested this though, just something you might be able to try.

i-am-at0m commented 1 year ago

So what happened is a bunch of stuff was requested in Overseerr, but didn't exist on disk yet because it wasn't released. Then I lost my Sonarr and Radarr databases and had to scan everything in again, so no library entries were created for anything that wasn't already on disk.

Overseerr thinks they're requested so won't allow another request, but since they don't exist in the starr apps they never get grabbed. Overseerr's normal library sync doesn't correct this state, but manually adding the item to the starr app and grabbing it does.

From the description I was hoping maintainerr could help me clean this up, but it's all about removing things from the library as opposed to removing orphaned requests from overseerr that don't have a matching library entry.

jorenn92 commented 1 year ago

Ah yes, I’m afraid Maintainerr won’t be of much help in this case.

A script does seem like the best option.

Their APIs are well documented and what you want to accomplish shouldn’t be that hard.

If you’re not comfortable writing it yourself, perhaps ChatGPT can help? I asked it for a script, and it does seem like a good starting point. I didn’t test it though


#!/bin/bash

# Overseerr API URL and API Key
OVERSEERR_URL="http://your-overseerr-url/api/v1"
OVERSEERR_API_KEY="your-overseerr-api-key"

# Sonarr API URL and API Key
SONARR_URL="http://your-sonarr-url/api"
SONARR_API_KEY="your-sonarr-api-key"

# Function to get Overseerr requests
get_overseerr_requests() {
  curl -s -H "Authorization: Bearer $OVERSEERR_API_KEY" "$OVERSEERR_URL/request"
}

# Function to check if a series exists in Sonarr
series_exists_in_sonarr() {
  local title="$1"
  local search_result=$(curl -s -H "X-Api-Key: $SONARR_API_KEY" "$SONARR_URL/series/lookup" -d "term=$title")
  local series_count=$(echo "$search_result" | jq -r '.[] | length')

  if [[ "$series_count" -gt 0 ]]; then
    return 0  # Series exists in Sonarr
  else
    return 1  # Series does not exist in Sonarr
  fi
}

# Function to add a request to Sonarr
add_to_sonarr() {
  local title="$1"
  local qualityProfileId="1"  # Modify this to your desired quality profile ID in Sonarr
  local rootFolder="1"        # Modify this to your desired root folder ID in Sonarr

  curl -s -H "X-Api-Key: $SONARR_API_KEY" -d "title=$title" -d "profileId=$qualityProfileId" -d "path=$rootFolder" "$SONARR_URL/series"
}

# Main script
requests=$(get_overseerr_requests)

if [[ -z "$requests" ]]; then
  echo "No requests found in Overseerr."
  exit 0
fi

for request in $(echo "$requests" | jq -r '.[] | @base64'); do
  title=$(echo "$request" | base64 --decode | jq -r '.title')

  if ! series_exists_in_sonarr "$title"; then
    add_to_sonarr "$title"
    echo "Added '$title' to Sonarr."
  else
    echo "'$title' already exists in Sonarr. Skipping."
  fi
done

echo "Sync completed."
jorenn92 commented 11 months ago

Closing because of no reaction.