mProjectsCode / obsidian-media-db-plugin

A plugin that can query multiple APIs for movies, series, anime, games, music and wiki articles, and import them into your vault.
GNU General Public License v3.0
243 stars 28 forks source link

Adding options to disable certain API per media type #133

Closed ltctceplrm closed 5 months ago

ltctceplrm commented 7 months ago

The code is currently not yet functional because I don't know how to get the MediaType so I can add it to the API name. To test if the rest of the code works I modified this line

const apiSettings = [api.apiName, MediaTypeModel].filter(s => s).join('') as keyof typeof this.plugin.settings;
const apiSettings = [api.apiName, "game"].filter(s => s).join('') as keyof typeof this.plugin.settings;

And it correctly filters out the APIs that are not checked. Same works for moviesor series.

@mProjectsCode is there a way to get the media type after it calls APIManager?

ltctceplrm commented 7 months ago

I've added a mediaType variable that gets sent with the search query so adding media by media type is currently functional. I still need to fix the advanced APIsearch since that one is broken API's that you can turn off, I think I went wrong somewhere with the API = default check

ltctceplrm commented 7 months ago

@mProjectsCode I found the mistake I mentioned and simplified the code by removing the whole "default" API setting, now Advanced Search and Media Type Search both work correctly! I'm looking through your notes now and seeing what I need to change

ltctceplrm commented 7 months ago

I reverted changes to main.ts so the this.apiManager.query method is left alone and instead modified hasType in APIModel.ts to check whether the API is turned on or not for the media type.

I've tested it out and it correctly skips the disabled APIs when selecting only 1 media type, however if you select multiple media types (movies and games) where the same API (omdb) has been turned off for one media type (movies) but not for another media type (games) then it will still return movies as well as games for omdb. I'm not sure if this is wanted/intentional or not.

ltctceplrm commented 7 months ago

Seeing as the plugin is simultaneously searching for games and movies I don't see how it would be possible to exclude just the games returned by omdb without really overcomplicating the code. Unless I'm missing an easy solution I'd suggest maybe only being able to toggle one media type at a time and if you toggle a second one it un-toggles the previous one?

ltctceplrm commented 7 months ago

I pushed too soon, there's still a mistake in my toggle thingy

ltctceplrm commented 7 months ago

Okay it's fixed now

ltctceplrm commented 6 months ago

Please let me know if I should change anything else or if it's good like this

mProjectsCode commented 6 months ago

I am currently quite busy, I will review this maybe next week.

ltctceplrm commented 6 months ago

That's okay, please take your time. Thank you for looking into it.

ltctceplrm commented 6 months ago

Thank you for looking over the code. I'm going to address some of the problems right now and the other ones I'll probably get to tomorrow.

ltctceplrm commented 5 months ago

Hello @mProjectsCode, I finally succeeded turning the API toggles into sub objects like you asked, the code additions are once again fully functional (at least according to my tests). I believe I have finished with this pull request but please let me know if I forgot something

mProjectsCode commented 5 months ago

I will just merge this and then make some changes myself

ltctceplrm commented 5 months ago

That's great, thank you merging and also fixing up the code.