-
Notifications
You must be signed in to change notification settings - Fork 0
/
songlocator-deezer.coffee
63 lines (49 loc) · 1.6 KB
/
songlocator-deezer.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
###
SongLocator resolver for Deezer.
2013 (c) Andrey Popp <8mayday@gmail.com>
###
((root, factory) ->
if typeof exports == 'object'
SongLocator = require('songlocator-base')
module.exports = factory(SongLocator)
else if typeof define == 'function' and define.amd
define (require) ->
SongLocator = require('songlocator-base')
root.SongLocator.Deezer = factory(SongLocator)
else
root.SongLocator.Deezer = factory(SongLocator)
) this, ({BaseResolver, extend}) ->
artistRoleRe = /\[[^\]]+\]/g
cleanArtist = (artist) ->
if artist?
cleaned = artist.replace(artistRoleRe, '', 'g').trim()
if cleaned then cleaned else artist
else
artist
class Resolver extends BaseResolver
name: 'deezer'
score: 0.9
search: (qid, query) ->
this.request
url: 'http://api.deezer.com/2.0/search'
params: {q: query}
callback: (error, response) =>
return if error?
return unless response.data.length > 0
results = for item in response.data
{
title: item.title
artist: cleanArtist(item.artist?.name)
album: item.album?.title
source: this.name
id: item.id
linkURL: item.link
imageURL: "#{item.album?.cover}?size=big"
audioURL: undefined
audioPreviewURL: item.preview
mimetype: 'audio/mpeg'
duration: item.duration
}
results = results.slice(0, this.options.searchMaxResults)
this.results(qid, results)
{Resolver}