Skip to content

Commit

Permalink
Merge pull request #40 from jhogervorst/fetch-all-episodes
Browse files Browse the repository at this point in the history
Fetch all episodes to get full history
  • Loading branch information
ThijsRay authored May 13, 2024
2 parents 4773d01 + 186234b commit 7c98c69
Showing 1 changed file with 27 additions and 12 deletions.
39 changes: 27 additions & 12 deletions podimo/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,19 +206,34 @@ async def getPodcasts(self, podcast_id, scraper):
}
}
"""
variables = {
"podcastId": podcast_id,
"limit": 100,
"offset": 0,
"sorting": "PUBLISHED_DESCENDING",
}
result = await self.post(headers, query, variables, scraper)
# podcastName = result[0]['podcastName']
podcastName = self.getPodcastName(result)
logging.debug(f"Fetched podcast '{podcastName}' ({podcast_id}) directly")

limit = 100
offset = 0
while True:
variables = {
"podcastId": podcast_id,
"limit": limit,
"offset": offset,
"sorting": "PUBLISHED_DESCENDING",
}
result = await self.post(headers, query, variables, scraper)
if offset == 0:
# podcastName = result[0]['podcastName']
podcastName = self.getPodcastName(result)
logging.debug(f"Fetched podcast '{podcastName}' ({podcast_id}) directly")
fullResult = result
else:
fullResult["episodes"] += result["episodes"]
numEpisodes = len(result["episodes"])
if numEpisodes == limit:
logging.debug(f"Fetched {numEpisodes} episodes; fetching more...")
offset += limit
else:
logging.debug(f"Fetched {numEpisodes} episodes; no more to fetch")
break

insertIntoPodcastCache(podcast_id, result)
return result
insertIntoPodcastCache(podcast_id, fullResult)
return fullResult

def getPodcastName (self, podcast):
return list(podcast.values())[1]["title"]
Expand Down

0 comments on commit 7c98c69

Please sign in to comment.