-
Notifications
You must be signed in to change notification settings - Fork 0
/
Search-Music.ps1
47 lines (39 loc) · 1.24 KB
/
Search-Music.ps1
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
[cmdletbinding()]
param(
[Parameter(Mandatory=$true)]
[string]$Keywords
)
Begin {
$songlist=@()
}
PROCESS {
$songs = ((Invoke-WebRequest "http://api.imjad.cn/cloudmusic/?type=search&search_type=1&s=$Keywords").content | ConvertFrom-Json).result.songs
foreach ($song in $songs) {
$songProp = New-Object -TypeName psobject -Property (
@{
ID="";
Name="";
Artist="";
Album="";
Duration=""
}
)
$id = $song.ID;
$name = $song.Name;
$Artist = $song.ar.Name;
$Album = $song.al.Name;
$dt = [timespan]::FromSeconds([int]$($song.dt)/1000)
$Duration = "{0:mm\:ss}" -f $dt
$songProp.ID = $id;
$songProp.Name = $name;
$songProp.Artist = $Artist;
$songProp.Album = $Album;
$songProp.Duration = $Duration
$songlist += $songProp
Remove-Variable songprop
}
}
END{
$songlist | Select-Object ID,Name,Duration,Artist,Album | Format-Table -AutoSize
Remove-Variable songlist
}