Support negative indices with --range and --chapter-range (#5402)
It seems it wasnt possible to download just the last pages of each chapter. I have looked through the code and the main difficulty is that _kwdict["count"] is not always defined if the chapter extractor is returning an iterator rather than a list. If that is the case, it will treat -n:-m as (0,sys.maxsize).
If you want I can cache some of the results rather than recalculating them on each call.
Fixes #5402
I suppose it might have been possible to do this with filter predicates by using page and count.
Another problem is that count does not always represent the total number of files. For other sites, e.g. Twitter / Instagram / anything with posts, it is used for the number of files per post.
It also doesn't work for --chapter-range, as it might represent the count value of the current chapter and not the total number of chapters.
We should introduce a new field that either holds the total number of files / items (total, count_total ?) or a boolean value indicating if count can be used as total number of items.