Stremio / stremio-addon-sdk

🧙 A Node.js SDK for creating and publishing Stremio add-ons
https://www.stremio.com/addon-sdk
MIT License
676 stars 180 forks source link

Help with UserSettings #182

Closed michalss closed 2 years ago

michalss commented 2 years ago

HI, I was able to replicate most of functions from our kodi plugin however i need to be able to do some user settings and save login data somewhere, somehow, at least. Im having very hard time to understand how to do this kind of settings. Can you please give me some sample, how to do this please? it is very difficult to work with settings in streamio :(.

Regards

jaruba commented 2 years ago

@michalss the addon sdk itself does not support settings, but the addon protocol does

the first things that you should know of are manifest.behaviorHints.configurable and manifest.behaviorHints.configurationRequired, see: https://github.com/Stremio/stremio-addon-sdk/blob/master/docs/api/responses/manifest.md#other-metadata

(you should ignore the configurableTV property, as it is not valid yet)

setting manifest.behaviorHints.configurable to true, will show a configure button next to the install button in the apps

if you also set manifest.behaviorHints.configurationRequired to true, will show ONLY a configure button in the apps (without showing any install button)

pressing the "configure" button will take the user to the /configure URL path of your addon server, so presuming that ur addon manifest URL would be https://my.addon.com/manifest.json, the users will be sent to https://my.addon.com/configure, so this is where a HTML configuration page should be available

on the configuration page, you should ask users for any additional data you need, let's presume that your configuration page requires an api key and a username, let's say that a user inserts api key ja189tg and his username is jaruba, you will need to add these values to the addon url, so the install button in this case, after the user filled the fields, should be changed to point to stremio://my.addon.com/ja189tg/jaruba/manifest.json, so the user chosen data will always be sent through the URL for all addon requests (the stremio:// protocol is supported in both Desktop and Android Mobile, opening such a link will open the app with a pop-up to install the addon from that manifest URL)

there are various examples of apps that use configuration pages, you can check this addon, for example: https://github.com/jaruba/stremio-imdb-watchlist/blob/master/index.js

michalss commented 2 years ago

Uff this is very bad way to doing it and it seems to me this would be blocker for us :( Btw i did checked this examples but it does not make much sense to me :( .

Anyway thx for help. I guess i might leave it alone for now, until streamio implement some kind of user settings..

michalss commented 2 years ago

Hmm ok did figure this out kind of. But how can i run serveHTTP(builder.getInterface(), { port: 7000 }) to make sure i gets /username/ as parameter. it always gives me http://ip:port/manifest.json but i need to have it like http://ip:port/:username/manifest.json

michalss commented 2 years ago

i did not find any example using sdk only express and i dont want to realy use extress

image

michalss commented 2 years ago

i know there i planty of examples to use exress but i wrote it all with sdk and dont want to really change it now :(

jaruba commented 2 years ago

Uff this is very bad way to doing it

I would disagree, it gives maximum flexibility to addon developers, and it is easier than it seems on first sight

I guess i might leave it alone for now, until streamio implement some kind of user settings..

This is the official way that Stremio handles addon settings, there is no plan to change this anytime soon

i did not find any example using sdk

There is none, as i mentioned in the first comment, the sdk does not support this, only the addon protocol does (which would need express or any other http server module), but you would also need express to do what you said in your other issue too: https://github.com/Stremio/stremio-addon-sdk/issues/180

The Addon SDK can handle most cases, but not all of them, it's best to use express for the things you (in particular) need.

i know there i planty of examples to use exress but i wrote it all with sdk and dont want to really change it now :(

it is not that hard to change, all responses will be the same, only the router code needs to change

jaruba commented 2 years ago

These two addons, for example, do the same thing (one uses express, one uses the sdk):

Check the /addon.js and /index.js files of these repos.

michalss commented 2 years ago

O thx, so to use UserSettings im force to use express way only. It is very unfortunate that in sdk is not possible to do the same thing :(. . Anyway ill try to rewrite it to express, but to be honest i would proffer to use sdk instead..

michalss commented 2 years ago

@jaruba HI is there any metahandler endpoint in express version pls ?

jaruba commented 2 years ago

@michalss this is the addon protocol specification with all endpoints: https://github.com/Stremio/stremio-addon-sdk/blob/master/docs/protocol.md#stremio-addon-protocol

jaruba commented 2 years ago

@michalss here is the metadata request for an addon, using a language chosen by the user: https://github.com/mrcanelas/tmdb-addon/blob/b23aa879429ffaaf238c1b28626beb0de2e0ea29/index.js#L77

michalss commented 2 years ago

hmm thx really help me. Starting to working as i would like to :D However getting error with express with streams.. cannot play them image

Checked the url and vlc player has no issue with it, Try many different urls, Still the same.. With SDK it works just fine..

michalss commented 2 years ago

Any idea where to look pls ? Its actualy happend with any pluing. Is there any log or something. How to fix this ?

michalss commented 2 years ago

OK it seems i figure it everything for now. Just dont know to make userdata pernament, every reset user settings are gone ? @jaruba Thx

michalss commented 2 years ago

Thank you a lot to @jaruba, very nice and helpful person.