Skip to content

Instantly share code, notes, and snippets.

@mavericksevmont
Last active November 1, 2020 21:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mavericksevmont/da6d289c11b08fc9d023419e05116b8d to your computer and use it in GitHub Desktop.
Save mavericksevmont/da6d289c11b08fc9d023419e05116b8d to your computer and use it in GitHub Desktop.
# Function declaration
function Get-SpotifyTitle {
[cmdletbinding()] param([string]$TrackUri)
$Cont = Invoke-WebRequest -Uri $TrackUri
$Title = $Cont.ParsedHTML.Title
$SplitTitle = $Title -split ', a song by '
$Song = $SplitTitle[0]
$Artist = $SplitTitle[1] -replace ' on Spotify'
[pscustomobject]@{ Song = "$Song" ; Artist = "$Artist" ; Uri = "$TrackUri" }
}
# Get Single Track
$TrackUri = "open.spotify.com/track/3KkXRkHbMCARz0aVfEt68P" # track's uri, obtained from copy/pasting from SPotify's App favorite list.
Get-SpotifyTitle -TrackUri $TrackUri
# Get multiple tracks from a list
$List = Get-Content D:\SpotUris.txt
$List | foreach {
Get-SpotifyTitle -TrackUri $_ # Run function
Start-Sleep -Milliseconds 100 # Added this due to 404 when requests were made too fast
} -OutVariable Results
# Export to a csv file
$FilePath = "$PSScriptRoot\YourSpotifySongs.csv" # Directory Path and filename, e.g. C:\Temp\Filename.csv
$Results | Export-Csv -Path $FilePath -Force -NoTypeInformation
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment