Результатов поиска: 240: Biography

Поисковый запрос: biography

Re: Скрипты для foo_uie_wsh_panel_mod

kgena_ua, приветствую. Ещё не проверил это дополнение к "Biography Text & Album Info & Picture от 18112016". Поэтому вы может уже всё реализовали.
kgena_ua:Нужно загружать все изображения (лимит максимальный)
Я по этому вопросу тему изучал. Как проверял. Эту тему как раз отправлял seriousstas в письме, но он только его сейчас получил, цитирую:

Для проверки своей версии дополнил строку "контекстного меню" выхода на ластфм. Понятное дело это не катит для использования, для альбомов содержащих больше одного слова надо + между словами ставить. Но к примеру возьмём Madonna - MDNA:
Код: Выделить всё
    case 16:
        var album = fb.TitleFormat("[%album%]").Eval();
        WshShell.run("http://www.last.fm/" + lang_query[lang] + "music/" + encodeURIComponent(artist) + "/" + album + "/+images/");
        break;
И попадаем сразу сюда: Обложка MDNA -- last.fm
То есть поисковый запрос делать сразу на страницу с альбомом, если это не радио, а уже потом загружать остальные картинки альбомов - пока не понимаю в каком порядке, так что бы картинка не попала в дубль ну вы поняли.
Ночью, как закончу с закачками, покопаюсь в вашем дополнении.
seriousstas, ковырял твой новый мод. Ты в полевых условиях(в машине) гонял его? Это я про новою возможность разворачивания текста половины. Ладно потом в лс отпишусь)))
AHAPXICT
20.11.2016, 20:05
 
Раздел: Секреты foobar2000
Тема: Скрипты для foo_uie_wsh_panel_mod
Ответы: 2986
Просмотры: 573115
  • 2

Re: Скрипты для foo_uie_wsh_panel_mod

Get Covers (Artwork)
version "20112016"

поддержка CUI и DUI.

Сначала отображает (или):
%album%.*
%artist%.* - добавлено;
cover.*
front.*
folder.*
album.*
(или встроенную обложку)
затем из текущей папки, затем из подпапок, потом идем выше и т.д.
Безымянный.jpg

Код: Выделить всё
// ==PREPROCESSOR==      
// @name "Get Covers (Artwork)"   
// @author "kgena_ua"   
// @version "20112016"   
// @feature "v1.4"      
// @feature "watch-metadb"      
// ==/PREPROCESSOR==     

function RGBA(r, g, b, a) {   return ((a << 24) | (r << 16) | (g << 8) | (b)); }
function RGB(r, g, b) { return (0xff000000 | (r << 16) | (g << 8) | (b)); }   
function getRed(color) {return ((color >> 16) & 0xff);};   
function getGreen(color) {return ((color >> 8) & 0xff);};   
function getBlue(color) {return (color & 0xff);};   

var font = gdi.Font("Arial",12, 0);   
var a_font = gdi.Font("Arial",12, 1);   
var b_font = gdi.Font("Arial",12, 0);
var ww = 200, wh = 200;

DT_LEFT = 0x00000000;
DT_RIGHT = 0x00000002;
DT_CENTER = 0x00000001;
DT_VCENTER = 0x00000004;
DT_SINGLELINE = 0x00000020;
DT_WORD_ELLIPSIS = 0x00040000;
DT_NOPREFIX = 0x00000800;

MF_ENABLED = 0x00000000;
MF_GRAYED = 0x00000001;
MF_SEPARATOR = 0x00000800;

ColorTypeCUI = {
    text: 0,
    selection_text: 1,
    inactive_selection_text: 2,
    background: 3,
    selection_background: 4,
    inactive_selection_background: 5,
    active_item_frame: 6
}

ColorTypeDUI = {
   text: 0,
   background: 1,
   highlight: 2,
   selection: 3
}

function get_color(){   
    if (window.InstanceType == 0){
        bgcolor = window.GetColorCUI(ColorTypeCUI.background);
        a_color = window.GetColorCUI(ColorTypeCUI.text);
        b_color = window.GetColorCUI(ColorTypeCUI.inactive_selection_text);
    } else if (window.InstanceType == 1) {
        bgcolor = window.GetColorDUI(ColorTypeDUI.background);
        a_color = window.GetColorDUI(ColorTypeDUI.text);
        b_color = window.GetColorDUI(ColorTypeDUI.highlight);
    }
    window.Repaint();
}

get_color();

function on_colors_changed(){
    get_color();
}

var transparent = window.GetProperty(" bg transparent (0-255)", 200);

var fso = new ActiveXObject("Scripting.FileSystemObject");
var WshShell = new ActiveXObject("WScript.Shell");

String.prototype.repeat = function(n) {
    return new Array(n + 1).join(this);
}

window.SetProperty(" - user:", "");
if (window.GetProperty(" - user:") != "" ) window.SetProperty(" - user:", "");

window.SetProperty("-".repeat(50), "");
if (window.GetProperty("-".repeat(50)) != "" ) window.SetProperty("-".repeat(50), "");

var dir_name, album, artist;
var old_dir_name, old_album;

var g_img = null
var cover_name;
var cover_size;
var cover_width;
var cover_height;
var nocover_path = window.GetProperty(" nocover path",".\\maybe\\textures\\nocover\\nocover.png");
var nocover = window.GetProperty(" nocover image", false);
var nocover_transparent = window.GetProperty(" nocover transparent (0-255)", 100);

var covers_external = [];
var covers_dir = [];
var covers_root = [];
var covers_root_subs = [];
var covers_dir_subs = [];
var external = [];
var embedded = [];
var covers = [];
var images = [];
var covernumber = 0;

var root_folders = new Array("cover", "covers", "scan", "scans", "artwork", "artworks", "images", "pic");

var set_external = window.GetProperty("external", true);
var set_embedded = window.GetProperty("embedded", true);
var set_priority = window.GetProperty("set_priority", 0);
var selection_mode = window.GetProperty("selection_mode", 0);
var cycle = window.GetProperty("auto cycle (sec)", 0);
if (cycle > 0) set_cycle_timer();
var info = window.GetProperty("info", false);
var fader = 255;
var fade_effect = window.GetProperty("fade effect", false);
var fade_step = window.GetProperty("fade step", 25);
var align_mode_a = new Array("adjust", "adjust top - center", "adjust top - left", "centre", "centre - top", "stretch");
var align_mode = window.GetProperty("align mode", 0);
var p_margin = window.GetProperty(" margin", 0);

var file_operation = false;

var delay = false;
var set_cycle = false;
var cycle_timer, step = 0;
var dis_timer, dis = 0;

var mode_1 = window.GetProperty("Mode 1", true);
var mode_2 = window.GetProperty("Mode 2", false);

var panel_on = true;

function on_paint(gr) {
    !window.IsTransparent && gr.FillSolidRect(0, 0, ww, wh, bgcolor);

    draw_image(gr);   
    draw_set(gr);
    draw_info(gr);
   
    gr.GdiDrawText( "", gdi.Font("Arial",12, 0), b_color, 10, 0, ww, wh, DT_LEFT | DT_WORD_ELLIPSIS );
    gr.GdiDrawText( "", gdi.Font("Arial",12, 0), b_color, 10, 30, ww, wh, DT_LEFT | DT_WORD_ELLIPSIS );
    gr.GdiDrawText( "", gdi.Font("Arial",12, 0), b_color, 10, 50, ww, wh, DT_LEFT | DT_WORD_ELLIPSIS );
}

var metadb;
on_item_focus_change();

function on_playlist_switch() {
    on_item_focus_change();
}

function on_playback_new_track() {
    on_item_focus_change();
}

function on_playback_dynamic_info_track() {
    on_item_focus_change();
}

function on_playback_stop() {
    on_item_focus_change();
}

function on_selection_changed(metadb) {   
    on_item_focus_change();   
}   

function on_item_focus_change() {   
    switch (selection_mode) {   
    case 0:   
        metadb = fb.IsPlaying ? fb.GetNowPlaying() : fb.GetFocusItem();   
        break;   
    case 1:   
       metadb = fb.GetFocusItem();
        break;    
    }   
    if (metadb) on_metadb_changed();
}

function on_metadb_changed() {
    if (metadb){
        dir_name = fb.Titleformat("$directory_path(%path%)").EvalWithMetadb(metadb);
        album = fb.Titleformat("%album%").EvalWithMetadb(metadb);
        artist = fb.Titleformat("%artist%").EvalWithMetadb(metadb);
        if (dir_name != old_dir_name || album != old_album){
            covernumber = 0;
            get_covers();
            old_dir_name = dir_name;
            old_album = album
        }
    }
    window.Repaint();
}

function get_covers() {
    g_img = null;

    get_external_covers(dir_name);
    get_embedded_covers();

    embedded = set_embedded ? embedded : [];
    external = set_external ? external : [];
   
    covers = [];
   
    if (set_priority == 0) {
        covers = covers.concat(external, embedded);
    }
    if (set_priority == 1) {
        covers = covers.concat(embedded, external);
    }

    if (mode_2){
        images = []; // *************** v 2

        for (var i = 0; i < covers.length; i++) {
            if (typeof covers[i] == 'object' ) {
                images.push(covers[i]);
            } else {
                images.push(resize_image(gdi.Image(covers[i])));
            }
        }
    }
    next_image(0);
}

function get_embedded_covers() {      //0 - front, 1 - back, 2 - disc, 3 - icon, 4 - artist   
    embedded = [];
    if ( metadb ) {
        for (var i = 0; i < 5; i++) {
            var temp = utils.GetAlbumArtEmbedded(metadb.RawPath, i);
            if (temp) embedded.push(temp);
        }
    }
}

function get_external_covers(path) {
    covers_dir = [];
    covers_root = [];
    covers_dir_subs = [];
    covers_root_subs = [];
    covers_external = [];
    external = [];

    try {
        dir = fso.GetFolder(path);
        get_covers_from_dir(covers_dir, dir);
       
        root = dir.ParentFolder;
        get_covers_from_dir(covers_root, root);
   
        var e = new Enumerator( dir.SubFolders );
        for(; !e.atEnd(); e.moveNext() ) {
            get_covers_from_dir(covers_dir_subs, e.item() );
        }
       
        var e = new Enumerator( root.SubFolders );
        for(; !e.atEnd(); e.moveNext() ) {
            var name = e.item().Path;
            var sub_root_name = name.substr(name.lastIndexOf("\\") + 1, name.length);
            for (i in root_folders) {
                if (sub_root_name.toLowerCase() == root_folders[i].toLowerCase()) {
                    get_covers_from_dir(covers_root_subs, e.item() );
                }
            }
        }
    } catch(e) {};
   
    covers_external = covers_external.concat(covers_dir, covers_root, covers_dir_subs, covers_root_subs);

    if (covers_external.length > 0) {
        for (i in covers_external) {
            var name = covers_external[i];
           
            if (get_fn(name).toLowerCase() == album.toLowerCase() || get_fn(name).toLowerCase() == artist.toLowerCase() ) {
                external.push(name);
                covers_external[i] = null;
            }
        }
       
        if (external.length == 0){
            for (i in covers_external) {
                var name = covers_external[i];
           
                if (name.match(/.*(cover|front|folder|album).*\.(jpg|jpeg|gif|png)$/i )) {
                    external.push(name);
                    covers_external[i] = null;
                }
            }
        }
       
        for (i in covers_external) {
            if (typeof(covers_external[i]) == 'string' ) external.push(covers_external[i]);
        }
    }
}

function get_covers_from_dir(array, dir) {
    var e = new Enumerator( dir.Files );
    while (!e.atEnd()) {
        var name = e.item().Name;
        if (name.match(/\.(jpg|jpeg|png|gif|bmp|tiff)$/i)) {
            array.push( e.item().Path );
        }
        e.moveNext();
    }
}

function next_image(d){
    fader = fade_effect ? 0 : 255;
    if (d < 0) {covernumber = covernumber <= 0 ? covers.length - 1 : covernumber = covernumber - 1};
    if (d > 0) {covernumber = covernumber >= covers.length - 1 ? 0 : covernumber = covernumber + 1};

    if (mode_1){
        if (typeof covers[covernumber] == 'object' ) {   // *************** v 1
            g_img = covers[covernumber];   // *************** v 1
        } else {   // *************** v 1
            g_img = resize_image(gdi.Image(covers[covernumber]));   // *************** v 1   
        }   // *************** v 1
    }

    if (mode_2) g_img = images[covernumber];  // *************** v 2
    if (g_img && fade_effect) fader_timer();
}

function resize_image(img){
    if (!img) return;
   
    var scale_w = ww / img.Width;
    var scale_h = wh / img.Height;
    var scale = Math.max(scale_w, scale_h);

    var nww = img.Width * scale;
    var nwh = img.Height * scale

    var temp_bmp = gdi.CreateImage(nww, nwh);
    var temp_gr = temp_bmp.GetGraphics();
    temp_gr.SetSmoothingMode(2);
    temp_gr.SetInterpolationMode(7);
    temp_gr.DrawImage(img, 0, 0, nww, nwh, 0, 0, img.width, img.height);
    temp_bmp.ReleaseGraphics(temp_gr);
   
    CollectGarbage();
    return temp_bmp;
    temp_bmp.Dispose();
    temp_gr = null;
    temp_bmp = null;
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function draw_image(gr){
    if (g_img){
        var size = calc_img_size(g_img);
        gr.DrawRect(size.x, size.y, size.width, size.height, 1, RGBA(getRed(bgcolor),getGreen(bgcolor),getBlue(bgcolor),fader));
        gr.DrawImage(g_img, size.x, size.y, size.width, size.height, size.cx, size.cy, size.cwidth, size.cheight, 0, covers.length > 0 ? fader : nocover_transparent);
    }
   
    if (covers.length == 0 && nocover){
        try {
            nc_img = gdi.Image(nocover_path);
            var size = calc_img_size(nc_img);
            gr.DrawImage(nc_img, size.x, size.y, size.width, size.height, size.cx, size.cy, size.cwidth, size.cheight, 0, nocover_transparent);
        } catch(e) {};
    }
}

function draw_set(gr){
    if(set_cycle){
        gr.FillSolidRect(0, 0, ww, wh, RGBA(getRed(bgcolor),getGreen(bgcolor),getBlue(bgcolor),transparent));

        var txt_cycle = cycle == 0 ? "off" : cycle + " sec";
        gr.GdiDrawText("auto cycle:   " + txt_cycle, b_font, b_color, 0, 20, ww, wh, DT_CENTER | DT_WORD_ELLIPSIS );
    }
}

function draw_info(gr){
    var text_h = gr.CalcTextHeight("00", font);   
    var text_y = wh -  text_h * 3 - 5;   

    if(info && g_img){   
        !set_cycle && gr.FillSolidRect(0, text_y - 5, ww, wh - text_y + 5, RGBA(getRed(bgcolor),getGreen(bgcolor),getBlue(bgcolor),transparent));   

        if (covers[covernumber]) {
           
            if (typeof covers[covernumber] != 'object'){
                if(fso.FileExists(covers[covernumber])){
                    cover_name = get_fnext(covers[covernumber]);
                    cover_width = gdi.Image(covers[covernumber]).width;
                    cover_height = gdi.Image(covers[covernumber]).Height;
                    cover_size = "   " + formatFileSize(fso.GetFile(covers[covernumber]).size);
                }
            }
           
            if (typeof covers[covernumber] == 'object'){
                cover_name = "embedded";
                cover_width = covers[covernumber].width;
                cover_height = covers[covernumber].Height;
                cover_size = "";
            }
           
            cover_name && gr.GdiDrawText(cover_name, font, b_color, 0, text_y, ww, wh, DT_CENTER | DT_WORD_ELLIPSIS | DT_NOPREFIX );
            cover_width && cover_height && cover_size && gr.GdiDrawText(cover_width + " x " + cover_height + "" + cover_size, font, a_color, 0, text_y + text_h, ww, wh, DT_CENTER | DT_WORD_ELLIPSIS );
            info_text = covernumber + 1 + " (" + covers.length + ")   " + external.length + " external   " + embedded.length + " embedded";
            gr.GdiDrawText(info_text, font, a_color, 0, text_y + text_h * 2, ww, wh, DT_CENTER | DT_WORD_ELLIPSIS );
        }
    }
   
    if (!g_img) {
        gr.GdiDrawText("no image", font, a_color, 0, 0, ww, wh, DT_SINGLELINE | DT_CENTER | DT_VCENTER | DT_WORD_ELLIPSIS );
    }
}

function on_mouse_lbtn_dblclk (x,y){
    if (typeof covers[covernumber] != 'object' ) {
        if(!fso.FileExists(covers[covernumber]))return;
        if (covers[covernumber]) WshShell.run( '"' + covers[covernumber] + '"' );
    }
}

function on_mouse_wheel(delta) {
    ShiftDown = utils.IsKeyPressed(0x10) ? true : false;
   
    if (!delay && !ShiftDown && covers.length > 1){
        delay = true;
        fdelay();
        next_image(delta);
    }

    if (ShiftDown) {
        if (delta < 0) {cycle = cycle <= 0 ? 0 : cycle - 5;};
        if (delta > 0) {cycle = cycle >= 60 ? 60 : cycle + 5;};
        window.SetProperty("auto cycle (sec)", cycle);
    }
    window.Repaint();
}

function on_mouse_move(x, y) {
    window.SetCursor(32649);
}

function on_mouse_leave() {
    window.SetCursor(32512);
}

function fdelay(){
    var delay_timer = window.SetTimeout(function() {
        delay = false;
        window.ClearTimeout(delay_timer);
    }, 200);
}

function on_key_down(vkey) {
    if (vkey == 16){
        set_cycle = true;
        dis_set();
        window.Repaint();
    }
    window.Repaint();
}

function set_cycle_timer(){
    cycle_timer && window.ClearInterval(cycle_timer);
    cycle_timer = window.SetInterval(function() {
        step =  set_cycle || file_operation ? 0 : step + 1;
        if (cycle > 0 && step >= cycle){
            if ( covers.length > 1) next_image(1);
            window.Repaint();
            step = 0;
        }
    window.Repaint();
    }, 1000 );
}

function dis_set(){
    dis = 0;
    dis_timer && window.ClearInterval(dis_timer);
    dis_timer = window.SetInterval(function() {
        if (set_cycle) {
            dis++;
            if(dis == 1) {
                set_cycle = false;
                if (cycle > 0) set_cycle_timer();
                if (cycle == 0) window.ClearInterval(cycle_timer);
                window.ClearInterval(dis_timer)
                window.Repaint();
            };
        }
    }, 1000 );
}

var ftimer;

function fader_timer(){
    ftimer && window.ClearInterval(ftimer);
    ftimer = window.SetInterval(function() {
    fader = fader + fade_step;
        if (fader >= 255) {
            fader= 255;
            window.ClearInterval(ftimer);
        }
    window.Repaint();
    }, 50 );
}

function change_filename(){
    if(!fso.FileExists(covers[covernumber]))return;
   
    var c_file_name = get_fn(covers[covernumber]);
   
    var nl = "\" + chr(10) + \"";
    var input_box_text = nl + "Enter new file name";
    var n_file_name = input_box(input_box_text, c_file_name, "Foobar 2000");
   
    if (n_file_name) {
        var dir = get_dp(covers[covernumber]);
        var ext = get_fext(covers[covernumber]);

        try {
            fso.MoveFile( covers[covernumber], dir + "\\" + n_file_name + "." + ext );
            get_covers();
           
            for (var i = 0; i < covers.length; i++) {
                if (get_fn(covers[i]) == n_file_name) {
                    covernumber = i;
                }
            }
        } catch(e) {}
    }
    file_operation = false;
}

function delete_file(){
    if(!fso.FileExists(covers[covernumber]))return;
    var source = covers[covernumber];
   
    var button_type = is_read_write(source) ? 0x3 : 0x5;
    var icon_type = is_read_write(source) ? 0x20 : 0x10;
    var second_button_is_default = 0x100;
   
    var btn = WshShell.Popup("Delete file:\n\n" + source, 0, "Foobar 2000", button_type + icon_type + second_button_is_default);
    switch (btn) {
    case 6:
        try{
            fso.DeleteFile(source);
            covernumber = covernumber == covers.length - 1 ? 0 : covernumber;
            get_covers();
        } catch(e) {}
        break;
    case 2:
    case 7:
        break;
    case 4:
        delete_file();
        break;
    }
    file_operation = false;
}

function change_file_attributes(){
    if(!fso.FileExists(covers[covernumber]))return;
    var source = covers[covernumber];

    var txt = is_read_write(source) ? "file is \nREAD-WRITE" : "file is \nREAD-ONLY";
    var button_type = 0x3;
    var icon_type = 0x40;
   
    var btn = WshShell.Popup(source + "\n\n" + txt + "\nchange file attributes ?", 0, "Foobar 2000", button_type + icon_type);
    switch (btn) {
    case 6:
        try{
            var file = fso.GetFile(source);
            file.Attributes = is_read_write(source) ? 33 : 32;
        } catch(e) {}
        break;
    case 2:
    case 7:
        break;
    }
    file_operation = false;
}

function input_box(p_text, d_text, w_title){
    vbe = new ActiveXObject('ScriptControl');
    vbe.Language = 'VBScript';
    return vbe.eval( "InputBox(\"" + p_text + "\",\"" + w_title + "\",\"" + d_text + "\")");
}

function is_read_write(f){ 
    if(fso.FileExists(f)) {
        var file = fso.GetFile(f);
        return file.Attributes == 32 ? true : false;
    }
}

function on_size(){
    ww = window.Width;   
    wh = window.Height;
}

function calc_img_size(img){
    var size = {x:0, y:0, width:0, height:0, cx:0, cy:0, cwidth:0, cheight:0};

    switch(align_mode) {   
   case 0: // adjust      
        var sw = ww / img.Width;
        var sh = wh / img.Height;
        var s = Math.min(sw, sh);
       
        var x = 0;
        var y = 0;
       
        if (sw > sh) x = (ww - img.Width * s) / 2;
        else if (sw < sh) y = (wh - img.height * s) / 2;

        var width = img.Width * s;
        var height = img.Height * s;
        var cx = 0;
        var cy = 0;
        var cwidth = img.Width;
        var cheight = img.Height;
      break;
       
    case 1: // adjust top - center
        var sw = ww / img.Width;
        var sh = wh / img.Height;
        var s = Math.min(sw, sh);

        var x = 0;
        if (sw > sh) x = (ww - img.Width * s) / 2;
        var y = 0;
        var width = img.Width * s;
        var height = img.Height * s;
        var cx = 0;
        var cy = 0;
        var cwidth = img.Width;
        var cheight = img.Height;
      break;
       
    case 2: // adjust top - left
        var sw = ww / img.Width;
        var sh = wh / img.Height;
        var s = Math.min(sw, sh);
       
        var x = 0;
        var y = 0;
        var width = img.Width * s;
        var height = img.Height * s;
        var cx = 0;
        var cy = 0;
        var cwidth = img.Width;
        var cheight = img.Height;
      break;

   case 3: // centre   
      var sr = img.Width / img.Height;   
      var dr = ww / wh;   
      if (sr < dr) {   
         var r = img.Width / ww;
         var cheight = wh * r;
         var cy = Math.round((img.Height - cheight) / 2);
         var cwidth = img.Width;
         var cx = 0;
      } else {   
         var r = img.Height / wh;
         var cwidth = ww * r;
         var cx = Math.round((img.Width - cwidth) / 2);
         var cheight = img.Height;
         var cy = 0;
      }   
        var x = 0;         
        var y = 0;         
        var width = ww;         
        var height = wh;         
      break;   
       
   case 4: // centre - top      
      var sr = img.Width / img.Height;   
      var dr = ww / wh;   
      if (sr < dr) {   
         var r = img.Width / ww;
         var cheight = wh * r;
         var cy = 0;
         var cwidth = img.Width;
         var cx = 0;
      } else {   
         var r = img.Height / wh;
         var cwidth = ww * r;
         var cx = Math.round((img.Width - cwidth) / 2);
         var cheight = img.Height;
         var cy = 0;
      }
        var x = 0;
        var y = 0;
        var width = ww;
        var height = wh;
      break;   
       
   case 5: // stretch      
        var x = 0;
        var y = 0;
        var width = ww;
        var height = wh;
        var cx = 0;
        var cy = 0;
        var cwidth = img.Width;
        var cheight = img.Height;
      break;   
    }
   
    size.x = x + p_margin;
    size.y = y + p_margin;
    size.width = width - p_margin * 2;
    size.height = height - p_margin * 2;
    size.cx = cx;
    size.cy = cy;
    size.cwidth = cwidth;
    size.cheight = cheight;
   
    return size;
}

function on_mouse_rbtn_up (x, y){
    var _menu = window.CreatePopupMenu();
   
    _menu.AppendMenuItem(MF_ENABLED, 10, "External covers");
    _menu.CheckMenuItem(10, set_external);
    _menu.AppendMenuItem(MF_ENABLED, 11, "Embedded covers");
    _menu.CheckMenuItem(11, set_embedded);

    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
    _menu.AppendMenuItem(MF_ENABLED, 20, "Priority external");   
    _menu.AppendMenuItem(MF_ENABLED, 21, "Priority embedded");   
    _menu.CheckMenuRadioItem(20, 21 , set_priority + 20);   
   _menu.EnableMenuItem(set_priority + 20, 1); 

    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);   
    _menu.AppendMenuItem(MF_ENABLED, 30, "Prefer now playing");   
    _menu.AppendMenuItem(MF_ENABLED, 31, "Follow selected track");   
    _menu.CheckMenuRadioItem(30, 31 , selection_mode + 30);   
   _menu.EnableMenuItem(selection_mode + 30, 1); 
       
    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);   
    _menu.AppendMenuItem(MF_ENABLED, 40, "Info");   
    _menu.CheckMenuItem(40, info);   

    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);   
    _menu.AppendMenuItem(MF_ENABLED, 50, "Fade effect");
    _menu.CheckMenuItem(50, fade_effect);
   
    _firstgroup = window.CreatePopupMenu();
    _firstgroup.AppendTo(_menu, MF_ENABLED, "Align : " + align_mode_a[align_mode]);
   
    _firstgroup.AppendMenuItem(MF_ENABLED, 60, align_mode_a[0]);         
    _firstgroup.AppendMenuItem(MF_ENABLED, 61, align_mode_a[1]);
    _firstgroup.AppendMenuItem(MF_ENABLED, 62, align_mode_a[2]);
    _firstgroup.AppendMenuItem(MF_ENABLED, 63, align_mode_a[3]);
    _firstgroup.AppendMenuItem(MF_ENABLED, 64, align_mode_a[4]);
    _firstgroup.AppendMenuItem(MF_ENABLED, 65, align_mode_a[5]);
    _firstgroup.CheckMenuRadioItem(60, 65, align_mode + 60);
    _firstgroup.EnableMenuItem(align_mode + 60, 1);

    MF_STRING = covers[covernumber] && typeof covers[covernumber] != 'object' ? MF_ENABLED : MF_GRAYED;
    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
    _menu.AppendMenuItem(MF_STRING, 70, "Open folder");
    _menu.AppendMenuItem(MF_STRING, 71, "Rename file");
    _menu.AppendMenuItem(MF_STRING, 72, "Delete file");
    _menu.AppendMenuItem(MF_STRING, 73, "Change file attributes");
   
    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
    MF_STRING = mode_2 ? MF_ENABLED : MF_GRAYED;
    _menu.AppendMenuItem(MF_STRING, 80, "Mode 1");
    _menu.CheckMenuItem(80, mode_1);
    MF_STRING = mode_1 ? MF_ENABLED : MF_GRAYED;
    _menu.AppendMenuItem(MF_STRING, 81, "Mode 2");
    _menu.CheckMenuItem(81, mode_2);
   
    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
    _menu.AppendMenuItem(MF_ENABLED, 100, "Reload");
    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
    _menu.AppendMenuItem(MF_ENABLED, 110, "Properties");
    _menu.AppendMenuItem(MF_ENABLED, 120, "Configure ...");

    ret = _menu.TrackPopupMenu(x,y);

    switch (ret) {
    case 10:
        set_external = set_external == false ? true : set_embedded == false ? true : false;
        window.SetProperty("external", set_external);
        covernumber = 0;
        get_covers();
        break;
    case 11:
        set_embedded = set_embedded == false ? true : set_external == false ? true : false;
        window.SetProperty("embedded", set_embedded);
        covernumber = 0;
        get_covers();
        break;
    case 20:
    case 21:
        set_priority = ret - 20;
        window.SetProperty("set_priority", set_priority);
        covernumber = 0;
        get_covers();
        break;
    case 30:
    case 31:
        selection_mode = ret - 30;
        window.SetProperty("selection_mode", selection_mode);
        on_item_focus_change();
        break;
    case 40:      
        window.SetProperty("info", !info);      
        info = window.GetProperty("info");       
        window.Repaint();       
        break;      
    case 50:      
        window.SetProperty("fade effect", !fade_effect);      
        fade_effect = window.GetProperty("fade effect");       
        break;   
    case 60:
    case 61:
    case 62:
    case 63:
    case 64:
    case 65:
        align_mode = ret - 60;
        window.SetProperty("align mode", align_mode);
        window.Repaint();
        break;
    case 70:      
      if (covers[covernumber] && typeof covers[covernumber] != 'object') WshShell.run( '"' + covers[covernumber].substring(0, covers[covernumber].lastIndexOf("\\")) + '"' );
        break;   
    case 71:   
        file_operation = true;   
        change_filename();   
        break;          
    case 72:   
        file_operation = true;   
        delete_file();   
        break;   
    case 73:   
        file_operation = true;   
        change_file_attributes();   
        break;   
    case 80:
    case 81:   
        window.SetProperty("Mode 1", !mode_1);
        mode_1 = window.GetProperty("Mode 1");
        window.SetProperty("Mode 2", !mode_1);   
        mode_2 = window.GetProperty("Mode 2");
        covernumber = 0;
        get_covers();
        break;   
    case 100:   
        window.Reload();   
        break;   
    case 110:
        window.ShowProperties();
        break;   
    case 120:
        window.ShowConfigure();   
        break;   
   }
    _menu.Dispose();
    return true;   


function get_fnext(p) {
    if (!p) return;
    return p.replace(/.*\\/g,'');
}

function get_fn(p) {
    if (!p) return;
    return p.replace(/.*\\|\..*/g,'');
}

function get_fext(p) {
    if (!p) return;
    return p.replace(/.*\./g,'');
}

function get_dp(p) {
    if (!p) return;
    return p.replace(/(.*)\\.*/g,'$1');
}

function formatFileSize(b){
    if (b > 1024 * 1024){
        b = Math.round(b / 1024 / 1024 * 100) / 100 + " MB"
    } else if (b > 1024){
        b = Math.round(b / 1024 * 100 ) / 100 + " KB"
    } else {
        b = b + " Bytes";
    }
    return b;
}
/*
function on_notify_data(name, info) {
    if(name == "panel") {
        if (info == "art"){
            panel_on = true;
            on_metadb_changed();
        } else{
            panel_on = false;
        }
    }
}
*/


Добавлено спустя 5 часов 6 минут:
AHAPXICT:Сам эту тему обдумываю, в общих чертах.
AHAPXICT, должны быть правильно прописаны тэги.
Написал несколько строк внизу Biography Text & Album Info & Picture от 18112016, по средней кнопке качает обложку в tmp_Biography. Пока не все качает, надо разбираться.
Код: Выделить всё

var tf_album;
   
function on_mouse_mbtn_down(){
    if (!metadb) return; 
        tf_album = Eval("%album%");
        get_album();
    }
   
function get_album(){
    xmlhttp3 = new ActiveXObject("Microsoft.XMLHTTP");   
    url3 = ("http://www.last.fm/" + lang_query[lang] + "music/" + encodeURIComponent(artist) + "/+" + p_a[select_p_a]); 
    xmlhttp3.open("GET", url3, true ); 
    xmlhttp3.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
    xmlhttp3.send(null);     
    xmlhttp3.onreadystatechange = function () {
        if (xmlhttp3.readyState == 4) {
            if (xmlhttp3.status == 200) { 
                doc.open();     
                var div = doc.createElement("div");
                div.innerHTML = xmlhttp3.responsetext;
                var data = div.getElementsByTagName("img");
                var urls = [];
                for (i = 0; i < data.length; i++) {   
                    if (data[i].className == "album-grid-album-art" && select_p_a == 1){ 
                        if ((data[i].src.indexOf("http://img2-ak.lst.fm/i/u/300") == 0 || data[i].src.indexOf("https://lastfm-img2.akamaized.net/i/u/300") == 0) && data[i].src.indexOf("c6f59c1e5e7240a4c0d427abd71f3dbb") < 0) {                       
                            if (data[i].alt.replace(/^(.*?)'|'$/g,'').toLowerCase() == tf_album.toLowerCase()){
                                urls.push(data[i].src.replace("300x300", quality[download_quality][2]))
                            }
                        }     
                    }
                }
                p = tmp_b_path;
                var found = urls.length;
                for (i = 0; i < Math.min(urls.length); i++) {     
                    var file = "\"" + p + "\\" + artist + "_" + tf_album + ".jpg" + "\"";     
                    WshShell.Run(vbs + " " + urls[i] + " " + file, 0, false);
                }     
                doc.close();
            }
        }
    }     
}
kgena_ua
20.11.2016, 10:04
 
Раздел: Секреты foobar2000
Тема: Скрипты для foo_uie_wsh_panel_mod
Ответы: 2986
Просмотры: 573115

Re: Скрипты для foo_uie_wsh_panel_mod

kgena_ua, Biography Text & Album Info & Picture last.fm (18.11.2016) пока работает нормально.

Только, что касается информации по альбому, какая задумка была ? В основном ничего не показывает.
Может получится вывести хотя бы часть, которая в большинстве альбомов присутствует, а количество слушателей - своего рода рейтинг альбома.

Результат работы панели:

Изображение

На сайте last.fm:

Изображение

Добавлено спустя 8 минут 46 секунд:
sega72, это тень шрифта в начале строк: 219. 223, 229 поставить //
MC Web
18.11.2016, 16:10
 
Раздел: Секреты foobar2000
Тема: Скрипты для foo_uie_wsh_panel_mod
Ответы: 2986
Просмотры: 573115

Re: Скрипты для foo_uie_wsh_panel_mod

kgena_ua:Biography Text & Album Info & Picture. www.last.fm
version "18112016

На интерфейсе DUI скрипт заработал.
Но, что-то случилось с шрифтом, читать некомфортно:
Untitled.jpg
sega72
18.11.2016, 15:11
 
Раздел: Секреты foobar2000
Тема: Скрипты для foo_uie_wsh_panel_mod
Ответы: 2986
Просмотры: 573115
  • 2

Re: Скрипты для foo_uie_wsh_panel_mod

MC Web, тут моя невнимательность. Я просто названия некоторых переменных и функций изменил. Лучше выложу новую версию:

Biography Text & Album Info & Picture. www.last.fm
version "18112016


- добавил отображения названия альбома;
- изменения в меню: last.fm Artist или last.fm Album;
- поддержка CUI и DUI.
Безымянный.png

Код: Выделить всё
// ==PREPROCESSOR==
// @name "Biography Text & Album Info & Picture. www.last.fm"
// @author "kgena_ua"
// @version "18112016"
// @feature "v1.4"
// @feature "watch-metadb"
// ==/PREPROCESSOR==

function RGB(r,g,b) { return (0xff000000|(r<<16)|(g<<8)|(b)); }
function RGBA(r,g,b,a) { return ((a << 24) | (r << 16) | (g << 8) | (b)); }
function getRed(color) {return ((color >> 16) & 0xff);};
function getGreen(color) {return ((color >> 8) & 0xff);};
function getBlue(color) {return (color & 0xff);};

DT_LEFT = 0x00000000;
DT_RIGHT = 0x00000002;
DT_CENTER = 0x00000001;
DT_VCENTER = 0x00000004;
DT_SINGLELINE = 0x00000020;
DT_WORD_ELLIPSIS = 0x00040000;
DT_WORDBREAK = 0x00000010;
DT_CALCRECT = 0x00000400;
DT_NOPREFIX = 0x00000800;

MF_ENABLED = 0x00000000;   
MF_GRAYED = 0x00000001;   
MF_SEPARATOR = 0x00000800; 

var ww = 200, wh = 200;

var font_name_h = window.GetProperty(" font name: artist", "Arial");
var font_name_t = window.GetProperty(" font name: biography", "Arial");
var font_size_h_d = window.GetProperty(" font size: artist (delta)", 0);
var font_size_t = window.GetProperty(" font size: biography", 12);
var h_font_style = window.GetProperty(" font style: artist", 1);
var t_font_style = window.GetProperty(" font style: biography", 0);
var min_font_size = 12;
var max_font_size = 16;

var h_font, t_font;
get_font();

function get_font(){
    h_font = gdi.Font(font_name_h, font_size_t + font_size_h_d, h_font_style);
    t_font = gdi.Font(font_name_t, font_size_t, t_font_style);
}   

ColorTypeCUI = {
    text: 0,
    selection_text: 1,
    inactive_selection_text: 2,
    background: 3,
    selection_background: 4,
    inactive_selection_background: 5,
    active_item_frame: 6
};

ColorTypeDUI = {
   text: 0,
   background: 1,
   highlight: 2,
   selection: 3
};

function get_color(){   
    if (window.InstanceType == 0){
        bgcolor = window.GetColorCUI(ColorTypeCUI.background);
        h_color = window.GetColorCUI(ColorTypeCUI.text);
        t_color = window.GetColorCUI(ColorTypeCUI.inactive_selection_text);
    } else if (window.InstanceType == 1) {
        bgcolor = window.GetColorDUI(ColorTypeDUI.background);
        h_color = window.GetColorDUI(ColorTypeDUI.text);
        t_color = window.GetColorDUI(ColorTypeDUI.highlight);
    }
    window.Repaint();
};

get_color();

function on_colors_changed(){
    get_color();
}

var fso = new ActiveXObject("Scripting.FileSystemObject");

var tmp_b_path = fb.ProfilePath + "\\tmp_Biography\\";
if (!fso.FolderExists(tmp_b_path)) {fso.CreateFolder(tmp_b_path)};

var script_path = tmp_b_path + "_download\\";
if (!fso.FolderExists(script_path)) {fso.CreateFolder(script_path)};
if (!fso.FileExists(script_path + "download.vbs")) {create_download_file()};

var doc = new ActiveXObject("htmlfile");
var WshShell = new ActiveXObject("WScript.Shell");
var vbs = "cscript //nologo \"" + script_path + "download.vbs\"";

var default_img_path = window.GetProperty(" default img path",".\\maybe\\textures\\nocover\\nocover.png");
var default_img = window.GetProperty(" default img", false);
var default_img_transparent = window.GetProperty(" default img transparent (0-255)", 100);

load_last_fm_logo();
//var logo_img = gdi.Image(script_path + "last_fm_logo.jpg");
var logo_img = gdi.Image(script_path + "footer_logo.png");

var artist, old_artist, album;
var path, directory_path;

function clean_name(n) {
    if (!n) return;
    return n.replace(/[^a-zA-Z0-9а-яА-Я\s-&\.,]/g,'').replace(/^\s+|\s+$/g,"").substr(0,200);
}

function artist_folder_path(n) {
    return tmp_b_path + n;
}

function check_folder(n) {
    if (!n) return;
    if(!fso.FolderExists(n)) {fso.CreateFolder(n)};
}

String.prototype.repeat = function(n) {
    return new Array(n + 1).join(this);
}

window.SetProperty(" - user", "");
if (window.GetProperty(" - user") != "" ) window.SetProperty(" - user", "");
window.SetProperty("-".repeat(50), "");
if (window.GetProperty("-".repeat(50)) != "" ) window.SetProperty("-".repeat(50), "");

var g_img = null;
var p_margin = window.GetProperty(" margin: picture", 0);
var align_mode_a = new Array("adjust", "adjust top - center", "adjust top - left", "centre", "centre - top", "stretch");
var align_mode = window.GetProperty("align mode", 0);
var selected = 0;
var files = [];
var images = [];
var save_images = window.GetProperty("save images", false);
var limit = window.GetProperty(" download limit",5);
var cycle = window.GetProperty("auto cycle (sec)", 0);
if (cycle > 0) set_cycle_timer();
var fader = 255;
var fade_effect = window.GetProperty("fade effect", false);
var fade_step = window.GetProperty("fade step", 25);
var on_pic = false;

var download_quality = window.GetProperty("download quality", 1);
var quality = [
    [ "low", "avatar170s" , "avatar300s"],
    [ "medium", "300x300" , "300x300"],
    [ "high", "770x0" , ""]
];

var scrollbar = window.GetProperty(" scrollbar", true);
var scrollbar_w = window.GetProperty(" scrollbar width ", 4);
var scrollbar_k;
var st_x = 0;
var sb_posy = 0;
var on_sb = false;
var on_sb_down = false;
var st_color;

var b_file;
var bg_transparent = window.GetProperty(" bg transparent (0-255)", 200);
var t_margin = window.GetProperty(" margin: text", 10);
var txt_x = window.GetProperty("txt_x", window.Width / 2);
var old_txt_x = 0;
var txt_y = window.GetProperty("txt_y", window.Height / 2);
var delta_x, delta_y;
var h_x, h1_y, h2_y, t_x, t_x;
var text = "";
var text_not_found = new Array(". . .", ". . .");
var s_text = 0;
var h_text_row_height = 0;
var text_row_height = 0;
var text_rows = 0;
var text_visable_rows = 0;
var text_visable_height = 0;
var text_array = [];
var on_artist = false;
var on_text = false;
var on_text_down = false;
var refresh_txt = true;

var album_info = window.GetProperty("album info", true);

var lang_query = new Array("", "ru/");
var lang_text = new Array("in", "ru");
//var lang_query = new Array("", "zh/");
//var lang_text = new Array("in", "zh");

var lang = window.GetProperty("lang", 0);

var select_p_a = window.GetProperty("artist/album", 0);
//var select_p_a = window.GetProperty("pictures/albums", 0);
var p_a = new Array("images", "albums");

var panel_on = true;

var selection_mode = window.GetProperty("selection mode", 0);
var metadb;
on_item_focus_change();

function on_paint(gr){   
   !window.IsTransparent && gr.FillSolidRect(0, 0, ww, wh, bgcolor);
   
    draw_image(gr);

    if(set_cycle){   
        gr.FillSolidRect(0, 0, ww, wh, RGBA(getRed(bgcolor),getGreen(bgcolor),getBlue(bgcolor),bg_transparent));   
        var txt_cycle = cycle == 0 ? "off" : cycle + " sec";   
        set_cycle && gr.GdiDrawText("auto cycle:   " + txt_cycle, t_font, t_color, 0, 20, ww, wh, DT_CENTER | DT_WORD_ELLIPSIS );
    } else{   
        gr.FillSolidRect(txt_x, txt_y, ww - txt_x, wh - txt_y, RGBA(getRed(bgcolor),getGreen(bgcolor),getBlue(bgcolor),bg_transparent));   
    }   

    draw_scrollbar(gr);   
   
    gr.GdiDrawText( artist, h_font, RGB(0,0,0), h_x + 1, h1_y + 2, ww - h_x - t_margin, wh, DT_LEFT | DT_WORD_ELLIPSIS | DT_NOPREFIX );   
    gr.GdiDrawText( artist, h_font, h_color, h_x, h1_y, ww - h_x - t_margin, wh, DT_LEFT | DT_WORD_ELLIPSIS | DT_NOPREFIX );   

    if (album_info && select_p_a == 1){
        gr.GdiDrawText( album, h_font, RGB(0,0,0), h_x + 1, h2_y + 2, ww - h_x - t_margin, wh, DT_LEFT | DT_WORD_ELLIPSIS | DT_NOPREFIX );   
        gr.GdiDrawText( album, h_font, t_color, h_x, h2_y, ww - h_x - t_margin, wh, DT_LEFT | DT_WORD_ELLIPSIS | DT_NOPREFIX );   
    }

    for (var i = 0; i < text_visable_rows * 2; i += 2) {
        try {
            gr.GdiDrawText( text_array[i + s_text * 2].replace(/^\s+|\s+$/g, ""), t_font, RGB(0,0,0), t_x + 1, t_y + text_row_height * i / 2 + 2, ww, wh, DT_LEFT | DT_NOPREFIX );
            gr.GdiDrawText( text_array[i + s_text * 2].replace(/^\s+|\s+$/g, ""), t_font, t_color, t_x, t_y + text_row_height * i / 2 , ww, wh, DT_LEFT | DT_NOPREFIX );
        } catch(e) {}
    }

    //gr.GdiDrawText( "files " + files.length, gdi.Font("Arial",12, 0), t_color, 10, 0, ww, wh, DT_LEFT | DT_WORD_ELLIPSIS );
    //gr.GdiDrawText( "images " + images.length, gdi.Font("Arial",12, 0), t_color, 10, 20, ww, wh, DT_LEFT | DT_WORD_ELLIPSIS );
    //gr.GdiDrawText( selected, gdi.Font("Arial",12, 0), t_color, 10, 40, ww, wh, DT_LEFT | DT_WORD_ELLIPSIS );
    //gr.GdiDrawText( "", gdi.Font("Arial",12, 0), t_color, 10, 60, ww, wh, DT_LEFT | DT_WORDBREAK );
    //gr.GdiDrawText( "", gdi.Font("Arial",12, 0), t_color, 10, 80, ww, wh, DT_LEFT | DT_WORDBREAK );
    //gr.GdiDrawText( "", gdi.Font("Arial",12, 0), t_color, 10, 100, ww, wh, DT_LEFT | DT_WORDBREAK );
}

function draw_image(gr){
    if (g_img && images.length > 0){
        var size = calc_img_size(g_img);
        gr.DrawRect(size.x, size.y, size.width, size.height, 1, RGBA(getRed(bgcolor),getGreen(bgcolor),getBlue(bgcolor),fader));
        gr.DrawImage(g_img, size.x, size.y, size.width, size.height, size.cx, size.cy, size.cwidth, size.cheight, 0, fader);
    }
   
    if (logo_img && images.length == 0 && !default_img){
        gr.DrawImage(logo_img, 10, 10, logo_img.Width * 1, logo_img.Height * 1, 0, 0, logo_img.Width, logo_img.Height, 0, 100);         
    }

    if (images.length == 0 && default_img){
        try {
            nc_img = gdi.Image(default_img_path);
            var size = calc_img_size(nc_img);
            gr.DrawImage(nc_img, size.x, size.y, size.width, size.height, size.cx, size.cy, size.cwidth, size.cheight, 0, default_img_transparent);
        } catch(e) {};
    }
}

function draw_scrollbar(gr){
    scrollbar_h = text_rows > text_visable_rows ? text_visable_height * (text_visable_rows / text_rows) : 0;
    if (text_rows > text_visable_rows){ scrollbar_h = Math.max(5, scrollbar_h)}
    scrollbar_y = s_text > 0 ? s_text * scrollbar_k : 0;

    st_x = ww - t_margin - scrollbar_w;
   
    sb_t = on_sb || on_sb_down ? 150 : 50;
    st_color = RGBA(getRed(h_color), getGreen(h_color), getBlue(h_color), sb_t);
   
    scrollbar && gr.FillSolidRect(st_x, t_y + scrollbar_y, scrollbar_w, scrollbar_h, st_color);
}

function on_playlist_switch() {
    on_item_focus_change();
}

function on_playback_new_track() {
    on_item_focus_change();
}

function on_playback_dynamic_info_track() {
    on_item_focus_change();
}

function on_playback_stop() {
    on_item_focus_change();
}

function on_selection_changed(metadb) {
   on_item_focus_change();
}

function on_item_focus_change() {
    switch (selection_mode) {
    case 0:
        metadb = fb.IsPlaying ? fb.GetNowPlaying() : fb.GetFocusItem();   
        break;   
    case 1:   
        metadb = fb.GetFocusItem();
        break;   
    }   
    if (metadb) on_metadb_changed();   
}   

function Eval(field) {   
    if (!metadb) return;   
    path = fb.Titleformat("%path%").EvalWithMetadb(metadb);
    directory_path = fb.Titleformat("$directory_path(%path%)").EvalWithMetadb(metadb);
    return path.indexOf('://') > 0 ? fb.TitleFormat("[" + field + "]").Eval(true) : fb.TitleFormat("[" + field + "]").EvalWithMetadb(metadb);
}   

function on_metadb_changed() {
    if (!panel_on) return;
    if (!metadb) return; 
    artist = Eval("%artist%");
    if (artist) {artist = clean_name(artist)} else {artist = ""};
    if (artist != old_artist){
        if (!save_images) del_folders(artist);
        get_pic();
        old_artist = artist;
    }
}   

function get_pic() {
    clear_txt_var();
    images = [];
    files = [];
    selected = 0;
    g_img = null;
    window.Repaint();
   
    check_folder(artist_folder_path(artist));
    if (fso.FolderExists(artist_folder_path(artist))){
        get_files_from_dir(artist_folder_path(artist));
        if (!g_img && images.length > 0) {
            next_image(0);
            get_text();
        } else {
            get_lastFM_pic(artist_folder_path(artist));
        }
    }
}

function get_lastFM_pic(p){
    xmlhttp1 = new ActiveXObject("Microsoft.XMLHTTP");   
    url1 = ("http://www.last.fm/" + lang_query[lang] + "music/" + encodeURIComponent(artist) + "/+" + p_a[select_p_a]); 
    xmlhttp1.open("GET", url1, true ); 
    xmlhttp1.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
    xmlhttp1.send(null);     
    xmlhttp1.onreadystatechange = function () {
        if (xmlhttp1.readyState == 4) {
            if (xmlhttp1.status == 200) { 
                doc.open();     
                var div = doc.createElement("div");
                div.innerHTML = xmlhttp1.responsetext;
                var data = div.getElementsByTagName("img");
                var urls = [];
                var name = [];
                for (i = 0; i < data.length; i++) {   
                    if (data[i].className == "image-list-image" && select_p_a == 0){       
                        if (data[i].src.indexOf("http://img2-ak.lst.fm/i/u/avatar170s") == 0 || data[i].src.indexOf("https://lastfm-img2.akamaized.net/i/u/avatar170s") == 0) {
                            urls.push(data[i].src.replace("avatar170s", quality[download_quality][1]));
                        }     
                    }   
                    if (data[i].className == "album-grid-album-art" && select_p_a == 1){ 
                        if ((data[i].src.indexOf("http://img2-ak.lst.fm/i/u/300") == 0 || data[i].src.indexOf("https://lastfm-img2.akamaized.net/i/u/300") == 0) && data[i].src.indexOf("c6f59c1e5e7240a4c0d427abd71f3dbb") < 0) {                       
                            urls.push(data[i].src.replace("300x300", quality[download_quality][2]))
                            name.push(data[i].alt.replace(/^(.*?)'|'$/g,''));
                        }     
                    }
                }
                var found = urls.length;
                for (i = 0; i < Math.min(urls.length, limit); i++) {     
                    var file = "\"" + p + "\\" + artist + "_"  + i + "_" + p_a[select_p_a] + ".jpg" + "\"";     
                    WshShell.Run(vbs + " " + urls[i] + " " + file, 0, false);
                   
                    if (select_p_a == 1){
                        name.push(name[i]);
                        utils.WriteINI( p + "\\" + artist + "_album_info.ini", "album_name", i, name[i]);
                    }
                }     
                doc.close();
                if (found > 0) get_files_if_loaded(p);
            }
        }
        get_text();       
    }     
}

function get_files_from_dir(p) {
    if (!artist) return;
    files = utils.Glob(p + "\\" + artist + "*" + p_a[select_p_a] + ".jpg").toArray();
   
    if (files.length > images.length){
        images = [];
       
        for (var i = 0; i < files.length; i += 1) {
            try {
                images.push(resize_image(gdi.Image(files[i])));
            } catch(e) {}
        }
    }
}

function next_image(d){
    fader = fade_effect ? 0 : 255;
    if (d < 0) {selected = selected <= 0 ? images.length - 1 : selected = selected - 1};
    if (d > 0) {selected = selected >= images.length - 1 ? 0 : selected = selected + 1};
    g_img = images[selected];
    if (g_img && fade_effect) fader_timer();
    window.Repaint();
    if (album_info && select_p_a == 1) get_a_text(selected);
}

function resize_image(img){
    if (!img) return;
   
    var scale_w = (window.Width - p_margin * 2) / img.Width;
    var scale_h = (window.Height - p_margin * 2) / img.Height;
    var scale = Math.min(scale_w, scale_h);
    var nww = img.Width * scale;
    var nwh = img.Height * scale

    var temp_bmp = gdi.CreateImage(nww, nwh);
    var temp_gr = temp_bmp.GetGraphics();
    temp_gr.SetSmoothingMode(2);
    temp_gr.SetInterpolationMode(7);
    temp_gr.DrawImage(img, 0, 0, nww, nwh, 0, 0, img.width, img.height);
    temp_bmp.ReleaseGraphics(temp_gr);
   
    CollectGarbage();
    return temp_bmp;
    temp_bmp.Dispose();
    temp_gr = null;
    temp_bmp = null;
}

function get_text(){
    if (album_info && select_p_a == 1){
        get_a_text(selected);
    } else {
        get_b_text();
    }
}

function clear_txt_var() {
    album = "";
    s_text = 0;
    text = "";
    text_array = [];
    window.Repaint();
}

function get_b_text() {
    clear_txt_var();
    refresh_txt = true;
    var b_text_file = artist_folder_path(artist) + "\\" + artist + "_biography_" + lang_text[lang] + ".txt";
   
    if (fso.FileExists(b_text_file)){
        text = utils.ReadTextFile(b_text_file);
        get_text_array();
    } else{
        get_lastFM_b_text(b_text_file);
    }
}

function get_lastFM_b_text(p){
    xmlhttp2 = new ActiveXObject("Microsoft.XMLHTTP");
    url2 = ("http://www.last.fm/" + lang_query[lang] + "music/" + encodeURIComponent(artist) + "/+wiki");
    xmlhttp2.open("GET", url2, true);
    xmlhttp2.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
    xmlhttp2.send(null);
    xmlhttp2.onreadystatechange = function () {
        if (xmlhttp2.readyState == 4) {
            if (xmlhttp2.status == 200) {
                doc.open();
                var div = doc.createElement("div");
                div.innerHTML = xmlhttp2.responsetext;
                var data = div.getElementsByTagName("div");
                for (i = 0; i < data.length; i++) {
                    if (data[i].className == "wiki-content") {
                        text = strip_tags(data[i].innerHTML).replace(/^\s+|\s+$/g,"");
                        break;
                    }
                }
                doc.close();
            }
            if (text != "") save_txt_file(text, p);
            if (text == "") text = text_not_found[lang];
            get_text_array();
        }
    }
}

function strip_tags(t) {
    doc.open();
    var div = doc.createElement("div");
    div.innerHTML = t.replace(/<[Pp][^>]*>/g, "").replace(/<\/[Pp]>/g, "<br>").replace(/\n/g, "<br>");
    var text = div.innerText;
    doc.close();
    return text;
}

function get_text_array() {
    h_x = txt_x + t_margin;
    h1_y = txt_y + t_margin;
 
    temp_bmp = gdi.CreateImage(1, 1);
    temp_gr = temp_bmp.GetGraphics();

    h_text_row_height = temp_gr.CalcTextHeight("Text", h_font);
    text_row_height = temp_gr.CalcTextHeight("Text", t_font);
   
    h2_y = h1_y + h_text_row_height;
   
    t_x = txt_x + t_margin;
    t_y = (album_info && select_p_a == 1 ? h2_y + h_text_row_height : h1_y + h_text_row_height) + text_row_height;
   
    string_width = scrollbar ? Math.max(ww - t_x - t_margin - scrollbar_w - 10, 0) : Math.max(ww - t_x - t_margin, 0);

    if (Math.abs(txt_x - old_txt_x) > 5 || refresh_txt){
        text_array = [];
        if (text) text_array = temp_gr.EstimateLineWrap(text.replace(/^\s+|\s+$/g,""), t_font, string_width).toArray();
        old_txt_x = txt_x;
        refresh_txt = false;
    }
   
    text_rows = text_array.length / 2;

    b_text_visable_area = Math.floor(Math.max(0, window.Height - t_margin - t_y));
    text_visable_rows = Math.floor(b_text_visable_area / text_row_height);
    text_visable_height = text_visable_rows * text_row_height;


    if (text_visable_rows + s_text > text_rows && s_text > 0) {
        s_text = (text_rows - text_visable_rows);
    }

    scrollbar_k = text_visable_height / text_rows;
   
    temp_bmp.ReleaseGraphics(temp_gr);
    temp_bmp.Dispose();
    temp_gr = null;
    temp_bmp = null;

    window.Repaint();
}

function save_txt_file(t, p){
    if (!artist) return;
    try {
        file = fso.OpenTextFile( p, 2, true, -1)
        file.WriteLine(t);
        file.Close();
    } catch(e) {
        return;
    }
}

function on_mouse_rbtn_up (x, y){     
    var _menu = window.CreatePopupMenu();
   
    _menu.AppendMenuItem(MF_ENABLED, 10, lang_text[0] + " text");   
    _menu.AppendMenuItem(MF_ENABLED, 11, lang_text[1] + " text");   
    _menu.CheckMenuRadioItem(10, 11, lang + 10);         
    _menu.EnableMenuItem(lang + 10, 1);     

    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);   
    _menu.AppendMenuItem(MF_ENABLED, 12, "Prefer now playing");   
    _menu.AppendMenuItem(MF_ENABLED, 13, "Follow selected track");   
    _menu.CheckMenuRadioItem(12, 13 , selection_mode + 12);   
    _menu.EnableMenuItem(selection_mode + 12, 1);
       
    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0); 
    _menu.AppendMenuItem(MF_ENABLED, 14, "Artist pictures");   
    _menu.AppendMenuItem(MF_ENABLED, 15, "Albums pictures");   
    _menu.CheckMenuRadioItem(14, 15 , select_p_a + 14);   
    _menu.EnableMenuItem(select_p_a + 14, 1);

    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0); 
    _menu.AppendMenuItem(MF_ENABLED, 16, "Album info");
    _menu.CheckMenuItem(16, album_info);

    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);   
   
    switch (select_p_a){
    case 0:
        IS_ARTIST = artist ? MF_ENABLED : MF_GRAYED;   
        _menu.AppendMenuItem(IS_ARTIST, 17, "last.fm Artist");
        break;
    case 1:
        IS_ALBUM = album ? MF_ENABLED : MF_GRAYED;   
        _menu.AppendMenuItem(IS_ALBUM, 17, "last.fm Album");
        break;
    }
   
    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
    _menu.AppendMenuItem(MF_ENABLED, 18, "Fade effect");
    _menu.CheckMenuItem(18, fade_effect);

    _firstgroup = window.CreatePopupMenu();
    _firstgroup.AppendTo(_menu,MF_ENABLED,  "Align : " + align_mode_a[align_mode]);
   
    _firstgroup.AppendMenuItem(MF_ENABLED, 20, align_mode_a[0]);         
    _firstgroup.AppendMenuItem(MF_ENABLED, 21, align_mode_a[1]);
    _firstgroup.AppendMenuItem(MF_ENABLED, 22, align_mode_a[2]);
    _firstgroup.AppendMenuItem(MF_ENABLED, 23, align_mode_a[3]);
    _firstgroup.AppendMenuItem(MF_ENABLED, 24, align_mode_a[4]);
    _firstgroup.AppendMenuItem(MF_ENABLED, 25, align_mode_a[5]);
    _firstgroup.CheckMenuRadioItem(20, 25, align_mode + 20);
    _firstgroup.EnableMenuItem(align_mode + 20, 1);

    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
    _secondgroup = window.CreatePopupMenu();
    _secondgroup.AppendTo(_menu,MF_ENABLED,  "Download quality : " + quality[download_quality][0]);
   
    _secondgroup.AppendMenuItem(MF_ENABLED, 30, "Low");
    _secondgroup.AppendMenuItem(MF_ENABLED, 31, "Medium");
    _secondgroup.AppendMenuItem(MF_ENABLED, 32, "High");
    _secondgroup.CheckMenuRadioItem(30, 32, download_quality + 30);
    _secondgroup.EnableMenuItem(download_quality + 30, 1);

    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
    MF_STRING = images.length > 0 ? MF_ENABLED : MF_GRAYED;
    _menu.AppendMenuItem(MF_STRING, 40, "Copy to folder containing track...");
    _menu.AppendMenuItem(MF_STRING, 50, "Open image");
   
    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
    _menu.AppendMenuItem(MF_ENABLED, 60, "Save images and text");
    _menu.CheckMenuItem(60, save_images);

    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);   
    _menu.AppendMenuItem(MF_ENABLED, 100, "Reload");   
    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);   
    _menu.AppendMenuItem(MF_ENABLED, 110, "Properties");   
    _menu.AppendMenuItem(MF_ENABLED, 120, "Configure ...");

    ret = _menu.TrackPopupMenu(x,y);

    switch (ret) {
    case 10:
    case 11:
        lang = ret - 10;
        window.SetProperty("lang", lang);
        get_text();
        break;
    case 12:
        selection_mode = 0;
        window.SetProperty("selection mode", selection_mode);
        on_item_focus_change();
        break;
    case 13:
        selection_mode = 1;
        window.SetProperty("selection mode", selection_mode);
        on_item_focus_change();
        break;
    case 14:
        select_p_a = 0;
        window.SetProperty("artist/album", select_p_a);
        get_pic();
        break;
    case 15:
        select_p_a = 1;
        window.SetProperty("artist/album", select_p_a);
        get_pic();
        break;
    case 16:
        window.SetProperty("album info", ! album_info);
        album_info = window.GetProperty("album info");
        get_text();
        break;
    case 17:
        switch (select_p_a){
        case 0:
            WshShell.run("http://www.last.fm/" + lang_query[lang] + "music/" + encodeURIComponent(artist));
            break;
        case 1:
            WshShell.run("http://www.last.fm/" + lang_query[lang] + "music/" + encodeURIComponent(artist) + "/" + encodeURIComponent(album));
            break;
        }
        break;
    case 18:
        window.SetProperty("fade effect", !fade_effect);
        fade_effect = window.GetProperty("fade effect");
        break;
    case 20:
    case 21:
    case 22:
    case 23:
    case 24:
    case 25:
        align_mode = ret - 20;
        window.SetProperty("align mode", align_mode);
        window.Repaint();
        break;
    case 30:
    case 31:
    case 32:   
        download_quality = ret - 30;
        window.SetProperty("download quality", download_quality);
        break;
    case 40:
        copy_files();
        break;
    case 50:
        try {
            if (images[selected]) WshShell.run( '"' + artist_folder_path(artist)+ "\\" + artist + "_"  + selected + "_" + p_a[select_p_a] + ".jpg" + '"' );
        } catch(e) {}
        break;
    case 60:
        window.SetProperty("Save images", !save_images);
        save_images = window.GetProperty("Save images");
        break;
    case 100:
        window.Reload();
        break;
    case 110:
        window.ShowProperties();
        break;   
    case 120:
        window.ShowConfigure();   
        break;   
   }
    _menu.Dispose();   
    return true;   
}   

var timer;

function get_files_if_loaded(p){
    timer && window.ClearInterval(timer);
    timer = window.SetInterval(function() {
        get_files_from_dir(p);
        if (images.length > 0)  {
            next_image(0);
            window.ClearInterval(timer); 
        }
    }, 500 );
}

var set_cycle = false;

function on_key_down(vkey) {
    if (vkey == 16){
        set_cycle = true;
        dis_set();
        window.Repaint();
    }
}

var cycle_timer, step = 0;

function set_cycle_timer(){
    cycle_timer && window.ClearInterval(cycle_timer);
    cycle_timer = window.SetInterval(function() {
        step =  set_cycle ? 0 : step + 1;
        if (cycle > 0 && step >= cycle){
            get_files_from_dir(artist_folder_path(artist));
            if (images.length > 1){
                next_image(1);
                step = 0;
            }
        }
        window.Repaint();
    }, 1000 );
}

var dis_timer, dis = 0;

function dis_set(){
    dis = 0;
    dis_timer && window.ClearInterval(dis_timer);
    dis_timer = window.SetInterval(function() {
        if (set_cycle) {
            dis++;
            if(dis == 1) {
                set_cycle = false;
                if (cycle > 0) set_cycle_timer();
                if (cycle == 0) window.ClearInterval(cycle_timer);
                window.ClearInterval(dis_timer)
                window.Repaint();
            };
        }
    }, 1000 );
}

var delay = false;

function fdelay(){
    var delay_timer = window.SetTimeout(function() {
        delay = false;
        window.ClearTimeout(delay_timer);
    }, 200);
}

var ftimer;

function fader_timer(){
    fader = 0;
    ftimer && window.ClearInterval(ftimer);
    ftimer = window.SetInterval(function() {
        fader = fader + fade_step;
        if (fader >= 255) {
            fader= 255;
            window.ClearInterval(ftimer);
        }
        window.Repaint();
    }, 42 );
}

function load_last_fm_logo(){
    if(!fso.FileExists(script_path + "footer_logo.png")) {
        var url = "http://www.last.fm/static/images/logo_static.png?5b6b42188c40"
        var file = "\"" + script_path + "last_fm_logo.jpg" + "\"";
        WshShell.Run(vbs + " " + url + " " + file, false);
       
        var url = "http://static-web.last.fm/static/images/favicon.702b239b6194.ico"
        var file = "\"" + script_path + "last_fm_ico.ico" + "\"";
        WshShell.Run(vbs + " " + url + " " + file, false);

        var url = "http://static-web.last.fm/static/images/footer_logo.ddcfd65712a6.png"
        var file = "\"" + script_path + "footer_logo.png" + "\"";
        WshShell.Run(vbs + " " + url + " " + file, false);
    }
}

function create_download_file() {
    try {
        file = fso.CreateTextFile(script_path + "download.vbs" )
       
        var text =   
            "If (WScript.Arguments.Count <> 2) Then" + "\n\r" +   
            "   WScript.Quit" + "\n\r" +
            "End If" + "\n\r" + "\n\r" +   

            "url = WScript.Arguments(0)" + "\n\r" +   
            "file = WScript.Arguments(1)" + "\n\r"  + "\n\r" +   

            "Set objFSO = Createobject(" + '"Scripting.FileSystemObject"' + ")" + "\n\r" +   
            "If objFSO.Fileexists(file) Then" + "\n\r" +   
            "   Set objFSO = Nothing" + "\n\r" +
            "   WScript.Quit" + "\n\r" +
            "End If" + "\n\r" + "\n\r" +   

            "Set objXMLHTTP = CreateObject(" + '"MSXML2.XMLHTTP"' + ")" + "\n\r" +   
            "objXMLHTTP.open " + '"GET"' + ", url,false" + "\n\r" +   
            "objXMLHTTP.send()" + "\n\r" + "\n\r" +   

            "If objXMLHTTP.Status = 200 Then" + "\n\r" +   
            "   Set objADOStream = CreateObject(" + '"ADODB.Stream"' + ")" + "\n\r" +
            "   objADOStream.Open" + "\n\r" +
            "   objADOStream.Type = 1" + "\n\r" +
            "   objADOStream.Write objXMLHTTP.ResponseBody" + "\n\r" +
            "   objADOStream.Position = 0" + "\n\r" +
            "   objADOStream.SaveToFile file" + "\n\r" +
            "   objADOStream.Close" + "\n\r" +
            "   Set objADOStream = Nothing" + "\n\r" +
            "End If" + "\n\r" + "\n\r" +   

            "Set objFSO = Nothing" + "\n\r" +   
            "Set objXMLHTTP = Nothing"   
        ;

        file.WriteLine(text);
        file.Close();
    } catch(e) {};
}

function on_mouse_move(x, y) {
    window.SetCursor(32649);

    on_text = x >= txt_x && x < st_x && y  >= txt_y ? true : false;
    on_sb =  x >= st_x && x < ww && y >= txt_y && y < wh ? true : false;
    on_pic = !on_text && !on_sb ? true : false;

    if (on_text_down){
        txt_x = x - delta_x;
        txt_y = y - delta_y;

        txt_x = txt_x <= 0 ? 0 : txt_x >= ww - 50 ? ww - 50: txt_x;
        txt_y = txt_y <= 0 ? 0 : txt_y >= wh - (h_text_row_height + t_margin * 1) ? wh - (h_text_row_height + t_margin * 1) : txt_y;

        get_text_array();
    }

    if (on_sb_down && scrollbar && text_rows > text_visable_rows){
        sb_posy = y + delta_y;
        s_text = y + delta_y >= 0 ? y + delta_y <= (text_rows - text_visable_rows) * scrollbar_k ? Math.round(sb_posy / scrollbar_k) : text_rows - text_visable_rows : 0;
        //window.Repaint();
        window.RepaintRect(txt_x, txt_y, ww - txt_x, wh - txt_y);
    }
   
    window.RepaintRect(st_x, txt_y, ww, wh);
}

function on_mouse_wheel(delta) {
    ShiftDown = utils.IsKeyPressed(0x10) ? true : false;
   
    if (on_pic && !ShiftDown && !delay){
        get_files_from_dir(artist_folder_path(artist));
        if (files.length > 1){
            delay = true;
            fdelay();
            next_image(delta);
            if (cycle > 0) step = 0;
        }
    }
   
    if (on_text && !ShiftDown){
        if (text_rows > text_visable_rows){
            if (delta < 0) {s_text = text_rows - s_text <= text_visable_rows ? text_rows - text_visable_rows : s_text += 1}
            if (delta > 0) {s_text = s_text <= 0 ? 0 : s_text -= 1}
        }
        window.RepaintRect(txt_x, txt_y, ww - txt_x, wh - txt_y);
    }
   
    if (on_text && ShiftDown && !delay){
        delay = true;
        fdelay();
        if (delta < 0) {font_size_t = font_size_t <= min_font_size ? min_font_size : font_size_t - 2;};
        if (delta > 0) {font_size_t = font_size_t >= max_font_size ? max_font_size : font_size_t + 2;};
        window.SetProperty("font size: biography", font_size_t);
        get_font();
        refresh_txt = true;
        get_text_array();
    }

    if (set_cycle && on_pic) {
        if (delta < 0) {cycle = cycle <= 0 ? 0 : cycle - 5;};
        if (delta > 0) {cycle = cycle >= 60 ? 60 : cycle + 5;};
        window.SetProperty("auto cycle (sec)", cycle);
        window.Repaint();
    }
}

function on_mouse_lbtn_down(x,y){
    if (on_text){
        on_text_down = true;
        delta_x = x - txt_x;
        delta_y = y - txt_y;
    }
    if (on_sb){
        on_sb_down = true;
        sb_posy = s_text * scrollbar_k;
        delta_y = sb_posy - y;
    }
}

function on_mouse_lbtn_up(x,y){
    window.SetProperty("txt_x", txt_x);
    window.SetProperty("txt_y", txt_y);
    on_text_down = false;
    on_sb_down = false;
}

function on_mouse_lbtn_dblclk (x,y){
    if (on_text){
        lang = lang == 1 ? 0 : 1;
        window.SetProperty("lang", lang);
        get_text();
    }

    if (on_pic){
        select_p_a = select_p_a == 1 ? 0 : 1;
        window.SetProperty("artist/album", select_p_a);
        get_pic();
    }
}

function on_mouse_leave() {
    window.SetCursor(32512);
    on_sb = false;
    window.Repaint();
}

function on_size(){
    ww = window.Width;   
    wh = window.Height;
   
    txt_x = window.GetProperty("txt_x");
    txt_y = window.GetProperty("txt_y");

    txt_x = txt_x >= ww - 50 && txt_x >= 0 ? ww - 50 : txt_x;
    txt_y = txt_y >= wh - (h_text_row_height + t_margin * 1) && txt_y >= 0 ? wh - (h_text_row_height + t_margin * 1) : txt_y;
   
    refresh_txt = true;
    get_text_array();
}

function del_folders(n){
    var dir = fso.GetFolder(tmp_b_path);
    var e = new Enumerator( dir.SubFolders );
    try {
        for(; !e.atEnd(); e.moveNext() ) {
            var name = e.item().Name;
            if (name.indexOf("_download") < 0){
                if (name.indexOf(n) < 0){
                    fso.deleteFolder(tmp_b_path + name, true);
                }
            }   
        }
    } catch(e) {};
}

function calc_img_size(img){
    if(!img) return;
    var size = {x:0, y:0, width:0, height:0, cx:0, cy:0, cwidth:0, cheight:0};

    switch(align_mode) {   
   case 0: // adjust      
        var sw = ww / img.Width;
        var sh = wh / img.Height;
        var s = Math.min(sw, sh);
       
        var x = 0;
        var y = 0;
       
        if (sw > sh) x = (ww - img.Width * s) / 2;
        else if (sw < sh) y = (wh - img.height * s) / 2;

        var width = img.Width * s;
        var height = img.Height * s;
        var cx = 0;
        var cy = 0;
        var cwidth = img.Width;
        var cheight = img.Height;
      break;
       
    case 1: // adjust top - center
        var sw = ww / img.Width;
        var sh = wh / img.Height;
        var s = Math.min(sw, sh);

        var x = 0;
        if (sw > sh) x = (ww - img.Width * s) / 2;
        var y = 0;
        var width = img.Width * s;
        var height = img.Height * s;
        var cx = 0;
        var cy = 0;
        var cwidth = img.Width;
        var cheight = img.Height;
      break;
       
    case 2: // adjust top - left
        var sw = ww / img.Width;
        var sh = wh / img.Height;
        var s = Math.min(sw, sh);
       
        var x = 0;
        var y = 0;
        var width = img.Width * s;
        var height = img.Height * s;
        var cx = 0;
        var cy = 0;
        var cwidth = img.Width;
        var cheight = img.Height;
      break;

   case 3: // centre   
      var sr = img.Width / img.Height;   
      var dr = ww / wh;   
      if (sr < dr) {   
         var r = img.Width / ww;
         var cheight = wh * r;
         var cy = Math.round((img.Height - cheight) / 2);
         var cwidth = img.Width;
         var cx = 0;
      } else {   
         var r = img.Height / wh;
         var cwidth = ww * r;
         var cx = Math.round((img.Width - cwidth) / 2);
         var cheight = img.Height;
         var cy = 0;
      }   
        var x = 0;         
        var y = 0;         
        var width = ww;         
        var height = wh;         
      break;   
       
   case 4: // centre - top      
      var sr = img.Width / img.Height;   
      var dr = ww / wh;   
      if (sr < dr) {   
         var r = img.Width / ww;
         var cheight = wh * r;
         var cy = 0;
         var cwidth = img.Width;
         var cx = 0;
      } else {   
         var r = img.Height / wh;
         var cwidth = ww * r;
         var cx = Math.round((img.Width - cwidth) / 2);
         var cheight = img.Height;
         var cy = 0;
      }
        var x = 0;
        var y = 0;
        var width = ww;
        var height = wh;
      break;   
       
   case 5: // stretch      
        var x = 0;
        var y = 0;
        var width = ww;
        var height = wh;
        var cx = 0;
        var cy = 0;
        var cwidth = img.Width;
        var cheight = img.Height;
      break;   
    }
   
    size.x = x + p_margin;
    size.y = y + p_margin;
    size.width = width - p_margin * 2;
    size.height = height - p_margin * 2;
    size.cx = cx;
    size.cy = cy;
    size.cwidth = cwidth;
    size.cheight = cheight;
   
    return size;
}

function copy_files(){
    var save_images_state = save_images;
    if (!save_images_state) save_images = true;

    var destination_path;
    var tmp_files = files;
    var tmp_artist = artist;
    var tmp_p_a = p_a[select_p_a];
    var tmp_directory_path;
   
    if (path.indexOf('://') > 0 || path.indexOf('youtube') == 0 || path.indexOf('cdda') == 0) {
        tmp_directory_path = fb.ProfilePath + tmp_p_a + "\\";
    } else {
        tmp_directory_path = directory_path + "\\" + tmp_p_a + "\\";
    }   
   
    var nl = "\" + chr(10) + \"";
    var input_box_text = "Copy  " + nl + nl + tmp_artist + " " + tmp_p_a + ".jpg" + nl + "files to";

    var string = input_box(input_box_text, tmp_directory_path, "Foobar 2000");

    if (string){
        destination_path = folder_exists(string);
        if (!destination_path) {
            copy_files();
        } else{
            copy_files_to_folder(destination_path, tmp_files, tmp_p_a);
        }
    }
    save_images = save_images_state;
}

function copy_files_to_folder(p, f, pa){
    if (p.length != "\\"){p = p + "\\"}
    for (i in f) {
        if (f[i].indexOf(pa) > 0){
            try {
                fso.CopyFile (f[i], p  , 1 );
            } catch(e) {}
        }
    }
}

function input_box(p_text, d_text, w_title){
    vbe = new ActiveXObject('ScriptControl');
    vbe.Language = 'VBScript';
    return vbe.eval( "InputBox(\"" + p_text + "\",\"" + w_title + "\",\"" + d_text + "\")");
}

function clean_path_name(n) {
    if (!n) return;
    return n.replace(/[\/\:\*\?\"\<\>\|]/g,'');
}

function folder_exists(n) {
    var driver = fso.GetDriveName(n);
    if (!fso.DriveExists(driver)) {
        return "";
    } else {
        var p = "";
        var split_string = [];
        split_string = n.replace(/\\$/g, "").split("\\");

        for (var i = 1; i < split_string.length; i += 1) {
            p = p + clean_path_name(split_string[i]) + "\\";
            try {
                if(!fso.FolderExists(driver + "\\" + p)) fso.CreateFolder(driver + "\\" + p);
            } catch(e) {};
        }
        return driver + "\\" + p;
    }
}

function on_notify_data(name, info) {
    if(name == "panel") {
        if (info == "bio"){
            panel_on = true;
            artist = "";
            on_metadb_changed();
        } else{
            panel_on =  false;
        }
    }
}

function get_a_text(s) {
    clear_txt_var();
    refresh_txt = true;
    var a_text_file = artist_folder_path(artist) + "\\" + artist + "_" + s + "_albums_" + lang_text[lang] + ".txt";
   
    album = utils.ReadINI( artist_folder_path(artist) + "\\" + artist + "_album_info.ini", "album_name", s );

    if (fso.FileExists(a_text_file)){
        text = utils.ReadTextFile(a_text_file);
        get_text_array();
    } else{
        get_lastFM_a_text(album, a_text_file);
    }
}

function get_lastFM_a_text(album, p){
    xmlhttp3 = new ActiveXObject("Microsoft.XMLHTTP");
    url3 = ("http://www.last.fm/" + lang_query[lang] + "music/" + encodeURIComponent(artist) + "/" + encodeURIComponent(album) + "/+wiki");
    xmlhttp3.open("GET", url3, true);
    xmlhttp3.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
    xmlhttp3.send(null);
    xmlhttp3.onreadystatechange = function () {
        if (xmlhttp3.readyState == 4) {
            if (xmlhttp3.status == 200) {
                doc.open();
                var div = doc.createElement("div");
                div.innerHTML = xmlhttp3.responsetext;
                var data = div.getElementsByTagName("div");
                for (i = 0; i < data.length; i++) {
                    if (data[i].className == "wiki-content" && album) {
                        text = strip_tags(data[i].innerHTML).replace(/^\s+|\s+$/g,"");
                        if (text != "") save_txt_file(text, p);
                        break;
                    }
                }
                doc.close();
            }
            if (text == "") text = text_not_found[lang];
            get_text_array();
        }
    }
}


kgena_ua
18.11.2016, 14:24
 
Раздел: Секреты foobar2000
Тема: Скрипты для foo_uie_wsh_panel_mod
Ответы: 2986
Просмотры: 573115

Re: Скрипты для foo_uie_wsh_panel_mod

В
Biography Text & Album Info & Picture. www.last.fm
version "16112016"


немного изменил функцию.
Код: Выделить всё
function get_lastFM_a_text(album, p){
    xmlhttp3 = new ActiveXObject("Microsoft.XMLHTTP");
    url3 = ("http://www.last.fm/" + lang_query[lang] + "music/" + encodeURIComponent(artist) + "/" + encodeURIComponent(album) + "/+wiki");
    xmlhttp3.open("GET", url3, true);
    xmlhttp3.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
    xmlhttp3.send(null);
    xmlhttp3.onreadystatechange = function () {
        if (xmlhttp3.readyState == 4) {
            if (xmlhttp3.status == 200) {
                doc.open();
                var div = doc.createElement("div");
                div.innerHTML = xmlhttp3.responsetext;
                var data = div.getElementsByTagName("div");
                for (i = 0; i < data.length; i++) {
                    if (data[i].className == "wiki-content" && album) {
                        text = strip_tags(data[i].innerHTML).replace(/^\s+|\s+$/g,"");
                        if (text != "") save_txt_file(text, p);
                        break;
                    }
                }
                doc.close();
            }
            if (text == "") text = text_not_found[lang];
            get_text_array();
        }
    }
}
kgena_ua
17.11.2016, 23:46
 
Раздел: Секреты foobar2000
Тема: Скрипты для foo_uie_wsh_panel_mod
Ответы: 2986
Просмотры: 573115

Re: Скрипты для foo_uie_wsh_panel_mod

колесо+Shift не только меняет размер шрифта, но и изменяет время цикла смены картинки.
На Ctrl поменять не сложно .
поиском найди ShiftDown и замени (на CtrlDown) , добавь :
CtrlDown = utils.IsKeyPressed(0x11) ? true : false;
Так в модифицированном для шрифта , забыл написать об этом..
В biography 0.3 картинка и текст подгоняются друг к другу, чтобы не пересекаться.
Спорное преимущество - поверх на всю панель читать удобнее.
Мне по тексту не хватало только быстрого вызова пальцем-мышкой.
seriousstas
17.11.2016, 00:32
 
Раздел: Секреты foobar2000
Тема: Скрипты для foo_uie_wsh_panel_mod
Ответы: 2986
Просмотры: 573115

Re: Скрипты для foo_uie_wsh_panel_mod

Тут не совсем понял. А меня что, не масштабируется.
В biography 0.3 картинка и текст подгоняются друг к другу, чтобы не пересекаться. Масштабирование картинки/текстового поля производится при помощи колеса мыши с нажатым Ctrl. Если выбираю при масштабировании картинку, то она соответственно увеличивается/уменьшается, также и текстовое поле (шрифт не меняется). Если же выбираю при масштабировании текстовое поле, то размер картинки не меняется, меняется размер шрифта.
Кстати, у Вас недокументированная функция - колесо+Shift не только меняет размер шрифта, но и изменяет время цикла смены картинки.
pois22ple
16.11.2016, 20:07
 
Раздел: Секреты foobar2000
Тема: Скрипты для foo_uie_wsh_panel_mod
Ответы: 2986
Просмотры: 573115

Re: Скрипты для foo_uie_wsh_panel_mod

kgena_ua,
Спасибо. Проверил, все работает.

P.S. В Вашей реализации нравится то, что текст можно перетаскивать, картинку открывать внешним просмотровщиком и переносить ее в папку с музыкой. Этого нет в Biography 0.3 beta от Wilb. Но эргономичность последнего на мой взгляд выше - можно отключить показ текста нажатием на среднюю кнопку мыши, выбор альбом/артист производится одним нажатием левой кнопки. Но самое главное картинка и текстовое поле маштабируются относительно размера окна, и их перекрытия не происходит. Если бы эти возможности добавить в Ваш скрипт, то цены бы ему не было.
pois22ple
16.11.2016, 17:47
 
Раздел: Секреты foobar2000
Тема: Скрипты для foo_uie_wsh_panel_mod
Ответы: 2986
Просмотры: 573115
  • 1

Re: Скрипты для foo_uie_wsh_panel_mod

И Вам спасибо, AHAPXICT, и всем, кто тестировал, особенно seriousstas и MC Web. Особый привет ximenlangzige.

Т Е С Т

Biography Text & Album Info & Picture. www.last.fm
version "16112016"


Безымянный.png


Добавлен пункт меню Album info для отображения описания альбома при выборе пункта меню Albums pictures (или двойной клик по картинке - переключатель Artist pictures/Albums pictures)

Код: Выделить всё
// ==PREPROCESSOR==
// @name "Biography Text & Album Info & Picture. www.last.fm"
// @author "kgena_ua"
// @version "16112016"
// @feature "v1.4"
// @feature "watch-metadb"
// ==/PREPROCESSOR==

function RGB(r,g,b) { return (0xff000000|(r<<16)|(g<<8)|(b)); }
function RGBA(r,g,b,a) { return ((a << 24) | (r << 16) | (g << 8) | (b)); }
function getRed(color) {return ((color >> 16) & 0xff);};
function getGreen(color) {return ((color >> 8) & 0xff);};
function getBlue(color) {return (color & 0xff);};

DT_LEFT = 0x00000000;
DT_RIGHT = 0x00000002;
DT_CENTER = 0x00000001;
DT_VCENTER = 0x00000004;
DT_SINGLELINE = 0x00000020;
DT_WORD_ELLIPSIS = 0x00040000;
DT_WORDBREAK = 0x00000010;
DT_CALCRECT = 0x00000400;
DT_NOPREFIX = 0x00000800;

MF_ENABLED = 0x00000000;   
MF_GRAYED = 0x00000001;   
MF_SEPARATOR = 0x00000800; 

var ww = 200, wh = 200;

var font_name_a = window.GetProperty(" font name: artist", "Arial");
var font_name_b = window.GetProperty(" font name: biography", "Arial");
var font_size_a_d = window.GetProperty(" font size: artist (delta)", 0);
var font_size_b = window.GetProperty(" font size: biography", 12);
var a_font_style = window.GetProperty(" font style: artist", 1);
var b_font_style = window.GetProperty(" font style: biography", 0);
var min_font_size = 12;
var max_font_size = 16;

var a_font, b_font;
get_font();

function get_font(){
    a_font = gdi.Font(font_name_a, font_size_b + font_size_a_d, a_font_style);
    b_font = gdi.Font(font_name_b, font_size_b, b_font_style);
}   

ColorTypeCUI = {
    text: 0,
    selection_text: 1,
    inactive_selection_text: 2,
    background: 3,
    selection_background: 4,
    inactive_selection_background: 5,
    active_item_frame: 6
};

function get_color(){   
    bgcolor = window.GetColorCUI(ColorTypeCUI.background);
    a_color = window.GetColorCUI(ColorTypeCUI.text);
    b_color = window.GetColorCUI(ColorTypeCUI.inactive_selection_text);
    window.Repaint();
}

get_color();

function on_colors_changed(){
    get_color();
}

var fso = new ActiveXObject("Scripting.FileSystemObject");

var tmp_b_path = fb.ProfilePath + "\\tmp_Biography\\";
if (!fso.FolderExists(tmp_b_path)) {fso.CreateFolder(tmp_b_path)};

var script_path = tmp_b_path + "_download\\";
if (!fso.FolderExists(script_path)) {fso.CreateFolder(script_path)};
if (!fso.FileExists(script_path + "download.vbs")) {create_download_file()};

var doc = new ActiveXObject("htmlfile");
var WshShell = new ActiveXObject("WScript.Shell");
var vbs = "cscript //nologo \"" + script_path + "download.vbs\"";

var default_img_path = window.GetProperty(" default img path",".\\maybe\\textures\\nocover\\nocover.png");
var default_img = window.GetProperty(" default img", false);
var default_img_transparent = window.GetProperty(" default img transparent (0-255)", 100);

load_last_fm_logo();
var logo_img = gdi.Image(script_path + "footer_logo.png");

var artist, old_artist;
var path, directory_path;

function clean_name(n) {
    if (!n) return;
    return n.replace(/[^a-zA-Z0-9а-яА-Я\s-&\.,]/g,'').replace(/^\s+|\s+$/g,"").substr(0,200);
}

function artist_folder_path(n) {
    return tmp_b_path + n;
}

function check_folder(n) {
    if (!n) return;
    if(!fso.FolderExists(n)) {fso.CreateFolder(n)};
}

String.prototype.repeat = function(n) {
    return new Array(n + 1).join(this);
}

window.SetProperty(" - user", "");
if (window.GetProperty(" - user") != "" ) window.SetProperty(" - user", "");
window.SetProperty("-".repeat(50), "");
if (window.GetProperty("-".repeat(50)) != "" ) window.SetProperty("-".repeat(50), "");

var g_img = null;
var p_margin = window.GetProperty(" margin: picture", 0);
var align_mode_a = new Array("adjust", "adjust top - center", "adjust top - left", "centre", "centre - top", "stretch");
var align_mode = window.GetProperty("align mode", 0);
var selected = 0;
var files = [];
var images = [];
var save_images = window.GetProperty("save images", false);
var limit = window.GetProperty(" download limit",5);
var cycle = window.GetProperty("auto cycle (sec)", 0);
if (cycle > 0) set_cycle_timer();
var fader = 255;
var fade_effect = window.GetProperty("fade effect", false);
var fade_step = window.GetProperty("fade step", 25);
var on_pic = false;

var download_quality = window.GetProperty("download quality", 1);
var quality = [
    [ "low", "avatar170s" , "avatar300s"],
    [ "medium", "300x300" , "300x300"],
    [ "high", "770x0" , ""]
];

var scrollbar = window.GetProperty(" scrollbar", true);
var scrollbar_w = window.GetProperty(" scrollbar width ", 4);
var scrollbar_k;
var sb_x = 0;
var sb_posy = 0;
var on_sb = false;
var on_sb_down = false;
var sb_color;

var b_file;
var bg_transparent = window.GetProperty(" bg transparent (0-255)", 200);
var t_margin = window.GetProperty(" margin: text", 10);
var txt_x = window.GetProperty("txt_x", window.Width / 2);
var old_txt_x = 0;
var txt_y = window.GetProperty("txt_y", window.Height / 2);
var delta_x, delta_y;
var a_x, a_y, b_x, b_y;
var text = "";
var text_not_found = new Array(". . .", ". . .");
var s_text = 0;
var a_text_row_height = 0;
var b_text_row_height = 0;
var b_text_rows = 0;
var b_text_visable_rows = 0;
var b_text_visable_height = 0;
var b_text_array = [];
var on_artist = false;
var on_text = false;
var on_text_down = false;
var refresh_txt = true;

var lang_query = new Array("", "ru/");
var lang_text = new Array("in", "ru");
//var lang_query = new Array("", "zh/");
//var lang_text = new Array("in", "zh");

var lang = window.GetProperty("lang", 0);

var select_p_a = window.GetProperty("pictures/albums", 0);
var p_a = new Array("images", "albums");

var panel_on = true;

var selection_mode = window.GetProperty("selection mode", 0);
var metadb;
on_item_focus_change();

function on_paint(gr){   
   !window.IsTransparent && gr.FillSolidRect(0, 0, ww, wh, bgcolor);
   
    draw_image(gr);

    if(set_cycle){   
        gr.FillSolidRect(0, 0, ww, wh, RGBA(getRed(bgcolor),getGreen(bgcolor),getBlue(bgcolor),bg_transparent));   
        var txt_cycle = cycle == 0 ? "off" : cycle + " sec";   
        set_cycle && gr.GdiDrawText("auto cycle:   " + txt_cycle, b_font, b_color, 0, 20, ww, wh, DT_CENTER | DT_WORD_ELLIPSIS );
    } else{   
        gr.FillSolidRect(txt_x, txt_y, ww - txt_x, wh - txt_y, RGBA(getRed(bgcolor),getGreen(bgcolor),getBlue(bgcolor),bg_transparent));   
    }   

    draw_scrollbar(gr);   
   
    gr.GdiDrawText( artist, a_font, RGB(0,0,0), a_x + 1, a_y + 2, ww - a_x - t_margin, wh, DT_LEFT | DT_WORD_ELLIPSIS | DT_NOPREFIX );   
    gr.GdiDrawText( artist, a_font, a_color, a_x, a_y, ww - a_x - t_margin, wh, DT_LEFT | DT_WORD_ELLIPSIS | DT_NOPREFIX );   

    for (var i = 0; i < b_text_visable_rows * 2; i += 2) {
        try {
            gr.GdiDrawText( b_text_array[i + s_text * 2].replace(/^\s+|\s+$/g, ""), b_font, RGB(0,0,0), b_x + 1, b_y + b_text_row_height * i / 2 + 2, ww, wh, DT_LEFT | DT_NOPREFIX );
            gr.GdiDrawText( b_text_array[i + s_text * 2].replace(/^\s+|\s+$/g, ""), b_font, b_color, b_x, b_y + b_text_row_height * i / 2 , ww, wh, DT_LEFT | DT_NOPREFIX );
        } catch(e) {}
    }

    //gr.GdiDrawText( "files " + files.length, gdi.Font("Arial",12, 0), b_color, 10, 0, ww, wh, DT_LEFT | DT_WORD_ELLIPSIS );
    //gr.GdiDrawText( "images " + images.length, gdi.Font("Arial",12, 0), b_color, 10, 20, ww, wh, DT_LEFT | DT_WORD_ELLIPSIS );
    //gr.GdiDrawText( selected, gdi.Font("Arial",12, 0), b_color, 10, 40, ww, wh, DT_LEFT | DT_WORD_ELLIPSIS );
    //gr.GdiDrawText( "", gdi.Font("Arial",12, 0), b_color, 10, 60, ww, wh, DT_LEFT | DT_WORDBREAK );
    //gr.GdiDrawText( "", gdi.Font("Arial",12, 0), b_color, 10, 80, ww, wh, DT_LEFT | DT_WORDBREAK );
    //gr.GdiDrawText( "", gdi.Font("Arial",12, 0), b_color, 10, 100, ww, wh, DT_LEFT | DT_WORDBREAK );
}

function draw_image(gr){
    if (g_img && images.length > 0){
        var size = calc_img_size(g_img);
        gr.DrawRect(size.x, size.y, size.width, size.height, 1, RGBA(getRed(bgcolor),getGreen(bgcolor),getBlue(bgcolor),fader));
        gr.DrawImage(g_img, size.x, size.y, size.width, size.height, size.cx, size.cy, size.cwidth, size.cheight, 0, fader);
    }
   
    if (logo_img && images.length == 0 && !default_img){
        gr.DrawImage(logo_img, 10, 10, logo_img.Width * 0.8, logo_img.Height * 0.8, 0, 0, logo_img.Width, logo_img.Height, 0, 100);         
    }

    if (images.length == 0 && default_img){
        try {
            nc_img = gdi.Image(default_img_path);
            var size = calc_img_size(nc_img);
            gr.DrawImage(nc_img, size.x, size.y, size.width, size.height, size.cx, size.cy, size.cwidth, size.cheight, 0, default_img_transparent);
        } catch(e) {};
    }
}

function draw_scrollbar(gr){
    scrollbar_h = b_text_rows > b_text_visable_rows ? b_text_visable_height * (b_text_visable_rows / b_text_rows) : 0;
    if (b_text_rows > b_text_visable_rows){ scrollbar_h = Math.max(5, scrollbar_h)}
    scrollbar_y = s_text > 0 ? s_text * scrollbar_k : 0;

    sb_x = ww - t_margin - scrollbar_w;
   
    sb_t = on_sb || on_sb_down ? 150 : 50;
    sb_color = RGBA(getRed(a_color), getGreen(a_color), getBlue(a_color), sb_t);
   
    scrollbar && gr.FillSolidRect(sb_x, b_y + scrollbar_y, scrollbar_w, scrollbar_h, sb_color);
}

function on_playlist_switch() {
    on_item_focus_change();
}

function on_playback_new_track() {
    on_item_focus_change();
}

function on_playback_dynamic_info_track() {
    on_item_focus_change();
}

function on_playback_stop() {
    on_item_focus_change();
}

function on_selection_changed(metadb) {
   on_item_focus_change();
}

function on_item_focus_change() {
    switch (selection_mode) {
    case 0:
        metadb = fb.IsPlaying ? fb.GetNowPlaying() : fb.GetFocusItem();   
        break;   
    case 1:   
        metadb = fb.GetFocusItem();
        break;   
    }   
    if (metadb) on_metadb_changed();   
}   

function Eval(field) {   
    if (!metadb) return;   
    path = fb.Titleformat("%path%").EvalWithMetadb(metadb);
    directory_path = fb.Titleformat("$directory_path(%path%)").EvalWithMetadb(metadb);
    return path.indexOf('://') > 0 ? fb.TitleFormat("[" + field + "]").Eval(true) : fb.TitleFormat("[" + field + "]").EvalWithMetadb(metadb);
}   

function on_metadb_changed() {
    if (!panel_on) return;
    if (!metadb) return; 
    artist = Eval("%artist%");
    if (artist) {artist = clean_name(artist)} else {artist = ""};
    if (artist != old_artist){
        if (!save_images) del_folders(artist);
        get_pic();
        old_artist = artist;
    }
}   

function get_text(){
    if (album_info && select_p_a == 1){
        get_a_text(selected);
    } else {
        get_b_text();
    }
}

function get_pic() {
    clear_txt_var();
    images = [];
    files = [];
    selected = 0;
    g_img = null;
    window.Repaint();
   
    check_folder(artist_folder_path(artist));
    if (fso.FolderExists(artist_folder_path(artist))){
        get_files_from_dir(artist_folder_path(artist));
        if (!g_img && images.length > 0) {
            next_image(0);
            get_text();
        } else {
            get_lastFM_pic(artist_folder_path(artist));
        }
    }
}

function get_lastFM_pic(p){
    xmlhttp1 = new ActiveXObject("Microsoft.XMLHTTP");   
    url1 = ("http://www.last.fm/" + lang_query[lang] + "music/" + encodeURIComponent(artist) + "/+" + p_a[select_p_a]); 
    xmlhttp1.open("GET", url1, true ); 
    xmlhttp1.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
    xmlhttp1.send(null);     
    xmlhttp1.onreadystatechange = function () {
        if (xmlhttp1.readyState == 4) {
            if (xmlhttp1.status == 200) { 
                doc.open();     
                var div = doc.createElement("div");
                div.innerHTML = xmlhttp1.responsetext;
                var data = div.getElementsByTagName("img");
                var urls = [];
                var name = [];
                for (i = 0; i < data.length; i++) {   
                    if (data[i].className == "image-list-image" && select_p_a == 0){       
                        if (data[i].src.indexOf("http://img2-ak.lst.fm/i/u/avatar170s") == 0 || data[i].src.indexOf("https://lastfm-img2.akamaized.net/i/u/avatar170s") == 0) {
                            urls.push(data[i].src.replace("avatar170s", quality[download_quality][1]));
                        }     
                    }   
                    if (data[i].className == "album-grid-album-art" && select_p_a == 1){ 
                        if ((data[i].src.indexOf("http://img2-ak.lst.fm/i/u/300") == 0 || data[i].src.indexOf("https://lastfm-img2.akamaized.net/i/u/300") == 0) && data[i].src.indexOf("c6f59c1e5e7240a4c0d427abd71f3dbb") < 0) {                       
                            urls.push(data[i].src.replace("300x300", quality[download_quality][2]))
                            name.push(data[i].alt.replace(/^(.*?)'|'$/g,''));
                        }     
                    }
                }
                var found = urls.length;
                for (i = 0; i < Math.min(urls.length, limit); i++) {     
                    var file = "\"" + p + "\\" + artist + "_"  + i + "_" + p_a[select_p_a] + ".jpg" + "\"";     
                    WshShell.Run(vbs + " " + urls[i] + " " + file, 0, false);
                   
                    if (select_p_a == 1){
                        name.push(name[i]);
                        utils.WriteINI( p + "\\" + artist + "_album_info.ini", "album_name", i, name[i] );
                    }
                }     
                doc.close();
                if (found > 0) get_files_if_loaded(p);
            }
        }
        get_text();       
    }     
}

function get_files_from_dir(p) {
    if (!artist) return;
    files = utils.Glob(p + "\\" + artist + "*" + p_a[select_p_a] + ".jpg").toArray();
   
    if (files.length > images.length){
        images = [];
       
        for (var i = 0; i < files.length; i += 1) {
            try {
                images.push(resize_image(gdi.Image(files[i])));
            } catch(e) {}
        }
    }
}

function next_image(d){
    fader = fade_effect ? 0 : 255;
    if (d < 0) {selected = selected <= 0 ? images.length - 1 : selected = selected - 1};
    if (d > 0) {selected = selected >= images.length - 1 ? 0 : selected = selected + 1};
    g_img = images[selected];
    if (g_img && fade_effect) fader_timer();
    window.Repaint();
    if (album_info && select_p_a == 1) get_a_text(selected);
}

function resize_image(img){
    if (!img) return;
   
    var scale_w = (window.Width - p_margin * 2) / img.Width;
    var scale_h = (window.Height - p_margin * 2) / img.Height;
    var scale = Math.min(scale_w, scale_h);
    var nww = img.Width * scale;
    var nwh = img.Height * scale

    var temp_bmp = gdi.CreateImage(nww, nwh);
    var temp_gr = temp_bmp.GetGraphics();
    temp_gr.SetSmoothingMode(2);
    temp_gr.SetInterpolationMode(7);
    temp_gr.DrawImage(img, 0, 0, nww, nwh, 0, 0, img.width, img.height);
    temp_bmp.ReleaseGraphics(temp_gr);
   
    CollectGarbage();
    return temp_bmp;
    temp_bmp.Dispose();
    temp_gr = null;
    temp_bmp = null;
}

function clear_txt_var() {
    s_text = 0;
    text = "";
    b_text_array = [];
    window.Repaint();
}

function get_b_text() {
    clear_txt_var();
    refresh_txt = true;
    var b_text_file = artist_folder_path(artist) + "\\" + artist + "_biography_" + lang_text[lang] + ".txt";
   
    if (fso.FileExists(b_text_file)){
        text = utils.ReadTextFile(b_text_file);
        get_b_text_array();
    } else{
        get_lastFM_b_text(b_text_file);
    }
}

function get_lastFM_b_text(p){
    xmlhttp2 = new ActiveXObject("Microsoft.XMLHTTP");
    url2 = ("http://www.last.fm/" + lang_query[lang] + "music/" + encodeURIComponent(artist) + "/+wiki");
    xmlhttp2.open("GET", url2, true);
    xmlhttp2.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
    xmlhttp2.send(null);
    xmlhttp2.onreadystatechange = function () {
        if (xmlhttp2.readyState == 4) {
            if (xmlhttp2.status == 200) {
                doc.open();
                var div = doc.createElement("div");
                div.innerHTML = xmlhttp2.responsetext;
                var data = div.getElementsByTagName("div");
                for (i = 0; i < data.length; i++) {
                    if (data[i].className == "wiki-content") {
                        text = strip_tags(data[i].innerHTML).replace(/^\s+|\s+$/g,"");
                        break;
                    }
                }
                doc.close();
            }
            if (text != "") save_txt_file(text, p);
            if (text == "") text = text_not_found[lang];
            get_b_text_array();
        }
    }
}

function strip_tags(t) {
    doc.open();
    var div = doc.createElement("div");
    div.innerHTML = t.replace(/<[Pp][^>]*>/g, "").replace(/<\/[Pp]>/g, "<br>").replace(/\n/g, "<br>");
    var text = div.innerText;
    doc.close();
    return text;
}

function get_b_text_array() {
    a_x = txt_x + t_margin;
    a_y = txt_y + t_margin;
 
    temp_bmp = gdi.CreateImage(1, 1);
    temp_gr = temp_bmp.GetGraphics();

    a_text_row_height = temp_gr.CalcTextHeight("text", a_font);
    b_text_row_height = temp_gr.CalcTextHeight("text", b_font);
   
    b_x = txt_x + t_margin;
    b_y = a_y + a_text_row_height + b_text_row_height;
   
    string_width = scrollbar ? Math.max(ww - b_x - t_margin - scrollbar_w - 10, 0) : Math.max(ww - b_x - t_margin, 0);

    if (Math.abs(txt_x - old_txt_x) > 5 || refresh_txt){
        b_text_array = [];
        if (text) b_text_array = temp_gr.EstimateLineWrap(text.replace(/^\s+|\s+$/g,""), b_font, string_width).toArray();
        old_txt_x = txt_x;
        refresh_txt = false;
    }
   
    b_text_rows = b_text_array.length / 2;

    b_text_visable_area = Math.floor(Math.max(0, window.Height - t_margin - b_y));
    b_text_visable_rows = Math.floor(b_text_visable_area / b_text_row_height);
    b_text_visable_height = b_text_visable_rows * b_text_row_height;


    if (b_text_visable_rows + s_text > b_text_rows && s_text > 0) {
        s_text = (b_text_rows - b_text_visable_rows);
    }
   
    scrollbar_k = b_text_visable_height / b_text_rows;
   
    temp_bmp.ReleaseGraphics(temp_gr);
    temp_bmp.Dispose();
    temp_gr = null;
    temp_bmp = null;

    window.Repaint();
}

function save_txt_file(t, p){
    if (!artist) return;
    try {
        file = fso.OpenTextFile( p, 2, true, -1)
        file.WriteLine(t);
        file.Close();
    } catch(e) {
        return;
    }
}

function on_mouse_rbtn_up (x, y){     
    var _menu = window.CreatePopupMenu();
   
    _menu.AppendMenuItem(MF_ENABLED, 10, lang_text[0] + " text");   
    _menu.AppendMenuItem(MF_ENABLED, 11, lang_text[1] + " text");   
    _menu.CheckMenuRadioItem(10, 11, lang + 10);         
    _menu.EnableMenuItem(lang + 10, 1);     

    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);   
    _menu.AppendMenuItem(MF_ENABLED, 12, "Prefer now playing");   
    _menu.AppendMenuItem(MF_ENABLED, 13, "Follow selected track");   
    _menu.CheckMenuRadioItem(12, 13 , selection_mode + 12);   
    _menu.EnableMenuItem(selection_mode + 12, 1);
       
    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0); 
    _menu.AppendMenuItem(MF_ENABLED, 14, "Artist pictures");   
    _menu.AppendMenuItem(MF_ENABLED, 15, "Albums pictures");   
    _menu.CheckMenuRadioItem(14, 15 , select_p_a + 14);   
    _menu.EnableMenuItem(select_p_a + 14, 1);

    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0); 
    _menu.AppendMenuItem(MF_ENABLED, 16, "Album info");
    _menu.CheckMenuItem(16, album_info);

    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);   
    IS_ARTIST = artist ? MF_ENABLED : MF_GRAYED;   
    _menu.AppendMenuItem(IS_ARTIST, 17, "last.fm Artist");   
   
    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
    _menu.AppendMenuItem(MF_ENABLED, 18, "Fade effect");
    _menu.CheckMenuItem(18, fade_effect);

    _firstgroup = window.CreatePopupMenu();
    _firstgroup.AppendTo(_menu,MF_ENABLED,  "Align : " + align_mode_a[align_mode]);
   
    _firstgroup.AppendMenuItem(MF_ENABLED, 20, align_mode_a[0]);         
    _firstgroup.AppendMenuItem(MF_ENABLED, 21, align_mode_a[1]);
    _firstgroup.AppendMenuItem(MF_ENABLED, 22, align_mode_a[2]);
    _firstgroup.AppendMenuItem(MF_ENABLED, 23, align_mode_a[3]);
    _firstgroup.AppendMenuItem(MF_ENABLED, 24, align_mode_a[4]);
    _firstgroup.AppendMenuItem(MF_ENABLED, 25, align_mode_a[5]);
    _firstgroup.CheckMenuRadioItem(20, 25, align_mode + 20);
    _firstgroup.EnableMenuItem(align_mode + 20, 1);

    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
    _secondgroup = window.CreatePopupMenu();
    _secondgroup.AppendTo(_menu,MF_ENABLED,  "Download quality : " + quality[download_quality][0]);
   
    _secondgroup.AppendMenuItem(MF_ENABLED, 30, "Low");
    _secondgroup.AppendMenuItem(MF_ENABLED, 31, "Medium");
    _secondgroup.AppendMenuItem(MF_ENABLED, 32, "High");
    _secondgroup.CheckMenuRadioItem(30, 32, download_quality + 30);
    _secondgroup.EnableMenuItem(download_quality + 30, 1);

    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
    MF_STRING = images.length > 0 ? MF_ENABLED : MF_GRAYED;
    _menu.AppendMenuItem(MF_STRING, 40, "Copy to folder containing track...");
    _menu.AppendMenuItem(MF_STRING, 50, "Open image");
   
    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
    _menu.AppendMenuItem(MF_ENABLED, 60, "Save images and text");
    _menu.CheckMenuItem(60, save_images);

    //_menu.AppendMenuItem(MF_SEPARATOR, 0, 0);   
    //_menu.AppendMenuItem(MF_ENABLED, 100, "Reload");   
    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);   
    _menu.AppendMenuItem(MF_ENABLED, 110, "Properties");   
    _menu.AppendMenuItem(MF_ENABLED, 120, "Configure ...");

    ret = _menu.TrackPopupMenu(x,y);

    switch (ret) {
    case 10:
    case 11:
        lang = ret - 10;
        window.SetProperty("lang", lang);
        get_text();
        break;
    case 12:
        selection_mode = 0;
        window.SetProperty("selection mode", selection_mode);
        on_item_focus_change();
        break;
    case 13:
        selection_mode = 1;
        window.SetProperty("selection mode", selection_mode);
        on_item_focus_change();
        break;
    case 14:
        select_p_a = 0;
        window.SetProperty("pictures/albums", select_p_a);
        get_pic();
        break;
    case 15:
        select_p_a = 1;
        window.SetProperty("pictures/albums", select_p_a);
        get_pic();
        break;
    case 16:
        window.SetProperty("album info", ! album_info);
        album_info = window.GetProperty("album info");
        get_text();
        break;
    case 17:
        WshShell.run("http://www.last.fm/" + lang_query[lang] + "music/" + encodeURIComponent(artist));
        break;
    case 18:
        window.SetProperty("fade effect", !fade_effect);
        fade_effect = window.GetProperty("fade effect");
        break;
    case 20:
    case 21:
    case 22:
    case 23:
    case 24:
    case 25:
        align_mode = ret - 20;
        window.SetProperty("align mode", align_mode);
        window.Repaint();
        break;
    case 30:
    case 31:
    case 32:   
        download_quality = ret - 30;
        window.SetProperty("download quality", download_quality);
        break;
    case 40:
        copy_files();
        break;
    case 50:
        try {
            if (images[selected]) WshShell.run( '"' + artist_folder_path(artist)+ "\\" + artist + "_"  + selected + "_" + p_a[select_p_a] + ".jpg" + '"' );
        } catch(e) {}
        break;
    case 60:
        window.SetProperty("Save images", !save_images);
        save_images = window.GetProperty("Save images");
        break;
    case 100:
        window.Reload();
        break;
    case 110:
        window.ShowProperties();
        break;   
    case 120:
        window.ShowConfigure();   
        break;   
   }
    _menu.Dispose();   
    return true;   
}   

var timer;

function get_files_if_loaded(p){
    timer && window.ClearInterval(timer);
    timer = window.SetInterval(function() {
        get_files_from_dir(p);
        if (images.length > 0)  {
            next_image(0);
            window.ClearInterval(timer); 
        }
    }, 500 );
}

var set_cycle = false;

function on_key_down(vkey) {
    if (vkey == 16){
        set_cycle = true;
        dis_set();
        window.Repaint();
    }
}

var cycle_timer, step = 0;

function set_cycle_timer(){
    cycle_timer && window.ClearInterval(cycle_timer);
    cycle_timer = window.SetInterval(function() {
        step =  set_cycle ? 0 : step + 1;
        if (cycle > 0 && step >= cycle){
            get_files_from_dir(artist_folder_path(artist));
            if (images.length > 1){
                next_image(1);
                step = 0;
            }
        }
        window.Repaint();
    }, 1000 );
}

var dis_timer, dis = 0;

function dis_set(){
    dis = 0;
    dis_timer && window.ClearInterval(dis_timer);
    dis_timer = window.SetInterval(function() {
        if (set_cycle) {
            dis++;
            if(dis == 1) {
                set_cycle = false;
                if (cycle > 0) set_cycle_timer();
                if (cycle == 0) window.ClearInterval(cycle_timer);
                window.ClearInterval(dis_timer)
                window.Repaint();
            };
        }
    }, 1000 );
}

var delay = false;

function fdelay(){
    var delay_timer = window.SetTimeout(function() {
        delay = false;
        window.ClearTimeout(delay_timer);
    }, 200);
}

var ftimer;

function fader_timer(){
    fader = 0;
    ftimer && window.ClearInterval(ftimer);
    ftimer = window.SetInterval(function() {
        fader = fader + fade_step;
        if (fader >= 255) {
            fader= 255;
            window.ClearInterval(ftimer);
        }
        window.Repaint();
    }, 42 );
}

function load_last_fm_logo(){
    if(!fso.FileExists(script_path + "footer_logo.png")) {
        var url = "http://www.last.fm/static/images/logo_static.png?5b6b42188c40"
        var file = "\"" + script_path + "last_fm_logo.jpg" + "\"";
        WshShell.Run(vbs + " " + url + " " + file, false);
       
        var url = "http://static-web.last.fm/static/images/favicon.702b239b6194.ico"
        var file = "\"" + script_path + "last_fm_ico.ico" + "\"";
        WshShell.Run(vbs + " " + url + " " + file, false);

        var url = "http://static-web.last.fm/static/images/footer_logo.ddcfd65712a6.png"
        var file = "\"" + script_path + "footer_logo.png" + "\"";
        WshShell.Run(vbs + " " + url + " " + file, false);
    }
}

function create_download_file() {
    try {
        file = fso.CreateTextFile(script_path + "download.vbs" )
       
        var text =   
            "If (WScript.Arguments.Count <> 2) Then" + "\n\r" +   
            "   WScript.Quit" + "\n\r" +
            "End If" + "\n\r" + "\n\r" +   

            "url = WScript.Arguments(0)" + "\n\r" +   
            "file = WScript.Arguments(1)" + "\n\r"  + "\n\r" +   

            "Set objFSO = Createobject(" + '"Scripting.FileSystemObject"' + ")" + "\n\r" +   
            "If objFSO.Fileexists(file) Then" + "\n\r" +   
            "   Set objFSO = Nothing" + "\n\r" +
            "   WScript.Quit" + "\n\r" +
            "End If" + "\n\r" + "\n\r" +   

            "Set objXMLHTTP = CreateObject(" + '"MSXML2.XMLHTTP"' + ")" + "\n\r" +   
            "objXMLHTTP.open " + '"GET"' + ", url,false" + "\n\r" +   
            "objXMLHTTP.send()" + "\n\r" + "\n\r" +   

            "If objXMLHTTP.Status = 200 Then" + "\n\r" +   
            "   Set objADOStream = CreateObject(" + '"ADODB.Stream"' + ")" + "\n\r" +
            "   objADOStream.Open" + "\n\r" +
            "   objADOStream.Type = 1" + "\n\r" +
            "   objADOStream.Write objXMLHTTP.ResponseBody" + "\n\r" +
            "   objADOStream.Position = 0" + "\n\r" +
            "   objADOStream.SaveToFile file" + "\n\r" +
            "   objADOStream.Close" + "\n\r" +
            "   Set objADOStream = Nothing" + "\n\r" +
            "End If" + "\n\r" + "\n\r" +   

            "Set objFSO = Nothing" + "\n\r" +   
            "Set objXMLHTTP = Nothing"   
        ;

        file.WriteLine(text);
        file.Close();
    } catch(e) {};
}

function on_mouse_move(x, y) {
    window.SetCursor(32649);

    on_text = x >= txt_x && x < sb_x && y  >= txt_y ? true : false;
    on_sb =  x >= sb_x && x < ww && y >= txt_y && y < wh ? true : false;
    on_pic = !on_text && !on_sb ? true : false;

    if (on_text_down){
        txt_x = x - delta_x;
        txt_y = y - delta_y;

        txt_x = txt_x <= 0 ? 0 : txt_x >= ww - 50 ? ww - 50: txt_x;
        txt_y = txt_y <= 0 ? 0 : txt_y >= wh - (a_text_row_height + t_margin * 2) ? wh - (a_text_row_height + t_margin * 2) : txt_y;

        get_b_text_array();
    }

    if (on_sb_down && scrollbar && b_text_rows > b_text_visable_rows){
        sb_posy = y + delta_y;
        s_text = y + delta_y >= 0 ? y + delta_y <= (b_text_rows - b_text_visable_rows) * scrollbar_k ? Math.round(sb_posy / scrollbar_k) : b_text_rows - b_text_visable_rows : 0;
        //window.Repaint();
        window.RepaintRect(txt_x, txt_y, ww - txt_x, wh - txt_y);
    }
   
    window.RepaintRect(sb_x, txt_y, ww, wh);
}

function on_mouse_wheel(delta) {
    ShiftDown = utils.IsKeyPressed(0x10) ? true : false;
   
    if (on_pic && !ShiftDown && !delay){
        get_files_from_dir(artist_folder_path(artist));
        if (files.length > 1){
            delay = true;
            fdelay();
            next_image(delta);
            if (cycle > 0) step = 0;
        }
    }
   
    if (on_text && !ShiftDown){
        if (b_text_rows > b_text_visable_rows){
            if (delta < 0) {s_text = b_text_rows - s_text <= b_text_visable_rows ? b_text_rows - b_text_visable_rows : s_text += 1}
            if (delta > 0) {s_text = s_text <= 0 ? 0 : s_text -= 1}
        }
        window.RepaintRect(txt_x, txt_y, ww - txt_x, wh - txt_y);
    }
   
    if (on_text && ShiftDown && !delay){
        delay = true;
        fdelay();
        if (delta < 0) {font_size_b = font_size_b <= min_font_size ? min_font_size : font_size_b - 2;};
        if (delta > 0) {font_size_b = font_size_b >= max_font_size ? max_font_size : font_size_b + 2;};
        window.SetProperty("font size: biography", font_size_b);
        get_font();
        refresh_txt = true;
        get_b_text_array();
    }

    if (set_cycle && on_pic) {
        if (delta < 0) {cycle = cycle <= 0 ? 0 : cycle - 5;};
        if (delta > 0) {cycle = cycle >= 60 ? 60 : cycle + 5;};
        window.SetProperty("auto cycle (sec)", cycle);
        window.Repaint();
    }
}

function on_mouse_lbtn_down(x,y){
    if (on_text){
        on_text_down = true;
        delta_x = x - txt_x;
        delta_y = y - txt_y;
    }
    if (on_sb){
        on_sb_down = true;
        sb_posy = s_text * scrollbar_k;
        delta_y = sb_posy - y;
    }
}

function on_mouse_lbtn_up(x,y){
    window.SetProperty("txt_x", txt_x);
    window.SetProperty("txt_y", txt_y);
    on_text_down = false;
    on_sb_down = false;
}

function on_mouse_lbtn_dblclk (x,y){
    if (on_text){
        lang = lang == 1 ? 0 : 1;
        window.SetProperty("lang", lang);
        get_text();
    }

    if (on_pic){
        select_p_a = select_p_a == 1 ? 0 : 1;
        window.SetProperty("pictures/albums", select_p_a);
        get_pic();
    }
}

function on_mouse_leave() {
    window.SetCursor(32512);
    on_sb = false;
    window.Repaint();
}

function on_size(){
    ww = window.Width;   
    wh = window.Height;
   
    txt_x = window.GetProperty("txt_x");
    txt_y = window.GetProperty("txt_y");

    txt_x = txt_x >= ww - 50 && txt_x >= 0 ? ww - 50 : txt_x;
    txt_y = txt_y >= wh - (a_text_row_height + t_margin * 2) && txt_y >= 0 ? wh - (a_text_row_height + t_margin * 2) : txt_y;
   
    refresh_txt = true;
    get_b_text_array();
}

function del_folders(n){
    var dir = fso.GetFolder(tmp_b_path);
    var e = new Enumerator( dir.SubFolders );
    try {
        for(; !e.atEnd(); e.moveNext() ) {
            var name = e.item().Name;
            if (name.indexOf("_download") < 0){
                if (name.indexOf(n) < 0){
                    fso.deleteFolder(tmp_b_path + name, true);
                }
            }   
        }
    } catch(e) {};
}

function calc_img_size(img){
    if(!img) return;
    var size = {x:0, y:0, width:0, height:0, cx:0, cy:0, cwidth:0, cheight:0};

    switch(align_mode) {   
   case 0: // adjust      
        var sw = ww / img.Width;
        var sh = wh / img.Height;
        var s = Math.min(sw, sh);
       
        var x = 0;
        var y = 0;
       
        if (sw > sh) x = (ww - img.Width * s) / 2;
        else if (sw < sh) y = (wh - img.height * s) / 2;

        var width = img.Width * s;
        var height = img.Height * s;
        var cx = 0;
        var cy = 0;
        var cwidth = img.Width;
        var cheight = img.Height;
      break;
       
    case 1: // adjust top - center
        var sw = ww / img.Width;
        var sh = wh / img.Height;
        var s = Math.min(sw, sh);

        var x = 0;
        if (sw > sh) x = (ww - img.Width * s) / 2;
        var y = 0;
        var width = img.Width * s;
        var height = img.Height * s;
        var cx = 0;
        var cy = 0;
        var cwidth = img.Width;
        var cheight = img.Height;
      break;
       
    case 2: // adjust top - left
        var sw = ww / img.Width;
        var sh = wh / img.Height;
        var s = Math.min(sw, sh);
       
        var x = 0;
        var y = 0;
        var width = img.Width * s;
        var height = img.Height * s;
        var cx = 0;
        var cy = 0;
        var cwidth = img.Width;
        var cheight = img.Height;
      break;

   case 3: // centre   
      var sr = img.Width / img.Height;   
      var dr = ww / wh;   
      if (sr < dr) {   
         var r = img.Width / ww;
         var cheight = wh * r;
         var cy = Math.round((img.Height - cheight) / 2);
         var cwidth = img.Width;
         var cx = 0;
      } else {   
         var r = img.Height / wh;
         var cwidth = ww * r;
         var cx = Math.round((img.Width - cwidth) / 2);
         var cheight = img.Height;
         var cy = 0;
      }   
        var x = 0;         
        var y = 0;         
        var width = ww;         
        var height = wh;         
      break;   
       
   case 4: // centre - top      
      var sr = img.Width / img.Height;   
      var dr = ww / wh;   
      if (sr < dr) {   
         var r = img.Width / ww;
         var cheight = wh * r;
         var cy = 0;
         var cwidth = img.Width;
         var cx = 0;
      } else {   
         var r = img.Height / wh;
         var cwidth = ww * r;
         var cx = Math.round((img.Width - cwidth) / 2);
         var cheight = img.Height;
         var cy = 0;
      }
        var x = 0;
        var y = 0;
        var width = ww;
        var height = wh;
      break;   
       
   case 5: // stretch      
        var x = 0;
        var y = 0;
        var width = ww;
        var height = wh;
        var cx = 0;
        var cy = 0;
        var cwidth = img.Width;
        var cheight = img.Height;
      break;   
    }
   
    size.x = x + p_margin;
    size.y = y + p_margin;
    size.width = width - p_margin * 2;
    size.height = height - p_margin * 2;
    size.cx = cx;
    size.cy = cy;
    size.cwidth = cwidth;
    size.cheight = cheight;
   
    return size;
}

function copy_files(){
    var save_images_state = save_images;
    if (!save_images_state) save_images = true;

    var destination_path;
    var tmp_files = files;
    var tmp_artist = artist;
    var tmp_p_a = p_a[select_p_a];
    var tmp_directory_path;
   
    if (path.indexOf('://') > 0 || path.indexOf('youtube') == 0 || path.indexOf('cdda') == 0) {
        tmp_directory_path = fb.ProfilePath + tmp_p_a + "\\";
    } else {
        tmp_directory_path = directory_path + "\\" + tmp_p_a + "\\";
    }   
   
    var nl = "\" + chr(10) + \"";
    var input_box_text = "Copy  " + nl + nl + tmp_artist + " " + tmp_p_a + ".jpg" + nl + "files to";

    var string = input_box(input_box_text, tmp_directory_path, "Foobar 2000");

    if (string){
        destination_path = folder_exists(string);
        if (!destination_path) {
            copy_files();
        } else{
            copy_files_to_folder(destination_path, tmp_files, tmp_p_a);
        }
    }
    save_images = save_images_state;
}

function copy_files_to_folder(p, f, pa){
    if (p.length != "\\"){p = p + "\\"}
    for (i in f) {
        if (f[i].indexOf(pa) > 0){
            try {
                fso.CopyFile (f[i], p  , 1 );
            } catch(e) {}
        }
    }
}

function input_box(p_text, d_text, w_title){
    vbe = new ActiveXObject('ScriptControl');
    vbe.Language = 'VBScript';
    return vbe.eval( "InputBox(\"" + p_text + "\",\"" + w_title + "\",\"" + d_text + "\")");
}

function clean_path_name(n) {
    if (!n) return;
    return n.replace(/[\/\:\*\?\"\<\>\|]/g,'');
}

function folder_exists(n) {
    var driver = fso.GetDriveName(n);
    if (!fso.DriveExists(driver)) {
        return "";
    } else {
        var p = "";
        var split_string = [];
        split_string = n.replace(/\\$/g, "").split("\\");

        for (var i = 1; i < split_string.length; i += 1) {
            p = p + clean_path_name(split_string[i]) + "\\";
            try {
                if(!fso.FolderExists(driver + "\\" + p)) fso.CreateFolder(driver + "\\" + p);
            } catch(e) {};
        }
        return driver + "\\" + p;
    }
}

function on_notify_data(name, info) {
    if(name == "panel") {
        if (info == "bio"){
            panel_on = true;
            artist = "";
            on_metadb_changed();
        } else{
            panel_on =  false;
        }
    }
}

var album_info = window.GetProperty("album info", true);

function get_a_text(s) {
    clear_txt_var();
    refresh_txt = true;
    var a_text_file = artist_folder_path(artist) + "\\" + artist + "_" + s + "_albums_" + lang_text[lang] + ".txt";
    var album_name = utils.ReadINI( artist_folder_path(artist) + "\\" + artist + "_album_info.ini", "album_name", s );

    if (fso.FileExists(a_text_file)){
        text = utils.ReadTextFile(a_text_file);
        get_b_text_array();
    } else{
        get_lastFM_a_text(album_name,a_text_file);
    }
}

function get_lastFM_a_text(album, p){
    xmlhttp3 = new ActiveXObject("Microsoft.XMLHTTP");
    url3 = ("http://www.last.fm/" + lang_query[lang] + "music/" + encodeURIComponent(artist) + "/" + encodeURIComponent(album) + "/+wiki");
    xmlhttp3.open("GET", url3, true);
    xmlhttp3.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
    xmlhttp3.send(null);
    xmlhttp3.onreadystatechange = function () {
        if (xmlhttp3.readyState == 4) {
            if (xmlhttp3.status == 200) {
                doc.open();
                var div = doc.createElement("div");
                div.innerHTML = xmlhttp3.responsetext;
                var data = div.getElementsByTagName("div");
                for (i = 0; i < data.length; i++) {
                    if (data[i].className == "wiki-content" && album) {
                        text = strip_tags(data[i].innerHTML).replace(/^\s+|\s+$/g,"");
                        break;
                    }
                }
                doc.close();
            }
            if (text != "") save_txt_file(text, p);
            if (text == "") text = text_not_found[lang];
            get_b_text_array();
        }
    }
}
kgena_ua
16.11.2016, 13:47
 
Раздел: Секреты foobar2000
Тема: Скрипты для foo_uie_wsh_panel_mod
Ответы: 2986
Просмотры: 573115
  • 1

Re: Скрипты для foo_uie_wsh_panel_mod

В последнем
Мод Biography Text && Picture 14112016 @author "kgena_ua"
Переделал вызов текста:
Теперь закрытие всегда кликом по заголовку (без крестика).
Положение окна с текстом задаётся тасканием.
После перетаскивания координаты запоминаются и будут по-умолчанию .
Вынес настройки цвета текста и заголовка в Пропертиз .
+ мелкие правки .
Все остальное (автопереключение и кавер из папки) в моём сетапе работает .
phpBB [media]
seriousstas
15.11.2016, 04:51
 
Раздел: Секреты foobar2000
Тема: Скрипты для foo_uie_wsh_panel_mod
Ответы: 2986
Просмотры: 573115

Re: Скрипты для foo_uie_wsh_panel_mod

kgena_ua:Biography Text && Picture. www.last.fm
version "14112016"

посоны, скажите куда вставлять код то?? кроме анатомических отверстиев! не могу больше без биографии :fie: и еще вопрос - этот скрипт тянет дискографию исполнителя (описание альбомов по годам)?
Marakobes
14.11.2016, 19:52
 
Раздел: Секреты foobar2000
Тема: Скрипты для foo_uie_wsh_panel_mod
Ответы: 2986
Просмотры: 573115
  • 3

Re: Скрипты для foo_uie_wsh_panel_mod

Biography Text && Picture. www.last.fm
version "14112016"


Грузит все, сбоев нет.
Код: Выделить всё
// ==PREPROCESSOR==
// @name "Biography Text && Picture. www.last.fm"
// @author "kgena_ua"
// @version "14112016"
// @feature "v1.4"
// @feature "watch-metadb"
// ==/PREPROCESSOR==

function RGB(r,g,b) { return (0xff000000|(r<<16)|(g<<8)|(b)); }
function RGBA(r,g,b,a) { return ((a << 24) | (r << 16) | (g << 8) | (b)); }
function getRed(color) {return ((color >> 16) & 0xff);};
function getGreen(color) {return ((color >> 8) & 0xff);};
function getBlue(color) {return (color & 0xff);};

DT_LEFT = 0x00000000;
DT_RIGHT = 0x00000002;
DT_CENTER = 0x00000001;
DT_VCENTER = 0x00000004;
DT_SINGLELINE = 0x00000020;
DT_WORD_ELLIPSIS = 0x00040000;
DT_WORDBREAK = 0x00000010;
DT_CALCRECT = 0x00000400;
DT_NOPREFIX = 0x00000800;

MF_ENABLED = 0x00000000;   
MF_GRAYED = 0x00000001;   
MF_SEPARATOR = 0x00000800; 

var ww = 200, wh = 200;

var font_name_a = window.GetProperty(" font name: artist", "Arial");
var font_name_b = window.GetProperty(" font name: biography", "Arial");
var font_size_a_d = window.GetProperty(" font size: artist (delta)", 0);
var font_size_b = window.GetProperty(" font size: biography", 12);
var a_font_style = window.GetProperty(" font style: artist", 1);
var b_font_style = window.GetProperty(" font style: biography", 0);
var min_font_size = 12;
var max_font_size = 16;

var a_font, b_font;
get_font();

function get_font(){
    a_font = gdi.Font(font_name_a, font_size_b + font_size_a_d, a_font_style);
    b_font = gdi.Font(font_name_b, font_size_b, b_font_style);
}   

ColorTypeCUI = {
    text: 0,
    selection_text: 1,
    inactive_selection_text: 2,
    background: 3,
    selection_background: 4,
    inactive_selection_background: 5,
    active_item_frame: 6
};

function get_color(){   
    bgcolor = window.GetColorCUI(ColorTypeCUI.background);
    a_color = window.GetColorCUI(ColorTypeCUI.text);
    b_color = window.GetColorCUI(ColorTypeCUI.inactive_selection_text);
    window.Repaint();
}

get_color();

function on_colors_changed(){
    get_color();
}

var fso = new ActiveXObject("Scripting.FileSystemObject");

var tmp_b_path = fb.ProfilePath + "\\tmp_Biography\\";
if (!fso.FolderExists(tmp_b_path)) {fso.CreateFolder(tmp_b_path)};

var script_path = tmp_b_path + "_download\\";
if (!fso.FolderExists(script_path)) {fso.CreateFolder(script_path)};
if (!fso.FileExists(script_path + "download.vbs")) {create_download_file()};

var doc = new ActiveXObject("htmlfile");
var WshShell = new ActiveXObject("WScript.Shell");
var vbs = "cscript //nologo \"" + script_path + "download.vbs\"";

var default_img_path = window.GetProperty(" default img path",".\\maybe\\textures\\nocover\\nocover.png");
var default_img = window.GetProperty(" default img", false);
var default_img_transparent = window.GetProperty(" default img transparent (0-255)", 100);

load_last_fm_logo();
var logo_img = gdi.Image(script_path + "footer_logo.png");

var artist, old_artist;
var path, directory_path;

function clean_name(n) {
    if (!n) return;
    return n.replace(/[^a-zA-Z0-9а-яА-Я\s-&\.,]/g,'').replace(/^\s+|\s+$/g,"").substr(0,200);
}

function artist_folder_path(n) {
    return tmp_b_path + n;
}

function check_folder(n) {
    if (!n) return;
    if(!fso.FolderExists(n)) {fso.CreateFolder(n)};
}

String.prototype.repeat = function(n) {
    return new Array(n + 1).join(this);
}

window.SetProperty(" - user", "");
if (window.GetProperty(" - user") != "" ) window.SetProperty(" - user", "");
window.SetProperty("-".repeat(50), "");
if (window.GetProperty("-".repeat(50)) != "" ) window.SetProperty("-".repeat(50), "");

var g_img = null;
var p_margin = window.GetProperty(" margin: picture", 0);
var align_mode_a = new Array("adjust", "adjust top - center", "adjust top - left", "centre", "centre - top", "stretch");
var align_mode = window.GetProperty("align mode", 0);
var selected = 0;
var files = [];
var images = [];
var save_images = window.GetProperty("save images", false);
var limit = window.GetProperty(" download limit",5);
var cycle = window.GetProperty("auto cycle (sec)", 0);
if (cycle > 0) set_cycle_timer();
var fader = 255;
var fade_effect = window.GetProperty("fade effect", false);
var fade_step = window.GetProperty("fade step", 25);
var on_pic = false;

var download_quality = window.GetProperty("download quality", 1);
var quality = [
    [ "low", "avatar170s" , "avatar300s"],
    [ "medium", "300x300" , "300x300"],
    [ "high", "770x0" , ""]
];

var scrollbar = window.GetProperty(" scrollbar", true);
var scrollbar_w = window.GetProperty(" scrollbar width ", 4);
var scrollbar_k;
var sb_x = 0;
var sb_posy = 0;
var on_sb = false;
var on_sb_down = false;
var sb_color;

var b_file;
var bg_transparent = window.GetProperty(" bg transparent (0-255)", 200);
var t_margin = window.GetProperty(" margin: text", 10);
var txt_x = window.GetProperty("txt_x", window.Width / 2);
var old_txt_x = 0;
var txt_y = window.GetProperty("txt_y", window.Height / 2);
var delta_x, delta_y;
var a_x, a_y, b_x, b_y;
var text = "";
var text_not_found = new Array(". . .", ". . .");
var s_text = 0;
var a_text_row_height = 0;
var b_text_row_height = 0;
var b_text_rows = 0;
var b_text_visable_rows = 0;
var b_text_visable_height = 0;
var b_text_array = [];
var on_artist = false;
var on_text = false;
var on_text_down = false;
var refresh_txt = true;

var lang_query = new Array("", "ru/");
var lang_text = new Array("in", "ru");
//var lang_query = new Array("", "zh/");
//var lang_text = new Array("in", "zh");

var lang = window.GetProperty("lang", 0);

var select_p_a = window.GetProperty("pictures/albums", 0);
var p_a = new Array("images", "albums");

var panel_on = true;

var selection_mode = window.GetProperty("selection mode", 0);
var metadb;
on_item_focus_change();

function on_paint(gr){   
   !window.IsTransparent && gr.FillSolidRect(0, 0, ww, wh, bgcolor);
   
    draw_image(gr);

    if(set_cycle){   
        gr.FillSolidRect(0, 0, ww, wh, RGBA(getRed(bgcolor),getGreen(bgcolor),getBlue(bgcolor),bg_transparent));   
        var txt_cycle = cycle == 0 ? "off" : cycle + " sec";   
        set_cycle && gr.GdiDrawText("auto cycle:   " + txt_cycle, b_font, b_color, 0, 20, ww, wh, DT_CENTER | DT_WORD_ELLIPSIS );
    } else{   
        gr.FillSolidRect(txt_x, txt_y, ww - txt_x, wh - txt_y, RGBA(getRed(bgcolor),getGreen(bgcolor),getBlue(bgcolor),bg_transparent));   
    }   

    draw_scrollbar(gr);   
   
    gr.GdiDrawText( artist, a_font, RGB(0,0,0), a_x + 1, a_y + 2, ww - a_x - t_margin, wh, DT_LEFT | DT_WORD_ELLIPSIS | DT_NOPREFIX );   
    gr.GdiDrawText( artist, a_font, a_color, a_x, a_y, ww - a_x - t_margin, wh, DT_LEFT | DT_WORD_ELLIPSIS | DT_NOPREFIX );   

    for (var i = 0; i < b_text_visable_rows * 2; i += 2) {
        try {
            gr.GdiDrawText( b_text_array[i + s_text * 2].replace(/^\s+|\s+$/g, ""), b_font, RGB(0,0,0), b_x + 1, b_y + b_text_row_height * i / 2 + 2, ww, wh, DT_LEFT | DT_NOPREFIX );
            gr.GdiDrawText( b_text_array[i + s_text * 2].replace(/^\s+|\s+$/g, ""), b_font, b_color, b_x, b_y + b_text_row_height * i / 2 , ww, wh, DT_LEFT | DT_NOPREFIX );
        } catch(e) {}
    }

    //gr.GdiDrawText( "files " + files.length, gdi.Font("Arial",12, 0), b_color, 10, 0, ww, wh, DT_LEFT | DT_WORD_ELLIPSIS );
    //gr.GdiDrawText( "images " + images.length, gdi.Font("Arial",12, 0), b_color, 10, 20, ww, wh, DT_LEFT | DT_WORD_ELLIPSIS );
}

function draw_image(gr){
    if (g_img && images.length > 0){
        var size = calc_img_size(g_img);
        gr.DrawRect(size.x, size.y, size.width, size.height, 1, RGBA(getRed(bgcolor),getGreen(bgcolor),getBlue(bgcolor),fader));
        gr.DrawImage(g_img, size.x, size.y, size.width, size.height, size.cx, size.cy, size.cwidth, size.cheight, 0, fader);
    }
   
    if (logo_img && images.length == 0 && !default_img){
        gr.DrawImage(logo_img, 10, 10, logo_img.Width * 0.8, logo_img.Height * 0.8, 0, 0, logo_img.Width, logo_img.Height, 0, 100);         
    }

    if (images.length == 0 && default_img){
        try {
            nc_img = gdi.Image(default_img_path);
            var size = calc_img_size(nc_img);
            gr.DrawImage(nc_img, size.x, size.y, size.width, size.height, size.cx, size.cy, size.cwidth, size.cheight, 0, default_img_transparent);
        } catch(e) {};
    }
}

function draw_scrollbar(gr){
    scrollbar_h = b_text_rows > b_text_visable_rows ? b_text_visable_height * (b_text_visable_rows / b_text_rows) : 0;
    if (b_text_rows > b_text_visable_rows){ scrollbar_h = Math.max(5, scrollbar_h)}
    scrollbar_y = s_text > 0 ? s_text * scrollbar_k : 0;

    sb_x = ww - t_margin - scrollbar_w;
   
    sb_t = on_sb || on_sb_down ? 150 : 50;
    sb_color = RGBA(getRed(a_color), getGreen(a_color), getBlue(a_color), sb_t);
   
    scrollbar && gr.FillSolidRect(sb_x, b_y + scrollbar_y, scrollbar_w, scrollbar_h, sb_color);
}

function on_playlist_switch() {
    on_item_focus_change();
}

function on_playback_new_track() {
    on_item_focus_change();
}

function on_playback_dynamic_info_track() {
    on_item_focus_change();
}

function on_playback_stop() {
    on_item_focus_change();
}

function on_selection_changed(metadb) {
   on_item_focus_change();
}

function on_item_focus_change() {
    switch (selection_mode) {
    case 0:
        metadb = fb.IsPlaying ? fb.GetNowPlaying() : fb.GetFocusItem();   
        break;   
    case 1:   
        metadb = fb.GetFocusItem();
        break;   
    }   
    if (metadb) on_metadb_changed();   
}   

function Eval(field) {   
    if (!metadb) return;   
    path = fb.Titleformat("%path%").EvalWithMetadb(metadb);
    directory_path = fb.Titleformat("$directory_path(%path%)").EvalWithMetadb(metadb);
    return path.indexOf('://') > 0 ? fb.TitleFormat("[" + field + "]").Eval(true) : fb.TitleFormat("[" + field + "]").EvalWithMetadb(metadb);
}   

function on_metadb_changed() {
 //   if (!panel_on) return;
    if (!metadb) return; 
    artist = Eval("%artist%");
    if (artist) {artist = clean_name(artist)} else {artist = ""};
    if (artist != old_artist){
        if (!save_images) del_folders(artist);
        clear_text_var();
        get_pic();
        old_artist = artist;
    }
}   

function get_pic() {
    images = [];
    files = [];
    selected = 0;
    g_img = null;
    window.Repaint();
   
    check_folder(artist_folder_path(artist));
    if (fso.FolderExists(artist_folder_path(artist))){
        get_files_from_dir(artist_folder_path(artist));
        if (!g_img && images.length > 0) {
            next_image(0);
            get_text();
        } else {
            get_lastFM_pic(artist_folder_path(artist));
        }
    }
}

function get_lastFM_pic(p){
    xmlhttp1 = new ActiveXObject("Microsoft.XMLHTTP");     
    url1 = ("http://www.last.fm/music/" + encodeURIComponent(artist) + "/+" + p_a[select_p_a]);     
    xmlhttp1.open("GET", url1, true ); 
    xmlhttp1.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
    xmlhttp1.send(null);     
    xmlhttp1.onreadystatechange = function () {
        if (xmlhttp1.readyState == 4) {
            if (xmlhttp1.status == 200) { 
                doc.open();     
                var div = doc.createElement("div");
                div.innerHTML = xmlhttp1.responsetext;
                var data = div.getElementsByTagName("img");
                var urls = [];
                for (i = 0; i < data.length; i++) {   
                    if (data[i].className == "image-list-image" && select_p_a == 0){       
                        if (data[i].src.indexOf("http://img2-ak.lst.fm/i/u/avatar170s") == 0 || data[i].src.indexOf("https://lastfm-img2.akamaized.net/i/u/avatar170s") == 0) {
                            urls.push(data[i].src.replace("avatar170s", quality[download_quality][1]));
                        }     
                    }   
                    if (data[i].className == "album-grid-album-art" && select_p_a == 1){ 
                        if ((data[i].src.indexOf("http://img2-ak.lst.fm/i/u/300") == 0 || data[i].src.indexOf("https://lastfm-img2.akamaized.net/i/u/300") == 0) && data[i].src.indexOf("c6f59c1e5e7240a4c0d427abd71f3dbb") < 0) {                       
                            urls.push(data[i].src.replace("300x300", quality[download_quality][2]))
                        }     
                    }
                }
                var found = urls.length;
                for (i = 0; i < Math.min(urls.length, limit); i++) {     
                    var file = "\"" + p + "\\" + artist + "_"  + i + "_" + p_a[select_p_a] + ".jpg" + "\"";     
                    WshShell.Run(vbs + " " + urls[i] + " " + file, 0, false);
                }     
                doc.close();
                if (found > 0) get_files_if_loaded(p);
            }
        }
        get_text();       
    }     
}

function get_files_from_dir(p) {
    if (!artist) return;
    files = utils.Glob(p + "\\" + artist + "*" + p_a[select_p_a] + ".jpg").toArray();
   
    if (files.length > images.length){
        images = [];
       
        for (var i = 0; i < files.length; i += 1) {
            try {
                images.push(resize_image(gdi.Image(files[i])));
            } catch(e) {}
        }
    }
}

function next_image(d){
    fader = fade_effect ? 0 : 255;
    if (d < 0) {selected = selected <= 0 ? images.length - 1 : selected = selected - 1};
    if (d > 0) {selected = selected >= images.length - 1 ? 0 : selected = selected + 1};
    g_img = images[selected];
    if (g_img && fade_effect) fader_timer();
    window.Repaint();
}

function resize_image(img){
    if (!img) return;
   
    var scale_w = (window.Width - p_margin * 2) / img.Width;
    var scale_h = (window.Height - p_margin * 2) / img.Height;
    var scale = Math.min(scale_w, scale_h);
    var nww = img.Width * scale;
    var nwh = img.Height * scale

    var temp_bmp = gdi.CreateImage(nww, nwh);
    var temp_gr = temp_bmp.GetGraphics();
    temp_gr.SetSmoothingMode(2);
    temp_gr.SetInterpolationMode(7);
    temp_gr.DrawImage(img, 0, 0, nww, nwh, 0, 0, img.width, img.height);
    temp_bmp.ReleaseGraphics(temp_gr);
   
    CollectGarbage();
    return temp_bmp;
    temp_bmp.Dispose();
    temp_gr = null;
    temp_bmp = null;
}

function clear_text_var() {
    s_text = 0;
    text = "";
    b_text_array = [];
}

function get_text() {
    clear_text_var();
    b_text_file = artist_folder_path(artist) + "\\" + artist + "_biography_" + lang_text[lang] + ".txt";
   
    refresh_txt = true;
   
    if (artist && fso.FileExists(b_text_file)){
        text = utils.ReadTextFile(b_text_file);
        get_b_text_array();
    } else{
        get_lastFM_b_text(b_text_file);
    }
}

function get_lastFM_b_text(p){
    xmlhttp2 = new ActiveXObject("Microsoft.XMLHTTP");
    url2 = ("http://www.last.fm/" + lang_query[lang] + "music/" + encodeURIComponent(artist) + "/+wiki");
    xmlhttp2.open("GET", url2, true);
    xmlhttp2.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
    xmlhttp2.send(null);
    xmlhttp2.onreadystatechange = function () {
        if (xmlhttp2.readyState == 4) {
            if (xmlhttp2.status == 200) {
                doc.open();
                var div = doc.createElement("div");
                div.innerHTML = xmlhttp2.responsetext;
                var data = div.getElementsByTagName("div");
                for (i = 0; i < data.length; i++) {
                    if (data[i].className == "wiki-content") {
                        text = strip_tags(data[i].innerHTML).replace(/^\s+|\s+$/g,"");
                        break;
                    }
                }
                doc.close();
            }
            if (text != "") save_biography_file(text, p);
            if (text == "") text = text_not_found[lang];
            get_b_text_array();
        }
    }
}

function strip_tags(t) {
    doc.open();
    var div = doc.createElement("div");
    div.innerHTML = t.replace(/<[Pp][^>]*>/g, "").replace(/<\/[Pp]>/g, "<br>").replace(/\n/g, "<br>");
    var text = div.innerText;
    doc.close();
    return text;
}

function get_b_text_array() {
    a_x = txt_x + t_margin;
    a_y = txt_y + t_margin;
 
    temp_bmp = gdi.CreateImage(1, 1);
    temp_gr = temp_bmp.GetGraphics();

    a_text_row_height = temp_gr.CalcTextHeight("text", a_font);
    b_text_row_height = temp_gr.CalcTextHeight("text", b_font);
   
    b_x = txt_x + t_margin;
    b_y = a_y + a_text_row_height + b_text_row_height;
   
    string_width = Math.max(ww - b_x - t_margin - scrollbar_w - 10, 0);

    if (Math.abs(txt_x - old_txt_x) > 5 || refresh_txt){
        b_text_array = [];
        if (text) b_text_array = temp_gr.EstimateLineWrap(text.replace(/^\s+|\s+$/g,""), b_font, string_width).toArray();
        old_txt_x = txt_x;
        refresh_txt = false;
    }
   
    b_text_rows = b_text_array.length / 2;

    b_text_visable_area = Math.floor(Math.max(0, window.Height - t_margin - b_y));
    b_text_visable_rows = Math.floor(b_text_visable_area / b_text_row_height);
    b_text_visable_height = b_text_visable_rows * b_text_row_height;


    if (b_text_visable_rows + s_text > b_text_rows && s_text > 0) {
        s_text = (b_text_rows - b_text_visable_rows);
    }
   
    scrollbar_k = b_text_visable_height / b_text_rows;
   
    temp_bmp.ReleaseGraphics(temp_gr);
    temp_bmp.Dispose();
    temp_gr = null;
    temp_bmp = null;

    window.Repaint();
}

function save_biography_file(t, p){
    if (!artist) return;
    try {
        file = fso.OpenTextFile( p, 2, true, -1)
        file.WriteLine(t);
        file.Close();
    } catch(e) {
        return;
    }
}

function on_mouse_rbtn_up (x, y){     
    var _menu = window.CreatePopupMenu();
   
    _menu.AppendMenuItem(MF_ENABLED, 10, lang_text[0] + " text");   
    _menu.AppendMenuItem(MF_ENABLED, 11, lang_text[1] + " text");   
    _menu.CheckMenuRadioItem(10, 11, lang + 10);         
    _menu.EnableMenuItem(lang + 10, 1);     

    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);   
    _menu.AppendMenuItem(MF_ENABLED, 12, "Prefer now playing");   
    _menu.AppendMenuItem(MF_ENABLED, 13, "Follow selected track");   
    _menu.CheckMenuRadioItem(12, 13 , selection_mode + 12);   
    _menu.EnableMenuItem(selection_mode + 12, 1);
       
    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0); 
    _menu.AppendMenuItem(MF_ENABLED, 14, "Artist pictures");   
    _menu.AppendMenuItem(MF_ENABLED, 15, "Albums pictures");   
    _menu.CheckMenuRadioItem(14, 15 , select_p_a + 14);   
    _menu.EnableMenuItem(select_p_a + 14, 1);

    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);   
    IS_ARTIST = artist ? MF_ENABLED : MF_GRAYED;   
    _menu.AppendMenuItem(IS_ARTIST, 16, "last.fm Artist");   
   
    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
    _menu.AppendMenuItem(MF_ENABLED, 17, "Fade effect");
    _menu.CheckMenuItem(17, fade_effect);

    _firstgroup = window.CreatePopupMenu();
    _firstgroup.AppendTo(_menu,MF_ENABLED,  "Align : " + align_mode_a[align_mode]);
   
    _firstgroup.AppendMenuItem(MF_ENABLED, 20, align_mode_a[0]);         
    _firstgroup.AppendMenuItem(MF_ENABLED, 21, align_mode_a[1]);
    _firstgroup.AppendMenuItem(MF_ENABLED, 22, align_mode_a[2]);
    _firstgroup.AppendMenuItem(MF_ENABLED, 23, align_mode_a[3]);
    _firstgroup.AppendMenuItem(MF_ENABLED, 24, align_mode_a[4]);
    _firstgroup.AppendMenuItem(MF_ENABLED, 25, align_mode_a[5]);
    _firstgroup.CheckMenuRadioItem(20, 25, align_mode + 20);
    _firstgroup.EnableMenuItem(align_mode + 20, 1);

    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
    _secondgroup = window.CreatePopupMenu();
    _secondgroup.AppendTo(_menu,MF_ENABLED,  "Download quality : " + quality[download_quality][0]);
   
    _secondgroup.AppendMenuItem(MF_ENABLED, 30, "Low");
    _secondgroup.AppendMenuItem(MF_ENABLED, 31, "Medium");
    _secondgroup.AppendMenuItem(MF_ENABLED, 32, "High");
    _secondgroup.CheckMenuRadioItem(30, 32, download_quality + 30);
    _secondgroup.EnableMenuItem(download_quality + 30, 1);

    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
    MF_STRING = images.length > 0 ? MF_ENABLED : MF_GRAYED;
    _menu.AppendMenuItem(MF_STRING, 40, "Copy to folder containing track...");
    _menu.AppendMenuItem(MF_STRING, 50, "Open image");
   
    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
    _menu.AppendMenuItem(MF_ENABLED, 60, "Save images and text");
    _menu.CheckMenuItem(60, save_images);

    //_menu.AppendMenuItem(MF_SEPARATOR, 0, 0);   
    //_menu.AppendMenuItem(MF_ENABLED, 100, "Reload");   
    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);   
    _menu.AppendMenuItem(MF_ENABLED, 110, "Properties");   
    _menu.AppendMenuItem(MF_ENABLED, 120, "Configure ...");

    ret = _menu.TrackPopupMenu(x,y);

    switch (ret) {
    case 10:
        lang = 0;
        window.SetProperty("lang", lang);
        get_text();
        break;
    case 11:
        lang = 1;
        window.SetProperty("lang", lang);
        get_text();
        break;
    case 12:
        selection_mode = 0;
        window.SetProperty("selection mode", selection_mode);
        on_item_focus_change();
        break;
    case 13:
        selection_mode = 1;
        window.SetProperty("selection mode", selection_mode);
        on_item_focus_change();
        break;
    case 14:
        select_p_a = 0;
        window.SetProperty("pictures/albums", select_p_a);
        get_pic();
        break;
    case 15:
        select_p_a = 1;
        window.SetProperty("pictures/albums", select_p_a);
        get_pic();
        break;
    case 16:
        WshShell.run("http://www.last.fm/" + lang_query[lang] + "music/" + encodeURIComponent(artist));
        break;
    case 17:
        window.SetProperty("fade effect", !fade_effect);
        fade_effect = window.GetProperty("fade effect");
        break;
    case 20:
    case 21:
    case 22:
    case 23:
    case 24:
    case 25:
        align_mode = ret - 20;
        window.SetProperty("align mode", align_mode);
        window.Repaint();
        break;
    case 30:
    case 31:
    case 32:   
        download_quality = ret - 30;
        window.SetProperty("download quality", download_quality);
        break;
    case 40:
        copy_files();
        break;
    case 50:
        try {
            if (images[selected]) WshShell.run( '"' + artist_folder_path(artist)+ "\\" + artist + "_"  + selected + "_" + p_a[select_p_a] + ".jpg" + '"' );
        } catch(e) {}
        break;
    case 60:
        window.SetProperty("Save images", !save_images);
        save_images = window.GetProperty("Save images");
        break;
    //case 100:
    //    window.Reload();
    //    break;
    case 110:
        window.ShowProperties();
        break;   
    case 120:
        window.ShowConfigure();   
        break;   
   }
    _menu.Dispose();   
    return true;   
}   

var timer;

function get_files_if_loaded(p){
    timer && window.ClearInterval(timer);
    timer = window.SetInterval(function() {
        get_files_from_dir(p);
        if (images.length > 0)  {
            next_image(0);
            window.ClearInterval(timer); 
        }
    }, 500 );
}

var set_cycle = false;

function on_key_down(vkey) {
    if (vkey == 16){
        set_cycle = true;
        dis_set();
        window.Repaint();
    }
}

var cycle_timer, step = 0;

function set_cycle_timer(){
    cycle_timer && window.ClearInterval(cycle_timer);
    cycle_timer = window.SetInterval(function() {
        step =  set_cycle ? 0 : step + 1;
        if (cycle > 0 && step >= cycle){
            get_files_from_dir(artist_folder_path(artist));
            if (images.length > 1){
                next_image(1);
                step = 0;
            }
        }
        window.Repaint();
    }, 1000 );
}

var dis_timer, dis = 0;

function dis_set(){
    dis = 0;
    dis_timer && window.ClearInterval(dis_timer);
    dis_timer = window.SetInterval(function() {
        if (set_cycle) {
            dis++;
            if(dis == 1) {
                set_cycle = false;
                if (cycle > 0) set_cycle_timer();
                if (cycle == 0) window.ClearInterval(cycle_timer);
                window.ClearInterval(dis_timer)
                window.Repaint();
            };
        }
    }, 1000 );
}

var delay = false;

function fdelay(){
    var delay_timer = window.SetTimeout(function() {
        delay = false;
        window.ClearTimeout(delay_timer);
    }, 200);
}

var ftimer;

function fader_timer(){
    fader = 0;
    ftimer && window.ClearInterval(ftimer);
    ftimer = window.SetInterval(function() {
        fader = fader + fade_step;
        if (fader >= 255) {
            fader= 255;
            window.ClearInterval(ftimer);
        }
        window.Repaint();
    }, 42 );
}

function load_last_fm_logo(){
    if(!fso.FileExists(script_path + "footer_logo.png")) {
        var url = "http://www.last.fm/static/images/logo_beta.png?eb6d3ca20e73"
        var file = "\"" + script_path + "last_fm_logo.jpg" + "\"";
        WshShell.Run(vbs + " " + url + " " + file, false);
       
        var url = "http://static-web.last.fm/static/images/favicon.702b239b6194.ico"
        var file = "\"" + script_path + "last_fm_ico.ico" + "\"";
        WshShell.Run(vbs + " " + url + " " + file, false);

        var url = "http://static-web.last.fm/static/images/footer_logo.ddcfd65712a6.png"
        var file = "\"" + script_path + "footer_logo.png" + "\"";
        WshShell.Run(vbs + " " + url + " " + file, false);
    }
}

function create_download_file() {
    try {
        file = fso.CreateTextFile(script_path + "download.vbs" )
       
        var text =   
            "If (WScript.Arguments.Count <> 2) Then" + "\n\r" +   
            "   WScript.Quit" + "\n\r" +
            "End If" + "\n\r" + "\n\r" +   

            "url = WScript.Arguments(0)" + "\n\r" +   
            "file = WScript.Arguments(1)" + "\n\r"  + "\n\r" +   

            "Set objFSO = Createobject(" + '"Scripting.FileSystemObject"' + ")" + "\n\r" +   
            "If objFSO.Fileexists(file) Then" + "\n\r" +   
            "   Set objFSO = Nothing" + "\n\r" +
            "   WScript.Quit" + "\n\r" +
            "End If" + "\n\r" + "\n\r" +   

            "Set objXMLHTTP = CreateObject(" + '"MSXML2.XMLHTTP"' + ")" + "\n\r" +   
            "objXMLHTTP.open " + '"GET"' + ", url,false" + "\n\r" +   
            "objXMLHTTP.send()" + "\n\r" + "\n\r" +   

            "If objXMLHTTP.Status = 200 Then" + "\n\r" +   
            "   Set objADOStream = CreateObject(" + '"ADODB.Stream"' + ")" + "\n\r" +
            "   objADOStream.Open" + "\n\r" +
            "   objADOStream.Type = 1" + "\n\r" +
            "   objADOStream.Write objXMLHTTP.ResponseBody" + "\n\r" +
            "   objADOStream.Position = 0" + "\n\r" +
            "   objADOStream.SaveToFile file" + "\n\r" +
            "   objADOStream.Close" + "\n\r" +
            "   Set objADOStream = Nothing" + "\n\r" +
            "End If" + "\n\r" + "\n\r" +   

            "Set objFSO = Nothing" + "\n\r" +   
            "Set objXMLHTTP = Nothing"   
        ;

        file.WriteLine(text);
        file.Close();
    } catch(e) {};
}

function on_mouse_move(x, y) {
    window.SetCursor(32649);

    on_text = x >= txt_x && x < sb_x && y  >= txt_y ? true : false;
    on_sb =  x >= sb_x && x < ww && y >= txt_y && y < wh ? true : false;
    on_pic = !on_text && !on_sb ? true : false;

    if (on_text_down){
        txt_x = x - delta_x;
        txt_y = y - delta_y;

        txt_x = txt_x <= 0 ? 0 : txt_x >= ww - 50 ? ww - 50: txt_x;
        txt_y = txt_y <= 0 ? 0 : txt_y >= wh - (a_text_row_height + t_margin * 2) ? wh - (a_text_row_height + t_margin * 2) : txt_y;

        get_b_text_array();
    }

    if (on_sb_down && scrollbar && b_text_rows > b_text_visable_rows){
        sb_posy = y + delta_y;
        s_text = y + delta_y >= 0 ? y + delta_y <= (b_text_rows - b_text_visable_rows) * scrollbar_k ? Math.round(sb_posy / scrollbar_k) : b_text_rows - b_text_visable_rows : 0;
        //window.Repaint();
        window.RepaintRect(txt_x, txt_y, ww - txt_x, wh - txt_y);
    }
   
    window.RepaintRect(sb_x, txt_y, ww, wh);
}

function on_mouse_wheel(delta) {
    ShiftDown = utils.IsKeyPressed(0x10) ? true : false;
   
    if (on_pic && !ShiftDown && !delay){
        get_files_from_dir(artist_folder_path(artist));
        if (files.length > 1){
            delay = true;
            fdelay();
            next_image(delta);
            if (cycle > 0) step = 0;
        }
    }
   
    if (on_text && !ShiftDown){
        if (b_text_rows > b_text_visable_rows){
            if (delta < 0) {s_text = b_text_rows - s_text <= b_text_visable_rows ? b_text_rows - b_text_visable_rows : s_text += 1}
            if (delta > 0) {s_text = s_text <= 0 ? 0 : s_text -= 1}
        }
        window.RepaintRect(txt_x, txt_y, ww - txt_x, wh - txt_y);
    }
   
    if (on_text && ShiftDown && !delay){
        delay = true;
        fdelay();
        if (delta < 0) {font_size_b = font_size_b <= min_font_size ? min_font_size : font_size_b - 2;};
        if (delta > 0) {font_size_b = font_size_b >= max_font_size ? max_font_size : font_size_b + 2;};
        window.SetProperty("font size: biography", font_size_b);
        get_font();
        refresh_txt = true;
        get_b_text_array();
    }

    if (set_cycle && on_pic) {
        if (delta < 0) {cycle = cycle <= 0 ? 0 : cycle - 5;};
        if (delta > 0) {cycle = cycle >= 60 ? 60 : cycle + 5;};
        window.SetProperty("auto cycle (sec)", cycle);
        window.Repaint();
    }
}

function on_mouse_lbtn_down(x,y){
    if (on_text){
        on_text_down = true;
        delta_x = x - txt_x;
        delta_y = y - txt_y;
    }
    if (on_sb){
        on_sb_down = true;
        sb_posy = s_text * scrollbar_k;
        delta_y = sb_posy - y;
    }
}

function on_mouse_lbtn_up(x,y){
    window.SetProperty("txt_x", txt_x);
    window.SetProperty("txt_y", txt_y);
    on_text_down = false;
    on_sb_down = false;
}

function on_mouse_lbtn_dblclk (x,y){
    if (on_text){
        lang = lang == 1 ? 0 : 1;
        window.SetProperty("lang", lang);
        get_text();
    }

    if (on_pic){
        select_p_a = select_p_a == 1 ? 0 : 1;
        window.SetProperty("pictures/albums", select_p_a);
        get_pic();
    }
}

function on_mouse_leave() {
    window.SetCursor(32512);
    on_sb = false;
    window.Repaint();
}

function on_size(){
    ww = window.Width;   
    wh = window.Height;
   
    txt_x = window.GetProperty("txt_x");
    txt_y = window.GetProperty("txt_y");

    txt_x = txt_x >= ww - 50 && txt_x >= 0 ? ww - 50 : txt_x;
    txt_y = txt_y >= wh - (a_text_row_height + t_margin * 2) && txt_y >= 0 ? wh - (a_text_row_height + t_margin * 2) : txt_y;
   
    refresh_txt = true;
    get_b_text_array();
}

function del_folders(n){
    var dir = fso.GetFolder(tmp_b_path);
    var e = new Enumerator( dir.SubFolders );
    try {
        for(; !e.atEnd(); e.moveNext() ) {
            var name = e.item().Name;
            if (name.indexOf("_download") < 0){
                if (name.indexOf(n) < 0){
                    fso.deleteFolder(tmp_b_path + name, true);
                }
            }   
        }
    } catch(e) {};
}

function calc_img_size(img){
    if(!img) return;
    var size = {x:0, y:0, width:0, height:0, cx:0, cy:0, cwidth:0, cheight:0};

    switch(align_mode) {   
   case 0: // adjust      
        var sw = ww / img.Width;
        var sh = wh / img.Height;
        var s = Math.min(sw, sh);
       
        var x = 0;
        var y = 0;
       
        if (sw > sh) x = (ww - img.Width * s) / 2;
        else if (sw < sh) y = (wh - img.height * s) / 2;

        var width = img.Width * s;
        var height = img.Height * s;
        var cx = 0;
        var cy = 0;
        var cwidth = img.Width;
        var cheight = img.Height;
      break;
       
    case 1: // adjust top - center
        var sw = ww / img.Width;
        var sh = wh / img.Height;
        var s = Math.min(sw, sh);

        var x = 0;
        if (sw > sh) x = (ww - img.Width * s) / 2;
        var y = 0;
        var width = img.Width * s;
        var height = img.Height * s;
        var cx = 0;
        var cy = 0;
        var cwidth = img.Width;
        var cheight = img.Height;
      break;
       
    case 2: // adjust top - left
        var sw = ww / img.Width;
        var sh = wh / img.Height;
        var s = Math.min(sw, sh);
       
        var x = 0;
        var y = 0;
        var width = img.Width * s;
        var height = img.Height * s;
        var cx = 0;
        var cy = 0;
        var cwidth = img.Width;
        var cheight = img.Height;
      break;

   case 3: // centre   
      var sr = img.Width / img.Height;   
      var dr = ww / wh;   
      if (sr < dr) {   
         var r = img.Width / ww;
         var cheight = wh * r;
         var cy = Math.round((img.Height - cheight) / 2);
         var cwidth = img.Width;
         var cx = 0;
      } else {   
         var r = img.Height / wh;
         var cwidth = ww * r;
         var cx = Math.round((img.Width - cwidth) / 2);
         var cheight = img.Height;
         var cy = 0;
      }   
        var x = 0;         
        var y = 0;         
        var width = ww;         
        var height = wh;         
      break;   
       
   case 4: // centre - top      
      var sr = img.Width / img.Height;   
      var dr = ww / wh;   
      if (sr < dr) {   
         var r = img.Width / ww;
         var cheight = wh * r;
         var cy = 0;
         var cwidth = img.Width;
         var cx = 0;
      } else {   
         var r = img.Height / wh;
         var cwidth = ww * r;
         var cx = Math.round((img.Width - cwidth) / 2);
         var cheight = img.Height;
         var cy = 0;
      }
        var x = 0;
        var y = 0;
        var width = ww;
        var height = wh;
      break;   
       
   case 5: // stretch      
        var x = 0;
        var y = 0;
        var width = ww;
        var height = wh;
        var cx = 0;
        var cy = 0;
        var cwidth = img.Width;
        var cheight = img.Height;
      break;   
    }
   
    size.x = x + p_margin;
    size.y = y + p_margin;
    size.width = width - p_margin * 2;
    size.height = height - p_margin * 2;
    size.cx = cx;
    size.cy = cy;
    size.cwidth = cwidth;
    size.cheight = cheight;
   
    return size;
}

function copy_files(){
    var save_images_state = save_images;
    if (!save_images_state) save_images = true;

    var destination_path;
    var tmp_files = files;
    var tmp_artist = artist;
    var tmp_p_a = p_a[select_p_a];
    var tmp_directory_path;
   
    if (path.indexOf('://') > 0 || path.indexOf('youtube') == 0 || path.indexOf('cdda') == 0) {
        tmp_directory_path = fb.ProfilePath + tmp_p_a + "\\";
    } else {
        tmp_directory_path = directory_path + "\\" + tmp_p_a + "\\";
    }   
   
    var nl = "\" + chr(10) + \"";
    var input_box_text = "Copy  " + nl + nl + tmp_artist + " " + tmp_p_a + ".jpg" + nl + "files to";

    var string = input_box(input_box_text, tmp_directory_path, "Foobar 2000");

    if (string){
        destination_path = folder_exists(string);
        if (!destination_path) {
            copy_files();
        } else{
            copy_files_to_folder(destination_path, tmp_files, tmp_p_a);
        }
    }
    save_images = save_images_state;
}

function copy_files_to_folder(p, f, pa){
    if (p.length != "\\"){p = p + "\\"}
    for (i in f) {
        if (f[i].indexOf(pa) > 0){
            try {
                fso.CopyFile (f[i], p  , 1 );
            } catch(e) {}
        }
    }
}

function input_box(p_text, d_text, w_title){
    vbe = new ActiveXObject('ScriptControl');
    vbe.Language = 'VBScript';
    return vbe.eval( "InputBox(\"" + p_text + "\",\"" + w_title + "\",\"" + d_text + "\")");
}

function clean_path_name(n) {
    if (!n) return;
    return n.replace(/[\/\:\*\?\"\<\>\|]/g,'');
}

function folder_exists(n) {
    var driver = fso.GetDriveName(n);
    if (!fso.DriveExists(driver)) {
        return "";
    } else {
        var p = "";
        var split_string = [];
        split_string = n.replace(/\\$/g, "").split("\\");

        for (var i = 1; i < split_string.length; i += 1) {
            p = p + clean_path_name(split_string[i]) + "\\";
            try {
                if(!fso.FolderExists(driver + "\\" + p)) fso.CreateFolder(driver + "\\" + p);
            } catch(e) {};
        }
        return driver + "\\" + p;
    }
}
/*
function on_notify_data(name, info) {
    if(name == "panel") {
        if (info == "bio"){
            panel_on = true;
            artist = "";
            on_metadb_changed();
        } else{
            panel_on =  false;
        }
    }
}
*/
kgena_ua
14.11.2016, 19:09
 
Раздел: Секреты foobar2000
Тема: Скрипты для foo_uie_wsh_panel_mod
Ответы: 2986
Просмотры: 573115

Re: Скрипты для foo_uie_wsh_panel_mod

WSH Biography Text & Picture Last.fm_rus (10.11.2016)
Код: Выделить всё
// ==PREPROCESSOR==
// @name "Biography Text && Picture. www.last.fm"
// @author "kgena_ua"
// @version "10112016"
// @feature "v1.4"
// @feature "watch-metadb"
// ==/PREPROCESSOR==

function RGB(r,g,b) { return (0xff000000|(r<<16)|(g<<8)|(b)); }
function RGBA(r,g,b,a) { return ((a << 24) | (r << 16) | (g << 8) | (b)); }
function getRed(color) {return ((color >> 16) & 0xff);};
function getGreen(color) {return ((color >> 8) & 0xff);};
function getBlue(color) {return (color & 0xff);};

DT_LEFT = 0x00000000;
DT_RIGHT = 0x00000002;
DT_CENTER = 0x00000001;
DT_VCENTER = 0x00000004;
DT_SINGLELINE = 0x00000020;
DT_WORD_ELLIPSIS = 0x00040000;
DT_WORDBREAK = 0x00000010;
DT_CALCRECT = 0x00000400;
DT_NOPREFIX = 0x00000800;

MF_ENABLED = 0x00000000;   
MF_GRAYED = 0x00000001;   
MF_SEPARATOR = 0x00000800;

var ww = 200, wh = 200;

var font_name_a = window.GetProperty(" font name: artist", "Verdan");
var font_name_b = window.GetProperty(" font name: biography", "Arial");
var font_size_a_d = window.GetProperty(" font size: artist (delta)", 4);
var font_size_b = window.GetProperty(" font size: biography", 12);
var a_font_style = window.GetProperty(" font style: artist", 2);
var b_font_style = window.GetProperty(" font style: biography", 0);
var min_font_size = 12;
var max_font_size = 16;

var a_font, b_font;
get_font();

function get_font(){
    a_font = gdi.Font(font_name_a, font_size_b + font_size_a_d, a_font_style);
    b_font = gdi.Font(font_name_b, font_size_b, b_font_style);
}   
/*
ColorTypeCUI = {
    text: 0,
    selection_text: 1,
    inactive_selection_text: 2,
    background: 3,
    selection_background: 4,
    inactive_selection_background: 5,
    active_item_frame: 6
};

function get_color(){   
    bgcolor = window.GetColorCUI(ColorTypeCUI.background);
    a_color = window.GetColorCUI(ColorTypeCUI.text);
    b_color = window.GetColorCUI(ColorTypeCUI.inactive_selection_text);
    window.Repaint();
}

get_color();

function on_colors_changed(){
    get_color();
}
*/

var bgcolor = RGB(19,30,38);    // RGB(31,41,48);
var a_color = RGB(128,192,255); // RGB(220,220,220);
var b_color = RGB(192,192,192); // RGB(255,255,230);

var fso = new ActiveXObject("Scripting.FileSystemObject");

var tmp_b_path = fb.ProfilePath + "\\tmp_Biography\\";
if (!fso.FolderExists(tmp_b_path)) {fso.CreateFolder(tmp_b_path)};

var script_path = tmp_b_path + "_download\\";
if (!fso.FolderExists(script_path)) {fso.CreateFolder(script_path)};
if (!fso.FileExists(script_path + "download.vbs")) {create_download_file()};

var doc = new ActiveXObject("htmlfile");
var WshShell = new ActiveXObject("WScript.Shell");
var vbs = "cscript //nologo \"" + script_path + "download.vbs\"";

var default_img_path = window.GetProperty(" default img path",".\\tmp_Biography\\_download\\nocover.png");
var default_img = window.GetProperty(" default img", false);
var default_img_transparent = window.GetProperty(" default img transparent (0-255)", 255);

load_last_fm_logo();
var logo_img = gdi.Image(script_path + "footer_logo.png");

var artist, old_artist;
var path, directory_path;

function clean_name(n) {
    if (!n) return;
    return n.replace(/[^a-zA-Z0-9а-яА-Я\s-&\.]/g,'').replace(/^\s+|\s+$/g,"");
}

function artist_folder_path(n) {
    return tmp_b_path + n;
}

function check_folder(n) {
    if(!fso.FolderExists(n)) {fso.CreateFolder(n)};
}

String.prototype.repeat = function(n) {
    return new Array(n + 1).join(this);
}

window.SetProperty(" - user", "");
if (window.GetProperty(" - user") != "" ) window.SetProperty(" - user", "");
window.SetProperty("-".repeat(50), "");
if (window.GetProperty("-".repeat(50)) != "" ) window.SetProperty("-".repeat(50), "");

var g_img = null;
var p_margin = window.GetProperty(" margin: picture", 0);
var align_mode_a = new Array("Подогнать", "Подогнать сверху - по центру", "Подогнать сверху - слева", "По центру", "По центру - сверху", "Растянуть");
var align_mode = window.GetProperty("align mode", 0);
var selected = 0;
var files = [];
var images = [];
var save_images = window.GetProperty("save images", false);
var limit = window.GetProperty(" download limit",5);
var cycle = window.GetProperty("auto cycle (sec)", 0);
if (cycle > 0) set_cycle_timer();
var fader = 255;
var fade_effect = window.GetProperty("fade effect", false);
var fade_step = window.GetProperty("fade step", 25);
var on_pic = false;

var download_quality = window.GetProperty("download quality", 1);
var quality = [
    [ "низкое", "avatar170s" , "300"],
    [ "среднее", "300x300" , "300"],
    [ "высокое", "770x0" , ""]
];

var scrollbar = window.GetProperty(" scrollbar", true);
var scrollbar_w = window.GetProperty(" scrollbar width ", 4);
var scrollbar_k;
var sb_x = 0;
var sb_posy = 0;
var on_sb = false;
var on_sb_down = false;
var sb_color;

var b_file;
var bg_transparent = window.GetProperty(" bg transparent (0-255)", 200);
var t_margin = window.GetProperty(" margin: text", 10);
var txt_x = window.GetProperty("txt_x", window.Width / 2);
var old_txt_x = 0;
var txt_y = window.GetProperty("txt_y", window.Height / 2);
var delta_x, delta_y;
var a_x, a_y, b_x, b_y;
var text = "";
var text_not_found = new Array("\n\nНичего не найдено", "\n\nНичего не найдено");
var s_text = 0;
var a_text_row_height = 0;
var b_text_row_height = 0;
var b_text_rows = 0;
var b_text_visable_rows = 0;
var b_text_visable_height = 0;
var b_text_array = [];
var on_artist = false;
var on_text = false;
var on_text_down = false;
var refresh_txt = true;

var lang_query = new Array("", "ru/");
var lang_text = new Array("in", "ru");
var lang = window.GetProperty("lang", 0);

var select_p_a = window.GetProperty("pictures/albums", 0);
var p_a = new Array("images", "albums");

var panel_on = true;

var selection_mode = window.GetProperty("selection mode", 0);
var metadb;
on_item_focus_change();

function on_paint(gr){   
   !window.IsTransparent && gr.FillSolidRect(0, 0, ww, wh, bgcolor);
   
    draw_image(gr);

    if(set_cycle){   
        gr.FillSolidRect(0, 0, ww, wh, RGBA(getRed(bgcolor),getGreen(bgcolor),getBlue(bgcolor),bg_transparent));   
        var txt_cycle = cycle == 0 ? "Отключено" : cycle + " сек.";   
        set_cycle && gr.GdiDrawText("Зацикливание изображений \n" + txt_cycle, b_font, b_color, 0, 20, ww, wh, DT_CENTER | DT_WORD_ELLIPSIS );
    } else{   
        gr.FillSolidRect(txt_x, txt_y, ww - txt_x, wh - txt_y, RGBA(getRed(bgcolor),getGreen(bgcolor),getBlue(bgcolor),bg_transparent));   
    }   

    draw_scrollbar(gr);   
   
    gr.GdiDrawText( artist, a_font, RGB(0,0,0), a_x + 1, a_y + 2, ww - a_x - t_margin, wh, DT_CENTER | DT_WORD_ELLIPSIS | DT_NOPREFIX );   
    gr.GdiDrawText( artist, a_font, a_color, a_x, a_y, ww - a_x - t_margin, wh, DT_CENTER | DT_WORD_ELLIPSIS | DT_NOPREFIX );   

    for (var i = 0; i < b_text_visable_rows * 2; i += 2) {
        try {
            gr.GdiDrawText( b_text_array[i + s_text * 2].replace(/^\s+|\s+$/g, ""), b_font, RGB(0,0,0), b_x + 1, b_y + b_text_row_height * i / 2 + 2, ww, wh, DT_LEFT | DT_NOPREFIX );
            gr.GdiDrawText( b_text_array[i + s_text * 2].replace(/^\s+|\s+$/g, ""), b_font, b_color, b_x, b_y + b_text_row_height * i / 2 , ww, wh, DT_LEFT | DT_NOPREFIX );
        } catch(e) {}
    }

   // gr.GdiDrawText( "files " + files.length, gdi.Font("Arial",12, 0), b_color, 10, 0, ww, wh, DT_LEFT | DT_WORD_ELLIPSIS );
    //gr.GdiDrawText( "images " + images.length, gdi.Font("Arial",12, 0), b_color, 10, 20, ww, wh, DT_LEFT | DT_WORD_ELLIPSIS );
}

function draw_image(gr){
    if (g_img && images.length > 0){
        var size = calc_img_size(g_img);
        gr.DrawRect(size.x, size.y, size.width, size.height, 1, RGBA(getRed(bgcolor),getGreen(bgcolor),getBlue(bgcolor),fader));
        gr.DrawImage(g_img, size.x, size.y, size.width, size.height, size.cx, size.cy, size.cwidth, size.cheight, 0, fader);
    }
   
    if (logo_img && images.length == 0 && !default_img){
        gr.DrawImage(logo_img, 10, 10, logo_img.Width * 0.8, logo_img.Height * 0.8, 0, 0, logo_img.Width, logo_img.Height, 0, 100);         
    }

    if (images.length == 0 && default_img){
        try {
            nc_img = gdi.Image(default_img_path);
            var size = calc_img_size(nc_img);
            gr.DrawImage(nc_img, size.x, size.y, size.width, size.height, size.cx, size.cy, size.cwidth, size.cheight, 0, default_img_transparent);
        } catch(e) {};
    }
}

function draw_scrollbar(gr){
    scrollbar_h = b_text_rows > b_text_visable_rows ? b_text_visable_height * (b_text_visable_rows / b_text_rows) : 0;
    if (b_text_rows > b_text_visable_rows){ scrollbar_h = Math.max(5, scrollbar_h)}
    scrollbar_y = s_text > 0 ? s_text * scrollbar_k : 0;

    sb_x = ww - t_margin - scrollbar_w;
   
    sb_t = on_sb || on_sb_down ? 150 : 50;
    sb_color = RGBA(getRed(a_color), getGreen(a_color), getBlue(a_color), sb_t);
   
    scrollbar && gr.FillSolidRect(sb_x, b_y + scrollbar_y, scrollbar_w, scrollbar_h, sb_color);
}

function on_playlist_switch() {
    on_item_focus_change();
}

function on_playback_new_track() {
    on_item_focus_change();
}

function on_playback_dynamic_info_track() {
    on_item_focus_change();
}

function on_playback_stop() {
    on_item_focus_change();
}

function on_selection_changed(metadb) {
   on_item_focus_change();
}

function on_item_focus_change() {
    switch (selection_mode) {
    case 0:
        metadb = fb.IsPlaying ? fb.GetNowPlaying() : fb.GetFocusItem();   
        break;   
    case 1:   
       metadb = fb.GetFocusItem();
        break;   
    }   
    if (metadb) on_metadb_changed();   
}   

function Eval(field) {   
    if (!metadb) return;   
    path = fb.Titleformat("%path%").EvalWithMetadb(metadb);
    directory_path = fb.Titleformat("$directory_path(%path%)").EvalWithMetadb(metadb);
    return path.indexOf('://') > 0 ? fb.TitleFormat("[" + field + "]").Eval(true) : fb.TitleFormat("[" + field + "]").EvalWithMetadb(metadb);
}   

function on_metadb_changed() {
    if (!panel_on) return;
    if (!metadb) return;
//  artist = Eval("%artist%");
    artist = Eval("$upper([%artist%])");
    if (artist) {artist = clean_name(artist)} else {artist = ""};
    if (artist != old_artist){
        if (!save_images) del_folders(artist);
        get_pic();
//      get_text();   //////////////////////////
        old_artist = artist;
    }
}   

function get_pic() {
    images = [];
    files = [];
    selected = 0;
    g_img = null;
    window.Repaint();
   
    check_folder(artist_folder_path(artist));
    if (fso.FolderExists(artist_folder_path(artist))){
        get_files_from_dir(artist_folder_path(artist));
        if (!g_img && images.length > 0) {
            next_image(0);
        } else {
            get_lastFM_pic(artist_folder_path(artist));
        }
    }
}

function get_lastFM_pic(p){
    xmlhttp1 = new ActiveXObject("Microsoft.XMLHTTP");     
    url1 = ("http://www.last.fm/music/" + encodeURIComponent(artist) + "/+" + p_a[select_p_a]);     
    xmlhttp1.open("GET", url1, true);     
    xmlhttp1.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
    xmlhttp1.send(null);     
    xmlhttp1.onreadystatechange = function () {
        if (xmlhttp1.readyState == 4) {
            if (xmlhttp1.status == 200) {
                doc.open();     
                var div = doc.createElement("div");
                div.innerHTML = xmlhttp1.responsetext;
                var data = div.getElementsByTagName("img");
                var urls = [];
                for (i = 0; i < data.length; i++) {   
                    if (data[i].className == "image-list-image" && select_p_a == 0){       
                        if (data[i].src.indexOf("http://img2-ak.lst.fm/i/u/avatar170s") == 0 || data[i].src.indexOf("https://lastfm-img2.akamaized.net/i/u/avatar170s") == 0) {
                            urls.push(data[i].src.replace("avatar170s", quality[download_quality][1]));
                        }     
                    }   
//                    if (data[i].className == "album-grid-album-art" && select_p_a == 1){   
//                        if (data[i].src.indexOf("http://img2-ak.lst.fm/i/u/300") == 0 && data[i].src.indexOf("c6f59c1e5e7240a4c0d427abd71f3dbb") < 0) {                       
//                            urls.push(data[i].src.replace("300", quality[download_quality][2]))
                    if (data[i].className == "album-grid-album-art" && select_p_a == 1){
                        if ((data[i].src.indexOf("http://img2-ak.lst.fm/i/u/300") == 0 || data[i].src.indexOf("https://lastfm-img2.akamaized.net/i/u/300") == 0) && data[i].src.indexOf("c6f59c1e5e7240a4c0d427abd71f3dbb") < 0) {                       
                            urls.push(data[i].src.replace("300", quality[download_quality][2]))
                        }     
                    }       
                }
                var found = urls.length;
                for (i = 0; i < Math.min(urls.length, limit); i++) {     
                    file = "\"" + p + "\\" + artist + "_"  + i + "_" + p_a[select_p_a] + ".jpg" + "\"";     
                    WshShell.Run(vbs + " " + urls[i] + " " + file, false);
                }     
                doc.close();
                if (found > 0) get_files_if_loaded(p);
 //             get_text(); ////////////////////////
            }
        }     
                get_text();
    }     
}

function get_files_from_dir(p) {
    if (!artist) return;
    files = utils.Glob(p + "\\" + artist + "*" + p_a[select_p_a] + ".jpg").toArray();
   
    if (files.length > images.length){
        images = [];
       
        for (var i = 0; i < files.length; i += 1) {
            try {
                images.push(resize_image(gdi.Image(files[i])));
            } catch(e) {}
        }
    }
}

function next_image(d){
    fader = fade_effect ? 0 : 255;
    if (d < 0) {selected = selected <= 0 ? images.length - 1 : selected = selected - 1};
    if (d > 0) {selected = selected >= images.length - 1 ? 0 : selected = selected + 1};
    g_img = images[selected];
    if (g_img && fade_effect) fader_timer();
    window.Repaint();
}

function resize_image(img){
    if (!img) return;
   
    var scale_w = (window.Width - p_margin * 2) / img.Width;
    var scale_h = (window.Height - p_margin * 2) / img.Height;
    var scale = Math.min(scale_w, scale_h);
    var nww = img.Width * scale;
    var nwh = img.Height * scale

    var temp_bmp = gdi.CreateImage(nww, nwh);
    var temp_gr = temp_bmp.GetGraphics();
    temp_gr.SetSmoothingMode(2);
    temp_gr.SetInterpolationMode(7);
    temp_gr.DrawImage(img, 0, 0, nww, nwh, 0, 0, img.width, img.height);
    temp_bmp.ReleaseGraphics(temp_gr);
   
    CollectGarbage();
    return temp_bmp;
    temp_bmp.Dispose();
    temp_gr = null;
    temp_bmp = null;
}

function get_text() {
    s_text = 0;
    text = "";
    b_text_array = [];
    b_text_file = artist_folder_path(artist) + "\\" + artist + "_biography_" + lang_query[lang].replace(/\//g,'') + ".txt";
   
    refresh_txt = true;
   
    if (artist && fso.FileExists(b_text_file)){
        text = utils.ReadTextFile(b_text_file);
        get_b_text_array();
    } else{
        get_lastFM_b_text(b_text_file);
    }
}

function get_lastFM_b_text(p){
    xmlhttp2 = new ActiveXObject("Microsoft.XMLHTTP");
    url2 = ("http://www.last.fm/" + lang_query[lang] + "music/" + encodeURIComponent(artist) + "/+wiki");
    xmlhttp2.open("GET", url2, true);
    xmlhttp2.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
    xmlhttp2.send(null);
    xmlhttp2.onreadystatechange = function () {
        if (xmlhttp2.readyState == 4) {
            if (xmlhttp2.status == 200) {
                doc.open();
                var div = doc.createElement("div");
                div.innerHTML = xmlhttp2.responsetext;
                var data = div.getElementsByTagName("div");
                for (i = 0; i < data.length; i++) {
                    if (data[i].className == "wiki-content") {
                        text = strip_tags(data[i].innerHTML);
                        break;
                    }
                }
                doc.close();
            }
            if (text != "") save_biography_file(text, p);
            if (text == "") text = text_not_found[lang];
            get_b_text_array();
        }
    }
}

function strip_tags(t) {
    doc.open();
    var div = doc.createElement("div");
    div.innerHTML = t.replace(/<[Pp][^>]*>/g, "").replace(/<\/[Pp]>/g, "<br>").replace(/\n/g, "<br>");
    var text = div.innerText;
    doc.close();
    return text;
}

function get_b_text_array() {
    a_x = txt_x + t_margin;
    a_y = txt_y + t_margin;
 
    temp_bmp = gdi.CreateImage(1, 1);
    temp_gr = temp_bmp.GetGraphics();

    a_text_row_height = temp_gr.CalcTextHeight("text", a_font);
    b_text_row_height = temp_gr.CalcTextHeight("text", b_font);
   
    b_x = txt_x + t_margin;
    b_y = a_y + a_text_row_height + b_text_row_height;
   
    string_width = Math.max(ww - b_x - t_margin - scrollbar_w - 10, 0);

    if (Math.abs(txt_x - old_txt_x) > 5 || refresh_txt){
        b_text_array = [];
        if (text) b_text_array = temp_gr.EstimateLineWrap(text, b_font, string_width).toArray();
        old_txt_x = txt_x;
        refresh_txt = false;
    }
   
    b_text_rows = b_text_array.length / 2;

    b_text_visable_area = Math.floor(Math.max(0, window.Height - t_margin - b_y));
    b_text_visable_rows = Math.floor(b_text_visable_area / b_text_row_height);
    b_text_visable_height = b_text_visable_rows * b_text_row_height;


    if (b_text_visable_rows + s_text > b_text_rows && s_text > 0) {
        s_text = (b_text_rows - b_text_visable_rows);
    }
   
    scrollbar_k = b_text_visable_height / b_text_rows;
   
    temp_bmp.ReleaseGraphics(temp_gr);
    temp_bmp.Dispose();
    temp_gr = null;
    temp_bmp = null;

    window.Repaint();
}

function save_biography_file(t, p){
    if (!artist) return;
    try {
        file = fso.OpenTextFile( p, 2, true, -1)
        file.WriteLine(t);
        file.Close();
    } catch(e) {
        return;
    }
}

function on_mouse_rbtn_up (x, y){     
    var _menu = window.CreatePopupMenu();
   
    _menu.AppendMenuItem(MF_ENABLED, 10, "Английский язык");   
    _menu.AppendMenuItem(MF_ENABLED, 11, "Русский язык");   
    _menu.CheckMenuRadioItem(10, 11, lang + 10);         
    _menu.EnableMenuItem(lang + 10, 1);     

    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);   
    _menu.AppendMenuItem(MF_ENABLED, 12, "Предпочитать воспроизводимый");   
    _menu.AppendMenuItem(MF_ENABLED, 13, "Следовать за выбранным треком");   
    _menu.CheckMenuRadioItem(12, 13 , selection_mode + 12);   
    _menu.EnableMenuItem(selection_mode + 12, 1);
       
    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
    _menu.AppendMenuItem(MF_ENABLED, 14, "Фото исполнителя");   
    _menu.AppendMenuItem(MF_ENABLED, 15, "Обложка альбома");   
    _menu.CheckMenuRadioItem(14, 15 , select_p_a + 14);   
    _menu.EnableMenuItem(select_p_a + 14, 1);

    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);   
    IS_ARTIST = artist ? MF_ENABLED : MF_GRAYED;   
    _menu.AppendMenuItem(IS_ARTIST, 16, "Страничка исполнителя на Last.fm");   
   
    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
    _menu.AppendMenuItem(MF_ENABLED, 17, "Эффект плавного перехода");
    _menu.CheckMenuItem(17, fade_effect);

    _firstgroup = window.CreatePopupMenu();
    _firstgroup.AppendTo(_menu,MF_ENABLED,  "Выравнивание : " + align_mode_a[align_mode]);
   
    _firstgroup.AppendMenuItem(MF_ENABLED, 20, align_mode_a[0]);         
    _firstgroup.AppendMenuItem(MF_ENABLED, 21, align_mode_a[1]);
    _firstgroup.AppendMenuItem(MF_ENABLED, 22, align_mode_a[2]);
    _firstgroup.AppendMenuItem(MF_ENABLED, 23, align_mode_a[3]);
    _firstgroup.AppendMenuItem(MF_ENABLED, 24, align_mode_a[4]);
    _firstgroup.AppendMenuItem(MF_ENABLED, 25, align_mode_a[5]);
    _firstgroup.CheckMenuRadioItem(20, 25, align_mode + 20);
    _firstgroup.EnableMenuItem(align_mode + 20, 1);

    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
    _secondgroup = window.CreatePopupMenu();
    _secondgroup.AppendTo(_menu,MF_ENABLED,  "Качество изображения : " + quality[download_quality][0]);
   
    _secondgroup.AppendMenuItem(MF_ENABLED, 30, "Низкое");
    _secondgroup.AppendMenuItem(MF_ENABLED, 31, "Среднее");
    _secondgroup.AppendMenuItem(MF_ENABLED, 32, "Высокое");
    _secondgroup.CheckMenuRadioItem(30, 32, download_quality + 30);
    _secondgroup.EnableMenuItem(download_quality + 30, 1);

    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
    MF_STRING = images.length > 0 ? MF_ENABLED : MF_GRAYED;
    _menu.AppendMenuItem(MF_STRING, 40, "Копировать в папку с треком...");
    _menu.AppendMenuItem(MF_STRING, 50, "Открыть изображение");
   
    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
    _menu.AppendMenuItem(MF_ENABLED, 60, "Сохранять изображения и текст");
    _menu.CheckMenuItem(40, save_images);

//    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);   
//    _menu.AppendMenuItem(MF_ENABLED, 100, "Перезагрузить");   
    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);   
    _menu.AppendMenuItem(MF_ENABLED, 110, "Свойства WSH");   
    _menu.AppendMenuItem(MF_ENABLED, 120, "Настройки WSH...");

    ret = _menu.TrackPopupMenu(x,y);

    switch (ret) {
    case 10:
        lang = 0;
        window.SetProperty("lang", lang);
        get_text();
        break;
    case 11:
        lang = 1;
        window.SetProperty("lang", lang);
        get_text();
        break;
    case 12:
        selection_mode = 0;
        window.SetProperty("selection mode", selection_mode);
        on_item_focus_change();
        break;
    case 13:
        selection_mode = 1;
        window.SetProperty("selection mode", selection_mode);
        on_item_focus_change();
        break;
    case 14:
        select_p_a = 0;
        window.SetProperty("pictures/albums", select_p_a);
        get_pic();
        break;
    case 15:
        select_p_a = 1;
        window.SetProperty("pictures/albums", select_p_a);
        get_pic();
        break;
    case 16:
        WshShell.run("http://www.last.fm/" + lang_query[lang] + "music/" + encodeURIComponent(artist));
        break;
    case 17:
        window.SetProperty("fade effect", !fade_effect);
        fade_effect = window.GetProperty("fade effect");
        break;
    case 20:
    case 21:
    case 22:
    case 23:
    case 24:
    case 25:
        align_mode = ret - 20;
        window.SetProperty("align mode", align_mode);
        window.Repaint();
        break;
    case 30:
    case 31:
    case 32:   
        download_quality = ret - 30;
        window.SetProperty("download quality", download_quality);
        break;
    case 40:
        copy_files();
        break;
    case 50:
        try {
            if (images[selected]) WshShell.run( '"' + artist_folder_path(artist)+ "\\" + artist + "_"  + selected + "_" + p_a[select_p_a] + ".jpg" + '"' );
        } catch(e) {}
        break;
    case 60:
        window.SetProperty("Save images", !save_images);
        save_images = window.GetProperty("Save images");
        break;
//    case 100:
//        window.Reload();
//        break;
    case 110:
        window.ShowProperties();
        break;   
    case 120:
        window.ShowConfigure();   
        break;   
   }
    _menu.Dispose();   
    return true;   
}   

var timer;

function get_files_if_loaded(p){
    timer && window.ClearInterval(timer);
    timer = window.SetInterval(function() {
        get_files_from_dir(p);
        if (images.length > 0)  {
            next_image(0);
            window.ClearInterval(timer);
        }
    }, 500 );   // 500
}

var set_cycle = false;

function on_key_down(vkey) {
    if (vkey == 16){
        set_cycle = true;
        dis_set();
        window.Repaint();
    }
}

var cycle_timer, step = 0;

function set_cycle_timer(){
    cycle_timer && window.ClearInterval(cycle_timer);
    cycle_timer = window.SetInterval(function() {
        step =  set_cycle ? 0 : step + 1;
        if (cycle > 0 && step >= cycle){
            get_files_from_dir(artist_folder_path(artist));
            if (images.length > 1){
                next_image(1);
                step = 0;
            }
        }
        window.Repaint();
    }, 1000 );  // 1000
}

var dis_timer, dis = 0;

function dis_set(){
    dis = 0;
    dis_timer && window.ClearInterval(dis_timer);
    dis_timer = window.SetInterval(function() {
        if (set_cycle) {
            dis++;
            if(dis == 1) {
                set_cycle = false;
                if (cycle > 0) set_cycle_timer();
                if (cycle == 0) window.ClearInterval(cycle_timer);
                window.ClearInterval(dis_timer)
                window.Repaint();
            };
        }
    }, 1000 );  // 1000
}

var delay = false;

function fdelay(){
    var delay_timer = window.SetTimeout(function() {
        delay = false;
        window.ClearTimeout(delay_timer);
    }, 200);    // 200
}

var ftimer;

function fader_timer(){
    fader = 0;
    ftimer && window.ClearInterval(ftimer);
    ftimer = window.SetInterval(function() {
        fader = fader + fade_step;
        if (fader >= 255) {
            fader= 255;
            window.ClearInterval(ftimer);
        }
        window.Repaint();
    }, 42 );
}

function load_last_fm_logo(){
    if(!fso.FileExists(script_path + "footer_logo.png")) {
        var url = "http://www.last.fm/static/images/logo_beta.png?eb6d3ca20e73"
        var file = "\"" + script_path + "last_fm_logo.jpg" + "\"";
        WshShell.Run(vbs + " " + url + " " + file, false);
       
        var url = "http://static-web.last.fm/static/images/favicon.702b239b6194.ico"
        var file = "\"" + script_path + "last_fm_ico.ico" + "\"";
        WshShell.Run(vbs + " " + url + " " + file, false);

        var url = "http://static-web.last.fm/static/images/footer_logo.ddcfd65712a6.png"
        var file = "\"" + script_path + "footer_logo.png" + "\"";
        WshShell.Run(vbs + " " + url + " " + file, false);
    }
}

function create_download_file() {
    try {
        file = fso.CreateTextFile(script_path + "download.vbs" )
       
        var text =   
            "If (WScript.Arguments.Count <> 2) Then" + "\n\r" +   
            "   WScript.Quit" + "\n\r" +
            "End If" + "\n\r" + "\n\r" +   

            "url = WScript.Arguments(0)" + "\n\r" +   
            "file = WScript.Arguments(1)" + "\n\r"  + "\n\r" +   

            "Set objFSO = Createobject(" + '"Scripting.FileSystemObject"' + ")" + "\n\r" +   
            "If objFSO.Fileexists(file) Then" + "\n\r" +   
            "   Set objFSO = Nothing" + "\n\r" +
            "   WScript.Quit" + "\n\r" +
            "End If" + "\n\r" + "\n\r" +   

            "Set objXMLHTTP = CreateObject(" + '"MSXML2.XMLHTTP"' + ")" + "\n\r" +   
            "objXMLHTTP.open " + '"GET"' + ", url,false" + "\n\r" +   
            "objXMLHTTP.send()" + "\n\r" + "\n\r" +   

            "If objXMLHTTP.Status = 200 Then" + "\n\r" +   
            "   Set objADOStream = CreateObject(" + '"ADODB.Stream"' + ")" + "\n\r" +
            "   objADOStream.Open" + "\n\r" +
            "   objADOStream.Type = 1" + "\n\r" +
            "   objADOStream.Write objXMLHTTP.ResponseBody" + "\n\r" +
            "   objADOStream.Position = 0" + "\n\r" +
            "   objADOStream.SaveToFile file" + "\n\r" +
            "   objADOStream.Close" + "\n\r" +
            "   Set objADOStream = Nothing" + "\n\r" +
            "End If" + "\n\r" + "\n\r" +   

            "Set objFSO = Nothing" + "\n\r" +   
            "Set objXMLHTTP = Nothing"   
        ;

        file.WriteLine(text);
        file.Close();
    } catch(e) {};
}

function on_mouse_move(x, y) {
    window.SetCursor(32649);

    on_text = x >= txt_x && x < sb_x && y  >= txt_y ? true : false;
    on_sb =  x >= sb_x && x < ww && y >= txt_y && y < wh ? true : false;
    on_pic = !on_text && !on_sb ? true : false;

    if (on_text_down){
        txt_x = x - delta_x;
        txt_y = y - delta_y;

        txt_x = txt_x <= 0 ? 0 : txt_x >= ww - 50 ? ww - 50: txt_x;
        txt_y = txt_y <= 0 ? 0 : txt_y >= wh - (a_text_row_height + t_margin * 2) ? wh - (a_text_row_height + t_margin * 2) : txt_y;

        get_b_text_array();
    }

    if (on_sb_down && scrollbar && b_text_rows > b_text_visable_rows){
        sb_posy = y + delta_y;
        s_text = y + delta_y >= 0 ? y + delta_y <= (b_text_rows - b_text_visable_rows) * scrollbar_k ? Math.round(sb_posy / scrollbar_k) : b_text_rows - b_text_visable_rows : 0;
        //window.Repaint();
        window.RepaintRect(txt_x, txt_y, ww - txt_x, wh - txt_y);
    }
   
    window.RepaintRect(sb_x, txt_y, ww, wh);
}

function on_mouse_wheel(delta) {
    ShiftDown = utils.IsKeyPressed(0x10) ? true : false;
   
   if (ShiftDown) on_key_down();
   
    if (on_pic && !ShiftDown && !delay){
        get_files_from_dir(artist_folder_path(artist));
        if (files.length > 1){
            delay = true;
            fdelay();
            next_image(delta);
            if (cycle > 0) step = 0;
        }
    }
   
    if (on_text && !ShiftDown){
        if (b_text_rows > b_text_visable_rows){
            if (delta < 0) {s_text = b_text_rows - s_text <= b_text_visable_rows ? b_text_rows - b_text_visable_rows : s_text += 1}
            if (delta > 0) {s_text = s_text <= 0 ? 0 : s_text -= 1}
        }
        window.RepaintRect(txt_x, txt_y, ww - txt_x, wh - txt_y);
    }
   
    if (on_text && ShiftDown && !delay){
        delay = true;
        fdelay();
        if (delta < 0) {font_size_b = font_size_b <= min_font_size ? min_font_size : font_size_b - 2;};
        if (delta > 0) {font_size_b = font_size_b >= max_font_size ? max_font_size : font_size_b + 2;};
        window.SetProperty("font size: biography", font_size_b);
        get_font();
        refresh_txt = true;
        get_b_text_array();
    }

    if (set_cycle && on_pic) {
        if (delta < 0) {cycle = cycle <= 0 ? 0 : cycle - 5;};
        if (delta > 0) {cycle = cycle >= 60 ? 60 : cycle + 5;};
        window.SetProperty("auto cycle (sec)", cycle);
        window.Repaint();
    }
}

function on_mouse_lbtn_down(x,y){
    if (on_text){
        on_text_down = true;
        delta_x = x - txt_x;
        delta_y = y - txt_y;
    }
    if (on_sb){
        on_sb_down = true;
        sb_posy = s_text * scrollbar_k;
        delta_y = sb_posy - y;
    }
}

function on_mouse_lbtn_up(x,y){
    window.SetProperty("txt_x", txt_x);
    window.SetProperty("txt_y", txt_y);
    on_text_down = false;
    on_sb_down = false;
}

function on_mouse_lbtn_dblclk (x,y){
    if (on_text){
        lang = lang == 1 ? 0 : 1;
        window.SetProperty("lang", lang);
        get_text();
    }

    if (on_pic){
        select_p_a = select_p_a == 1 ? 0 : 1;
        window.SetProperty("pictures/albums", select_p_a);
        get_pic();
    }
}

function on_mouse_leave() {
    window.SetCursor(32512);
    on_sb = false;
    window.Repaint();
}

function on_size(){
    ww = window.Width;   
    wh = window.Height;
   
    txt_x = window.GetProperty("txt_x");
    txt_y = window.GetProperty("txt_y");

    txt_x = txt_x >= ww - 50 && txt_x >= 0 ? ww - 50 : txt_x;
    txt_y = txt_y >= wh - (a_text_row_height + t_margin * 2) && txt_y >= 0 ? wh - (a_text_row_height + t_margin * 2) : txt_y;
   
    refresh_txt = true;
    get_b_text_array();
}

function del_folders(n){
    var dir = fso.GetFolder(tmp_b_path);
    var e = new Enumerator( dir.SubFolders );
    try {
        for(; !e.atEnd(); e.moveNext() ) {
            var name = e.item().Name;
            if (name.indexOf("_download") < 0){
                if (name.indexOf(n) < 0){
                    fso.deleteFolder(tmp_b_path + name, true);
                }
            }   
        }
    } catch(e) {};
}

function calc_img_size(img){
    if(!img) return;
    var size = {x:0, y:0, width:0, height:0, cx:0, cy:0, cwidth:0, cheight:0};

    switch(align_mode) {   
   case 0: // adjust     
        var sw = ww / img.Width;
        var sh = wh / img.Height;
        var s = Math.min(sw, sh);
       
        var x = 0;
        var y = 0;
       
        if (sw > sh) x = (ww - img.Width * s) / 2;
        else if (sw < sh) y = (wh - img.height * s) / 2;

        var width = img.Width * s;
        var height = img.Height * s;
        var cx = 0;
        var cy = 0;
        var cwidth = img.Width;
        var cheight = img.Height;
      break;
       
    case 1: // adjust top - center
        var sw = ww / img.Width;
        var sh = wh / img.Height;
        var s = Math.min(sw, sh);

        var x = 0;
        if (sw > sh) x = (ww - img.Width * s) / 2;
        var y = 0;
        var width = img.Width * s;
        var height = img.Height * s;
        var cx = 0;
        var cy = 0;
        var cwidth = img.Width;
        var cheight = img.Height;
      break;
       
    case 2: // adjust top - left
        var sw = ww / img.Width;
        var sh = wh / img.Height;
        var s = Math.min(sw, sh);
       
        var x = 0;
        var y = 0;
        var width = img.Width * s;
        var height = img.Height * s;
        var cx = 0;
        var cy = 0;
        var cwidth = img.Width;
        var cheight = img.Height;
      break;

   case 3: // centre   
      var sr = img.Width / img.Height;   
      var dr = ww / wh;   
      if (sr < dr) {   
         var r = img.Width / ww;
         var cheight = wh * r;
         var cy = Math.round((img.Height - cheight) / 2);
         var cwidth = img.Width;
         var cx = 0;
      } else {   
         var r = img.Height / wh;
         var cwidth = ww * r;
         var cx = Math.round((img.Width - cwidth) / 2);
         var cheight = img.Height;
         var cy = 0;
      }   
        var x = 0;         
        var y = 0;         
        var width = ww;         
        var height = wh;         
      break;   
       
   case 4: // centre - top     
      var sr = img.Width / img.Height;   
      var dr = ww / wh;   
      if (sr < dr) {   
         var r = img.Width / ww;
         var cheight = wh * r;
         var cy = 0;
         var cwidth = img.Width;
         var cx = 0;
      } else {   
         var r = img.Height / wh;
         var cwidth = ww * r;
         var cx = Math.round((img.Width - cwidth) / 2);
         var cheight = img.Height;
         var cy = 0;
      }
        var x = 0;
        var y = 0;
        var width = ww;
        var height = wh;
      break;   
       
   case 5: // stretch     
        var x = 0;
        var y = 0;
        var width = ww;
        var height = wh;
        var cx = 0;
        var cy = 0;
        var cwidth = img.Width;
        var cheight = img.Height;
      break;   
    }
   
    size.x = x + p_margin;
    size.y = y + p_margin;
    size.width = width - p_margin * 2;
    size.height = height - p_margin * 2;
    size.cx = cx;
    size.cy = cy;
    size.cwidth = cwidth;
    size.cheight = cheight;
   
    return size;
}

function copy_files(){
    var save_images_state = save_images;
    if (!save_images_state) save_images = true;

    var destination_path;
    var tmp_files = files;
    var tmp_artist = artist;
    var tmp_p_a = p_a[select_p_a];
    var tmp_directory_path;
   
    if (path.indexOf('://') > 0 || path.indexOf('youtube') == 0 || path.indexOf('cdda') == 0) {
        tmp_directory_path = fb.ProfilePath + tmp_p_a + "\\";
    } else {
        tmp_directory_path = directory_path + "\\" + tmp_p_a + "\\";
    }   
   
    var nl = "\" + chr(10) + \"";
    var input_box_text = "Копировать  " + nl + nl + tmp_artist + " " + tmp_p_a + ".jpg" + nl + "файлы в";

    var string = input_box(input_box_text, tmp_directory_path, "Foobar 2000");

    if (string){
        destination_path = folder_exists(string);
        if (!destination_path) {
            copy_files();
        } else{
            copy_files_to_folder(destination_path, tmp_files, tmp_p_a);
        }
    }
    save_images = save_images_state;
}

function copy_files_to_folder(p, f, pa){
    if (p.length != "\\"){p = p + "\\"}
    for (i in f) {
        if (f[i].indexOf(pa) > 0){
            try {
                fso.CopyFile (f[i], p  , 1 );
            } catch(e) {}
        }
    }
}

function input_box(p_text, d_text, w_title){
    vbe = new ActiveXObject('ScriptControl');
    vbe.Language = 'VBScript';
    return vbe.eval( "InputBox(\"" + p_text + "\",\"" + w_title + "\",\"" + d_text + "\")");
}

function clean_path_name(n) {
    if (!n) return;
    return n.replace(/[\/\:\*\?\"\<\>\|]/g,'');
}

function folder_exists(n) {
    var driver = fso.GetDriveName(n);
    if (!fso.DriveExists(driver)) {
        return "";
    } else {
        var p = "";
        var split_string = [];
        split_string = n.replace(/\\$/g, "").split("\\");

        for (var i = 1; i < split_string.length; i += 1) {
            p = p + clean_path_name(split_string[i]) + "\\";
            try {
                if(!fso.FolderExists(driver + "\\" + p)) fso.CreateFolder(driver + "\\" + p);
            } catch(e) {};
        }
      return driver + "\\" + p;
    }
}

function on_notify_data(name, info) {
    if(name == "panel") {
        if (info == "bio"){
            panel_on = true;
            artist = "";
            on_metadb_changed();
        } else{
            panel_on =  false;
        }
    }
}

//var WshShell = WScript.CreateObject("WScript.Shell")
//WshShell.SendKeys("+{F10}");
Сейчас этот вариант у себя гоняю...
MC Web
14.11.2016, 15:34
 
Раздел: Секреты foobar2000
Тема: Скрипты для foo_uie_wsh_panel_mod
Ответы: 2986
Просмотры: 573115
  • 2

Re: Скрипты для foo_uie_wsh_panel_mod

Biography Text && Picture. www.last.fm
version 10112016

Безымянный2.png
Безымянный2.png (11.38 КБ) Просмотров: 1857
Безымянный.png

Код: Выделить всё
// ==PREPROCESSOR==
// @name "Biography Text && Picture. www.last.fm"
// @author "kgena_ua"
// @version "10112016"
// @feature "v1.4"
// @feature "watch-metadb"
// ==/PREPROCESSOR==

function RGB(r,g,b) { return (0xff000000|(r<<16)|(g<<8)|(b)); }
function RGBA(r,g,b,a) { return ((a << 24) | (r << 16) | (g << 8) | (b)); }
function getRed(color) {return ((color >> 16) & 0xff);};
function getGreen(color) {return ((color >> 8) & 0xff);};
function getBlue(color) {return (color & 0xff);};

DT_LEFT = 0x00000000;
DT_RIGHT = 0x00000002;
DT_CENTER = 0x00000001;
DT_VCENTER = 0x00000004;
DT_SINGLELINE = 0x00000020;
DT_WORD_ELLIPSIS = 0x00040000;
DT_WORDBREAK = 0x00000010;
DT_CALCRECT = 0x00000400;
DT_NOPREFIX = 0x00000800;

MF_ENABLED = 0x00000000;   
MF_GRAYED = 0x00000001;   
MF_SEPARATOR = 0x00000800; 

var ww = 200, wh = 200;

var font_name_a = window.GetProperty(" font name: artist", "Arial");
var font_name_b = window.GetProperty(" font name: biography", "Arial");
var font_size_a_d = window.GetProperty(" font size: artist (delta)", 0);
var font_size_b = window.GetProperty(" font size: biography", 12);
var a_font_style = window.GetProperty(" font style: artist", 1);
var b_font_style = window.GetProperty(" font style: biography", 0);
var min_font_size = 12;
var max_font_size = 16;

var a_font, b_font;
get_font();

function get_font(){
    a_font = gdi.Font(font_name_a, font_size_b + font_size_a_d, a_font_style);
    b_font = gdi.Font(font_name_b, font_size_b, b_font_style);
}   

ColorTypeCUI = {
    text: 0,
    selection_text: 1,
    inactive_selection_text: 2,
    background: 3,
    selection_background: 4,
    inactive_selection_background: 5,
    active_item_frame: 6
};

function get_color(){   
    bgcolor = window.GetColorCUI(ColorTypeCUI.background);
    a_color = window.GetColorCUI(ColorTypeCUI.text);
    b_color = window.GetColorCUI(ColorTypeCUI.inactive_selection_text);
    window.Repaint();
}

get_color();

function on_colors_changed(){
    get_color();
}

var fso = new ActiveXObject("Scripting.FileSystemObject");

var tmp_b_path = fb.ProfilePath + "\\tmp_Biography\\";
if (!fso.FolderExists(tmp_b_path)) {fso.CreateFolder(tmp_b_path)};

var script_path = tmp_b_path + "_download\\";
if (!fso.FolderExists(script_path)) {fso.CreateFolder(script_path)};
if (!fso.FileExists(script_path + "download.vbs")) {create_download_file()};

var doc = new ActiveXObject("htmlfile");
var WshShell = new ActiveXObject("WScript.Shell");
var vbs = "cscript //nologo \"" + script_path + "download.vbs\"";

var default_img_path = window.GetProperty(" default img path",".\\maybe\\textures\\nocover\\nocover.png");
var default_img = window.GetProperty(" default img", false);
var default_img_transparent = window.GetProperty(" default img transparent (0-255)", 100);

load_last_fm_logo();
var logo_img = gdi.Image(script_path + "footer_logo.png");

var artist, old_artist;
var path, directory_path;

function clean_name(n) {
    if (!n) return;
    return n.replace(/[^a-zA-Z0-9а-яА-Я\s-&]/g,'').replace(/^\s+|\s+$/g,"");
}

function artist_folder_path(n) {
    return tmp_b_path + n;
}

function check_folder(n) {
    if(!fso.FolderExists(n)) {fso.CreateFolder(n)};
}

String.prototype.repeat = function(n) {
    return new Array(n + 1).join(this);
}

window.SetProperty(" - user", "");
if (window.GetProperty(" - user") != "" ) window.SetProperty(" - user", "");
window.SetProperty("-".repeat(50), "");
if (window.GetProperty("-".repeat(50)) != "" ) window.SetProperty("-".repeat(50), "");

var g_img = null;
var p_margin = window.GetProperty(" margin: picture", 0);
var align_mode_a = new Array("adjust", "adjust top - center", "adjust top - left", "centre", "centre - top", "stretch");
var align_mode = window.GetProperty("align mode", 0);
var selected = 0;
var files = [];
var images = [];
var save_images = window.GetProperty("save images", false);
var limit = window.GetProperty(" download limit",5);
var cycle = window.GetProperty("auto cycle (sec)", 0);
if (cycle > 0) set_cycle_timer();
var fader = 255;
var fade_effect = window.GetProperty("fade effect", false);
var fade_step = window.GetProperty("fade step", 25);
var on_pic = false;

var download_quality = window.GetProperty("download quality", 1);
var quality = [
    [ "low", "avatar170s" , "300"],
    [ "medium", "300x300" , "300"],
    [ "high", "770x0" , ""]
];

var scrollbar = window.GetProperty(" scrollbar", true);
var scrollbar_w = window.GetProperty(" scrollbar width ", 4);
var scrollbar_k;
var sb_x = 0;
var sb_posy = 0;
var on_sb = false;
var on_sb_down = false;
var sb_color;

var b_file;
var bg_transparent = window.GetProperty(" bg transparent (0-255)", 200);
var t_margin = window.GetProperty(" margin: text", 10);
var txt_x = window.GetProperty("txt_x", window.Width / 2);
var old_txt_x = 0;
var txt_y = window.GetProperty("txt_y", window.Height / 2);
var delta_x, delta_y;
var a_x, a_y, b_x, b_y;
var text = "";
var text_not_found = new Array(". . .", ". . .");
var s_text = 0;
var a_text_row_height = 0;
var b_text_row_height = 0;
var b_text_rows = 0;
var b_text_visable_rows = 0;
var b_text_visable_height = 0;
var b_text_array = [];
var on_artist = false;
var on_text = false;
var on_text_down = false;
var refresh_txt = true;

var lang_query = new Array("", "ru/");
var lang_text = new Array("in", "ru");
var lang = window.GetProperty("lang", 0);

var select_p_a = window.GetProperty("pictures/albums", 0);
var p_a = new Array("images", "albums");

var panel_on = true;

var selection_mode = window.GetProperty("selection mode", 0);
var metadb;
on_item_focus_change();

function on_paint(gr){   
   !window.IsTransparent && gr.FillSolidRect(0, 0, ww, wh, bgcolor);
   
    draw_image(gr);

    if(set_cycle){   
        gr.FillSolidRect(0, 0, ww, wh, RGBA(getRed(bgcolor),getGreen(bgcolor),getBlue(bgcolor),bg_transparent));   
        var txt_cycle = cycle == 0 ? "off" : cycle + " sec";   
        set_cycle && gr.GdiDrawText("auto cycle:   " + txt_cycle, b_font, b_color, 0, 20, ww, wh, DT_CENTER | DT_WORD_ELLIPSIS );
    } else{   
        gr.FillSolidRect(txt_x, txt_y, ww - txt_x, wh - txt_y, RGBA(getRed(bgcolor),getGreen(bgcolor),getBlue(bgcolor),bg_transparent));   
    }   

    draw_scrollbar(gr);   
   
    gr.GdiDrawText( artist, a_font, RGB(0,0,0), a_x + 1, a_y + 2, ww - a_x - t_margin, wh, DT_LEFT | DT_WORD_ELLIPSIS | DT_NOPREFIX );   
    gr.GdiDrawText( artist, a_font, a_color, a_x, a_y, ww - a_x - t_margin, wh, DT_LEFT | DT_WORD_ELLIPSIS | DT_NOPREFIX );   

    for (var i = 0; i < b_text_visable_rows * 2; i += 2) {
        try {
            gr.GdiDrawText( b_text_array[i + s_text * 2].replace(/^\s+|\s+$/g, ""), b_font, RGB(0,0,0), b_x + 1, b_y + b_text_row_height * i / 2 + 2, ww, wh, DT_LEFT | DT_NOPREFIX );
            gr.GdiDrawText( b_text_array[i + s_text * 2].replace(/^\s+|\s+$/g, ""), b_font, b_color, b_x, b_y + b_text_row_height * i / 2 , ww, wh, DT_LEFT | DT_NOPREFIX );
        } catch(e) {}
    }

   // gr.GdiDrawText( "files " + files.length, gdi.Font("Arial",12, 0), b_color, 10, 0, ww, wh, DT_LEFT | DT_WORD_ELLIPSIS );
    //gr.GdiDrawText( "images " + images.length, gdi.Font("Arial",12, 0), b_color, 10, 20, ww, wh, DT_LEFT | DT_WORD_ELLIPSIS );
}

function draw_image(gr){
    if (g_img && images.length > 0){
        var size = calc_img_size(g_img);
        gr.DrawRect(size.x, size.y, size.width, size.height, 1, RGBA(getRed(bgcolor),getGreen(bgcolor),getBlue(bgcolor),fader));
        gr.DrawImage(g_img, size.x, size.y, size.width, size.height, size.cx, size.cy, size.cwidth, size.cheight, 0, fader);
    }
   
    if (logo_img && images.length == 0 && !default_img){
        gr.DrawImage(logo_img, 10, 10, logo_img.Width * 0.8, logo_img.Height * 0.8, 0, 0, logo_img.Width, logo_img.Height, 0, 100);         
    }

    if (images.length == 0 && default_img){
        try {
            nc_img = gdi.Image(default_img_path);
            var size = calc_img_size(nc_img);
            gr.DrawImage(nc_img, size.x, size.y, size.width, size.height, size.cx, size.cy, size.cwidth, size.cheight, 0, default_img_transparent);
        } catch(e) {};
    }
}

function draw_scrollbar(gr){
    scrollbar_h = b_text_rows > b_text_visable_rows ? b_text_visable_height * (b_text_visable_rows / b_text_rows) : 0;
    if (b_text_rows > b_text_visable_rows){ scrollbar_h = Math.max(5, scrollbar_h)}
    scrollbar_y = s_text > 0 ? s_text * scrollbar_k : 0;

    sb_x = ww - t_margin - scrollbar_w;
   
    sb_t = on_sb || on_sb_down ? 150 : 50;
    sb_color = RGBA(getRed(a_color), getGreen(a_color), getBlue(a_color), sb_t);
   
    scrollbar && gr.FillSolidRect(sb_x, b_y + scrollbar_y, scrollbar_w, scrollbar_h, sb_color);
}

function on_playlist_switch() {
    on_item_focus_change();
}

function on_playback_new_track() {
    on_item_focus_change();
}

function on_playback_dynamic_info_track() {
    on_item_focus_change();
}

function on_playback_stop() {
    on_item_focus_change();
}

function on_selection_changed(metadb) {
   on_item_focus_change();
}

function on_item_focus_change() {
    switch (selection_mode) {
    case 0:
        metadb = fb.IsPlaying ? fb.GetNowPlaying() : fb.GetFocusItem();   
        break;   
    case 1:   
       metadb = fb.GetFocusItem();
        break;   
    }   
    if (metadb) on_metadb_changed();   
}   

function Eval(field) {   
    if (!metadb) return;   
    path = fb.Titleformat("%path%").EvalWithMetadb(metadb);
    directory_path = fb.Titleformat("$directory_path(%path%)").EvalWithMetadb(metadb);
    return path.indexOf('://') > 0 ? fb.TitleFormat("[" + field + "]").Eval(true) : fb.TitleFormat("[" + field + "]").EvalWithMetadb(metadb);
}   

function on_metadb_changed() {
    if (!panel_on) return;
    if (!metadb) return; 
    artist = Eval("%artist%");
    if (artist) {artist = clean_name(artist)} else {artist = ""};
    if (artist != old_artist){
        if (!save_images) del_folders(artist);
        get_text();
        get_pic();
        old_artist = artist;
    }
}   

function get_pic() {
    images = [];
    files = [];
    selected = 0;
    g_img = null;
    window.Repaint();
   
    check_folder(artist_folder_path(artist));
    if (fso.FolderExists(artist_folder_path(artist))){
        get_files_from_dir(artist_folder_path(artist));
        if (!g_img && images.length > 0) {
            next_image(0);
        } else {
            get_lastFM_pic(artist_folder_path(artist));
        }
    }
}

function get_lastFM_pic(p){
    xmlhttp1 = new ActiveXObject("Microsoft.XMLHTTP");     
    url1 = ("http://www.last.fm/music/" + encodeURIComponent(artist) + "/+" + p_a[select_p_a]);     
    xmlhttp1.open("GET", url1, true);     
    xmlhttp1.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
    xmlhttp1.send(null);     
    xmlhttp1.onreadystatechange = function () {
        if (xmlhttp1.readyState == 4) {
            if (xmlhttp1.status == 200) { 
                doc.open();     
                var div = doc.createElement("div");
                div.innerHTML = xmlhttp1.responsetext;
                var data = div.getElementsByTagName("img");
                var urls = [];
                for (i = 0; i < data.length; i++) {   
                    if (data[i].className == "image-list-image" && select_p_a == 0){       
                        if (data[i].src.indexOf("http://img2-ak.lst.fm/i/u/avatar170s") == 0 || data[i].src.indexOf("https://lastfm-img2.akamaized.net/i/u/avatar170s") == 0) {
                            urls.push(data[i].src.replace("avatar170s", quality[download_quality][1]));
                        }     
                    }   
                    if (data[i].className == "album-grid-album-art" && select_p_a == 1){   
                        if (data[i].src.indexOf("http://img2-ak.lst.fm/i/u/300") == 0 && data[i].src.indexOf("c6f59c1e5e7240a4c0d427abd71f3dbb") < 0) {                       
                            urls.push(data[i].src.replace("300", quality[download_quality][2]))
                        }     
                    }       
                }
                var found = urls.length;
                for (i = 0; i < Math.min(urls.length, limit); i++) {     
                    file = "\"" + p + "\\" + artist + "_"  + i + "_" + p_a[select_p_a] + ".jpg" + "\"";     
                    WshShell.Run(vbs + " " + urls[i] + " " + file, false);
                }     
                doc.close();
                if (found > 0) get_files_if_loaded(p);
            }
        }     
    }     
}

function get_files_from_dir(p) {
    if (!artist) return;
    files = utils.Glob(p + "\\" + artist + "*" + p_a[select_p_a] + ".jpg").toArray();
   
    if (files.length > images.length){
        images = [];
       
        for (var i = 0; i < files.length; i += 1) {
            try {
                images.push(resize_image(gdi.Image(files[i])));
            } catch(e) {}
        }
    }
}

function next_image(d){
    fader = fade_effect ? 0 : 255;
    if (d < 0) {selected = selected <= 0 ? images.length - 1 : selected = selected - 1};
    if (d > 0) {selected = selected >= images.length - 1 ? 0 : selected = selected + 1};
    g_img = images[selected];
    if (g_img && fade_effect) fader_timer();
    window.Repaint();
}

function resize_image(img){
    if (!img) return;
   
    var scale_w = (window.Width - p_margin * 2) / img.Width;
    var scale_h = (window.Height - p_margin * 2) / img.Height;
    var scale = Math.min(scale_w, scale_h);
    var nww = img.Width * scale;
    var nwh = img.Height * scale

    var temp_bmp = gdi.CreateImage(nww, nwh);
    var temp_gr = temp_bmp.GetGraphics();
    temp_gr.SetSmoothingMode(2);
    temp_gr.SetInterpolationMode(7);
    temp_gr.DrawImage(img, 0, 0, nww, nwh, 0, 0, img.width, img.height);
    temp_bmp.ReleaseGraphics(temp_gr);
   
    CollectGarbage();
    return temp_bmp;
    temp_bmp.Dispose();
    temp_gr = null;
    temp_bmp = null;
}

function get_text() {
    s_text = 0;
    text = "";
    b_text_array = [];
    b_text_file = artist_folder_path(artist) + "\\" + artist + "_biography_" + lang_query[lang].replace(/\//g,'') + ".txt";
   
    refresh_txt = true;
   
    if (artist && fso.FileExists(b_text_file)){
        text = utils.ReadTextFile(b_text_file);
        get_b_text_array();
    } else{
        get_lastFM_b_text(b_text_file);
    }
}

function get_lastFM_b_text(p){
    xmlhttp2 = new ActiveXObject("Microsoft.XMLHTTP");
    url2 = ("http://www.last.fm/" + lang_query[lang] + "music/" + encodeURIComponent(artist) + "/+wiki");
    xmlhttp2.open("GET", url2, true);
    xmlhttp2.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
    xmlhttp2.send(null);
    xmlhttp2.onreadystatechange = function () {
        if (xmlhttp2.readyState == 4) {
            if (xmlhttp2.status == 200) {
                doc.open();
                var div = doc.createElement("div");
                div.innerHTML = xmlhttp2.responsetext;
                var data = div.getElementsByTagName("div");
                for (i = 0; i < data.length; i++) {
                    if (data[i].className == "wiki-content") {
                        text = strip_tags(data[i].innerHTML);
                        break;
                    }
                }
                doc.close();
            }
            if (text != "") save_biography_file(text, p);
            if (text == "") text = text_not_found[lang];
            get_b_text_array();
        }
    }
}

function strip_tags(t) {
    doc.open();
    var div = doc.createElement("div");
    div.innerHTML = t.replace(/<[Pp][^>]*>/g, "").replace(/<\/[Pp]>/g, "<br>").replace(/\n/g, "<br>");
    var text = div.innerText;
    doc.close();
    return text;
}

function get_b_text_array() {
    a_x = txt_x + t_margin;
    a_y = txt_y + t_margin;
 
    temp_bmp = gdi.CreateImage(1, 1);
    temp_gr = temp_bmp.GetGraphics();

    a_text_row_height = temp_gr.CalcTextHeight("text", a_font);
    b_text_row_height = temp_gr.CalcTextHeight("text", b_font);
   
    b_x = txt_x + t_margin;
    b_y = a_y + a_text_row_height + b_text_row_height;
   
    string_width = Math.max(ww - b_x - t_margin - scrollbar_w - 10, 0);

    if (Math.abs(txt_x - old_txt_x) > 5 || refresh_txt){
        b_text_array = [];
        if (text) b_text_array = temp_gr.EstimateLineWrap(text, b_font, string_width).toArray();
        old_txt_x = txt_x;
        refresh_txt = false;
    }
   
    b_text_rows = b_text_array.length / 2;

    b_text_visable_area = Math.floor(Math.max(0, window.Height - t_margin - b_y));
    b_text_visable_rows = Math.floor(b_text_visable_area / b_text_row_height);
    b_text_visable_height = b_text_visable_rows * b_text_row_height;


    if (b_text_visable_rows + s_text > b_text_rows && s_text > 0) {
        s_text = (b_text_rows - b_text_visable_rows);
    }
   
    scrollbar_k = b_text_visable_height / b_text_rows;
   
    temp_bmp.ReleaseGraphics(temp_gr);
    temp_bmp.Dispose();
    temp_gr = null;
    temp_bmp = null;

    window.Repaint();
}

function save_biography_file(t, p){
    if (!artist) return;
    try {
        file = fso.OpenTextFile( p, 2, true, -1)
        file.WriteLine(t);
        file.Close();
    } catch(e) {
        return;
    }
}

function on_mouse_rbtn_up (x, y){     
    var _menu = window.CreatePopupMenu();
   
    _menu.AppendMenuItem(MF_ENABLED, 10, "EN text");   
    _menu.AppendMenuItem(MF_ENABLED, 11, "RU text");   
    _menu.CheckMenuRadioItem(10, 11, lang + 10);         
    _menu.EnableMenuItem(lang + 10, 1);     

    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);   
    _menu.AppendMenuItem(MF_ENABLED, 12, "Prefer now playing");   
    _menu.AppendMenuItem(MF_ENABLED, 13, "Follow selected track");   
    _menu.CheckMenuRadioItem(12, 13 , selection_mode + 12);   
    _menu.EnableMenuItem(selection_mode + 12, 1);
       
    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0); 
    _menu.AppendMenuItem(MF_ENABLED, 14, "Artist pictures");   
    _menu.AppendMenuItem(MF_ENABLED, 15, "Albums pictures");   
    _menu.CheckMenuRadioItem(14, 15 , select_p_a + 14);   
    _menu.EnableMenuItem(select_p_a + 14, 1);

    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);   
    IS_ARTIST = artist ? MF_ENABLED : MF_GRAYED;   
    _menu.AppendMenuItem(IS_ARTIST, 16, "last.fm Artist");   
   
    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
    _menu.AppendMenuItem(MF_ENABLED, 17, "Fade effect");
    _menu.CheckMenuItem(17, fade_effect);

    _firstgroup = window.CreatePopupMenu();
    _firstgroup.AppendTo(_menu,MF_ENABLED,  "Align : " + align_mode_a[align_mode]);
   
    _firstgroup.AppendMenuItem(MF_ENABLED, 20, align_mode_a[0]);         
    _firstgroup.AppendMenuItem(MF_ENABLED, 21, align_mode_a[1]);
    _firstgroup.AppendMenuItem(MF_ENABLED, 22, align_mode_a[2]);
    _firstgroup.AppendMenuItem(MF_ENABLED, 23, align_mode_a[3]);
    _firstgroup.AppendMenuItem(MF_ENABLED, 24, align_mode_a[4]);
    _firstgroup.AppendMenuItem(MF_ENABLED, 25, align_mode_a[5]);
    _firstgroup.CheckMenuRadioItem(20, 25, align_mode + 20);
    _firstgroup.EnableMenuItem(align_mode + 20, 1);

    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
    _secondgroup = window.CreatePopupMenu();
    _secondgroup.AppendTo(_menu,MF_ENABLED,  "Download quality : " + quality[download_quality][0]);
   
    _secondgroup.AppendMenuItem(MF_ENABLED, 30, "Low");
    _secondgroup.AppendMenuItem(MF_ENABLED, 31, "Medium");
    _secondgroup.AppendMenuItem(MF_ENABLED, 32, "High");
    _secondgroup.CheckMenuRadioItem(30, 32, download_quality + 30);
    _secondgroup.EnableMenuItem(download_quality + 30, 1);

    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
    MF_STRING = images.length > 0 ? MF_ENABLED : MF_GRAYED;
    _menu.AppendMenuItem(MF_STRING, 40, "Copy to folder containing track...");
    _menu.AppendMenuItem(MF_STRING, 50, "Open image");
   
    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
    _menu.AppendMenuItem(MF_ENABLED, 60, "Save images and text");
    _menu.CheckMenuItem(40, save_images);

    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);   
    _menu.AppendMenuItem(MF_ENABLED, 100, "Reload");   
    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);   
    _menu.AppendMenuItem(MF_ENABLED, 110, "Properties");   
    _menu.AppendMenuItem(MF_ENABLED, 120, "Configure ...");

    ret = _menu.TrackPopupMenu(x,y);

    switch (ret) {
    case 10:
        lang = 0;
        window.SetProperty("lang", lang);
        get_text();
        break;
    case 11:
        lang = 1;
        window.SetProperty("lang", lang);
        get_text();
        break;
    case 12:
        selection_mode = 0;
        window.SetProperty("selection mode", selection_mode);
        on_item_focus_change();
        break;
    case 13:
        selection_mode = 1;
        window.SetProperty("selection mode", selection_mode);
        on_item_focus_change();
        break;
    case 14:
        select_p_a = 0;
        window.SetProperty("pictures/albums", select_p_a);
        get_pic();
        break;
    case 15:
        select_p_a = 1;
        window.SetProperty("pictures/albums", select_p_a);
        get_pic();
        break;
    case 16:
        WshShell.run("http://www.last.fm/" + lang_query[lang] + "music/" + encodeURIComponent(artist));
        break;
    case 17:
        window.SetProperty("fade effect", !fade_effect);
        fade_effect = window.GetProperty("fade effect");
        break;
    case 20:
    case 21:
    case 22:
    case 23:
    case 24:
    case 25:
        align_mode = ret - 20;
        window.SetProperty("align mode", align_mode);
        window.Repaint();
        break;
    case 30:
    case 31:
    case 32:   
        download_quality = ret - 30;
        window.SetProperty("download quality", download_quality);
        break;
    case 40:
        copy_files();
        break;
    case 50:
        try {
            if (images[selected]) WshShell.run( '"' + artist_folder_path(artist)+ "\\" + artist + "_"  + selected + "_" + p_a[select_p_a] + ".jpg" + '"' );
        } catch(e) {}
        break;
    case 60:
        window.SetProperty("Save images", !save_images);
        save_images = window.GetProperty("Save images");
        break;
    case 100:
        window.Reload();
        break;
    case 110:
        window.ShowProperties();
        break;   
    case 120:
        window.ShowConfigure();   
        break;   
   }
    _menu.Dispose();   
    return true;   
}   

var timer;

function get_files_if_loaded(p){
    timer && window.ClearInterval(timer);
    timer = window.SetInterval(function() {
        get_files_from_dir(p);
        if (images.length > 0)  {
            next_image(0);
            window.ClearInterval(timer); 
        }
    }, 500 );
}

var set_cycle = false;

function on_key_down(vkey) {
    if (vkey == 16){
        set_cycle = true;
        dis_set();
        window.Repaint();
    }
}

var cycle_timer, step = 0;

function set_cycle_timer(){
    cycle_timer && window.ClearInterval(cycle_timer);
    cycle_timer = window.SetInterval(function() {
        step =  set_cycle ? 0 : step + 1;
        if (cycle > 0 && step >= cycle){
            get_files_from_dir(artist_folder_path(artist));
            if (images.length > 1){
                next_image(1);
                step = 0;
            }
        }
        window.Repaint();
    }, 1000 );
}

var dis_timer, dis = 0;

function dis_set(){
    dis = 0;
    dis_timer && window.ClearInterval(dis_timer);
    dis_timer = window.SetInterval(function() {
        if (set_cycle) {
            dis++;
            if(dis == 1) {
                set_cycle = false;
                if (cycle > 0) set_cycle_timer();
                if (cycle == 0) window.ClearInterval(cycle_timer);
                window.ClearInterval(dis_timer)
                window.Repaint();
            };
        }
    }, 1000 );
}

var delay = false;

function fdelay(){
    var delay_timer = window.SetTimeout(function() {
        delay = false;
        window.ClearTimeout(delay_timer);
    }, 200);
}

var ftimer;

function fader_timer(){
    fader = 0;
    ftimer && window.ClearInterval(ftimer);
    ftimer = window.SetInterval(function() {
        fader = fader + fade_step;
        if (fader >= 255) {
            fader= 255;
            window.ClearInterval(ftimer);
        }
        window.Repaint();
    }, 42 );
}

function load_last_fm_logo(){
    if(!fso.FileExists(script_path + "footer_logo.png")) {
        var url = "http://www.last.fm/static/images/logo_beta.png?eb6d3ca20e73"
        var file = "\"" + script_path + "last_fm_logo.jpg" + "\"";
        WshShell.Run(vbs + " " + url + " " + file, false);
       
        var url = "http://static-web.last.fm/static/images/favicon.702b239b6194.ico"
        var file = "\"" + script_path + "last_fm_ico.ico" + "\"";
        WshShell.Run(vbs + " " + url + " " + file, false);

        var url = "http://static-web.last.fm/static/images/footer_logo.ddcfd65712a6.png"
        var file = "\"" + script_path + "footer_logo.png" + "\"";
        WshShell.Run(vbs + " " + url + " " + file, false);
    }
}

function create_download_file() {
    try {
        file = fso.CreateTextFile(script_path + "download.vbs" )
       
        var text =   
            "If (WScript.Arguments.Count <> 2) Then" + "\n\r" +   
            "   WScript.Quit" + "\n\r" +
            "End If" + "\n\r" + "\n\r" +   

            "url = WScript.Arguments(0)" + "\n\r" +   
            "file = WScript.Arguments(1)" + "\n\r"  + "\n\r" +   

            "Set objFSO = Createobject(" + '"Scripting.FileSystemObject"' + ")" + "\n\r" +   
            "If objFSO.Fileexists(file) Then" + "\n\r" +   
            "   Set objFSO = Nothing" + "\n\r" +
            "   WScript.Quit" + "\n\r" +
            "End If" + "\n\r" + "\n\r" +   

            "Set objXMLHTTP = CreateObject(" + '"MSXML2.XMLHTTP"' + ")" + "\n\r" +   
            "objXMLHTTP.open " + '"GET"' + ", url,false" + "\n\r" +   
            "objXMLHTTP.send()" + "\n\r" + "\n\r" +   

            "If objXMLHTTP.Status = 200 Then" + "\n\r" +   
            "   Set objADOStream = CreateObject(" + '"ADODB.Stream"' + ")" + "\n\r" +
            "   objADOStream.Open" + "\n\r" +
            "   objADOStream.Type = 1" + "\n\r" +
            "   objADOStream.Write objXMLHTTP.ResponseBody" + "\n\r" +
            "   objADOStream.Position = 0" + "\n\r" +
            "   objADOStream.SaveToFile file" + "\n\r" +
            "   objADOStream.Close" + "\n\r" +
            "   Set objADOStream = Nothing" + "\n\r" +
            "End If" + "\n\r" + "\n\r" +   

            "Set objFSO = Nothing" + "\n\r" +   
            "Set objXMLHTTP = Nothing"   
        ;

        file.WriteLine(text);
        file.Close();
    } catch(e) {};
}

function on_mouse_move(x, y) {
    window.SetCursor(32649);

    on_text = x >= txt_x && x < sb_x && y  >= txt_y ? true : false;
    on_sb =  x >= sb_x && x < ww && y >= txt_y && y < wh ? true : false;
    on_pic = !on_text && !on_sb ? true : false;

    if (on_text_down){
        txt_x = x - delta_x;
        txt_y = y - delta_y;

        txt_x = txt_x <= 0 ? 0 : txt_x >= ww - 50 ? ww - 50: txt_x;
        txt_y = txt_y <= 0 ? 0 : txt_y >= wh - (a_text_row_height + t_margin * 2) ? wh - (a_text_row_height + t_margin * 2) : txt_y;

        get_b_text_array();
    }

    if (on_sb_down && scrollbar && b_text_rows > b_text_visable_rows){
        sb_posy = y + delta_y;
        s_text = y + delta_y >= 0 ? y + delta_y <= (b_text_rows - b_text_visable_rows) * scrollbar_k ? Math.round(sb_posy / scrollbar_k) : b_text_rows - b_text_visable_rows : 0;
        //window.Repaint();
        window.RepaintRect(txt_x, txt_y, ww - txt_x, wh - txt_y);
    }
   
    window.RepaintRect(sb_x, txt_y, ww, wh);
}

function on_mouse_wheel(delta) {
    ShiftDown = utils.IsKeyPressed(0x10) ? true : false;
   
   if (ShiftDown) on_key_down();
   
    if (on_pic && !ShiftDown && !delay){
        get_files_from_dir(artist_folder_path(artist));
        if (files.length > 1){
            delay = true;
            fdelay();
            next_image(delta);
            if (cycle > 0) step = 0;
        }
    }
   
    if (on_text && !ShiftDown){
        if (b_text_rows > b_text_visable_rows){
            if (delta < 0) {s_text = b_text_rows - s_text <= b_text_visable_rows ? b_text_rows - b_text_visable_rows : s_text += 1}
            if (delta > 0) {s_text = s_text <= 0 ? 0 : s_text -= 1}
        }
        window.RepaintRect(txt_x, txt_y, ww - txt_x, wh - txt_y);
    }
   
    if (on_text && ShiftDown && !delay){
        delay = true;
        fdelay();
        if (delta < 0) {font_size_b = font_size_b <= min_font_size ? min_font_size : font_size_b - 2;};
        if (delta > 0) {font_size_b = font_size_b >= max_font_size ? max_font_size : font_size_b + 2;};
        window.SetProperty("font size: biography", font_size_b);
        get_font();
        refresh_txt = true;
        get_b_text_array();
    }

    if (set_cycle && on_pic) {
        if (delta < 0) {cycle = cycle <= 0 ? 0 : cycle - 5;};
        if (delta > 0) {cycle = cycle >= 60 ? 60 : cycle + 5;};
        window.SetProperty("auto cycle (sec)", cycle);
        window.Repaint();
    }
}

function on_mouse_lbtn_down(x,y){
    if (on_text){
        on_text_down = true;
        delta_x = x - txt_x;
        delta_y = y - txt_y;
    }
    if (on_sb){
        on_sb_down = true;
        sb_posy = s_text * scrollbar_k;
        delta_y = sb_posy - y;
    }
}

function on_mouse_lbtn_up(x,y){
    window.SetProperty("txt_x", txt_x);
    window.SetProperty("txt_y", txt_y);
    on_text_down = false;
    on_sb_down = false;
}

function on_mouse_lbtn_dblclk (x,y){
    if (on_text){
        lang = lang == 1 ? 0 : 1;
        window.SetProperty("lang", lang);
        get_text();
    }

    if (on_pic){
        select_p_a = select_p_a == 1 ? 0 : 1;
        window.SetProperty("pictures/albums", select_p_a);
        get_pic();
    }
}

function on_mouse_leave() {
    window.SetCursor(32512);
    on_sb = false;
    window.Repaint();
}

function on_size(){
    ww = window.Width;   
    wh = window.Height;
   
    txt_x = window.GetProperty("txt_x");
    txt_y = window.GetProperty("txt_y");

    txt_x = txt_x >= ww - 50 && txt_x >= 0 ? ww - 50 : txt_x;
    txt_y = txt_y >= wh - (a_text_row_height + t_margin * 2) && txt_y >= 0 ? wh - (a_text_row_height + t_margin * 2) : txt_y;
   
    refresh_txt = true;
    get_b_text_array();
}

function del_folders(n){
    var dir = fso.GetFolder(tmp_b_path);
    var e = new Enumerator( dir.SubFolders );
    try {
        for(; !e.atEnd(); e.moveNext() ) {
            var name = e.item().Name;
            if (name.indexOf("_download") < 0){
                if (name.indexOf(n) < 0){
                    fso.deleteFolder(tmp_b_path + name, true);
                }
            }   
        }
    } catch(e) {};
}

function calc_img_size(img){
    if(!img) return;
    var size = {x:0, y:0, width:0, height:0, cx:0, cy:0, cwidth:0, cheight:0};

    switch(align_mode) {   
   case 0: // adjust      
        var sw = ww / img.Width;
        var sh = wh / img.Height;
        var s = Math.min(sw, sh);
       
        var x = 0;
        var y = 0;
       
        if (sw > sh) x = (ww - img.Width * s) / 2;
        else if (sw < sh) y = (wh - img.height * s) / 2;

        var width = img.Width * s;
        var height = img.Height * s;
        var cx = 0;
        var cy = 0;
        var cwidth = img.Width;
        var cheight = img.Height;
      break;
       
    case 1: // adjust top - center
        var sw = ww / img.Width;
        var sh = wh / img.Height;
        var s = Math.min(sw, sh);

        var x = 0;
        if (sw > sh) x = (ww - img.Width * s) / 2;
        var y = 0;
        var width = img.Width * s;
        var height = img.Height * s;
        var cx = 0;
        var cy = 0;
        var cwidth = img.Width;
        var cheight = img.Height;
      break;
       
    case 2: // adjust top - left
        var sw = ww / img.Width;
        var sh = wh / img.Height;
        var s = Math.min(sw, sh);
       
        var x = 0;
        var y = 0;
        var width = img.Width * s;
        var height = img.Height * s;
        var cx = 0;
        var cy = 0;
        var cwidth = img.Width;
        var cheight = img.Height;
      break;

   case 3: // centre   
      var sr = img.Width / img.Height;   
      var dr = ww / wh;   
      if (sr < dr) {   
         var r = img.Width / ww;
         var cheight = wh * r;
         var cy = Math.round((img.Height - cheight) / 2);
         var cwidth = img.Width;
         var cx = 0;
      } else {   
         var r = img.Height / wh;
         var cwidth = ww * r;
         var cx = Math.round((img.Width - cwidth) / 2);
         var cheight = img.Height;
         var cy = 0;
      }   
        var x = 0;         
        var y = 0;         
        var width = ww;         
        var height = wh;         
      break;   
       
   case 4: // centre - top      
      var sr = img.Width / img.Height;   
      var dr = ww / wh;   
      if (sr < dr) {   
         var r = img.Width / ww;
         var cheight = wh * r;
         var cy = 0;
         var cwidth = img.Width;
         var cx = 0;
      } else {   
         var r = img.Height / wh;
         var cwidth = ww * r;
         var cx = Math.round((img.Width - cwidth) / 2);
         var cheight = img.Height;
         var cy = 0;
      }
        var x = 0;
        var y = 0;
        var width = ww;
        var height = wh;
      break;   
       
   case 5: // stretch      
        var x = 0;
        var y = 0;
        var width = ww;
        var height = wh;
        var cx = 0;
        var cy = 0;
        var cwidth = img.Width;
        var cheight = img.Height;
      break;   
    }
   
    size.x = x + p_margin;
    size.y = y + p_margin;
    size.width = width - p_margin * 2;
    size.height = height - p_margin * 2;
    size.cx = cx;
    size.cy = cy;
    size.cwidth = cwidth;
    size.cheight = cheight;
   
    return size;
}

function copy_files(){
    var save_images_state = save_images;
    if (!save_images_state) save_images = true;

    var destination_path;
    var tmp_files = files;
    var tmp_artist = artist;
    var tmp_p_a = p_a[select_p_a];
    var tmp_directory_path;
   
    if (path.indexOf('://') > 0 || path.indexOf('youtube') == 0 || path.indexOf('cdda') == 0) {
        tmp_directory_path = fb.ProfilePath + tmp_p_a + "\\";
    } else {
        tmp_directory_path = directory_path + "\\" + tmp_p_a + "\\";
    }   
   
    var nl = "\" + chr(10) + \"";
    var input_box_text = "Copy  " + nl + nl + tmp_artist + " " + tmp_p_a + ".jpg" + nl + "files to";

    var string = input_box(input_box_text, tmp_directory_path, "Foobar 2000");

    if (string){
        destination_path = folder_exists(string);
        if (!destination_path) {
            copy_files();
        } else{
            copy_files_to_folder(destination_path, tmp_files, tmp_p_a);
        }
    }
    save_images = save_images_state;
}

function copy_files_to_folder(p, f, pa){
    if (p.length != "\\"){p = p + "\\"}
    for (i in f) {
        if (f[i].indexOf(pa) > 0){
            try {
                fso.CopyFile (f[i], p  , 1 );
            } catch(e) {}
        }
    }
}

function input_box(p_text, d_text, w_title){
    vbe = new ActiveXObject('ScriptControl');
    vbe.Language = 'VBScript';
    return vbe.eval( "InputBox(\"" + p_text + "\",\"" + w_title + "\",\"" + d_text + "\")");
}

function clean_path_name(n) {
    if (!n) return;
    return n.replace(/[\/\:\*\?\"\<\>\|]/g,'');
}

function folder_exists(n) {
    var driver = fso.GetDriveName(n);
    if (!fso.DriveExists(driver)) {
        return "";
    } else {
        var p = "";
        var split_string = [];
        split_string = n.replace(/\\$/g, "").split("\\");

        for (var i = 1; i < split_string.length; i += 1) {
            p = p + clean_path_name(split_string[i]) + "\\";
            try {
                if(!fso.FolderExists(driver + "\\" + p)) fso.CreateFolder(driver + "\\" + p);
            } catch(e) {};
        }
      return driver + "\\" + p;
    }
}

function on_notify_data(name, info) {
    if(name == "panel") {
        if (info == "bio"){
            panel_on = true;
            artist = "";
            on_metadb_changed();
        } else{
            panel_on =  false;
        }
    }
}

//var WshShell = WScript.CreateObject("WScript.Shell")
//WshShell.SendKeys("+{F10}");
kgena_ua
12.11.2016, 22:43
 
Раздел: Секреты foobar2000
Тема: Скрипты для foo_uie_wsh_panel_mod
Ответы: 2986
Просмотры: 573115

Re: Скрипты для foo_uie_wsh_panel_mod

seriousstas, значит это не у меня одного.

Думал, что это связано с моим Интернет соединением, запустил параллельно в сборке через прикрепляемую панель Biography от WilB - там картинки грузит все, когда сбоит скрипт WSH Biography Text & Picture Llast.fm.
MC Web
12.11.2016, 11:10
 
Раздел: Секреты foobar2000
Тема: Скрипты для foo_uie_wsh_panel_mod
Ответы: 2986
Просмотры: 573115

Re: Скрипты для foo_uie_wsh_panel_mod

kgena_ua, попался (хоть и редко) плейлист, не в кодировке UTF-8, при загрузке которого происходит сбой в работе скрипта WSH Biography Text & Picture Last.fm.

http://www.ex.ua/playlist/1217123.m3u
MC Web
07.11.2016, 21:11
 
Раздел: Секреты foobar2000
Тема: Скрипты для foo_uie_wsh_panel_mod
Ответы: 2986
Просмотры: 573115

Re: Скрипты для foo_uie_wsh_panel_mod

Вышла новая версия Biography 0.2 beta для JScript Panel 1.1.0+ от WilB:

Изображение

Еще бы не мусорил, цены бы ему не было...
MC Web
05.11.2016, 14:16
 
Раздел: Секреты foobar2000
Тема: Скрипты для foo_uie_wsh_panel_mod
Ответы: 2986
Просмотры: 573115

Re: Скрипты для foo_uie_wsh_panel_mod

kgena_ua
Автономно работающий скрипт
Плюсанул!
А я "гибрид" Biography Text && Picture
похоже допилил . Вчера скачал сам свой архив и понял что не работает авто переключение ..
Когда дедал совместимость с XP - сломал ..
Вобщем - сейчас у меня работает , как надо . (нашел время потестить нормально :oops: )
Добавил установку приоритета и для текста : Например - ставим Рус. Если есть - будет Рус иначе Eng
И наоборот . Тот-же принцип и для картинок .

Кто-то спрашивал ,где там фон шрифт менять (эти параметры) :
_Text Color
*_Background Color
font size: artist (delta)
font size: biography
font name: artist
font name: biography
seriousstas
03.11.2016, 22:23
 
Раздел: Секреты foobar2000
Тема: Скрипты для foo_uie_wsh_panel_mod
Ответы: 2986
Просмотры: 573115

Re: Скрипты для foo_uie_wsh_panel_mod

seriousstas, а что это utils.GetAlbumArtV2 ? То что не работает $replace в Display так это понятно, не понятно почему. Может на "гидрогене" спроси? Выше как раз задавал этот вопрос, причём такое условие как $meta_sep(name,sep) работает, значит меню Display условия понимает.

Добавлено спустя 6 минут 38 секунд:
В старой БИО все картинки подписаны так: Andre_Manoukian_0_images и условие B:\tmp_Biography\$meta_sep(%artist%,'_')*.* прекрасно ставит нижнее подчёркивание и при необходимости можно вывести картинку артиста в Cover Panel (опционально)
AHAPXICT
22.10.2016, 15:50
 
Раздел: Секреты foobar2000
Тема: Скрипты для foo_uie_wsh_panel_mod
Ответы: 2986
Просмотры: 573115
Пред.След.

Вернуться в: Скрипты для foo_uie_wsh_panel_mod