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

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

  • 3

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

Biography Text && Picture. www.last.fm
11042016


Реализована возможность копировать файлы.

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

Код: Выделить всё
// ==PREPROCESSOR==
// @name "Biography Text && Picture. www.last.fm"
// @author "kgena_ua"
// @version "11042016"
// @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;

var ww,wh;

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 = 10;
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);
}

get_color();

function on_colors_changed(){
    get_color();
}
*/
var bgcolor = RGB(31,41,48);
var a_color = RGB(220,220,220);
var b_color = RGB(255,255,230);

var transparent = 200;

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 nocover_path = window.GetProperty("nocover path",".\\nocover\\nocover.png");
var nocover = window.GetProperty("nocover image", false);
var nocover_transparent = window.GetProperty("nocover transparent (0-255)", 100);

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

var artist, old_artis;
var path, directory_path;

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

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

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

var g_img = null;
var p_margin = window.GetProperty("margin: picture", 10);
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 found = 0;
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", 5);
var on_pic = false;

var scrollbar = window.GetProperty("scrollbar", true);
var scrollbar_k;
var sb_posy = 0;
var on_sb = false;
var on_sb_down = false;

var t_margin = window.GetProperty("margin: text", 10);
var txt_x = window.GetProperty("txt_x", window.Width / 2);
var txt_y = window.GetProperty("txt_y", window.Height / 2);
var delta_x, delta_y;
var a_x, a_y;
var b_x, b_y;
var text = "";
var s_text = 0;
var old_string_width = 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 abc_lang = new Array("", "ru/");
var abc = window.GetProperty("abc", 0);
var if_not_found = new Array(". . .", ". . .");
var select_p_a = window.GetProperty("pictures/albums", 0);
var p_a = new Array("images", "albums");

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);
    paint(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";   
        set_cycle && gr.GdiDrawText("auto cycle \n" + txt_cycle, b_font, b_color, 15, 15, ww, wh, DT_LEFT | DT_WORD_ELLIPSIS );   
    } else{   
        gr.FillSolidRect(txt_x, txt_y, ww - txt_x, wh - txt_y, RGBA(getRed(bgcolor),getGreen(bgcolor),getBlue(bgcolor),transparent));   
    }   

    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) {}
    }

    scrollbar && draw_scrollbar(gr);
}

function paint(gr){
    if (g_img){
        var size = calc_img_size(g_img);
        gr.DrawImage(g_img, size.x, size.y, size.width, size.height, size.cx, size.cy, size.cwidth, size.cheight, 0, images.length > 0 ? fader : nocover_transparent);
    }
   
    if (logo_img && images.length == 0 && !nocover){
        gr.DrawImage(logo_img, p_margin, p_margin, logo_img.Width * 0.8, logo_img.Height * 0.8, 0, 0, logo_img.Width, logo_img.Height, 0, 255);   
    }

    if (images.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_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;
   
    gr.FillSolidRect(ww - 4, b_y + scrollbar_y, 2, scrollbar_h, a_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() : fb.TitleFormat("[" + field + "]").EvalWithMetadb(metadb);   
    //return fb.Titleformat("[" + field + "]").EvalWithMetadb(metadb) ? fb.TitleFormat("[" + field + "]").EvalWithMetadb(metadb) : fb.TitleFormat("[" + field + "]").Eval(true);   
}   

function on_metadb_changed() {
    if (!metadb) return;   
    artist = Eval("%artist%").replace(/^\s+|\s+$/g, "");
    if (artist != old_artis){
        if (!save_images) del_folders();
        s_text = 0;
        text = "";
        old_string_width = 0;
        get_b_text_array()       
        get_lastFM_b_text();
        //get_text();

        g_img = null;
        files = [];
        images = [];
        found = 0;
        selected = 0;
        get_pic();
        old_artis = artist;
    }
}   

function get_pic() {
    if (!artist) return;
   
    check_folder(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));
    }
}
var q, qq;
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 data2 = div.getElementsByTagName("div");
                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) {
                            urls.push(data[i].src.replace("avatar170s", "770x0"));
                        }     
                    }       
                    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", ""))
                        }     
                    }       
                }
                found = Math.min(urls.length, limit); window.Repaint();             
                for (i = 0; i < Math.min(urls.length, limit); i++) {     
                    file = "\"" + p + "\\" + clean_name(artist) + "_"  + i + "_" + p_a[select_p_a] + ".jpg" + "\"";     
                    WshShell.Run(vbs + " " + urls[i] + " " + file, false);
                }     
                doc.close();
                if (found > 0) get_files_if_loaded();
            }
        }     
    }     
}

function get_files_from_dir(p) {
    if (!artist) return;
    p = p + "\\";
    //files = [];
    images = [];
    files = utils.Glob(p + "*.*").toArray();
    for (i in files) {
        if (files[i].indexOf(clean_name(artist)) > 0 && files[i].indexOf(p_a[select_p_a]) > 0){
            try {
                images.push(get_images(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 get_images(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_lastFM_b_text(){
    xmlhttp2 = new ActiveXObject("Microsoft.XMLHTTP");
    url2 = ("http://www.last.fm/" + abc_lang[abc] + "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 == "") text = if_not_found[abc];
            old_string_width = 0;
            get_b_text_array();
            //save_biography_file(text);
        }
    }
}

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, 0);

    if (old_string_width != string_width){
        b_text_array = [];
        if (text) b_text_array = temp_gr.EstimateLineWrap(text, b_font, string_width).toArray();

        old_string_width = string_width;
    }
   
    b_text_rows = b_text_array.length / 2;

    b_text_visable_height = Math.round(Math.max(0, wh - t_margin - b_y));
    b_text_visable_rows = Math.round(b_text_visable_height / 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 on_mouse_rbtn_up (x, y){     
    var _menu = window.CreatePopupMenu();

    MF_ENABLED = 0x00000000;   
    MF_GRAYED = 0x00000001;   
    MF_SEPARATOR = 0x00000800;   
     
    _menu.AppendMenuItem(MF_ENABLED, 10, "EN text");   
    _menu.AppendMenuItem(MF_ENABLED, 11, "RU text");   
    _menu.CheckMenuRadioItem(10, 11, abc + 10);         
    _menu.EnableMenuItem(abc + 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);   
    var 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);

    var _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.CheckMenuRadioItem(20, 24, align_mode + 20);
    _firstgroup.EnableMenuItem(align_mode + 20, 1);
   
   
    var MF_ = images.length > 0 ? MF_ENABLED : MF_GRAYED;
    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
    _menu.AppendMenuItem(MF_, 30, "Copy to folder containing track...");
   
    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
    _menu.AppendMenuItem(MF_ENABLED, 40, "Save images");
    _menu.CheckMenuItem(40, save_images);

//    if (ShiftDown) {   
       //_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:
        abc = 0;
        window.SetProperty("abc", abc);
        s_text = 0;
        text = "";
        get_lastFM_b_text();
        break;
    case 11:
        abc = 1;
        window.SetProperty("abc", abc);
        s_text = 0;
        text = "";
        get_lastFM_b_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);
        g_img = null;
        files = [];
        images = [];
        found = 0;
        selected = 0;
        window.Repaint();
        get_pic();
        break;
    case 15:
        select_p_a = 1;
        window.SetProperty("pictures/albums", select_p_a);
        g_img = null;
        files = [];
        images = [];
        found = 0;
        selected = 0;
        window.Repaint();
        get_pic();
        break;
    case 16:
        WshShell.run("http://www.last.fm/" + abc_lang[abc] + "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:
        align_mode = ret - 20;
        window.SetProperty("align mode", align_mode);
        window.Repaint();
        break;
    case 30:
        copy_files();
        break;
    case 40:
        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;
var fff = 0;
function get_files_if_loaded(){
    fff = 0;
    timer && window.ClearInterval(timer);
    timer = window.SetInterval(function() {
        get_files_from_dir(artist_folder_path(artist));
        if (!g_img && images.length > 0) next_image(0);
       
        if (found > 0 && images.length == found && g_img) {
            window.ClearInterval(timer);     
        }
       
        fff = fff + 1;
        window.Repaint();
    }, 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){
            if (images.length > 1){
                next_image(1);
                window.Repaint();
                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();
    }, 10 );
}

function load_last_fm_logo(){
    if(!fso.FileExists(script_path + "last_fm_logo.jpg")) {
        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);
    }
}

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 < ww - 20 && y  >= txt_y ? true : false;
    on_sb =  x > ww - 20 && y  >= txt_y ? true : false;
    on_pic = !on_text && !on_sb ? true : false;
   
    //if (on_pic && c_selected == selected){ //****
    //    delay = true; //****
    //    fdelay(); //****
    //    if (x > pic_posx) next_image(1); //****
    //    if (x < pic_posx) next_image(-1); //****
    //    if (cycle > 0) step = 0; //****
    //} //****
   
    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();
    }
}

function on_mouse_wheel(delta) {
    ShiftDown = utils.IsKeyPressed(0x10) ? true : false;
   
    if (on_pic && !ShiftDown && !delay && images.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}
        }
    }
   
    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();
        old_string_width = 0;
        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();
}

//var pic_posx = 0; //****
//var c_selected; //****

function on_mouse_lbtn_down(x,y){
    //on_text = x >= txt_x && x < ww  && y >= txt_y && y <= b_y ? true : false; //****
    //on_sb = x >= txt_x && x < ww && y >= b_y ? true : false; //****
    //on_pic = !on_text && !on_sb ? true : false; //****
   
    //if (on_pic){ //****
    //    pic_posx = x; //****
    //    c_selected = selected; //****
    //} //****
   
    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;
   
    //on_pic = false; //****
}

function on_mouse_lbtn_dblclk (x,y){
    if (on_text){
        abc = abc == 1 ? 0 : 1;
        window.SetProperty("abc", abc);
        s_text = 0;
        b_text_array = [];
        text = "";
        get_lastFM_b_text();
    }
   
    try {
        if (on_pic && images[selected]) WshShell.run( '"' + artist_folder_path(artist)+ "\\" + clean_name(artist) + "_"  + selected + "_" + p_a[select_p_a] + ".jpg" + '"' );
    } catch(e) {}
}

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

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;
   
    get_b_text_array();
}

function del_folders(){
    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(clean_name(artist)) < 0){
                    fso.deleteFolder(tmp_b_path + name);
                }
            }   
        }
    } catch(e) {};
}

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 copy_files(){
    var save_images_state = save_images;
    if (!save_images_state) save_images = true;

    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 + nl + "files to";

    var destination_folder = input_box(input_box_text, tmp_directory_path, "Copy files...");

    if (destination_folder){
        destination_folder = clean_path_name(destination_folder);
        ppp = destination_folder;   
        folder_exists(destination_folder);
        copy_files_to_folder(destination_folder, 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) {
    return n.replace(/[\/\*\?\"\<\>\|]/g,'');
}

function folder_exists(n) {
    if (n.length != "\\"){n = n + "\\"}
    for (var i = 3; i < n.length; i += 1) {
        if (n[i] == "\\"){
            if(!fso.FolderExists(n.substr(0, i))) {fso.CreateFolder(n.substr(0, i))};
        }
    }
}
kgena_ua
11.04.2016, 16:12
 
Раздел: Секреты foobar2000
Тема: Скрипты для foo_uie_wsh_panel_mod
Ответы: 2986
Просмотры: 572835

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

kgena_ua
Biography Text && Picture. www.last.fm
version "09042016
Спасибо большое за труды :beer: это как раз то чего так не хватало :dance: .
Теперь скрипты Марка можно смело удалить.
duzzy
09.04.2016, 23:52
 
Раздел: Секреты foobar2000
Тема: Скрипты для foo_uie_wsh_panel_mod
Ответы: 2986
Просмотры: 572835
  • 2

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

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


Изменения:
- добавлен пункт меню выровнять;
- исправления.
Безымянный.png

Код: Выделить всё
// ==PREPROCESSOR==
// @name "Biography Text && Picture. www.last.fm"
// @author "kgena_ua"
// @version "09042016"
// @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;

var ww,wh;

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 = 10;
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);
}

get_color();

function on_colors_changed(){
    get_color();
}
*/
var bgcolor = RGB(31,41,48);
var a_color = RGB(220,220,220);
var b_color = RGB(255,255,230);

var transparent = 200;

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 nocover_path = window.GetProperty("nocover path",".\\nocover\\nocover.png");
var nocover = window.GetProperty("nocover image", false);
var nocover_transparent = window.GetProperty("nocover transparent (0-255)", 100);

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

var artist, old_artis;

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

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

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

var g_img = null;
var p_margin = window.GetProperty("margin: picture", 10);
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 found = 0;
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", 5);
var on_pic = false;

var scrollbar = window.GetProperty("scrollbar", true);
var scrollbar_k;
var sb_posy = 0;
var on_sb = false;
var on_sb_down = false;

var t_margin = window.GetProperty("margin: text", 10);
var txt_x = window.GetProperty("txt_x", window.Width / 2);
var txt_y = window.GetProperty("txt_y", window.Height / 2);
var delta_x, delta_y;
var a_x, a_y;
var b_x, b_y;
var text = "";
var s_text = 0;
var old_string_width = 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 abc_lang = new Array("", "ru/");
var abc = window.GetProperty("abc", 0);
var if_not_found = new Array(". . .", ". . .");
var select_p_a = window.GetProperty("pictures/albums", 0);
var p_a = new Array("images", "albums");

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);
    paint(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";   
        set_cycle && gr.GdiDrawText("auto cycle \n" + txt_cycle, b_font, b_color, 15, 15, ww, wh, DT_LEFT | DT_WORD_ELLIPSIS );   
    } else{   
        gr.FillSolidRect(txt_x, txt_y, ww - txt_x, wh - txt_y, RGBA(getRed(bgcolor),getGreen(bgcolor),getBlue(bgcolor),transparent));   
    }   

    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) {}
    }

    scrollbar && draw_scrollbar(gr);
}

function paint(gr){
    if (g_img){
        var size = calc_img_size(g_img);
        gr.DrawImage(g_img, size.x, size.y, size.width, size.height, size.cx, size.cy, size.cwidth, size.cheight, 0, images.length > 0 ? fader : nocover_transparent);
    }
   
    if (logo_img && images.length == 0 && !nocover){
        gr.DrawImage(logo_img, p_margin, p_margin, logo_img.Width * 0.8, logo_img.Height * 0.8, 0, 0, logo_img.Width, logo_img.Height, 0, 255);   
    }

    if (images.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_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;
   
    gr.FillSolidRect(ww - 4, b_y + scrollbar_y, 2, scrollbar_h, a_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);   
    return path.indexOf('://') > 0 ? fb.TitleFormat("[" + field + "]").Eval() : fb.TitleFormat("[" + field + "]").EvalWithMetadb(metadb);   
    //return fb.Titleformat("[" + field + "]").EvalWithMetadb(metadb) ? fb.TitleFormat("[" + field + "]").EvalWithMetadb(metadb) : fb.TitleFormat("[" + field + "]").Eval(true);   
}   

function on_metadb_changed() {
    if (!metadb) return;   
    artist = Eval("%artist%").replace(/^\s+|\s+$/g, "");
    if (artist != old_artis){
        if (!save_images) del_folders();
        s_text = 0;
        text = "";
        old_string_width = 0;
        get_b_text_array()       
        get_lastFM_b_text();
        //get_text();

        g_img = null;
        files = [];
        images = [];
        found = 0;
        selected = 0;
        get_pic();
        old_artis = artist;
    }
}   

function get_pic() {
    if (!artist) return;
   
    check_folder(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));
    }
}
var q, qq;
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 data2 = div.getElementsByTagName("div");
                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) {
                            urls.push(data[i].src.replace("avatar170s", "770x0"));
                        }     
                    }       
                    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", ""))
                        }     
                    }       
                }
                found = Math.min(urls.length, limit); window.Repaint();             
                for (i = 0; i < Math.min(urls.length, limit); i++) {     
                    file = "\"" + p + "\\" + clean_name(artist) + "_"  + i + "_" + p_a[select_p_a] + ".jpg" + "\"";     
                    WshShell.Run(vbs + " " + urls[i] + " " + file, false);
                }     
                doc.close();
                if (found > 0) get_files_if_loaded();
            }
        }     
    }     
}

function get_files_from_dir(p) {
    if (!artist) return;
    p = p + "\\";
    images = [];
    files = utils.Glob(p + "*.*").toArray();
    for (i in files) {
        if (files[i].indexOf(clean_name(artist)) > 0 && files[i].indexOf(p_a[select_p_a]) > 0){
            try {
                images.push(get_images(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 get_images(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_lastFM_b_text(){
    xmlhttp2 = new ActiveXObject("Microsoft.XMLHTTP");
    url2 = ("http://www.last.fm/" + abc_lang[abc] + "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 == "") text = if_not_found[abc];
            old_string_width = 0;
            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, 0);

    if (old_string_width != string_width){
        b_text_array = [];
        if (text) b_text_array = temp_gr.EstimateLineWrap(text, b_font, string_width).toArray();

        old_string_width = string_width;
    }
   
    b_text_rows = b_text_array.length / 2;

    b_text_visable_height = Math.round(Math.max(0, wh - t_margin - b_y));
    b_text_visable_rows = Math.round(b_text_visable_height / 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 on_mouse_rbtn_up (x, y){     
    var _menu = window.CreatePopupMenu();

    MF_ENABLED = 0x00000000;   
    MF_GRAYED = 0x00000001;   
    MF_SEPARATOR = 0x00000800;   
     
    _menu.AppendMenuItem(MF_ENABLED, 10, "EN text");   
    _menu.AppendMenuItem(MF_ENABLED, 11, "RU text");   
    _menu.CheckMenuRadioItem(10, 11, abc + 10);         
    _menu.EnableMenuItem(abc + 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);   
    var 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);

    var _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.CheckMenuRadioItem(20, 24, align_mode + 20);
    _firstgroup.EnableMenuItem(align_mode + 20, 1);
   
    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
    _menu.AppendMenuItem(MF_GRAYED, 30, "Copy to folder containing track...");
   
    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
    _menu.AppendMenuItem(MF_ENABLED, 40, "Save images");
    _menu.CheckMenuItem(40, save_images);

//    if (ShiftDown) {   
        _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:
        abc = 0;
        window.SetProperty("abc", abc);
        s_text = 0;
        text = "";
        get_lastFM_b_text();
        break;
    case 11:
        abc = 1;
        window.SetProperty("abc", abc);
        s_text = 0;
        text = "";
        get_lastFM_b_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);
        g_img = null;
        files = [];
        images = [];
        found = 0;
        selected = 0;
        window.Repaint();
        get_pic();
        break;
    case 15:
        select_p_a = 1;
        window.SetProperty("pictures/albums", select_p_a);
        g_img = null;
        files = [];
        images = [];
        found = 0;
        selected = 0;
        window.Repaint();
        get_pic();
        break;
    case 16:
        WshShell.run("http://www.last.fm/" + abc_lang[abc] + "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:
        align_mode = ret - 20;
        window.SetProperty("align mode", align_mode);
        window.Repaint();
        break;
    case 40:
        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;
var fff = 0;
function get_files_if_loaded(){
    fff = 0;
    timer && window.ClearInterval(timer);
    timer = window.SetInterval(function() {
        get_files_from_dir(artist_folder_path(artist));
        if (!g_img && images.length > 0) next_image(0);
       
        if (found > 0 && images.length == found) {
            window.ClearInterval(timer);     
        }
       
        fff = fff + 1;
        window.Repaint();
    }, 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){
            if (images.length > 1){
                next_image(1);
                window.Repaint();
                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();
    }, 10 );
}

function load_last_fm_logo(){
    if(!fso.FileExists(script_path + "last_fm_logo.jpg")) {
        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);
    }
}

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 < ww - 20 && y  >= txt_y ? true : false;
    on_sb =  x > ww - 20 && y  >= txt_y ? true : false;
    on_pic = !on_text && !on_sb ? true : false;
   
    //if (on_pic && c_selected == selected){ //****
    //    delay = true; //****
    //    fdelay(); //****
    //    if (x > pic_posx) next_image(1); //****
    //    if (x < pic_posx) next_image(-1); //****
    //    if (cycle > 0) step = 0; //****
    //} //****
   
    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();
    }
}

function on_mouse_wheel(delta) {
    ShiftDown = utils.IsKeyPressed(0x10) ? true : false;
   
    if (on_pic && !ShiftDown && !delay && images.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}
        }
    }
   
    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();
        old_string_width = 0;
        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();
}

//var pic_posx = 0; //****
//var c_selected; //****

function on_mouse_lbtn_down(x,y){
    //on_text = x >= txt_x && x < ww  && y >= txt_y && y <= b_y ? true : false; //****
    //on_sb = x >= txt_x && x < ww && y >= b_y ? true : false; //****
    //on_pic = !on_text && !on_sb ? true : false; //****
   
    //if (on_pic){ //****
    //    pic_posx = x; //****
    //    c_selected = selected; //****
    //} //****
   
    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;
   
    //on_pic = false; //****
}

function on_mouse_lbtn_dblclk (x,y){
    if (on_text){
        abc = abc == 1 ? 0 : 1;
        window.SetProperty("abc", abc);
        s_text = 0;
        b_text_array = [];
        text = "";
        get_lastFM_b_text();
    }
   
    try {
        if (on_pic && images[selected]) WshShell.run( '"' + artist_folder_path(artist)+ "\\" + clean_name(artist) + "_"  + selected + "_" + p_a[select_p_a] + ".jpg" + '"' );
    } catch(e) {}
}

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

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;
   
    get_b_text_array();
}

function del_folders(){
    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(clean_name(artist)) < 0){
                    fso.deleteFolder(tmp_b_path + name);
                }
            }   
        }
    } catch(e) {};
}

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;
}
kgena_ua
09.04.2016, 21:36
 
Раздел: Секреты foobar2000
Тема: Скрипты для foo_uie_wsh_panel_mod
Ответы: 2986
Просмотры: 572835

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

kgena_ua, предложение по скрипту WSH Biography Text & Picture Last.fm:
- Возможность сохранения изображений не только скопом в одной папке в качестве кэша, но и возможность сохранения, при необходимости, в папке / теге файлов
- Контекстное меню Сохранить изображение как в зависимости от выбранного режима отображения Фото исполнителя / Обложка альбома сохраняет в папке / теге соответственно artist / front (cover).

Последний скрипт (из ЛС) вроде работает нормально...
MC Web
09.04.2016, 14:16
 
Раздел: Секреты foobar2000
Тема: Скрипты для foo_uie_wsh_panel_mod
Ответы: 2986
Просмотры: 572835

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

в папку tmp_Biography/Album/группа/название альбома/фото.jpg
А что насчет фото чтобы на всю панель растягивалась.
mans
07.04.2016, 21:04
 
Раздел: Секреты foobar2000
Тема: Скрипты для foo_uie_wsh_panel_mod
Ответы: 2986
Просмотры: 572835

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

mans:фото он сохраняет, а текст он сохраняет?
Ну куда теперь деваться. Раз появилась возможность сохранять изображения ....
mans:фото альбомов скачивал в отдельную папку
В какую.
На данный момент все скачивается в:
папка tmp_Biography - папка "artist".
Как нужно.
kgena_ua
07.04.2016, 20:53
 
Раздел: Секреты foobar2000
Тема: Скрипты для foo_uie_wsh_panel_mod
Ответы: 2986
Просмотры: 572835
  • 1

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

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


Только сделал. Особо не тестировал.

Изменения:
- добавлен пункт меню "Fade effect";
- добавлен пункт меню "Save images". Изображения сохраняются в папке tmp_Biography. При выборе исполнителя, для которого были загружены изображения, скачивание картинок не производится.

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


Код: Выделить всё
// ==PREPROCESSOR==
// @name "Biography Text && Picture. www.last.fm"
// @author "kgena_ua"
// @version "07042016"
// @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;

var ww,wh;

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 = 10;
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);
}

get_color();

function on_colors_changed(){
    get_color();
}
*/
var bgcolor = RGB(31,41,48);
var a_color = RGB(220,220,220);
var b_color = RGB(255,255,230);

var transparent = 200;

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 nocover_path = window.GetProperty("nocover path",".\\nocover\\nocover.png");
var nocover = window.GetProperty("nocover image", false);
var nocover_transparent = window.GetProperty("nocover transparent (0-255)", 100);

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

var artist, old_artis;

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

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

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

var g_img = null;
var p_margin = window.GetProperty("margin: picture", 10);
var selected = 0;
var files = [];
var images = [];
var loaded = 0;
var save_images = window.GetProperty("save images", false);
var limit = window.GetProperty("download limit",5);
var cycle = window.GetProperty("auto cycle (sec)", 0);
var fader = 255;
var fade_effect = window.GetProperty("fade effect", false);
var fade_step = window.GetProperty("fade step", 5);
var on_pic = false;

var scrollbar = window.GetProperty("scrollbar", true);
var scrollbar_k;
var sb_posy = 0;
var on_sb = false;
var on_sb_down = false;

var t_margin = window.GetProperty("margin: text", 10);
var txt_x = window.GetProperty("txt_x", window.Width / 2);
var txt_y = window.GetProperty("txt_y", window.Height / 2);
var delta_x, delta_y;
var a_x, a_y;
var b_x, b_y;
var text = "";
var s_text = 0;
var old_string_width = 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 abc_lang = new Array("", "ru/");
var abc = window.GetProperty("abc", 0);
var if_not_found = new Array(". . .", ". . .");
var select_p_a = window.GetProperty("pictures/albums", 0);
var p_a = new Array("images", "albums");

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);
    paint(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";   
        set_cycle && gr.GdiDrawText("auto cycle \n" + txt_cycle, b_font, b_color, 15, 15, ww, wh, DT_LEFT | DT_WORD_ELLIPSIS );   
    } else{   
        gr.FillSolidRect(txt_x, txt_y, ww - txt_x, wh - txt_y, RGBA(getRed(bgcolor),getGreen(bgcolor),getBlue(bgcolor),transparent));   
    }   

    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) {}
    }

    scrollbar && draw_scrollbar(gr);

    gr.GdiDrawText( "", gdi.Font("Arial",12, 0), b_color, 15, 0, ww, wh, DT_LEFT | DT_WORD_ELLIPSIS );
    gr.GdiDrawText( "", gdi.Font("Arial",12, 0), b_color, 15, 20, ww, wh, DT_LEFT | DT_WORD_ELLIPSIS );

}

function paint(gr){
    if (g_img){
        var scale_w = (ww - p_margin * 2) / g_img.Width;
        var scale_h = (wh - p_margin * 2) / g_img.Height;
        var scale = Math.min(scale_w, scale_h);
        gr.DrawImage(g_img, p_margin, p_margin, g_img.Width * scale, g_img.Height * scale, 0, 0, g_img.Width, g_img.Height, 0, images.length > 0 ? fader : nocover_transparent);
    }
   
    if (logo_img && images.length == 0 && !nocover){
        gr.DrawImage(logo_img, p_margin, p_margin, logo_img.Width * 0.8, logo_img.Height * 0.8, 0, 0, logo_img.Width, logo_img.Height, 0, 255);   
    }

    if (images.length == 0 && nocover){
        try {
            nc_img = gdi.Image(nocover_path);
            var scale_w = (ww - p_margin * 2) / nc_img.Width;
            var scale_h = (wh - p_margin * 2) / nc_img.Height;
            var scale = Math.min(scale_w, scale_h);
            gr.DrawImage(nc_img, p_margin, p_margin, nc_img.Width * scale, nc_img.Height * scale, 0, 0, nc_img.Width, nc_img.Height, 0, nocover_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;
   
    gr.FillSolidRect(ww - 4, b_y + scrollbar_y, 2, scrollbar_h, a_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);   
    return path.indexOf('://') > 0 ? fb.TitleFormat("[" + field + "]").Eval() : fb.TitleFormat("[" + field + "]").EvalWithMetadb(metadb);   
    //return fb.Titleformat("[" + field + "]").EvalWithMetadb(metadb) ? fb.TitleFormat("[" + field + "]").EvalWithMetadb(metadb) : fb.TitleFormat("[" + field + "]").Eval(true);   
}   

function on_metadb_changed() {
    if (!metadb) return;   
    artist = Eval("%artist%").replace(/^\s+|\s+$/g, "");
    if (artist != old_artis){
        s_text = 0;
        text = "";
        old_string_width = 0;
        get_b_text_array()       
        get_lastFM_b_text();

        g_img = null;
        files = [];
        images = [];
        selected = 0;
        if (!save_images) del_folders();
        get_pic();
        old_artis = artist;
    }
}   

function get_pic() {
    if (!artist) return;
   
    check_folder(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));
        load();
    }
}

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) {
                            urls.push(data[i].src.replace("avatar170s", "770x0"));
                        }     
                    }       
                    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", ""))
                        }     
                    }       
                }
                loaded = Math.min(urls.length, limit);;               
                for (i = 0; i < Math.min(urls.length, limit); i++) {     
                    file = "\"" + p + "\\" + clean_name(artist) + "_"  + i + "_" + p_a[select_p_a] + ".jpg" + "\"";     
                    WshShell.Run(vbs + " " + urls[i] + " " + file, false);
                }     
              doc.close();
            }
        }     
    }     
}

function get_files_from_dir(p) {
    if (!artist) return;
    p = p + "\\";
    files = [];
    images = [];
    files = utils.Glob(p + "*.*").toArray();
    for (i in files) {
        if (files[i].indexOf(clean_name(artist)) > 0 && files[i].indexOf(p_a[select_p_a]) > 0){
            try {
                images.push(get_images(gdi.Image(files[i])));
            } catch(e) {}
        }
    }
   
   /* try {
        var e = new Enumerator( fso.GetFolder(p).Files );
        for ( ; !e.atEnd(); e.moveNext() ) {
            var name = e.item().Name;
            if (name.indexOf(clean_name(artist)) == 0 && name.indexOf(p_a[select_p_a]) > 0){
                if(fso.FileExists(p + name)){
                    files.push(p + name);
                    images.push(get_images(gdi.Image(p + name)));
                }
            }
        }
    } 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 get_images(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_lastFM_b_text(){
    xmlhttp2 = new ActiveXObject("Microsoft.XMLHTTP");
    url2 = ("http://www.last.fm/" + abc_lang[abc] + "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 == "") text = if_not_found[abc];
            old_string_width = 0;
            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, 0);

    if (old_string_width != string_width){
        b_text_array = [];
        if (text) b_text_array = temp_gr.EstimateLineWrap(text, b_font, string_width).toArray();

        old_string_width = string_width;
    }
   
    b_text_rows = b_text_array.length / 2;

    b_text_visable_height = Math.round(Math.max(0, wh - t_margin - b_y));
    b_text_visable_rows = Math.round(b_text_visable_height / 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 on_mouse_rbtn_up (x, y){     
    var _menu = window.CreatePopupMenu();
    var i = 1;

    MF_ENABLED = 0x00000000;   
    MF_GRAYED = 0x00000001;   
    MF_SEPARATOR = 0x00000800;   
     
    _menu.AppendMenuItem(MF_ENABLED, i++, "EN text");   
    _menu.AppendMenuItem(MF_ENABLED, i++, "RU text");   
    _menu.CheckMenuRadioItem(1, i, abc + 1);         
    _menu.EnableMenuItem(abc + 1, 1);     

    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);   
       
    _menu.AppendMenuItem(MF_ENABLED, i++, "Prefer now playing");   
    _menu.AppendMenuItem(MF_ENABLED, i++, "Follow selected track");   
    _menu.CheckMenuRadioItem(i - 2, i , selection_mode + 3);   
   _menu.EnableMenuItem(selection_mode + 3, 1);
       
    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);   
    _menu.AppendMenuItem(MF_ENABLED, i++, "Artist pictures");   
    _menu.AppendMenuItem(MF_ENABLED, i++, "Albums pictures");   
    _menu.CheckMenuRadioItem(i - 2, i , select_p_a + 5);   
   _menu.EnableMenuItem(select_p_a + 5, 1);

    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);   
    var is_artist = artist ? MF_ENABLED : MF_GRAYED;   
    _menu.AppendMenuItem(is_artist, i++, "last.fm Artist");   
   
    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
    _menu.AppendMenuItem(MF_ENABLED, i++, "Fade effect");
    _menu.CheckMenuItem(i - 1, fade_effect);
   
    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
    _menu.AppendMenuItem(MF_ENABLED, i++, "Save images");
    _menu.CheckMenuItem(i - 1, save_images);
     
//    if (ShiftDown) {   
        _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);   
        _menu.AppendMenuItem(MF_ENABLED, 10, "Reload");   
        _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);   
        _menu.AppendMenuItem(MF_ENABLED, 20, "Properties");   
        _menu.AppendMenuItem(MF_ENABLED, 30, "Configure ...");
//    }

    ret = _menu.TrackPopupMenu(x,y);

    switch (ret) {
    case 1:
        abc = 0;
        window.SetProperty("abc", abc);
        s_text = 0;
        text = "";
        get_lastFM_b_text();
        break;
    case 2:
        abc = 1;
        window.SetProperty("abc", abc);
        s_text = 0;
        text = "";
        get_lastFM_b_text();
        break;
    case 3:
        selection_mode = 0;
        window.SetProperty("selection mode", selection_mode);
        on_item_focus_change();
        break;
    case 4:
        selection_mode = 1;
        window.SetProperty("selection mode", selection_mode);
        on_item_focus_change();
        break;
    case 5:
        select_p_a = 0;
        window.SetProperty("pictures/albums", select_p_a);
        images = [];
        loaded = 0;
        g_img = null;
        selected = 0;
        window.Repaint();
        get_pic();
        break;
    case 6:
        select_p_a = 1;
        window.SetProperty("pictures/albums", select_p_a);
        images = [];
        loaded = 0;
        g_img = null;
        selected = 0;
        window.Repaint();
        get_pic();
        break;
    case 7:
        WshShell.run("http://www.last.fm/" + abc_lang[abc] + "music/" + encodeURIComponent(artist));
        break;
    case 8:
        window.SetProperty("fade effect", !fade_effect);
        fade_effect = window.GetProperty("fade effect");
        break;
    case 9:
        window.SetProperty("Save images", !save_images);
        save_images = window.GetProperty("Save images");
        break;
    case 10:
        window.Reload();
        break;
    case 20:
        window.ShowProperties();
        break;   
    case 30:
        window.ShowConfigure();   
        break;   
   }
    _menu.Dispose();   
    return true;   
}   

//var timer = window.SetInterval(on_timer, 1000);
var timer;

function load(){
    timer && window.ClearInterval(timer);
    timer = window.SetInterval(function() {
        get_files_from_dir(artist_folder_path(artist));
        if (!g_img && images.length > 0) next_image(0);
       
        if (images.length == loaded && g_img) {
            window.ClearInterval(timer);     
        }
    }, 500 );
}
/*
function on_timer(id){
    if (images.length < loaded) {
        get_files_from_dir(artist_folder_path(artist));
        if (!g_img && images.length > 0) next_image(0);
    }
   
    step =  set_cycle || cycle == 0 ? 0 : step + 1;
    if (cycle > 0 && step >= cycle){
        if (images.length > 1){
            next_image(1);
            window.Repaint();
            step = 0;
        }
    }
}
*/

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){
            if (images.length > 1){
                next_image(1);
                window.Repaint();
                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();
    }, 10 );
}

function del_folders(){
    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){
                fso.deleteFolder(tmp_b_path + name);
            }   
        }
    } catch(e) {};
}

function load_last_fm_logo(){
    if(!fso.FileExists(script_path + "last_fm_logo.jpg")) {
        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);
    }
}

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 < ww - 20 && y  >= txt_y ? true : false;
    on_sb =  x > ww - 20 && y  >= txt_y ? true : false;
    on_pic = !on_text && !on_sb ? true : false;
   
   // if (on_pic && c_selected == selected){ //****
   //     fader = fade_effect && images.length > 1 ? 0 : 255; //****
   //     if (x > pic_posx) {selected = selected >= images.length - 1 ? 0 : selected = selected + 1}; //****
   //     if (x < pic_posx) {selected = selected <= 0 ? images.length - 1 : selected = selected - 1}; //****
   //     g_img = images[selected]; //****
   //      if (g_img && images.length > 1 && fade_effect) fader_timer(); //****
   //     window.Repaint(); //****
   // } //****
   
    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();
    }
}

function on_mouse_wheel(delta) {
    ShiftDown = utils.IsKeyPressed(0x10) ? true : false;
   
    if (on_pic && !ShiftDown && !delay && images.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}
        }
    }
   
    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();
        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();
}

//var pic_posx = 0; //****
//var c_selected; //****

function on_mouse_lbtn_down(x,y){
    //on_text = x >= txt_x && x < ww  && y >= txt_y && y <= b_y ? true : false; //****
    //on_sb = x >= txt_x && x < ww && y >= b_y ? true : false; //****
    //on_pic = !on_text && !on_sb ? true : false; //****
   
    //if (on_pic){ //****
    //    pic_posx = x; //****
    //    c_selected = selected; //****
   // }
    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;
   
    //on_pic = false; //****
}

function on_mouse_lbtn_dblclk (x,y){
    if (on_text){
        abc = abc == 1 ? 0 : 1;
        window.SetProperty("abc", abc);
        s_text = 0;
        b_text_array = [];
        text = "";
        get_lastFM_b_text();
    }
   
    try {
        if (on_pic && files[selected]) WshShell.run( '"' + files[selected] + '"' );
    } catch(e) {}
}

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

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;
   
    get_b_text_array();
}


 
kgena_ua
07.04.2016, 16:44
 
Раздел: Секреты foobar2000
Тема: Скрипты для foo_uie_wsh_panel_mod
Ответы: 2986
Просмотры: 572835

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

И еще просьба к Kgena_ua, сделайте в вашем скрипте (может быть как опцию) возможность сохранять фото как в марковском скрипте.
mans
No_mad

Если заремить удаление, то фото будут просто накапливаться в tmp_Biography . В скрипте есть проверка на наличие уже скачанного , соответственно , перезаписи (перезагрузки) не будет . Далее , есть несколько способов - либо чистить ручками, либо на двойной клик , либо сделать(отдельную)кнопку закрытия Фубара и повесить function del_files_from_dir() .
Можно и добавить накапливание (вкл-выкл) в контекстное меню ..

Где заремить (// fso.deleteFile(tmp_b_path + name );):
Код: Выделить всё
function del_files_from_dir() {
    var del_files = [];
    var e = new Enumerator( fso.GetFolder(tmp_b_path).Files );
    while ( !e.atEnd() ) {
        var name = e.item().Name;
        try {
            //fso.deleteFile(tmp_b_path + name );
        } catch(e) {};
        e.moveNext();
    }
}

Так-же есть для WSH такой марковский вариант (звезд не наблюдаю - содержимое тегов + фоновая картинка ):
/viewtopic.php?p=60349#p60349
Недавно , ещё повесил кнопку вкл-выкл миниатюр снизу - если нужно - заверну ..

Добавлено спустя 21 минуту 45 секунд:
Еще на днях доделал это слайдшоу на весь экран :
/viewtopic.php?p=60444#p60444
Сделал так :
Запуск - через AHK по двойному клику по картинке от kgena_ua . Далее (что-бы шоу продолжало крутится)- бросаю логотип с расширением и названием например Last.png .
А удаление - по расширению создаваемых картинок - jpg :
Код: Выделить всё
function del_files_from_dir() {
   
    var del_files = [];
    var e = new Enumerator( fso.GetFolder(tmp_b_path).Files );
    while ( !e.atEnd() ) {
        var name = e.item().Name;
      if (name.match(/(jpg|jpeg|gif)$/i)) {
        try {
           fso.deleteFile(tmp_b_path + name );
        } catch(e) {};
        }
        e.moveNext();
    }
}
Теперь шоу будет бесконечо , а при отсутствии картинок - Last.png или что-либо ещё
seriousstas
04.04.2016, 23:36
 
Раздел: Секреты foobar2000
Тема: Скрипты для foo_uie_wsh_panel_mod
Ответы: 2986
Просмотры: 572835

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

Скрипт от kgena_ua этого не делает, стало быть либо пользуется другим протоколом, либо вообще скачивает с другого адреса. Все осложняется тем, что скрипты от marc2003 практически недоступны анализу, слишком мудрено. Пользуйтесь скриптом от kgena_ua - есть надежда, что опции "сохранить как", "сохранить в папку трека", "сохранить в подпапку "Covers"" в нем вскоре появятся, пока можете руками из открытой папки tmp_Biography укомплектовать свои записи картинками.
No_mad
04.04.2016, 16:14
 
Раздел: Секреты foobar2000
Тема: Скрипты для foo_uie_wsh_panel_mod
Ответы: 2986
Просмотры: 572835

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

No_mad, эту идею уже высказывал, сам так хочу сделать, но пока отложил эту затею))). Я понимаю что вам нужно. Такая возможность есть в стандартном плагине foo_uie_biography, там такую операцию можно настроить для автоматического или ручного сохранения альбома или артиста в папку с музыкой. Раньше от лени так и делал, тогда картинки были как правило 500х500, а сейчас 300х300))) Если вы не имеете опыта для редактирования скриптов, то это сложно реализовать самому.

Добавлено спустя 3 часа 3 минуты:
seriousstas, в сети?

Добавлено спустя 17 минут 27 секунд:
Я понял как стандартную программу просмотра изображений заставить работать без перебоев))) Ну это потом.
AHAPXICT
27.03.2016, 01:12
 
Раздел: Секреты foobar2000
Тема: Скрипты для foo_uie_wsh_panel_mod
Ответы: 2986
Просмотры: 572835

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

kgena_ua, просьба по скрипту "Biography Text && Picture. www.last.fm"
Как ввести в контекстное меню пункт "дублировать изображение в папку трека" и защиту от краша, если это радио или СД
ну, типа (просто для примера, не на языке WSH, т.к. не владею :)
copy to... ;
else ()
No_mad
27.03.2016, 00:49
 
Раздел: Секреты foobar2000
Тема: Скрипты для foo_uie_wsh_panel_mod
Ответы: 2986
Просмотры: 572835

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

kgena_ua, приветствую.

Столкнулся с одной "проблемой" при работе скрипта WSH Biography Text & Picture Last.fm, возможно кому то тоже попадалась.
Решил послушать альбомы In-Grid с EX.UA, на одном не хочет выводить ни фото ни биографию. Сначала думал загвоздка в "тире", тогда почему на других работает? Оказалось перед именем исполнителя стоит пробел, вроде не заметно, а не работает и сам никак не исправишь.

Возможно внести коррективы в работу скрипта для подобных случаев?
MC Web
26.03.2016, 18:19
 
Раздел: Секреты foobar2000
Тема: Скрипты для foo_uie_wsh_panel_mod
Ответы: 2986
Просмотры: 572835

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

AHAPXICT:После переключения c БИО на другую панель (PSS) скрипт VBScript продолжает работать, то есть качает картинки - удаляет картинки. Вот я и поставил вопрос подобным образом
Тут есть свои плюсы и минусы, если говорим про скрипт WSH Biography Text & Picture last.fm от kgena_ua, тем более если обещают модифицированный.
При его де активации большой экономии ресурсов не получим, а не удобств будет больше при открытии окна, начнется поиск картинок и биографии - это трата времени, а так в фоновом режиме.
Соглашусь, когда ресурсоёмкая панель, у меня например отключается панель Визуализации на milkdrop2, когда она не активна. При ее открытии проходит какое то время для запуска, но это экономит ресурсы.
MC Web
24.03.2016, 18:44
 
Раздел: Секреты foobar2000
Тема: Скрипты для foo_uie_wsh_panel_mod
Ответы: 2986
Просмотры: 572835
  • 1

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

seriousstas, онаружил, что WSH Biography подтормаживает другие скрипты с динамическим выводом, во время различных манипуляций с панелью.
Занялся оптимизацией.
Для наглядности видео, что получилось.
Обратите внимание на бегушую строку и пикметр до и после оптимизации.

phpBB [media]
kgena_ua
24.03.2016, 02:11
 
Раздел: Секреты foobar2000
Тема: Скрипты для foo_uie_wsh_panel_mod
Ответы: 2986
Просмотры: 572835

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

pois22ple, добрый день, спасибо.
pois22ple:Если запускать foobar с активным пустым плейлистом
Понял.
Когда-то, на другом скрипте, сталкивался с этим. Надо вспомнить.
Исправим.

Добавлено спустя 12 минут 27 секунд:
pois22ple,
function get_files_from_dir(), добавить if (!artist) return;
Код: Выделить всё
function get_files_from_dir() {
    if (!artist) return; 
    files = [];
    var e = new Enumerator( fso.GetFolder(tmp_b_path).Files );
    while ( !e.atEnd() ) {
        var name = e.item().Name;
        if (name.indexOf(clean_filename(artist)) == 0){
            files.push(tmp_b_path + name);
        }
        e.moveNext();
    }
}
Позже выложу обновление. Много мелких изменений.

Добавлено спустя 2 часа 20 минут:
Biography Text && Picture. www.last.fm
version "13032016"

Код: Выделить всё
// ==PREPROCESSOR==
// @name "Biography Text && Picture. www.last.fm"
// @author "kgena_ua"
// @version "13032016"
// @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;

var ww,wh;

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 = 10;
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);
}

get_color();

function on_colors_changed(){
    get_color();
}
*/
var bgcolor = RGB(31,41,48);
var a_color = RGB(220,220,220);
var b_color = RGB(255,255,230);

var transparent = 200;

var doc = new ActiveXObject("htmlfile");
var fso = new ActiveXObject("Scripting.FileSystemObject");
var WshShell = new ActiveXObject("WScript.Shell");
var script_path = fb.ProfilePath + "\\tmp_Biography\\download\\";
var vbs = "cscript //nologo \"" + script_path + "download.vbs\"";

var tmp_b_path = fb.ProfilePath + "\\tmp_Biography\\";
if(!fso.FolderExists(tmp_b_path)) {fso.CreateFolder(tmp_b_path)};
if(!fso.FolderExists(tmp_b_path + "\\download\\")) {fso.CreateFolder(tmp_b_path + "\\download\\")};
if(!fso.FileExists(tmp_b_path + "\\download\\" + "download.vbs")) {create_download_file()};
var nocover_path = window.GetProperty("nocover path",".\\nocover\\nocover.png");
var nocover = window.GetProperty("nocover image", false);

load_last_fm_logo();
var logo_img = gdi.Image(tmp_b_path + "\\download\\" + "last_fm_logo.jpg");

var artist, old_artis, filename;

function clean_filename(filename) {
    return filename.replace(/[\/\:\*\?\"\<\>\|\s]/g,'_');
}

var g_img = null;
var p_margin = window.GetProperty("margin: picture", 10);
var files = [], selected = 0;
var limit = window.GetProperty("download limit",5);
var cycle = window.GetProperty("auto cycle (sec)", 0);
var on_pic = false;

var scrollbar = window.GetProperty("scrollbar", true);
var scrollbar_k;
var sb_posy = 0;
var on_sb = false;
var on_sb_down = false;

var t_margin = window.GetProperty("margin: text", 10);
var txt_x = window.GetProperty("txt_x", window.Width / 2);
var txt_y = window.GetProperty("txt_y", window.Height / 2);
var delta_x, delta_y;
var a_x, a_y;
var b_x, b_y;
var text = "";
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_text = false;
var on_text_down = false;

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

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);

    paint(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";   
        set_cycle && gr.GdiDrawText("auto cycle \n" + txt_cycle, b_font, b_color, 15, 15, ww, wh, DT_LEFT | DT_WORD_ELLIPSIS );   
    } else{   
        gr.FillSolidRect(txt_x, txt_y, ww - txt_x, wh - txt_y, RGBA(getRed(bgcolor),getGreen(bgcolor),getBlue(bgcolor),transparent));   
    }   

    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; i++) {
        gr.GdiDrawText(b_text_array[i + s_text], b_font, RGB(0,0,0), b_x + 1, b_y + b_text_row_height * i + 2, ww, wh, DT_LEFT | DT_NOPREFIX );
        gr.GdiDrawText(b_text_array[i + s_text], b_font, b_color, b_x, b_y + b_text_row_height * i, ww, wh, DT_LEFT | DT_NOPREFIX );
    }

    scrollbar && draw_scrollbar(gr);

    gr.GdiDrawText("", gdi.Font("Arial",12, 0), b_color, 15, 0, ww, wh, DT_LEFT | DT_WORD_ELLIPSIS );
}

function paint(gr){
    g_img = gdi.Image(files[selected]);
    if (!g_img && nocover){
        try {
            g_img = gdi.Image(nocover_path);
        } catch(e) {};
    }
   
    if (g_img){
        var scale_w = (ww - p_margin * 2) / g_img.Width;
        var scale_h = (wh - p_margin * 2) / g_img.Height;
        var scale = Math.min(scale_w, scale_h);
       
        if (files.length > 0){
            g_img = g_img.CreateRawBitmap();
            gr.GdiDrawBitmap(g_img, p_margin, p_margin, g_img.Width * scale, g_img.Height * scale, 0, 0, g_img.Width, g_img.Height);
        } else {
            gr.DrawImage(g_img, p_margin, p_margin, g_img.Width * scale, g_img.Height * scale, 0, 0, g_img.Width, g_img.Height, 0, 100);
        }
    }
   
    if (logo_img && files.length == 0 && !nocover){
        gr.DrawImage(logo_img, p_margin, p_margin, logo_img.Width * 0.8, logo_img.Height * 0.8, 0, 0, logo_img.Width, logo_img.Height, 0, 255);   
    }
}

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;
   
    gr.FillSolidRect(ww - 4, b_y + scrollbar_y, 2, scrollbar_h, a_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);   
    return path.indexOf('://') > 0 ? fb.TitleFormat("[" + field + "]").Eval() : fb.TitleFormat("[" + field + "]").EvalWithMetadb(metadb);   
    //return fb.Titleformat("[" + field + "]").EvalWithMetadb(metadb) ? fb.TitleFormat("[" + field + "]").EvalWithMetadb(metadb) : fb.TitleFormat("[" + field + "]").Eval(true);   
}   

function on_metadb_changed() {
    if (!metadb) return;   
    artist = Eval("%artist%");
    if (artist != old_artis){
        CollectGarbage();
        g_img = null;
        s_text = 0;
        text = "";
        get_b_text_array()       
        get_b_text();
        del_files_from_dir();
        files = [];
        selected = 0;
        get_pic();       
        old_artis = artist;
    }
}     

function get_pic(){
    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) {
                            urls.push(data[i].src.replace("avatar170s", "770x0"));
                        }     
                    }       
                    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", ""))
                        }     
                    }       
                }     
                for (i = 0; i < Math.min(urls.length, limit); i++) {     
                    file = "\"" + tmp_b_path + clean_filename(artist) + "_"  + i + "_" + p_a[select_p_a] + ".jpg" + "\"";     
                    WshShell.Run(vbs + " " + urls[i] + " " + file, false);
                }     
              doc.close();
            }       
        }     
    }     
}

function get_files_from_dir() {
    if (!artist) return; 
    files = [];
    var e = new Enumerator( fso.GetFolder(tmp_b_path).Files );
    while ( !e.atEnd() ) {
        var name = e.item().Name;
        if (name.indexOf(clean_filename(artist)) == 0){
            files.push(tmp_b_path + name);
        }
        e.moveNext();
    }
}

function get_b_text(){
    xmlhttp2 = new ActiveXObject("Microsoft.XMLHTTP");
    url2 = ("http://www.last.fm/" + abc_lang[abc] + "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 == "") text = if_not_found[abc];
            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;
   
    var strings_array = [];
    b_text_array = [];
   
    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;

    var string_width = Math.max(ww - b_x - 10, 0);

    if (text) strings_array = temp_gr.EstimateLineWrap(text, b_font, string_width).toArray();

    for (var i = 0; i < strings_array.length; i += 2) {
        b_text_array.push(strings_array[i].replace(/^\s+|\s+$/g, ""));
    }

    b_text_rows = b_text_array.length;

    b_text_visable_height = Math.round(Math.max(0, wh - t_margin - b_y));
    b_text_visable_rows = Math.round(b_text_visable_height / b_text_row_height);

    temp_bmp.ReleaseGraphics(temp_gr);
    temp_bmp.Dispose();
    temp_gr = null;
    temp_bmp = null;

    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;
    window.Repaint();
}

function on_mouse_rbtn_up (x, y){     
    var _menu = window.CreatePopupMenu();
    var i = 1;

    MF_ENABLED = 0x00000000;   
    MF_GRAYED = 0x00000001;   
    MF_SEPARATOR = 0x00000800;   
     
    _menu.AppendMenuItem(MF_ENABLED, i++, "EN text");   
    _menu.AppendMenuItem(MF_ENABLED, i++, "RU text");   
    _menu.CheckMenuRadioItem(1, i, abc + 1);         
    _menu.EnableMenuItem(abc + 1, 1);     

    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);   
       
    _menu.AppendMenuItem(MF_ENABLED, i++, "Prefer now playing");   
    _menu.AppendMenuItem(MF_ENABLED, i++, "Follow selected track");   
    _menu.CheckMenuRadioItem(i - 2, i , selection_mode + 3);   
   _menu.EnableMenuItem(selection_mode + 3, 1);
       
    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);   
    _menu.AppendMenuItem(MF_ENABLED, i++, "Artist pictures");   
    _menu.AppendMenuItem(MF_ENABLED, i++, "Albums pictures");   
    _menu.CheckMenuRadioItem(i - 2, i , select_p_a + 5);   
   _menu.EnableMenuItem(select_p_a + 5, 1);

    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);   
    var is_artist = artist ? MF_ENABLED : MF_GRAYED;   
    _menu.AppendMenuItem(is_artist, i++, "last.fm Artist");   
     
//    if (ShiftDown) {   
        _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);   
        _menu.AppendMenuItem(MF_ENABLED, 10, "Reload");   
        _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);   
        _menu.AppendMenuItem(MF_ENABLED, 20, "Properties");   
        _menu.AppendMenuItem(MF_ENABLED, 30, "Configure ...");
//    }

    ret = _menu.TrackPopupMenu(x,y);

    switch (ret) {
    case 1:
        abc = 0;
        window.SetProperty("abc", abc);
        s_text = 0;
        text = "";
        get_b_text();
        break;
    case 2:
        abc = 1;
        window.SetProperty("abc", abc);
        s_text = 0;
        text = "";
        get_b_text();
        break;
    case 3:
        selection_mode = 0;
        window.SetProperty("selection mode", selection_mode);
        on_item_focus_change();
        break;
    case 4:
        selection_mode = 1;
        window.SetProperty("selection mode", selection_mode);
        on_item_focus_change();
        break;
    case 5:
        select_p_a = 0;
        window.SetProperty("pictures/albums", select_p_a);
        del_files_from_dir();
        files = [];
        selected = 0;
        get_pic();
        break;
    case 6:
        select_p_a = 1;
        window.SetProperty("pictures/albums", select_p_a);
        del_files_from_dir();
        files = [];
        selected = 0;
        get_pic();
        break;
    case 7:
        WshShell.run("http://www.last.fm/" + abc_lang[abc] + "music/" + encodeURIComponent(artist));
        break;
    case 10:
        window.Reload();
        break;
    case 20:
        window.ShowProperties();
        break;   
    case 30:
        window.ShowConfigure();   
        break;   
   }
    _menu.Dispose();   
    return true;   
}   

var timer = window.SetInterval(on_timer, 1000);
var step = 0;
var set_cycle = false;
var dis_timer, dis = 0;

function on_timer(id) {
    step =  set_cycle || cycle == 0 ? 0 : step + 1;
    if (files.length == 0) {
        get_files_from_dir();
        window.Repaint();
    };
   
    if (cycle > 0 && step >= cycle){
        selected = selected >= files.length - 1 ? 0 : selected = selected + 1;
        window.Repaint();
        step = 0;
    }
}

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

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;
                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);
}

function del_files_from_dir() {
    var del_files = [];
    var e = new Enumerator( fso.GetFolder(tmp_b_path).Files );
    while ( !e.atEnd() ) {
        var name = e.item().Name;
        try {
            fso.deleteFile(tmp_b_path + name );
        } catch(e) {};
        e.moveNext();
    }
}

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

function create_download_file() {
    try {
        file = fso.CreateTextFile(tmp_b_path + "\\download\\" + "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 < ww - 20 && y  >= txt_y ? true : false;
    on_sb =  x > ww - 20 && y  >= txt_y ? 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();
    }
}

function on_mouse_wheel(delta) {
    ShiftDown = utils.IsKeyPressed(0x10) ? true : false;
   
    if (on_pic && !ShiftDown && !delay){
        delay = true;
        fdelay();
        get_files_from_dir();
        if (delta < 0) {selected = selected <= 0 ? files.length - 1 : selected = selected - 1};
        if (delta > 0) {selected = selected >= files.length - 1 ? 0 : selected = selected + 1};
    }
   
    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}
        }
    }
   
    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();
        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){
        abc = abc == 1 ? 0 : 1;
        window.SetProperty("abc", abc);
        s_text = 0;
        b_text_array = [];
        text = "";
        get_b_text();
    }
    if (on_pic && files[selected]) WshShell.run( '"' + files[selected] + '"' );
}

function on_mouse_leave() {
    window.SetCursor(32512);
    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;
   
    get_b_text_array();
}
kgena_ua
13.03.2016, 14:04
 
Раздел: Секреты foobar2000
Тема: Скрипты для foo_uie_wsh_panel_mod
Ответы: 2986
Просмотры: 572835

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

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

Яндекс-переводчик / Yandex-translator
zeremy the offer is good.
Then we have to go on, the language selection from the context menu and not only the menu but also the language of the site get the biography of the artist.
MC Web
01.03.2016, 14:06
 
Раздел: Секреты foobar2000
Тема: Скрипты для foo_uie_wsh_panel_mod
Ответы: 2986
Просмотры: 572835
  • 4

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

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


Дополнения:
- максимально вывел в меню Properties необходимые для пользователя настройки;
- изменение размера шрифта (10 - 16) - Shift + колесо мыши на тексте;
- размер шрифта для артиста привязан к размеру шрифта биографии через переменную font size: artist (delta) в меню Properties;
- добавил прозрачность для изображения nocover.
Безымянный.png

Код: Выделить всё
// ==PREPROCESSOR==
// @name "Biography Text && Picture. www.last.fm"
// @author "kgena_ua"
// @version "27022016"
// @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;

var ww,wh;

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 = 10;
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);
}

get_color();
*/

var bgcolor = RGB(31,41,48);
var a_color = RGB(220,220,220);
var b_color = RGB(255,255,230);

var transparent = 200;

var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
var doc = new ActiveXObject("htmlfile");
var fso = new ActiveXObject("Scripting.FileSystemObject");
var WshShell = new ActiveXObject("WScript.Shell");
var script_path = fb.ProfilePath + "\\tmp_Biography\\download\\";
var vbs = "cscript //nologo \"" + script_path + "download.vbs\"";

var tmp_b_path = fb.ProfilePath + "\\tmp_Biography\\";
if(!fso.FolderExists(tmp_b_path)) {fso.CreateFolder(tmp_b_path)};
if(!fso.FolderExists(tmp_b_path + "\\download\\")) {fso.CreateFolder(tmp_b_path + "\\download\\")};
if(!fso.FileExists(tmp_b_path + "\\download\\" + "download.vbs")) {create_download_file()};
var nocover_path = window.GetProperty("nocover path",".\\nocover\\nocover.png");
var nocover = window.GetProperty("nocover image", false);

var last_fm_logo;
load_last_fm_logo();

var artist, old_artis;

var g_img = null;
var p_margin = window.GetProperty("margin: picture", 10);
var files = [], selected = 0;
var limit = window.GetProperty("download limit",5);
var cycle = window.GetProperty("auto cycle (sec)", 0);
var pic_scroll = false;

var scrollbar = window.GetProperty("scrollbar", false);
var sb_down = false;
var sb_scroll = false;
var scrollbar_k;
var posy = 0;

var t_margin = window.GetProperty("margin: text", 10);
var txt_x = window.GetProperty("txt_x", window.Width / 2);
var txt_y = window.GetProperty("txt_y", window.Height / 2);
var delta_x, delta_y;
var artist_x, artist_y;
var b_x = 0, b_y = 0;
var text = "";
var s_text = 0;
var string_width;
var strings_array = [];
var b_text_rows = 0;
var b_text_row_height = 0;
var b_text_visable_rows = 0;
var b_text_visable_height = 0;
var b_text_array = [];
var k_down = false;
var text_scroll = false;

var abc_lang = new Array("", "ru/");
var abc = window.GetProperty("abc", 0);
var if_not_found = new Array(". . .", ". . .");
var select_p_a = window.GetProperty("pictures/albums", 0);
var select_p_a_old;
var p_a = new Array("images", "albums");

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);

    paint(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";   
        set_cycle && gr.GdiDrawText("auto cycle \n" + txt_cycle, b_font, b_color, 15, 15, ww, wh, DT_LEFT | DT_WORD_ELLIPSIS );   
    } else{   
        gr.FillSolidRect(txt_x, txt_y, ww - txt_x, wh - txt_y, RGBA(getRed(bgcolor),getGreen(bgcolor),getBlue(bgcolor),transparent));   
    }   

    gr.GdiDrawText(artist, a_font, RGB(0,0,0), artist_x + 1, artist_y + 2, ww - artist_x - t_margin, wh, DT_LEFT | DT_WORD_ELLIPSIS );   
    gr.GdiDrawText(artist, a_font, a_color, artist_x, artist_y, ww - artist_x - t_margin, wh, DT_LEFT | DT_WORD_ELLIPSIS );   

    for (var i = 0; i < b_text_visable_rows; i++) { 
        gr.GdiDrawText(b_text_array[i + s_text], b_font, RGB(0,0,0), b_x + 1, b_y + b_text_row_height * i + 2, ww, wh, DT_LEFT );
        gr.GdiDrawText(b_text_array[i + s_text], b_font, b_color, b_x, b_y + b_text_row_height * i, ww, wh, DT_LEFT );
    } 

    scrollbar && draw_scrollbar(gr);

    gr.GdiDrawText("", b_font, b_color, 15, 0, ww, wh, DT_LEFT | DT_WORD_ELLIPSIS );
}

function paint(gr){
    g_img = gdi.Image(files[selected]); 
    if (!g_img && nocover){
        try {
            g_img = gdi.Image(nocover_path); 
        } catch(e) {};
    }
   
    if (g_img){
        var scale_w = (ww - p_margin * 2) / g_img.Width;
        var scale_h = (wh - p_margin * 2) / g_img.Height;
        var scale = Math.min(scale_w, scale_h);
       
        if (files.length > 0){
            g_img = g_img.CreateRawBitmap();
            gr.GdiDrawBitmap(g_img, p_margin, p_margin, g_img.Width * scale, g_img.Height * scale, 0, 0, g_img.Width, g_img.Height);
        } else {
            gr.DrawImage(g_img, p_margin, p_margin, g_img.Width * scale, g_img.Height * scale, 0, 0, g_img.Width, g_img.Height, 0, 100); 
        }
    }
   
    logo_img = gdi.Image(tmp_b_path + "\\download\\" + "last_fm_logo.jpg");
    if (logo_img && files.length == 0 && !nocover){
        gr.DrawImage(logo_img, p_margin, p_margin, logo_img.Width * 0.8, logo_img.Height * 0.8, 0, 0, logo_img.Width, logo_img.Height, 0, 255);   
    }
}

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;
    scrollbar_y = s_text > 0 ? s_text * scrollbar_k : 0;

    gr.FillSolidRect(ww - 4, b_y + scrollbar_y, 2, scrollbar_h, a_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);   
    //return path.indexOf('://') > 0 ? fb.TitleFormat("[" + field + "]").Eval() : fb.TitleFormat("[" + field + "]").EvalWithMetadb(metadb);   
    return fb.Titleformat("[" + field + "]").EvalWithMetadb(metadb) ? fb.TitleFormat("[" + field + "]").EvalWithMetadb(metadb) : fb.TitleFormat("[" + field + "]").Eval(true);   
}   

function on_metadb_changed() {
    if (!metadb) return;   
    artist = Eval("%artist%");
    if (artist != old_artis || select_p_a != select_p_a_old){
        CollectGarbage();
        g_img = null;
        files = [];
        del_files_from_dir();
        selected = 0;
        s_text = 0;
        text = "";
        get_b_text_array()       
        get_pic();
        old_artis = artist;
        select_p_a_old = select_p_a;
    }
}      

function get_pic(){      
    var url1 = ("http://www.last.fm/music/" + encodeURIComponent(artist) + "/+" + p_a[select_p_a]);      
    xmlhttp.open("GET", url1, true);      
    xmlhttp.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");      
    xmlhttp.send();      
    xmlhttp.onreadystatechange = function () {      
        if (xmlhttp.readyState == 4) {      
            if (xmlhttp.status == 200) {      
                doc.open();      
              var div = doc.createElement("div");
              div.innerHTML = xmlhttp.responsetext;
              var data = div.getElementsByTagName("img");
              var urls = [];
                for (i = 0; i < data.length; i++) {      
                    if (data[i].className == "image-list-image"){        
                        if (data[i].src.indexOf("http://img2-ak.lst.fm/i/u/avatar170s") == 0) urls.push(data[i].src.replace("avatar170s", ""));       
                    }       
                    if (data[i].className == "album-grid-album-art"){        
                        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", ""));       
                    }        
                }      
                for (i = 0; i < Math.min(urls.length, limit); i++) {      
                    file = "\"" + tmp_b_path + artist + "_"  + i + "_" +p_a[select_p_a] + ".jpg" + "\"";      
                    WshShell.Run(vbs + " " + urls[i] + " " + file, false);       
                }      
              doc.close();
            }       
            get_b_text();      
        }      
    }      
}

function get_files_from_dir() {
    files = [];
    var e = new Enumerator( fso.GetFolder(tmp_b_path).Files );
    while ( !e.atEnd() ) {
        var name = e.item().Name;
        if (name.indexOf(artist) == 0){
            files.push(tmp_b_path + name);
        }
        e.moveNext();
    }
}

/*function get_files_from_dir() {
    files = [];
    files = utils.Glob(tmp_b_path + artist + "*.*").toArray();
}
*/
function get_b_text(){
    var url2 = ("http://www.last.fm/" + abc_lang[abc] + "music/" + encodeURIComponent(artist) + "/+wiki");
    xmlhttp.open("GET", url2, true);
    xmlhttp.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
    xmlhttp.send();
    xmlhttp.onreadystatechange = function () {
        if (xmlhttp.readyState == 4) {
            if (xmlhttp.status == 200) {
                doc.open();
                var div = doc.createElement("div");
                div.innerHTML = xmlhttp.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 == "") text = if_not_found[abc];
            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() {
    artist_x = txt_x + t_margin;
    artist_y = txt_y + t_margin;
    strings_array = [];
    b_text_array = [];
   
    temp_bmp = gdi.CreateImage(1, 1);
    temp_gr = temp_bmp.GetGraphics();

    b_x = txt_x + t_margin;
    b_y = txt_y + temp_gr.CalcTextHeight("text", a_font) + t_margin * 2;

    b_text_row_height = temp_gr.CalcTextHeight("text", b_font)
    string_width = Math.max(ww - b_x - 10, 0);

    if (text) strings_array = temp_gr.EstimateLineWrap(text, b_font, string_width).toArray();

    for (var i = 0; i < strings_array.length; i += 2) {
        b_text_array.push(strings_array[i].replace(/^\s+|\s+$/g, ""));
    }

    b_text_rows = b_text_array.length;
    b_text_visable_rows = Math.round((wh - b_y - 10) / b_text_row_height);
    b_text_visable_height = Math.round(wh - b_y - 10);

    temp_bmp.ReleaseGraphics(temp_gr);
    temp_bmp.Dispose();
    temp_gr = null;
    temp_bmp = null;

    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;
    window.Repaint();
}

function on_mouse_rbtn_up (x, y){     
    var _menu = window.CreatePopupMenu();
    var i = 1;

    MF_ENABLED = 0x00000000;   
    MF_GRAYED = 0x00000001;   
    MF_SEPARATOR = 0x00000800;   
      
    _menu.AppendMenuItem(MF_ENABLED, i++, "EN text");   
    _menu.AppendMenuItem(MF_ENABLED, i++, "RU text");   
    _menu.CheckMenuRadioItem(1, i, abc + 1);         
    _menu.EnableMenuItem(abc + 1, 1);     

    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);   
       
    _menu.AppendMenuItem(MF_ENABLED, i++, "Prefer now playing");   
    _menu.AppendMenuItem(MF_ENABLED, i++, "Follow selected track");   
    _menu.CheckMenuRadioItem(i - 2, i , selection_mode + 3);   
   _menu.EnableMenuItem(selection_mode + 3, 1);
       
    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);   
    _menu.AppendMenuItem(MF_ENABLED, i++, "Artist pictures");   
    _menu.AppendMenuItem(MF_ENABLED, i++, "Albums pictures");   
    _menu.CheckMenuRadioItem(i - 2, i , select_p_a + 5);   
   _menu.EnableMenuItem(select_p_a + 5, 1); 

    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);   
    var is_artist = artist ? MF_ENABLED : MF_GRAYED;   
    _menu.AppendMenuItem(is_artist, i++, "last.fm Artist");   
      
//    if (ShiftDown) {   
        _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);   
        _menu.AppendMenuItem(MF_ENABLED, 10, "Reload");   
        _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);   
        _menu.AppendMenuItem(MF_ENABLED, 20, "Properties");   
        _menu.AppendMenuItem(MF_ENABLED, 30, "Configure ...");
//    }

    ret = _menu.TrackPopupMenu(x,y);

    switch (ret) {
    case 1:
        abc = 0;
        window.SetProperty("abc", abc);
        s_text = 0;
        text = "";
        get_b_text();
        break;
    case 2:
        abc = 1;
        window.SetProperty("abc", abc);
        s_text = 0;
        text = "";
        get_b_text();
        break;
    case 3:
        selection_mode = 0;
        window.SetProperty("selection_mode", selection_mode);
        on_item_focus_change();
        break;
    case 4:
        selection_mode = 1;
        window.SetProperty("selection_mode", selection_mode);
        on_item_focus_change();
        break;
    case 5:
        select_p_a = 0;
        window.SetProperty("pictures/albums", select_p_a);
        on_metadb_changed();
        break;
    case 6:
        select_p_a = 1;
        window.SetProperty("pictures/albums", select_p_a);
        on_metadb_changed();
        break;
    case 7:
        WshShell.run("http://www.last.fm/" + abc_lang[abc] + "music/" + encodeURIComponent(artist));
        break;
    case 10:
        window.Reload();
        break;
    case 20:
        window.ShowProperties();
        break;   
    case 30:
        window.ShowConfigure();   
        break;   
   }
    _menu.Dispose();   
    return true;   
}   

var timer = window.SetInterval(on_timer, 1000);
var step = 0;
var set_cycle = false;
var dis_timer, dis = 0;

function on_timer(id) {
    step =  set_cycle || cycle == 0 ? 0 : step + 1;
    if (files.length == 0) {get_files_from_dir(); window.Repaint();};
   
    if (cycle > 0 && step >= cycle){
        selected = selected >= files.length - 1 ? 0 : selected = selected + 1;
        window.Repaint();
        step = 0;
    }
}

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

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;
                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);
}

function del_files_from_dir() {
    var del_files = [];
    var e = new Enumerator( fso.GetFolder(tmp_b_path).Files );
    while ( !e.atEnd() ) {
        var name = e.item().Name;
        try {
            fso.deleteFile(tmp_b_path + name );
        } catch(e) {};
        e.moveNext();
    }
}

/*
function del_files_from_dir() {
    del_files = [];
    del_files = utils.Glob(tmp_b_path + "*.*").toArray();
   
    for (i in del_files) {
        try {
            fso.deleteFile(del_files[i]);
        } catch(e) {};
    }
}
*/

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

function create_download_file() {
    try {
        file = fso.CreateTextFile(tmp_b_path + "\\download\\" + "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);
   
    text_scroll = x >= txt_x && x < ww - 20 && y  >= txt_y ? true : false;
    sb_scroll =  x > ww - 20 && y  >= txt_y ? true : false;
    pic_scroll = !text_scroll && !sb_scroll ? true : false;
   
    if (k_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 - 50 ? wh - 50: txt_y;
        get_b_text_array();
    }

    if (sb_down && scrollbar){
        posy = y + delta_y;
        s_text = y + delta_y >= 0 ? y + delta_y <= (b_text_rows - b_text_visable_rows) * scrollbar_k ? Math.round(posy / scrollbar_k) : b_text_rows - b_text_visable_rows : 0;
        window.Repaint();
    }
}

function on_mouse_wheel(delta) {
    ShiftDown = utils.IsKeyPressed(0x10) ? true : false;
   
    if (!delay && pic_scroll && !ShiftDown){
        delay = true;
        fdelay();
        get_files_from_dir(); 
        if (delta < 0) {selected = selected <= 0 ? files.length - 1 : selected = selected - 1};
        if (delta > 0) {selected = selected >= files.length - 1 ? 0 : selected = selected + 1};

    }
   
    if (text_scroll && !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}
        }
    }
   
    if (!delay && text_scroll && ShiftDown){
        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();
        get_b_text_array();
    }
   
    if (set_cycle && pic_scroll) {
        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 (text_scroll){
        k_down = true;
        delta_x = x - txt_x;
        delta_y = y - txt_y;
    }
    if (sb_scroll){
        sb_down = true;
        posy = s_text * scrollbar_k;
        delta_y = posy - y;
    }
}

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

function on_mouse_lbtn_dblclk (x,y){
    if (text_scroll){
        abc = abc == 1 ? 0 : 1;
        window.SetProperty("abc", abc);
        s_text = 0;
        b_text_array = [];
        text = "";
        get_b_text();
    }
    if (files[selected] && pic_scroll) WshShell.run( '"' + files[selected] + '"' );
}

function on_mouse_leave() {
    window.SetCursor(32512);
    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 - 50 && txt_y >= 0 ? wh - 50 : txt_y;
   
    get_b_text_array();
}
kgena_ua
27.02.2016, 17:23
 
Раздел: Секреты foobar2000
Тема: Скрипты для foo_uie_wsh_panel_mod
Ответы: 2986
Просмотры: 572835

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

MC Web, да, завтра попробую вставить в сборку.
Скрипт у меня один, в сборке вообще нет биографии (кроме foo_uie_biography).
А пока все соответствует
Безымянный.jpg

В противном случае возьму старый скрипт и буду выкладывать Вам с пошаговыми изменениями, если Вы не против.
kgena_ua
25.02.2016, 00:40
 
Раздел: Секреты foobar2000
Тема: Скрипты для foo_uie_wsh_panel_mod
Ответы: 2986
Просмотры: 572835
  • 3

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

Biography Text && Picture. www.last.fm// "
version "23022016"


Изменения:
- подчистил;
- добавлен пункт меню last.fm Artist;
- включение, отключение nocover через меню properties (путь строка 47). При отключенном nocover логотип last fm;
- добавлен scrollbar, включение, отключение через меню properties.
phpBB [media]

Код: Выделить всё
// ==PREPROCESSOR==
// @name "Biography Text && Picture. www.last.fm"
// @author "kgena_ua"
// @version "23022016"
// @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);};

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

var on_mouse = false;

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;

var bgcolor = RGB(31,41,48);
var a_color = RGB(220,220,220);
var b_color = RGB(255,255,230);
var transparent = 200;

var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
var doc = new ActiveXObject("htmlfile");
var fso = new ActiveXObject("Scripting.FileSystemObject");
var WshShell = new ActiveXObject("WScript.Shell");
var script_path = fb.ProfilePath + "\\tmp_Biography\\download\\";
var vbs = "cscript //nologo \"" + script_path + "download.vbs\"";

var tmp_b_path = fb.ProfilePath + "\\tmp_Biography\\";
if(!fso.FolderExists(tmp_b_path)) {fso.CreateFolder(tmp_b_path)};
if(!fso.FolderExists(tmp_b_path + "\\download\\")) {fso.CreateFolder(tmp_b_path + "\\download\\")};
if(!fso.FileExists(tmp_b_path + "\\download\\" + "download.vbs")) {create_download_file()};
var nocover_path = fb.ProfilePath + "nocover.png";
var nocover = window.GetProperty("nocover image", false);

var last_fm_logo;
load_last_fm_logo();

var artist, old_artis;
var g_img = null;
var p_margn = 10;
var files = [], selected = 0;
var limit = window.GetProperty("download limit",5);
var cycle = window.GetProperty("auto cycle (sec)", 0);

var txt_x = window.GetProperty("txt_x", window.Width / 2);
var txt_y = window.GetProperty("txt_y", window.Height / 2);
var delta_x, delta_y;
var k_down = false;
var text_scroll = false;
var pic_scroll = false;

var scrollbar = window.GetProperty("scrollbar", false);
var sb_down = false;
var sb_scroll = false;
var scrollbar_k;
var posy = 0;

var t_margin = 10;
var artist_x, artist_y;
var b_x = 0, b_y = 0;
var text = "";
var s_text = 0;
var string_width;
var strings_array = [];
var b_text_rows = 0;
var b_text_row_height = 0;
var b_text_visable_rows = 0;
var b_text_visable_height = 0;
var b_text_array = [];

var abc_lang = new Array("", "ru/");
var abc = window.GetProperty("abc", 0);
var if_not_found = new Array(". . .", ". . .");
var select_p_a = window.GetProperty("pictures/albums", 0);
var select_p_a_old;
var p_a = new Array("images", "albums");

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);

    paint(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";   
        set_cycle && gr.GdiDrawText("auto cycle \n" + txt_cycle, b_font, b_color, 15, 15, ww, wh, DT_LEFT | DT_WORD_ELLIPSIS );   
    } else{   
        gr.FillSolidRect(txt_x, txt_y, ww - txt_x, wh - txt_y, RGBA(getRed(bgcolor),getGreen(bgcolor),getBlue(bgcolor),transparent));   
    }   

    //gr.GdiDrawText(artist, a_font, RGB(0,0,0), artist_x + 1, artist_y + 2, ww - artist_x, wh, DT_LEFT | DT_WORD_ELLIPSIS );   
    gr.GdiDrawText(artist, a_font, a_color, artist_x, artist_y, ww - artist_x, wh, DT_LEFT | DT_WORD_ELLIPSIS );   

    for (var i = 0; i < b_text_visable_rows; i++) { 
        //gr.GdiDrawText(b_text_array[i + s_text], b_font, RGB(0,0,0), b_x + 1, b_y + b_text_row_height * i + 2, ww, wh, DT_LEFT );
        gr.GdiDrawText(b_text_array[i + s_text], b_font, b_color, b_x, b_y + b_text_row_height * i, ww, wh, DT_LEFT );
    } 

    scrollbar && draw_scrollbar(gr);
   
    gr.GdiDrawText("", b_font, b_color, 15, 0, ww, wh, DT_LEFT | DT_WORD_ELLIPSIS );
}

function paint(gr){
    g_img = gdi.Image(files[selected]); 
    if (!g_img && nocover){
        try {
            g_img = gdi.Image(nocover_path); 
        } catch(e) {};
    }
   
    if (g_img){
        var scale_w = (ww - p_margn * 2) / g_img.Width;
        var scale_h = (wh - p_margn * 2) / g_img.Height;
        var scale = Math.min(scale_w, scale_h);
       
        g_img = g_img.CreateRawBitmap();
        gr.GdiDrawBitmap(g_img, p_margn, p_margn, g_img.Width * scale, g_img.Height * scale, 0, 0, g_img.Width, g_img.Height);
    }
   
    logo_img = gdi.Image(tmp_b_path + "\\download\\" + "last_fm_logo.jpg");
    if (logo_img && files.length == 0 && !nocover){
        gr.DrawImage(logo_img, p_margn, p_margn, logo_img.Width * 0.8, logo_img.Height * 0.8, 0, 0, logo_img.Width, logo_img.Height, 0, 255);   
    }
}

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;
    scrollbar_y = s_text > 0 ? s_text * scrollbar_k : 0;

    gr.FillSolidRect(ww - 4, b_y + scrollbar_y, 2, scrollbar_h, b_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);   
    //return path.indexOf('://') > 0 ? fb.TitleFormat("[" + field + "]").Eval() : fb.TitleFormat("[" + field + "]").EvalWithMetadb(metadb);   
    return fb.Titleformat("[" + field + "]").EvalWithMetadb(metadb) ? fb.TitleFormat("[" + field + "]").EvalWithMetadb(metadb) : fb.TitleFormat("[" + field + "]").Eval(true);   
}   

function on_metadb_changed() {
    if (!metadb) return;   
    artist = Eval("%artist%");
    if (artist != old_artis || select_p_a != select_p_a_old){
        CollectGarbage();
        g_img = null;
        files = [];
        del_files_from_dir();
        selected = 0;
        s_text = 0;
        text = "";
        get_b_text_array()       
        get_pic();
        old_artis = artist;
        select_p_a_old = select_p_a;
    }
}      

function get_pic(){      
    var url1 = ("http://www.last.fm/music/" + encodeURIComponent(artist) + "/+" + p_a[select_p_a]);      
    xmlhttp.open("GET", url1, true);      
    xmlhttp.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");      
    xmlhttp.send();      
    xmlhttp.onreadystatechange = function () {      
        if (xmlhttp.readyState == 4) {      
            if (xmlhttp.status == 200) {      
                doc.open();      
              var div = doc.createElement("div");
              div.innerHTML = xmlhttp.responsetext;
              var data = div.getElementsByTagName("img");
              var urls = [];
                for (i = 0; i < data.length; i++) {      
                    if (data[i].className == "image-list-image"){        
                        if (data[i].src.indexOf("http://img2-ak.lst.fm/i/u/avatar170s") == 0) urls.push(data[i].src.replace("avatar170s", ""));       
                    }       
                    if (data[i].className == "album-grid-album-art"){        
                        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", ""));       
                    }        
                }      
                for (i = 0; i < Math.min(urls.length, limit); i++) {      
                    file = "\"" + tmp_b_path + artist + "_"  + i + "_" +p_a[select_p_a] + ".jpg" + "\"";      
                    WshShell.Run(vbs + " " + urls[i] + " " + file, false);       
                }      
              doc.close();
            }       
            get_b_text();      
        }      
    }      
}

function get_files_from_dir() {
    files = [];
    var e = new Enumerator( fso.GetFolder(tmp_b_path).Files );
    while ( !e.atEnd() ) {
        var name = e.item().Name;
        if (name.indexOf(artist) == 0){
            files.push(tmp_b_path + name);
        }
        e.moveNext();
    }
}

/*function get_files_from_dir() {
    files = [];
    files = utils.Glob(tmp_b_path + artist + "*.*").toArray();
}
*/
function get_b_text(){
    var url2 = ("http://www.last.fm/" + abc_lang[abc] + "music/" + encodeURIComponent(artist) + "/+wiki");
    xmlhttp.open("GET", url2, true);
    xmlhttp.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
    xmlhttp.send();
    xmlhttp.onreadystatechange = function () {
        if (xmlhttp.readyState == 4) {
            if (xmlhttp.status == 200) {
                doc.open();
                var div = doc.createElement("div");
                div.innerHTML = xmlhttp.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 == "") text = if_not_found[abc];
            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() {
    artist_x = txt_x + t_margin;
    artist_y = txt_y + t_margin;
    strings_array = [];
    b_text_array = [];
   
    temp_bmp = gdi.CreateImage(1, 1);
    temp_gr = temp_bmp.GetGraphics();

    b_x = txt_x + t_margin;
    b_y = txt_y + temp_gr.CalcTextHeight("text", a_font) + t_margin * 2;

    b_text_row_height = temp_gr.CalcTextHeight("text", b_font)
    string_width = Math.max(ww - b_x - 10, 0);

    if (text) strings_array = temp_gr.EstimateLineWrap(text, b_font, string_width).toArray();

    for (var i = 0; i < strings_array.length; i += 2) {
        b_text_array.push(strings_array[i].replace(/^\s+|\s+$/g, ""));
    }

    b_text_rows = b_text_array.length;
    b_text_visable_rows = Math.round((wh - b_y - 10) / b_text_row_height);
    b_text_visable_height = Math.round(wh - b_y - 10);
   // b_text_height = b_text_array.length * b_text_row_height;

    temp_bmp.ReleaseGraphics(temp_gr);
    temp_bmp.Dispose();
    temp_gr = null;
    temp_bmp = null;

    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;
    window.Repaint();
}

function on_mouse_rbtn_up (x, y){     
    var _menu = window.CreatePopupMenu();
    var i = 1;

    MF_ENABLED = 0x00000000;   
    MF_GRAYED = 0x00000001;   
    MF_SEPARATOR = 0x00000800;   
      
    _menu.AppendMenuItem(MF_ENABLED, i++, "EN text");   
    _menu.AppendMenuItem(MF_ENABLED, i++, "RU text");   
    _menu.CheckMenuRadioItem(1, i, abc + 1);         
    _menu.EnableMenuItem(abc + 1, 1);     

    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);   
       
    _menu.AppendMenuItem(MF_ENABLED, i++, "Prefer now playing");   
    _menu.AppendMenuItem(MF_ENABLED, i++, "Follow selected track");   
    _menu.CheckMenuRadioItem(i - 2, i , selection_mode + 3);   
   _menu.EnableMenuItem(selection_mode + 3, 1);
       
    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);   
    _menu.AppendMenuItem(MF_ENABLED, i++, "Artist pictures");   
    _menu.AppendMenuItem(MF_ENABLED, i++, "Albums pictures");   
    _menu.CheckMenuRadioItem(i - 2, i , select_p_a + 5);   
   _menu.EnableMenuItem(select_p_a + 5, 1); 

    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);   
    var is_artist = artist ? MF_ENABLED : MF_GRAYED;   
    _menu.AppendMenuItem(is_artist, i++, "last.fm Artist");   
      
//    if (ShiftDown) {   
        _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);   
        _menu.AppendMenuItem(MF_ENABLED, 10, "Reload");   
        _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);   
        _menu.AppendMenuItem(MF_ENABLED, 20, "Properties");   
        _menu.AppendMenuItem(MF_ENABLED, 30, "Configure ...");
//    }

    ret = _menu.TrackPopupMenu(x,y);

    switch (ret) {
    case 1:
        abc = 0;
        window.SetProperty("abc", abc);
        s_text = 0;
        text = "";
        get_b_text();
        break;
    case 2:
        abc = 1;
        window.SetProperty("abc", abc);
        s_text = 0;
        text = "";
        get_b_text();
        break;
    case 3:
        selection_mode = 0;
        window.SetProperty("selection_mode", selection_mode);
        on_item_focus_change();
        break;
    case 4:
        selection_mode = 1;
        window.SetProperty("selection_mode", selection_mode);
        on_item_focus_change();
        break;
    case 5:
        select_p_a = 0;
        window.SetProperty("pictures/albums", select_p_a);
        on_metadb_changed();
        break;
    case 6:
        select_p_a = 1;
        window.SetProperty("pictures/albums", select_p_a);
        on_metadb_changed();
        break;
    case 7:
        WshShell.run("http://www.last.fm/music/" + encodeURIComponent(artist));
        break;
    case 10:
        window.Reload();
        break;
    case 20:
        window.ShowProperties();
        break;   
    case 30:
        window.ShowConfigure();   
        break;   
   }
    _menu.Dispose();   
    return true;   
}   

var timer = window.SetInterval(on_timer, 1000);
var step = 0;
var set_cycle = false;
var dis_timer, dis = 0;

function on_timer(id) {
    step =  set_cycle || cycle == 0 ? 0 : step + 1;
    if (files.length == 0) {get_files_from_dir(); window.Repaint();};
   
    if (cycle > 0 && step >= cycle){
        selected = selected >= files.length - 1 ? 0 : selected = selected + 1;
        window.Repaint();
        step = 0;
    }
}

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

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;
                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);
}

function del_files_from_dir() {
    var del_files = [];
    var e = new Enumerator( fso.GetFolder(tmp_b_path).Files );
    while ( !e.atEnd() ) {
        var name = e.item().Name;
        try {
            fso.deleteFile(tmp_b_path + name );
        } catch(e) {};
        e.moveNext();
    }
}

/*
function del_files_from_dir() {
    del_files = [];
    del_files = utils.Glob(tmp_b_path + "*.*").toArray();
   
    for (i in del_files) {
        try {
            fso.deleteFile(del_files[i]);
        } catch(e) {};
    }
}
*/

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

function create_download_file() {
    try {
        file = fso.CreateTextFile(tmp_b_path + "\\download\\" + "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);
    if (k_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 - 50 ? wh - 50: txt_y;
        //if (b_text_visable_rows + s_text > b_text_rows && s_text > 0){ s_text -= 1};
        get_b_text_array();
    }

    text_scroll = x >= txt_x && x < ww - 20 && y  >= txt_y ? true : false;
    sb_scroll =  x > ww - 20 && y  >= txt_y ? true : false;
    pic_scroll = !text_scroll && !sb_scroll ? true : false;

    if (sb_down && scrollbar){
        posy = y + delta_y;
        s_text = y + delta_y >= 0 ? y + delta_y <= (b_text_rows - b_text_visable_rows) * scrollbar_k ? Math.round(posy / scrollbar_k) : b_text_rows - b_text_visable_rows : 0;
        window.Repaint();
    }
}

function on_mouse_wheel(delta) {
    ShiftDown = utils.IsKeyPressed(0x10) ? true : false;
   
    if (!delay && pic_scroll && !ShiftDown){
        delay = true;
        fdelay();
        get_files_from_dir(); 
        if (delta < 0) {selected = selected <= 0 ? files.length - 1 : selected = selected - 1};
        if (delta > 0) {selected = selected >= files.length - 1 ? 0 : selected = selected + 1};

    }
    if (text_scroll && !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}
        }
    }
   
    if (set_cycle) {
        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 (text_scroll){
        k_down = true;
        delta_x = x - txt_x;
        delta_y = y - txt_y;
    }
    if (sb_scroll){
        sb_down = true;
        posy = s_text * scrollbar_k;
        delta_y = posy - y;
    }
}

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

function on_mouse_lbtn_dblclk (x,y){
    if (text_scroll){
        abc = abc == 1 ? 0 : 1;
        window.SetProperty("abc", abc);
        s_text = 0;
        b_text_array = [];
        text = "";
        get_b_text();
    }
    if (files[selected] && pic_scroll) WshShell.run( '"' + files[selected] + '"' );
}

function on_mouse_leave() {
    window.SetCursor(32512);
    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 - 50 && txt_y >= 0 ? wh - 50 : txt_y;
   
   // if (b_text_visable_rows + s_text > b_text_rows && s_text > 0) {s_text -= 1};
    get_b_text_array();
}

Добавлено спустя 8 минут 47 секунд:
вова_сбрат:в заголовке выводит название активного (звучащего) плейлиста....
Как в WSH выглядят эти строки?
Код: Выделить всё
 plist_name = plman.GetPlaylistName(plman.ActivePlaylist);
вова_сбрат:выводить в Status bar (DUI)
Наверное не получится.
kgena_ua
23.02.2016, 22:07
 
Раздел: Секреты foobar2000
Тема: Скрипты для foo_uie_wsh_panel_mod
Ответы: 2986
Просмотры: 572835

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

я думал над организацией показа всех картинок в одной панели. Например так:
часть скрипта, отвечающего за 'внешние картинки в папке трека и дочерних + вшитые' считает и нумерует их, допустим "covers" =3.
А часть, ответственная за картинки био накачивает их в тмп био, считает и нумерует (независимо от части "covers"). Допустим , "Biography Picture" = 6.
При включении Play таймер первым запускает показ "covers" (т.к. "Biography Picture" в это время только завершают скачивание), и делает это 3 цикла, показав все картинки "covers" по одному разу. После того, как N_Cikle_C==3 происходит переключение на показ из тмп био и отрабатывается 6 циклов (N_Cikle_B==6), после чего, если трек не кончился, плей лист не сменился и т.д. - все повторяется.
Такой алгоритм развязывает обсчет картинок обложек и биокартинок и таймер один. Польза - не будет 2х панелей картинок, на которых часто уныло висит одна вшитая картинка, а вторая показывает ноковер, т.к. интернета нет :smile: Скрипты подвергаются минимальным переделкам - их связывает только function on_paint(gr) и таймер-триггер.Сам могу только "ломать" скрипты, - кодю слабо, учусь только на примерах. Помогите реализовать, если возможно.
No_mad
23.02.2016, 01:10
 
Раздел: Секреты foobar2000
Тема: Скрипты для foo_uie_wsh_panel_mod
Ответы: 2986
Просмотры: 572835
Пред.След.

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