Closed roidy closed 1 year ago
Yeah the pagination is an issue because TMDb pre-paginates discover you can't really get random items. Trakt lists you can get random items though - so you could use MDbList https://mdblist.com/ to generate an automated list using a set of rules and then randomise it in TMDbHelper.
I should be able to add a random page option for discover. The main problem there will be if the random page number selected doesn't exist. We won't know how many pages there are in advance, so won't know how wide to set the randomised range.
I should be able to add a random page option for discover. The main problem there will be if the random page number selected doesn't exist. We won't know how many pages there are in advance, so won't know how wide to set the randomised range.
The api returns total_pages with the results, so just an idea could it be done with two api calls one to get the total_pages then one to return a random page?
Have to get a page to get total_pages, so may as well try to get a random page first go.
I was more thinking from the skin side you'd want to be able to set the range since true randomisation of pages will give bad results - e.g. probably aren't going to want to get page 100 when default sorting is popularity because that's going to be all the crap that no one wants to watch. Skin would have to guess a bit at what will be an acceptable range to randomise.
I was more thinking from the skin side you'd want to be able to set the range since true randomisation of pages will give bad results - e.g. probably aren't going to want to get page 100 when default sorting is popularity because that's going to be all the crap that no one wants to watch. Skin would have to guess a bit at what will be an acceptable range to randomise.
Yep, that makes sense. I mainly want a way to fill a widget with content from a watch provider and not have it show the same 20 items just in a random order every time.
Any update on this?
@roidy any reason you closed this? I was going to add it - just hadn't quite got to it yet.
After 2 weeks with out a response I didn't think it was going anywhere. So instead of keep bugging you I just closed it. It doesn't need to be open for it to be added does it?
^^^ That'll give page randomisation options for standard TMDb lists (e.g. discover, popular, trending etc.)
&page=random
will pick a random page between 1-10
Optionally can specify the range with &random_page_start=1&random_page_end=10
but probably the default range of 10 pages is enough. If you combine it with Kodi's sortby="random" content tag, it feels like a fairly decent approximation of true randomisation (it is 200 items afterall).
I'll add some checks for the total_pages later to make sure it doesn't go past the upper limit.
Just tested and that works really nice.
I think ten pages is more that enough to keep the content looking random enough to be interesting.
Massive thanks 👍
No problem!
Turns out if you get a page outside of the total_pages range then you get no response at all. So only way to get total_pages is to request the first page. Not sure if it is worth the extra overhead of getting an extra page just to check.
Let's see how it goes without an upper limit check. If you find it is a problem, let me know and I can add a check for it. I think probably though majority of the time would get away without one though.
You also can't request a page greater than 500. Not that you'd want one that high anyway.
Would a solution be to grab a page in the range 1-10 then if it returns nothing just try again with a lower upper limit eg 1-5
Turns out if you get a page outside of the total_pages range then you get no response at all. So only way to get total_pages is to request the first page. Not sure if it is worth the extra overhead of getting an extra page just to check.
Umm... I've just checked and while getting a page outside the max range does return no results it will return the number of pages. So requesting the first page isn't the only way to get the total number of pages.
https://api.themoviedb.org/3/discover/movie?api_key=xxxxxxxxx&sort_by=title&page=9&with_people=287
returns:-
{
"page": 9,
"results": [],
"total_pages": 8,
"total_results": 143
}
You also can't request a page greater than 500
Turns out that's the issue I had. Was trying to get a something like page 800.
API docs specify the page limit is 1000... but I'm pretty sure you're right, the limit appears actually to be 500.
Yep, if you request any page over 500 you get the following reponse:-
https://api.themoviedb.org/3/discover/movie?api_key=xxxxxxxx&page=501
{
"errors": [
"page must be less than or equal to 500"
]
}
^^^ That should work.
Also swapped random_page_start|end=
with a single random_page_limit=
param as I'm not sure if there's much benefit to controlling the start page.
Yep, that works great. After multiple tests on an end point that I know has less than 10 pages it always return a valid page of results.
Agreed, I can't think of a situation were you'd want to start at anything other than the first page.
Thanks 👍
If I fill a list with content from a provider and set the kodi list sort method to random I only get the first page of items in a random order. Is there a way to get random items from the entire provider and not just page 1, in fact can it be done from any paginated list? I'm guessing no due to the way the data is paginated.
Failing that is there a way to get data from a random page every time instead of the first one?
For instance:- plugin://plugin.video.themoviedb.helper/?info=discover&tmdb_type=tv&with_watch_providers=8&watch_region=US&with_id=True&widget=true&page=random