Skip to content

Commit

Permalink
✨ (getEpisodeList.ps1): add iframe embedding for episodes
Browse files Browse the repository at this point in the history
Enhance the episode data by including Spotify oEmbed iframes. This
provides a richer user experience by allowing episodes to be embedded
directly on web pages. The script now fetches iframe HTML for each
episode and appends it to the episode data, which is then saved to
JSON. This change facilitates easier integration of episode content
into web applications.
  • Loading branch information
MrHinsh committed Nov 15, 2024
1 parent 8b9c644 commit ed977c5
Show file tree
Hide file tree
Showing 2 changed files with 108 additions and 38 deletions.
102 changes: 75 additions & 27 deletions .powershell/getEpisodeList.ps1
Original file line number Diff line number Diff line change
@@ -1,53 +1,101 @@
# Define your Client ID and Client Secret
$clientId = "1120c6949df54792975a405bbdcaa3bf"
$clientSecret = $Env:SPOTIFY_CLIENT_SECRET
# Define your Spotify Client ID and Client Secret
$spotifyClientId = "1120c6949df54792975a405bbdcaa3bf"
$spotifyClientSecret = $Env:SPOTIFY_CLIENT_SECRET

# Define the token endpoint
$tokenUri = "https://accounts.spotify.com/api/token"
# Define your YouTube Data API Key
$youtubeApiKey = $Env:YOUTUBE_API_KEY

# Prepare the headers
$headers = @{
# Define the YouTube channel ID to restrict searches
$youtubeChannelId = "UCQxOqOLPrgtWJAKJzOgR5uw" # Replace with your desired channel's ID

# Spotify token endpoint
$spotifyTokenUri = "https://accounts.spotify.com/api/token"

# Prepare the headers for Spotify authentication
$spotifyHeaders = @{
"Content-Type" = "application/x-www-form-urlencoded"
}

# Prepare the body
$body = @{
# Prepare the body for Spotify authentication
$spotifyBody = @{
grant_type = "client_credentials"
client_id = $clientId
client_secret = $clientSecret
client_id = $spotifyClientId
client_secret = $spotifyClientSecret
}

# Request Spotify access token
$spotifyResponse = Invoke-RestMethod -Method Post -Uri $spotifyTokenUri -Headers $spotifyHeaders -Body $spotifyBody
$spotifyAccessToken = $spotifyResponse.access_token

# Spotify Show ID
$spotifyShowId = "27PyDccVtzuOWFtB7Qi84q"

# Spotify episodes API endpoint
$spotifyEpisodesUri = "https://api.spotify.com/v1/shows/$spotifyShowId/episodes?limit=50&offset=0"

# Prepare Spotify headers with the access token
$spotifyAuthHeaders = @{
Authorization = "Bearer $spotifyAccessToken"
}

# Send the request to get the access token
$response = Invoke-RestMethod -Method Post -Uri $tokenUri -Headers $headers -Body $body
$accessToken = $response.access_token
# Fetch episodes from Spotify
$spotifyEpisodesResponse = Invoke-RestMethod -Method Get -Uri $spotifyEpisodesUri -Headers $spotifyAuthHeaders
$episodes = $spotifyEpisodesResponse.items

# Define the Spotify Show ID
$showId = "27PyDccVtzuOWFtB7Qi84q"
# Function to fetch the oEmbed iframe for a given Spotify episode URL
function Get-EpisodeIframe {
param (
[string]$episodeUrl
)
$oEmbedApi = "https://open.spotify.com/oembed?url=$episodeUrl"
$oEmbedResponse = Invoke-RestMethod -Method Get -Uri $oEmbedApi
return $oEmbedResponse.html
}

# Set the API endpoint
$episodesUri = "https://api.spotify.com/v1/shows/$showId/episodes?limit=50&offset=0"
# Function to search YouTube for a video matching the episode title within a specific channel and return the video ID
function Get-YouTubeVideoId {
param (
[string]$searchQuery
)
$youtubeSearchApi = "https://www.googleapis.com/youtube/v3/search?part=snippet&type=video&q=$($searchQuery -replace ' ', '+')&channelId=$youtubeChannelId&key=$youtubeApiKey&maxResults=1"
$youtubeResponse = Invoke-RestMethod -Method Get -Uri $youtubeSearchApi

# Prepare the headers with the access token
$headers = @{
Authorization = "Bearer $accessToken"
if ($youtubeResponse.items.Count -gt 0) {
return $youtubeResponse.items[0].id.videoId
}
else {
return $null
}
}

# Send the request to get the episodes
$response = Invoke-RestMethod -Method Get -Uri $episodesUri -Headers $headers
# Augment episodes with iframe and YouTube video ID data
foreach ($episode in $episodes) {
$episodeUrl = $episode.external_urls.spotify
$iframeHtml = Get-EpisodeIframe -episodeUrl $episodeUrl

# Add the iframe property dynamically
$episode | Add-Member -MemberType NoteProperty -Name "iframe" -Value $iframeHtml

# Search YouTube using the episode's name and get the video ID
$youtubeVideoId = Get-YouTubeVideoId -searchQuery $episode.name

# Add the YouTube video ID dynamically
$episode | Add-Member -MemberType NoteProperty -Name "youtube_video_id" -Value $youtubeVideoId
}

# Define the target directory and file path
$targetDirectory = "site/data"
$targetFilePath = "$targetDirectory/episodes.json"

# Ensure the target directory exists; create it if it doesn't
# Ensure the target directory exists
if (-Not (Test-Path -Path $targetDirectory)) {
New-Item -Path $targetDirectory -ItemType Directory -Force
}

# Convert the episode data to JSON
$jsonData = $response.items | ConvertTo-Json -Depth 10
# Convert the augmented episodes to JSON
$jsonData = $episodes | ConvertTo-Json -Depth 10

# Save the JSON data to the file
Set-Content -Path $targetFilePath -Value $jsonData -Encoding UTF8

Write-Output "Episodes have been saved to $targetFilePath"
Write-Output "Episodes with iframes and YouTube video IDs have been saved to $targetFilePath"
44 changes: 33 additions & 11 deletions site/data/episodes.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@
"release_date": "2024-06-04",
"release_date_precision": "day",
"type": "episode",
"uri": "spotify:episode:3LEaVHBStIllvP1hLkfkl3"
"uri": "spotify:episode:3LEaVHBStIllvP1hLkfkl3",
"iframe": "<iframe style=\"border-radius: 12px\" width=\"624\" height=\"351\" title=\"Spotify Embed: Power &amp; Politics! Communicating and Building Political Capital for Agile Transformations!\" frameborder=\"0\" allowfullscreen allow=\"autoplay; clipboard-write; encrypted-media; fullscreen; picture-in-picture\" loading=\"lazy\" src=\"https://open.spotify.com/embed/episode/3LEaVHBStIllvP1hLkfkl3/video?utm_source=oembed\"></iframe>",
"youtube_video_id": "LA3CIxYy3m8"
},
{
"audio_preview_url": "https://podz-content.spotifycdn.com/audio/clips/7iVbUCIF0o3g5bA3GfjvR7/clip_347836_407836.mp3",
Expand Down Expand Up @@ -77,7 +79,9 @@
"release_date": "2024-04-25",
"release_date_precision": "day",
"type": "episode",
"uri": "spotify:episode:2sT2nROL9UGKsKGrkgW0LY"
"uri": "spotify:episode:2sT2nROL9UGKsKGrkgW0LY",
"iframe": "<iframe style=\"border-radius: 12px\" width=\"624\" height=\"351\" title=\"Spotify Embed: Agile at Microsoft\" frameborder=\"0\" allowfullscreen allow=\"autoplay; clipboard-write; encrypted-media; fullscreen; picture-in-picture\" loading=\"lazy\" src=\"https://open.spotify.com/embed/episode/2sT2nROL9UGKsKGrkgW0LY/video?utm_source=oembed\"></iframe>",
"youtube_video_id": "CC4tZG1w-Mw"
},
{
"audio_preview_url": "https://podz-content.spotifycdn.com/audio/clips/0LV2QYQlhE0KgO5KZ49PDU/clip_614932_674932.mp3",
Expand Down Expand Up @@ -117,7 +121,9 @@
"release_date": "2024-02-22",
"release_date_precision": "day",
"type": "episode",
"uri": "spotify:episode:10uHQxi2SRHbWXgGC6Bnzw"
"uri": "spotify:episode:10uHQxi2SRHbWXgGC6Bnzw",
"iframe": "<iframe style=\"border-radius: 12px\" width=\"624\" height=\"351\" title=\"Spotify Embed: Mindset Versus Philosophy\" frameborder=\"0\" allowfullscreen allow=\"autoplay; clipboard-write; encrypted-media; fullscreen; picture-in-picture\" loading=\"lazy\" src=\"https://open.spotify.com/embed/episode/10uHQxi2SRHbWXgGC6Bnzw/video?utm_source=oembed\"></iframe>",
"youtube_video_id": "2GqcNjEXNzk"
},
{
"audio_preview_url": "https://podz-content.spotifycdn.com/audio/clips/5hQc9sdg9cXuz83lfhG8Tw/clip_607923_667923.mp3",
Expand Down Expand Up @@ -157,7 +163,9 @@
"release_date": "2024-01-25",
"release_date_precision": "day",
"type": "episode",
"uri": "spotify:episode:1bouCJJKac0MPgFFEaJyGq"
"uri": "spotify:episode:1bouCJJKac0MPgFFEaJyGq",
"iframe": "<iframe style=\"border-radius: 12px\" width=\"624\" height=\"351\" title=\"Spotify Embed: Enterprise Agility\" frameborder=\"0\" allowfullscreen allow=\"autoplay; clipboard-write; encrypted-media; fullscreen; picture-in-picture\" loading=\"lazy\" src=\"https://open.spotify.com/embed/episode/1bouCJJKac0MPgFFEaJyGq/video?utm_source=oembed\"></iframe>",
"youtube_video_id": "eeLA6MTJLJ0"
},
{
"audio_preview_url": "https://podz-content.spotifycdn.com/audio/clips/2eGzOPgbJwNd4UoNakVDGg/clip_176366_236366.mp3",
Expand Down Expand Up @@ -197,7 +205,9 @@
"release_date": "2023-12-19",
"release_date_precision": "day",
"type": "episode",
"uri": "spotify:episode:4nxJcTneeQVZeQw8FYRrnI"
"uri": "spotify:episode:4nxJcTneeQVZeQw8FYRrnI",
"iframe": "<iframe style=\"border-radius: 12px\" width=\"624\" height=\"351\" title=\"Spotify Embed: Agile Alchemy\" frameborder=\"0\" allowfullscreen allow=\"autoplay; clipboard-write; encrypted-media; fullscreen; picture-in-picture\" loading=\"lazy\" src=\"https://open.spotify.com/embed/episode/4nxJcTneeQVZeQw8FYRrnI/video?utm_source=oembed\"></iframe>",
"youtube_video_id": null
},
{
"audio_preview_url": "https://podz-content.spotifycdn.com/audio/clips/6k5jWwFQGYcMtKEL319zD9/clip_543216_603216.mp3",
Expand Down Expand Up @@ -237,7 +247,9 @@
"release_date": "2023-11-23",
"release_date_precision": "day",
"type": "episode",
"uri": "spotify:episode:60GjA3dexfE6nmdvPoqxof"
"uri": "spotify:episode:60GjA3dexfE6nmdvPoqxof",
"iframe": "<iframe style=\"border-radius: 12px\" width=\"624\" height=\"351\" title=\"Spotify Embed: Continuous Delivery\" frameborder=\"0\" allowfullscreen allow=\"autoplay; clipboard-write; encrypted-media; fullscreen; picture-in-picture\" loading=\"lazy\" src=\"https://open.spotify.com/embed/episode/60GjA3dexfE6nmdvPoqxof/video?utm_source=oembed\"></iframe>",
"youtube_video_id": "FCcOX9v_9yk"
},
{
"audio_preview_url": "https://podz-content.spotifycdn.com/audio/clips/4mjHZ9AxKAsJGY2W8lhJMU/clip_400736_460736.mp3",
Expand Down Expand Up @@ -277,7 +289,9 @@
"release_date": "2023-10-26",
"release_date_precision": "day",
"type": "episode",
"uri": "spotify:episode:5gOaOrHXLCpnUvinv1RJGX"
"uri": "spotify:episode:5gOaOrHXLCpnUvinv1RJGX",
"iframe": "<iframe style=\"border-radius: 12px\" width=\"624\" height=\"351\" title=\"Spotify Embed: Ethics in Agile\" frameborder=\"0\" allowfullscreen allow=\"autoplay; clipboard-write; encrypted-media; fullscreen; picture-in-picture\" loading=\"lazy\" src=\"https://open.spotify.com/embed/episode/5gOaOrHXLCpnUvinv1RJGX/video?utm_source=oembed\"></iframe>",
"youtube_video_id": "FCcOX9v_9yk"
},
{
"audio_preview_url": "https://podz-content.spotifycdn.com/audio/clips/3G0gTRSlbceC0mLoYIoS5l/clip_640280_700280.mp3",
Expand Down Expand Up @@ -317,7 +331,9 @@
"release_date": "2023-06-29",
"release_date_precision": "day",
"type": "episode",
"uri": "spotify:episode:370aUUSMn8LlwfjrgZoHd7"
"uri": "spotify:episode:370aUUSMn8LlwfjrgZoHd7",
"iframe": "<iframe style=\"border-radius: 12px\" width=\"624\" height=\"351\" title=\"Spotify Embed: Words matter.\" frameborder=\"0\" allowfullscreen allow=\"autoplay; clipboard-write; encrypted-media; fullscreen; picture-in-picture\" loading=\"lazy\" src=\"https://open.spotify.com/embed/episode/370aUUSMn8LlwfjrgZoHd7/video?utm_source=oembed\"></iframe>",
"youtube_video_id": "EcfCdaF9b9I"
},
{
"audio_preview_url": "https://podz-content.spotifycdn.com/audio/clips/3XNvN4BDTWQkFdvo5scTlK/clip_614167_674167.mp3",
Expand Down Expand Up @@ -357,7 +373,9 @@
"release_date": "2023-06-01",
"release_date_precision": "day",
"type": "episode",
"uri": "spotify:episode:6LcIvzb81bwqODR3hhUnQa"
"uri": "spotify:episode:6LcIvzb81bwqODR3hhUnQa",
"iframe": "<iframe style=\"border-radius: 12px\" width=\"624\" height=\"351\" title=\"Spotify Embed: Are office spaces dead\" frameborder=\"0\" allowfullscreen allow=\"autoplay; clipboard-write; encrypted-media; fullscreen; picture-in-picture\" loading=\"lazy\" src=\"https://open.spotify.com/embed/episode/6LcIvzb81bwqODR3hhUnQa/video?utm_source=oembed\"></iframe>",
"youtube_video_id": "cKWVVYxrcHw"
},
{
"audio_preview_url": "https://podz-content.spotifycdn.com/audio/clips/5MEiFc8e1e5pyJzCfaGhpQ/clip_2768400_2821200.mp3",
Expand Down Expand Up @@ -397,7 +415,9 @@
"release_date": "2023-04-27",
"release_date_precision": "day",
"type": "episode",
"uri": "spotify:episode:4734iiQaczSmTlAT7tbKzR"
"uri": "spotify:episode:4734iiQaczSmTlAT7tbKzR",
"iframe": "<iframe style=\"border-radius: 12px\" width=\"624\" height=\"351\" title=\"Spotify Embed: Product owners are obsolete!\" frameborder=\"0\" allowfullscreen allow=\"autoplay; clipboard-write; encrypted-media; fullscreen; picture-in-picture\" loading=\"lazy\" src=\"https://open.spotify.com/embed/episode/4734iiQaczSmTlAT7tbKzR/video?utm_source=oembed\"></iframe>",
"youtube_video_id": "H0BkB3b9CVM"
},
{
"audio_preview_url": "https://podz-content.spotifycdn.com/audio/clips/5FouHhWWMtnl9EhIiF9r5x/clip_210738_270738.mp3",
Expand Down Expand Up @@ -437,6 +457,8 @@
"release_date": "2023-04-01",
"release_date_precision": "day",
"type": "episode",
"uri": "spotify:episode:4Ecjpkzht6Hl1s96OjKzFT"
"uri": "spotify:episode:4Ecjpkzht6Hl1s96OjKzFT",
"iframe": "<iframe style=\"border-radius: 12px\" width=\"624\" height=\"351\" title=\"Spotify Embed: Life coaches masquerading as Agile Coaches\" frameborder=\"0\" allowfullscreen allow=\"autoplay; clipboard-write; encrypted-media; fullscreen; picture-in-picture\" loading=\"lazy\" src=\"https://open.spotify.com/embed/episode/4Ecjpkzht6Hl1s96OjKzFT/video?utm_source=oembed\"></iframe>",
"youtube_video_id": null
}
]

0 comments on commit ed977c5

Please sign in to comment.