Skip to content

Instantly share code, notes, and snippets.

@milnak
Last active February 23, 2023 06:04
Show Gist options
  • Save milnak/b90f118c4d541af627df9760107d41c4 to your computer and use it in GitHub Desktop.
Save milnak/b90f118c4d541af627df9760107d41c4 to your computer and use it in GitHub Desktop.
Convert spotify playlist via ctrl-a,ctrl-c to a CSV list of artist,title,uri
# (Get-Clipboard) -split "`n" | .\Write-SpotifyTrackInfo.ps1 | Format-List
param(
[Parameter(Position = 0, Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)]
[String[]]$URIs
)
process {
$regex = '<title>(?<Title>.+).* - .*by (?<Artist>.+) \| Spotify<\/title>'
foreach ($uri in $URIs) {
if (-not ([uri]$uri).IsAbsoluteUri) {
continue
}
$response = Invoke-WebRequest -Uri $uri
$content = $response.Content.Substring(0, 250)
Write-Verbose "Content: $content"
if ($content -match $regex) {
[PSCustomObject]@{
Artist = [Net.WebUtility]::HtmlDecode($Matches.Artist)
Title = [Net.WebUtility]::HtmlDecode($Matches.Title)
Uri = $uri
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment