Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- ===========================================================================================================
- Lyriks 1.1 (build 20101021.1315) - 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.FoobarPath + "lyrics\\";
- var lyrics_dir2 = fb.Titleformat("$replace($replace(%path%,%filename_ext%,),\,\\)");
- //}}
- //{{
- // new objects
- sentence = function () {
- this.type = null;
- 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("segoe ui", 12, 0);
- 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, 130);
- g_ovbg_lineseparatorcolour = RGBA(000, 000, 000, 100);
- 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_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;
- var 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(tab, str, count, timer_prec, balise) {
- var tminutes, tsecondes, tcentiemes;
- var i;
- var f_sentence = new sentence;
- var b = balise - 1;
- if(g_lyrics_status==1 && balise>0) {
- if (str.substring(0,1)=="[") {
- tminutes = str.substring(1+(b*g_balise_char_offset), 3+(b*g_balise_char_offset));
- tsecondes = str.substring(4+(b*g_balise_char_offset), 6+(b*g_balise_char_offset));
- tcentiemes = str.substring(7+(b*g_balise_char_offset), 9+(b*g_balise_char_offset));
- if(IsNumeric(str.substring(1,2))==true) {
- f_sentence.type = "ly";
- f_sentence.timer = Math.round(tminutes)*60*100 + Math.round(tsecondes)*100 + Math.round(tcentiemes) - DEFAULT_OFFSET;
- f_sentence.text = remove_enhanced_balises(str.substring(g_balise_char_offset*g_balise_total, str.length));
- f_sentence.text = (f_sentence.text.length==0)?f_sentence.text+" ":f_sentence.text;
- } else {
- f_sentence.type = null;
- f_sentence.timer = 0;
- f_sentence.text = "";
- }
- } else {
- // no balise ==> line is set as a comment (as a blank line)
- if(count==0) g_lyrics_status = 2;
- f_sentence.type = null;
- f_sentence.timer = timer_prec;
- f_sentence.text = "";
- }
- } else {
- f_sentence.type = "tx";
- f_sentence.timer = 0;
- // check if it's not finally a synch lyrics (lrc) with some first lines with no timestamp!
- if (str.substring(0,1)=="[") {
- // test balise (=ts) type is ok ( [99:99.999] )
- if (ts_analyzer(str).substring(9,10)=="]") {
- g_lyrics_status = 1;
- str = ts_analyzer(str);
- tminutes = str.substring(1+(b*g_balise_char_offset), 3+(b*g_balise_char_offset));
- tsecondes = str.substring(4+(b*g_balise_char_offset), 6+(b*g_balise_char_offset));
- tcentiemes = str.substring(7+(b*g_balise_char_offset), 9+(b*g_balise_char_offset));
- f_sentence.type = "ly";
- f_sentence.timer = Math.round(tminutes)*60*100 + Math.round(tsecondes)*100 + Math.round(tcentiemes) - DEFAULT_OFFSET;
- f_sentence.text = remove_enhanced_balises(str.substring(g_balise_char_offset*g_balise_total, str.length));
- f_sentence.text = (f_sentence.text.length==0)?f_sentence.text+" ":f_sentence.text;
- } else {
- f_sentence.text = str;
- }
- } else {
- f_sentence.text = str;
- }
- }
- return f_sentence;
- }
- function load_file(filePath, fileName) {
- var tab = Array();
- var fline = new sentence;
- var count = 0;
- var enr = 0;
- var str="";
- var balise;
- var delta;
- g_file = open_file(filePath, fileName, ForReading);
- g_balise_shift = 0;
- while(!g_file.AtEndOfStream) {
- str = g_file.ReadLine();
- if(g_lyrics_status==1) {
- if (str.substring(0,1)=="[") {
- str = ts_analyzer(str);
- g_balise_total = 0;
- balise = 0;
- while(str.substring(balise*10,balise*10+1)=="[") {
- balise += 1;
- }
- g_balise_total = balise;
- } else if(enr==0) {
- g_lyrics_status = 2;
- g_balise_total = 1;
- }
- } else {
- g_balise_total = 1;
- }
- if(g_balise_total>1) g_multi_balise = true; else g_multi_balise = false;
- // str loop for each timestamp found for it ==> occurs created in the array
- for (balise=1;balise<=g_balise_total;balise++) {
- fline=grab_timer(tab, str, count, (count>0)?tab[count-1].timer:0, balise);
- if(fline.type!=null) {
- tab.push(fline);
- count++;
- }
- }
- enr += 1;
- }
- close_file(g_file);
- // if file read is empty, set lyrics as not found to avoid script errors
- if(count==0) {
- g_lyrics_status = 0;
- 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);
- return g_tab;
- } else {
- // add a default last sentence with a timer maximum (for ease of use focus line search method)
- tab.push(new sentence);
- tab[count].type = "ly";
- tab[count].timer = 9999999;
- tab[count].text = "---";
- tab[count].total_lines = 1;
- tab[count].ante_lines = tab[count-1].ante_lines + tab[count-1].total_lines;
- return sort_tab(tab);
- }
- }
- function parse_tag(tag) {
- 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)=="["))) {
- t_tab.push(tag.substring(j, i));
- if(tag.charCodeAt(i)!=10) {
- j = i;
- } else {
- j = i+1;
- }
- }
- }
- return parse_line(t_tab);
- }
- function parse_line(tagtab) {
- var tab = Array();
- var fline = new sentence;
- var count = 0;
- var enr = 0;
- var str="";
- var balise;
- var delta;
- g_balise_shift = 0;
- for(enr=0;enr<tagtab.length;enr++) {
- str = tagtab[enr];
- if(g_lyrics_status==1) {
- if (str.substring(0,1)=="[") {
- str = ts_analyzer(str);
- g_balise_total = 0;
- balise = 0;
- while(str.substring(balise*10,balise*10+1)=="[") {
- balise += 1;
- }
- g_balise_total = balise;
- } else if(enr==0) {
- g_lyrics_status = 2;
- g_balise_total = 1;
- }
- } else {
- g_balise_total = 1;
- }
- if(g_balise_total>1) g_multi_balise = true; else g_multi_balise = false;
- // str loop for each timestamp found for it ==> occurs created in the array
- for (balise=1;balise<=g_balise_total;balise++) {
- fline=grab_timer(tab, str, count, (count>0)?tab[count-1].timer:0, balise);
- if(fline.type!=null) {
- tab.push(fline);
- count++;
- }
- }
- }
- // if file read is empty, set lyrics as not found to avoid script errors
- if(count==0) {
- g_lyrics_status = 0;
- 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);
- return g_tab;
- } else {
- // add a default last sentence with a timer maximum (for ease of use focus line search method)
- tab.push(new sentence);
- tab[count].type = "ly";
- tab[count].timer = 9999999;
- tab[count].text = "---";
- tab[count].total_lines = 1;
- tab[count].ante_lines = tab[count-1].ante_lines + tab[count-1].total_lines;
- return sort_tab(tab);
- }
- }
- function load_track_info() {
- var tab = Array(new sentence, new sentence, new sentence, new sentence);
- var count = 0;
- tab[count].type = "tx";
- tab[count].text = "---";
- count++;
- tab[count].type = "tx";
- tab[count].text = artist.Eval();
- count++;
- tab[count].type = "tx";
- tab[count].text = title.Eval();
- count++;
- tab[count].type = "tx";
- 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 get_lyrics() {
- var i=0;
- var nbl=0;
- var delta;
- var tag;
- var bool_tag = 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 in music folder (filename syntax #1)
- g_lyrics_status=null;
- g_lyrics_filename = artist.Eval() + " -" + title.Eval();
- if(file_exists(lyrics_dir2.EvalWithMetadb(g_metadb)+g_lyrics_filename+".lrc")) {
- g_lyrics_filename = g_lyrics_filename+".lrc";
- g_lyrics_status = 1;
- g_lyrics_path = lyrics_dir2.EvalWithMetadb(g_metadb);
- } else {
- if(file_exists(lyrics_dir2.EvalWithMetadb(g_metadb)+g_lyrics_filename+".txt")) {
- g_lyrics_filename = g_lyrics_filename+".txt";
- g_lyrics_status = 2;
- g_lyrics_path = lyrics_dir2.EvalWithMetadb(g_metadb);
- }
- }
- // check files in music folder (filename syntax #2)
- if(g_lyrics_status==null) {
- g_lyrics_filename = artist.Eval() + " - " + title.Eval();
- if(file_exists(lyrics_dir2.EvalWithMetadb(g_metadb)+g_lyrics_filename+".lrc")) {
- g_lyrics_filename = g_lyrics_filename+".lrc";
- g_lyrics_status = 1;
- g_lyrics_path = lyrics_dir2.EvalWithMetadb(g_metadb);
- } else {
- if(file_exists(lyrics_dir2.EvalWithMetadb(g_metadb)+g_lyrics_filename+".txt")) {
- g_lyrics_filename = g_lyrics_filename+".txt";
- g_lyrics_status = 2;
- g_lyrics_path = lyrics_dir2.EvalWithMetadb(g_metadb);
- }
- }
- }
- // if not found, check in lyrics folder (filename syntax #1)
- if(g_lyrics_status==null) {
- g_lyrics_filename = artist.Eval() + " -" + title.Eval();
- if(file_exists(lyrics_dir1+g_lyrics_filename+".lrc")) {
- g_lyrics_filename = g_lyrics_filename+".lrc";
- g_lyrics_status = 1;
- g_lyrics_path = lyrics_dir1;
- } else {
- if(file_exists(lyrics_dir1+g_lyrics_filename+".txt")) {
- g_lyrics_filename = g_lyrics_filename+".txt";
- g_lyrics_status = 2;
- g_lyrics_path = lyrics_dir1;
- }
- }
- }
- // if not found, check in lyrics folder (filename syntax #2)
- if(g_lyrics_status==null) {
- g_lyrics_filename = artist.Eval() + " - " + title.Eval();
- if(file_exists(lyrics_dir1+g_lyrics_filename+".lrc")) {
- g_lyrics_filename = g_lyrics_filename+".lrc";
- g_lyrics_status = 1;
- g_lyrics_path = lyrics_dir1;
- } else {
- if(file_exists(lyrics_dir1+g_lyrics_filename+".txt")) {
- g_lyrics_filename = g_lyrics_filename+".txt";
- g_lyrics_status = 2;
- g_lyrics_path = lyrics_dir1;
- } else {
- g_lyrics_status = 0;
- g_lyrics_path = null;
- }
- }
- }
- }
- // if lyrics found
- if(g_lyrics_status>0) {
- 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);
- }
- }
- }
- 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
- if(ctab[i].type!=null) {
- 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]);
- }
- tab = calc_lines(tab);
- 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;
- var ch;
- var str2 = "";
- var state=0;
- var deb = -1;
- var fin = -1;
- var sep1 = -1;
- var sep2 = -1;
- var ts_len;
- var suite=0;
- for(i=0;i<str.length;i++) {
- ch = str.substring(i, i+1);
- switch(state) {
- case 0:
- if(ch=="[") {
- 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;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement