File size: 933 Bytes
b58c6cb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import config from '../../config.js'
import youtube from './youtube.js'
import soundcloud from './soundcloud.js'
import bandcamp from './bandcamp.js'
import deezer from './deezer.js'

async function searchWithDefault(query, fallback) {
  const searchSource = fallback ? config.search.fallbackSearchSource : config.search.defaultSearchSource

  switch (searchSource) {
    case 'ytmusic':
    case 'youtube': {
      return youtube.search(query, searchSource, false)
    }
    case 'soundcloud': {
      return soundcloud.search(query, false)
    }
    case 'bandcamp': {
      return bandcamp.search(query, false)
    }
    case 'deezer': {
      return deezer.search(query, false)
    }
    default: {
      console.warn(`[\u001b[33msources\u001b[37m]: Default search source: unknown, falling back to: ${config.search.fallbackSearchSource}`)

      return searchWithDefault(query, true)
    }
  }
}

export default searchWithDefault