Repository navigation
Expand file tree
/
Copy pathspotify_transcript.py
More file actions
64 lines (52 loc) · 2.28 KB
/
Copy pathspotify_transcript.py
File metadata and controls
64 lines (52 loc) · 2.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import requests
import json
CLIENT_ID = "7fb1be85577a44a99036ae5afeded772"
CLIENT_SECRET = "fc05d3027d754b149c8d8d82aca9daee"
EPISODE_ID = "6FfOT7TDLNzdD1M81SChga"
def get_access_token():
url = "https://accounts.spotify.com/api/token"
resp = requests.post(url, data={
"grant_type": "client_credentials",
"client_id": CLIENT_ID,
"client_secret": CLIENT_SECRET,
})
resp.raise_for_status()
return resp.json()["access_token"]
def get_episode_info(token, episode_id):
url = f"https://api.spotify.com/v1/episodes/{episode_id}"
resp = requests.get(url, headers={"Authorization": f"Bearer {token}"})
resp.raise_for_status()
return resp.json()
def main():
print("Authenticating with Spotify...")
token = get_access_token()
print("Fetching episode info...")
episode = get_episode_info(token, EPISODE_ID)
print(f"\nPodcast: {episode['show']['name']}")
print(f"Episode: {episode['name']}")
print(f"Duration: {episode['duration_ms'] // 60000} min")
print(f"Description: {episode['description'][:300]}")
print(f"Release: {episode['release_date']}")
print(f"Audio Preview URL: {episode.get('audio_preview_url', 'N/A')}")
# Try undocumented transcript endpoint
print("\nAttempting to fetch transcript...")
transcript_url = f"https://spclient.wg.spotify.com/transcript-read-along/v2/episode/{EPISODE_ID}"
resp = requests.get(transcript_url, headers={"Authorization": f"Bearer {token}"})
if resp.status_code == 200:
data = resp.json()
print("Transcript found!\n")
if "section" in data:
for section in data["section"]:
for line in section.get("startMs", []):
print(line.get("words", ""))
else:
print(json.dumps(data, indent=2, ensure_ascii=False))
else:
print(f"Transcript not available via this method (status {resp.status_code})")
print("\nSpotify does not expose transcripts through the public Web API.")
print("Alternatives:")
print(" 1. If the podcast is on YouTube, we can grab the transcript there")
print(" 2. Download the audio and use Whisper for speech-to-text")
print(" 3. Check the podcast's website for published transcripts")
if __name__ == "__main__":
main()