Skip to content

Instantly share code, notes, and snippets.

@bake
Created February 6, 2015 23:10
Show Gist options
  • Save bake/193affd03ab95f1cd404 to your computer and use it in GitHub Desktop.
Save bake/193affd03ab95f1cd404 to your computer and use it in GitHub Desktop.
Wikia Lyrics
http = require 'http'
itunes = require 'playback'
entities = require 'entities'
size = process.stdout.getWindowSize()
api = 'http://lyrics.wikia.com/api.php'
itunes.on 'playing', (track) ->
search track.artist, track.name
search = (artist, track) ->
get api + '?artist=' + encodeURI(artist) + '&song=' + encodeURI(track) + '&fmt=realjson', (body) ->
body = JSON.parse body
console.log ''
console.log artist + ' - ' + track
console.log '==='
console.log ''
get body.url, parseLyrics
parseLyrics = (body) ->
body = body.match /<div cl?ass='lyricbox'>(.*)/ig
body = body[0]
body = body.replace /(<br( \/)?>)/ig, '&#10;'
body = body.replace /(<([^>]+)>)/ig, ''
body = body.match /(&#[0-9]+;)/ig
body = body.join ''
body = entities.decodeHTML body
body = body.trim()
if body is ''
console.log 'Not found :('
else console.log body
get = (url, callback) ->
http.get url, (response) ->
body = ''
response.on 'data', (chunk) ->
body += chunk
response.on 'end', ->
callback body
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment