1

Kejunのブログのコードを使用していました。

.lrc(基本的に歌詞ファイル)を解析して、時間変数と文字列(歌詞を読み取る)を取得したいと思います。このコードを試してみましたが、出力を取得できなかったようです。

   <html>
<head> 
<script src="jquery-1.7.1.js"></script>
<script> 
$(document).ready(function () {
    $.ajax({
        type: "GET",
        url: "a.txt",
        dataType: "text",
        success: function (data) {
            parseLyric(data);
        }
    });
});

var _current_lyric = new Array();

function convertLRCLyric(inf) {
    inf += "n";
    var lyric = inf.match(/([(d{2}:d{2}(.d{1,2}){0,1})]){1,}W*n|([(d{2}:d{2}:d{2}(.d{1,2}){0,1})]){1,}W*n/ig);
    var l_s = '',
        l_tt, l_ww, l_i, l_ii;
    if (!lyric || !lyric.length) {
        return;
    }

    for (l_i = 0; l_i < lyric.length; l_i++) {
        l_tt = lyric[l_i].match(/([d{2}:d{2}(.d{1,2}){0,1}])|([d{2}:d{2}:d{2}(.d{1,2}){0,1}])/ig);
        l_ww = lyric[l_i].replace(/[S+]/ig, '').replace(/n{1,}/ig, '');
        for (l_ii = 0; l_ii < l_tt.length; l_ii++) {
            l_tt[l_ii] = l_tt[l_ii].replace(/[/,'').replace(/]/, '');
            if (l_tt[l_ii].search(/d{2}:d{2}:d{2}.d{2}/g) >= 0) {
                _current_lyric[l_tt[l_ii].substring(0, l_tt[l_ii].length - 1)] = l_ww;
            } else if (l_tt[l_ii].search(/d{2}:d{2}:d{2}.d{1}/g) >= 0) {
                _current_lyric[l_tt[l_ii]] = l_ww;
            } else if (l_tt[l_ii].search(/d{2}:d{2}:d{2}/g) >= 0) {
                _current_lyric[l_tt[l_ii] + ".0"] = l_ww;
            } else if (l_tt[l_ii].search(/d{2}:d{2}.d{2}/g) >= 0) {
                _current_lyric["00:" + l_tt[l_ii].substring(0, l_tt[l_ii].length - 1)] = l_ww;
            } else if (l_tt[l_ii].search(/d{2}:d{2}.d{1}/g) >= 0) {
                _current_lyric["00:" + l_tt[l_ii]] = l_ww;
            } else if (l_tt[l_ii].search(/d{2}:d{2}/g) >= 0) {
                _current_lyric["00:" + l_tt[l_ii] + ".0"] = l_ww;
            }
        }
    }
}

function parseLyric(allText) {
    _current_lyric = [];
    convertLRCLyric(allText);
    var ly = "";
    for (var time in _current_lyric) {
        ly += time + "--" + _current_lyric[time] + "n";
    }
    alert(ly);
}
</script>
</head>
<body>

</body>
</html>

しかし、私は空白のアラートを受け取り続けます。どんな助けでも素晴らしいでしょう。前もって感謝します 。

4

2 に答える 2

2

答え :

さて、私は自分のパーサーを作成しました。ここにコードがあります

var contents = " " ;
function readMultipleFiles(evt) {
    //Retrieve all the files from the FileList object
    var files = evt.target.files;

    if (files) {
        for (var i = 0, f; f = files[i]; i++) {
            var r = new FileReader();
            r.onload = (function (f) {
                return function (e) {
                    contents = e.target.result;
                   processData(contents);
                };
            })(f);
            r.readAsText(f);
        }
    } else {
        alert("Failed to load files");
    }
}
document.getElementById('fileinput').addEventListener('change', readMultipleFiles, false);



var allTextLines = " ";
var lyrics = [];
var tim = [] ;
var line = " ";


// parsing the Lyrics 
function processData(allText) { // This will only divide with respect to new lines 
    allTextLines = allText.split(/\r\n|\n/);

     next();
   } 
 function next()
 {
for (i=0;i<allTextLines.length;i++)
{
if (allTextLines[i].search(/^(\[)(\d*)(:)(.*)(\])(.*)/i)>=0 )// any line without the prescribed format wont enter this loop 
{
    line = allTextLines[i].match(/^(\[)(\d*)(:)(.*)(\])(.*)/i);
        tim[i] = (parseInt(line[2])*60)+ parseInt(line[4]); // will give seconds 
        lyrics[i]= line[6] ;//will give lyrics 

 }
 }  

  } 
于 2012-07-27T14:57:30.043 に答える
0

コードphp:フォーマット付き

public function get_lrc_song($song) {
    $lyrics_file = $song ['lyrics_file'];
    $json = curlClass::getInstance ( true )->fetchURL ( $lyrics_file );
    $content = explode ( "\n", $json );
    $regix = "$\][^>]+$";
    $result = "";
    foreach ( $content as $item ) {
        $isHas = preg_match ( $regix, $item, $data );
        $dt = str_replace ( "]", "", $data[0] );
        if ($dt != ""){
            $result .= $dt . "\n";
        }
    }
    echo $result;
}
于 2016-07-15T04:01:10.423 に答える