Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
# Setup the Azure Functions parameters
# https://marcfunction1.azurewebsites.net/api/sca/scanowplaying?state={state}
switch -RegEx ($REQ_QUERY_STATE)
{
\S {$state = $REQ_QUERY_STATE}
# https://marcfunction1.azurewebsites.net/api/sca/{state}
default {$state = $REQ_PARAMS_STATE}
}
# If no state was provided
if(($REQ_PARAMS_STATE -eq $null) -and ($REQ_QUERY_STATE -eq $null)) {$state = 'National'}
if($state -eq 'National') {Clear-Variable state}
$AustereoStations = @()
$AustereoStations += ((Invoke-WebRequest -Uri 'https://master.myradio-api.prod.scadigital.com.au/mmm/stations' -UseBasicParsing).content | ConvertFrom-Json).stations | ? {$_.state -eq $state}
$AustereoStations += ((Invoke-WebRequest -Uri 'https://master.myradio-api.prod.scadigital.com.au/hit/stations' -UseBasicParsing).content | ConvertFrom-Json).stations | ? {$_.state -eq $state}
$AustereoStationObject = @()
foreach ($AustereoStation in $AustereoStations) {
$AustereoStation.name
$RadioSong = @()
if ($AustereoStation.localStreams) {
$streamUrl = ($AustereoStation.localStreams | ? {$_.callSign -match '2'}).streamUrl
}
else {
$streamUrl = $AustereoStation.streamUrl
}
if ($streamUrl -match '.') {
$streamUrldomain = ($streamUrl).Split('/', 4)[2]
$streamUrlprefix = ($streamUrl | Split-Path -Parent).Replace('\', '/')
$null = (Invoke-WebRequest -Uri $streamUrl -UseBasicParsing).RawContent -match '.*\.m3u8.{0,}'; $playlistUrl = $Matches[0]
if ($playlistUrl -match 'http') {
$streamMetaData = Invoke-WebRequest -Uri $playlistUrl -UseBasicParsing
}
if ($playlistUrl -notmatch 'http') {
$streamMetaData = Invoke-WebRequest -Uri "$streamUrlprefix/$playlistUrl" -UseBasicParsing
}
$null = $streamMetaData.RawContent -match '#EXTINF:4.*?,(.*\s-\s.*)'
$RadioSong = $Matches[1]
}
if ($AustereoStation.state) {$state = $AustereoStation.state} else {$state = 'National'}
$w = [PSCustomObject]@{
song = $RadioSong
station = $AustereoStation.name
code = $AustereoStation.stationCode
state = $state
listen = $AustereoStation.streamUrl
}
$w | ft * -AutoSize -Wrap
if ($w.song -match '.') {
$AustereoStationObject += $w
}
}
$html = $AustereoStationObject | ConvertTo-Html -Title 'SCA Just Played' | Out-String
# Turn the URLs into Hyperlinks with Regex
$searchText1 = 'https:\/\/'
$replaceText1 = '<a href="https://'
$searchText2 = '\.m3u8'
$replaceText2 = '.m3u8">Listen Live</a>'
$searchText3 = '_32.stream'
$replaceText3 = '_128.stream'
$html = $html -replace $searchText1, $replaceText1
$html = $html -replace $searchText2, $replaceText2
$html = $html -replace $searchText3, $replaceText3
@{
headers = @{"content-type" = "text/html"}
body = $html
} | ConvertTo-Json > $res
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.