sonarr-radarr-lidarr-autosearch-browser-extension icon indicating copy to clipboard operation
sonarr-radarr-lidarr-autosearch-browser-extension copied to clipboard

Radarr API integration

Open aommm opened this issue 3 years ago • 13 comments

Hi!

I'd be interested in contributing to a Radarr API integration (I noticed the github project). Just wanted to check a few things with you before starting:

  1. How come "Only possible on IMDb and TMDb"?
  2. Is there anything else I should know before starting to hack on this? Have you done any prior work on this?
  3. Do you have any thoughts about how the UI should look?

Regarding the UI, one idea is to do both of these: a) Different icons based on availability (e.g. overlay the current icon with ✅ / ❌ once the API call completes) b) Add a dialog that is shown on icon hover, that contains more info & actions

Example screenshots to illustrate b) (disclaimer: I am not a UI designer 😅) image image image

My current plan:

  1. Add Radarr API settings (api key)
  2. Add Radarr "does this exist" functionality (perhaps only illustrated by icon for now)

Curious to hear your feedback and thoughts!

aommm avatar Jan 16 '21 12:01 aommm

Hi 😃

The note in the project you referenced discusses adding items to Sonarr or Radarr via their API. There were also a couple of other things I thought of doing, although I'm unsure if they're possible without further analysis:

  1. Get the Sonarr, Radarr or Lidarr version to set the advanced settings (for search box selector, etc) to make the extension simpler to set up.
  2. Show whether the film/tv show/etc already exists in Sonarr/Radarr/Lidarr.

I think there are 2 main things to consider before implementing any new feature:

  1. The feature should work across all versions of Sonarr/Radarr/Lidarr, or be able to be configured to do so.
  2. Complex functionality should be optional and off by default. I want users to be able to install the extension and not worry about having to configure API integrations, etc if they don't want to.

It's likely not everyone is up to date with versions. For example, I'm currently using Radarr v0.2.0.1504 and Sonarr v2.0.0.5344. This is because I run these on my NAS and am limited by the available versions in the community store for the NAS OS. For every new integration (e.g. Plex), compatibility between versions should also be considered and catered for where required.

To answer your points:

  1. In order to add items to an integration you would need to know the exact item to add, and that wouldn't be possible with a text search; only with an IMDb, TVDb or TMDb id (or MusicBrainz id for Lidarr). It may be possible to call the API, do a search, show a list of options and then allow one to be selected and sent back to the API, but this seems needlessly complex when you can just click through to a search on the integration.
  2. Only what I have previously mentioned; i.e. version compatibility, making more complex functionality optional, and being limited to integrations where an item can be referenced by an id.
  3. To add more functionality to the icon that is added to a website, I liked the idea of adapting one of these circle menu effects to show info or give options: https://onaircode.com/css-circle-menu-examples/

The only other thing to add at this point is that I need to merge branch: https://github.com/trossr32/sonarr-radarr-lidarr-autosearch-browser-extension/tree/20210112-search-by-ids into master at some point. This branch contains changes to search Sonarr and Radarr by the ids I mentioned above, and also changes some of the search functionality to use regex expressions as I think it's a lot cleaner. I'll update this ticket when I've fully tested these changes and am ready to merge.

I'm going to take some time to do some testing against the APIs to see what is there in various versions and what can and can't be done. I'll consider all the changes that will be required to get this implemented and then put a roadmap together.

Really appreciate you helping with this!

trossr32 avatar Jan 16 '21 23:01 trossr32

Thanks for the detailed answer! Agree with your priorities and principles (1. compatibility and 2. ease-of-use/"good defaults"). Then I'll hold off for a while, but I'll gladly help once we have a more concrete roadmap 🙂

aommm avatar Jan 17 '21 10:01 aommm

Further info

This comment will be updated for a while as more analysis is performed.

Postman API testing

I've set up Postman collections for Radarr and Sonarr and tested all endpoints (except POSTs) against the detailed versions. APIs seem to be unified across versions which is great news:

postman.collections.zip

Notes on API integration

API key, quality profile and destination folder (directory where the series or movie will be stored) will need to be set in settings for an implementation. First set API key. Call API and get quality profiles. Set one of the returned profiles as the default. The alternative is to show quality profiles each time an add needs to be actioned. (This should probably happen if the returned quality profiles at the point of creating an add don't contain the selected default? i.e. if a profile has been removed since it was set as the default) Get all movies/shows and can then derive destination folder from the first instance ('path' less the 'titleSlug').

NOTE: When performing a lookup if the movie exists in Radarr or Sonarr there's no way of telling from the response, so will need to batch get all movies/shows and find in the response.

Resource links:

https://www.reddit.com/r/radarr/comments/76w2pi/adding_movie_via_api/ https://www.reddit.com/r/radarr/comments/6figzu/help_adding_movies_via_the_api/ https://onaircode.com/css-circle-menu-examples/ https://radarr.video/docs/api/ https://github.com/Sonarr/Sonarr/wiki/API https://github.com/lidarr/Lidarr/wiki/API

Potential workflow

if it's an integration/implementation that uses id:
    . check we have an API key.
    . check a quality profile has been configured.
    . check a destination folder has been configured.
    if all true:
        . call implementation API and get all quality profiles.
        if quality profile in settings exists in returned profiles:
            . call implementation API and get all movies/shows.
            if valid response:
                . check if currently viewed movie/show exists in response.
                    if true:
                        . show already in implementation via icon. 
                        . change link to go to the page in the implementation (titleslug in response)
                    if false:
                        . call implementation API lookup endpoint with id.
                            if successful and 1 item in response:
                                . change icon to perform add functionality and build post request

Todo

  • [ ] Add Lidarr API versions to the Postman collections and test features available
  • [ ] Options page UI design for required settings
  • [ ] Consider using the API integration to just default the advanced settings based on the integration version as a nice start off ticket.
  • [ ] Look at all website sources and see if useful ids are present (as pointed about by @aommm regarding letterboxd)
  • [ ] Test UI design for turning the embedded icon into an animated menu/info control

trossr32 avatar Jan 17 '21 16:01 trossr32

I hacked together some changes to the settings page in my PR above:

[X] Options page UI design for required settings [X] Consider using the API integration to just default the advanced settings based on the integration version as a nice start off ticket.

This is what it looks like now, and it's functional: image (have only tested with Firefox, Radarr v3, and not Lidarr/Sonarr)

I don't think my code is very useful though, it's kind of messy. 😅

In my UI design, I introduced a bunch of dependencies between different settings (API key, API status, "Fetch from API" links). Example of dependencies: "refresh" link depends on API key value, "Fetch from API" link depends on API status & API version.

The current code structure for the settings page is minimalistic, and doesn't make it easy to express these kind of dependencies. Nevertheless I tried, and kind of went overboard and created my own jquery witch brew state management system.

Learning: if we want cleaner code for the settings page, I think we will have to:

  • Scrap the "Save" buttons
  • Introduce some system that helps us manage state & re-rendering (I know React, but there are others)

Next steps:

Would appreciate feedback on my POC. What do you think about the UI design? What are your thoughts for structuring the settings page code-wise? Should we rewrite it, or is my POC with explicit dependencies everywhere good enough?

aommm avatar Jan 22 '21 23:01 aommm

This is great, thanks. I'll have a proper look through and integrate it into the changes I'm working on at the moment. I think the API key (and maybe all settings) should be on the main options page rather than the advanced page? I'll get back to you soon 😃

trossr32 avatar Jan 22 '21 23:01 trossr32

I also agree with you regarding the save button; I'm working on saving every input as it's done so it's all saved in real time

trossr32 avatar Jan 22 '21 23:01 trossr32

I just saw your changes as well, seems like great minds think alike? 😄

I think your design makes more sense with the API key on the main settings. And please feel free to look through my code and harvest anything that could be useful!

aommm avatar Jan 22 '21 23:01 aommm

We might also have to think a bit about the state management...

Random musings: Do we want one object to be the source of truth for all the settings state? So e.g. on every keypress, should we write to the object? If the state object changes, how do we make sure to re-render appropriate parts of the UI? The state object could also change "from without", e.g. by an API call returning. We might need to re-render the UI when this happens.

Probably you are thinking a bit about this when you're working on the real-time save. Looking forward to see your ideas :)

aommm avatar Jan 22 '21 23:01 aommm

Just stumbled onto this add-on, thank you. Did you ever make any progress with direct adding movies from IMDb through the API?

My intended purpose was getting this add-on for my wife, and then she could add movies to be downloaded without the need to log in to Radarr.

Rouzax avatar Aug 18 '21 16:08 Rouzax

@Rouzax I haven't done anything further with this yet. It's a pretty big project but I have a few weeks off work at the beginning of September so will likely take some time to do some development on this extension, as there's some more integrations I need to get done too. I'll take another look in a few weeks and keep this issue updated with progress. Thanks for chasing, keeps me motivated 😄

trossr32 avatar Aug 18 '21 17:08 trossr32

Not chasing 😀, just curious.

Rouzax avatar Aug 18 '21 18:08 Rouzax

What is the reason that you currently need the API key for Radarr? That isn't really leveraged for anything at the moment.

Rouzax avatar Aug 30 '21 18:08 Rouzax

What is the reason that you currently need the API key for Radarr? That isn't really leveraged for anything at the moment.

@Rouzax There's no need for the API key as such; all it does is retrieve the current Radarr version and apply the correct settings accordingly.

trossr32 avatar Aug 30 '21 20:08 trossr32

Again just curious if you made some progress on this?

Rouzax avatar Nov 24 '22 09:11 Rouzax

Closing as I can't really see a benefit of this, especially given the amount of work, the difficulty with supporting multiple API versions and the servarr apis being so changeable.

trossr32 avatar Mar 04 '23 17:03 trossr32