Last active
October 18, 2017 03:14
-
-
Save marckean/4f78e2ceceb9cc5f7960cc4910ca026b to your computer and use it in GitHub Desktop.
This file contains 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
# Setup the Azure Functions parameters | |
switch -RegEx ($REQ_QUERY_URL) | |
{ | |
\S {$url = $REQ_QUERY_URL} | |
default {$url = "http://legacy.scahw.com.au/$REQ_PARAMS_URL.xspf"} | |
} | |
# Invoke the web request to the URL | |
$iwr = Invoke-RestMethod -Uri $url | |
# Build up the .Net web client | |
$HttpCompletionOption = 'ResponseContentRead' | |
Add-Type -AssemblyName System.Net.Http | |
$webClient = New-Object System.Net.Http.HttpClient | |
$webclient.DefaultRequestHeaders.Add('Icy-MetaData', '1') | |
# Get the Stream URL | |
$null = $iwr.InnerXml -match '<location>(?<location>.*)<\/location>' | |
$location = $matches.location | |
# Fire up the stream | |
$response = $webClient.GetAsync($location,$HttpCompletionOption) | |
$null = $webclient.DefaultRequestHeaders.Remove('Icy-MetaData') | |
# Pause until the stream title actually fires up | |
Start-Sleep -Seconds 2 | |
# Grab the song | |
$iwr = Invoke-RestMethod -Uri $url | |
$null = $iwr.InnerXml -match '<title>(?<song>.*)<\/title>' | |
$song = ($matches).song | ConvertTo-Json | |
# Kill the stream | |
$webclient.Dispose() | |
Out-File -Encoding Ascii -FilePath $res -inputObject $song |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment