Last active
November 1, 2020 21:06
-
-
Save mavericksevmont/da6d289c11b08fc9d023419e05116b8d 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
# 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