jacksonblankenship / roombarr

Automated cleanup tool for Radarr, leveraging MDBList to manage and delete orphaned movies while preserving manually added content.
0 stars 0 forks source link

feat: add support for multiple MDBLists and automate Radarr setup #2

Open jacksonblankenship opened 1 month ago

jacksonblankenship commented 1 month ago

Here's my take on the pseudo-code for this implementation. Subject to change as I proceed.

Pseudo-Code for Roombarr

<functionName> - Function that performs a specific task

  1. Load Configuration

    • Read configuration file or source <loadConfig>
    • For each list in the configuration:
      • Calculate key <provider.computeListKey>
      • Check if Radarr tag with key exists <fetchAllRadarrTags>
      • If not, create tag in Radarr <createRadarrTag>
      • Check if Radarr import list with key exists <fetchAllRadarrLists>
      • If not, create import list in Radarr <createRadarrList>
  2. Fetch All Movies from Radarr <fetchAllRadarrMovies>

  3. Process Each List

    • For each list in the configuration:
      • Calculate key <provider.computeListKey>
      • Filter movies from Radarr that are tagged with a tag with the same name as the key
      • Get the current import list of the list <provider.fetchListMovies>
      • Determine orphaned movies by subtracting the import list movies from the filtered movies
  4. Handle Orphaned Movies

    • For each orphaned movie:
      • Check if the movie has other tags associated with it
      • If yes:
        • Remove the tag associated with the current list from the movie <removeRadarrTag>
        • Send a notification informing the user that the tag was removed but the movie was not deleted as it is still on other lists <sendNotification>
      • If no other tags:
        • Check if the notification date is today
        • If yes, send warning notification <sendNotification>
        • Check if the deletion date is today
        • If yes
          • Delete the movie from Radarr <deleteRadarrMovie>
          • Send confirmation notification <sendNotification>
jacksonblankenship commented 1 month ago

During implementation, it became clear that handling the creation and management of import lists directly from our side presents significant challenges. The configuration of import lists in Radarr involves a variety of user preferences that are complex to address without a full-blown user interface. Given the complexity and our current constraints, it is not practical to develop a UI for this purpose.

To streamline the process and avoid unnecessary complications, we are adjusting the approach for integrating Roombarr with Radarr. Users will now set up their own import lists in Radarr, allowing them to tailor these lists according to their specific needs. Roombarr will then monitor these lists based on their names, which simplifies the integration and reduces the need for extensive configuration on our end.

Here's how the revised process works:

  1. Onboarding and Configuration Validation

    • Check for Roombarr Tag:
      • Endpoint: GET /api/v3/tag
      • Verify if the "Roombarr" tag exists.
      • If it doesn't exist, create the "Roombarr" tag.
      • Endpoint: POST /api/v3/tag
    • Validate Configured Lists:
      • Endpoint: GET /api/v3/importlist
      • Check if each list specified in the application configuration exists.
      • If any list does not exist, exit the application with an error.
    • Associate Roombarr Tag with Lists:
      • Endpoint: GET /api/v3/importlist
      • For each list in the configuration, ensure it has the "Roombarr" tag.
      • If a list does not have the "Roombarr" tag, add it.
      • Endpoint: PUT /api/v3/importlist/{id} (Modify the list to include the Roombarr tag)
    • Remove Roombarr Tag from Unconfigured Lists:
      • Endpoint: GET /api/v3/importlist
      • Identify lists in Radarr that are not in the current configuration but have the "Roombarr" tag.
      • Remove the "Roombarr" tag from these lists.
      • Endpoint: PUT /api/v3/importlist/{id} (Modify the list to remove the Roombarr tag)
  2. Data Retrieval from Radarr

    • Get Import List Movies:
      • Endpoint: GET /api/v3/importlist/movie
      • Fetch the list of movies associated with all import lists.
    • Get All Movies:
      • Endpoint: GET /api/v3/movie
      • Retrieve all movies from Radarr.
  3. Filtering and Processing

    • Filter Import List Movies:
      • From the list of movies associated with import lists, filter down to only those movies that belong to lists specified in the configuration.
    • Filter Movies by Roombarr Tag:
      • From the list of all movies, filter down to those that have the "Roombarr" tag.
    • Determine Orphaned Movies:
      • Identify movies that are tagged with "Roombarr" but are not associated with any of the monitored lists (i.e., movies in the filtered list from Radarr but not in the filtered import list).
  4. Handle Orphaned Movies

    • For Each Orphaned Movie:
      • Check Notification Date:
      • If today is the date for a notification (5 days before deletion), send a notification to inform the user about the impending deletion.
      • Check Deletion Date:
      • If today is the deletion date (30 days after falling off the list):
        • Check if the Movie has Other Tags:
        • Determine if the movie has tags other than "Roombarr."
        • If there are other tags:
          • Remove the "Roombarr" tag from the movie.
          • Endpoint: PUT /api/v3/movie/{id} (Modify the movie to remove the Roombarr tag)
          • Send a notification informing the user that the "Roombarr" tag was removed but the movie was not deleted.
        • If no other tags:
          • Delete the Movie:
          • Delete the movie from Radarr.
            • Endpoint: DELETE /api/v3/movie/{id}
          • Send a confirmation notification that the movie was deleted.

Summary

jacksonblankenship commented 1 month ago

Issue with Date Calculation and Media Deletion

Summary:

The current approach mistakenly uses the media's "added" date to calculate deletion timing, which does not align with our goal of deleting media based on how long it has been off the import list. This results in unintended behavior:

  1. Minimum Time on Server: Media may stay on the server for a minimum period based on its "added" date, rather than being deleted after a certain period off the list (e.g., 30 days). This is not the intended behavior.

  2. Lack of Notification for Long-standing Media: Media that has been off the list for a long time may be deleted without prior notification if it has been on the server for longer than the minimum time. This bypasses the intended notification process.

Proposed Solution:

  1. File-Based State Tracking:

    • Use a JSON file to track the state of import lists and recently deleted media. This avoids the need for a database and simplifies state persistence.
  2. Tracking and Management Process:

    • Fetch Current List: Retrieve the current import list of movies each time the script runs.
    • Compare Lists: Compare the current list with the previous state to identify movies that have fallen off.
    • Manage Recently Deleted: Track movies that have recently fallen off and those that have reappeared to update their status.
  3. Date-Based Actions:

    • Notification: Send notifications for movies approaching their deletion date (e.g., 5 days before).
    • Deletion: Delete movies that have been off the list for the full retention period (e.g., 30 days) and respect the notification schedule.

This approach will ensure that media management aligns with our intended behavior, providing accurate notifications and deletions based on the import list status.