Forked from cleverdevil/overcast-recently-played.py
Last active
August 9, 2020 20:37
-
-
Save mmodrow/36a52d965de3283b3568d75ef20f0a09 to your computer and use it in GitHub Desktop.
Fetch recently played episodes from an Overcast.fm full OPML-Export. Then, return those episodes as JSON.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
param ( | |
# path the to a file with the response of https://overcast.fm/account/export_opml/extended | |
[string]$inputFileName = "overcast_all.opml", | |
[bool]$playedOnly = $true, | |
# 0: title only; 1: adds user manipulation data; 2: adds publishing data; 3: adds overcast metadata | |
[int]$verbosity = 1 | |
) | |
$ompl = [xml](Get-Content $inputFileName) | |
$recentChanges = (New-Object System.Collections.ArrayList) | |
foreach ($podcast in @($ompl.SelectNodes(".//*[@type='rss']"))) { | |
$podcastTitle = $podcast.title | |
$recentChangesInPodcast = New-Object PSCustomObject | |
$recentChangesInPodcast | Add-Member NoteProperty "Title" $podcastTitle | |
$recentChangesInPodcast | Add-Member NoteProperty "Episodes" (New-Object System.Collections.ArrayList) | |
$touchedEpisodes = @( | |
$podcast.outline | | |
Where-Object { | |
$_.userUpdatedDate -ne $null -and | |
([DateTime]::NOW - [DateTime]($_.userUpdatedDate)).TotalDays -lt 6 | |
} | |
) | |
if ($playedOnly) { | |
$touchedEpisodes = $touchedEpisodes | Where-Object { $_.played -eq 1 } | |
} | |
foreach ($episode in $touchedEpisodes) { | |
$episodeTitle = $episode.title | |
$publishedAt = $episode.pubDate | |
$userUpdatedDate = $episode.userUpdatedDate | |
$progress = $episode.progress | |
$url = $episode.url | |
$overcastUrl = $episode.overcastUrl | |
$overcastId = $episode.overcastId | |
$isPlayed = $episode.played -eq "1" | |
$isDeleted = $episode.userDeleted -eq "1" | |
$episodeObject = New-Object PSCustomObject | |
$episodeObject | Add-Member NoteProperty "Title" $episodeTitle | |
if ($verbosity -gt 0) { | |
$episodeObject | Add-Member NoteProperty "UserUpdatedDate" $userUpdatedDate | |
$episodeObject | Add-Member NoteProperty "Progress" $progress | |
$episodeObject | Add-Member NoteProperty "IsPlayed" $isPlayed | |
$episodeObject | Add-Member NoteProperty "IsDeleted" $isDeleted | |
} | |
if ($verbosity -gt 1) { | |
$episodeObject | Add-Member NoteProperty "PublishedAt" $publishedAt | |
$episodeObject | Add-Member NoteProperty "URL" $url | |
} | |
if ($verbosity -gt 2) { | |
$episodeObject | Add-Member NoteProperty "OvercastUrl" $overcastUrl | |
$episodeObject | Add-Member NoteProperty "OvercastId" $overcastId | |
} | |
$recentChangesInPodcast.Episodes.Add($episodeObject) | Out-Null | |
} | |
if ($recentChangesInPodcast.Episodes.count -gt 0) { | |
$recentChanges.Add($recentChangesInPodcast) | Out-Null | |
} | |
} | |
$json = ConvertTo-Json $recentChanges -Depth 5 | |
return $json |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment