Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==PREPROCESSOR==
- // @import "%fb2k_profile_path%marc2003\common.js"
- // @name "Thumbs2"
- // @author "marc2003"
- // ==/PREPROCESSOR==
- var panel_id = window.GetProperty("panel_id", window.id);
- var cycle_tf_file = settings_path + panel_id + "cycle";
- var cycle_tf = read(cycle_tf_file);
- var g_img = arr = new Array();
- var artist = '';
- var folder = '';
- var index = 0;
- var offset = 0;
- var my_y = 0;
- var but_y = 0;
- var x_off = 0;
- var images_width = 0;
- var working = false;
- var blacklist_file = '';
- var back_img = gdi.Image(images_path + "back.png");
- var forward_img = gdi.Image(images_path + "forward.png");
- var thumb_size = window.GetProperty("thumb_size", 75);
- var square = window.GetProperty("square", false);
- var cycle = window.GetProperty("cycle", 200) - 200;
- var limit = window.GetProperty("limit", 305) - 300;
- window.GetProperty("bl", true);
- window.GetProperty("auto", true);
- window.GetProperty("mode", 101);
- on_item_focus_change();
- function on_playback_time(time) {
- if(cycle > 0 && arr.length > 1 && (time % cycle == 0)) on_mouse_wheel(-1);
- if(window.GetProperty("mode") == 101 && time == 1 && arr.length == 0 && window.GetProperty("auto")) download_images();
- }
- function on_mouse_move(x, y) {
- my_y = y;
- switch(true) {
- case (!g_metadb):
- case (g_img.length == 0):
- window.SetCursor(IDC_ARROW);
- break;
- case (g_img.length == 1):
- case (g_img.length > columns && offset > 0 && x > (x_off - 25) && x< x_off - 5 && y > but_y && y < but_y + 20):
- case (g_img.length > columns && offset < g_img.length - columns && x > x_off + images_width + 5 && x < x_off + images_width + 25 && y > but_y && y < but_y + 20):
- case (y > 20 && y < wh - (thumb_size + 30)):
- case (y > wh - thumb_size - 12 && x > x_off && x < x_off + images_width):
- window.SetCursor(IDC_HAND);
- break;
- default:
- window.SetCursor(IDC_ARROW);
- }
- }
- function on_mouse_lbtn_up(x,y) {
- switch(true) {
- case (!g_metadb):
- case (g_img.length == 0):
- return;
- case (g_img.length == 1):
- case (y > 10 && y < wh - (thumb_size + 30)):
- try { WshShell.Run("\"" + arr[index] + "\""); } catch(e) {}
- break;
- case (y > wh - thumb_size - 12 && x > x_off && x < x_off + images_width):
- index = Math.floor(((x - x_off) / (thumb_size + 10)) + offset);
- window.RepaintRect(0, 0, ww, wh - thumb_size - 15);
- break;
- case (g_img.length > columns && offset > 0 && x > (x_off - 25) && x< x_off - 5 && y > but_y && y < but_y + 20):
- offset--;
- window.RepaintRect(0, wh - thumb_size - 15, ww, thumb_size + 15);
- break;
- case (g_img.length > columns && offset < g_img.length - columns && x > x_off + images_width + 5 && x < x_off + images_width + 25 && y > but_y && y < but_y + 20):
- offset++;
- window.RepaintRect(0, wh - thumb_size - 15, ww, thumb_size + 15);
- break;
- default:
- }
- }
- function clear_cache() {
- if(g_img.length == 0) return;
- for(i = 0; i < g_img.length; i++) {
- g_img[i].Dispose();
- }
- g_img = new Array();
- window.Repaint();
- }
- function on_playback_new_track() {
- on_item_focus_change();
- }
- function on_metadb_changed() {
- if(window.GetProperty("mode") == 101 && artist == fb.TitleFormat("%artist%").EvalWithMetadb(g_metadb)) return;
- if(window.GetProperty("mode") == 102 && folder == fb.TitleFormat(cycle_tf).EvalWithMetadb(g_metadb)) return;
- update_image();
- }
- function update_image() {
- if(!g_metadb) return;
- clear_cache();
- if(window.GetProperty("mode") == 101) {
- artist = fb.TitleFormat("%artist%").EvalWithMetadb(g_metadb);
- folder = data_folder + fb.TitleFormat("$crc32(%artist%)").EvalWithMetadb(g_metadb);
- bl();
- } else {
- folder = fb.TitleFormat(cycle_tf).EvalWithMetadb(g_metadb);
- }
- arr = read_images();
- offset = 0;
- index = 0;
- load_image();
- }
- function load_image() {
- g_img = new Array();
- for(i = 0; i < arr.length; i++) {
- g_img[i] = gdi.Image(arr[i]);
- }
- window.Repaint();
- }
- function on_mouse_wheel(delta) {
- if(!g_metadb || g_img.length < 2) return;
- if(my_y < wh - (thumb_size + 30)) {
- index += -delta;
- if(index < 0) index = g_img.length - 1;
- if(index >= g_img.length) index = 0;
- window.RepaintRect(0, 0, ww, wh - thumb_size - 15);
- } else {
- if(g_img.length < columns) return;
- offset += -delta;
- if(offset < 0) offset = 0;
- if(offset > g_img.length - columns) offset = g_img.length - columns;
- window.RepaintRect(0, wh - thumb_size - 15, ww, thumb_size + 15);
- }
- }
- function on_size() {
- ww = window.width;
- wh = window.height;
- columns = Math.floor((ww - 50) / (thumb_size + 10));
- offset = 0;
- }
- function on_paint(gr) {
- gr.SetInterpolationMode(6);
- gr.FillSolidRect(0, 0, ww, wh, g_backcolor);
- switch(true) {
- case (!g_metadb):
- gr.GdiDrawText("[no selection]", g_font, g_textcolor, 0, 0, ww, wh, DT_VCENTER | DT_CENTER | DT_WORDBREAK | DT_CALCRECT | DT_NOPREFIX);
- break;
- case (working):
- gr.GdiDrawText("[fetching images]", g_font, g_textcolor, 0, 0, ww, wh, DT_VCENTER | DT_CENTER | DT_WORDBREAK | DT_CALCRECT | DT_NOPREFIX);
- break;
- case (g_img.length == 0):
- gr.GdiDrawText("[no image]", g_font, g_textcolor, 0, 0, ww, wh, DT_VCENTER | DT_CENTER | DT_WORDBREAK | DT_CALCRECT | DT_NOPREFIX);
- break;
- case (g_img.length == 1):
- scale2(gr, g_img[0], 10, 10, ww - 20, wh - 20, false);
- break;
- default:
- temp = Math.min(columns, g_img.length);
- images_width = (thumb_size * temp) + (temp > 1 ? (temp - 1) * 10 : 0);
- x_off = Math.round((ww - images_width) / 2);
- current_image = offset;
- for(col = 0; col < temp; col++) {
- g_img[current_image] && scale2(gr, g_img[current_image], x_off + (col * (thumb_size + 10)), wh - thumb_size - 10, thumb_size, thumb_size, square);
- current_image++;
- }
- scale2(gr, g_img[index], 10, 20, ww - 20, wh - thumb_size - 50, false);
- if(g_img.length > columns) {
- but_y = wh - thumb_size - 10 + (Math.round((thumb_size - 20) / 2));
- if(offset > 0) gr.DrawImage(back_img, x_off - 25, but_y, 20, 20, 0, 0, 20, 20);
- if(offset < g_img.length - columns) gr.DrawImage(forward_img, x_off + images_width + 5, but_y, 20, 20, 0, 0, 20, 20);
- }
- break;
- }
- }
- function on_mouse_rbtn_up(x, y) {
- var _menu = window.CreatePopupMenu();
- var _lastfm_options = window.CreatePopupMenu();
- var _limit = window.CreatePopupMenu();
- var _thumb = window.CreatePopupMenu();
- var _mode = window.CreatePopupMenu();
- var _cycle = window.CreatePopupMenu();
- var _selection = window.CreatePopupMenu();
- var idx;
- if(window.GetProperty("mode") == 101) {
- _menu.AppendMenuItem(g_metadb ? MF_STRING : MF_GRAYED, 11, "Download artist art from Last.fm");
- _lastfm_options.AppendMenuItem(MF_STRING, 1000, "Automatically download");
- _lastfm_options.CheckMenuItem(1000, window.GetProperty("auto"));
- _limit.AppendMenuItem(MF_STRING, 301, "1");
- _limit.AppendMenuItem(MF_STRING, 303, "3");
- _limit.AppendMenuItem(MF_STRING, 305, "5");
- _limit.AppendMenuItem(MF_STRING, 310, "10");
- _limit.AppendMenuItem(MF_STRING, 320, "20");
- _limit.CheckMenuRadioItem(301, 320, window.GetProperty("limit"));
- _lastfm_options.AppendMenuItem(MF_STRING | MF_POPUP, _limit.ID, "Limit");
- _lastfm_options.AppendMenuItem(MF_SEPARATOR, 0, 0);
- _lastfm_options.AppendMenuItem(MF_STRING, 1001, "Blacklist deleted images");
- _lastfm_options.CheckMenuItem(1001, window.GetProperty("bl"));
- _lastfm_options.AppendMenuItem(fso.FileExists(blacklist_file) ? MF_STRING : MF_GRAYED, 1002, "Clear blacklist for this artist");
- _lastfm_options.AppendMenuItem(MF_SEPARATOR, 0, 0);
- _lastfm_options.AppendMenuItem(MF_STRING, 1003, "Explain blacklisting");
- _menu.AppendMenuItem(MF_STRING | MF_POPUP, _lastfm_options.ID, "Last.fm options");
- _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
- }
- _thumb.AppendMenuItem(MF_STRING, 1075, "75px");
- _thumb.AppendMenuItem(MF_STRING, 1100, "100px");
- _thumb.AppendMenuItem(MF_STRING, 1150, "150px");
- _thumb.AppendMenuItem(MF_STRING, 1200, "200px");
- _thumb.AppendMenuItem(MF_SEPARATOR, 0, 0);
- _thumb.AppendMenuItem(MF_STRING, 2000, "Square");
- _thumb.CheckMenuItem(2000, square);
- _thumb.CheckMenuRadioItem(1075, 1200, window.GetProperty("thumb_size") + 1000);
- _menu.AppendMenuItem(MF_STRING | MF_POPUP, _thumb.ID, "Thumbnails");
- _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
- _cycle.AppendMenuItem(MF_STRING, 200, "Off");
- _cycle.AppendMenuItem(MF_STRING, 205, "5 seconds");
- _cycle.AppendMenuItem(MF_STRING, 210, "10 seconds");
- _cycle.AppendMenuItem(MF_STRING, 220, "20 seconds");
- _cycle.CheckMenuRadioItem(200, 220, window.GetProperty("cycle"));
- _menu.AppendMenuItem(MF_STRING | MF_POPUP, _cycle.ID, "Cycle");
- _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
- _menu.AppendMenuItem(g_metadb && fso.FolderExists(folder) ? MF_STRING : MF_GRAYED, 12, "Open containing folder");
- if(g_img.length > 0 && y < wh - 40 - thumb_size) _menu.AppendMenuItem(MF_STRING, 15, "Delete this image");
- _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
- _mode.AppendMenuItem(MF_STRING, 101, "Last.fm Artist Art");
- _mode.AppendMenuItem(MF_STRING, 102, "Custom Folder");
- _mode.AppendMenuItem(MF_SEPARATOR, 0, 0);
- _mode.CheckMenuRadioItem(101, 102, window.GetProperty("mode"));
- _mode.AppendMenuItem(window.GetProperty("mode") == 102 ? MF_STRING : MF_GRAYED, 21, "Set Custom Folder....");
- _menu.AppendMenuItem(MF_STRING | MF_POPUP, _mode.ID, "Mode");
- _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
- _menu.AppendMenuItem(MF_STRING | MF_POPUP, _selection.ID, "Selection mode");
- _selection.AppendMenuItem(MF_STRING, 900, "Use display preferences");
- _selection.AppendMenuItem(MF_STRING, 901, "Prefer now playing");
- _selection.AppendMenuItem(MF_STRING, 902, "Follow selected track");
- _selection.CheckMenuRadioItem(900, 903, selection_mode + 900);
- _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
- if(utils.IsKeyPressed(0x10)) _menu.AppendMenuItem(MF_STRING, 99, "Properties");
- _menu.AppendMenuItem(MF_STRING, 100, "Configure...");
- idx = _menu.TrackPopupMenu(x, y);
- switch(idx) {
- case 101:
- case 102:
- window.SetProperty("mode", idx);
- update_image();
- break;
- case 200:
- case 205:
- case 210:
- case 220:
- window.SetProperty("cycle", idx);
- cycle = idx - 200;
- break;
- case 301:
- case 303:
- case 305:
- case 310:
- case 320:
- window.SetProperty("limit", idx);
- limit = idx - 300;
- break;
- case 11:
- download_images();
- break;
- case 12:
- try { WshShell.Run("explorer \"" + folder + "\""); } catch(e) {}
- break;
- case 15:
- clear_cache();
- try {
- if(window.GetProperty("mode") == 101 && window.GetProperty("bl") == true) {
- ts = fso.OpenTextFile(blacklist_file, 2, true, -1);
- ts.WriteLine(blacklist + arr[index] + "|") ;
- ts.close();
- }
- fso.DeleteFile(arr[index]);
- } catch(e) {
- fb.trace("Error: Could not delete " + arr[index]);
- }
- update_image();
- break;
- case 21:
- cycle_tf = text_input_box("Thumbs2", "Enter title formatting or an absolute path to a folder.\n\nYou can specify multiple folders using | as a separator.", cycle_tf_file);
- update_image();
- break;
- case 99:
- window.ShowProperties();
- break;
- case 100:
- window.ShowConfigure();
- break;
- case 1000:
- window.SetProperty("auto", !window.GetProperty("auto"));
- break;
- case 1001:
- window.SetProperty("bl", !window.GetProperty("bl"));
- break;
- case 1002:
- try { fso.DeleteFile(blacklist_file); } catch(e) {}
- break;
- case 1003:
- fb.ShowPopupMessage("When you delete an image, there is no way for this script to prevent it being downloaded again. As a workaround, you can \"blacklist\" images you don't want and they will be deleted after downloading is complete.", "Thumbs2");
- break;
- case 1075:
- case 1100:
- case 1150:
- case 1200:
- window.SetProperty("thumb_size", idx -1000);
- thumb_size = window.GetProperty("thumb_size");
- columns = Math.floor((ww - 50) / (thumb_size + 10));
- offset = 0;
- window.Repaint();
- break;
- case 2000:
- window.SetProperty("square",!square);
- square = window.GetProperty("square");
- window.Repaint();
- break;
- case 900:
- case 901:
- case 902:
- window.SetProperty("selection_mode", idx - 900);
- selection_mode = window.GetProperty("selection_mode");
- on_item_focus_change();
- break;
- }
- _selection.Dispose();
- _mode.Dispose();
- _limit.Dispose();
- _lastfm_options.Dispose();
- _thumb.Dispose();
- _cycle.Dispose();
- _menu.Dispose();
- return true;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement