const LyricBase = require('../include/lyric-base');
const BlockedError = require('../include/blocked-error');

const keyword = 'azlyrics';

class Lyric extends LyricBase {
  find_lyric(url, html) {
    const prefix = '<!-- Usage of azlyrics.com content';
    const suffix = '</div>';

    let lyric = this.find_string_by_prefix_suffix(html, prefix, suffix);
    lyric = this.sanitize_html(lyric);

    this.lyric = lyric;

    return true;
  }

  find_info(url, html) {
    const patterns = {
      title: 'SongName = "(.*?)"',
      artist: 'ArtistName = "(.*?)"',
    };

    this.fill_song_info(html, patterns);
    return true;
  }

  async parse_page() {
    const { url } = this;

    try {
      const html = await this.get_html(url);
      this.find_lyric(url, html);
      this.find_info(url, html);
    } catch (error) {
      if (error.status === 403) {
        throw new BlockedError('AZLyrics shows 403');
      }
    }

    return true;
  }
}

exports.keyword = keyword;
exports.Lyric = Lyric;

if (require.main === module) {
  (async () => {
    const url = 'https://www.azlyrics.com/lyrics/coldplay/upup.html';
    const object = new Lyric(url);
    const lyric = await object.get();
    console.log(lyric);
  })();
}

@@ -607,16 +607,144 @@
 tterns);
+%0A%0A    if (!this.title) %7B%0A      console.error('Failed to find title');%0A      console.error(url);%0A      console.error(html);%0A    %7D
 %0A    ret

add some log error for azlyrics