I’m having trouble getting podcast episode details through the Spotify Web API. When I fetch current playback info, songs work fine but podcast episodes always return null for the item field.
Here’s what I’m working with:
def fetch_playing_content():
if current_time() > token_expires:
print("Token needs refresh...")
update_token()
if not auth_token:
print("Token refresh failed.")
return None, None, None, 0, 0
auth_headers = {"Authorization": f"Bearer {auth_token}"}
api_response = requests.get("https://api.spotify.com/v1/me/player", headers=auth_headers)
if api_response.status_code == 200:
player_data = api_response.json()
if player_data and player_data['is_playing']:
content_type = player_data.get('currently_playing_type')
current_item = player_data.get('item')
if content_type == 'track' and current_item:
song_id = current_item['id']
song_title = current_item['name']
performer = current_item['artists'][0]['name']
current_pos = player_data['progress_ms']
total_length = current_item['duration_ms']
return song_id, song_title, performer, current_pos, total_length
elif content_type == 'episode':
if current_item and 'id' in current_item:
ep_id = current_item['id']
else:
ctx = player_data.get('context')
if ctx and 'uri' in ctx:
ctx_uri = ctx['uri']
if 'episode' in ctx_uri:
ep_id = ctx_uri.split(':')[-1]
else:
return None, None, None, 0, 0
else:
return None, None, None, 0, 0
ep_response = requests.get(f"https://api.spotify.com/v1/episodes/{ep_id}", headers=auth_headers)
if ep_response.status_code == 200:
ep_data = ep_response.json()
ep_title = ep_data['name']
show_creator = ep_data['show']['publisher']
current_pos = player_data['progress_ms']
total_length = ep_data['duration_ms']
return ep_id, ep_title, show_creator, current_pos, total_length
return None, None, None, 0, 0
Anyone found a solution for this issue?