Список разделов › Аудиоплеер foobar2000 › Секреты foobar2000
// ==PREPROCESSOR==
// @name "Properties & properties file (ml)"
// @author "kgena_ua"
// @version "22102017"
// @feature "v1.4"
// @feature "watch-metadb"
// @tooltip "custom-paint"
// ==/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)); }
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, wh_old;
IDC_HAND = 32649;
IDC_ARROW = 32512;
IDC_SIZEWE = 32644;
MF_ENABLED = 0x00000000;
MF_GRAYED = 0x00000001;
MF_SEPARATOR = 0x00000800;
VK_SHIFT = 0x10;
VK_CONTROL = 0x11;
VK_ESCAPE = 0x1B;
String.prototype.repeat = function(n) {
return new Array(n + 1).join(this);
}
window.SetProperty(" - user", "");
if (window.GetProperty(" - user") != "" ) window.SetProperty(" - user", "");
window.SetProperty("-".repeat(50), "");
if (window.GetProperty("-".repeat(50)) != "" ) window.SetProperty("-".repeat(50), "");
var font_name_item_name = window.GetProperty(" font name: item name", "Arial");
var font_name_item_value = window.GetProperty(" font name: item value", "Arial");
var font_name_group = window.GetProperty(" font name: group", "Arial");
var font_size_item_name = window.GetProperty(" font size: item name", 11);
var font_size_item_value = window.GetProperty(" font size: item value", 12);
var font_size_group = window.GetProperty(" font size: group", 11);
var font_style_item_name = window.GetProperty(" font style: item name", 0);
var font_style_item_value = window.GetProperty(" font style: item value", 0);
var font_style_group = window.GetProperty(" font style: group", 0);
var font_size_tooltip = window.GetProperty(" font size: tooltip", 12);
var font_item, font_group, font_tooltip;
get_font();
function get_font(){
font_item_name = gdi.Font(font_name_item_name, font_size_item_name, font_style_item_name);
font_item_value = gdi.Font(font_name_item_value, font_size_item_value, font_style_item_value);
font_group = gdi.Font(font_name_group, font_size_group, font_style_group);
font_tooltip = gdi.Font(font_name_item_value, font_size_tooltip, font_style_item_value);
}
ColorTypeCUI = {
text: 0,
selection_text: 1,
inactive_selection_text: 2,
background: 3,
selection_background: 4,
inactive_selection_background: 5,
active_item_frame: 6
};
ColorTypeDUI = {
text: 0,
background: 1,
highlight: 2,
selection: 3
};
function get_color(){
if (window.InstanceType == 0){
bgcolor = window.GetColorCUI(ColorTypeCUI.background);
color_item_name = window.GetColorCUI(ColorTypeCUI.text);
color_item_value = window.GetColorCUI(ColorTypeCUI.inactive_selection_text);
color_group_text = window.GetColorCUI(ColorTypeCUI.inactive_selection_background);
} else if (window.InstanceType == 1) {
bgcolor = window.GetColorDUI(ColorTypeDUI.background);
color_item_name = window.GetColorDUI(ColorTypeDUI.text);
color_item_value = window.GetColorDUI(ColorTypeDUI.highlight);
color_group_text = window.GetColorDUI(ColorTypeDUI.selection);
}
window.Repaint();
}
get_color();
function on_colors_changed(){
get_color();
}
var custom_colors = window.GetProperty(" colors: custom", false);
var c_bgcolor = customColor(window.GetProperty(" color: background", "0-0-0"));
var c_color_item_name = customColor(window.GetProperty(" color: item name", "180-180-180"));
var c_color_item_value = customColor(window.GetProperty(" color: item value", "255-255-220"));
var c_color_group_text = customColor(window.GetProperty(" color: group text", "100-100-100"));
bgcolor = custom_colors ? c_bgcolor : bgcolor;
color_item_name = custom_colors ? c_color_item_name : color_item_name;
color_item_value = custom_colors ? c_color_item_value : color_item_value;
color_group_text = custom_colors ? c_color_group_text : color_group_text;
function customColor(colour){
tempc = colour.split("-");
return (0xff000000 | (tempc[0]<<16) | (tempc[1]<<8) | (tempc[2]));
}
var selection_mode = window.GetProperty("selection_mode", 0);
var idx, old_idx;
var item_name_array = [];
var item_name_array_2 = [];
var item_value_array = [];
var tmp_item_name_array = [];
var tmp_item_name_array_2 = [];
var tmp_item_value_array = [];
var name, value;
var artist, old_artist;
var album, old_album;
var similar = [];
var similar_artist = [];///////////
var artist_info = [];
var album_info = [];
var auto_sizing = window.GetProperty("auto sizing", true);
var group_text = window.GetProperty("group text", true);
var vertical_item_padding = window.GetProperty(" vertical item padding", 1);
var clipboard_item_name = window.GetProperty("clipboard item name", false);
var t_h;
var t_x1 = window.GetProperty(" text: margin", 10);
var t_x2;
var text_h;
var panel_h;
window.GetProperty("text: x2 custom", 0);
var lbtn_down = false;
var shift_down = false;
var control_down = false;
var pos_x;
var drag_x = 0, drag_y = 0;
var move_x = false, move_y = false;
var s = 0;
var old_x, old_y;
var Tooltip = window.GetProperty("tooltip", false);
var tooltip_time = fb.CreateProfiler("Time tooltip");
var tooltip_state = false;
var tooltip_text;
var tooltip_t = [];
var tooltip_max_w = window.GetProperty(" tooltip text max width", 250);
var tooltip_delay_time = window.GetProperty(" tooltip delay time", 300);
///// WSH panel
var tooltip = window.CreateTooltip();
///// jscript panel
//var tooltip = window.CreateTooltip(font_name_item_value, font_size_tooltip, font_style_item_value);
//tooltip.SetMaxWidth(tooltip_max_w);
var lang_text = ["en", "ru"];
var lang = window.GetProperty("lang", 0);
htmlfile = new ActiveXObject('htmlfile');
var clipboardData = "";
var doc = new ActiveXObject("htmlfile");
function on_paint(gr) {
!window.IsTransparent && gr.FillSolidRect(0, 0, ww, wh, bgcolor);
draw_array(gr);
gr.GdiDrawText( "", font_item_value, color_item_value, 0, 60, ww, wh, DT_RIGHT | DT_WORD_ELLIPSIS);
gr.GdiDrawText( "", font_item_value, color_item_value, 0, 80, ww, wh, DT_RIGHT | DT_WORD_ELLIPSIS);
gr.GdiDrawText( "", font_item_value, color_item_value, 0, 100, ww, wh, DT_RIGHT | DT_WORD_ELLIPSIS);
gr.GdiDrawText( "", font_item_value, color_item_value, 0, 120, ww, wh, DT_RIGHT | DT_WORD_ELLIPSIS);
gr.GdiDrawText( "", font_item_value, color_item_value, 0, 140, ww, wh, DT_RIGHT | DT_WORD_ELLIPSIS);
}
var groups = ["metadata", "general", "replaygain", "location", "playback statistics", "last.FM statistics", "last.FM"];
window.GetProperty( groups[0], true),
window.GetProperty( groups[1], true),
window.GetProperty( groups[2], true),
window.GetProperty( groups[3], true),
window.GetProperty( groups[4], true),
window.GetProperty( groups[5], true);
window.GetProperty( groups[6], true);
var tfname = [
["$meta(artist)", "Исполнитель"],
["%title%", "Название"],
["%album%", "Альбом"],
["%date%", "Год"],
["%genre%", "Жанр"],
["%composer%", "Композитор"],
["%performer%", "Первый исполнительь"],
["$meta(album artist)", "Исполнитель альбома"],
["%track number%", "Номер трека"],
["%totaltracks%", "Всего треков"],
["%discnumber%", "Номер диска"],
["%totaldiscs%", "Всего дисков"],
["%rating%", "Рейтинг"],
["$meta(rating)", "Рейтинг"],
["%comment%", "Комментарий"],
["%publisher%", "Издатель"],
["%catalog%", "Каталог"],
["%discid%", "ID диска"],
["%label%", "Лейбл"],
["%releaser%", "Продавец"],
["%subtitle%", "Субтитры"],
["group_" + groups[1], "общие"],
["$info(samplerate)", "Частота дискретизации"],
["$info(channels)", "Каналов"],
["$info(bitspersample)", "Бит на семпл"],
["$info(bitrate)", "Битрейт"],
["%codec%", "Кодек"],
["$info(codec_profile)", "Профиль кодека"],
["$info(mp3_stereo_mode)", "Режим стерео MP3"],
["$info(encoding)", "Кодирование"],
["%length%", "Длина"],
["$info(tool)", "Кодировщик"],
["$info(cue_embedded)", "Встроенный CUE"],
["$info(tagtype)", "Тип тега"],
["group_" + groups[2], "Усиление громкости"],
["%replaygain_album_gain%", "Усиление громкости альбома"],
["%replaygain_album_peak%", "Пиковый уровень альбома"],
["%replaygain_track_gain%", "усиление громкости трека"],
["%replaygain_track_peak%", "Пиковый уровень трека"],
["group_" + groups[3], "расположение"],
["%filename_ext%", "Имя файла"],
["$directory_path(%path%)", "Путь к файлу"],
["%url%", "Ссылка"],
["%subsong%", "Позиция трека"],
["%filesize_natural%", "Размер файла"],
["%last_modified%", "Изменен"],
["%folder_name%", "Имя папки"],
["group_" + groups[4], "Cтатистика воспроизведения"],
["%play_count%", "Количество воспроизведений"],
["%first_played%", "Первое воспроизведение"],
["%last_played%", "Последнее воспроизведение"],
["%added%", "Добавлен"],
["group_" + groups[5], "сайт Last.FM"],
["%lastfm_bio%", "Биография"],
["%lastfm_artist_playcount%", "Прослушиваний исполнителя"],
["%lastfm_artist_listeners%", "Слушателей исполнителя"],
["%lastfm_album_playcount%", "Прослушиваний альбома"],
["%lastfm_album_listeners%", "Слушателей альбома"],
["%lastfm_album_content%", "Содержимое альбома"],
["group_" + groups[6], "сайт Last.FM"],
["%lastfm_similar_artist%", "Похожие исполнители"]
];
function set_cursor() {
if (move_y || lbtn_down) window.SetCursor(IDC_HAND);
if (move_x) window.SetCursor(IDC_SIZEWE);
}
var selected_idx = [];
function on_mouse_lbtn_down(x, y) {
lbtn_down = true;
if (move_y) drag_y = y - s;
if (move_x) drag_x = x - t_x2;
if (control_down){
old_idx = idx;
selected_idx[idx] = selected_idx[idx] == 0 ? 1 : 0;
copy_to_clipboard();
}
}
function on_mouse_lbtn_up(x, y) {
lbtn_down = false;
if (move_x) {
window.SetProperty("text: x2 custom", t_x2);
}
}
function on_mouse_lbtn_dblclk(x, y){
group = item_name_array[idx] && item_name_array[idx].search('group') >= 0 ? true : false;
if (group){
group_name = item_name_array[idx].replace("group_", "");
group_collapsed = window.GetProperty(group_name);
window.SetProperty(group_name, !group_collapsed);
create_array();
window.Repaint();
}
if (!control_down){
ini_selected_idx(0);
copy_to_clipboard();
window.Repaint();
}
}
function on_mouse_move(x, y) {
if (shift_down && !move_x) drag_x = x - t_x2;
if (shift_down) drag_y = (y - s);
idx = Math.floor((y + Math.abs(s)) / t_h);
pos_x = x;
mouse_on_pos();
if (old_y != y || old_x != x){
if (Tooltip && !control_down) tooltip_activate_wsh(x, y);
//if (Tooltip) tooltip_activate_jscript(x, y)
old_y = y;
old_x = x;
}
if (lbtn_down && move_y && !control_down) {
if (text_h > panel_h){
s = y - drag_y;
s = s >= 0 ? 0 : s;
s = s <= (panel_h - text_h) && s < 0 ? (panel_h - text_h) : s;
}
}
if (lbtn_down && move_x) {
auto_sizing = false;
window.SetProperty("auto sizing", auto_sizing);
tmp_t_x2 = x - drag_x;
t_x2 = tmp_t_x2 <= t_x1 ? t_x1 : tmp_t_x2 >= ww - t_x1 - 50 ? ww - t_x1 - 50 : tmp_t_x2;
}
if (control_down && lbtn_down && old_idx != idx){
selected_idx[idx] = selected_idx[idx] == 0 ? 1 : 0;
copy_to_clipboard();
old_idx = idx;
}
window.Repaint();
}
function on_mouse_wheel(delta) {
if (move_y) {
if (text_h > panel_h){
if (delta < 0) {s = text_h - Math.abs(s) <= panel_h ? panel_h - text_h : Math.max(s + delta * t_h, panel_h - text_h)};
if (delta > 0) {s = s >= 0 ? 0 : Math.min(0, s + delta * t_h)};
}
window.Repaint();
}
}
function applyDelta() {
s = s > 0 ? 0 : s;
s = s < (wh - item_name_array.length * t_h) && s < 0 ? (wh - item_name_array.length * t_h) : s;
window.Repaint();
}
function on_mouse_leave() {
window.SetCursor(IDC_ARROW);
window.Repaint();
}
function mouse_on_pos(){
if (shift_down && pos_x >= t_x2) {
move_x = true;
move_y = false;
} else {
move_y = true;
move_x = false;
}
set_cursor();
}
function on_key_down(vkey) {
if (vkey == VK_SHIFT){
shift_down = true;
if (lbtn_down) drag_x = pos_x - t_x2;
}
mouse_on_pos();
if (vkey == VK_CONTROL){
control_down = true;
}
if (vkey == VK_ESCAPE){
ini_selected_idx(0);
copy_to_clipboard();
}
}
function on_key_up(vkey) {
if (vkey == VK_SHIFT){
shift_down = false;
}
mouse_on_pos();
if (vkey == VK_CONTROL){
control_down = false;
}
}
function on_size() {
ww = window.Width;
wh = window.Height;
if (wh != wh_old && s < 0) {
s = wh >= wh_old ? 0 : s;
wh_old = wh;
}
create_array();
}
function clear_item_name(n) {
return n.replace(/.*\(|lastfm_|replaygain_|[^a-z0-9\s\_]/g,"").replace(/_/g," ");
//return n.replace(/.*\((?!\))|lastfm_|replaygain_|[^a-z0-9\s\_]/g,"").replace(/_/g," ");
}
function clear_group_text(n) {
return n.replace(/group_/g,"").replace(/(?=.)/g," ").replace(/^\s/g,"")
}
function data_format(n) {
if (!n) return;
d = n.substr(8, 2);
m = parseInt(n.substr(5, 2), 10);
y = n.substr(0, 4);
t = n.substr(11, 8);
m_text = lang == 0 ? months_en[m - 1] : months_ru[m - 1];
return d + " " + m_text + " " + y + ", " + t;
}
var measure_arr = [
["$info(bitrate)", "kbps", "кбит/с"],
["$info(samplerate)", "Hz", "Гц"],
["$info(bitspersample)", "bps", ""],
["$info(channels)", "ch", ""],
["%play_count%", "times", ""]
]
function get_measure(n) {
tmp = "";
var j = 0;
do {
if (measure_arr[j][0] == n) {
tmp = lang == 0 ? measure_arr[j][1] : measure_arr[j][2];
}
j++;
} while (j < measure_arr.length);
return tmp;
}
var months_en = ["Jan.", "Feb.", "Mar.", "Apr.", "May", "Jun.", "Jul.", "Aug.", "Sept.", "Oct.", "Nov.", "Dec."];
var months_ru = ["Янв.", "Фев.", "Мрт", "Апр.", "Май", "Июн.", "Июл.", "Авг.", "Сен.", "Окт.", "Нбр", "Дек."];
function create_array() {
tmp_item_name_array = [];
tmp_item_name_array_2 = [];
tmp_item_value_array = [];
t_x2 = 0;
similar_artist = [];
for (j = 0; j < tfname.length; j++) {
group = tfname[j][0].search('group') >= 0 ? true : false;
var value = "";
if (!group) {
switch (tfname[j][0]) {
case "%lastfm_similar_artist%":
value = Eval(tfname[j][0]) ? Eval(tfname[j][0]) : similar;
break;
case "%lastfm_artist_playcount%":
value = Eval(tfname[j][0]) ? Eval(tfname[j][0]) : artist_info[0];
break;
case "%lastfm_artist_listeners%":
value = Eval(tfname[j][0]) ? Eval(tfname[j][0]) : artist_info[1];
break;
case "%lastfm_album_playcount%":
value = Eval(tfname[j][0]) ? Eval(tfname[j][0]) : album_info[0];
break;
case "%lastfm_album_listeners%":
value = Eval(tfname[j][0]) ? Eval(tfname[j][0]) : album_info[1];
break;
default:
value = Eval(tfname[j][0]);
}
}
if (value && value != 0 || group) {
m_text = get_measure(tfname[j][0]);
value = value + (m_text ? " " + m_text : "");
tmp_item_name_array.push(tfname[j][0]);
tmp_item_name_array_2.push(tfname[j][1]);
if (tfname[j][0] != "%lastfm_similar_artist%"){
tmp_item_value_array.push(value);
}
if (tfname[j][0] == "%lastfm_similar_artist%") {
similar_artist = similar;
}
}
if (value && value != 0 && !group){
tmp = lang == 0 ? clear_item_name(tfname[j][0]) : tfname[j][1];
tmp_t_x2 = calc_text_data("w", tmp, font_item_name);
t_x2 = tmp_t_x2 > t_x2 ? tmp_t_x2 : t_x2;
}
}
t_x2 = auto_sizing ? t_x2 + t_x1 + 10 : window.GetProperty("text: x2 custom");
for (var i = 0; i < similar_artist.length; i++) {
if (i >= 1) {
tmp_item_name_array.push("");
tmp_item_name_array_2.push("");
}
value = similar_artist[i].replace(/^\s+|\s+$/g, "");
tmp_item_value_array.push(value);
}
clear_collapse_expand_groups();
ini_selected_idx(0);
}
function clear_collapse_expand_groups() {
item_name_array = [];
item_name_array_2 = [];
item_value_array = [];
group_name = groups[0];
for (j = 0; j < tmp_item_name_array.length; j++) {
group = tmp_item_name_array[j].search('group') >= 0 ? true : false;
if (group){
group_name = tmp_item_name_array[j].replace("group_", "");
}
selected_items = window.GetProperty(group_name);
item_nane = tmp_item_name_array[j];
item_nane_2 = tmp_item_name_array_2[j];
item_value = tmp_item_value_array[j];
if (!group){
if (selected_items){
item_name_array.push(item_nane);
item_name_array_2.push(item_nane_2);
item_value_array.push(item_value);
}
}
if (group){
if (tmp_item_value_array[j + 1]){
item_name_array.push(item_nane);
item_name_array_2.push(item_nane_2);
item_value_array.push(item_value);
}
}
}
}
function draw_array(gr) {
f_h_name = gr.CalcTextHeight("Text", font_item_name);
f_h_value = gr.CalcTextHeight("Text", font_item_value);
f_h = Math.max(f_h_name, f_h_value);
t_h = f_h + window.GetProperty(" vertical item padding");
text_h = item_name_array.length * t_h;
panel_h = Math.round(window.Height / t_h) * t_h;
if (text_h < panel_h && s < 0) s = 0;
star_size = f_h_value - 3;
star_offset = star_size + 2;
for (var i = 0; i < item_name_array.length; i++) {
group = item_name_array[i].search('group') >= 0 ? true : false;
t_y = i * t_h + s;
l_y = t_y + t_h / 2;
if (!group){
name = clear_item_name(item_name_array[i]);
rating_text = item_name_array[i] == "$meta(rating)" ? lang == 0 ? " (tag)" : " (тег)" : "";
t_w = Math.min(ww - (ww - t_x2)- t_x1, ww - t_x1 * 2) - 10;
name = lang == 0 ? name : item_name_array_2[i];
gr.GdiDrawText(name + rating_text, font_item_name, color_item_name, t_x1, t_y, t_w, t_h, DT_LEFT | DT_SINGLELINE | DT_VCENTER | DT_WORD_ELLIPSIS | DT_NOPREFIX);
}
if (group){
name = lang == 0 ? item_name_array[i] : item_name_array_2[i];
name = group_text ? clear_group_text(name) : "";
t_w = ww - t_x1 * 2;
group_name = item_name_array[i].replace("group_", "");
group_collapsed = window.GetProperty(group_name);
color = color_group_text;
gr.GdiDrawText(name, font_group, color, t_x1, t_y, t_w, t_h, DT_LEFT | DT_SINGLELINE | DT_VCENTER | DT_WORD_ELLIPSIS | DT_NOPREFIX);
l_x = group_text && name ? Math.min(gr.CalcTextWidth(name, font_group) + 5, ww - t_x1 * 2) : 0;
gr.DrawLine(t_x1 + l_x, l_y, ww - t_x1, l_y, 1, color_group_text);
}
var color = selected_idx[i] == 0 ? color_item_value : color_item_name;
if (item_name_array[i].search(/rating/g) > 0){
for (var r = 0; r < Math.min(item_value_array[i] * star_offset, ww - t_x2 - t_x1); r = r + star_offset) {
draw_star(gr, t_x2 + star_size / 3 + r, t_y + t_h / 2, star_size, true, 0, color, false, bgcolor, 255);
}
} else {
value = item_name_array[i].search(/_modified|_played|_played|added/g) > 0 ? data_format(item_value_array[i]) : item_value_array[i];
t_w2 = ww - t_x2 - t_x1;
gr.GdiDrawText( value, font_item_value, color, t_x2, t_y, t_w2, t_h, DT_LEFT | DT_SINGLELINE | DT_VCENTER | DT_WORD_ELLIPSIS | DT_NOPREFIX);
}
}
}
var metadb;
on_item_focus_change();
function on_playlist_switch() {
on_item_focus_change();
}
function on_playback_new_track() {
on_item_focus_change();
}
function on_playback_dynamic_info_track() {
on_item_focus_change();
}
function on_playback_stop() {
on_item_focus_change();
}
function on_selection_changed(metadb) {
on_item_focus_change();
}
function on_item_focus_change() {
switch (selection_mode) {
case 0:
metadb = fb.IsPlaying ? fb.GetNowPlaying() : fb.GetFocusItem();
break;
case 1:
metadb = fb.GetFocusItem();
break;
}
if (metadb) on_metadb_changed();
}
function on_metadb_changed() {
//artist = Eval("%artist%") ? Eval("%artist%") : "";
//album = Eval("%album%") ? Eval("%album%") : "";
artist = Eval("%artist%");
album = Eval("%album%");
if (artist != old_artist) {
similar = [];
get_lastFM_similar(artist);
artist_info = [];
get_lastFM_artist_info(artist);
old_artist = artist;
}
if (album != old_album) {
album_info = [];
get_lastFM_album_info(artist, album)
old_album = album;
}
create_array();
window.Repaint();
}
function Eval(field) {
if (metadb) {
type = metadb.RawPath;
if (type.indexOf("file") >= 0){
return fb.TitleFormat("[" + field + "]").EvalWithMetadb(metadb);
} else{
if (selection_mode == 0){
if (field == "$meta(artist)" || field == "%title%" || field == "%artist%"){
return fb.TitleFormat("[" + field + "]").Eval(true);
}
if (field == "%genre%"){
return fb.TitleFormat("[" + field + "]").EvalWithMetadb(metadb);
}
}
return fb.TitleFormat("[" + field + "]").EvalWithMetadb(metadb);
}
}
}
function on_mouse_rbtn_up (x, y){
tooltip_state && tooltip.Deactivate();
var _menu = window.CreatePopupMenu();
_menu.AppendMenuItem(MF_ENABLED, 10, "Prefer now playing");
_menu.AppendMenuItem(MF_ENABLED, 11, "Follow selected track");
_menu.CheckMenuRadioItem(10, 11, selection_mode + 10);
_menu.EnableMenuItem(selection_mode + 10, 1);
_menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
_menu.AppendMenuItem(MF_ENABLED, 20, "Group text");
_menu.CheckMenuItem(20, group_text);
_menu.AppendMenuItem(MF_ENABLED, 30, "Tooltip");
_menu.CheckMenuItem(30, Tooltip);
_menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
_menu.AppendMenuItem(MF_ENABLED, 50, "Create txt/xls file");
_menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
MF_STRING = auto_sizing ? MF_GRAYED : MF_ENABLED;
_menu.AppendMenuItem(MF_STRING, 60, "Auto-sizing columns");
_menu.CheckMenuItem(60, auto_sizing);
_menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
_menu.AppendMenuItem(MF_ENABLED, 70, "Item text: " + lang_text[0]);
_menu.AppendMenuItem(MF_ENABLED, 71, "Item text: " + lang_text[1]);
_menu.CheckMenuRadioItem(70, 71, lang + 70);
_menu.EnableMenuItem(lang + 70, 1);
_menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
_menu.AppendMenuItem(MF_ENABLED, 80, "Copy to clipboard (all)");
_menu.AppendMenuItem(MF_ENABLED, 81, "Copy item name");
_menu.CheckMenuItem(81, clipboard_item_name);
_menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
_menu.AppendMenuItem(MF_ENABLED, 100, "Reload");
_menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
_menu.AppendMenuItem(MF_ENABLED, 200, "Properties");
_menu.AppendMenuItem(MF_ENABLED, 300, "Configure ...");
ret = _menu.TrackPopupMenu(x,y);
switch (ret) {
case 10:
case 11:
selection_mode = ret - 10;
window.SetProperty("selection_mode", selection_mode);
on_item_focus_change();
break;
case 20:
window.SetProperty("group text", !group_text);
group_text = window.GetProperty("group text");
break;
case 30:
window.SetProperty("tooltip", !Tooltip);
Tooltip = window.GetProperty("tooltip");
deactive_tooltip();
break;
case 50:
menu_create_file(x,y);
break;
case 60:
if (!auto_sizing){
auto_sizing = true;
window.SetProperty("auto sizing", auto_sizing);
create_array();
}
break;
case 70:
case 71:
lang = ret - 70;
window.SetProperty("lang", lang);
create_array();
break;
case 80:
ini_selected_idx(1);
copy_to_clipboard();
break;
case 81:
window.SetProperty("clipboard item name", !clipboard_item_name);
clipboard_item_name = window.GetProperty("clipboard item name");
on_mouse_rbtn_up (x, y);
break;
case 100:
try {
window.Reload();
} catch(e) {};
break;
case 200:
window.ShowProperties();
break;
case 300:
window.ShowConfigure();
break;
}
_menu.Dispose();
return true;
}
///////////////////////////// Create file
var fso = new ActiveXObject("Scripting.FileSystemObject");
var output_path = fb.ProfilePath + "\\tmp_Properties\\";
function check_folder(n) {
if (!n) return;
try {
if(!fso.FolderExists(n)) {fso.CreateFolder(n)};
} catch(e) {}
}
window.GetProperty("ext",1);
var separator = Array(" ; ","\t");
var tmp_output_item_name_array = [];
var output_array = [];
var pllist_name;
var selected;
var shift = 0;
create_tmp_output_item_name_array();
function create_tmp_output_item_name_array() {
tmp_output_item_name_array = [];
for (var j = 0; j < tfname.length; j++) {
if (tfname[j][0].search(/group|lastfm/g) < 0){
//if (tfname[j].indexOf('group') < 0 || tfname[j].indexOf('%lastfm') < 0){
tmp_output_item_name_array.push(tfname[j][0]);
}
}
}
for (var j = 0; j < tmp_output_item_name_array.length; j++) {
//window.GetProperty(j + 1, 0);
window.GetProperty(j + 1, false);
}
function create_output_array() {
output_array = [];
for (var j = 0; j < tmp_output_item_name_array.length; j++) {
selected = window.GetProperty(j + 1);
//if ( selected == 1 ) {output_array.push(tmp_output_item_name_array[j])};
if ( selected ) {output_array.push(tmp_output_item_name_array[j])};
}
createTextFile();
}
function createTextFile(){
check_folder(output_path);
count = plman.GetPlaylistSelectedItems(plman.ActivePlaylist).Count;
if (count == 0 || output_array.length == 0) return;
if (window.GetProperty("ext") == 0) {
output_file = output_path + "plist " + pllist_name + ".txt";
} else {
output_file = output_path + "plist " + pllist_name + ".xls";
}
try { file = fso.CreateTextFile( output_file )
} catch(e) { return };
var text_item_name = [];
var string_item_name = "";
for (var j = 0; j < output_array.length; j++) {
text_item_name.push(output_array[j]);
}
string_item_name = text_item_name.join(separator[window.GetProperty("ext")]);
file.WriteLine(string_item_name);
file.WriteLine("");
for (var i = 0; i < count; i++) {
item = plman.GetPlaylistSelectedItems(plman.ActivePlaylist).Item(i);
var text_item_value = [];
var string_item_value = "";
for (var j = 0; j < output_array.length; j++) {
value = fb.TitleFormat("[" + output_array[j] + "]").EvalWithMetadb(item);
text = get_measure(output_array[j]);
text = value && text ? " " + text : "";
text_item_value.push(value + text);
string_item_value = text_item_value.join(separator[window.GetProperty("ext")]);
}
try { file.WriteLine(string_item_value);
} catch(e) {};
}
file.Close();
}
function menu_create_file(x, y){
var _menu = window.CreatePopupMenu();
var i = 1;
count = plman.GetPlaylistSelectedItems(plman.ActivePlaylist).Count;
MF_STRING = count == 0 ? MF_GRAYED : MF_ENABLED;
pllist_name = plman.GetPlaylistName(plman.ActivePlaylist);
pllist_name = count == 0 ? "*" : pllist_name.replace(/[\/\:\*\?\"\<\>\|]/g,'');
_menu.AppendMenuItem(MF_STRING, i++, "Create " + pllist_name + (window.GetProperty("ext") == 0 ? ".txt" : ".xls"));
_menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
var lines = 20;
bl = tmp_output_item_name_array.length > lines ? lines + shift : tmp_output_item_name_array.length;
for (var j = shift; j < bl; j++) {
menuItem = clear_item_name(tmp_output_item_name_array[j]);
_menu.AppendMenuItem(MF_ENABLED, i++, menuItem);
_menu.CheckMenuItem(i - 1, window.GetProperty(i - 2 + shift));
// _menu.CheckMenuItem(i - 1, sel_arr[i - 3 + shift]);
}
_menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
_menu.AppendMenuItem(MF_ENABLED, 100, "txt");
_menu.AppendMenuItem(MF_ENABLED, 101, "xls");
_menu.CheckMenuRadioItem(100, 101, 100 + window.GetProperty("ext"));
_menu.EnableMenuItem(100 + window.GetProperty("ext"), 1);
_menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
_menu.AppendMenuItem(MF_ENABLED, 110, "Select all");
_menu.AppendMenuItem(MF_ENABLED, 120, "Clear all");
if (tmp_output_item_name_array.length > lines) {
_menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
_menu.AppendMenuItem(shift == 0 ? MF_GRAYED : MF_ENABLED, 130, "Up");
_menu.AppendMenuItem(shift + lines >= tmp_output_item_name_array.length ? MF_GRAYED : MF_ENABLED, 140, "Down");
}
ret = _menu.TrackPopupMenu(x, y - 250);
switch (true) {
case (ret == 1):
create_output_array();
break;
case (ret >= 2 && ret <= tmp_output_item_name_array.length + 1):
selected = window.GetProperty(ret - 1 + shift);
//window.SetProperty(ret - 1 + shift, selected == 0 ? 1 : 0);
window.SetProperty(ret - 1 + shift, selected == false ? true : false);
menu_create_file(x,y);
break;
case (ret == 100):
window.SetProperty("ext", 0);
menu_create_file(x,y);
break;
case (ret == 101):
window.SetProperty("ext", 1);
menu_create_file(x,y);
break;
case (ret == 110):
for (var j = 1; j < tmp_output_item_name_array.length + 1; j++) {
//window.SetProperty(j, 1);
window.SetProperty(j, true);
}
menu_create_file(x,y);
break;
case (ret == 120):
for (var j = 1; j < tmp_output_item_name_array.length + 1; j++) {
//window.SetProperty(j, 0);
window.SetProperty(j, false);
}
menu_create_file(x,y);
break;
case (ret == 130):
shift = shift - 1;
menu_create_file(x,y);
break;
case (ret == 140):
shift = shift + 1;
menu_create_file(x,y);
break;
}
_menu.Dispose();
}
///////////////////////////// Copy to clipboard
function ini_selected_idx(n){
for (j = 0; j < item_name_array.length; j++) {
selected_idx[j] = n;
}
}
function copy_to_clipboard(){
var clipboard_text = "";
for (var i = 0; i < item_name_array.length; i++) {
if (selected_idx[i] > 0){
group = item_name_array[i].search('group') >= 0 ? true : false;
if (!group){
name = clear_item_name(item_name_array[i]);
rating_text = item_name_array[i] == "$meta(rating)" ? lang == 0 ? " (tag)" : " (тег)" : "";
name = lang == 0 ? name : item_name_array_2[i];
value = item_value_array[i];
name = clipboard_item_name ? name + "\t" : "";
clipboard_text = clipboard_text + name + value + (i < item_name_array.length - 1 ? "\r\n" : "");
}
}
}
htmlfile.parentWindow.clipboardData.setData("text", clipboard_text);
}
///////////////////////////// Draw star
function draw_star(gr, x, y, img_size, fill, line_thickness, color, sh, sh_color, alpha){
var radius = img_size / 2;
var radius_2 = radius / 2.61803;
line_thickness = line_thickness >= radius_2 ? radius_2 : line_thickness;
var delta = line_thickness / 2 * Math.tan(72 / 180 * Math.PI);
var points = [], sh_points = [];
var x_points_1 = [], y_points_1 = [], x_points_2 = [], y_points_2 = [];
for (var i = 0; i < 10; i++) {
if (i % 2 == 0) {
x_points_1.push((radius - delta) * Math.cos(Math.PI * i / 10 * 2 - Math.PI / 2));
y_points_1.push((radius - delta) * Math.sin(Math.PI * i / 10 * 2 - Math.PI / 2));
} else {
x_points_2.push((radius - delta) / 2.61803 * Math.cos(Math.PI * i / 10 * 2 - Math.PI / 2));
y_points_2.push((radius - delta) / 2.61803 * Math.sin(Math.PI * i / 10 * 2 - Math.PI / 2));
}
}
for (var i = 0; i < 5; i++) {
points.push(x_points_1[i] + radius, y_points_1[i] + radius, x_points_2[i] + radius, y_points_2[i] + radius);
sh_points.push(x_points_1[i] + radius + 1, y_points_1[i] + radius + 1, x_points_2[i] + radius + 1, y_points_2[i] + radius + 1);
}
var img = gdi.CreateImage(img_size, img_size);
var temp_gr = img.GetGraphics();
temp_gr.SetSmoothingMode(2);
if (line_thickness > 0) {
sh && temp_gr.DrawPolygon(sh_color, line_thickness, sh_points);
temp_gr.DrawPolygon(color, line_thickness, points);
}
if (fill && line_thickness == 0) {
sh && temp_gr.FillPolygon(sh_color, 1, sh_points);
temp_gr.FillPolygon(color, 1, points)
}
gr.DrawImage(img, x - radius, y - radius, img_size, img_size, 0, 0, img_size, img_size, 0, alpha);
img.ReleaseGraphics(temp_gr);
img.Dispose();
temp_gr = null;
img = null;
}
///////////////////////////// wsh tooltip (custom paint)
function active_tooltip(){
if (!tooltip_state){
tooltip_state = true;
tooltip.Activate();
tooltip.TrackActivate = true;
}
}
function deactive_tooltip(){
if (tooltip_state){
tooltip.Deactivate();
tooltip.TrackActivate = false;
tooltip_state = false;
}
}
function on_tooltip_custom_paint(gr){
for (var i = 0; i < tooltip_t.length; i += 1) {
gr.GdiDrawText( tooltip_t[i], font_tooltip, RGB(0,0,0), 5, tooltip_t_h * i + 1, tooltip.Width, tooltip.Height, DT_LEFT | DT_WORDBREAK | DT_NOPREFIX );
}
}
function tooltip_activate_wsh(x, y) {
tooltip_x = t_x2 - 5;
tooltip_y = idx * t_h - Math.abs(s);
var value_width = calc_text_data( "w", item_value_array[idx], font_item_value );
if (value_width > ww - t_x2 - t_x1 && x > t_x2 && x < ww - t_x1 && y > tooltip_y + 1 && y < tooltip_y + t_h - 1){
if (tooltip_time.Time > tooltip_delay_time && !tooltip_state) {
tooltip_text = item_value_array[idx];
calc_tooltip_dim();
tooltip.TrackPosition( tooltip_x, tooltip_y + window.GetProperty(" vertical item padding") / 2);
active_tooltip();
tooltip.Text = " ";
}
} else {
tooltip_time.Reset();
deactive_tooltip();
}
}
function calc_tooltip_dim(){
tooltip_t_w = calc_text_data( "w", tooltip_text, font_tooltip );
tooltip_t_h = calc_text_data( "h", tooltip_text, font_tooltip );
tooltip_t_tmp = calc_text_data( "a", tooltip_text, font_tooltip, tooltip_max_w );
tooltip_t = [];
tooltip_l = [];
for (var i = 0; i < tooltip_t_tmp.length; i += 1) {
if (i % 2 == 0) {
tooltip_t.push(tooltip_t_tmp[i].replace(/^\s+|\s+$/g, ""));
} else {
tooltip_l.push(tooltip_t_tmp[i]);
}
}
if (tooltip_t_w <= tooltip_max_w){
tooltip.Width = tooltip_t_w + 5;
tooltip.Height = tooltip_t_h;
} else {
tooltip.Width = Math.max.apply(null, tooltip_l) + 5;
tooltip.Height = tooltip_t_h * tooltip_t.length;
}
}
function calc_text_data(d, text, font, max_w) {
var temp_bmp = gdi.CreateImage(1, 1);
var temp_gr = temp_bmp.GetGraphics();
var tmp;
switch (d) {
case "w":
tmp = temp_gr.CalcTextWidth(text, font);
break;
case "h":
tmp = temp_gr.CalcTextHeight(text, font);
break;
case "a":
tmp = temp_gr.EstimateLineWrap(text, font, max_w).toArray();
break;
}
temp_bmp.ReleaseGraphics(temp_gr);
temp_bmp.Dispose();
temp_gr = null;
temp_bmp = null;
return tmp;
}
///////////////////////////// jscript tooltip
function tooltip_activate_jscript(x, y) {
tooltip_x = t_x2 - 5;
tooltip_y = idx * t_h - Math.abs(s);
var value_width = calc_text_data("w", item_value_array[idx], font_item_value)
if (value_width > ww - t_x2 - t_x1 && x > t_x2 && x < ww - t_x1 && y > tooltip_y + 1 && y < tooltip_y + t_h - 1){
if (tooltip_time.Time > tooltip_delay_time) {
tooltip.Text = item_value_array[idx];
tooltip.TrackPosition( tooltip_x, tooltip_y + window.GetProperty(" vertical item padding") / 2);
tooltip.TrackActivate = true;
tooltip.Activate();
tooltip_state = true;
}
} else {
tooltip.Deactivate();
tooltip.TrackActivate = false;
tooltip_time.Reset();
tooltip_state = false;
}
}
function get_lastFM_similar(a){
if (!a) return
var xmlhttp0 = new ActiveXObject("Microsoft.XMLHTTP");
var url0 = ("https://www.last.fm/music/" + encodeURIComponent(a) + "/+similar");
xmlhttp0.open("GET", url0, true );
xmlhttp0.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
xmlhttp0.send(null);
xmlhttp0.onreadystatechange = function () {
if (xmlhttp0.readyState == 4) {
if (xmlhttp0.status == 200) {
doc.open();
var div = doc.createElement("div");
div.innerHTML = xmlhttp0.responsetext;
var a = div.getElementsByTagName("a");
j = 0;
for (i = 0; i < a.length; i++) {
if (a[i].className == "link-block-target"){
similar[j] = a[i].innerHTML.replace(/(&)/g,'&');
j++
if (j == 6) break;
}
}
doc.close();
create_array();
window.Repaint();
}
}
}
}
function get_lastFM_artist_info(a){
if (!a) return
var xmlhttp1 = new ActiveXObject("Microsoft.XMLHTTP");
var url1 = ("https://www.last.fm/music/" + encodeURIComponent(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 abbr = div.getElementsByTagName("abbr");
for (i = 0; i < abbr.length; i++) {
if (abbr[i].className == "intabbr"){
artist_info.push(abbr[i].title.replace(/\,/g, " "));
}
}
doc.close();
create_array();
window.Repaint();
}
}
}
}
function get_lastFM_album_info(a, al){
if (!a || !al) return
var xmlhttp2 = new ActiveXObject("Microsoft.XMLHTTP");
var url2 = ("https://www.last.fm/music/" + encodeURIComponent(a) + "/" + encodeURIComponent(al));
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 abbr = div.getElementsByTagName("abbr");
var tmp = [];
for (i = 0; i < abbr.length; i++) {
if (abbr[i].className == "intabbr"){
album_info.push(abbr[i].title.replace(/\,/g, " "));
}
}
doc.close();
create_array();
window.Repaint();
}
}
}
}
function print(msg) {
fb.trace(msg);
}
// ==PREPROCESSOR==
// @name "Properties & properties file (ml)"
// @author "kgena_ua"
// @version "25102017"
// @feature "v1.4"
// @feature "watch-metadb"
// @tooltip "custom-paint"
// ==/PREPROCESSOR==
function RGB(r,g,b) { return (0xff000000|(r<<16)|(g<<8)|(b)); }
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, wh_old;
IDC_HAND = 32649;
IDC_ARROW = 32512;
IDC_SIZEWE = 32644;
MF_ENABLED = 0x00000000;
MF_GRAYED = 0x00000001;
MF_SEPARATOR = 0x00000800;
VK_SHIFT = 0x10;
VK_CONTROL = 0x11;
VK_ESCAPE = 0x1B;
String.prototype.repeat = function(n) {
return new Array(n + 1).join(this);
}
window.SetProperty(" - user", "");
if (window.GetProperty(" - user") != "" ) window.SetProperty(" - user", "");
window.SetProperty("-".repeat(50), "");
if (window.GetProperty("-".repeat(50)) != "" ) window.SetProperty("-".repeat(50), "");
var font_name_item_name = window.GetProperty(" font name: item name", "Arial");
var font_name_item_value = window.GetProperty(" font name: item value", "Arial");
var font_name_group = window.GetProperty(" font name: group", "Arial");
var font_size_item_name = window.GetProperty(" font size: item name", 11);
var font_size_item_value = window.GetProperty(" font size: item value", 12);
var font_size_group = window.GetProperty(" font size: group", 11);
var font_style_item_name = window.GetProperty(" font style: item name", 0);
var font_style_item_value = window.GetProperty(" font style: item value", 0);
var font_style_group = window.GetProperty(" font style: group", 0);
var font_size_tooltip = window.GetProperty(" font size: tooltip", 12);
var font_item, font_group, font_tooltip;
get_font();
function get_font(){
font_item_name = gdi.Font(font_name_item_name, font_size_item_name, font_style_item_name);
font_item_value = gdi.Font(font_name_item_value, font_size_item_value, font_style_item_value);
font_group = gdi.Font(font_name_group, font_size_group, font_style_group);
font_tooltip = gdi.Font(font_name_item_value, font_size_tooltip, font_style_item_value);
}
ColorTypeCUI = {
text: 0,
selection_text: 1,
inactive_selection_text: 2,
background: 3,
selection_background: 4,
inactive_selection_background: 5,
active_item_frame: 6
};
ColorTypeDUI = {
text: 0,
background: 1,
highlight: 2,
selection: 3
};
function get_color(){
if (window.InstanceType == 0){
bgcolor = window.GetColorCUI(ColorTypeCUI.background);
color_item_name = window.GetColorCUI(ColorTypeCUI.text);
color_item_value = window.GetColorCUI(ColorTypeCUI.inactive_selection_text);
color_group_text = window.GetColorCUI(ColorTypeCUI.inactive_selection_background);
} else if (window.InstanceType == 1) {
bgcolor = window.GetColorDUI(ColorTypeDUI.background);
color_item_name = window.GetColorDUI(ColorTypeDUI.text);
color_item_value = window.GetColorDUI(ColorTypeDUI.highlight);
color_group_text = window.GetColorDUI(ColorTypeDUI.selection);
}
window.Repaint();
}
get_color();
function on_colors_changed(){
get_color();
}
var custom_colors = window.GetProperty(" colors: custom", false);
var c_bgcolor = customColor(window.GetProperty(" color: background", "0-0-0"));
var c_color_item_name = customColor(window.GetProperty(" color: item name", "180-180-180"));
var c_color_item_value = customColor(window.GetProperty(" color: item value", "255-255-220"));
var c_color_group_text = customColor(window.GetProperty(" color: group text", "100-100-100"));
bgcolor = custom_colors ? c_bgcolor : bgcolor;
color_item_name = custom_colors ? c_color_item_name : color_item_name;
color_item_value = custom_colors ? c_color_item_value : color_item_value;
color_group_text = custom_colors ? c_color_group_text : color_group_text;
function customColor(colour){
tempc = colour.split("-");
return (0xff000000 | (tempc[0]<<16) | (tempc[1]<<8) | (tempc[2]));
}
var selection_mode = window.GetProperty("selection_mode", 0);
var idx, old_idx;
var item_name_array = [];
var item_name_array_2 = [];
var item_value_array = [];
var tmp_item_name_array = [];
var tmp_item_name_array_2 = [];
var tmp_item_value_array = [];
var name, value;
var artist, old_artist;
var album, old_album;
var similar;
var similar_artist = [];///////////
var artist_info = [];
var album_info = [];
var auto_sizing = window.GetProperty("auto sizing", true);
var group_text = window.GetProperty("group text", true);
var vertical_item_padding = window.GetProperty(" vertical item padding", 1);
var clipboard_item_name = window.GetProperty("clipboard item name", false);
var t_h;
var t_x1 = window.GetProperty(" text: margin", 10);
var t_x2;
var text_h;
var panel_h;
window.GetProperty("text: x2 custom", 0);
var lbtn_down = false;
var shift_down = false;
var control_down = false;
var pos_x;
var drag_x = 0, drag_y = 0;
var move_x = false, move_y = false;
var s = 0;
var old_x, old_y;
var Tooltip = window.GetProperty("tooltip", false);
var tooltip_time = fb.CreateProfiler("Time tooltip");
var tooltip_state = false;
var tooltip_text;
var tooltip_t = [];
var tooltip_max_w = window.GetProperty(" tooltip text max width", 250);
var tooltip_delay_time = window.GetProperty(" tooltip delay time", 300);
///// WSH panel
var tooltip = window.CreateTooltip();
///// jscript panel
//var tooltip = window.CreateTooltip(font_name_item_value, font_size_tooltip, font_style_item_value);
//tooltip.SetMaxWidth(tooltip_max_w);
var lang_text = ["en", "ru"];
var lang = window.GetProperty("lang", 0);
htmlfile = new ActiveXObject('htmlfile');
var clipboardData = "";
var doc = new ActiveXObject("htmlfile");
function on_paint(gr) {
!window.IsTransparent && gr.FillSolidRect(0, 0, ww, wh, bgcolor);
draw_array(gr);
gr.GdiDrawText( "", font_item_value, color_item_value, 0, 60, ww, wh, DT_RIGHT | DT_WORD_ELLIPSIS);
}
var groups = ["metadata", "general", "replaygain", "location", "playback statistics", "last.FM statistics", "last.FM"];
window.GetProperty( groups[0], true),
window.GetProperty( groups[1], true),
window.GetProperty( groups[2], true),
window.GetProperty( groups[3], true),
window.GetProperty( groups[4], true),
window.GetProperty( groups[5], true);
window.GetProperty( groups[6], true);
var tfname = [
["$meta(artist)", "Исполнитель"],
["%title%", "Название"],
["%album%", "Альбом"],
["%date%", "Год"],
["%genre%", "Жанр"],
["%composer%", "Композитор"],
["%performer%", "Первый исполнительь"],
["$meta(album artist)", "Исполнитель альбома"],
["%track number%", "Номер трека"],
["%totaltracks%", "Всего треков"],
["%discnumber%", "Номер диска"],
["%totaldiscs%", "Всего дисков"],
["%rating%", "Рейтинг"],
["$meta(rating)", "Рейтинг"],
["%comment%", "Комментарий"],
["%publisher%", "Издатель"],
["%catalog%", "Каталог"],
["%discid%", "ID диска"],
["%label%", "Лейбл"],
["%releaser%", "Продавец"],
["%subtitle%", "Субтитры"],
["group_" + groups[1], "общие"],
["$info(samplerate)", "Частота дискретизации"],
["$info(channels)", "Каналов"],
["$info(bitspersample)", "Бит на семпл"],
["$info(bitrate)", "Битрейт"],
["%codec%", "Кодек"],
["$info(codec_profile)", "Профиль кодека"],
["$info(mp3_stereo_mode)", "Режим стерео MP3"],
["$info(encoding)", "Кодирование"],
["%length%", "Длина"],
["$info(tool)", "Кодировщик"],
["$info(cue_embedded)", "Встроенный CUE"],
["$info(tagtype)", "Тип тега"],
["group_" + groups[2], "Усиление громкости"],
["%replaygain_album_gain%", "Усиление громкости альбома"],
["%replaygain_album_peak%", "Пиковый уровень альбома"],
["%replaygain_track_gain%", "усиление громкости трека"],
["%replaygain_track_peak%", "Пиковый уровень трека"],
["group_" + groups[3], "расположение"],
["%filename_ext%", "Имя файла"],
["$directory_path(%path%)", "Путь к файлу"],
["%url%", "Ссылка"],
["%subsong%", "Позиция трека"],
["%filesize_natural%", "Размер файла"],
["%last_modified%", "Изменен"],
["%folder_name%", "Имя папки"],
["group_" + groups[4], "Cтатистика воспроизведения"],
["%play_count%", "Количество воспроизведений"],
["%first_played%", "Первое воспроизведение"],
["%last_played%", "Последнее воспроизведение"],
["%added%", "Добавлен"],
["group_" + groups[5], "сайт Last.FM"],
["%lastfm_bio%", "Биография"],
["%lastfm_album_listeners%", "Слушателей альбома"],
["%lastfm_album_playcount%", "Прослушиваний альбома"],
["%lastfm_artist_listeners%", "Слушателей исполнителя"],
["%lastfm_artist_playcount%", "Прослушиваний исполнителя"],
["%lastfm_album_content%", "Содержимое альбома"],
["group_" + groups[6], "сайт Last.FM"],
["%lastfm_similar_artist%", "Похожие исполнители"]
];
function set_cursor() {
if (move_y || lbtn_down) window.SetCursor(IDC_HAND);
if (move_x) window.SetCursor(IDC_SIZEWE);
}
var selected_idx = [];
function on_mouse_lbtn_down(x, y) {
lbtn_down = true;
if (move_y) drag_y = y - s;
if (move_x) drag_x = x - t_x2;
if (control_down){
old_idx = idx;
selected_idx[idx] = selected_idx[idx] == 0 ? 1 : 0;
copy_to_clipboard();
}
}
function on_mouse_lbtn_up(x, y) {
lbtn_down = false;
if (move_x) {
window.SetProperty("text: x2 custom", t_x2);
}
}
function on_mouse_lbtn_dblclk(x, y){
group = item_name_array[idx] && item_name_array[idx].search('group') >= 0 ? true : false;
if (group){
group_name = item_name_array[idx].replace("group_", "");
group_collapsed = window.GetProperty(group_name);
window.SetProperty(group_name, !group_collapsed);
create_array();
window.Repaint();
}
if (!control_down){
ini_selected_idx(0);
copy_to_clipboard();
window.Repaint();
}
}
function on_mouse_move(x, y) {
if (shift_down && !move_x) drag_x = x - t_x2;
if (shift_down) drag_y = (y - s);
idx = Math.floor((y + Math.abs(s)) / t_h);
pos_x = x;
mouse_on_pos();
if (old_y != y || old_x != x){
if (Tooltip && !control_down) tooltip_activate_wsh(x, y);
//if (Tooltip) tooltip_activate_jscript(x, y)
old_y = y;
old_x = x;
}
if (lbtn_down && move_y && !control_down) {
if (text_h > panel_h){
s = y - drag_y;
s = s >= 0 ? 0 : s;
s = s <= (panel_h - text_h) && s < 0 ? (panel_h - text_h) : s;
}
}
if (lbtn_down && move_x) {
auto_sizing = false;
window.SetProperty("auto sizing", auto_sizing);
tmp_t_x2 = x - drag_x;
t_x2 = tmp_t_x2 <= t_x1 ? t_x1 : tmp_t_x2 >= ww - t_x1 - 50 ? ww - t_x1 - 50 : tmp_t_x2;
}
if (control_down && lbtn_down && old_idx != idx){
selected_idx[idx] = selected_idx[idx] == 0 ? 1 : 0;
copy_to_clipboard();
old_idx = idx;
}
window.Repaint();
}
function on_mouse_wheel(delta) {
if (move_y) {
if (text_h > panel_h){
if (delta < 0) {s = text_h - Math.abs(s) <= panel_h ? panel_h - text_h : Math.max(s + delta * t_h, panel_h - text_h)};
if (delta > 0) {s = s >= 0 ? 0 : Math.min(0, s + delta * t_h)};
}
window.Repaint();
}
}
function applyDelta() {
s = s > 0 ? 0 : s;
s = s < (wh - item_name_array.length * t_h) && s < 0 ? (wh - item_name_array.length * t_h) : s;
window.Repaint();
}
function on_mouse_leave() {
window.SetCursor(IDC_ARROW);
window.Repaint();
}
function mouse_on_pos(){
if (shift_down && pos_x >= t_x2) {
move_x = true;
move_y = false;
} else {
move_y = true;
move_x = false;
}
set_cursor();
}
function on_key_down(vkey) {
if (vkey == VK_SHIFT){
shift_down = true;
if (lbtn_down) drag_x = pos_x - t_x2;
}
mouse_on_pos();
if (vkey == VK_CONTROL){
control_down = true;
}
if (vkey == VK_ESCAPE){
ini_selected_idx(0);
copy_to_clipboard();
}
}
function on_key_up(vkey) {
if (vkey == VK_SHIFT){
shift_down = false;
}
mouse_on_pos();
if (vkey == VK_CONTROL){
control_down = false;
}
}
function on_size() {
ww = window.Width;
wh = window.Height;
if (wh != wh_old && s < 0) {
s = wh >= wh_old ? 0 : s;
wh_old = wh;
}
create_array();
}
function clear_item_name(n) {
return n.replace(/.*\(|lastfm_|replaygain_|[^a-z0-9\s\_]/g,"").replace(/_/g," ");
//return n.replace(/.*\((?!\))|lastfm_|replaygain_|[^a-z0-9\s\_]/g,"").replace(/_/g," ");
}
function clear_group_text(n) {
return n.replace(/group_/g,"").replace(/(?=.)/g," ").replace(/^\s/g,"")
}
function data_format(n) {
if (!n) return;
d = n.substr(8, 2);
m = parseInt(n.substr(5, 2), 10);
y = n.substr(0, 4);
t = n.substr(11, 8);
m_text = lang == 0 ? months_en[m - 1] : months_ru[m - 1];
return d + " " + m_text + " " + y + ", " + t;
}
var measure_arr = [
["$info(bitrate)", "kbps", "кбит/с"],
["$info(samplerate)", "Hz", "Гц"],
["$info(bitspersample)", "bps", ""],
["$info(channels)", "ch", ""],
["%play_count%", "times", ""]
]
function get_measure(n) {
tmp = "";
var j = 0;
do {
if (measure_arr[j][0] == n) {
tmp = lang == 0 ? measure_arr[j][1] : measure_arr[j][2];
}
j++;
} while (j < measure_arr.length);
return tmp;
}
var months_en = ["Jan.", "Feb.", "Mar.", "Apr.", "May", "Jun.", "Jul.", "Aug.", "Sept.", "Oct.", "Nov.", "Dec."];
var months_ru = ["Янв.", "Фев.", "Мрт", "Апр.", "Май", "Июн.", "Июл.", "Авг.", "Сен.", "Окт.", "Нбр", "Дек."];
function create_array() {
tmp_item_name_array = [];
tmp_item_name_array_2 = [];
tmp_item_value_array = [];
t_x2 = 0;
similar_artist = [];
for (j = 0; j < tfname.length; j++) {
group = tfname[j][0].search('group') >= 0 ? true : false;
var value = "";
if (!group) {
switch (tfname[j][0]) {
case "%lastfm_album_listeners%":
value = Eval(tfname[j][0]) ? Eval(tfname[j][0]) : album_info[1];
break;
case "%lastfm_album_playcount%":
value = Eval(tfname[j][0]) ? Eval(tfname[j][0]) : album_info[0];
break;
case "%lastfm_artist_listeners%":
value = Eval(tfname[j][0]) ? Eval(tfname[j][0]) : artist_info[1];
break;
case "%lastfm_artist_playcount%":
value = Eval(tfname[j][0]) ? Eval(tfname[j][0]) : artist_info[0];
break;
case "%lastfm_similar_artist%":
value = Eval(tfname[j][0]) ? Eval(tfname[j][0]) : similar;
similar_artist = value ? value.split(';') : "" ;
break;
default:
value = tfname[j][0].search(/_modified|_played|_played|added/g) > 0 ? data_format(Eval(tfname[j][0])) : Eval(tfname[j][0]);
}
}
if (value && value != 0 || group) {
tmp_item_name_array.push(tfname[j][0]);
tmp_item_name_array_2.push(tfname[j][1]);
m_text = get_measure(tfname[j][0]);
value = value + (m_text ? " " + m_text : "");
if (tfname[j][0] != "%lastfm_similar_artist%"){
tmp_item_value_array.push(value);
}
}
if (value && value != 0 && !group){
tmp = lang == 0 ? clear_item_name(tfname[j][0]) : tfname[j][1];
tmp_t_x2 = calc_text_data("w", tmp, font_item_name);
t_x2 = tmp_t_x2 > t_x2 ? tmp_t_x2 : t_x2;
}
}
t_x2 = auto_sizing ? t_x2 + t_x1 + 10 : window.GetProperty("text: x2 custom");
for (var i = 0; i < similar_artist.length; i++) {
if (i >= 1) {
tmp_item_name_array.push("");
tmp_item_name_array_2.push("");
}
value = similar_artist[i].replace(/^\s+|\s+$/g, "");
tmp_item_value_array.push(value);
}
clear_collapse_expand_groups();
ini_selected_idx(0);
}
function clear_collapse_expand_groups() {
item_name_array = [];
item_name_array_2 = [];
item_value_array = [];
group_name = groups[0];
for (j = 0; j < tmp_item_name_array.length; j++) {
group = tmp_item_name_array[j].search('group') >= 0 ? true : false;
if (group){
group_name = tmp_item_name_array[j].replace("group_", "");
}
selected_items = window.GetProperty(group_name);
item_nane = tmp_item_name_array[j];
item_nane_2 = tmp_item_name_array_2[j];
item_value = tmp_item_value_array[j];
if (!group){
if (selected_items){
item_name_array.push(item_nane);
item_name_array_2.push(item_nane_2);
item_value_array.push(item_value);
}
}
if (group){
if (tmp_item_value_array[j + 1]){
item_name_array.push(item_nane);
item_name_array_2.push(item_nane_2);
item_value_array.push(item_value);
}
}
}
window.Repaint();
}
function draw_array(gr) {
f_h_name = gr.CalcTextHeight("Text", font_item_name);
f_h_value = gr.CalcTextHeight("Text", font_item_value);
f_h = Math.max(f_h_name, f_h_value);
t_h = f_h + window.GetProperty(" vertical item padding");
text_h = item_name_array.length * t_h;
panel_h = Math.round(window.Height / t_h) * t_h;
if (text_h < panel_h && s < 0) s = 0;
star_size = f_h_value - 3;
star_offset = star_size + 2;
for (var i = 0; i < item_name_array.length; i++) {
group = item_name_array[i].search('group') >= 0 ? true : false;
t_y = i * t_h + s;
l_y = t_y + t_h / 2;
if (!group){
rating_text = item_name_array[i] == "$meta(rating)" ? lang == 0 ? " (tag)" : " (тег)" : "";
name = lang == 0 ? clear_item_name(item_name_array[i]) : item_name_array_2[i];
t_w = Math.min(ww - (ww - t_x2)- t_x1, ww - t_x1 * 2) - 10;
gr.GdiDrawText(name + rating_text, font_item_name, color_item_name, t_x1, t_y, t_w, t_h, DT_LEFT | DT_SINGLELINE | DT_VCENTER | DT_WORD_ELLIPSIS | DT_NOPREFIX);
}
if (group){
name = lang == 0 ? clear_group_text(item_name_array[i]) : item_name_array_2[i];
t_w = ww - t_x1 * 2;
group_text && gr.GdiDrawText(name, font_group, color_group_text, t_x1, t_y, t_w, t_h, DT_LEFT | DT_SINGLELINE | DT_VCENTER | DT_WORD_ELLIPSIS | DT_NOPREFIX);
l_x = group_text && name ? Math.min(gr.CalcTextWidth(name, font_group) + 5, ww - t_x1 * 2) : 0;
gr.DrawLine(t_x1 + l_x, l_y, ww - t_x1, l_y, 1, color_group_text);
}
var color = selected_idx[i] == 0 ? color_item_value : color_item_name;
if (item_name_array[i].search(/rating/g) > 0){
for (var r = 0; r < Math.min(item_value_array[i] * star_offset, ww - t_x2 - t_x1); r = r + star_offset) {
draw_star(gr, t_x2 + star_size / 3 + r, t_y + t_h / 2, star_size, true, 0, color, false, bgcolor, 255);
}
} else {
value = item_value_array[i];
t_w2 = ww - t_x2 - t_x1;
gr.GdiDrawText( value, font_item_value, color, t_x2, t_y, t_w2, t_h, DT_LEFT | DT_SINGLELINE | DT_VCENTER | DT_WORD_ELLIPSIS | DT_NOPREFIX);
}
}
}
var metadb;
on_item_focus_change();
function on_playlist_switch() {
on_item_focus_change();
}
function on_playback_new_track() {
on_item_focus_change();
}
function on_playback_dynamic_info_track() {
on_item_focus_change();
}
function on_playback_stop() {
on_item_focus_change();
}
function on_selection_changed(metadb) {
on_item_focus_change();
}
function on_item_focus_change() {
switch (selection_mode) {
case 0:
metadb = fb.IsPlaying ? fb.GetNowPlaying() : fb.GetFocusItem();
break;
case 1:
metadb = fb.GetFocusItem();
break;
}
if (metadb) on_metadb_changed();
}
function on_metadb_changed() {
artist = Eval("%artist%");
album = Eval("%album%");
if (album != old_album) {
album_info = [];
get_lastFM_album_info(artist, album)
old_album = album;
}
if (artist != old_artist) {
similar = "";
get_lastFM_similar(artist);
artist_info = [];
get_lastFM_artist_info(artist);
old_artist = artist;
}
create_array();
}
function Eval(field) {
if (metadb) {
type = metadb.RawPath;
if (type.indexOf("file") >= 0){
return fb.TitleFormat("[" + field + "]").EvalWithMetadb(metadb);
} else{
if (selection_mode == 0){
if (field == "$meta(artist)" || field == "%title%" || field == "%artist%"){
return fb.TitleFormat("[" + field + "]").Eval(true);
}
if (field == "%genre%"){
return fb.TitleFormat("[" + field + "]").EvalWithMetadb(metadb);
}
}
return fb.TitleFormat("[" + field + "]").EvalWithMetadb(metadb);
}
}
}
function on_mouse_rbtn_up (x, y){
tooltip_state && tooltip.Deactivate();
var _menu = window.CreatePopupMenu();
_menu.AppendMenuItem(MF_ENABLED, 10, "Prefer now playing");
_menu.AppendMenuItem(MF_ENABLED, 11, "Follow selected track");
_menu.CheckMenuRadioItem(10, 11, selection_mode + 10);
_menu.EnableMenuItem(selection_mode + 10, 1);
_menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
_menu.AppendMenuItem(MF_ENABLED, 20, "Group text");
_menu.CheckMenuItem(20, group_text);
_menu.AppendMenuItem(MF_ENABLED, 30, "Tooltip");
_menu.CheckMenuItem(30, Tooltip);
_menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
_menu.AppendMenuItem(MF_ENABLED, 50, "Create txt/xls file");
_menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
MF_STRING = auto_sizing ? MF_GRAYED : MF_ENABLED;
_menu.AppendMenuItem(MF_STRING, 60, "Auto-sizing columns");
_menu.CheckMenuItem(60, auto_sizing);
_menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
_menu.AppendMenuItem(MF_ENABLED, 70, "Item text: " + lang_text[0]);
_menu.AppendMenuItem(MF_ENABLED, 71, "Item text: " + lang_text[1]);
_menu.CheckMenuRadioItem(70, 71, lang + 70);
_menu.EnableMenuItem(lang + 70, 1);
_menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
_menu.AppendMenuItem(MF_ENABLED, 80, "Copy to clipboard (all)");
_menu.AppendMenuItem(MF_ENABLED, 81, "Copy item name");
_menu.CheckMenuItem(81, clipboard_item_name);
//_menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
//_menu.AppendMenuItem(MF_ENABLED, 100, "Reload");
_menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
_menu.AppendMenuItem(MF_ENABLED, 200, "Properties");
_menu.AppendMenuItem(MF_ENABLED, 300, "Configure ...");
ret = _menu.TrackPopupMenu(x,y);
switch (ret) {
case 10:
case 11:
selection_mode = ret - 10;
window.SetProperty("selection_mode", selection_mode);
on_item_focus_change();
break;
case 20:
window.SetProperty("group text", !group_text);
group_text = window.GetProperty("group text");
break;
case 30:
window.SetProperty("tooltip", !Tooltip);
Tooltip = window.GetProperty("tooltip");
deactive_tooltip();
break;
case 50:
menu_create_file(x,y);
break;
case 60:
if (!auto_sizing){
auto_sizing = true;
window.SetProperty("auto sizing", auto_sizing);
create_array();
}
break;
case 70:
case 71:
lang = ret - 70;
window.SetProperty("lang", lang);
create_array();
break;
case 80:
ini_selected_idx(1);
copy_to_clipboard();
break;
case 81:
window.SetProperty("clipboard item name", !clipboard_item_name);
clipboard_item_name = window.GetProperty("clipboard item name");
ini_selected_idx(0);
copy_to_clipboard();
on_mouse_rbtn_up (x, y);
break;
case 100:
try {
window.Reload();
} catch(e) {};
break;
case 200:
window.ShowProperties();
break;
case 300:
window.ShowConfigure();
break;
}
_menu.Dispose();
return true;
}
///////////////////////////// Create file
var fso = new ActiveXObject("Scripting.FileSystemObject");
var output_path = fb.ProfilePath + "\\tmp_Properties\\";
function check_folder(n) {
if (!n) return;
try {
if(!fso.FolderExists(n)) {fso.CreateFolder(n)};
} catch(e) {}
}
window.GetProperty("ext", 1);
var separator = Array(" ; ","\t");
var tmp_output_item_name_array = [];
var output_array = [];
var pllist_name;
var selected;
var shift = 0;
create_tmp_output_item_name_array();
function create_tmp_output_item_name_array() {
tmp_output_item_name_array = [];
for (var j = 0; j < tfname.length; j++) {
if (tfname[j][0].search(/group|lastfm/g) < 0){
tmp_output_item_name_array.push(tfname[j][0]);
}
}
}
for (var j = 0; j < tmp_output_item_name_array.length; j++) {
window.GetProperty(j + 1, false);
}
function create_output_array() {
output_array = [];
for (var j = 0; j < tmp_output_item_name_array.length; j++) {
selected = window.GetProperty(j + 1);
if ( selected ) {output_array.push(tmp_output_item_name_array[j])};
}
createTextFile();
}
function createTextFile(){
check_folder(output_path);
count = plman.GetPlaylistSelectedItems(plman.ActivePlaylist).Count;
if (count == 0 || output_array.length == 0) return;
if (window.GetProperty("ext") == 0) {
output_file = output_path + "plist " + pllist_name + ".txt";
} else {
output_file = output_path + "plist " + pllist_name + ".xls";
}
try { file = fso.CreateTextFile( output_file )
} catch(e) { return };
var text_item_name = [];
var string_item_name = "";
for (var j = 0; j < output_array.length; j++) {
text_item_name.push(output_array[j]);
}
string_item_name = text_item_name.join(separator[window.GetProperty("ext")]);
file.WriteLine(string_item_name);
file.WriteLine("");
for (var i = 0; i < count; i++) {
item = plman.GetPlaylistSelectedItems(plman.ActivePlaylist).Item(i);
var text_item_value = [];
var string_item_value = "";
for (var j = 0; j < output_array.length; j++) {
value = fb.TitleFormat("[" + output_array[j] + "]").EvalWithMetadb(item);
text = get_measure(output_array[j]);
text = value && text ? " " + text : "";
text_item_value.push(value + text);
string_item_value = text_item_value.join(separator[window.GetProperty("ext")]);
}
try { file.WriteLine(string_item_value);
} catch(e) {};
}
file.Close();
}
function menu_create_file(x, y){
var _menu = window.CreatePopupMenu();
var i = 1;
count = plman.GetPlaylistSelectedItems(plman.ActivePlaylist).Count;
MF_STRING = count == 0 ? MF_GRAYED : MF_ENABLED;
pllist_name = plman.GetPlaylistName(plman.ActivePlaylist);
pllist_name = count == 0 ? "*" : pllist_name.replace(/[\/\:\*\?\"\<\>\|]/g,'');
_menu.AppendMenuItem(MF_STRING, i++, "Create " + pllist_name + (window.GetProperty("ext") == 0 ? ".txt" : ".xls"));
_menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
var lines = 20;
bl = tmp_output_item_name_array.length > lines ? lines + shift : tmp_output_item_name_array.length;
for (var j = shift; j < bl; j++) {
menuItem = clear_item_name(tmp_output_item_name_array[j]);
_menu.AppendMenuItem(MF_ENABLED, i++, menuItem);
_menu.CheckMenuItem(i - 1, window.GetProperty(i - 2 + shift));
}
_menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
_menu.AppendMenuItem(MF_ENABLED, 100, "txt");
_menu.AppendMenuItem(MF_ENABLED, 101, "xls");
_menu.CheckMenuRadioItem(100, 101, 100 + window.GetProperty("ext"));
_menu.EnableMenuItem(100 + window.GetProperty("ext"), 1);
_menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
_menu.AppendMenuItem(MF_ENABLED, 110, "Select all");
_menu.AppendMenuItem(MF_ENABLED, 120, "Clear all");
if (tmp_output_item_name_array.length > lines) {
_menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
_menu.AppendMenuItem(shift == 0 ? MF_GRAYED : MF_ENABLED, 130, "Up");
_menu.AppendMenuItem(shift + lines >= tmp_output_item_name_array.length ? MF_GRAYED : MF_ENABLED, 140, "Down");
}
ret = _menu.TrackPopupMenu(x, y - 250);
switch (true) {
case (ret == 1):
create_output_array();
break;
case (ret >= 2 && ret <= tmp_output_item_name_array.length + 1):
selected = window.GetProperty(ret - 1 + shift);
window.SetProperty(ret - 1 + shift, selected == false ? true : false);
menu_create_file(x,y);
break;
case (ret == 100):
window.SetProperty("ext", 0);
menu_create_file(x,y);
break;
case (ret == 101):
window.SetProperty("ext", 1);
menu_create_file(x,y);
break;
case (ret == 110):
for (var j = 1; j < tmp_output_item_name_array.length + 1; j++) {
window.SetProperty(j, true);
}
menu_create_file(x,y);
break;
case (ret == 120):
for (var j = 1; j < tmp_output_item_name_array.length + 1; j++) {
window.SetProperty(j, false);
}
menu_create_file(x,y);
break;
case (ret == 130):
shift = shift - 1;
menu_create_file(x,y);
break;
case (ret == 140):
shift = shift + 1;
menu_create_file(x,y);
break;
}
_menu.Dispose();
}
///////////////////////////// Copy to clipboard
function ini_selected_idx(n){
for (j = 0; j < item_name_array.length; j++) {
selected_idx[j] = n;
}
}
function copy_to_clipboard(){
var clipboard_text = "";
for (var i = 0; i < item_name_array.length; i++) {
if (selected_idx[i] > 0){
group = item_name_array[i].search('group') >= 0 ? true : false;
if (!group){
name = lang == 0 ? clear_item_name(item_name_array[i]) : item_name_array_2[i];
value = item_value_array[i];
name = clipboard_item_name ? name + "\t" : "";
clipboard_text = clipboard_text + name + value + (i < item_name_array.length - 1 ? "\r\n" : "");
}
}
}
htmlfile.parentWindow.clipboardData.setData("text", clipboard_text);
}
///////////////////////////// Draw star
function draw_star(gr, x, y, img_size, fill, line_thickness, color, sh, sh_color, alpha){
var radius = img_size / 2;
var radius_2 = radius / 2.61803;
line_thickness = line_thickness >= radius_2 ? radius_2 : line_thickness;
var delta = line_thickness / 2 * Math.tan(72 / 180 * Math.PI);
var points = [], sh_points = [];
var x_points_1 = [], y_points_1 = [], x_points_2 = [], y_points_2 = [];
for (var i = 0; i < 10; i++) {
if (i % 2 == 0) {
x_points_1.push((radius - delta) * Math.cos(Math.PI * i / 10 * 2 - Math.PI / 2));
y_points_1.push((radius - delta) * Math.sin(Math.PI * i / 10 * 2 - Math.PI / 2));
} else {
x_points_2.push((radius - delta) / 2.61803 * Math.cos(Math.PI * i / 10 * 2 - Math.PI / 2));
y_points_2.push((radius - delta) / 2.61803 * Math.sin(Math.PI * i / 10 * 2 - Math.PI / 2));
}
}
for (var i = 0; i < 5; i++) {
points.push(x_points_1[i] + radius, y_points_1[i] + radius, x_points_2[i] + radius, y_points_2[i] + radius);
sh_points.push(x_points_1[i] + radius + 1, y_points_1[i] + radius + 1, x_points_2[i] + radius + 1, y_points_2[i] + radius + 1);
}
var img = gdi.CreateImage(img_size, img_size);
var temp_gr = img.GetGraphics();
temp_gr.SetSmoothingMode(2);
if (line_thickness > 0) {
sh && temp_gr.DrawPolygon(sh_color, line_thickness, sh_points);
temp_gr.DrawPolygon(color, line_thickness, points);
}
if (fill && line_thickness == 0) {
sh && temp_gr.FillPolygon(sh_color, 1, sh_points);
temp_gr.FillPolygon(color, 1, points)
}
gr.DrawImage(img, x - radius, y - radius, img_size, img_size, 0, 0, img_size, img_size, 0, alpha);
img.ReleaseGraphics(temp_gr);
img.Dispose();
temp_gr = null;
img = null;
}
///////////////////////////// wsh tooltip (custom paint)
function active_tooltip(){
if (!tooltip_state){
tooltip_state = true;
tooltip.Activate();
tooltip.TrackActivate = true;
}
}
function deactive_tooltip(){
if (tooltip_state){
tooltip.Deactivate();
tooltip.TrackActivate = false;
tooltip_state = false;
}
}
function on_tooltip_custom_paint(gr){
for (var i = 0; i < tooltip_t.length; i += 1) {
gr.GdiDrawText( tooltip_t[i], font_tooltip, RGB(0,0,0), 5, tooltip_t_h * i + 1, tooltip.Width, tooltip.Height, DT_LEFT | DT_WORDBREAK | DT_NOPREFIX );
}
}
function tooltip_activate_wsh(x, y) {
tooltip_x = t_x2 - 5;
tooltip_y = idx * t_h - Math.abs(s);
var value_width = calc_text_data( "w", item_value_array[idx], font_item_value );
if (value_width > ww - t_x2 - t_x1 && x > t_x2 && x < ww - t_x1 && y > tooltip_y + 1 && y < tooltip_y + t_h - 1){
if (tooltip_time.Time > tooltip_delay_time && !tooltip_state) {
tooltip_text = item_value_array[idx];
calc_tooltip_dim();
tooltip.TrackPosition( tooltip_x, tooltip_y + window.GetProperty(" vertical item padding") / 2);
active_tooltip();
tooltip.Text = " ";
}
} else {
tooltip_time.Reset();
deactive_tooltip();
}
}
function calc_tooltip_dim(){
tooltip_t_w = calc_text_data( "w", tooltip_text, font_tooltip );
tooltip_t_h = calc_text_data( "h", tooltip_text, font_tooltip );
tooltip_t_tmp = calc_text_data( "a", tooltip_text, font_tooltip, tooltip_max_w );
tooltip_t = [];
tooltip_l = [];
for (var i = 0; i < tooltip_t_tmp.length; i += 1) {
if (i % 2 == 0) {
tooltip_t.push(tooltip_t_tmp[i].replace(/^\s+|\s+$/g, ""));
} else {
tooltip_l.push(tooltip_t_tmp[i]);
}
}
if (tooltip_t_w <= tooltip_max_w){
tooltip.Width = tooltip_t_w + 5;
tooltip.Height = tooltip_t_h;
} else {
tooltip.Width = Math.max.apply(null, tooltip_l) + 5;
tooltip.Height = tooltip_t_h * tooltip_t.length;
}
}
function calc_text_data(d, text, font, max_w) {
var temp_bmp = gdi.CreateImage(1, 1);
var temp_gr = temp_bmp.GetGraphics();
var tmp;
switch (d) {
case "w":
tmp = temp_gr.CalcTextWidth(text, font);
break;
case "h":
tmp = temp_gr.CalcTextHeight(text, font);
break;
case "a":
tmp = temp_gr.EstimateLineWrap(text, font, max_w).toArray();
break;
}
temp_bmp.ReleaseGraphics(temp_gr);
temp_bmp.Dispose();
temp_gr = null;
temp_bmp = null;
return tmp;
}
///////////////////////////// jscript tooltip
function tooltip_activate_jscript(x, y) {
tooltip_x = t_x2 - 5;
tooltip_y = idx * t_h - Math.abs(s);
var value_width = calc_text_data("w", item_value_array[idx], font_item_value)
if (value_width > ww - t_x2 - t_x1 && x > t_x2 && x < ww - t_x1 && y > tooltip_y + 1 && y < tooltip_y + t_h - 1){
if (tooltip_time.Time > tooltip_delay_time) {
tooltip.Text = item_value_array[idx];
tooltip.TrackPosition( tooltip_x, tooltip_y + window.GetProperty(" vertical item padding") / 2);
tooltip.TrackActivate = true;
tooltip.Activate();
tooltip_state = true;
}
} else {
tooltip.Deactivate();
tooltip.TrackActivate = false;
tooltip_time.Reset();
tooltip_state = false;
}
}
///////////////////////////// lastFM data
function get_lastFM_similar(a){
if (!a) return
var xmlhttp0 = new ActiveXObject("Microsoft.XMLHTTP");
var url0 = ("https://www.last.fm/music/" + encodeURIComponent(a) + "/+similar");
xmlhttp0.open("GET", url0, true );
xmlhttp0.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
xmlhttp0.send(null);
xmlhttp0.onreadystatechange = function () {
if (xmlhttp0.readyState == 4) {
if (xmlhttp0.status == 200) {
doc.open();
var div = doc.createElement("div");
div.innerHTML = xmlhttp0.responsetext;
var a = div.getElementsByTagName("a");
var tmp = [];
var j = 0;
for (i = 0; i < a.length; i++) {
if (a[i].className == "link-block-target"){
tmp[j] = a[i].innerHTML.replace(/(&)/g,'&');
j++
if (j == 6) break;
}
}
doc.close();
similar = tmp.join(";");
create_array();
}
}
}
}
function get_lastFM_artist_info(a){
if (!a) return
var xmlhttp1 = new ActiveXObject("Microsoft.XMLHTTP");
var url1 = ("https://www.last.fm/music/" + encodeURIComponent(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 abbr = div.getElementsByTagName("abbr");
for (i = 0; i < abbr.length; i++) {
if (abbr[i].className == "intabbr"){
artist_info.push(abbr[i].title.replace(/\,/g, " "));
}
}
doc.close();
create_array();
}
}
}
}
function get_lastFM_album_info(a, al){
if (!a || !al) return
var xmlhttp2 = new ActiveXObject("Microsoft.XMLHTTP");
var url2 = ("https://www.last.fm/music/" + encodeURIComponent(a) + "/" + encodeURIComponent(al));
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 abbr = div.getElementsByTagName("abbr");
for (i = 0; i < abbr.length; i++) {
if (abbr[i].className == "intabbr"){
album_info.push(abbr[i].title.replace(/\,/g, " "));
}
}
doc.close();
create_array();
}
}
}
}
function print(msg) {
fb.trace(msg);
}
kgena_ua:Сохранение в буфере обмена : Ctrl + лев.кн.мыши на значении(ях), отмена выделения - двойной клик лев.кн.мыши.
У меня копирует нормально, а вот с выделением проблема - если цвет шрифта черный то невидно выделения.MC Web:Констатация факта, у себя не смог ничего скопировать в буфер обмена, как ни старался. Через контекстное меню тоже.
Aliado_71, можно, если преобразовать текст в img (связано с возможностью двигать текст вверх и вниз). Только нужно посмотреть не будут-ли тормоза при изменении ширины колонок.Aliado_71:добавить регулировку отступа текста не только по горизонтали, но и по вертикали
Цвет выделения - цвет "item name".Aliado_71:а вот с выделением проблема - если цвет шрифта черный то невидно выделения
Aliado_71, тут мне не понятно, что значит : "...если изменять общие настройки".Aliado_71:слетают кастомные настройки цветов панели и шрифтов если изменять общие настройки
Rating & File attributes не делался под jscript panel.Aliado_71:"Rating & File attributes" вылетает если попытаться сохранить рейтинг в тег
kgena_ua, Когда я включаю в панели - colors: custom true и выставляю например свой цвет фона, то если изменить цвет фона в общих настройках Colums UI то и в панели он меняется тоже, хотя настройки выставлены пользовательские. Проверенно на двух разных компах.kgena_ua:Aliado_71, тут мне не понятно, что значит : "...если изменять общие настройки".
// ==PREPROCESSOR==
// @name "Properties & properties file (ml)"
// @author "kgena_ua"
// @version "05112017"
// @feature "v1.4"
// @feature "watch-metadb"
// @tooltip "custom-paint"
// ==/PREPROCESSOR==
function RGB(r,g,b) { return (0xff000000|(r<<16)|(g<<8)|(b)); }
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;
IDC_HAND = 32649;
IDC_ARROW = 32512;
IDC_SIZEWE = 32644;
MF_ENABLED = 0x00000000;
MF_GRAYED = 0x00000001;
MF_SEPARATOR = 0x00000800;
VK_SHIFT = 0x10;
VK_CONTROL = 0x11;
VK_ESCAPE = 0x1B;
String.prototype.repeat = function(n) {
return new Array(n + 1).join(this);
}
window.SetProperty(" - user", "");
if (window.GetProperty(" - user") != "" ) window.SetProperty(" - user", "");
window.SetProperty("-".repeat(50), "");
if (window.GetProperty("-".repeat(50)) != "" ) window.SetProperty("-".repeat(50), "");
var font_name_item_name = window.GetProperty(" font name: item name", "Arial");
var font_name_item_value = window.GetProperty(" font name: item value", "Arial");
var font_name_group = window.GetProperty(" font name: group", "Arial");
var font_size_item_name = window.GetProperty(" font size: item name", 11);
var font_size_item_value = window.GetProperty(" font size: item value", 12);
var font_size_group = window.GetProperty(" font size: group", 11);
var font_style_item_name = window.GetProperty(" font style: item name", 0);
var font_style_item_value = window.GetProperty(" font style: item value", 0);
var font_style_group = window.GetProperty(" font style: group", 0);
var font_size_tooltip = window.GetProperty(" font size: tooltip", 12);
var font_item, font_group, font_tooltip;
get_font();
function get_font(){
font_item_name = gdi.Font(font_name_item_name, font_size_item_name, font_style_item_name);
font_item_value = gdi.Font(font_name_item_value, font_size_item_value, font_style_item_value);
font_group = gdi.Font(font_name_group, font_size_group, font_style_group);
font_tooltip = gdi.Font(font_name_item_value, font_size_tooltip, font_style_item_value);
}
ColorTypeCUI = {
text: 0,
selection_text: 1,
inactive_selection_text: 2,
background: 3,
selection_background: 4,
inactive_selection_background: 5,
active_item_frame: 6
};
ColorTypeDUI = {
text: 0,
background: 1,
highlight: 2,
selection: 3
};
var bgcolor, color_item_name, color_item_value, color_group_text;
function get_color(){
if (window.InstanceType == 0){
s_bgcolor = window.GetColorCUI(ColorTypeCUI.background);
s_color_item_name = window.GetColorCUI(ColorTypeCUI.text);
s_color_item_value = window.GetColorCUI(ColorTypeCUI.inactive_selection_text);
s_color_group_text = window.GetColorCUI(ColorTypeCUI.inactive_selection_background);
} else if (window.InstanceType == 1) {
s_bgcolor = window.GetColorDUI(ColorTypeDUI.background);
s_color_item_name = window.GetColorDUI(ColorTypeDUI.text);
s_color_item_value = window.GetColorDUI(ColorTypeDUI.highlight);
s_color_group_text = window.GetColorDUI(ColorTypeDUI.selection);
}
window.Repaint();
}
var c_bgcolor = customColor(window.GetProperty(" color: background", "0-0-0"));
var c_color_item_name = customColor(window.GetProperty(" color: item name", "180-180-180"));
var c_color_item_value = customColor(window.GetProperty(" color: item value", "255-255-220"));
var c_color_group_text = customColor(window.GetProperty(" color: group text", "100-100-100"));
function customColor(colour){
tempc = colour.split("-");
return (0xff000000 | (tempc[0]<<16) | (tempc[1]<<8) | (tempc[2]));
}
var custom_colors = window.GetProperty(" colors: custom", false);
function ini_color(){
bgcolor = custom_colors ? c_bgcolor : s_bgcolor;
color_item_name = custom_colors ? c_color_item_name : s_color_item_name;
color_item_value = custom_colors ? c_color_item_value : s_color_item_value;
color_group_text = custom_colors ? c_color_group_text : s_color_group_text;
}
get_color();
ini_color();
function on_colors_changed(){
get_color();
ini_colors();
}
var selection_mode = window.GetProperty("selection_mode", 0);
var idx, old_idx;
var item_name_array = [];
var item_name_array_2 = [];
var item_value_array = [];
var tmp_item_name_array = [];
var tmp_item_name_array_2 = [];
var tmp_item_value_array = [];
var name, value;
var artist, old_artist;
var album, old_album;
var similar;
var similar_artist = [];
var artist_info = [];
var album_info = [];
var auto_sizing = window.GetProperty("auto sizing", true);
var group_text = window.GetProperty("group text", true);
var vertical_item_padding = window.GetProperty(" vertical item padding", 1);
var clipboard_item_name = window.GetProperty("clipboard item name", false);
var f_h;
var margin_h = window.GetProperty(" text: margin", 10);
var t_x1 = margin_h;
var t_x2;
var text_h;
var panel_h;
window.GetProperty("text: x2 custom", 0);
var lbtn_down = false;
var shift_down = false;
var control_down = false;
var pos_x;
var drag_x = 0, drag_y = 0;
var move_x = false, move_y = false;
var s = 0;
var old_x, old_y;
var Tooltip = window.GetProperty("tooltip", false);
var tooltip_time = fb.CreateProfiler("Time tooltip");
var tooltip_state = false;
var tooltip_text;
var tooltip_t = [];
var tooltip_max_w = window.GetProperty(" tooltip text max width", 250);
var tooltip_delay_time = window.GetProperty(" tooltip delay time (ms)", 300);
var p_wsh = window.GetProperty(" panel (tooltip ini): WSH", true);
var p_jscript = window.GetProperty(" panel (tooltip ini): jscript", false);
try {
if (p_wsh) {var tooltip = window.CreateTooltip();}
if (p_jscript) {
var tooltip = window.CreateTooltip(font_name_item_value, font_size_tooltip, font_style_item_value);
tooltip.SetMaxWidth(tooltip_max_w);
}
} catch(e) {};
var lang_text = ["en", "ru"];
var lang = window.GetProperty("lang", 0);
htmlfile = new ActiveXObject('htmlfile');
var clipboardData = "";
var doc = new ActiveXObject("htmlfile");
function on_paint(gr) {
!window.IsTransparent && gr.FillSolidRect(0, 0, ww, wh, bgcolor);
draw_array(gr);
gr.GdiDrawText( "", font_item_value, color_item_value, 0, 0, ww, wh, DT_RIGHT | DT_WORD_ELLIPSIS);
gr.GdiDrawText( "", font_item_value, color_item_value, 0, 20, ww, wh, DT_RIGHT | DT_WORD_ELLIPSIS);
}
var groups = ["metadata", "general", "replaygain", "location", "playback statistics", "last.FM statistics", "last.FM"];
window.GetProperty( groups[0], true);
window.GetProperty( groups[1], true);
window.GetProperty( groups[2], true);
window.GetProperty( groups[3], true);
window.GetProperty( groups[4], true);
window.GetProperty( groups[5], true);
window.GetProperty( groups[6], true);
var tfname = [
["group_" + groups[0], ".........."],
["$meta(artist)", "Исполнитель"],
["%title%", "Название"],
["%album%", "Альбом"],
["%date%", "Год"],
["%genre%", "Жанр"],
["%composer%", "Композитор"],
["%performer%", "Первый исполнительь"],
["$meta(album artist)", "Исполнитель альбома"],
["%track number%", "Номер трека"],
["%totaltracks%", "Всего треков"],
["%discnumber%", "Номер диска"],
["%totaldiscs%", "Всего дисков"],
["%rating%", "Рейтинг"],
["$meta(rating)", "Рейтинг"],
["%comment%", "Комментарий"],
["%publisher%", "Издатель"],
["%catalog%", "Каталог"],
["%discid%", "ID диска"],
["%label%", "Лейбл"],
["%releaser%", "Продавец"],
["%subtitle%", "Субтитры"],
["group_" + groups[1], "общие"],
["$info(samplerate)", "Частота дискретизации"],
["$info(channels)", "Каналов"],
["$info(bitspersample)", "Бит на семпл"],
["$info(bitrate)", "Битрейт"],
["%codec%", "Кодек"],
["$info(codec_profile)", "Профиль кодека"],
["$info(mp3_stereo_mode)", "Режим стерео MP3"],
["$info(encoding)", "Кодирование"],
["%length%", "Длина"],
["$info(tool)", "Кодировщик"],
["$info(cue_embedded)", "Встроенный CUE"],
["$info(tagtype)", "Тип тега"],
["group_" + groups[2], "усиление громкости"],
["%replaygain_album_gain%", "Усиление громкости альбома"],
["%replaygain_album_peak%", "Пиковый уровень альбома"],
["%replaygain_track_gain%", "усиление громкости трека"],
["%replaygain_track_peak%", "Пиковый уровень трека"],
["group_" + groups[3], "расположение"],
["%filename_ext%", "Имя файла"],
["$directory_path(%path%)", "Путь к файлу"],
["%url%", "Ссылка"],
["%subsong%", "Позиция трека"],
["%filesize_natural%", "Размер файла"],
["%last_modified%", "Изменен"],
["%folder_name%", "Имя папки"],
["group_" + groups[4], "статистика воспроизведения"],
["%play_count%", "Количество воспроизведений"],
["%first_played%", "Первое воспроизведение"],
["%last_played%", "Последнее воспроизведение"],
["%added%", "Добавлен"],
["group_" + groups[5], "сайт Last.FM"],
["%lastfm_bio%", "Биография"],
["%lastfm_album_listeners%", "Слушателей альбома"],
["%lastfm_album_playcount%", "Прослушиваний альбома"],
["%lastfm_artist_listeners%", "Слушателей исполнителя"],
["%lastfm_artist_playcount%", "Прослушиваний исполнителя"],
["%lastfm_album_content%", "Содержимое альбома"],
["group_" + groups[6], "сайт Last.FM"],
["%lastfm_similar_artist%", "Похожие исполнители"]
];
function set_cursor() {
if (move_y || lbtn_down) window.SetCursor(IDC_HAND);
if (move_x) window.SetCursor(IDC_SIZEWE);
}
var selected_idx = [];
function on_mouse_lbtn_down(x, y) {
deactive_tooltip();
lbtn_down = true;
if (move_y) drag_y = y - s;
if (move_x) drag_x = x - t_x2;
if (control_down){
old_idx = idx;
selected_idx[idx] = selected_idx[idx] == 0 ? 1 : 0;
copy_to_clipboard();
}
}
function on_mouse_lbtn_up(x, y) {
lbtn_down = false;
if (move_x) {
window.SetProperty("text: x2 custom", t_x2);
}
}
function on_mouse_lbtn_dblclk(x, y){
group = item_name_array[idx] && item_name_array[idx].search('group') >= 0 ? true : false;
if (group){
group_name = item_name_array[idx].replace("group_", "");
group_collapsed = window.GetProperty(group_name);
window.SetProperty(group_name, !group_collapsed);
create_array();
window.Repaint();
}
if (!control_down){
ini_selected_idx(0);
copy_to_clipboard();
window.Repaint();
}
}
function on_mouse_move(x, y) {
if (shift_down && !move_x) drag_x = x - t_x2;
if (shift_down) drag_y = (y - s);
idx = Math.floor((y + Math.abs(s)) / f_h);
pos_x = x;
mouse_on_pos();
if (Tooltip && !lbtn_down && !shift_down && !control_down && (old_y != y || old_x != x)){
try {
if (p_wsh) tooltip_activate_wsh(x, y);
if (p_jscript) tooltip_activate_jscript(x, y);
} catch(e) {}
old_y = y;
old_x = x;
}
if (lbtn_down && move_y && !control_down) {
if (text_h > panel_h){
s = y - drag_y;
s = s >= 0 ? 0 : s;
s = s <= (panel_h - text_h) && s < 0 ? (panel_h - text_h) : s;
}
window.Repaint();
}
if (lbtn_down && move_x) {
auto_sizing = false;
window.SetProperty("auto sizing", auto_sizing);
tmp_t_x2 = x - drag_x;
t_x2 = tmp_t_x2 <= t_x1 ? t_x1 : tmp_t_x2 >= ww - t_x1 - 50 ? ww - t_x1 - 50 : tmp_t_x2;
window.Repaint();
}
if (control_down && lbtn_down && old_idx != idx){
selected_idx[idx] = selected_idx[idx] == 0 ? 1 : 0;
copy_to_clipboard();
old_idx = idx;
}
}
function on_mouse_wheel(delta) {
if (move_y) {
if (text_h > panel_h){
if (delta < 0) {s = Math.max(panel_h - text_h, s + delta * f_h)};
if (delta > 0) {s = Math.min(0, s + delta * f_h)};
}
window.Repaint();
}
}
function on_mouse_leave() {
window.SetCursor(IDC_ARROW);
window.Repaint();
}
function mouse_on_pos(){
if (shift_down && pos_x >= t_x2) {
move_x = true;
move_y = false;
} else {
move_y = true;
move_x = false;
}
set_cursor();
}
function on_key_down(vkey) {
deactive_tooltip();
if (vkey == VK_SHIFT){
shift_down = true;
if (lbtn_down) drag_x = pos_x - t_x2;
}
mouse_on_pos();
if (vkey == VK_CONTROL){
control_down = true;
}
if (vkey == VK_ESCAPE){
ini_selected_idx(0);
copy_to_clipboard();
}
}
function on_key_up(vkey) {
if (vkey == VK_SHIFT){
shift_down = false;
}
mouse_on_pos();
if (vkey == VK_CONTROL){
control_down = false;
}
}
function on_size() {
ww = window.Width;
wh = window.Height;
}
function clear_item_name(n) {
return n.replace(/.*\(|lastfm_|replaygain_|[^a-z0-9\s\_]/g,"").replace(/_/g," ");
//return n.replace(/.*\((?!\))|lastfm_|replaygain_|[^a-z0-9\s\_]/g,"").replace(/_/g," ");
}
function clear_group_text(n) {
return n.replace(/group_/g,"").replace(/(?=.)/g," ").replace(/^\s/g,"")
}
function data_format(n) {
if (!n) return;
d = n.substr(8, 2);
m = parseInt(n.substr(5, 2), 10);
y = n.substr(0, 4);
t = n.substr(11, 8);
m_text = lang == 0 ? months_en[m - 1] : months_ru[m - 1];
return d + " " + m_text + " " + y + ", " + t;
}
var measure_arr = [
["$info(bitrate)", "kbps", "кбит/с"],
["$info(samplerate)", "Hz", "Гц"],
["$info(bitspersample)", "bps", ""],
["$info(channels)", "ch", ""],
["%play_count%", "times", ""]
]
function get_measure(n) {
tmp = "";
var j = 0;
do {
if (measure_arr[j][0] == n) {
tmp = lang == 0 ? measure_arr[j][1] : measure_arr[j][2];
}
j++;
} while (j < measure_arr.length);
return tmp;
}
var months_en = ["Jan.", "Feb.", "Mar.", "Apr.", "May", "Jun.", "Jul.", "Aug.", "Sept.", "Oct.", "Nov.", "Dec."];
var months_ru = ["Янв.", "Фев.", "Мрт", "Апр.", "Май", "Июн.", "Июл.", "Авг.", "Сен.", "Окт.", "Нбр", "Дек."];
function create_array() {
tmp_item_name_array = [];
tmp_item_name_array_2 = [];
tmp_item_value_array = [];
t_x2 = 0;
similar_artist = [];
for (j = 0; j < tfname.length; j++) {
group = tfname[j][0].search('group') >= 0 ? true : false;
var value = "";
if (!group) {
switch (tfname[j][0]) {
case "%lastfm_album_listeners%":
value = Eval(tfname[j][0]) ? Eval(tfname[j][0]) : album_info[1];
break;
case "%lastfm_album_playcount%":
value = Eval(tfname[j][0]) ? Eval(tfname[j][0]) : album_info[0];
break;
case "%lastfm_artist_listeners%":
value = Eval(tfname[j][0]) ? Eval(tfname[j][0]) : artist_info[1];
break;
case "%lastfm_artist_playcount%":
value = Eval(tfname[j][0]) ? Eval(tfname[j][0]) : artist_info[0];
break;
case "%lastfm_similar_artist%":
value = Eval(tfname[j][0]) ? Eval(tfname[j][0]) : similar;
similar_artist = value ? value.split(';') : "" ;
break;
default:
value = tfname[j][0].search(/_modified|_played|_played|added/g) > 0 ? data_format(Eval(tfname[j][0])) : Eval(tfname[j][0]);
}
}
if (value && value != 0 || group) {
tmp_item_name_array.push(tfname[j][0]);
tmp_item_name_array_2.push(tfname[j][1]);
m_text = get_measure(tfname[j][0]);
value = value + (m_text ? " " + m_text : "");
if (tfname[j][0] != "%lastfm_similar_artist%"){
tmp_item_value_array.push(value);
}
}
if (value && value != 0 && !group){
tmp = lang == 0 ? clear_item_name(tfname[j][0]) : tfname[j][1];
tmp_t_x2 = calc_text_data("w", tmp, font_item_name);
t_x2 = tmp_t_x2 > t_x2 ? tmp_t_x2 : t_x2;
}
}
t_x2 = auto_sizing ? t_x2 + t_x1 + 10 : window.GetProperty("text: x2 custom");
for (var i = 0; i < similar_artist.length; i++) {
if (i >= 1) {
tmp_item_name_array.push("");
tmp_item_name_array_2.push("");
}
value = similar_artist[i].replace(/^\s+|\s+$/g, "");
tmp_item_value_array.push(value);
}
clear_collapse_expand_groups();
ini_selected_idx(0);
}
function clear_collapse_expand_groups() {
item_name_array = [];
item_name_array_2 = [];
item_value_array = [];
group_name = groups[0];
for (j = 0; j < tmp_item_name_array.length; j++) {
group = tmp_item_name_array[j].search('group') >= 0 ? true : false;
if (group){
group_name = tmp_item_name_array[j].replace("group_", "");
}
selected_items = window.GetProperty(group_name);
item_nane = tmp_item_name_array[j];
item_nane_2 = tmp_item_name_array_2[j];
item_value = tmp_item_value_array[j];
if (!group){
if (selected_items){
item_name_array.push(item_nane);
item_name_array_2.push(item_nane_2);
item_value_array.push(item_value);
}
}
if (group){
if (tmp_item_value_array[j + 1]){
item_name_array.push(item_nane);
item_name_array_2.push(item_nane_2);
item_value_array.push(item_value);
}
}
}
window.Repaint();
}
function draw_array(gr) {
f_h_name = gr.CalcTextHeight("Text", font_item_name);
f_h_value = gr.CalcTextHeight("Text", font_item_value);
f_h = Math.max(f_h_name, f_h_value) + window.GetProperty(" vertical item padding");
text_h = item_name_array.length * f_h;
panel_h = Math.floor(window.Height / f_h) * f_h;
if (text_h <= panel_h && s < 0) s = 0;
star_size = f_h_value - 3;
star_offset = star_size + 2;
for (var i = 0; i < item_name_array.length; i++) {
group = item_name_array[i].search('group') >= 0 ? true : false;
t_y = i * f_h + s;
l_y = t_y + f_h / 2;
if (!group){
rating_text = item_name_array[i] == "$meta(rating)" ? lang == 0 ? " (tag)" : " (тег)" : "";
name = (lang == 0 ? clear_item_name(item_name_array[i]) : item_name_array_2[i]) + rating_text;
t_w = Math.min(ww - (ww - t_x2)- t_x1, ww - t_x1 * 2) - 10;
gr.GdiDrawText(name, font_item_name, color_item_name, t_x1, t_y, t_w, f_h, DT_LEFT | DT_SINGLELINE | DT_VCENTER | DT_WORD_ELLIPSIS | DT_NOPREFIX);
}
if (group){
name = lang == 0 ? clear_group_text(item_name_array[i]) : item_name_array_2[i];
t_w = ww - t_x1 * 2;
group_text && gr.GdiDrawText(name, font_group, color_group_text, t_x1, t_y, t_w, f_h, DT_LEFT | DT_SINGLELINE | DT_VCENTER | DT_WORD_ELLIPSIS | DT_NOPREFIX);
l_x = group_text && name ? Math.min(gr.CalcTextWidth(name, font_group) + 5, ww - t_x1 * 2) : 0;
gr.DrawLine(t_x1 + l_x, l_y, ww - t_x1, l_y, 1, color_group_text);
}
var color = selected_idx[i] == 0 ? color_item_value : color_item_name;
if (item_name_array[i].search(/rating/g) > 0){
for (var r = 0; r < Math.min(item_value_array[i] * star_offset, ww - t_x2 - t_x1 - star_size / 2); r = r + star_offset) {
draw_star(gr, t_x2 + star_size / 3 + r, t_y + f_h / 2, star_size, true, 0, color, false, bgcolor, 255);
}
} else {
value = item_value_array[i];
t_w2 = ww - t_x2 - t_x1;
gr.GdiDrawText( value, font_item_value, color, t_x2, t_y, t_w2, f_h, DT_LEFT | DT_SINGLELINE | DT_VCENTER | DT_WORD_ELLIPSIS | DT_NOPREFIX);
}
}
}
var metadb;
on_item_focus_change();
function on_playlist_switch() {
on_item_focus_change();
}
function on_playback_new_track() {
on_item_focus_change();
}
function on_playback_dynamic_info_track() {
on_item_focus_change();
}
function on_playback_stop() {
on_item_focus_change();
}
function on_selection_changed(metadb) {
on_item_focus_change();
}
function on_item_focus_change() {
switch (selection_mode) {
case 0:
metadb = fb.IsPlaying ? fb.GetNowPlaying() : fb.GetFocusItem();
break;
case 1:
metadb = fb.GetFocusItem();
break;
}
if (metadb) on_metadb_changed();
}
function on_metadb_changed() {
artist = Eval("%artist%");
album = Eval("%album%");
if (album != old_album) {
album_info = [];
get_lastFM_album_info(artist, album)
old_album = album;
}
if (artist != old_artist) {
similar = "";
get_lastFM_similar(artist);
artist_info = [];
get_lastFM_artist_info(artist);
old_artist = artist;
}
create_array();
}
function Eval(field) {
if (metadb) {
type = metadb.RawPath;
if (type.indexOf("file") >= 0){
return fb.TitleFormat("[" + field + "]").EvalWithMetadb(metadb);
} else{
if (selection_mode == 0){
if (field == "$meta(artist)" || field == "%title%" || field == "%artist%"){
return fb.TitleFormat("[" + field + "]").Eval(true);
}
if (field == "%genre%"){
return fb.TitleFormat("[" + field + "]").EvalWithMetadb(metadb);
}
}
return fb.TitleFormat("[" + field + "]").EvalWithMetadb(metadb);
}
}
}
function on_mouse_rbtn_up (x, y){
tooltip_state && tooltip.Deactivate();
var _menu = window.CreatePopupMenu();
_menu.AppendMenuItem(MF_ENABLED, 10, "Prefer now playing");
_menu.AppendMenuItem(MF_ENABLED, 11, "Follow selected track");
_menu.CheckMenuRadioItem(10, 11, selection_mode + 10);
_menu.EnableMenuItem(selection_mode + 10, 1);
_menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
_menu.AppendMenuItem(MF_ENABLED, 20, "Group text");
_menu.CheckMenuItem(20, group_text);
_menu.AppendMenuItem(MF_ENABLED, 30, "Tooltip");
_menu.CheckMenuItem(30, Tooltip);
_menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
_menu.AppendMenuItem(MF_ENABLED, 50, "Create txt/xls file");
_menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
MF_STRING = auto_sizing ? MF_GRAYED : MF_ENABLED;
_menu.AppendMenuItem(MF_STRING, 60, "Auto-sizing columns");
_menu.CheckMenuItem(60, auto_sizing);
_menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
_menu.AppendMenuItem(MF_ENABLED, 70, "Item text: " + lang_text[0]);
_menu.AppendMenuItem(MF_ENABLED, 71, "Item text: " + lang_text[1]);
_menu.CheckMenuRadioItem(70, 71, lang + 70);
_menu.EnableMenuItem(lang + 70, 1);
_menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
_menu.AppendMenuItem(MF_ENABLED, 80, "Copy to clipboard (all)");
_menu.AppendMenuItem(MF_ENABLED, 81, "Copy item name");
_menu.CheckMenuItem(81, clipboard_item_name);
//_menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
//_menu.AppendMenuItem(MF_ENABLED, 100, "Reload");
_menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
_menu.AppendMenuItem(MF_ENABLED, 200, "Properties");
_menu.AppendMenuItem(MF_ENABLED, 300, "Configure ...");
ret = _menu.TrackPopupMenu(x,y);
switch (ret) {
case 10:
case 11:
selection_mode = ret - 10;
window.SetProperty("selection_mode", selection_mode);
on_item_focus_change();
break;
case 20:
window.SetProperty("group text", !group_text);
group_text = window.GetProperty("group text");
break;
case 30:
window.SetProperty("tooltip", !Tooltip);
Tooltip = window.GetProperty("tooltip");
deactive_tooltip();
break;
case 50:
menu_create_file(x,y);
break;
case 60:
if (!auto_sizing){
auto_sizing = true;
window.SetProperty("auto sizing", auto_sizing);
create_array();
}
break;
case 70:
case 71:
lang = ret - 70;
window.SetProperty("lang", lang);
create_array();
break;
case 80:
ini_selected_idx(1);
copy_to_clipboard();
break;
case 81:
window.SetProperty("clipboard item name", !clipboard_item_name);
clipboard_item_name = window.GetProperty("clipboard item name");
ini_selected_idx(0);
copy_to_clipboard();
on_mouse_rbtn_up (x, y);
break;
case 100:
try {
window.Reload();
} catch(e) {};
break;
case 200:
window.ShowProperties();
break;
case 300:
window.ShowConfigure();
break;
}
_menu.Dispose();
return true;
}
///////////////////////////// Create file
var fso = new ActiveXObject("Scripting.FileSystemObject");
var output_path = fb.ProfilePath + "\\tmp_Properties\\";
function check_folder(n) {
if (!n) return;
try {
if(!fso.FolderExists(n)) {fso.CreateFolder(n)};
} catch(e) {}
}
window.GetProperty("ext", 1);
var separator = Array(" ; ","\t");
var tmp_output_item_name_array = [];
var output_array = [];
var pllist_name;
var selected;
var shift = 0;
create_tmp_output_item_name_array();
function create_tmp_output_item_name_array() {
tmp_output_item_name_array = [];
for (var j = 0; j < tfname.length; j++) {
if (tfname[j][0].search(/group|lastfm/g) < 0){
tmp_output_item_name_array.push(tfname[j][0]);
}
}
}
for (var j = 0; j < tmp_output_item_name_array.length; j++) {
window.GetProperty(j + 1, false);
}
function create_output_array() {
output_array = [];
for (var j = 0; j < tmp_output_item_name_array.length; j++) {
selected = window.GetProperty(j + 1);
if ( selected ) {output_array.push(tmp_output_item_name_array[j])};
}
createTextFile();
}
function createTextFile(){
check_folder(output_path);
count = plman.GetPlaylistSelectedItems(plman.ActivePlaylist).Count;
if (count == 0 || output_array.length == 0) return;
if (window.GetProperty("ext") == 0) {
output_file = output_path + "plist " + pllist_name + ".txt";
} else {
output_file = output_path + "plist " + pllist_name + ".xls";
}
try { file = fso.CreateTextFile( output_file )
} catch(e) { return };
var text_item_name = [];
var string_item_name = "";
for (var j = 0; j < output_array.length; j++) {
text_item_name.push(output_array[j]);
}
string_item_name = text_item_name.join(separator[window.GetProperty("ext")]);
file.WriteLine(string_item_name);
file.WriteLine("");
for (var i = 0; i < count; i++) {
item = plman.GetPlaylistSelectedItems(plman.ActivePlaylist).Item(i);
var text_item_value = [];
var string_item_value = "";
for (var j = 0; j < output_array.length; j++) {
value = fb.TitleFormat("[" + output_array[j] + "]").EvalWithMetadb(item);
text = get_measure(output_array[j]);
text = value && text ? " " + text : "";
text_item_value.push(value + text);
string_item_value = text_item_value.join(separator[window.GetProperty("ext")]);
}
try { file.WriteLine(string_item_value);
} catch(e) {};
}
file.Close();
}
function menu_create_file(x, y){
var _menu = window.CreatePopupMenu();
var i = 1;
count = plman.GetPlaylistSelectedItems(plman.ActivePlaylist).Count;
MF_STRING = count == 0 ? MF_GRAYED : MF_ENABLED;
pllist_name = plman.GetPlaylistName(plman.ActivePlaylist);
pllist_name = count == 0 ? "*" : pllist_name.replace(/[\/\:\*\?\"\<\>\|]/g,'');
_menu.AppendMenuItem(MF_STRING, i++, "Create " + pllist_name + (window.GetProperty("ext") == 0 ? ".txt" : ".xls"));
_menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
var lines = 20;
bl = tmp_output_item_name_array.length > lines ? lines + shift : tmp_output_item_name_array.length;
for (var j = shift; j < bl; j++) {
menuItem = clear_item_name(tmp_output_item_name_array[j]);
_menu.AppendMenuItem(MF_ENABLED, i++, menuItem);
_menu.CheckMenuItem(i - 1, window.GetProperty(i - 2 + shift));
}
_menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
_menu.AppendMenuItem(MF_ENABLED, 100, "txt");
_menu.AppendMenuItem(MF_ENABLED, 101, "xls");
_menu.CheckMenuRadioItem(100, 101, 100 + window.GetProperty("ext"));
_menu.EnableMenuItem(100 + window.GetProperty("ext"), 1);
_menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
_menu.AppendMenuItem(MF_ENABLED, 110, "Select all");
_menu.AppendMenuItem(MF_ENABLED, 120, "Clear all");
if (tmp_output_item_name_array.length > lines) {
_menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
_menu.AppendMenuItem(shift == 0 ? MF_GRAYED : MF_ENABLED, 130, "Up");
_menu.AppendMenuItem(shift + lines >= tmp_output_item_name_array.length ? MF_GRAYED : MF_ENABLED, 140, "Down");
}
ret = _menu.TrackPopupMenu(x, y - 250);
switch (true) {
case (ret == 1):
create_output_array();
break;
case (ret >= 2 && ret <= tmp_output_item_name_array.length + 1):
selected = window.GetProperty(ret - 1 + shift);
window.SetProperty(ret - 1 + shift, selected == false ? true : false);
menu_create_file(x,y);
break;
case (ret == 100):
window.SetProperty("ext", 0);
menu_create_file(x,y);
break;
case (ret == 101):
window.SetProperty("ext", 1);
menu_create_file(x,y);
break;
case (ret == 110):
for (var j = 1; j < tmp_output_item_name_array.length + 1; j++) {
window.SetProperty(j, true);
}
menu_create_file(x,y);
break;
case (ret == 120):
for (var j = 1; j < tmp_output_item_name_array.length + 1; j++) {
window.SetProperty(j, false);
}
menu_create_file(x,y);
break;
case (ret == 130):
shift = shift - 1;
menu_create_file(x,y);
break;
case (ret == 140):
shift = shift + 1;
menu_create_file(x,y);
break;
}
_menu.Dispose();
}
///////////////////////////// Copy to clipboard
function ini_selected_idx(n){
for (j = 0; j < item_name_array.length; j++) {
selected_idx[j] = n;
}
}
function copy_to_clipboard(){
var clipboard_text = "";
for (var i = 0; i < item_name_array.length; i++) {
if (selected_idx[i] > 0){
group = item_name_array[i].search('group') >= 0 ? true : false;
if (!group){
name = lang == 0 ? clear_item_name(item_name_array[i]) : item_name_array_2[i];
value = item_value_array[i];
name = clipboard_item_name ? name + "\t" : "";
clipboard_text = clipboard_text + name + value + (i < item_name_array.length - 1 ? "\r\n" : "");
}
}
}
htmlfile.parentWindow.clipboardData.setData("text", clipboard_text);
window.Repaint();
}
///////////////////////////// Draw star
function draw_star(gr, x, y, img_size, fill, line_thickness, color, sh, sh_color, alpha){
var radius = img_size / 2;
var radius_2 = radius / 2.61803;
line_thickness = line_thickness >= radius_2 ? radius_2 : line_thickness;
var delta = line_thickness / 2 * Math.tan(72 / 180 * Math.PI);
var points = [], sh_points = [];
var x_points_1 = [], y_points_1 = [], x_points_2 = [], y_points_2 = [];
for (var i = 0; i < 10; i++) {
if (i % 2 == 0) {
x_points_1.push((radius - delta) * Math.cos(Math.PI * i / 10 * 2 - Math.PI / 2));
y_points_1.push((radius - delta) * Math.sin(Math.PI * i / 10 * 2 - Math.PI / 2));
} else {
x_points_2.push((radius - delta) / 2.61803 * Math.cos(Math.PI * i / 10 * 2 - Math.PI / 2));
y_points_2.push((radius - delta) / 2.61803 * Math.sin(Math.PI * i / 10 * 2 - Math.PI / 2));
}
}
for (var i = 0; i < 5; i++) {
points.push(x_points_1[i] + radius, y_points_1[i] + radius, x_points_2[i] + radius, y_points_2[i] + radius);
sh_points.push(x_points_1[i] + radius + 1, y_points_1[i] + radius + 1, x_points_2[i] + radius + 1, y_points_2[i] + radius + 1);
}
var img = gdi.CreateImage(img_size, img_size);
var temp_gr = img.GetGraphics();
temp_gr.SetSmoothingMode(2);
if (line_thickness > 0) {
sh && temp_gr.DrawPolygon(sh_color, line_thickness, sh_points);
temp_gr.DrawPolygon(color, line_thickness, points);
}
if (fill && line_thickness == 0) {
sh && temp_gr.FillPolygon(sh_color, 1, sh_points);
temp_gr.FillPolygon(color, 1, points)
}
gr.DrawImage(img, x - radius, y - radius, img_size, img_size, 0, 0, img_size, img_size, 0, alpha);
img.ReleaseGraphics(temp_gr);
img.Dispose();
temp_gr = null;
img = null;
}
///////////////////////////// wsh tooltip (custom paint)
function active_tooltip(){
if (!tooltip_state){
tooltip_state = true;
tooltip.Activate();
tooltip.TrackActivate = true;
}
}
function deactive_tooltip(){
tooltip_time.Reset();
if (tooltip_state){
tooltip.Deactivate();
tooltip.TrackActivate = false;
tooltip_state = false;
}
}
function on_tooltip_custom_paint(gr){
for (var i = 0; i < tooltip_t.length; i += 1) {
gr.GdiDrawText( tooltip_t[i], font_tooltip, RGB(0,0,0), 5, tooltip_t_h * i + 1, tooltip.Width, tooltip.Height, DT_LEFT | DT_WORDBREAK | DT_NOPREFIX );
}
}
function tooltip_activate_wsh(x, y) {
tooltip_x = t_x2 - 5;
tooltip_y = idx * f_h - Math.abs(s);
var value_width = calc_text_data( "w", item_value_array[idx], font_item_value );
if (value_width > ww - t_x2 - t_x1 && x > t_x2 && x < ww - t_x1 && y > tooltip_y + 1 && y < tooltip_y + f_h - 1){
if (tooltip_time.Time > tooltip_delay_time && !tooltip_state) {
tooltip_text = item_value_array[idx];
calc_tooltip_dim();
tooltip.TrackPosition( tooltip_x, tooltip_y + window.GetProperty(" vertical item padding") / 2);
active_tooltip();
tooltip.Text = " ";
}
} else {
deactive_tooltip();
}
}
function calc_tooltip_dim(){
tooltip_t_w = calc_text_data( "w", tooltip_text, font_tooltip );
tooltip_t_h = calc_text_data( "h", tooltip_text, font_tooltip );
tooltip_t_tmp = calc_text_data( "a", tooltip_text, font_tooltip, tooltip_max_w );
tooltip_t = [];
tooltip_l = [];
for (var i = 0; i < tooltip_t_tmp.length; i += 1) {
if (i % 2 == 0) {
tooltip_t.push(tooltip_t_tmp[i].replace(/^\s+|\s+$/g, ""));
} else {
tooltip_l.push(tooltip_t_tmp[i]);
}
}
if (tooltip_t_w <= tooltip_max_w){
tooltip.Width = tooltip_t_w + 5;
tooltip.Height = tooltip_t_h;
} else {
tooltip.Width = Math.max.apply(null, tooltip_l) + 5;
tooltip.Height = tooltip_t_h * tooltip_t.length;
}
}
function calc_text_data(d, text, font, max_w) {
var temp_bmp = gdi.CreateImage(1, 1);
var temp_gr = temp_bmp.GetGraphics();
var tmp;
switch (d) {
case "w":
tmp = temp_gr.CalcTextWidth(text, font);
break;
case "h":
tmp = temp_gr.CalcTextHeight(text, font);
break;
case "a":
tmp = temp_gr.EstimateLineWrap(text, font, max_w).toArray();
break;
}
temp_bmp.ReleaseGraphics(temp_gr);
temp_bmp.Dispose();
temp_gr = null;
temp_bmp = null;
return tmp;
}
///////////////////////////// jscript tooltip
function tooltip_activate_jscript(x, y) {
tooltip_x = t_x2 - 5;
tooltip_y = idx * f_h - Math.abs(s);
var value_width = calc_text_data("w", item_value_array[idx], font_item_value)
if (value_width > ww - t_x2 - t_x1 && x > t_x2 && x < ww - t_x1 && y > tooltip_y + 1 && y < tooltip_y + f_h - 1){
if (tooltip_time.Time > tooltip_delay_time) {
tooltip.Text = item_value_array[idx];
tooltip.TrackPosition( tooltip_x, tooltip_y + window.GetProperty(" vertical item padding") / 2);
tooltip.TrackActivate = true;
tooltip.Activate();
tooltip_state = true;
}
} else {
deactive_tooltip();
}
}
///////////////////////////// lastFM data
function get_lastFM_similar(a){
if (!a) return
var xmlhttp0 = new ActiveXObject("Microsoft.XMLHTTP");
var url0 = ("https://www.last.fm/music/" + encodeURIComponent(a) + "/+similar");
xmlhttp0.open("GET", url0, true );
xmlhttp0.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
xmlhttp0.send(null);
xmlhttp0.onreadystatechange = function () {
if (xmlhttp0.readyState == 4) {
if (xmlhttp0.status == 200) {
doc.open();
var div = doc.createElement("div");
div.innerHTML = xmlhttp0.responsetext;
var a = div.getElementsByTagName("a");
var tmp = [];
var j = 0;
for (i = 0; i < a.length; i++) {
if (a[i].className == "link-block-target"){
tmp[j] = a[i].innerHTML.replace(/(&)/g,'&');
j++
if (j == 6) break;
}
}
doc.close();
similar = tmp.join(";");
create_array();
}
}
}
}
function get_lastFM_artist_info(a){
if (!a) return
var xmlhttp1 = new ActiveXObject("Microsoft.XMLHTTP");
var url1 = ("https://www.last.fm/music/" + encodeURIComponent(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 abbr = div.getElementsByTagName("abbr");
for (i = 0; i < abbr.length; i++) {
if (abbr[i].className == "intabbr"){
artist_info.push(abbr[i].title.replace(/\,/g, " "));
}
}
doc.close();
create_array();
}
}
}
}
function get_lastFM_album_info(a, al){
if (!a || !al) return
var xmlhttp2 = new ActiveXObject("Microsoft.XMLHTTP");
var url2 = ("https://www.last.fm/music/" + encodeURIComponent(a) + "/" + encodeURIComponent(al));
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 abbr = div.getElementsByTagName("abbr");
for (i = 0; i < abbr.length; i++) {
if (abbr[i].className == "intabbr"){
album_info.push(abbr[i].title.replace(/\,/g, " "));
}
}
doc.close();
create_array();
}
}
}
}
function print(msg) {
fb.trace(msg);
}
// ==PREPROCESSOR==
// @name "Create rating autoPlaylist"
// @feature "v1.4"
// @feature "watch-metadb"
// ==/PREPROCESSOR==
function RGB(r,g,b) { return (0xff000000|(r<<16)|(g<<8)|(b)); }
var font = gdi.Font("arial",12,0);
var ww,wh;
DT_LEFT = 0x00000000;
DT_CENTER = 0x00000001;
DT_VCENTER = 0x00000004;
DT_SINGLELINE = 0x00000020;
MF_ENABLED = 0x00000000;
MF_GRAYED = 0x00000001;
MF_SEPARATOR = 0x00000800;
var q_r1 = window.GetProperty("r1", 0);
var q_r2 = window.GetProperty("r2", 0);
var q_r3 = window.GetProperty("r3", 0);
var q_r4 = window.GetProperty("r4", 0);
var q_r5 = window.GetProperty("r5", 5);
var q_artist = window.GetProperty("artist", true);
var q_album = window.GetProperty("album", false);
var q_auto_del_pll = window.GetProperty("autodelete playlist", true);
var q_auto_play = window.GetProperty("autoplay", true);
function on_paint(gr){
gr.GdiDrawText("on_mouse_lbtn_up", font, RGB(10,10,10), 0, 0, ww, wh, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
}
on_item_focus_change();
function on_playlist_switch() {
on_item_focus_change();
}
function on_playback_new_track() {
on_item_focus_change(); //
}
function on_selection_changed(metadb) {
on_item_focus_change(); //
}
function on_playback_stop() {
on_item_focus_change();
}
function on_item_focus_change() {
metadb = fb.IsPlaying ? fb.GetNowPlaying() : fb.GetFocusItem();
if (metadb) on_metadb_changed();
}
function on_metadb_changed() {
if (metadb){
artist = fb.TitleFormat("$if2(%artist%,)").EvalWithMetadb(metadb);
album = fb.TitleFormat("$if2(%album%,)").EvalWithMetadb(metadb);
}
}
var query;
var artist, album;
var sort_string = "%artist% - %date% - %album% - %discnumber% - %tracknumber% - %title%";
function on_mouse_lbtn_up(x, y){
if (q_r1 + q_r2 + q_r3 + q_r4 + q_r5 == 0) window.SetProperty("r5", 5);
q_r5 = window.GetProperty("r5");
var _menu = window.CreatePopupMenu();
_menu.AppendMenuItem(MF_ENABLED, 1, "r 1");
_menu.CheckMenuItem(1, q_r1);
_menu.AppendMenuItem(MF_ENABLED, 2, "r 2");
_menu.CheckMenuItem(2, q_r2);
_menu.AppendMenuItem(MF_ENABLED, 3, "r 3");
_menu.CheckMenuItem(3, q_r3);
_menu.AppendMenuItem(MF_ENABLED, 4, "r 4");
_menu.CheckMenuItem(4, q_r4);
_menu.AppendMenuItem(MF_ENABLED, 5, "r 5");
_menu.CheckMenuItem(5, q_r5);
_menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
MF = artist ? MF_ENABLED : MF_GRAYED;
_menu.AppendMenuItem(MF, 10, "Artist : " + artist);
_menu.CheckMenuItem(10, q_artist);
MF = album ? MF_ENABLED : MF_GRAYED;
_menu.AppendMenuItem(MF, 20, "Album : " + album);
_menu.CheckMenuItem(20, q_album);
MF_STRING = artist && album ? MF_ENABLED : MF_GRAYED;
_menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
_menu.AppendMenuItem(MF_STRING, 30, "CREATE PLAYLIST" + (!q_artist && !q_album ? " (Library)" : ""));
_menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
_menu.AppendMenuItem(MF_ENABLED, 40, "Autoplay");
_menu.CheckMenuItem(40, q_auto_play);
_menu.AppendMenuItem(MF_ENABLED, 50, "Delete previous playlist");
_menu.CheckMenuItem(50, q_auto_del_pll);
_menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
_menu.AppendMenuItem(MF_ENABLED, 100, "Properties");
_menu.AppendMenuItem(MF_ENABLED, 120, "Configure ...");
ret = _menu.TrackPopupMenu(x + 20, y - 20);
if (ret == 0) return;
switch (ret) {
case 1:
case 2:
case 3:
case 4:
case 5:
window.GetProperty("r" + ret) == 0 ? window.SetProperty("r" + ret, ret) : window.SetProperty("r" + ret, 0);
q_r1 = window.GetProperty("r1");
q_r2 = window.GetProperty("r2");
q_r3 = window.GetProperty("r3");
q_r4 = window.GetProperty("r4");
q_r5 = window.GetProperty("r5");
on_mouse_lbtn_up(x, y);
break;
case 10:
window.SetProperty("artist", !q_artist);
q_artist = window.GetProperty("artist");
on_mouse_lbtn_up(x, y);
break;
case 20:
window.SetProperty("album", !q_album);
q_album = window.GetProperty("album");
on_mouse_lbtn_up(x, y);
break;
case 30:
createAutoPlaylist();
break;
case 40:
window.SetProperty("autoplay", !q_auto_play);
q_auto_play = window.GetProperty("autoplay");
on_mouse_lbtn_up(x, y);
break;
case 50:
window.SetProperty("auto delete playlist", !q_auto_del_pll);
q_auto_del_pll = window.GetProperty("auto delete playlist");
on_mouse_lbtn_up(x, y);
break;
case 100:
window.ShowProperties();
break;
case 120:
window.ShowConfigure();
break;
}
_menu.Dispose();
return true;
}
function createAutoPlaylist() {
query = "";
var r_array = [q_r1, q_r2, q_r3, q_r4, q_r5];
var r_morethan = [];
for (i = 0; i < r_array.length; i++) {
if (r_array[i] != 0) r_morethan.push(r_array[i]);
}
min_r = Math.min.apply(null, r_morethan) - 1;
max_r = Math.max.apply(null, r_morethan) + 1;
q1 = "((%rating% GREATER " + min_r + " AND %rating% LESS " + max_r + ") OR (rating GREATER " + min_r + " AND rating LESS " + max_r + "))";
q2 = q_artist ? " AND %artist% IS " + artist : "";
q3 = q_album ? " AND %album% IS " + album : "";
query = q1 + q2 + q3;
if (q_auto_del_pll) remove_pll("rating");
idx = plman.PlaylistCount;
txt0 = r_morethan.join(' ') + ":";
txt1 = q_artist ? " " + artist : "";
txt2 = q_album ? " " + album : "";
txt3 = !q_artist && !q_album ? " Library" : "";
autopllname = "rating " + txt0 + txt1 + txt2 + txt3;
fb.CreateAutoPlaylist(idx, autopllname, query, sort_string, 0);
check_pllist(idx);
}
function check_pllist(idx) {
count = plman.PlaylistItemCount(idx);
if (count > 0){
plman.ActivePlaylist = idx;
if (q_auto_play) execute_pll(idx);
} else {
plman.RemovePlaylist(idx);
}
}
function remove_pll(pll_name){
remove_idx = plman.PlaylistCount;
for (var i = remove_idx; i > 0; i--) {
if (plman.GetPlaylistName(i).indexOf(pll_name) >= 0) {plman.RemovePlaylist(i)}
}
}
function execute_pll(idx){
plman.ExecutePlaylistDefaultAction(idx, 0);
}
function on_size(){
ww = window.Width;
wh = window.Height;
}
Вернуться в Секреты foobar2000