")[0] -split ">")[1] -replace "&","&"
$EpisodeName = ((($TVShow -split "
")[0] -split ">")[0] -split "season-")[1]) -split "/Episode-")[1] -replace '"$'
$AirDateString = (($TVShow -split "epdate`">")[1] -split "")[0]
$Year = "20" + (($AirDateString -split " ")[2] -replace "^'")
$MonthString = ($AirDateString -split " ")[1]
$Day = ($AirDateString -split " ")[0] -replace "[^\d]"
$Month = switch ($MonthString)
{
"Jan" { "1" }
"Feb" { "2" }
"Mar" { "3" }
"Apr" { "4" }
"May" { "5" }
"Jun" { "6" }
"Jul" { "7" }
"Aug" { "8" }
"Sep" { "9" }
"Oct" { "10" }
"Nov" { "11" }
"Dec" { "12" }
}
$AirTime = ((($TVShow -split "eptime`">")[1] -split "")[0] -split " ")[0]
$AirTimeAndDate = Get-Date "$Year-$Month-$Day $AirTime"
$returnObject = New-Object System.Object
$returnObject | Add-Member -Type NoteProperty -Name TVShow -Value $TVShowName
$returnObject | Add-Member -Type NoteProperty -Name EpisodeName -Value $EpisodeName
$returnObject | Add-Member -Type NoteProperty -Name Season -Value $Season
$returnObject | Add-Member -Type NoteProperty -Name Episode -Value $Episode
$returnObject | Add-Member -Type NoteProperty -Name AirDate -Value $AirTimeAndDate
Write-Output $returnObject
# Cleanup
Remove-Variable TVShowName, EpisodeName, Season, Episode, AirTimeAndDate, AirDateString, Year, MonthString, Month, Day, AirTime, returnObject
}
}
End { }
}
function Get-TVShowAirDate
{
<#
.Synopsis
Retrieves information about a specific tv show's air dates
.DESCRIPTION
This cmdlet parses pogdesign's tv calendar for a specific tv show's air dates
.EXAMPLE
Get-TVShowAirDate
.EXAMPLE
Get-TVShowAirDate | Format-Table
.EXAMPLE
Get-TVShowNextAirDate | Get-TVShowAirDate | ft
#>
[CmdletBinding()]
param([Parameter(Mandatory=$True, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true)]
[string] $TVShow)
Begin { }
Process {
$URL = "http://www.pogdesign.co.uk/cat/$($TVShow -replace ' ','-' -replace "&","and" -replace '[^a-zA-Z\d-]')-summary"
try {
$TVShowInfo = Invoke-WebRequest -Uri $URL -UseBasicParsing
}
catch {
Write-Error "Failed to fetch TV Show data."
return
}
#$TVShowEpisodeSpans = (($TVShowInfo.Content -split "Next Airing Episode Dates")[1] -split "Back to the TV Calendar")[0] -split "UNAIRED')[0] }
foreach ($TVShowEpisodeSpan in $TVShowEpisodeSpans) {
$EpisodeName = (($TVShowEpisodeSpan -split '")[5] -replace "&","&"
$Season = (($TVShowEpisodeSpan -split 'itemprop="seasonNumber" >')[1] -split "")[0]
$Episode = ((($TVShowEpisodeSpan -split 'itemprop="episodeNumber"')[1] -split "`">")[1] -split "")[0]
$AirDate = (($TVShowEpisodeSpan -split 'itemprop="releasedEvent" content="')[1] -split '"')[0]
$AirTime = (((($TVShowEpisodeSpan -split 'itemprop="releasedEvent" content="')[1] -split '">')[1] -split "- ")[1] -split "")[0]
$AirDateTime = Get-Date "$AirDate $AirTime"
$returnObject = New-Object System.Object
$returnObject | Add-Member -Type NoteProperty -Name TVShow -Value $TVShow
$returnObject | Add-Member -Type NoteProperty -Name EpisodeName -Value $EpisodeName
$returnObject | Add-Member -Type NoteProperty -Name Season -Value $Season
$returnObject | Add-Member -Type NoteProperty -Name Episode -Value $Episode
$returnObject | Add-Member -Type NoteProperty -Name AirDate -Value $AirDateTime
Write-Output $returnObject
# Cleanup
Remove-Variable EpisodeName, Season, Episode, AirDateTime
}
}
End { }
}