-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGetSpotifyIdBySearchWeb.ps1
More file actions
54 lines (44 loc) · 1.79 KB
/
Copy pathGetSpotifyIdBySearchWeb.ps1
File metadata and controls
54 lines (44 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#region config
$albumListFile = "albumlist.txt"
$albumUrisFile = "albumUris.txt"
$global:spotifyApiUri = "https://spclient.wg.spotify.com"
#Get here: Bearer from Browser Developer Tools
$global:spotifyOAuthToken = "XXXXX"
Add-Type -Assembly System.Web
#endregion
#region functions
Function SearchForAlbumOnSpotify() {
Param (
[Parameter(Mandatory=$True,ValueFromPipeline=$False,ValueFromPipelinebyPropertyName=$False)]
[String]$albumName
)
Begin {
$albumNameEncoded = [System.Web.HttpUtility]::UrlEncode($albumName)
$albumNameEncoded = $albumNameEncoded.toString().Replace("+", "%20")
$uri = "$($global:spotifyApiUri)/searchview/km/v4/search/$($albumNameEncoded)?entityVersion=2&limit=10&imageSize=large&catalogue=&country=C&locale=de&platform=web"
}
Process {
$result = Invoke-Restmethod -Method GET -Uri $($uri) -ContentType "application/json" -Headers @{"Authorization" = "Bearer $($global:spotifyOAuthToken)"}
}
End {
Write-Output $result.results
}
}
#endregion
#region main programm
$albumNames = Get-Content $albumListFile
Foreach ($albumName in $albumNames) {
$spotifyAlbums = SearchForAlbumOnSpotify -albumName $albumName
If ($spotifyAlbums.topHit) {
If ($spotifyAlbums.albums.total -eq 1) {
$spotifyAlbumUri = $spotifyAlbums.albums.hits[0].uri
} else {
$spotifyAlbumUri = $spotifyAlbums.topHit.hits[0].uri
}
Write-Host "$($spotifyAlbumUri)`t`t $($albumName): Found matching item" -ForegroundColor Green
"$spotifyAlbumUri" | Add-Content $albumUrisFile
} Else {
Write-Host "$($albumName): Not able to find matching album" -ForegroundColor Red
}
}
#endregion