Skip to content

Commit

Permalink
Adds episodeByGuid (#9)
Browse files Browse the repository at this point in the history
* Adds episodebyguid

- changes the test data from this american life to lex because it was failing for every test

* Adds podcastguid as an optional required arg
  • Loading branch information
dbellotti authored Feb 24, 2024
1 parent 63fdb84 commit ee9007f
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 5 deletions.
46 changes: 46 additions & 0 deletions podcastindex/podcastindex.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,52 @@ def episodeById(self, id, fulltext=False):
# Call Api for result
return self._make_request_get_result_helper(url, payload)

def episodeByGuid(
self, guid, feedurl=None, feedid=None, podcastguid=None, fulltext=False
):
"""
Lookup episode by guid.
Args:
guid (string): Episode GUID.
feedurl (string): The feed's url.
feedid (string or integer): Podcast index internal ID.
podcastguid (string): The GUID of the podcast to search within.
fulltext (bool): Return full text in the text fields. Default: False
*guid and at least one of feedurl or feedid must be specified.
Raises:
requests.exceptions.HTTPError: When the status code is not OK.
requests.exceptions.ReadTimeout: When the request times out.
Returns:
Dict: API response
"""
if not guid:
raise ValueError("guid must not be None or empty")
if not (feedurl or feedid or podcastguid):
raise ValueError(
"At least one of feedurl or feedid or podcastguid must not be None or empty"
)

# Setup request
url = self.base_url + "/episodes/byguid"

# Setup payload
payload = {"guid": guid}
if feedurl:
payload["feedurl"] = feedurl
if feedid:
payload["feedid"] = feedid
if podcastguid:
payload["podcastguid"] = podcastguid
if fulltext:
payload["fulltext"] = True

# Call Api for result
return self._make_request_get_result_helper(url, payload)

def episodesByPerson(self, query, clean=False, fulltext=False):
"""
Returns all of the episodes where the specified person is mentioned.
Expand Down
40 changes: 35 additions & 5 deletions tests/test_episode_lookup.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import logging

import podcastindex
import pytest
import requests

import podcastindex

logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger()

feedUrl = "http://feed.thisamericanlife.org/talpodcast"
feedId = 522613
itunesId = 201671138
feedUrl = "https://lexfridman.com/feed/podcast/"
feedId = 745287
itunesId = 1434243584
badItunesId = "abcdefg1234"


Expand Down Expand Up @@ -77,4 +78,33 @@ def test_episode_lookup_by_id():
latest_episode_id = results["items"][0]["id"]

results = index.episodeById(latest_episode_id)
assert results["episode"]["id"] == latest_episode_id, "Episode fetched by ID should match ID used in query"
assert (
results["episode"]["id"] == latest_episode_id
), "Episode fetched by ID should match ID used in query"


def test_episode_lookup_by_guid():
config = podcastindex.get_config_from_env()
index = podcastindex.init(config)

results = index.episodesByFeedUrl(feedUrl)
latest_episode_guid = results["items"][0]["guid"]

results = index.episodeByGuid(latest_episode_guid, feedUrl)
assert (
results["episode"]["guid"] == latest_episode_guid
), "Episode fetched by GUID and FEEDURL should match GUID used in query"

results = index.episodeByGuid(
latest_episode_guid, feedid=results["episode"]["feedId"]
)
assert (
results["episode"]["guid"] == latest_episode_guid
), "Episode fetched by GUID and FEEDID should match GUID used in query"

results = index.episodeByGuid(
latest_episode_guid, podcastguid=results["episode"]["podcastGuid"]
)
assert (
results["episode"]["guid"] == latest_episode_guid
), "Episode fetched by GUID and PODCASTGUID should match GUID used in query"

0 comments on commit ee9007f

Please sign in to comment.