foobar2000的ESLyric酷歌词网站歌词脚本

除了网易云音乐的歌词脚本,其他网上很多歌词脚本已经失效,自己新增一个,有需要的拿去用

var KGC_CFG = {
    DEBUG: false,
    D_SRV: "http://www.kugeci.com/",
    S_SRV: "http://www.kugeci.com/search",
	RETRY: 1,
};

var kgc_http = {
    handle: null,
    type: null,
};

var kgc_abort = {
    handle: null,
    isvalid: true
};

function get_my_name()
{
    return "kugeci|酷歌词";
}

function get_version() 
{
    return "0.0.1";
}

function get_author() 
{
    return "AIRKEN";
}

function start_search(info,callback)
{
	//add your codes here
	var i = null, song = null, html_text = null, gc_text = null, new_lyric = null;
	var reg = new RegExp("<td><a href=\"(.*?)\"><","g"), reg_text = null;
    var regex_artist = new RegExp("演唱:(.*?)</a>","");
    var regex_gq = new RegExp(">&nbsp;(.*?)</h1>","");
    var regex_gqgc = new RegExp("<div id=\"lyricsContainer\">(.*?)</div>","");
    var gqid = null, id_text = null, gqmc = null, gqgs = null, gqgc = null;
	
    html_text = kgc_download(KGC_CFG.S_SRV, "q=" + kgc_normalize(info.Title));
    if (html_text) {
        for (i = 0, song = []; reg_text = reg.exec(html_text); i++) {
			song[i] = reg_text[1];
        }    
    }
    for (i = 0; i < song.length; i++ ) {
        try {
            html_text = kgc_download(song[i], null);
            gc_text = html_text.replace(/\n|\r/g,"");
            gqgs = regex_artist.exec(gc_text)[1];
            gqgs = gqgs.replace(/\s/g,"");
            gqmc = regex_gq.exec(gc_text)[1];
            gqmc = gqmc.replace(/\s/g,"");
            gqgc = regex_gqgc.exec(gc_text)[1];
            gqgc = gqgc.replace(/<br \/>/g,"\n");

            new_lyric = callback.CreateLyric();
            new_lyric.Title = gqmc;
            new_lyric.Artist = gqgs;
            new_lyric.Location = song[i];
            new_lyric.Source = get_my_name();
            new_lyric.LyricText = gqgc;
            callback.AddLyric(new_lyric);
            (i%2 == 0) && callback.Refresh();
        } catch (e) {
            console("Unkown, failed to add lyric");
        }		
	}
}

function kgc_download(url, param) {
    // retry several times at most
    var i = null, xml_text = null;
    for (i = 0; i < KGC_CFG.RETRY; i++) {
        if (!kgc_http.handle) {
            try {
                kgc_http.handle = utils.CreateHttpClient();
                kgc_http.type = "u_c";
            } catch (e) {
                try {
                    kgc_http.handle = utils.CreateHttpRequest("GET");
                    kgc_http.type = "u_r";
                } catch (err) {
                    try {
                        kgc_http.handle = new ActiveXObject("Microsoft.XMLHTTP");
                        kgc_http.type = "ie";
                    } catch (error) {
                        kgc_http.handle = null;
                        kgc_http.type = null;
                        continue;
                    }
                }
            }
        }
        try {
            if (param) {
                url += "?" + encodeURI(param);
            }
            if (kgc_http.type == "u_c") {
                kgc_http.handle.addHttpHeader("Referer", KGC_CFG.D_SRV);
                xml_text = kgc_http.handle.Request(url, "GET");
                if (kgc_http.handle.StatusCode == 200) {
                    return xml_text;
                }
            } else if (kgc_http.type == "u_r") {
                kgc_http.AddHeader("Referer", KGC_CFG.D_SRV);
                xml_text = kgc_http.handle.Run(url);
                return xml_text;
            } else if (kgc_http.type == "ie") {
                kgc_http.handle.open("GET", url, false);
                kgc_http.handle.setRequestHeader("Referer", KGC_CFG.D_SRV);
                kgc_http.handle.send();
                if (kgc_http.handle.readyState == 4 && kgc_http.handle.status == 200) {
                    xml_text = kgc_http.handle.responseText;
                    return xml_text;
                }
            }
        } catch (e) {
            continue;
        }
    }
    return null;
}

function kgc_normalize(str) {
    var s = null;
    if (str) {
        s = str;
        // !"#$%&'()*+,-./:;<=>?@[\]^_`{|}~
        s = s.replace(/([\u0021-\u002F]|[\u003A-\u0040]|[\u005B-\u0060]|[\u007B-\u007E])+/g, " ");
        // !"#$%&'()*+,-./:;<=>?@[\]^_`{|}~
        s = s.replace(/([\uFF01-\uFF20]|[\uFF3B-\uFF40]|[\uFF5B-\uFF5E])+/g, " ");
        // ·×‐‑‒–—―‖‗‘’‚‛“”„‟…‧‰、。〇〈〉《》「」『』【】〔〕〖〗〜・
        s = s.replace(/(\u00B7|\u00D7|[\u2010-\u201F]|[\u2026-\u2027]|\u2030|[\u3001-\u3002]|[\u3007-\u3011]|[\u3014-\u3017]|\u301C|\u30FB)+/g, " ");
        s = s.replace(/\s+/g, " ");
    } else {
        s = "";
    }
    return s;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值