Properly offset media listing

This commit is contained in:
Ruud
2014-03-07 15:44:09 +01:00
parent 8a295c72ba
commit 527d6ab7ff
+6 -4
View File
@@ -197,19 +197,21 @@ class MediaPlugin(MediaBase):
if total_count == 0:
return 0, []
offset = 0
limit = -1
if limit_offset:
splt = splitString(limit_offset) if isinstance(limit_offset, (str, unicode)) else limit_offset
limit = tryInt(splt[0])
offset = tryInt(0 if len(splt) is 1 else splt[1])
start = offset * limit
end = start + limit
media_ids = media_ids[start:end]
# List movies based on title order
medias = []
for m in db.all('media_title'):
media_id = m['_id']
if media_id not in media_ids: continue
if offset > 0:
offset -= 1
continue
media = db.run('media', 'to_dict', media_id)
@@ -220,7 +222,7 @@ class MediaPlugin(MediaBase):
# remove from media ids
media_ids.remove(media_id)
if len(media_ids) == 0: break
if len(media_ids) == 0 or len(medias) == limit: break
return total_count, medias