Created
December 5, 2024 03:01
-
-
Save Mike-Crowley/6cc781eb371ac19445b5e3bd6aba3453 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| $Headers = @{ | |
| "Accept" = "application/json" | |
| "authorization" = "Bearer BQAJ" # Can acquire from the browser | |
| } | |
| $uri = @' | |
| https://api.spotify.com/v1/me/top/tracks?limit=50 | |
| '@ | |
| $QueryResults = [Collections.Generic.List[Object]]::new() | |
| do { | |
| $PageResults = Invoke-RestMethod -Uri $uri -Headers $Headers | |
| if ($PageResults.items) { | |
| $QueryResults.AddRange($PageResults.items) | |
| } | |
| else { | |
| $QueryResults.Add($PageResults) | |
| } | |
| $uri = $PageResults.next | |
| } until (-not $uri) | |
| $OutputFile = ([Environment]::GetFolderPath("Desktop") + "\topTracks.csv") | |
| Write-Host "Found $($QueryResults.count) tracks." -ForegroundColor Cyan | |
| $QueryResults = $QueryResults | Select-Object Name, @{n = "albumName"; e = { $_.album.name } }, @{n = "duration"; e = { [timespan]::FromMilliseconds($_.duration_ms) } }, preview_url | |
| $QueryResults | Export-Csv $OutputFile |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment