Skip to content

Commit 91fe4a5

Browse files
Adds pagination support to the plugin
1 parent c6c2a4d commit 91fe4a5

File tree

1 file changed

+21
-12
lines changed

1 file changed

+21
-12
lines changed

src/gpodder/plugins/podverse.py

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
import urllib.parse
2727

2828
logger = logging.getLogger(__name__)
29-
29+
PAGE_SIZE = 20
3030

3131
@registry.directory.register_instance
3232
class PodverseSearchProvider(directory.Provider):
@@ -36,20 +36,29 @@ def __init__(self):
3636
self.priority = directory.Provider.PRIORITY_SECONDARY_SEARCH
3737

3838
def on_search(self, query):
39-
json_url = "https://api.podverse.fm/api/v1/podcast?page=1&searchTitle={}&sort=top-past-week".format(urllib.parse.quote(query))
40-
39+
page = 1
4140
result_data = []
42-
json_data = util.read_json(json_url)[0]
4341

44-
for entry in json_data:
45-
if entry["credentialsRequired"]:
46-
continue
42+
while True:
43+
json_url = "https://api.podverse.fm/api/v1/podcast?page={}&searchTitle={}&sort=top-past-week".format(page, urllib.parse.quote(query))
44+
45+
json_data, entry_count = util.read_json(json_url)
46+
47+
if entry_count > 0:
48+
for entry in json_data:
49+
if entry["credentialsRequired"]:
50+
continue
51+
52+
title = entry["title"]
53+
url = entry["feedUrls"][0]["url"]
54+
image = entry["imageUrl"]
55+
description = entry["description"]
56+
57+
result_data.append(directory.DirectoryEntry(title, url, image, -1, description))
4758

48-
title = entry["title"]
49-
url = entry["feedUrls"][0]["url"]
50-
image = entry["imageUrl"]
51-
description = entry["description"]
59+
if entry_count < PAGE_SIZE:
60+
break
5261

53-
result_data.append(directory.DirectoryEntry(title, url, image, -1, description))
62+
page += 1
5463

5564
return result_data

0 commit comments

Comments
 (0)