a lrc file shows wrong when 01:00.00
please check it
song:download
lrc file:download
i'll check it asap (maybe a bug fixed yesterday for some kind of ts!!!), thanks for reporting, update to come with the fix
Error: WSH Panel Mod ({96603E1C-15B1-4657-BEB3-A2A5389CA2BF}): Microsoft JScript 运行时错误:
无效的过程调用或参数
Ln: 769, Col: 5
<source text only available in compile time>
Ln: 769 is
var tpath = Array(lyrics_dir1.EvalWithMetadb(g_metadb), lyrics_dir2);
/*
====================================================================================================
=======
Lyriks 1.2 (build 20101023.1300) - a WSH lyrics module by Br3tt
- This WSH script get lyrics from TAG first then from local file in Music folder then in foobar2000\lyrics\ and finally
it displays them (scrolling+sync)
- It handles TXT and LRC format (sync handled), but not the LRC Enhanced format (translated to simple LRC format)
- exotics timestamps are now handled (like [9:99], [99:99.999], [9:99.999], [99:99:999] ...)
- filenames supported are : <%artist%> -<%title%>.lrc (or .txt) AND <%artist%> - <%title%>.lrc (or .txt)
- Comments, Blank lines (no timestamp) and Info lines (ar:, ti, ...) are ignored.
- Manual Scrolling possible with the mousewheel (double click on the panel to re-center on the active line)
- Requirements :
1) foobar2000
2) WSH Panel Mod component
3) this script!
4) Optional: a lyrics grabber (i.e: Lyric Show Panel by hidding the panel, foo_lyricsDB, ...)
- Some settings are available by using the panel Properties (right click on WSH panel -> Properties)
- This script don't make any changes to your files and write nothing on your system, except the creation of the folder
foobar2000/lyrics if not found
====================================================================================================
=======
*/
// Text formatting function
// {{
function StringFormat() {
var h_align = 0, v_align = 0, trimming = 0, flags = 0;
switch (arguments.length)
{
// fall-thru
case 4:
flags = arguments[3];
case 3:
trimming = arguments[2];
case 2:
v_align = arguments[1];
case 1:
h_align = arguments[0];
break;
default:
return 0;
}
return ((h_align << 28) | (v_align << 24) | (trimming << 20) | flags);
}
StringAlignment = {
Near: 0,
Centre: 1,
Far: 2
};
var lt_stringformat = StringFormat(StringAlignment.Near, StringAlignment.Near);
var ct_stringformat = StringFormat(StringAlignment.Centre, StringAlignment.Near);
var rt_stringformat = StringFormat(StringAlignment.Far, StringAlignment.Near);
var lc_stringformat = StringFormat(StringAlignment.Near, StringAlignment.Centre);
var cc_stringformat = StringFormat(StringAlignment.Centre, StringAlignment.Centre);
var rc_stringformat = StringFormat(StringAlignment.Far, StringAlignment.Centre);
var lb_stringformat = StringFormat(StringAlignment.Near, StringAlignment.Far);
var cb_stringformat = StringFormat(StringAlignment.Centre, StringAlignment.Far);
var rb_stringformat = StringFormat(StringAlignment.Far, StringAlignment.Far);
// }}
// Use with GdiDrawText()
// {{
var DT_LEFT = 0x00000000;
var DT_RIGHT = 0x00000002;
var DT_TOP = 0x00000000;
var DT_CENTER = 0x00000001;
var DT_VCENTER = 0x00000004;
var DT_WORDBREAK = 0x00000010;
var DT_CALCRECT = 0x00000400;
var DT_NOPREFIX = 0x00000800;
var DT_END_ELLIPSIS = 0x00008000;
// }}
//{{
// IO Mode
var ForReading = 1;
var ForWriting = 2;
var ForAppending = 8;
//}}
//{{
// Paths
var lyrics_dir1 = fb.Titleformat("$replace($replace(%path%,%filename_ext%,),\,\\)");
var lyrics_dir2 = fb.FoobarPath + "lyric\\";
//}}
//{{
// new objects
sentence = function () {
this.timer = 0;
this.text = "";
this.total_lines = 0;
this.ante_lines = 0;
}
//}}
function RGBA(r, g, b, a) {
return ((a << 24) | (r << 16) | (g << 8) | (b));
}
// ================================================/ TF
var len = fb.Titleformat("%length%");
var elap = fb.TitleFormat("%playback_time%");
var remain = fb.TitleFormat("%playback_time_remaining%");
var len_seconds = fb.Titleformat("%length_seconds%");
var elap_seconds = fb.TitleFormat("%playback_time_seconds%");
var remain_seconds = fb.Titleformat("%playback_time_remaining_seconds%");
var artist = fb.Titleformat("$replace(%artist%,'/','_')");
var title = fb.Titleformat("%title%");
var lyrics = fb.TitleFormat("[$if2(%LYRICS%,$if2(%LYRIC%,$if2(%UNSYNCED LYRICS%,%UNSYNCED LYRIC%)))]");
// ================================================/ Declarations
var g_font = gdi.Font("calibri", 12, 2);
var g_playtimer;
var g_metadb;
var ww = 0, wh = 0;
var PLAYTIMER_VALUE = window.GetProperty("Timer value in ms [10;100]", 10);
var LINE_HEIGHT = window.GetProperty("Line height [20;30]", 24);
var TEXT_SHADOW = window.GetProperty("Text shadow (true/false)", true);
var PLAIN_COLOR_BG = window.GetProperty("Plain colour background (true/false)", false);
var DITHER = window.GetProperty("Top & Botom dither (true/false)", true);
var H_PADDING = window.GetProperty("Horizontal padding [0;20]", 20);
var TXT_ALIGN = window.GetProperty("Text alignment (left/center/right)", "center");
var LIGHT_BG = window.GetProperty("Light background", true);
var DEBUG = false;
var DEFAULT_OFFSET = 29;
var g_fso = new ActiveXObject("Scripting.FileSystemObject");
var g_file = null;
var g_tab = Array();
var g_scroll=0;
var g_lyrics_path;
var g_lyrics_filename;
var g_lyrics_status;
var focus=0;
var focus_next=0;
var g_plainbg_colour;
var g_ovbg_normalcolour;
var g_ovbg_lineseparatorcolour;
var g_ovbg_highlightcolour;
var g_txt_normalcolour;
var g_txt_highlightcolour;
var g_txt_shadowcolour;
var centiemes = 0;
var g_is_scrolling = false;
var g_multi_balise = false;
var g_balise_total;
var g_balise_char_offset = 10;
var g_tab_length;
var g_txt_align;
var midpoint;
var pos;
// START
function on_size() {
var k;
ww = window.Width;
wh = window.Height;
g_metadb = fb.IsPlaying ? fb.GetNowPlaying() : false;
// exit test on useless calls made (wsh tweak)
if(!ww && !wh) return true;
midpoint = wh / 2 - LINE_HEIGHT / 2;
// colour definitions
// g_plainbg_colour = RGBA(140, 200, 250, 255);
// g_ovbg_normalcolour = RGBA(000, 000, 000, 255);
// g_ovbg_lineseparatorcolour = RGBA(000, 000, 000, 255);
// g_ovbg_highlightcolour = RGBA(020, 100, 240, 130);
// g_txt_normalcolour = RGBA(200, 200, 210, 255);
// g_txt_highlightcolour = RGBA(255, 255, 255, 255);
// g_txt_shadowcolour = RGBA(000, 000, 000, 150);
g_plainbg_colour = RGBA(140, 200, 250, 255);
g_ovbg_normalcolour = RGBA(255, 255, 255, 255);
g_ovbg_lineseparatorcolour = RGBA(255, 255, 255, 255);
g_ovbg_highlightcolour = RGBA(255, 255, 255, 255);
g_txt_normalcolour = RGBA(120, 120,120, 255);
// g_txt_highlightcolour = RGBA(148,148,239, 255);
g_txt_highlightcolour = RGBA(0,128,255, 255);
g_txt_shadowcolour = RGBA(255, 255, 255, 200);
g_playtimer && window.KillTimer(g_playtimer);
if(fb.IsPlaying||fb.IsPaused) {
g_scroll=0;
g_is_scrolling = false;
get_lyrics();
change_focus();
k = g_tab[focus].ante_lines * LINE_HEIGHT;
if(g_lyrics_status>0) {
pos = midpoint - k;
g_playtimer = window.CreateTimerInterval(PLAYTIMER_VALUE);
} else {
delta = (g_tab[g_tab.length-1].ante_lines + g_tab[g_tab.length-1].total_lines);
pos = (wh / 2) - (delta * LINE_HEIGHT / 2);
}
}
}
function on_paint(gr) {
PLAIN_COLOR_BG && gr.FillSolidRect(0, 0, ww, wh, g_plainbg_colour);
if(fb.IsPlaying||fb.IsPaused) {
show_lyrics(gr, g_tab, pos);
DEBUG && gr.GdiDrawText(g_lyrics_status.toString(), g_font, g_normalcolour, 5, 5, ww, LINE_HEIGHT, DT_TOP |
DT_LEFT | DT_WORDBREAK | DT_CALCRECT | DT_NOPREFIX);
}
DITHER && gr.FillGradRect(0, 0, ww, 11, 90, g_txt_shadowcolour, RGBA(0,0,0,0));
DITHER && gr.FillGradRect(0, wh-11, ww, 11, 270, g_txt_shadowcolour, RGBA(0,0,0,0));
DITHER && gr.FillGradRect(0, 0, ww, 1, 90, g_txt_shadowcolour, RGBA(0,0,0,0));
DITHER && gr.FillGradRect(0, wh-2, ww, 1, 90, RGBA(0,0,0,0), g_txt_shadowcolour);
}
function on_mouse_lbtn_dblclk(x, y, mask) {
on_size();
}
function on_mouse_leave() {
window.Repaint();
}
function on_playback_time(time) {
// at each new seconde, centiemes is reset to 0 (Increment on timer every 100ms)
centiemes = 0;
if(g_lyrics_status==0) {
if(elap_seconds.Eval()==3) {
on_size();
}
window.Repaint();
}
}
function on_playback_new_track(info) {
g_metadb = fb.IsPlaying ? fb.GetNowPlaying() : false;
g_playtimer && window.KillTimer(g_playtimer);
pos=0;
g_scroll = 0;
g_is_scrolling = false;
get_lyrics();
change_focus();
if(g_lyrics_status>0) {
g_playtimer = window.CreateTimerInterval(PLAYTIMER_VALUE);
}
}
function on_playback_seek(time) {
var k;
if(g_lyrics_status>0) {
g_scroll = 0;
g_is_scrolling = false;
change_focus();
k = g_tab[focus].ante_lines * LINE_HEIGHT;
pos = midpoint - k;
window.Repaint();
}
}
function on_playback_stop(reason) {
g_metadb = fb.IsPlaying ? fb.GetNowPlaying() : false;
g_playtimer && window.KillTimer(g_playtimer);
if(reason==0) {
// Stop
window.Repaint();
}
}
function on_mouse_wheel(delta) {
if(g_lyrics_status>0) {
if(delta>0) {
pos = (pos>=midpoint)?pos:pos + LINE_HEIGHT;
} else {
pos = (pos<=(wh/2 - g_tab_length*LINE_HEIGHT))?pos:pos - LINE_HEIGHT;
}
window.Repaint();
}
}
function on_timer(id) {
var t1 = elap_seconds.Eval() * 100 + centiemes;
var t2 = len_seconds.Eval() * 100;
var p1, p2;
if(t1>t2-100) {
g_playtimer && window.KillTimer(g_playtimer);
}
if(g_playtimer) {
if(g_playtimer.ID == id) {
if(!g_is_scrolling && t1>=g_tab[focus_next].timer) {
p1 = g_tab[focus].ante_lines*LINE_HEIGHT;
p2 = g_tab[focus_next].ante_lines*LINE_HEIGHT;
g_scroll = p2 - p1;
change_focus();
g_is_scrolling = true;
}
if (g_scroll>0) {
pos -= 1;
g_scroll -= 1;
window.Repaint();
} else {
g_is_scrolling = false;
}
centiemes = (centiemes>98)?0:(centiemes+1);
}
}
}
function show_lyrics(gr, tab, posy) {
var i, k, text_colour;
gr.SetTextRenderingHint(5);
// decoding text alignment (from Properties)
switch(TXT_ALIGN.toUpperCase()) {
case "LEFT":
g_txt_align = lc_stringformat;
break;
case "CENTER":
g_txt_align = cc_stringformat;
break;
case "RIGHT":
g_txt_align = rc_stringformat;
break;
default:
g_txt_align = cc_stringformat;
}
if(g_lyrics_status>0) {
if(posy>=0) {
LIGHT_BG && gr.FillSolidRect(0, Math.floor(posy - wh/2), ww, Math.floor(wh/2), g_ovbg_normalcolour);
}
} else {
LIGHT_BG && gr.FillSolidRect(0, 0, ww, wh, g_ovbg_normalcolour);
}
for(i=0;i<tab.length;i++) {
if(Math.round(posy)>=(LINE_HEIGHT*-4) && Math.round(posy)<wh) {
if(i==focus && g_lyrics_status==1) {
text_colour = g_txt_highlightcolour;
} else {
if(g_lyrics_status==0) {
text_colour = g_txt_highlightcolour;
} else {
text_colour = g_txt_normalcolour;
}
}
if(g_lyrics_status>0) {
if(!LIGHT_BG && i==focus && tab[i].text.length>1 && g_lyrics_status==1) {
gr.FillSolidRect(0, Math.floor(posy), ww, (tab[i].total_lines*LINE_HEIGHT), g_ovbg_highlightcolour);
} else {
LIGHT_BG && gr.FillSolidRect(0, Math.floor(posy), ww, (tab[i].total_lines*LINE_HEIGHT-1), (i==focus
&& tab[i].text.length>1 && g_lyrics_status==1)?g_ovbg_highlightcolour:g_ovbg_normalcolour);
LIGHT_BG && gr.FillSolidRect(0, Math.floor(posy+(tab[i].total_lines*LINE_HEIGHT-1)), ww, 1,
g_ovbg_lineseparatorcolour);
}
}
TEXT_SHADOW && gr.DrawString(tab[i].text, g_font, g_txt_shadowcolour, 1+H_PADDING, Math.floor(posy)-1, ww-
H_PADDING*2, (tab[i].total_lines*LINE_HEIGHT), g_txt_align);
TEXT_SHADOW && gr.DrawString(tab[i].text, g_font, g_txt_shadowcolour, 1+H_PADDING, Math.floor(posy), ww-
H_PADDING*2, (tab[i].total_lines*LINE_HEIGHT), g_txt_align);
gr.DrawString(tab[i].text, g_font, text_colour, 0+H_PADDING, Math.floor(posy)-1, ww-H_PADDING*2, (tab
[i].total_lines*LINE_HEIGHT), g_txt_align);
}
posy = Math.floor(posy+LINE_HEIGHT+((tab[i].total_lines-1)*LINE_HEIGHT));
}
if(g_lyrics_status>0 && posy<=wh) {
LIGHT_BG && gr.FillSolidRect(0, Math.floor(posy), ww, Math.floor(wh), g_ovbg_normalcolour);
}
}
function grab_timer(t_tab) {
var tminutes, tsecondes, tcentiemes;
var i, k, f_sentence, b, c, delta, repeat_text;
var tab = Array();
for(i=0;i<t_tab.length;i++) {
if(g_lyrics_status==1) {
// -----------
// sync lyrics
// -----------
if(IsTimestamped(t_tab[i])) {
b = 0;
while(t_tab[i].substring(b*10, b*10+1)=="[") {
b++;
}
c = b;
repeat_text = remove_enhanced_balises(t_tab[i].substring(c*10, t_tab[i].length));
if(repeat_text.length==0) repeat_text = repeat_text + " ";
for(b=0;b<c;b++) {
f_sentence = new sentence;
tminutes = t_tab[i].substring(1+(b*10), 3+(b*10));
tsecondes = t_tab[i].substring(4+(b*10), 6+(b*10));
tcentiemes = t_tab[i].substring(7+(b*10), 9+(b*10));
f_sentence.timer = Math.round(tminutes)*60*100 + Math.round(tsecondes)*100 + Math.round(tcentiemes)
- DEFAULT_OFFSET;
if(f_sentence.timer<0) f_sentence.timer=0;
f_sentence.text = repeat_text;
tab.push(f_sentence);
}
}
} else {
// -------------
// unsync lyrics
// -------------
if(IsTimestamped(t_tab[i])) {
// if sync line in unsync lyrics, i remove timestamps in this line
b = 0;
while(IsTimestamped(t_tab[i].substring(b*10, b*10+10))) {
b++;
}
t_tab[i] = t_tab[i].substring(b*10, t_tab[i].length);
}
f_sentence = new sentence;
f_sentence.timer = 0;
f_sentence.text = t_tab[i];
tab.push(f_sentence);
}
}
if(tab.length==0) {
g_lyrics_status = 0;
tab = load_track_info();
delta = (tab[tab.length-1].ante_lines + tab[tab.length-1].total_lines);
pos = (wh / 2) - (delta * LINE_HEIGHT / 2);
} else {
f_sentence = new sentence;
f_sentence.timer = 9999999;
f_sentence.text = "---";
tab.push(f_sentence);
}
CollectGarbage();
return calc_lines(sort_tab(tab));
}
function load_file(filePath, fileName) {
var i;
var t_tab = Array();
var str;
g_file = open_file(filePath, fileName, ForReading);
while(!g_file.AtEndOfStream) {
str = g_file.ReadLine();
// blank lines are ignored
if(str.length>0) t_tab.push(str);
}
close_file(g_file);
return grab_timer(check_lyrics_type(t_tab));
}
function check_lyrics_type(t_tab) {
var i;
var count = 0;
var ts_percent;
var tab = Array();
for(i=0;i<t_tab.length;i++) {
if(IsTimestamped(t_tab[i])) {
// format timestamps to default syntax : [99:99.99]
tab.push(ts_analyzer(t_tab[i]));
// count # of sync lines
count++;
} else {
if(t_tab[i].length>0) tab.push(t_tab[i]);
}
}
// calc percent of sync lines, if more than 50% of the total filled lines, it's sync lyrics, else, unsync lyrics!
ts_percent = Math.round(count/tab.length*100);
if(ts_percent>50) {
// sync lyrics
g_lyrics_status = 1;
} else {
// unsync lyrics
g_lyrics_status = 2;
}
return t_tab;
}
function parse_tag(tag, delimiter) {
var t_tab = Array();
var i, j;
j = 0;
for(i=0;i<tag.length;i++) {
if(i==tag.length-1 || tag.charCodeAt(i)==10 || (i>0 && (i<tag.length-5) && (tag.substring(i, i+1)==delimiter) &&
(tag.substring(i-1, i)!="]"))) {
if(i==tag.length-1) {
t_tab.push(tag.substring(j, i+1));
} else {
t_tab.push(tag.substring(j, i));
}
if(tag.charCodeAt(i)!=10) {
j = i;
} else {
j = i+1;
}
}
}
return grab_timer(check_lyrics_type(t_tab));
}
function load_track_info() {
var tab = Array(new sentence, new sentence, new sentence, new sentence);
var count = 0;
tab[count].text = "---";
count++;
tab[count].text = artist.Eval();
count++;
tab[count].text = title.Eval();
count++;
tab[count].text = "---";
count++;
return calc_lines(tab);
}
function open_file(filePath, fileName, ioMode) {
var fileInst = null;
var bool = file_exists(filePath + fileName);
if(bool) {
fileInst = g_fso.OpenTextFile(filePath + fileName, ioMode);
}
return fileInst;
}
function close_file(fileInst) {
fileInst.Close();
}
function read_file(fileInst) {
var line = fileInst.ReadLine();
return line;
}
function folder_exists(folderPath) {
var fso, bool;
fso = new ActiveXObject("Scripting.FileSystemObject");
bool = fso.FolderExists(folderPath);
return bool;
}
function file_exists(filePath) {
var fso, bool;
fso = new ActiveXObject("Scripting.FileSystemObject");
bool = fso.Fileexists(filePath);
return bool;
}
function lyrics_folder_exists(folder_name) {
var fso;
var bool=1;
fso = new ActiveXObject("Scripting.FileSystemObject");
if (folder_exists(fb.ProfilePath + folder_name) == false) {
fso.CreateFolder(fb.ProfilePath + folder_name);
bool=0;
}
return bool;
}
function change_focus() {
var i, j;
var t1 = elap_seconds.Eval()*100+centiemes;
if(g_lyrics_status>0) {
// search line index just after actual timer
for(i=0;i<g_tab.length;i++) {
if(g_tab[i].timer>t1) break;
}
focus_next=i;
focus = (i>0)?i-1:0;
// now i check if there are more than one line with the same timer as focus one & if found, i take it as new
focus 'cause it's the first (not a blank line)
if(focus>0) {
for(i=0;i<focus;i++) {
if(g_tab[i].timer==focus) {
focus = i;
break;
}
}
}
}
}
function calc_lines(ctab) {
var i, j;
var padx = 0;
var tmp_img;
var gp;
var lineh;
g_tab_length = 0;
if(ww==0) return ctab; // test to avoid errors if panel is hidden (ww=0)
tmp_img = gdi.CreateImage(ww-(H_PADDING*2)-padx, 100);
gp = tmp_img.GetGraphics();
for(i=0;i<ctab.length;i++) {
// calc sentence #lines to display / window.width
lineh = gp.MeasureString(ctab[i].text, g_font, 0, 0, ww-(H_PADDING*2)-padx, wh).Height;
ctab[i].total_lines = (lineh/LINE_HEIGHT) > Math.floor(lineh/LINE_HEIGHT) ? Math.floor(lineh/LINE_HEIGHT) + 1 :
Math.floor(lineh/LINE_HEIGHT) ;
ctab[i].ante_lines = 0;
for(j=0;j<i;j++) {
ctab[i].ante_lines += ctab[j].total_lines;
}
g_tab_length += ctab[i].total_lines;
}
CollectGarbage();
return ctab;
}
function sort_tab(tab2sort) {
var tab = Array();
var i, j;
var tmp = new sentence;
var smallest = 0;
for(i=0;i<tab2sort.length;i++) {
for(j=i;j<tab2sort.length;j++) {
if(tab2sort[i].timer > tab2sort[j].timer) {
tmp = tab2sort[i];
tab2sort[i] = tab2sort[j];
tab2sort[j] = tmp;
}
}
tab.push(tab2sort[i]);
}
return tab;
}
function remove_enhanced_balises(str) {
var i;
var chr1, chr2;
var new_str="";
for(i=0;i<str.length;i++) {
chr1 = str.substring(i, i+1);
if(i+10<=str.length) chr2 = str.substring(i+9, i+10); else chr2=null;
if(chr1=="<" && chr2==">") {
i = i + 10 - 1;
} else {
new_str = new_str + chr1;
}
}
return new_str;
}
function ts_analyzer(str) {
var i, j, ch, ts_len;
var str2 = "";
var state=0;
var deb = -1;
var fin = -1;
var sep1 = -1;
var sep2 = -1;
var suite=0;
for(i=0;i<str.length;i++) {
ch = str.substring(i, i+1);
switch(state) {
case 0:
if(ch=="[" && IsNumeric(str.substring(i+1, i+2))) {
state=1;
deb=i;
fin=-1;
}
break;
case 1:
if(deb>=0 && ch==":") {
state=2;
sep1=i;
}
if(i>deb+3) {
deb=-1;
fin=-1;
sep1=-1;
sep2=-1;
state=0;
}
break;
case 2:
if(sep1>=0 && (ch==":" || ch==".")) {
state=3;
sep2=i;
}
if(sep1>=0 && sep2==-1 && ch=="]") {
state=4;
fin=i;
}
if(i>sep1+3) {
deb=-1;
fin=-1;
sep1=-1;
sep2=-1;
state=0;
}
break;
case 3:
if(deb>=0 && ch=="]") {
state=4;
if(i==str.length-1) {
str=str+" ";
}
fin=i;
}
if(i>deb+10) {
deb=-1;
fin=-1;
sep1=-1;
sep2=-1;
state=0;
}
break;
case 4:
ts_len=fin-deb+1;
switch(ts_len) {
case 6:
str2 = str2 + "[0" + str.substring(deb+1,deb+2) + ":" + str.substring(deb+3, deb+5) + ".00]";
break;
case 7:
str2 = str2 + str.substring(deb,deb+6) + ".00]";
break;
case 9:
str2 = str2 + "[0" + str.substring(deb+1,deb+2) + ":" + str.substring(deb+3, deb+5) + "." +
str.substring(deb+6, deb+8) + "]";
break;
case 10:
if(sep1==deb+2) {
str2 = str2 + "[0" + str.substring(deb+1,deb+2) + ":" + str.substring(deb+3, deb+5) + "." +
str.substring(deb+6, deb+8) + "]";
} else {
str2 = str2 + str.substring(deb,deb+10);
}
break;
case 11:
str2 = str2 + str.substring(deb,deb+9) + "]";
break;
}
j += 10;
if(str.substring(fin+1,fin+2)=="[") {
suite = 1;
i = fin;
deb = -1;
fin = -1;
sep1 = -1;
sep2 = -1;
state = 0;
} else {
suite = -1;
i = str.length - 1;
str2 = str2 + str.substring(fin+1, str.length);
}
break;
}
}
return str2;
}
function IsNumeric(str) {
var ValidChars = "0123456789.";
for (i = 0; i < str.length; i++) {
if (ValidChars.indexOf(str.charAt(i)) == -1) {
return false;
}
}
return true;
}
function IsTimestamped(str) {
var ValidChars = "[0123456789:.]";
var count = 0;
for (i = 0; i < (str.length>10?10:str.length); i++) {
if (ValidChars.indexOf(str.charAt(i)) >=0) {
count++;
}
}
if(count>=6 && count <=11) {
return true;
} else {
return false;
}
}
function check_file(path, filename) {
if(file_exists(path+filename+".lrc")) {
g_lyrics_filename = filename+".lrc";
g_lyrics_path = path;
return true;
} else {
if(file_exists(path+filename+".txt")) {
g_lyrics_filename = filename+".txt";
g_lyrics_path = path;
return true;
}
}
return false;
}
function get_lyrics() {
var i, count, delta, tag;
var tpath = Array(lyrics_dir1.EvalWithMetadb(g_metadb), lyrics_dir2);
var tfilename= Array(artist.Eval() + " -" + title.Eval(), artist.Eval() + " - " + title.Eval());
var bool_tag = false;
var bool_file = false;
// reset lyrics tab
g_lyrics_status = 0;
if(g_tab.length>0) g_tab.splice(0, g_tab.length);
pos = midpoint;
focus = 0;
window.Repaint();
// check TAGs
tag = lyrics.Eval();
if(tag.length>0) {
bool_tag = true;
if(tag.substring(0,1)=="[") g_lyrics_status = 1; else g_lyrics_status = 2;
} else {
// check files
i = 0;
while(!bool_file && i<2) {
j = 0;
while(!bool_file && j<2) {
bool_file = check_file(tpath[i], tfilename[j]);
j++;
}
i++;
}
}
// if lyrics found
if(bool_tag || bool_file) {
if(bool_tag) {
g_tab = parse_tag(tag, "[");
} else {
g_tab = load_file(g_lyrics_path, g_lyrics_filename);
}
} else {
g_tab = load_track_info();
delta = (g_tab[g_tab.length-1].ante_lines + g_tab[g_tab.length-1].total_lines);
pos = (wh / 2) - (delta * LINE_HEIGHT / 2);
}
if(g_lyrics_status==2) {
for(i=0;i<g_tab.length-1;i++) {
g_tab[i].timer = i * Math.floor(len_seconds.Eval() * 100 / g_tab.length);
}
}
}