-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgather-audio.coffee
67 lines (52 loc) · 1.88 KB
/
gather-audio.coffee
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
55
56
57
58
59
60
61
62
63
64
65
66
67
randomWords = require "random-words"
shuffle = require "./shuffle"
Source = require "./Source"
# ---------------------
# Setup audio providers
# ---------------------
get_env_var = require "./get-env-var"
net_enabled = true
OGA_enabled = true
soundcloud_client_id = get_env_var "SOUNDCLOUD_CLIENT_ID"
soundcloud_enabled = soundcloud_client_id?
FS_audio_glob = get_env_var "AUDIO_SOURCE_FILES_GLOB"
FS_enabled = false #FS_audio_glob?
if not net_enabled
soundcloud_enabled = false
OGA_enabled = false
if soundcloud_enabled
soundcloud = require "./audio-providers/soundcloud"
soundcloud.init(id: soundcloud_client_id)
if FS_enabled
FS = require "./audio-providers/filesystem"
if OGA_enabled
OGA = require "./audio-providers/opengameart"
# ---------------------
module.exports = (query, new_source_callback)->
sources = []
# TODO: abstract "OR"-searching by using "a OR b" for OGA but multiple searches for SC
# so we can do searches for themes globally, and expose that to the user
on_new_source = (stream_url, attribution)=>
new_source_callback new Source stream_url, attribution
if soundcloud_enabled
# query = randomWords(1).join(" ")
# TODO: named arguments
soundcloud.search query, on_new_source, ()=>
console.log "[SC] Done collecting track metadata from search"
if OGA_enabled
# query = randomWords(5).join(" OR ")
# TODO: named arguments
OGA.search query,
(err, stream_url, attribution)=>
return console.error "[OGA] Error fetching track metadata:", err if err
on_new_source(stream_url, attribution)
()=>
console.log "[OGA] Done collecting track metadata from search"
if FS_enabled
# TODO: named arguments
FS.glob FS_audio_glob,
(err, stream_url, attribution)=>
return console.error "[FS] Error fetching track metadata:", err if err
on_new_source(stream_url, attribution)
()=>
console.log "[FS] Done collecting track metadata from files"