-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi-itunes-main.v
44 lines (33 loc) · 989 Bytes
/
api-itunes-main.v
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
// Search itune API in Vlang
// No warranty of any kind. Use as is.
import json
import net.http
import os
struct SearchMusic {
resultcount int [json: resultCount]
results []Result
}
struct Result {
artistname string [json: artistName]
collectionprice string [json: collectionPrice]
kind string [json: kind]
releasedate string [json: releaseDate]
trackname string [json: trackName]
}
fn main() {
config := http.FetchConfig{
user_agent: 'Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:88.0) Gecko/20100101 Firefox/88.0'
}
user_search := os.input('Search itunes : ')
url := 'https://itunes.apple.com/search?term= $user_search'
resp := http.fetch(http.FetchConfig{ ...config, url: url }) or {
println('failed to fetch data from the server')
return
}
search_results := json.decode(SearchMusic, resp.text) or {
println('failed to decode json')
return
}
println('Result music search:\n\n $search_results .')
//println('Raw response:\n\n $resp .')
}