-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathradio.ml
51 lines (46 loc) · 1.06 KB
/
radio.ml
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
#require "yojson"
open Yojson.Basic
let get_station (j : json) (s : string) = (
Util.member s j
|> Util.to_string_option
)
let add_station (j : json) (name : string) (url : string) = (
let value = "{\"" ^ name ^ "\": \"" ^ url ^ "\"}" in
Util.combine j (from_string value)
)
let print_stations (j : json) = (
let rec inner l index = (
match l with
| hd :: tl when index < 4 -> (
Printf.printf "%s\t" hd;
inner tl (index + 1)
)
| hd :: tl -> (
Printf.printf "%s\n" hd;
inner tl 0
)
| [] -> (
Printf.printf "\n"
)
) in
inner (Util.keys j) 0
)
let _ = (
let j = from_file "stations.json" in
let cmd = "mpv --vid=no --shuffle " in
let rec inner () = (
print_stations j;
print_string "Please enter a station: ";
let station_opt = get_station j (read_line ()) in
match station_opt with
| Some s -> (
Sys.chdir (Sys.getenv "HOME");
Sys.command (cmd ^ "\"" ^ s ^ "\"") |> (fun x -> ());
inner ()
)
| None -> (
print_endline "Goodbye!"
)
) in
inner ()
)