import { AllHtmlEntities as Entities } from 'html-entities';
import fetch from 'node-fetch';

const decoder = new Entities();

PlaybackAPI.on('change:song', (song) => {
  fetch(`http://lyrics.wikia.com/wiki/${song.artist}:${song.title}`)
    .then((data) => data.text())
    .then((html) => {
      let lyrics = (/('|")lyricbox('|")>.+<\/script>(.+)<!--/g.exec(html)[3]);
      lyrics = lyrics.replace(/<br \/>/gi, '\n');
      lyrics = decoder.decode(lyrics);
      PlaybackAPI.setPlaybackSongLyrics(lyrics);
    })
    .catch((e) => {
      Logger.verbose('Lyrics parsing failed', e);
    });
});

@@ -326,16 +326,17 @@
 ox('%7C%22)%3E
+(
 .+%3C%5C/scr
@@ -339,16 +339,18 @@
 /script%3E
+)?
 (.+)%3C!--
@@ -367,9 +367,9 @@
 ml)%5B
-3
+4
 %5D);%0A

Fix the lyrics finding regexp