Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var VERSION = "8.2014-12-20.03";
- /*
- (c) 2010-2014 marc2003
- Please do not distribute modified versions of this file with your own scripts or themes.
- You should be able to customise pretty much anything you want by editing the script
- in your panel, not in this file. Leaving this intact and in its correct location
- means you/other people can get bug fixes by using the "Update script" option on the
- right click menu. If you need any help with customising then just come and ask on
- hydrogenaudio.
- http://www.hydrogenaud.io/forums/index.php?showtopic=77883
- */
- var DT_LEFT = 0x00000000;
- var DT_CENTER = 0x00000001;
- var DT_RIGHT = 0x00000002;
- var DT_VCENTER = 0x00000004;
- var DT_WORDBREAK = 0x00000010;
- var DT_CALCRECT = 0x00000400;
- var DT_NOPREFIX = 0x00000800;
- var DT_END_ELLIPSIS = 0x00008000;
- var MF_GRAYED = 0x00000001;
- var MF_STRING = 0x00000000;
- var IDC_ARROW = 32512;
- var IDC_HAND = 32649;
- var ONE_DAY = 86400000;
- var ONE_WEEK = 604800000;
- var TPM_RIGHTALIGN = 0x0008;
- try {
- var doc = new ActiveXObject("htmlfile");
- var app = new ActiveXObject("Shell.Application");
- var WshShell = new ActiveXObject("WScript.Shell");
- var fso = new ActiveXObject("Scripting.FileSystemObject");
- var vb = new ActiveXObject("ScriptControl");
- vb.Language = "VBScript";
- } catch(e) {
- fb.ShowPopupMessage("Failed to load required system components. Please check \"Safe mode\" has been turned off.\n\nFile>Preferences>Tools>WSH Panel Mod");
- }
- String.prototype.addCommas = function() {
- return this.replace(/\B(?=(\d{3})+(?!\d))/g, ",");
- }
- String.prototype.trim = function() {
- return this.replace(/^\s+|\s+$/g, "");
- }
- String.prototype.ucfirst = function() {
- return this.charAt(0).toUpperCase() + this.substr(1);
- }
- String.prototype.sp = function() {
- if (this.is_file()) {
- return fso.GetFile(this).ShortPath;
- } else {
- p.console("File not found: " + this);
- return this;
- }
- }
- String.prototype.last_modified = function() {
- return Date.parse(fso.Getfile(this).DateLastModified);
- }
- String.prototype.is_file = function() {
- return fso.FileExists(this);
- }
- String.prototype.is_folder = function() {
- return fso.FolderExists(this);
- }
- String.prototype.create = function() {
- if (!this.is_folder()) fso.CreateFolder(this);
- }
- String.prototype.get_files = function(exts) {
- var files = [];
- if (this.is_folder()) {
- var f, fi, path, ext;
- f = fso.GetFolder(this);
- fi = new Enumerator(f.files);
- for (; !fi.atEnd(); fi.moveNext()) {
- path = fi.item().path;
- ext = path.split(".").pop().toLowerCase();
- if (exts.toLowerCase().indexOf(ext) > -1) files.push(path);
- }
- }
- return files;
- }
- String.prototype.expired = function(p) {
- return Date.parse(Date()) - this.last_modified() > p;
- }
- String.prototype.validate = function() {
- return this.replace(/[\/\\|:]/g, '-').replace(/\*/g, 'x').replace(/"/g, "''").replace(/[<>]/g, '_').replace(/\?/g, "");
- }
- function tf(t, metadb) {
- return metadb ? fb.TitleFormat(t).EvalWithMetadb(metadb).trim() : "";
- }
- function tfe(t, f) {
- return fb.TitleFormat(t).Eval(f).trim();
- }
- function RGB(r, g, b) {
- return 0xff000000 | r << 16 | g << 8 | b;
- }
- function RGBA(r, g, b, a) {
- return a << 24 | r << 16 | g << 8 | b;
- }
- function toRGB(c) {
- return [c >> 16, c >> 8 & 0xFF, c & 0xFF];
- }
- function blend_colours(c1, c2, f) {
- c1 = toRGB(c1);
- c2 = toRGB(c2);
- var r = Math.round(c1[0] + f * (c2[0] - c1[0]));
- var g = Math.round(c1[1] + f * (c2[1] - c1[1]));
- var b = Math.round(c1[2] + f * (c2[2] - c1[2]));
- return RGB(r, g, b);
- }
- function on_colors_changed() {
- p.colours_changed();
- }
- function on_font_changed() {
- p.font_changed();
- }
- function on_selection_changed() {
- p.item_focus_change();
- }
- function on_playlist_switch() {
- p.item_focus_change();
- }
- function on_playback_new_track() {
- p.item_focus_change();
- }
- function on_playback_dynamic_info_track() {
- p.item_focus_change();
- }
- function on_playback_stop() {
- p.item_focus_change();
- }
- function on_item_focus_change() {
- p.item_focus_change();
- }
- function on_mouse_leave() {
- if (typeof p.menu_btn == "object") p.menu_btn.leave();
- if (typeof b == "object") b.leave();
- if (typeof r == "object") r.leave();
- if (typeof li == "object") li.leave();
- p.tt("");
- }
- function on_mouse_rbtn_up(x, y) {
- p.rbtn_up(x, y);
- return true;
- }
- function on_notify_data(name, data) {
- if (name == "lastfm" && data == "update" && typeof l == "object") l.notify_data();
- if (name == "autoplaylists" && data == "update" && typeof li == "object" && li.mode == "autoplaylists") li.update();
- if (name == "love" && typeof ps == "object") l.post(tf("%LASTFM_LOVED_DB%", data) == 1 ? "track.unlove" : "track.love", data);
- }
- function panel(name, features) {
- this.item_focus_change = function() {
- if (!this.metadb_func) return;
- switch(true) {
- case typeof ps == "object":
- case this.selection_mode == 1:
- this.metadb = fb.IsPlaying ? fb.GetNowPlaying() : fb.GetFocusItem();
- break;
- case this.selection_mode == 0:
- this.metadb = fb.GetSelection();
- break;
- case this.selection_mode == 2:
- this.metadb = fb.GetFocusItem();
- break;
- }
- if (this.metadb) on_metadb_changed();
- }
- this.colours_changed = function() {
- if (this.is_dui) {
- this.textcolour = window.GetColorDUI(0);
- this.backcolour = window.GetColorDUI(1);
- this.textcolour_hl = window.GetColorDUI(2);
- } else {
- this.textcolour = window.GetColorCUI(0);
- this.backcolour = window.GetColorCUI(3);
- this.textcolour_hl = blend_colours(this.textcolour, this.backcolour, 0.4);
- }
- window.Repaint();
- }
- this.font_changed = function() {
- this.font = this.is_dui ? window.GetFontDUI(0) : window.GetFontCUI(0);
- try {
- this.font_name = this.font.Name;
- } catch(e) {
- this.console("Unable to use your default font. Using Segoe UI instead.");
- this.font_name = "Segoe UI";
- }
- this.title_font = gdi.Font(this.font_name, 16, 1);
- this.normal_font = gdi.Font(this.font_name, this.normal_font_size);
- this.list_font = gdi.Font(this.font_name, this.list_font_size);
- this.fixed_font = gdi.Font("Lucida Console", this.normal_font_size);
- this.row_height = this.normal_font.Height + 2;
- if (typeof t == "object") t.size();
- if (typeof li == "object") {
- switch(li.mode) {
- case "lastfm_charts":
- case "autoplaylists":
- li.update();
- break;
- default:
- li.artist = "";
- this.item_focus_change();
- break;
- }
- }
- window.Repaint();
- }
- this.size = function() {
- this.w = window.Width;
- this.h = window.Height;
- }
- this.move = function(x, y) {
- if (typeof this.menu_btn == "object" && !this.hover) {
- this.hover = true;
- window.RepaintRect(this.menu_btn.x, this.menu_btn.y, this.menu_btn.w, this.menu_btn.h);
- }
- this.mx = x;
- this.my = y;
- }
- this.rbtn_up = function(x, y) {
- var _menu = window.CreatePopupMenu();
- var _custom_background = window.CreatePopupMenu();
- var _metadb = window.CreatePopupMenu();
- var _cover = window.CreatePopupMenu();
- var _font = window.CreatePopupMenu();
- var _sub1 = window.CreatePopupMenu();
- var _sub2 = window.CreatePopupMenu();
- var _sub3 = window.CreatePopupMenu();
- var _sub4 = window.CreatePopupMenu();
- var _sub5 = window.CreatePopupMenu();
- var _sub6 = window.CreatePopupMenu();
- var _sub7 = window.CreatePopupMenu();
- switch(true) {
- case typeof a == "object" && a.trace(x, y):
- _menu.AppendMenuItem(MF_STRING, 100, "Refresh");
- _menu.AppendMenuSeparator();
- _menu.AppendMenuItem(MF_STRING, 101, "Front");
- _menu.AppendMenuItem(MF_STRING, 102, "Back");
- _menu.AppendMenuItem(MF_STRING, 103, "Disc");
- _menu.AppendMenuItem(MF_STRING, 104, "Icon");
- _menu.AppendMenuItem(MF_STRING, 105, "Artist");
- _menu.CheckMenuRadioItem(101, 105, a.id + 101);
- _menu.AppendMenuSeparator();
- _menu.AppendMenuItem(MF_STRING, 110, "Crop (focus on centre)");
- _menu.AppendMenuItem(MF_STRING, 111, "Crop (focus on top)");
- _menu.AppendMenuItem(MF_STRING, 112, "Stretch");
- _menu.AppendMenuItem(MF_STRING, 113, "Centre");
- _menu.CheckMenuRadioItem(110, 113, a.type + 110);
- _menu.AppendMenuSeparator();
- _cover.AppendMenuItem(this.metadb ? MF_STRING : MF_GRAYED, 120, "Google images (launches browser)");
- _cover.AppendMenuItem(this.metadb ? MF_STRING : MF_GRAYED, 121, "Album Art Downloader");
- _cover.AppendMenuSeparator();
- _cover.AppendMenuItem(MF_STRING, 122, "Help");
- _cover.AppendTo(_menu, MF_STRING, "Cover search");
- _menu.AppendMenuSeparator();
- _sub1.AppendMenuItem(MF_STRING, 123, "Opens image");
- _sub1.AppendMenuItem(MF_STRING, 124, "Opens containing folder");
- _sub1.CheckMenuRadioItem(123, 124, a.dblclk == 0 ? 123 : 124);
- _sub1.AppendTo(_menu, MF_STRING, "Double click");
- _menu.AppendMenuSeparator();
- break;
- case typeof c == "object" && c.trace(x, y):
- _menu.AppendMenuItem(MF_STRING, 100, "Refresh");
- _menu.AppendMenuSeparator();
- _menu.AppendMenuItem(MF_STRING, 130, "Gloss effect");
- _menu.CheckMenuItem(130, c.gloss);
- _menu.AppendMenuItem(MF_STRING, 131, "Shadow effect");
- _menu.CheckMenuItem(131, c.shadow);
- _menu.AppendMenuSeparator();
- _cover.AppendMenuItem(this.metadb ? MF_STRING : MF_GRAYED, 120, "Google images (launches browser)");
- _cover.AppendMenuItem(this.metadb ? MF_STRING : MF_GRAYED, 121, "Album Art Downloader");
- _cover.AppendMenuSeparator();
- _cover.AppendMenuItem(MF_STRING, 122, "Help");
- _cover.AppendTo(_menu, MF_STRING, "Cover search");
- _menu.AppendMenuSeparator();
- _sub1.AppendMenuItem(MF_STRING, 125, "Opens image");
- _sub1.AppendMenuItem(MF_STRING, 126, "Opens containing folder");
- _sub1.CheckMenuRadioItem(125, 126, c.dblclk == 0 ? 125 : 126);
- _sub1.AppendTo(_menu, MF_STRING, "Double click");
- _menu.AppendMenuSeparator();
- break;
- case typeof li == "object" && li.trace(x, y):
- switch(li.mode) {
- case "autoplaylists":
- _menu.AppendMenuItem(MF_STRING, 240, "Add new autoplaylist...");
- _menu.AppendMenuSeparator();
- _menu.AppendMenuItem(MF_STRING, 200, "Change title...");
- _menu.AppendMenuSeparator();
- for (i = 1; i < 9; i++) {
- _sub1.AppendMenuItem(MF_STRING, i + 200, i);
- }
- _sub1.AppendTo(_menu, MF_STRING, "Save slot");
- _sub1.CheckMenuRadioItem(201, 208, li.autoplaylists_slot + 200);
- _menu.AppendMenuSeparator();
- _sub2.AppendMenuItem(MF_STRING, 210, "run query");
- _sub2.AppendMenuItem(MF_STRING, 211, "do nothing");
- _sub2.CheckMenuRadioItem(210, 211, li.autoplaylists_success ? 210 : 211);
- _sub2.AppendTo(_menu, MF_STRING, "On successful creation/edit");
- for (i = 0; i < li.autoplaylists_deleted_items.length; i++) {
- var temp = li.autoplaylists_deleted_items[i].split("¬");
- _sub3.AppendMenuItem(MF_STRING, i + 220, temp[0]);
- }
- if (li.autoplaylists_deleted_items.length > 0) _sub3.AppendTo(_menu, MF_STRING, "Restore");
- _menu.AppendMenuSeparator();
- _menu.AppendMenuItem(MF_STRING, 230, "Replace exisiting playlists with the same name");
- _menu.CheckMenuItem(230, li.autoplaylists_remove_duplicates);
- _menu.AppendMenuSeparator();
- break;
- case "echonest":
- for (i = 0; i < li.echonest_modes.length; i++) {
- _menu.AppendMenuItem(MF_STRING, i + 290, li.echonest_modes[i].ucfirst());
- }
- _menu.CheckMenuRadioItem(290, 292, li.echonest_mode + 290);
- _menu.AppendMenuSeparator();
- break;
- case "lastfm":
- for (i = 0; i < li.lastfm_modes.length; i++) {
- _menu.AppendMenuItem(MF_STRING, 300 + i, li.lastfm_modes[i].ucfirst());
- }
- _menu.CheckMenuRadioItem(300, 304, li.lastfm_mode + 300);
- _menu.AppendMenuSeparator();
- if (li.lastfm_mode != 2) {
- _sub1.AppendMenuItem(MF_STRING, 310, "Last.fm");
- _sub1.AppendMenuItem(MF_STRING, 311, "Autoplaylist");
- _sub1.CheckMenuRadioItem(310, 311, li.lastfm_link ? 310 : 311);
- _sub1.AppendTo(_menu, MF_STRING, "Links");
- _menu.AppendMenuSeparator();
- }
- _menu.AppendMenuItem(MF_STRING, 320, "Last.fm auto-correct");
- _menu.CheckMenuItem(320, l.auto_correct);
- _menu.AppendMenuSeparator();
- break;
- case "lastfm_charts":
- for (i = 0; i < li.lastfm_charts_modes.length; i++) {
- _menu.AppendMenuItem(MF_STRING, i + 350, li.lastfm_charts_modes[i].ucfirst());
- }
- _menu.CheckMenuRadioItem(350, 352, li.lastfm_charts_mode + 350);
- _menu.AppendMenuSeparator();
- for (i = 0; i < li.lastfm_charts_periods_display.length; i++) {
- _menu.AppendMenuItem(MF_STRING, i + 360, li.lastfm_charts_periods_display[i].ucfirst());
- }
- _menu.CheckMenuRadioItem(360, 365, li.lastfm_charts_period + 360);
- _menu.AppendMenuSeparator();
- _sub1.AppendMenuItem(MF_STRING, 310, "Last.fm");
- _sub1.AppendMenuItem(MF_STRING, 311, "Autoplaylist");
- _sub1.CheckMenuRadioItem(310, 311, li.lastfm_link ? 310 : 311);
- _sub1.AppendTo(_menu, MF_STRING, "Links");
- _menu.AppendMenuSeparator();
- _menu.AppendMenuItem(MF_STRING, 370, "Bar colour...");
- _menu.AppendMenuSeparator();
- break;
- case "musicbrainz":
- _menu.AppendMenuItem(MF_STRING, 400, "Releases");
- _menu.AppendMenuItem(MF_STRING, 401, "Links");
- _menu.CheckMenuRadioItem(400, 401, li.mbs["2k3.musicbrainz_releases"] ? 400 : 401);
- _menu.AppendMenuSeparator();
- if (li.mbs["2k3.musicbrainz_releases"]) {
- for (i = 0; i < li.mbm.length; i++) {
- _menu.AppendMenuItem(li.mbs["2k3.musicbrainz_show_all"] && i > 0 && i <= 6 ? MF_GRAYED : MF_STRING, i + 410, li.mbm[i]);
- _menu.CheckMenuItem(i + 410, li.mbs[li.mbl[i]]);
- if (i == 3 || i == 6) _menu.AppendMenuSeparator();
- }
- _menu.AppendMenuSeparator();
- } else {
- _menu.AppendMenuItem(MF_STRING, 420, "Show icons");
- _menu.CheckMenuItem(420, li.mbs["2k3.musicbrainz_show_icons"]);
- _menu.AppendMenuSeparator();
- }
- break;
- }
- if (li.filename.is_file()) {
- _menu.AppendMenuItem(MF_STRING, 499, "Open containing folder");
- _menu.AppendMenuSeparator();
- }
- if (li.mode != "echonest") {
- _font.AppendMenuItem(MF_STRING, 490, 11);
- _font.AppendMenuItem(MF_STRING, 492, 13);
- _font.AppendMenuItem(MF_STRING, 494, 15);
- _font.AppendTo(_menu, MF_STRING, "Font size");
- _font.CheckMenuRadioItem(490, 494, this.list_font_size + 479);
- _menu.AppendMenuSeparator();
- }
- break;
- case typeof ps == "object" && b.buttons.ps.trace(x, y):
- var ok = ps.check_component && !ps.loved_working && !ps.playcount_working && l.username.length > 0;
- _sub1.AppendMenuItem(ok ? MF_STRING : MF_GRAYED, 500, "loved tracks and playcount");
- _sub1.AppendMenuItem(ok ? MF_STRING : MF_GRAYED, 501, "loved tracks only");
- _sub1.AppendMenuSeparator();
- _sub1.AppendMenuItem(MF_STRING, 502, "Show console");
- _sub1.CheckMenuItem(502, ps.show_console);
- _sub1.AppendTo(_menu, MF_STRING, "Library import");
- _menu.AppendMenuSeparator();
- _sub2.AppendMenuItem(MF_STRING, 321, "Last.fm auto-correct");
- _sub2.CheckMenuItem(321, l.auto_correct);
- _sub2.AppendMenuItem(MF_STRING, 511, "Only update tracks in Media Library");
- _sub2.CheckMenuItem(511, ps.library);
- _sub2.AppendMenuItem(MF_STRING, 512, "Extended logging");
- _sub2.CheckMenuItem(512, ps.logging);
- _sub2.AppendTo(_menu, MF_STRING, "Auto-updates");
- _menu.AppendMenuSeparator();
- _sub3.AppendMenuItem(MF_STRING, 520, "Enabled");
- _sub3.CheckMenuItem(520, ps.auto_love);
- _sub3.AppendMenuSeparator();
- _sub3.AppendMenuItem(ps.auto_love ? MF_STRING : MF_GRAYED, 521, "Condition");
- _sub3.AppendTo(_menu, MF_STRING, "Automatically love tracks");
- _menu.AppendMenuSeparator();
- break;
- case typeof s == "object" && s.mode == "spectrogram" && s.trace(x, y) :
- _menu.AppendMenuItem(MF_STRING, 580, "SoX options...");
- _menu.AppendMenuSeparator();
- _menu.AppendMenuItem(MF_STRING, 581, "Marker colour...");
- _menu.AppendMenuSeparator();
- _menu.AppendMenuItem(MF_STRING, 582, "Only analyse tracks in library");
- _menu.CheckMenuItem(582, s.library);
- _menu.AppendMenuSeparator();
- _sub1.AppendMenuItem(MF_STRING, 590, "Clear all");
- _sub1.AppendMenuItem(MF_STRING, 591, "Clear older than 1 day");
- _sub1.AppendMenuItem(MF_STRING, 592, "Clear older than 1 week");
- _sub1.AppendMenuSeparator();
- _sub1.AppendMenuItem(MF_GRAYED, 593, "In use: " + (fso.GetFolder(s.folder).size / 1048576).toFixed(2) + "MB");
- _sub1.AppendTo(_menu, MF_STRING, "Cached images");
- _menu.AppendMenuSeparator();
- break;
- case typeof t == "object" && t.trace(x, y):
- switch(t.mode) {
- case "allmusic":
- _sub1.AppendMenuItem(MF_STRING, 600, "Artist...");
- _sub1.AppendMenuItem(MF_STRING, 601, "Album...");
- _sub1.AppendTo(_menu, MF_STRING, "Field remapping");
- _menu.AppendMenuSeparator();
- _menu.AppendMenuItem(this.metadb ? MF_STRING : MF_GRAYED, 602, "Paste text from clipboard");
- _menu.AppendMenuSeparator();
- break;
- case "lastfm_wiki":
- _menu.AppendMenuItem(MF_STRING, 650, "Last.fm");
- _menu.AppendMenuItem(MF_STRING, 651, "Wikipedia");
- _menu.CheckMenuRadioItem(650, 651, t.biography_lastfm ? 650 : 651);
- _menu.AppendMenuSeparator();
- if (t.biography_lastfm) {
- for (i = 0; i < t.biography_lastfm_sites.length; i++) {
- _sub1.AppendMenuItem(MF_STRING, i + 660, t.biography_lastfm_sites[i]);
- }
- _sub1.CheckMenuRadioItem(660, 671, t.biography_lastfm_site + 660);
- _sub1.AppendTo(_menu, MF_STRING, "Last.fm site");
- _menu.AppendMenuSeparator();
- }
- break;
- case "simple_tag":
- _menu.AppendMenuItem(MF_STRING, 620, "Custom title...");
- _menu.AppendMenuItem(MF_STRING, 621, "Custom tag...");
- _menu.AppendMenuSeparator();
- _menu.AppendMenuItem(MF_STRING, 622, "Centre text");
- _menu.CheckMenuItem(622, t.centre);
- _menu.AppendMenuSeparator();
- break;
- case "simple_text":
- _menu.AppendMenuItem(MF_STRING, 630, "Refresh");
- _menu.AppendMenuSeparator();
- _menu.AppendMenuItem(MF_STRING, 620, "Custom title...");
- _menu.AppendMenuItem(MF_STRING, 632, "Custom path...");
- _menu.AppendMenuSeparator();
- _menu.AppendMenuItem(MF_STRING, 633, "Fixed width font");
- _menu.CheckMenuItem(633, t.fixed);
- _menu.AppendMenuSeparator();
- break;
- }
- if (t.filename.is_file()) {
- _menu.AppendMenuItem(MF_STRING, 699, "Open containing folder");
- _menu.AppendMenuSeparator();
- }
- _font.AppendMenuItem(MF_STRING, 680, 12);
- _font.AppendMenuItem(MF_STRING, 682, 14);
- _font.AppendMenuItem(MF_STRING, 684, 16);
- _font.AppendTo(_menu, MF_STRING, "Font size");
- _font.CheckMenuRadioItem(680, 684, this.normal_font_size + 668);
- _menu.AppendMenuSeparator();
- break;
- case typeof th == "object":
- if (th.source == 0) { //last.fm
- _menu.AppendMenuItem(this.metadb ? MF_STRING : MF_GRAYED, 700, "Download artist art from Last.fm");
- _menu.AppendMenuItem(MF_STRING, 701, "Help");
- _menu.AppendMenuSeparator();
- _sub1.AppendMenuItem(MF_STRING, 705, "Off");
- _sub1.AppendMenuItem(MF_STRING, 706, "Library tracks only");
- _sub1.AppendMenuItem(MF_STRING, 707, "All tracks");
- _sub1.CheckMenuRadioItem(705, 707, th.auto_download + 705);
- _sub1.AppendTo(_menu, MF_STRING, "Automatic download");
- _sub2.AppendMenuItem(MF_STRING, 710, "Small");
- _sub2.AppendMenuItem(MF_STRING, 711, "Medium");
- _sub2.AppendMenuItem(MF_STRING, 712, "Original");
- _sub2.CheckMenuRadioItem(710, 712, th.download_size + 710);
- _sub2.AppendTo(_menu, MF_STRING, "Download size");
- _sub3.AppendMenuItem(MF_STRING, 721, "1");
- _sub3.AppendMenuItem(MF_STRING, 723, "3");
- _sub3.AppendMenuItem(MF_STRING, 725, "5");
- _sub3.CheckMenuRadioItem(721, 725, th.limit + 720);
- _sub3.AppendTo(_menu, MF_STRING, "Limit");
- } else if (th.source == 1) { //custom folder
- _menu.AppendMenuItem(MF_STRING, 730, "Refresh");
- _menu.AppendMenuSeparator();
- _menu.AppendMenuItem(MF_STRING, 731, "Set custom folder...");
- }
- if (th.source != 2) {
- _menu.AppendMenuSeparator();
- _sub4.AppendMenuItem(MF_STRING, 735, "Last.fm artist art");
- _sub4.AppendMenuItem(MF_STRING, 736, "Custom folder");
- _sub4.CheckMenuRadioItem(735, 736, th.source + 735);
- _sub4.AppendTo(_menu, MF_STRING, "Image source");
- _menu.AppendMenuSeparator();
- }
- _sub5.AppendMenuItem(MF_STRING, 740, "Off");
- _sub5.AppendMenuItem(MF_STRING, 745, "5 seconds");
- _sub5.AppendMenuItem(MF_STRING, 750, "10 seconds");
- _sub5.AppendMenuItem(MF_STRING, 760, "20 seconds");
- _sub5.CheckMenuRadioItem(740, 760, th.cycle + 740);
- _sub5.AppendTo(_menu, MF_STRING, "Cycle");
- _menu.AppendMenuSeparator();
- if (th.mode != th.modes.disabled) {
- _sub6.AppendMenuItem(MF_STRING, 765, "Grid");
- _sub6.AppendMenuItem(MF_STRING, 766, "Left");
- _sub6.AppendMenuItem(MF_STRING, 767, "Right");
- _sub6.AppendMenuItem(MF_STRING, 768, "Top");
- _sub6.AppendMenuItem(MF_STRING, 769, "Bottom");
- _sub6.AppendMenuItem(MF_STRING, 770, "Off");
- _sub6.CheckMenuRadioItem(765, 770, th.mode + 765);
- if (th.mode != th.modes.off) {
- _sub6.AppendMenuSeparator();
- _sub6.AppendMenuItem(MF_STRING, 775, "75px");
- _sub6.AppendMenuItem(MF_STRING, 800, "100px");
- _sub6.AppendMenuItem(MF_STRING, 850, "150px");
- _sub6.AppendMenuItem(MF_STRING, 900, "200px");
- _sub6.AppendMenuItem(MF_STRING, 950, "250px");
- _sub6.AppendMenuItem(MF_STRING, 1000, "300px");
- _sub6.CheckMenuRadioItem(775, 1000, th.px + 700);
- }
- _sub6.AppendTo(_menu, MF_STRING, "Thumbs");
- _menu.AppendMenuSeparator();
- }
- _sub7.AppendMenuItem(MF_STRING, 1001, "Newest first");
- _sub7.AppendMenuItem(MF_STRING, 1002, "Oldest first");
- _sub7.AppendMenuItem(MF_STRING, 1003, "A-Z");
- _sub7.AppendMenuItem(MF_STRING, 1004, "Z-A");
- _sub7.CheckMenuRadioItem(1001, 1004, th.sort + 1001);
- _sub7.AppendTo(_menu, MF_STRING, "Sorting");
- _menu.AppendMenuSeparator();
- if (!th.trace(x, y) || th.mode == th.modes.grid && th.overlay) {
- if (this.metadb) {
- _menu.AppendMenuItem(MF_STRING, 1010, "Open containing folder");
- _menu.AppendMenuSeparator();
- }
- if (th.images.length > 0) {
- _menu.AppendMenuItem(MF_STRING, 1011, "Open image");
- _menu.AppendMenuItem(MF_STRING, 1012, "Delete image");
- _menu.AppendMenuSeparator();
- _menu.AppendMenuItem(MF_STRING, 1013, "Crop (focus on centre)");
- _menu.AppendMenuItem(MF_STRING, 1014, "Crop (focus on top)");
- _menu.AppendMenuItem(MF_STRING, 1015, "Stretch");
- _menu.AppendMenuItem(MF_STRING, 1016, "Centre");
- _menu.CheckMenuRadioItem(1013, 1016, th.type + 1013);
- _menu.AppendMenuSeparator();
- if (th.source == 0 && th.images.length > 1) {
- _menu.AppendMenuItem(th.default_file == th.files[th.image] ? MF_GRAYED : MF_STRING, 1017, "Set as default");
- _menu.AppendMenuItem(MF_STRING, 1018, "Clear default");
- _menu.AppendMenuSeparator();
- }
- }
- }
- break;
- }
- if (this.check_feature("custom_background")) {
- if (!this.is_dui) _custom_background.AppendMenuItem(MF_STRING, 1, "None");
- _custom_background.AppendMenuItem(MF_STRING, 2, this.is_dui ? "Use default UI setting" : "Use columns UI setting");
- _custom_background.AppendMenuItem(MF_STRING, 3, "Splitter");
- _custom_background.AppendMenuItem(MF_STRING, 4, "Custom");
- _custom_background.CheckMenuRadioItem(1, 4, this.background_mode + 1);
- _custom_background.AppendMenuSeparator();
- _custom_background.AppendMenuItem(this.background_mode == 3 ? MF_STRING : MF_GRAYED, 5, "Set custom colour...");
- _custom_background.AppendTo(_menu, MF_STRING, "Background");
- _menu.AppendMenuSeparator();
- }
- if (typeof l == "object" && l.need_username) {
- _menu.AppendMenuItem(MF_STRING, 10, "Last.fm username...");
- if (typeof ps == "object") _menu.AppendMenuItem(l.username.length > 0 ? MF_STRING : MF_GRAYED, 11, "Last.fm password...");
- _menu.AppendMenuSeparator();
- }
- if (this.check_feature("metadb")) {
- _metadb.AppendMenuItem(MF_STRING, 20, "Use display preferences");
- _metadb.AppendMenuItem(MF_STRING, 21, "Prefer now playing");
- _metadb.AppendMenuItem(MF_STRING, 22, "Follow selected track");
- _metadb.CheckMenuRadioItem(20, 22, this.selection_mode + 20);
- _metadb.AppendTo(_menu, MF_STRING, "Selection mode");
- _menu.AppendMenuSeparator();
- }
- if (this.check_feature("remap")) {
- _menu.AppendMenuItem(MF_STRING, 30, "Artist field remapping...");
- _menu.AppendMenuSeparator();
- }
- _menu.AppendMenuItem(MF_STRING, 31, "Update script");
- _menu.AppendMenuItem(MF_STRING, 32, "About");
- _menu.AppendMenuSeparator();
- if (utils.IsKeyPressed(0x10)) _menu.AppendMenuItem(MF_STRING, 49, "Properties");
- _menu.AppendMenuItem(MF_STRING, 50, "Configure...");
- var idx = _menu.TrackPopupMenu(x, y);
- switch(idx) {
- case 1:
- case 2:
- case 3:
- case 4:
- this.background_mode = idx - 1;
- window.SetProperty("2k3.background_mode", this.background_mode);
- window.Repaint();
- break;
- case 5:
- this.background_custom_colour = this.InputBox("Enter a custom colour for the background. Uses RGB. Example usage:\n\n234-211-74", this.name, this.background_custom_colour);
- window.SetProperty("2k3.background_custom_colour", this.background_custom_colour);
- window.Repaint();
- break;
- case 10:
- l.update_username();
- break;
- case 11:
- l.update_password();
- break;
- case 20:
- case 21:
- case 22:
- this.selection_mode = idx - 20;
- window.SetProperty("2k3.selection_mode", this.selection_mode);
- this.item_focus_change();
- break;
- case 30:
- this.artist_tf = this.InputBox("The default is %artist%\n\nYou can use the full foobar2000 title formatting syntax here.", "Artist field remapping", this.artist_tf);
- if (this.artist_tf == "") this.artist_tf = "%artist%";
- window.SetProperty("2k3.artist_tf", this.artist_tf);
- this.item_focus_change();
- break;
- case 31:
- this.update_script();
- break;
- case 32:
- this.MsgBox("Common file: " + VERSION + "\n(c) 2014 marc2003", 0, this.name);
- break;
- case 49:
- window.ShowProperties();
- break;
- case 50:
- window.ShowConfigure();
- break;
- case 100: //artreader /cd refresh
- this.item_focus_change();
- break;
- case 101:
- case 102:
- case 103:
- case 104:
- case 105:
- a.id = idx - 101;
- window.SetProperty("2k3.artreader_id", a.id);
- this.item_focus_change();
- break;
- case 110:
- case 111:
- case 112:
- case 113:
- a.type = idx - 110;
- window.SetProperty("2k3.artreader_type", a.type);
- window.RepaintRect(a.x, a.y, a.w, a.h);
- break;
- case 120:
- this.browser("https://www.google.com/search?tbm=isch&q=" + encodeURIComponent(this.eval("%album artist%[ %album%]")));
- break;
- case 121:
- this.aad();
- break;
- case 122:
- fb.ShowPopupMessage("You can get Album Art Downloader here:\n\nhttp://www.hydrogenaud.io/forums/index.php?showtopic=57392", this.name);
- break;
- case 123:
- case 124:
- a.dblclk = idx - 123;
- window.SetProperty("2k3.artreader_dblclk", a.dblclk);
- break;
- case 125:
- case 126:
- c.dblclk = idx -125;
- window.SetProperty("2k3.cd_dblclk", c.dblclk);
- break;
- case 130:
- c.gloss = !c.gloss;
- window.SetProperty("2k3.cd_gloss", c.gloss);
- window.Repaint();
- break;
- case 131:
- c.shadow = !c.shadow;
- window.SetProperty("2k3.cd_shadow", c.shadow);
- window.Repaint();
- break;
- case 200:
- li.autoplaylists_title = this.InputBox("Enter a new title", this.name, li.autoplaylists_title);
- if (li.autoplaylists_title == "") li.autoplaylists_title = "Autoplaylists";
- window.SetProperty("2k3.autoplaylists_title", li.autoplaylists_title);
- window.Repaint();
- break;
- case 201:
- case 202:
- case 203:
- case 204:
- case 205:
- case 206:
- case 207:
- case 208:
- li.autoplaylists_slot = idx - 200;
- window.SetProperty("2k3.autoplaylists_slot", li.autoplaylists_slot);
- li.filename = this.settings_folder + "autoplaylists" + li.autoplaylists_slot;
- li.update();
- break;
- case 210:
- case 211:
- li.autoplaylists_success = idx == 210;
- window.SetProperty("2k3.autoplaylists_success", li.autoplaylists_success);
- break;
- case 220:
- case 221:
- case 222:
- case 223:
- case 224:
- case 225:
- case 226:
- case 227:
- li.data.push(li.autoplaylists_deleted_items[idx - 220]);
- li.autoplaylists_deleted_items.splice(idx - 220, 1);
- this.save(li.data.join("\n"), li.filename);
- window.NotifyOthers("autoplaylists", "update");
- li.update();
- break;
- case 230:
- li.autoplaylists_remove_duplicates = !li.autoplaylists_remove_duplicates;
- window.SetProperty("2k3.autoplaylists_remove_duplicates", li.autoplaylists_remove_duplicates);
- break;
- case 240:
- li.autoplaylists_add();
- break;
- case 290:
- case 291:
- case 292:
- li.echonest_mode = idx - 290;
- window.SetProperty("2k3.echonest_mode", li.echonest_mode);
- li.artist = "";
- this.item_focus_change();
- break;
- case 300:
- case 301:
- case 302:
- case 303:
- case 304:
- li.lastfm_mode = idx - 300;
- window.SetProperty("2k3.lastfm_mode", li.lastfm_mode);
- li.artist = "";
- this.item_focus_change();
- break;
- case 310:
- case 311:
- li.lastfm_link = idx == 310;
- window.SetProperty("2k3.lastfm_link", li.lastfm_link);
- break;
- case 320:
- case 321:
- l.auto_correct = !l.auto_correct;
- window.SetProperty("2k3.lastfm_auto_correct", l.auto_correct);
- if (this.metadb && idx == 320) li.get();
- break;
- case 350:
- case 351:
- case 352:
- li.lastfm_charts_mode = idx - 350;
- window.SetProperty("2k3.lastfm_charts_mode", li.lastfm_charts_mode);
- li.update();
- break;
- case 360:
- case 361:
- case 362:
- case 363:
- case 364:
- case 365:
- li.lastfm_charts_period = idx - 360;
- window.SetProperty("2k3.lastfm_charts_period", li.lastfm_charts_period);
- li.update();
- break;
- case 370:
- li.lastfm_charts_bar_colour = this.InputBox("Enter a custom colour for the bars. Uses RGB. Example usage:\n\n72-127-221", this.name, li.lastfm_charts_bar_colour);
- window.SetProperty("2k3.lastfm_charts_bar_colour", li.lastfm_charts_bar_colour);
- window.Repaint();
- break;
- case 400:
- case 401:
- li.mb_set("2k3.musicbrainz_releases", idx == 400);
- break;
- case 410:
- case 411:
- case 412:
- case 413:
- case 414:
- case 415:
- case 416:
- case 417:
- case 418:
- li.mb_set(li.mbl[idx - 410], !li.mbs[li.mbl[idx - 410]]);
- break;
- case 420:
- li.mb_set("2k3.musicbrainz_show_icons", !li.mbs["2k3.musicbrainz_show_icons"]);
- break;
- case 490:
- case 492:
- case 494:
- this.list_font_size = idx - 479;
- window.SetProperty("2k3.list_font_size", this.list_font_size);
- this.font_changed();
- break;
- case 499:
- this.explorer(li.filename);
- break;
- case 500:
- case 501:
- ps.full_import = idx == 500;
- ps.start_import();
- break;
- case 502:
- ps.show_console = !ps.show_console;
- window.SetProperty("2k3.playcount_sync_show_console", ps.show_console);
- break;
- case 511:
- ps.library = !ps.library;
- window.SetProperty("2k3.playcount_sync_library", ps.library);
- break;
- case 512:
- ps.logging = !ps.logging;
- window.SetProperty("2k3.playcount_sync_logging", ps.logging);
- break;
- case 520:
- ps.auto_love = !ps.auto_love;
- window.SetProperty("2k3.playcount_sync_auto_love", ps.auto_love);
- break;
- case 521:
- ps.auto_love_tf = this.InputBox("The result of the title formatting set here must equal 1 for a track to be automatically loved.\n\nExample:\n\n$ifequal(%rating%,5,1,0)", this.name, ps.auto_love_tf);
- window.SetProperty("2k3.playcount_sync_auto_love_tf", ps.auto_love_tf);
- break;
- case 580:
- s.sox_params = this.InputBox("All SoX spectrogram options should work here.\n\n-r, -d and -o are already configured so do not use those. Check sox.pdf for everything else.", this.name, s.sox_params);
- window.SetProperty("2k3.seekbar_sox_params", s.sox_params);
- if (fb.IsPlaying) s.playback_new_track();
- break;
- case 581:
- s.marker = this.InputBox("Enter a custom colour for the marker. Uses RGB. Example usage:\n\n234-211-74", this.name, s.marker);
- window.SetProperty("2k3.seekbar_marker", s.marker);
- break;
- case 582:
- s.library = !s.library;
- window.SetProperty("2k3.seekbar_library", s.library);
- break;
- case 590:
- s.clear_images(0);
- break;
- case 591:
- s.clear_images(ONE_DAY);
- break;
- case 592:
- s.clear_images(ONE_WEEK);
- break;
- case 600:
- t.allmusic_artist_tf = this.InputBox("The default is %album artist%\n\nYou can use the full foobar2000 title formatting syntax here.", "Artist field remapping", t.allmusic_artist_tf);
- if (t.allmusic_artist_tf == "") t.allmusic_artist_tf = "%album artist%";
- window.SetProperty("2k3.allmusic_artist_tf", t.allmusic_artist_tf);
- this.item_focus_change();
- break;
- case 601:
- t.allmusic_album_tf = this.InputBox("The default is %album%\n\nYou can use the full foobar2000 title formatting syntax here.", "Album field remapping", t.allmusic_album_tf);
- if (t.allmusic_album_tf == "") t.allmusic_album_tf = "%album%";
- window.SetProperty("2k3.allmusic_album_tf", t.allmusic_album_tf);
- this.item_focus_change();
- break;
- case 602:
- var text = doc.parentWindow.clipboardData.getData("Text");
- if (typeof text == "string") {
- this.save(text, t.filename);
- t.text = text;
- t.update();
- window.Repaint();
- }
- break;
- case 620:
- t.title_tf = this.InputBox("You can use full title formatting here.", this.name, t.title_tf);
- window.SetProperty("2k3.text_title_tf", t.title_tf);
- window.Repaint();
- break;
- case 621:
- t.tag_tf = this.InputBox("Enter a custom tag.", this.name, t.tag_tf);
- window.SetProperty("2k3.text_tag_tf", t.tag_tf);
- t.filename = "";
- this.item_focus_change();
- break;
- case 622:
- t.centre = !t.centre;
- window.SetProperty("2k3.text_centre", t.centre);
- window.RepaintRect(t.x, t.y, t.w, t.h);
- break;
- case 630:
- t.filename = "";
- this.item_focus_change();
- break;
- case 632:
- t.filename_tf = this.InputBox("Use title formatting to specify a path to your text file. eg: $directory_path(%path%)\\info.txt\n\nIf you prefer, you can specify just the path to a folder and the first txt or log file will be used.", this.name, t.filename_tf);
- window.SetProperty("2k3.text_filename_tf", t.filename_tf);
- this.item_focus_change();
- break;
- case 633:
- t.fixed = !t.fixed;
- window.SetProperty("2k3.text_fixed_font", t.fixed);
- t.update();
- window.RepaintRect(t.x, t.y, t.w, t.h);
- break;
- case 650:
- case 651:
- t.biography_lastfm = idx == 650;
- window.SetProperty("2k3.biography_lastfm", t.biography_lastfm);
- t.artist = "";
- this.item_focus_change();
- break;
- case 660:
- case 661:
- case 662:
- case 663:
- case 664:
- case 665:
- case 666:
- case 667:
- case 668:
- case 669:
- case 670:
- case 671:
- t.biography_lastfm_site = idx - 660;
- window.SetProperty("2k3.biography_lastfm_site", t.biography_lastfm_site);
- t.artist = "";
- this.item_focus_change();
- break;
- case 680:
- case 682:
- case 684:
- this.normal_font_size = idx - 668;
- window.SetProperty("2k3.normal_font_size", this.normal_font_size);
- this.font_changed();
- break;
- case 699:
- this.explorer(t.filename);
- break;
- case 700:
- th.download();
- break;
- case 701:
- fb.ShowPopupMessage("-Automatic downloads have been turned off by default. You can turn it back on if you like.\n\n-The automatic download option only triggers when there are no existing images and when you start playback. It will not download on a selection change or when playing back streams with dynamic metadata.\n\n-If downloading doesn't work, check the Console and if you see HTTP status code 0, you need to hold shift and right click the panel. Edit the value of \"2k3.thumbs_domain\" to whichever localised last.fm site you use like \"http://wwww.lastfm.de\" etc.", this.name);
- break;
- case 705:
- case 706:
- case 707:
- th.auto_download = idx - 705;
- window.SetProperty("2k3.thumbs_auto_download", th.auto_download);
- break;
- case 710:
- case 711:
- case 712:
- th.download_size = idx - 710;
- window.SetProperty("2k3.thumbs_download_size", thumbs.download_size);
- break;
- case 721:
- case 723:
- case 725:
- th.limit = idx - 720;
- window.SetProperty("2k3.thumbs_limit", th.limit);
- break;
- case 730:
- th.update();
- break;
- case 731:
- th.custom_folder_tf = this.InputBox("Enter title formatting or an absolute path to a folder. You can specify multiple folders using | as a separator.", this.name, th.custom_folder_tf);
- if (th.custom_folder_tf == "") th.custom_folder_tf = "$directory_path(%path%)";
- window.SetProperty("2k3.thumbs_custom_folder_tf", th.custom_folder_tf);
- th.folder = "";
- this.item_focus_change();
- break;
- case 735:
- case 736:
- th.source = idx - 735;
- window.SetProperty("2k3.thumbs_source", th.source);
- th.artist = "";
- th.folder = "";
- this.item_focus_change();
- break;
- case 740:
- case 745:
- case 750:
- case 760:
- th.cycle = idx - 740;
- window.SetProperty("2k3.thumbs_cycle", th.cycle);
- break;
- case 765:
- case 766:
- case 767:
- case 768:
- case 769:
- case 770:
- th.mode = idx - 765;
- window.SetProperty("2k3.thumbs_mode", th.mode);
- th.size(true);
- window.Repaint();
- break;
- case 775:
- case 800:
- case 850:
- case 900:
- case 950:
- case 1000:
- th.px = idx - 700;
- window.SetProperty("2k3.thumbs_px", th.px);
- th.size(true);
- window.Repaint();
- break;
- case 1001:
- case 1002:
- case 1003:
- case 1004:
- th.sort = idx - 1001;
- if (th.images.length > 0) th.update();
- break;
- case 1010:
- if (th.images.length == 0) this.run("\"" + th.folders[0] + "\"");
- else this.explorer(th.files[th.image]);
- break;
- case 1011:
- this.run("\"" + th.files[th.image] + "\"");
- break;
- case 1012:
- th.delete_image();
- break;
- case 1013:
- case 1014:
- case 1015:
- case 1016:
- th.type = idx - 1013;
- window.SetProperty("2k3.thumbs_type", th.type);
- window.Repaint();
- break;
- case 1017:
- th.set_default(th.files[th.image].split("\\").pop());
- break;
- case 1018:
- th.set_default("");
- break;
- }
- _menu.Dispose();
- _custom_background.Dispose();
- _metadb.Dispose();
- _cover.Dispose();
- _font.Dispose();
- _sub1.Dispose();
- _sub2.Dispose();
- _sub3.Dispose();
- _sub4.Dispose();
- _sub5.Dispose();
- _sub6.Dispose();
- _sub7.Dispose();
- }
- this.features_init = function() {
- for (i in this.features) {
- switch(this.features[i]) {
- case "custom_menu":
- this.hover = false;
- this.menu_btn = new sb(0, 0, 20, 20, gdi.Image(this.ip + "buttons\\cog.png"), "p.hover", function() { p.menu(); });
- this.menu_btn.leave = function() {
- p.hover = false;
- window.RepaintRect(this.x, this.y, this.w, this.h);
- }
- break;
- case "custom_background":
- this.background_mode = window.GetProperty("2k3.background_mode", 1);
- this.background_custom_colour = window.GetProperty("2k3.background_custom_colour", "0-0-0");
- break;
- case "metadb":
- this.selection_mode = window.GetProperty("2k3.selection_mode", 1);
- break;
- case "themes":
- try {
- this.themed_header = window.CreateThemeManager("Header");
- this.themed_header.SetPartAndStateId(1, 1);
- this.themed_button = window.CreateThemeManager("Button");
- } catch(e) {
- this.MsgBox("Your Windows theme does not support this script.", 0, this.name);
- }
- break;
- case "remap":
- this.artist_tf = window.GetProperty("2k3.artist_tf", "%artist%");
- break;
- }
- }
- }
- this.check_feature = function(f) {
- for (i in this.features) {
- if (this.features[i] == f) return true;
- }
- return false;
- }
- this.eval = function(t) {
- if (!this.metadb) return "";
- if (fb.IsPlaying && this.is_stream()) {
- t = tfe(t);
- try { t = decodeURIComponent(t); } catch(e) {}
- return t;
- } else {
- return tf(t, this.metadb);
- }
- }
- this.is_stream = function() {
- //support m-TAGS (foo_tags.dll)
- var path = tf("$if2(%__@%,%path%)", this.metadb);
- switch(true) {
- case path.indexOf("http") == 0:
- case path.indexOf("mms") == 0:
- return true;
- default:
- return false;
- }
- }
- this.open = function(f) {
- return utils.ReadTextFile(f);
- }
- this.save = function(t, f, m) {
- if (typeof m == "undefined") m = -1;
- try {
- var ts = fso.OpenTextFile(f, 2, true, m);
- ts.WriteLine(t);
- ts.Close();
- return true;
- } catch(e) {
- return false;
- }
- }
- this.console = function(t) {
- fb.trace(this.name + ": " + t);
- }
- this.strip_tags = function(t) {
- doc.open();
- var div = doc.createElement("div");
- div.innerHTML = t.replace(/\n/g, "<br>");
- var text = div.innerText.trim();
- doc.close();
- return text;
- }
- this.InputBox = function(prompt, title, value) {
- prompt = prompt.replace(/"/g, '" + Chr(34) + "').replace(/\n/g, '" + Chr(13) + "');
- title = title.replace(/"/g, '" + Chr(34) + "');
- value = value.replace(/"/g, '" + Chr(34) + "');
- var temp_value = vb.eval('InputBox' + '("' + prompt + '", "' + title + '", "' + value + '")');
- if (typeof temp_value == "undefined") return value;
- if (temp_value.length == 254) this.MsgBox("Your entry was too long and will be truncated.\n\nSee the WSH panel mod script discussion thread on hydrogenaudio forums for help.", 0, this.name);
- return temp_value.trim();
- }
- this.MsgBox = function(prompt, buttons, title) {
- prompt = prompt.replace(/"/g, '" + Chr(34) + "').replace(/\n/g, '" + Chr(13) + "');
- title = title.replace(/"/g, '" + Chr(34) + "');
- return vb.eval('MsgBox' + '("' + prompt + '", "' + buttons + '", "' + title + '")');
- }
- this.browser = function(c) {
- if (!this.run(c)) this.MsgBox("Unable to launch your default browser.", 0, this.name);
- }
- this.run = function(c) {
- try {
- WshShell.Run(c);
- return true;
- } catch(e) {
- return false;
- }
- }
- this.run_cmd = function(c, w) {
- try { WshShell.Run(c, 0, w); } catch(e) {}
- }
- this.explorer = function(f) {
- if (f.is_file()) this.run("explorer /select,\"" + f + "\"");
- }
- this.aad = function() {
- var aad_path = window.GetProperty("2k3.aad_path", "");
- if (!aad_path.is_file()) {
- var folder = app.BrowseForFolder(0, "Locate Album Art Downloader", 0x00000200);
- var file = folder ? folder.items().item().path + "\\AlbumArt.exe" : "";
- if (file.is_file()) {
- aad_path = file;
- window.SetProperty("2k3.aad_path", aad_path);
- }
- }
- if (aad_path.is_file()) {
- var album_artist = "/ar \"" + this.eval("[%album artist%]") + "\"";
- var album = " /al \"" + this.eval("[%album%]") + "\"";
- this.run("\"" + aad_path + "\"" + album_artist + album);
- }
- }
- this.tt = function(t) {
- if (this.tooltip.Text == t) return;
- this.tooltip.Text = t;
- this.tooltip.Activate();
- }
- this.splitRGB = function(c) {
- var temp_col = c.split("-");
- return RGB(temp_col[0], temp_col[1], temp_col[2]);
- }
- this.draw_background = function(gr) {
- if (this.check_feature("custom_background")) {
- var col;
- switch(this.background_mode) {
- case 0:
- col = null;
- break;
- case 1:
- col = this.backcolour;
- break;
- case 2:
- col = utils.GetSysColor(15);
- break;
- case 3:
- col = this.splitRGB(this.background_custom_colour);
- break;
- }
- if (col) gr.FillSolidRect(0, 0, this.w, this.h, col);
- } else {
- gr.FillSolidRect(0, 0, this.w, this.h, this.backcolour);
- }
- }
- this.draw_image = function(gr, img, pos_x, pos_y, width, height, type, border, alpha) {
- if (!img) return;
- gr.SetInterpolationMode(7);
- switch(type) {
- case 0: //crop
- case 1: //crop top
- var sr = img.Width / img.Height;
- var dr = width / height;
- if (sr < dr) {
- var r = img.Width / width;
- var ch = height * r;
- var sy = Math.round((img.Height - ch) / (type == 1 ? 4 : 2));
- var cw = img.Width;
- var sx = 0;
- } else {
- var r = img.Height / height;
- var cw = width * r;
- var sx = Math.round((img.Width - cw) / 2);
- var ch = img.Height;
- var sy = 0;
- }
- gr.DrawImage(img, pos_x, pos_y, width, height, sx + 5, sy + 5, cw - 10, ch - 10, 0, alpha || 255);
- if (border) gr.DrawRect(pos_x, pos_y, width - 1, height - 1, 1, border);
- break;
- case 2: //stretch
- gr.DrawImage(img, pos_x, pos_y, width, height, 0, 0, img.Width, img.Height, 0, alpha || 255);
- if (border) gr.DrawRect(pos_x, pos_y, width - 1, height - 1, 1, border);
- break;
- case 3: //centre
- default:
- var s = Math.min(width / img.Width, height / img.Height);
- var nw = Math.floor(img.Width * s);
- var nh = Math.floor(img.Height * s);
- pos_x += Math.round((width - nw) / 2);
- pos_y += Math.round((height - nh) / 2);
- if (type == "centre") gr.DrawImage(img, pos_x, pos_y, nw, nh, 5, 5, img.Width - 10, img.Height - 10, 0, alpha || 255);
- else gr.DrawImage(img, pos_x, pos_y, nw, nh, 0, 0, img.Width, img.Height, 0, alpha || 255);
- if (border) gr.DrawRect(pos_x, pos_y, nw - 1, nh - 1, 1, border);
- break;
- }
- }
- this.centre_text = function(gr, text, font, colour, x, y, w, h) {
- gr.GdiDrawText(text, font, colour, x, y, w, h, DT_VCENTER | DT_CENTER | DT_WORDBREAK | DT_CALCRECT | DT_NOPREFIX);
- }
- this.left_text = function(gr, text, font, colour, x, y, w, h) {
- gr.GdiDrawText(text, font, colour, x, y, w, h, DT_VCENTER | DT_END_ELLIPSIS | DT_CALCRECT | DT_NOPREFIX);
- }
- this.right_text = function(gr, text, font, colour, x, y, w, h) {
- gr.GdiDrawText(text, font, colour, x, y, w, h, DT_VCENTER | DT_RIGHT | DT_END_ELLIPSIS | DT_CALCRECT | DT_NOPREFIX);
- }
- this.format_time = function(t) {
- t = Math.round(t);
- var w = Math.floor(t / 604800);
- var d = Math.floor((t -= w * 604800) / 86400);
- var h = Math.floor((t -= d * 86400) / 3600);
- var m = Math.floor((t -= h * 3600) / 60);
- var s = t -= m * 60;
- var temp = "";
- if (w > 0) temp += w + "wk ";
- if (w > 0 || d > 0) temp += d + "d ";
- if (w > 0 || d > 0 || h > 0) temp += h + ":";
- temp += (m < 10 && h > 0 ? "0" + m : m) + ":";
- temp += (s < 10 ? "0" + s : s);
- return temp;
- }
- this.update_script = function() {
- this.xmlhttp.open("GET", this.common_js_url, true);
- this.xmlhttp.send();
- this.xmlhttp.onreadystatechange = function() {
- if (p.xmlhttp.readyState == 4) {
- if (p.xmlhttp.status == 200) {
- var text = p.xmlhttp.responsetext;
- switch(true) {
- case text.indexOf("function panel") == -1:
- p.MsgBox("Unexpected server error. Not updating.", 0, p.name);
- break;
- case text.indexOf("var VERSION = \"" + VERSION) == 0:
- p.MsgBox("Already using latest version.", 0, p.name);
- break;
- default:
- if (p.save(text, p.common_js_file)) {
- if (p.MsgBox("Download successful. Restart foobar2000 now?", 4, p.name) == 6) fb.RunMainMenuCommand("File/Restart");
- } else {
- p.MsgBox("Unexpected error. Not updating.", 0, p.name);
- }
- break;
- }
- } else {
- p.console(p.xmlhttp.responsetext || "HTTP error: " + p.xmlhttp.status);
- }
- }
- }
- }
- this.json_parse = function(a, b, c, d) {
- try {
- var data = JSON.parse(a);
- } catch(e) {
- this.console("JSON.parse error.");
- return false;
- }
- if (b) {
- b = b.split(".");
- for (i in b) {
- if (data === null || typeof data[b[i]] === 'undefined') return [];
- data = data[b[i]];
- }
- }
- if (c) {
- data = data.sort(function(e, f) {
- if (!e[c]) return 1;
- if (!f[c]) return -1;
- if (e[c] < f[c]) return d ? 1 : -1;
- if (e[c] > f[c]) return d ? -1 : 1;
- return 0;
- });
- }
- return data;
- }
- this.new_artist_folder = function(t) {
- var folder = this.artists_folder + t.validate() + "\\";
- folder.create();
- return folder;
- }
- this.delete_file = function(f) {
- if (!f.is_file()) return;
- try {
- fso.DeleteFile(f);
- } catch(e) {
- this.console("Could not delete " + f);
- }
- }
- this.fb2k_escape = function(t) {
- return t.replace(/'/g, "''").replace(/[\(\)\[\],$]/g, "'$&'");
- }
- var i;
- this.name = name;
- this.features = features;
- this.is_dui = window.InstanceType;
- this.script_path = fb.ProfilePath + "marc2003\\";
- this.ip = this.script_path + "images8\\";
- this.common_js_url = "https://dl.dropboxusercontent.com/u/22801321/wsh/marc2003/common8.js";
- this.common_js_file = this.script_path + "common8.js";
- this.tooltip = window.CreateTooltip();
- this.w = 0;
- this.h = 0;
- this.mx = 0;
- this.my = 0;
- this.metadb = fb.GetFocusItem();
- this.data_folder = fb.ProfilePath + "wsh_data\\";
- this.artists_folder = this.data_folder + "artists\\"
- this.settings_folder = fb.ProfilePath + "wsh_settings\\";
- this.artist = "";
- this.artist_tf = "%artist%";
- this.normal_font_size = window.GetProperty("2k3.normal_font_size", 14);
- this.list_font_size = window.GetProperty("2k3.list_font_size", 11);
- this.up_img = gdi.Image(this.ip + "buttons\\up.png");
- this.down_img = gdi.Image(this.ip + "buttons\\down.png");
- this.selection_mode = 1;
- this.metadb_func = typeof on_metadb_changed == "function";
- this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
- this.features_init();
- this.colours_changed();
- this.font_changed();
- }
- function artreader(x, y, w, h) {
- this.draw = function(gr) {
- if (!this.img) return;
- p.draw_image(gr, this.img, this.x, this.y, this.w, this.h, this.type);
- }
- this.metadb_changed = function() {
- if (!p.metadb) return;
- this.img && this.img.Dispose();
- this.path = "";
- this.img = utils.GetAlbumArtV2(p.metadb, this.id);
- window.RepaintRect(this.x, this.y, this.w, this.h);
- utils.GetAlbumArtAsync(window.ID, p.metadb, this.id);
- }
- this.get_album_art_done = function(p) {
- this.path = p;
- }
- this.trace = function(x, y) {
- return x > this.x && x < this.x + this.w && y > this.y && y < this.y + this.h;
- }
- this.wheel = function(s) {
- if (!this.trace(p.mx, p.my)) return false;
- this.id -= s;
- if (this.id < 0) this.id = 4;
- if (this.id > 4) this.id = 0;
- window.SetProperty("2k3.artreader_id", this.id);
- p.item_focus_change();
- return true;
- }
- this.move = function(x, y) {
- if (this.trace(x, y)) {
- if (this.img) p.tt("Original size: " + this.img.Width + "x" + this.img.Height + "px");
- this.hover = true;
- return true;
- } else {
- if (this.hover) p.tt("");
- this.hover = false;
- return false;
- }
- }
- this.lbtn_dblclk = function(x, y) {
- switch(true) {
- case !this.trace(x, y):
- return false;
- case this.path == p.metadb.path:
- case this.dblclk == 1:
- p.explorer(this.path);
- break;
- case this.path.is_file():
- p.run("\"" + this.path + "\"");
- break;
- }
- return true;
- }
- this.x = x;
- this.y = y;
- this.w = w;
- this.h = h;
- this.id = window.GetProperty("2k3.artreader_id", 0);
- this.type = window.GetProperty("2k3.artreader_type", 0);
- this.dblclk = window.GetProperty("2k3.artreader_dblclk", 0);
- this.img = null;
- this.path = null;
- this.hover = false;
- }
- function buttons(type) {
- this.draw = function(gr) {
- for (i in this.buttons) {
- this.buttons[i].draw(gr);
- }
- }
- this.move = function(x, y) {
- this.tmp_btn = null;
- for (i in this.buttons) {
- if (this.buttons[i].trace(x, y)) this.tmp_btn = i;
- }
- if (this.btn == this.tmp_btn) return this.btn;
- if (this.tmp_btn) this.buttons[this.tmp_btn].cs("hover");
- if (this.btn) this.buttons[this.btn].cs("normal");
- this.btn = this.tmp_btn;
- if (!this.btn) p.tt("");
- return this.btn;
- }
- this.lbtn_up = function(x, y) {
- if (!this.btn) return false;
- this.buttons[this.btn].lbtn_up(x, y);
- return true;
- }
- this.leave = function() {
- if (this.btn) this.buttons[this.btn].cs("normal");
- this.btn = null;
- }
- var i;
- this.buttons = [];
- this.btn = null;
- if (type == "playback") {
- this.images = {
- play: gdi.Image(p.ip + "buttons\\play.png"),
- stop: gdi.Image(p.ip + "buttons\\stop.png"),
- pause: gdi.Image(p.ip + "buttons\\pause.png"),
- previous: gdi.Image(p.ip + "buttons\\previous.png"),
- next: gdi.Image(p.ip + "buttons\\next.png"),
- preferences: gdi.Image(p.ip + "buttons\\preferences.png"),
- search: gdi.Image(p.ip + "buttons\\search.png"),
- help: gdi.Image(p.ip + "buttons\\help.png")
- }
- }
- }
- function button(x, y, w, h, img_src, func, tiptext, themed) {
- this.draw = function (gr) {
- if (this.themed) {
- p.themed_button.SetPartAndStateId(1, this.id);
- p.themed_button.DrawThemeBackground(gr, this.x, this.y, this.w, this.h);
- this.img && p.draw_image(gr, this.img, this.x + Math.round((this.w - this.img.Width) / 2), this.y + Math.round((this.h - this.img.Height) / 2), this.img.Width, this.img.Height);
- } else {
- this.img && p.draw_image(gr, this.img, this.x, this.y, this.w, this.h);
- }
- }
- this.trace = function(x, y) {
- return x > this.x && x < this.x + this.w && y > this.y && y < this.y + this.h;
- }
- this.lbtn_up = function () {
- this.func && this.func(x, y);
- }
- this.cs = function(s) {
- if (s == "hover") {
- this.img = this.img_hover;
- this.id = 2;
- p.tt(this.tiptext);
- } else {
- this.img = this.img_normal;
- this.id = 0;
- }
- window.RepaintRect(this.x, this.y, this.w, this.h);
- }
- this.x = x;
- this.y = y;
- this.w = w;
- this.h = h;
- this.func = func;
- this.tiptext = tiptext;
- this.themed = themed;
- this.id = 0;
- this.img_normal = img_src.normal;
- this.img_hover = img_src.hover || this.img_normal;
- this.img = this.img_normal;
- }
- function cd(x, y, w, h) {
- this.draw = function(gr) {
- if (this.shadow) p.draw_image(gr, this.shadow_img, this.x, this.y, this.w, this.h);
- p.draw_image(gr, this.case_img, this.x, this.y, this.w, this.h);
- if (this.img) {
- this.ratio = Math.min(this.w / this.case_img.Width, this.h / this.case_img.Height);
- this.nw = 488 * this.ratio;
- this.nh = 476 * this.ratio;
- this.nx = Math.round((this.w - (452 * this.ratio)) / 2);
- this.ny = Math.round((this.h - this.nh) / 2);
- p.draw_image(gr, this.img, this.nx + this.x, this.ny + this.y, this.nw, this.nh, 1);
- }
- p.draw_image(gr, this.semi_img, this.x, this.y, this.w, this.h);
- if (this.gloss) p.draw_image(gr, this.gloss_img, this.x, this.y, this.w, this.h);
- }
- this.metadb_changed = function() {
- if (!p.metadb) return;
- this.img && this.img.Dispose();
- this.path = "";
- this.img = utils.GetAlbumArtV2(p.metadb, 0);
- window.Repaint();
- utils.GetAlbumArtAsync(window.ID, p.metadb, 0);
- }
- this.get_album_art_done = function(ip) {;
- this.path = ip;
- }
- this.trace = function(x, y) {
- return x > this.x && x < this.x + this.w && y > this.y && y < this.y + this.h;
- }
- this.move = function(x, y) {
- if (this.trace(x, y)) {
- if (this.img) p.tt("Original size: " + this.img.Width + "x" + this.img.Height + "px");
- this.hover = true;
- return true;
- } else {
- if (this.hover) p.tt("");
- this.hover = false;
- return false;
- }
- }
- this.lbtn_dblclk = function(x, y) {
- switch(true) {
- case !this.trace(x, y):
- return false;
- case this.path == p.metadb.path:
- case this.dblclk == 1:
- p.explorer(this.path);
- break;
- case this.path.is_file():
- p.run("\"" + this.path + "\"");
- break;
- }
- return true;
- }
- this.x = x;
- this.y = y;
- this.w = w;
- this.h = h;
- this.shadow_img = gdi.Image(p.ip + "cd\\shadow.png");
- this.case_img = gdi.Image(p.ip + "cd\\case.png");
- this.semi_img = gdi.Image(p.ip + "cd\\semi.png");
- this.gloss_img = gdi.Image(p.ip + "cd\\gloss.png");
- this.gloss = window.GetProperty("2k3.cd_gloss", false);
- this.shadow = window.GetProperty("2k3.cd_shadow", false);
- this.dblclk = window.GetProperty("2k3.cd_dblclk", 0);
- this.img = null;
- this.path = null;
- this.hover = false;
- }
- function lastfm() {
- this.notify_data = function() {
- this.username = p.open(this.username_file).trim();
- this.sk = p.open(this.sk_file).trim();
- if (typeof li == "object" && li.mode == "lastfm_charts") li.update();
- if (typeof ps == "object") {
- ps.loved_working = false;
- ps.playcount_working = false;
- if (p.metadb) p.item_focus_change();
- else ps.update_button();
- }
- window.Repaint();
- }
- this.post = function(method, metadb) {
- switch(method) {
- case "auth.getMobileSession":
- var func = function() {
- var data = p.json_parse(l.xmlhttp.responsetext);
- if (!data) return;
- if (data.error) {
- p.MsgBox(data.message, 0, p.name);
- } else if (data.session && data.session.key.length == 32) {
- p.MsgBox("Your password was verified successfully. It will not be saved anywhere.", 0, p.name);
- p.save(data.session.key, l.sk_file, 0);
- window.NotifyOthers("lastfm", "update");
- l.notify_data();
- }
- }
- this.authToken = md5(this.username + md5(this.password));
- this.api_sig = md5("api_key" + this.api_key + "authToken" + this.authToken + "method" + method + "username" + this.username + this.secret);
- this.data = "method=" + method + "&api_key=" + this.api_key + "&api_sig=" + this.api_sig + "&format=json&authToken=" + this.authToken + "&username=" + this.username;
- break;
- case "track.love":
- case "track.unlove":
- var func = function() {
- var data = p.json_parse(l.xmlhttp.responsetext);
- if (!data) return;
- if (data.error) {
- p.console(data.message);
- } else if (data.status && data.status == "ok") {
- p.console("Track " + (method == "track.love" ? "loved successfully." : "unloved successfully."));
- fb.RunContextCommandWithMetadb("Customdb Love " + (method == "track.love" ? 1 : 0), metadb, 8);
- }
- }
- if (!ps.check_component || !metadb || this.username.length == 0 || this.sk.length != 32) return;
- this.artist = tf(p.artist_tf, metadb);
- this.track = tf("%title%", metadb);
- if (this.artist == "" || this.artist == "?") return;
- p.console("Attempting to " + (method == "track.love" ? "love \"" : "unlove \"") + this.track + "\" by \"" + this.artist + "\"");
- p.console("Contacting Last.fm....");
- this.api_sig = md5("api_key" + this.api_key + "artist" + this.artist + "method" + method + "sk" + this.sk + "track" + this.track + this.secret);
- this.data = "method=" + method + "&api_key=" + this.api_key + "&api_sig=" + this.api_sig + "&format=json&sk=" + this.sk + "&artist=" + encodeURIComponent(this.artist) + "&track=" + encodeURIComponent(this.track);
- break;
- default:
- return;
- }
- this.xmlhttp.open("POST", "https://ws.audioscrobbler.com/2.0/", true);
- this.xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
- this.xmlhttp.setRequestHeader("User-Agent", this.ua);
- this.xmlhttp.send(this.data);
- this.xmlhttp.onreadystatechange = function() {
- if (l.xmlhttp.readyState == 4) {
- if (l.xmlhttp.status == 200) {
- func();
- } else {
- p.console(l.xmlhttp.responsetext || "HTTP error: " + l.xmlhttp.status);
- }
- }
- }
- }
- this.update_username = function() {
- var old_username = this.username;
- this.username = p.InputBox("Enter your Last.fm username", p.name, this.username);
- if (this.username != old_username) {
- p.save(this.username, this.username_file);
- p.save("", this.sk_file, 0);
- window.NotifyOthers("lastfm", "update");
- this.notify_data();
- }
- }
- this.update_password = function() {
- this.password = p.InputBox("Enter your Last.fm password", p.name, "");
- if (this.password.length > 0) {
- this.sk = "";
- p.save(this.sk, this.sk_file, 0);
- window.NotifyOthers("lastfm", "update");
- this.notify_data();
- this.post("auth.getMobileSession");
- }
- }
- this.get_url = function() {
- var url = "http://ws.audioscrobbler.com/2.0/?format=json&api_key=" + this.api_key + "&s=" + Math.random();
- if (this.need_username) url += "&user=" + this.username + "&username=" + this.username;
- return url;
- }
- this.username_error = "Use the right click menu to set your Last.fm username.";
- this.password_error = "Use the right click menu to set your Last.fm password.";
- this.api_key = "56d9e050cc2d6b36102c8b4a5fe6152d";
- this.secret = "9f1f4346ce3ba206390074ff8cb4c6ce";
- this.ua = "foobar2000_wsh_panel_mod_lastfm";
- this.username_file = p.settings_folder + "username";
- this.username = p.open(this.username_file).trim();
- this.sk_file = p.settings_folder + "sk";
- this.sk = p.open(this.sk_file).trim();
- this.auto_correct = window.GetProperty("2k3.lastfm_auto_correct", true);
- this.need_username = false;
- this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
- }
- function list(mode, x, y, w, h) {
- this.size = function() {
- this.row_height = this.mode == "echonest" ? 90 : 20;
- this.rows = Math.floor((this.h - 30) / this.row_height);
- this.index = 0;
- this.offset = 0;
- switch(true) {
- case this.mode == "lastfm_charts":
- this.text_width = Math.round(this.w / 3);
- this.lastfm_charts_bar_x = this.text_width + 40;
- break;
- case this.mode == "musicbrainz" && this.mbs["2k3.musicbrainz_releases"]:
- this.text_width = this.w - 130;
- break;
- default:
- this.text_width = this.w - 50;
- break;
- }
- var but_x = this.x + Math.round((this.w - 15) / 2);
- this.up_btn = new sb(but_x, this.y, 15, 15, p.up_img, "li.offset > 0", function() { li.wheel(1); });
- this.down_btn = new sb(but_x, this.y + this.h - 15, 15, 15, p.down_img, "li.offset < li.items - li.rows", function() { li.wheel(-1); });
- }
- this.draw = function(gr) {
- switch(this.mode) {
- case "autoplaylists":
- for (i = 0; i < Math.min(this.items, this.rows); i++) {
- p.left_text(gr, this.names[i + this.offset], p.list_font, p.textcolour, this.x, this.y + 15 + (i * this.row_height), this.text_width, this.row_height);
- if (!this.autoplaylists_editing && this.autoplaylists_hover && this.index == i + this.offset) {
- p.draw_image(gr, this.autoplaylists_edit_img, this.x + this.w - 40, this.y + 16 + (i * this.row_height), 16, 16);
- p.draw_image(gr, this.autoplaylists_del_img, this.x + this.w - 20, this.y + 16 + (i * this.row_height), 16, 16);
- }
- }
- break;
- case "echonest":
- for (i = 0; i < Math.min(this.items, this.rows); i++) {
- p.left_text(gr, this.names[i + this.offset], p.title_font, p.textcolour_hl, this.x, this.y + 15 + (i * this.row_height), this.w - 110, 24);
- p.right_text(gr, this.dates[i + this.offset], p.title_font, p.textcolour_hl, this.x, this.y + 15 + (i * this.row_height), this.w, 24);
- gr.GdiDrawText(this.summaries[i + this.offset], p.normal_font, p.textcolour, this.x, this.y + 37 + (i * this.row_height), this.w, (p.list_font.Height * Math.floor(64 / p.list_font.Height)) + 2, DT_WORDBREAK | DT_CALCRECT | DT_NOPREFIX);
- }
- break;
- case "lastfm":
- for (i = 0; i < Math.min(this.items, this.rows); i++) {
- p.left_text(gr, this.names[i + this.offset], p.list_font, p.textcolour, this.x + this.text_x, this.y + 15 + (i * this.row_height), this.text_width, this.row_height);
- }
- break;
- case "lastfm_charts":
- var max_bar_width = (this.w - this.lastfm_charts_bar_x - 50) / this.playcounts[0];
- for (i = 0; i < Math.min(this.items, this.rows); i++) {
- p.right_text(gr, this.ranks[i + this.offset] + ".", p.list_font, p.textcolour_hl, this.x, this.y + 15 + (i * this.row_height), this.text_x - 5, this.row_height);
- var bar_width = max_bar_width * this.playcounts[i + this.offset];
- var bar_colour = p.splitRGB(this.lastfm_charts_bar_colour);
- gr.FillSolidRect(this.lastfm_charts_bar_x + this.x, this.y + 16 + (i * this.row_height), bar_width, 18, bar_colour);
- p.left_text(gr, this.playcounts[i + this.offset].addCommas(), p.list_font, p.textcolour, this.x + 5 + this.lastfm_charts_bar_x + bar_width, this.y + 15 + (i * this.row_height), 50, this.row_height);
- p.left_text(gr, this.names[i + this.offset], p.list_font, p.textcolour, this.x + this.text_x, this.y + 15 + (i * this.row_height), this.text_width, this.row_height);
- }
- break;
- case "musicbrainz":
- this.text_x = !this.mbs["2k3.musicbrainz_releases"] && this.mbs["2k3.musicbrainz_show_icons"] ? 20 : 0;
- for (i = 0; i < Math.min(this.items, this.rows); i++) {
- if (this.mbs["2k3.musicbrainz_releases"]) {
- if (this.mbs["2k3.musicbrainz_show_release_type"]) p.right_text(gr, this.release_types[i + this.offset], p.list_font, p.textcolour, this.x, this.y + 15 + (i * this.row_height), this.w - 38, this.row_height);
- p.right_text(gr, this.dates[i + this.offset], p.list_font, p.textcolour_hl, this.x, this.y + 15 + (i * this.row_height), this.w, this.row_height);
- } else {
- if (this.mbs["2k3.musicbrainz_show_icons"]) p.draw_image(gr, this.musicbrainz_images[this.images[i + this.offset]], this.x, this.y + 16 + (i * this.row_height), 16, 16);
- }
- p.left_text(gr, this.names[i + this.offset], p.list_font, p.textcolour, this.x + this.text_x, this.y + 15 + (i * this.row_height), this.text_width, this.row_height);
- }
- break;
- case "properties":
- for (i = 0; i < Math.min(this.items, this.rows); i++) {
- p.left_text(gr, this.names[i + this.offset], p.list_font, p.textcolour_hl, this.x, this.y + 15 + (i * this.row_height), this.text_x - 10, this.row_height);
- p.left_text(gr, this.urls[i + this.offset], p.list_font, p.textcolour, this.x + this.text_x, this.y + 15 + (i * this.row_height), this.w - this.text_x - 10, this.row_height);
- }
- break;
- }
- this.up_btn.draw(gr);
- this.down_btn.draw(gr);
- }
- this.metadb_changed = function() {
- if (!p.metadb) return false;
- if (this.mode != "properties") {
- p.artist = p.eval(p.artist_tf);
- if (this.artist == p.artist) return false;
- this.artist = p.artist;
- this.folder = p.new_artist_folder(this.artist);
- }
- this.update();
- return true;
- }
- this.trace = function(x, y) {
- return x > this.x && x < this.x + this.w && y > this.y && y < this.y + this.h;
- }
- this.wheel = function(s) {
- if (!this.trace(p.mx, p.my)) return false;
- if (this.items > this.rows) {
- this.offset -= s * (this.mode == "echonest" ? 1 : 5);
- if (this.offset < 0) this.offset = 0;
- if (this.rows + this.offset > this.items) this.offset = this.items - this.rows;
- window.RepaintRect(this.x, this.y, this.w, this.h);
- }
- return true;
- }
- this.move = function(x, y) {
- this.index = Math.floor((y - this.y - 15) / this.row_height) + this.offset;
- this.in_range = this.index >= this.offset && this.index < this.offset + Math.min(this.rows, this.items);
- switch(true) {
- case !this.trace(x, y):
- case this.mode == "autoplaylists" && this.autoplaylists_editing:
- window.SetCursor(IDC_ARROW);
- this.leave();
- return false;
- case this.up_btn.trace(x, y):
- case this.down_btn.trace(x, y):
- window.SetCursor(IDC_HAND);
- break;
- case !this.in_range:
- window.SetCursor(IDC_ARROW);
- this.leave();
- break;
- case this.mode == "autoplaylists":
- switch(true) {
- case x > this.x && x < this.x + Math.min(this.names_widths[this.index], this.text_width):
- window.SetCursor(IDC_HAND);
- p.tt('Run "' + this.names[this.index] + '"');
- break;
- case x > this.x + this.w - 40 && x < this.x + this.w - 20:
- window.SetCursor(IDC_HAND);
- p.tt('Edit "' + this.names[this.index] + '"');
- break;
- case x > this.x + this.w - 20 && x < this.x + this.w:
- window.SetCursor(IDC_HAND);
- p.tt('Delete "' + this.names[this.index] + '"');
- break;
- default:
- window.SetCursor(IDC_ARROW);
- p.tt("");
- this.leave();
- break;
- }
- this.autoplaylists_hover = true;
- window.RepaintRect(this.x + this.w - 40, this.y + 15, 40, Math.min(this.rows, this.items) * this.row_height);
- break;
- case this.mode == "echonest":
- case x > this.x + this.text_x && x < this.x + this.text_x + Math.min(this.names_widths[this.index], this.text_width):
- window.SetCursor(IDC_HAND);
- switch(true) {
- case this.mode == "lastfm" && this.lastfm_mode != 2 && !this.lastfm_link:
- case this.mode == "lastfm_charts" && !this.lastfm_link:
- case this.mode == "properties":
- p.tt("Autoplaylist: " + this.queries[this.index]);
- break;
- default:
- p.tt(this.urls[this.index]);
- break;
- }
- break;
- default:
- window.SetCursor(IDC_ARROW);
- p.tt("");
- break;
- }
- return true;
- }
- this.lbtn_up = function(x, y) {
- switch(true) {
- case !this.trace(x, y):
- return false;
- case this.mode == "autoplaylists" && this.autoplaylists_editing:
- case this.up_btn.lbtn_up(x, y):
- case this.down_btn.lbtn_up(x, y):
- case !this.in_range:
- break;
- case this.mode == "autoplaylists":
- switch(true) {
- case x > this.x && x < this.x + Math.min(this.names_widths[this.index], this.text_width):
- this.autoplaylists_run(this.names[this.index], this.queries[this.index], this.sorts[this.index], this.forced[this.index]);
- break;
- case x > this.x + this.w - 40 && x < this.x + this.w - 20:
- this.autoplaylists_edit(x, y);
- break;
- case x > this.x + this.w - 20 && x < this.x + this.w:
- this.autoplaylists_delete();
- break;
- }
- break;
- case this.mode == "echonest":
- case x > this.x + this.text_x && x < this.x + this.text_x + Math.min(this.names_widths[this.index], this.text_width):
- switch(true) {
- case this.mode == "lastfm" && this.lastfm_mode != 2 && !this.lastfm_link:
- case this.mode == "lastfm_charts" && !this.lastfm_link:
- case this.mode == "properties":
- fb.CreateAutoPlaylist(fb.PlaylistCount, this.names[this.index], this.queries[this.index]);
- fb.ActivePlaylist = fb.PlaylistCount - 1;
- break;
- default:
- p.browser(this.urls[this.index]);
- break;
- }
- break;
- }
- return true;
- }
- this.leave = function() {
- if (this.mode == "autoplaylists") {
- this.autoplaylists_hover = false;
- window.RepaintRect(this.x, this.y, this.w, this.h);
- }
- }
- this.update = function() {
- this.items = 0;
- this.offset = 0;
- this.index = 0;
- var temp_bmp = gdi.CreateImage(1, 1);
- var temp_gr = temp_bmp.GetGraphics();
- switch(this.mode) {
- case "autoplaylists":
- this.data = [];
- this.names = [];
- this.queries = [];
- this.sorts = [];
- this.forced = [];
- this.names_widths = [];
- var text = p.open(this.filename);
- if (text.length > 0) this.data = text.split(/\r?\n/g);
- for (i in this.data) {
- var temp = this.data[i].split("¬");
- this.names[i] = temp[0];
- this.queries[i] = temp[1];
- this.sorts[i] = temp[2];
- this.forced[i] = temp[3];
- this.names_widths[i] = temp_gr.CalcTextWidth(this.names[i], p.list_font);
- }
- this.items = this.data.length;
- break;
- case "echonest":
- this.names = [];
- this.urls = [];
- this.dates = [];
- this.summaries = [];
- this.filename = this.folder + "echonest_" + this.echonest_modes[this.echonest_mode] + ".json";
- if (this.filename.is_file()) {
- var temp_date;
- var data = p.json_parse(p.open(this.filename), "response." + this.echonest_modes[this.echonest_mode]);
- for (i in data) {
- this.names[i] = p.strip_tags(data[i].name).replace(/\s{2,}/g,' ');
- this.urls[i] = (data[i].url || "").replace(/\\/g, "");
- temp_date = (data[i].date_posted || data[i].date_reviewed || data[i].date_found || "").substring(0, 10);
- this.dates[i] = temp_date.substring(8,10) + "-" + temp_date.substring(5,7) + "-" + temp_date.substring(0,4);
- this.summaries[i] = p.strip_tags(data[i].summary);
- }
- this.items = data.length;
- if (this.filename.expired(ONE_DAY)) this.get();
- } else {
- this.get();
- }
- break;
- case "lastfm":
- this.names = [];
- this.names_widths = [];
- this.urls = [];
- this.queries = [];
- this.filename = this.folder + this.lastfm_methods[this.lastfm_mode] + ".json";
- if (this.filename.is_file()) {
- var data = p.json_parse(p.open(this.filename), this.lastfm_json[this.lastfm_mode]);
- var query_text = this.lastfm_queries[this.lastfm_mode] + " HAS ";
- if (typeof data.length == "undefined") data = [data];
- for (i in data) {
- this.names[i] = data[i].name;
- this.names_widths[i] = temp_gr.CalcTextWidth(this.names[i], p.list_font);
- this.urls[i] = data[i].url;
- if (this.lastfm_mode != 2) this.queries[i] = query_text + data[i].name;
- }
- this.items = data.length;
- if (this.filename.expired(ONE_DAY)) this.get();
- } else {
- this.get();
- }
- break;
- case "lastfm_charts":
- this.names = [];
- this.names_widths = [];
- this.urls = [];
- this.queries = [];
- this.ranks = [];
- this.playcounts = [];
- this.filename = this.folder + l.username + "_" + this.lastfm_charts_modes[this.lastfm_charts_mode] + "_" + this.lastfm_charts_periods[this.lastfm_charts_period] + ".json";
- if (this.filename.is_file()) {
- var data = p.json_parse(p.open(this.filename), this.lastfm_charts_json[this.lastfm_charts_mode]);
- var query_text = this.lastfm_charts_queries[this.lastfm_charts_mode] + " HAS ";
- if (typeof data.length == "undefined") data = [data];
- for (i in data) {
- this.names[i] = this.lastfm_charts_mode == 0 ? data[i].name : data[i].name + " - " + data[i].artist.name;
- this.names_widths[i] = temp_gr.CalcTextWidth(this.names[i], p.list_font);
- this.urls[i] = data[i].url;
- this.queries[i] = query_text + data[i].name;
- this.playcounts[i] = data[i].playcount;
- this.ranks[i] = i > 0 && this.playcounts[i] == this.playcounts[i - 1] ? this.ranks[i - 1] : data[i]["@attr"].rank;
- }
- this.items = data.length;
- if (this.filename.expired(ONE_DAY)) this.get();
- } else {
- this.get();
- }
- break;
- case "musicbrainz":
- this.names = [];
- this.names_widths = [];
- this.urls = [];
- this.dates = [];
- this.release_types = [];
- this.images = [];
- this.mb_temp = [];
- this.page = 1;
- this.filename = this.folder + "musicbrainz_" + (this.mbs["2k3.musicbrainz_releases"] ? "releases1.json" : "links.json");
- if (this.filename.is_file()) {
- if (this.mbs["2k3.musicbrainz_releases"]) {
- p.delete_file(this.folder + "musicbrainz_releases.json");
- var data = p.json_parse(p.open(this.filename), "", "first-release-date", this.mbs["2k3.musicbrainz_newest_first"]);
- var primary, secondary, name;
- for (i in data) {
- primary = data[i]["primary-type"];
- secondary = data[i]["secondary-types"].join("").toLowerCase();
- switch(true) {
- case !this.mbs["2k3.musicbrainz_remix"] && secondary.indexOf("remix") > -1:
- case !this.mbs["2k3.musicbrainz_compilation"] && secondary.indexOf("compilation") > -1:
- case !this.mbs["2k3.musicbrainz_live"] && secondary.indexOf("live") > -1:
- break;
- case this.mbs["2k3.musicbrainz_other"] && (primary == null || primary == "Other" || primary == "Broadcast"):
- case this.mbs["2k3.musicbrainz_single"] && primary == "Single":
- case this.mbs["2k3.musicbrainz_ep"] && primary == "EP":
- case this.mbs["2k3.musicbrainz_album"] && primary == "Album":
- name = data[i].title;
- this.names.push(name);
- this.names_widths.push(temp_gr.CalcTextWidth(name, p.list_font));
- this.urls.push("http://musicbrainz.org/release-group/" + data[i].id);
- this.dates.push(data[i]["first-release-date"].substring(0,4));
- switch(true) {
- case secondary.indexOf("remix") > -1:
- this.release_types.push("Remix");
- break;
- case secondary.indexOf("compilation") > -1:
- this.release_types.push("Compilation");
- break;
- case secondary.indexOf("live") > -1:
- this.release_types.push("Live");
- break;
- default:
- this.release_types.push(primary || "Unknown");
- break;
- }
- }
- }
- this.items = this.names.length;
- } else {
- var data = p.json_parse(p.open(this.filename), "relations");
- for (i in data) {
- this.urls[i] = data[i].url.resource;
- this.images[i] = "external";
- if (data[i].type == "official homepage") {
- this.images[i] = "home";
- } else {
- for (var name in this.musicbrainz_images) {
- if (this.urls[i].indexOf(name) > -1) {
- this.images[i] = name;
- break;
- }
- }
- }
- this.names[i] = this.urls[i];
- this.names_widths[i] = temp_gr.CalcTextWidth(this.names[i], p.list_font);
- }
- this.items = data.length;
- }
- if (this.filename.expired(ONE_DAY)) this.get();
- } else {
- this.get();
- }
- break;
- case "properties":
- this.names = [];
- this.names_widths = [];
- this.urls = [];
- this.queries = [];
- this.img = false;
- this.filename = p.metadb.Path;
- var fileinfo = p.metadb.GetFileInfo();
- var name;
- for (i = 0; i < fileinfo.MetaCount; i++) {
- name = fileinfo.MetaName(i);
- this.names[i] = name.toUpperCase();
- this.urls[i] = p.eval("$meta(" + name + ")").replace(/\s{2,}/g,' ');
- this.queries[i] = this.names[i].toLowerCase() + " IS " + this.urls[i];
- }
- this.names = this.names.concat(["", "PATH", "FILE SIZE", "LAST MODIFIED", "", "DURATION"]);
- this.urls = this.urls.concat(["", p.metadb.Path, p.eval("[%filesize_natural%]"), p.eval("[%last_modified%]"), "", p.eval("[%length%]")]);
- this.queries = this.queries.concat(["", "%path% IS " + p.metadb.Path, "%filesize_natural% IS " + p.eval("[%filesize_natural%]"), "%last_modified% IS " + p.eval("[%last_modified%]"), "", "%length% IS " + p.eval("[%length%]")]);
- for (i = 0; i < fileinfo.InfoCount; i++) {
- name = fileinfo.InfoName(i);
- this.names.push(name.toUpperCase());
- this.urls.push(p.eval("%__" + name + "%"));
- this.queries.push("%__" + name + "%" + " IS " + p.eval("%__" + name + "%"));
- }
- for (i in this.names) {
- this.names_widths[i] = temp_gr.CalcTextWidth(this.urls[i], p.list_font);
- }
- fileinfo.Dispose();
- this.items = this.names.length;
- break;
- }
- temp_bmp.ReleaseGraphics(temp_gr);
- temp_bmp.Dispose();
- temp_gr = null;
- temp_bmp = null;
- window.Repaint();
- }
- this.get = function() {
- var fn = this.filename;
- var func = function() {
- p.save(li.xmlhttp.responsetext, fn);
- if (li.mode == "lastfm_charts") {
- li.update();
- } else {
- li.artist = "";
- p.item_focus_change();
- }
- }
- switch(this.mode) {
- case "echonest":
- if (this.artist == "" || this.artist == "?") return;
- var url = "http://developer.echonest.com/api/v4/artist/" + this.echonest_modes[this.echonest_mode] + "/?name=" + encodeURIComponent(this.artist) + "&api_key=EKWS4ESQLKN3G2ZWV";
- break;
- case "lastfm":
- if (this.artist == "" || this.artist == "?") return;
- var url = l.get_url() + "&method=" + this.lastfm_methods[this.lastfm_mode] + "&artist=" + encodeURIComponent(this.artist) + "&autocorrect=" + (l.auto_correct ? 1 : 0);
- break;
- case "lastfm_charts":
- if (l.username.length == 0) return p.console(l.username_error);
- var url = l.get_url() + "&method=user." + this.lastfm_charts_methods[this.lastfm_charts_mode] + "&period=" + this.lastfm_charts_periods[this.lastfm_charts_period];
- break;
- case "musicbrainz":
- var fn1 = this.folder + "musicbrainz_artistid.txt";
- this.musicbrainz_id = p.eval("$if3(%musicbrainz_artistid%,%musicbrainz artist id%,)");
- this.musicbrainz_id = this.musicbrainz_id.substring(0, 36);
- if (this.musicbrainz_id.length == 0) this.musicbrainz_id = p.open(fn1);
- if (this.musicbrainz_id.length == 0) {
- func = function() {
- li.musicbrainz_save_id(li.xmlhttp.responsetext, fn1);
- }
- if (this.artist == "" || this.artist == "?") return;
- var url = "https://musicbrainz.org/ws/2/artist/?query=artist:" + encodeURIComponent(this.musicbrainz_escape(this.artist)) + "&fmt=json";
- } else {
- if (this.mbs["2k3.musicbrainz_releases"]) {
- var func = function() {
- var data = p.json_parse(li.xmlhttp.responsetext);
- var count = data["release-group-count"];
- var pages = Math.min(5, Math.ceil(count / 100));
- li.mb_temp = li.mb_temp.concat(data["release-groups"]);
- if (count == 0 || li.page == pages) {
- p.save(JSON.stringify(li.mb_temp), fn);
- li.artist = "";
- p.item_focus_change();
- } else {
- li.page++;
- li.get();
- }
- }
- var url = "https://musicbrainz.org/ws/2/release-group?artist=" + this.musicbrainz_id + "&limit=100&offset=" + ((this.page - 1) * 100) + "&fmt=json";
- } else {
- var url = "https://musicbrainz.org/ws/2/artist/" + this.musicbrainz_id + "?inc=url-rels&fmt=json";
- }
- }
- break;
- default:
- return;
- }
- this.xmlhttp.open("GET", url, true);
- this.xmlhttp.setRequestHeader("User-Agent", this.ua);
- this.xmlhttp.send();
- this.xmlhttp.onreadystatechange = function() {
- if (li.xmlhttp.readyState == 4) {
- if (li.xmlhttp.status == 200) {
- func();
- } else {
- p.console(li.xmlhttp.responsetext || "HTTP error: " + li.xmlhttp.status);
- }
- }
- }
- }
- this.header_text = function() {
- switch(this.mode) {
- case "autoplaylists":
- return this.autoplaylists_title;
- case "echonest":
- return this.artist + ": " + this.echonest_modes[this.echonest_mode];
- case "lastfm":
- return this.artist + ": " + this.lastfm_modes[this.lastfm_mode];
- case "lastfm_charts":
- return l.username + ": " + this.lastfm_charts_periods_display[this.lastfm_charts_period] + " " + this.lastfm_charts_modes[this.lastfm_charts_mode] + " charts";
- case "musicbrainz":
- return this.artist + ": " + (this.mbs["2k3.musicbrainz_releases"] ? "releases" : "links");
- case "properties":
- return p.eval("%artist% - %title%");
- }
- }
- this.init = function() {
- switch(this.mode) {
- case "autoplaylists":
- this.autoplaylists_add = function() {
- if (this.autoplaylists_editing) return;
- this.autoplaylists_editing = true;
- var new_name = p.InputBox("Enter a name for your autoplaylist", p.name, "");
- if (new_name == "") return this.autoplaylists_editing = false;
- var new_query = p.InputBox("Enter your autoplaylist query", p.name, "");
- if (new_query == "") return this.autoplaylists_editing = false;
- var new_sort = p.InputBox("Enter a sort pattern\n\n(optional)", p.name, "");
- var new_force = new_sort.length > 0 ? p.MsgBox("Force sort?", 4, p.name) : 7;
- this.data.push(new_name + "¬" + new_query + "¬" + new_sort + "¬" + new_force);
- if (this.data.length > this.rows) this.offset = this.data.length - this.rows;
- p.save(this.data.join("\n"), this.filename);
- if (this.autoplaylists_success) this.autoplaylists_run(new_name, new_query, new_sort, new_force);
- window.NotifyOthers("autoplaylists", "update");
- this.update();
- this.autoplaylists_editing = false;
- }
- this.autoplaylists_edit = function(x, y) {
- var _menu = window.CreatePopupMenu();
- var i = this.index;
- _menu.AppendMenuItem(MF_STRING, 1, "Rename...");
- _menu.AppendMenuItem(MF_STRING, 2, "Edit query...");
- _menu.AppendMenuItem(MF_STRING, 3, "Edit sort pattern...");
- _menu.AppendMenuItem(MF_STRING, 4, "Force Sort");
- _menu.CheckMenuItem(4, this.forced[i] == 6);
- this.autoplaylists_editing = true;
- this.autoplaylists_hover = false;
- window.RepaintRect(this.x + this.w - 40, this.y + 15, 40, Math.min(this.rows, this.items) * this.row_height);
- var idx = _menu.TrackPopupMenu(x, y);
- switch(idx) {
- case 0:
- this.autoplaylists_editing = false;
- _menu.Dispose();
- return;
- case 1:
- var new_name = p.InputBox("Rename your autoplaylist", p.name, this.names[i]);
- if (new_name != "") this.names[i] = new_name;
- break;
- case 2:
- var new_query = p.InputBox("Enter your autoplaylist query", p.name, this.queries[i]);
- if (new_query != "") this.queries[i] = new_query;
- break;
- case 3:
- var new_sort = p.InputBox("Enter a sort pattern\n\n(optional)", p.name, this.sorts[i]);
- this.sorts[i] = new_sort;
- this.forced[i] = new_sort.length > 0 ? p.MsgBox("Force sort?", 4, p.name) : 7;
- break;
- case 4:
- this.forced[i] = this.forced[i] == 6 ? 7 : 6;
- break;
- }
- _menu.Dispose();
- var temp = this.names[i] + "¬" + this.queries[i] + "¬" + this.sorts[i] + "¬" + this.forced[i];
- if (this.data[i] != temp) {
- this.data[i] = temp;
- p.save(this.data.join("\n"), this.filename);
- if (this.autoplaylists_success) this.autoplaylists_run(this.names[i], this.queries[i], this.sorts[i], this.forced[i]);
- window.NotifyOthers("autoplaylists", "update");
- this.update();
- }
- this.autoplaylists_editing = false;
- }
- this.autoplaylists_delete = function() {
- if (this.offset > 1) this.offset--;
- this.autoplaylists_deleted_items.unshift(this.data[this.index]);
- this.data.splice(this.index, 1);
- p.save(this.data.join("\n"), this.filename);
- window.NotifyOthers("autoplaylists", "update");
- this.update();
- }
- this.autoplaylists_run = function(n, q, s, f) {
- if (this.autoplaylists_remove_duplicates) {
- var i = 0;
- while(i < fb.PlaylistCount) {
- if (fb.GetPlaylistName(i) == n) fb.RemovePlaylist(i);
- else i++;
- }
- }
- fb.CreateAutoPlaylist(fb.PlaylistCount, n, q, s, f == 6);
- fb.ActivePlaylist = fb.PlaylistCount - 1;
- }
- this.autoplaylists_del_img = gdi.Image(p.ip + "misc\\cross2.png");
- this.autoplaylists_edit_img = gdi.Image(p.ip + "misc\\edit.png");
- this.autoplaylists_hover = false;
- this.autoplaylists_editing = false;
- this.autoplaylists_remove_duplicates = window.GetProperty("2k3.autoplaylists_remove_duplicates", true);
- this.autoplaylists_success = window.GetProperty("2k3.autoplaylists_success", true);
- this.autoplaylists_title = window.GetProperty("2k3.autoplaylists_title", "Autoplaylists");
- this.autoplaylists_slot = window.GetProperty("2k3.autoplaylists_slot", 1);
- this.filename = p.settings_folder + "autoplaylists" + this.autoplaylists_slot;
- this.autoplaylists_deleted_items = [];
- p.settings_folder.create();
- break;
- case "echonest":
- this.echonest_modes = ["news", "reviews", "blogs"];
- this.echonest_mode = window.GetProperty("2k3.echonest_mode", 0);
- this.ua = "";
- p.data_folder.create();
- p.artists_folder.create();
- break;
- case "lastfm":
- this.mode = "lastfm";
- this.lastfm_json = ["similarartists.artist", "toptags.tag", "topfans.user", "topalbums.album", "toptracks.track"];
- this.lastfm_queries = ["artist", "genre", "", "album", "title"];
- this.lastfm_methods = ["artist.getSimilar", "artist.getTopTags", "artist.getTopFans", "artist.getTopAlbums", "artist.getTopTracks"];
- this.lastfm_modes = ["similar artists", "top tags", "top fans", "top albums", "top tracks"];
- this.lastfm_mode = window.GetProperty("2k3.lastfm_mode", 0);
- this.lastfm_link = window.GetProperty("2k3.lastfm_link", true);
- this.ua = l.ua;
- p.data_folder.create();
- p.artists_folder.create();
- break;
- case "lastfm_charts":
- this.mode = "lastfm_charts";
- this.text_x = 30;
- this.lastfm_charts_json = ["topartists.artist", "topalbums.album", "toptracks.track"];
- this.lastfm_charts_queries = ["artist", "album", "title"];
- this.lastfm_charts_modes = ["artist", "album", "track"];
- this.lastfm_charts_mode = window.GetProperty("2k3.lastfm_charts_mode", 0);
- this.lastfm_charts_methods = ["getTopArtists", "getTopAlbums", "getTopTracks"];
- this.lastfm_charts_periods_display = ["overall", "last 7 days", "1 month", "3 month", "6 month", "12 month"];
- this.lastfm_charts_periods = ["overall", "7day", "1month", "3month", "6month", "12month"];
- this.lastfm_charts_period = window.GetProperty("2k3.lastfm_charts_period", 0);
- this.lastfm_charts_bar_colour = window.GetProperty("2k3.lastfm_charts_bar_colour", "72-127-221");
- this.lastfm_link = window.GetProperty("2k3.lastfm_link", true);
- l.need_username = true;
- this.ua = l.ua;
- this.folder = p.data_folder + "charts\\";
- p.data_folder.create();
- p.settings_folder.create();
- this.folder.create();
- break;
- case "musicbrainz":
- this.musicbrainz_save_id = function(t, f) {
- var artist = li.musicbrainz_tidy(li.artist);
- var data = p.json_parse(t, "artists");
- for (i in data) {
- if (artist == li.musicbrainz_tidy(data[i].name)) {
- p.save(data[i].id, f, 0);
- li.artist = "";
- p.item_focus_change();
- break;
- }
- }
- }
- this.musicbrainz_tidy = function(t) {
- return t.replace(/’/g, "'").toLowerCase();
- }
- this.musicbrainz_escape = function(t) {
- return t.replace(/[+!(){}\[\]^"~*?:\\\/-]/g, "\\$&");
- }
- this.musicbrainz_images = {
- "viaf.org": gdi.Image(p.ip + "mb\\viaf_small.png"),
- "allmusic.com": gdi.Image(p.ip + "mb\\allmusic_small.png"),
- "external": gdi.Image(p.ip + "mb\\external_small.png"),
- "bbc.co.uk": gdi.Image(p.ip + "mb\\bbc_small.png"),
- "facebook.com": gdi.Image(p.ip + "mb\\facebook_small.png"),
- "home": gdi.Image(p.ip + "mb\\home_small.png"),
- "last.fm": gdi.Image(p.ip + "mb\\lastfm_small.png"),
- "twitter.com": gdi.Image(p.ip + "mb\\twitter_small.png"),
- "soundcloud.com": gdi.Image(p.ip + "mb\\soundcloud_small.png"),
- "wikipedia.org": gdi.Image(p.ip + "mb\\wikipedia_small.png"),
- "discogs.com": gdi.Image(p.ip + "mb\\discogs_small.png"),
- "myspace.com": gdi.Image(p.ip + "mb\\myspace_small.png"),
- "youtube.com": gdi.Image(p.ip + "mb\\youtube_small.png"),
- "imdb.com": gdi.Image(p.ip + "mb\\imdb_small.png"),
- "plus.google.com": gdi.Image(p.ip + "mb\\google_plus_small.png"),
- "lyrics.wikia.com": gdi.Image(p.ip + "mb\\lyrics_wikia_small.png"),
- "flickr.com": gdi.Image(p.ip + "mb\\flickr_small.png"),
- "secondhandsongs.com": gdi.Image(p.ip + "mb\\secondhandsongs_small.png"),
- "vimeo.com": gdi.Image(p.ip + "mb\\vimeo_small.png"),
- "rateyourmusic.com": gdi.Image(p.ip + "mb\\rateyourmusic_small.png"),
- "instagram.com": gdi.Image(p.ip + "mb\\instagram_small.png"),
- "tumblr.com": gdi.Image(p.ip + "mb\\tumblr_small.png"),
- "decoda.com": gdi.Image(p.ip + "mb\\decoda_small.png"),
- "wikidata.org": gdi.Image(p.ip + "mb\\wikidata_small.png")
- };
- this.mb_set = function(s, v) {
- this.mbs[s] = v;
- window.SetProperty(s, v);
- this.artist = "";
- p.item_focus_change();
- }
- this.mbl = ["2k3.musicbrainz_album", "2k3.musicbrainz_ep", "2k3.musicbrainz_single", "2k3.musicbrainz_other", "2k3.musicbrainz_live", "2k3.musicbrainz_remix", "2k3.musicbrainz_compilation", "2k3.musicbrainz_show_release_type", "2k3.musicbrainz_newest_first"];
- this.mbm = ["Include albums", "Include EPs", "Include singles", "Include others", "Include 'Live' releases", "Include 'Remix' releases", "Include 'Compilation' releases", "Show release type", "Newest first"];
- this.mbs = {"2k3.musicbrainz_show_icons": window.GetProperty("2k3.musicbrainz_show_icons", true), "2k3.musicbrainz_releases": window.GetProperty("2k3.musicbrainz_releases", true)};
- for (i in this.mbl) {
- this.mbs[this.mbl[i]] = window.GetProperty(this.mbl[i], true);
- }
- this.ua = "foobar2000_wsh_panel_mod_musicbrainz +http://www.hydrogenaud.io/forums/index.php?showuser=19379";
- p.data_folder.create();
- p.artists_folder.create();
- break;
- case "properties":
- this.mode = "properties";
- this.text_x = 200;
- break;
- }
- }
- var i;
- this.mode = mode;
- this.x = x;
- this.y = y;
- this.w = w;
- this.h = h;
- this.index = 0;
- this.offset = 0;
- this.items = 0;
- this.artist = "";
- this.filename = "";
- this.text_x = 0;
- this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
- this.init();
- }
- function playcount_sync(x, y, size) {
- this.playback_time = function() {
- this.time_elapsed++;
- if (this.time_elapsed == 3 && this.auto_love && tfe(this.auto_love_tf) == 1 && this.old_userloved == 0) {
- p.console("Automatically loving this track....");
- this.love_track();
- }
- if (this.time_elapsed == this.target_time) {
- if (!this.library || fb.IsMetadbInMediaLibrary(p.metadb)) {
- switch(true) {
- case this.loved_working || this.playcount_working:
- return;
- case !this.check_component:
- p.console(this.error_message);
- return;
- default:
- p.console("Contacting Last.fm....");
- this.get(l.get_url() + "&method=track.getinfo&artist=" + encodeURIComponent(this.artist) + "&track=" + encodeURIComponent(this.track) + "&autocorrect=" + (l.auto_correct ? 1 : 0), function() {
- ps.update_track();
- });
- }
- } else {
- p.console("Skipping... Track not in library.");
- }
- }
- }
- this.metadb_changed = function() {
- if (!p.metadb) return false;
- this.artist = tf(p.artist_tf, p.metadb);
- this.track = tf("%title%", p.metadb);
- this.old_userloved = tf("%LASTFM_LOVED_DB%", p.metadb) == 1 ? 1 : 0;
- this.old_userplaycount = tf("%LASTFM_PLAYCOUNT_DB%", p.metadb);
- this.method = this.old_userloved == 1 ? "track.unlove" : "track.love";
- this.crc32 = tf("$crc32($lower(%artist%%title%))", p.metadb);
- this.update_button();
- return true;
- }
- this.playback_new_track = function() {
- this.auto_love_count = 0;
- this.time_elapsed = 0;
- switch(true) {
- case fb.PlaybackLength == 0:
- this.target_time = 240;
- break;
- case fb.PlaybackLength >= 30:
- this.target_time = Math.min(Math.floor(fb.PlaybackLength / 2), 240);
- break;
- default:
- this.target_time = 5;
- break;
- }
- p.item_focus_change();
- }
- this.playback_edited = function() {
- if (this.auto_love && tfe(this.auto_love_tf) == 1 && this.old_userloved == 0 && this.auto_love_count == 0) {
- this.auto_love_count = 1;
- p.console("Automatically loving this track....");
- this.love_track();
- }
- }
- this.love_track = function() {
- l.post(this.method, p.metadb);
- }
- this.get = function(url, func) {
- if (l.username.length == 0) {
- this.loved_working = false;
- this.playcount_working = false;
- p.console(l.username_error);
- return;
- }
- this.xmlhttp.open("GET", url, true);
- this.xmlhttp.setRequestHeader("User-Agent", l.ua);
- this.xmlhttp.send();
- this.xmlhttp.onreadystatechange = function() {
- if (ps.xmlhttp.readyState == 4) {
- if (ps.xmlhttp.status == 200) {
- func();
- } else {
- p.console(ps.xmlhttp.responsetext || "HTTP error: " + ps.xmlhttp.status);
- }
- }
- }
- }
- this.update_track = function() {
- var data = p.json_parse(ps.xmlhttp.responsetext, "track");
- if (data.length == 0) return p.console(ps.xmlhttp.responsetext);
- this.userplaycount = data.userplaycount > 0 ? ++data.userplaycount : 1;
- this.userloved = data.userloved == 1 ? 1 : 0;
- switch(true) {
- case fb.PlaybackLength < 30:
- case fb.PlaybackLength > 10800:
- fb.RunContextCommandWithMetadb("Customdb Love " + this.userloved, p.metadb, 8);
- break;
- case this.userplaycount < this.old_userplaycount:
- p.console("Playcount returned from Last.fm is lower than current value. Not updating.");
- fb.RunContextCommandWithMetadb("Customdb Love " + this.userloved, p.metadb, 8);
- break;
- case this.userplaycount == this.old_userplaycount:
- p.console("No changes found. Not updating.");
- fb.RunContextCommandWithMetadb("Customdb Love " + this.userloved, p.metadb, 8);
- break;
- default:
- p.console("Last.fm responded ok. Attempting to update playcount...");
- if (this.logging) {
- p.console("Old value: " + this.old_userplaycount);
- p.console("New value: " + this.userplaycount);
- }
- fb.RunContextCommandWithMetadb("Customdb Delete Playcount", p.metadb, 8);
- fb.RunContextCommandWithMetadb("Customdb Love 0", p.metadb, 8);
- window.SetTimeout(function() {
- var query = '\"INSERT INTO quicktag(url,subsong,fieldname,value) VALUES(\\"' + ps.crc32 + '\\",\\"-1\\",\\"LASTFM_PLAYCOUNT_DB\\",\\"' + ps.userplaycount + '\\")\";';
- var command = ps.sqlite3_file.sp() + " ";
- command += ps.db_file.sp() + " ";
- command += query;
- var attempt = 1;
- while(tf("%LASTFM_PLAYCOUNT_DB%", p.metadb) != ps.userplaycount && attempt <= 5) {
- if (ps.logging) p.console("Attempt: " + attempt);
- p.run_cmd(command, true);
- attempt++;
- }
- fb.RunContextCommandWithMetadb("Customdb Refresh", p.metadb, 8);
- if (tf("%LASTFM_PLAYCOUNT_DB%", p.metadb) == ps.userplaycount) p.console("Playcount updated successfully.");
- else p.console("Database error. Playcount not updated.");
- if (ps.userloved == 1) fb.RunContextCommandWithMetadb("Customdb Love 1", p.metadb, 8);
- }, 100);
- break;
- }
- }
- this.start_import = function() {
- if (this.show_console) fb.ShowConsole();
- this.loved_page_errors = 0;
- this.playcount_page_errors = 0;
- this.pages = 0;
- this.r = 1;
- this.sql = "BEGIN TRANSACTION;\n";
- this.loved_working = true;
- p.console("Starting import...");
- this.sync_loved(1);
- }
- this.sync_loved = function(p) {
- if (!this.loved_working) return p.console("Import aborted.");
- this.page = p;
- this.get(l.get_url() + "&method=user.getlovedtracks&limit=200&page=" + this.page, function() {
- ps.update_loved();
- });
- }
- this.update_loved = function() {
- var artist, title, data, url;
- data = p.json_parse(ps.xmlhttp.responsetext);
- if (data && data.lovedtracks && data.lovedtracks.track) {
- if (this.page == 1) this.pages = data.lovedtracks["@attr"].totalPages;
- data = data.lovedtracks.track;
- if (typeof data.length == "undefined") data = [data];
- for (i in data) {
- artist = data[i].artist.name;
- title = data[i].name;
- p.console(this.r + ": " + artist + " - " + title);
- url = tfe("$crc32($lower(" + p.fb2k_escape(artist) + p.fb2k_escape(title) + "))", true);
- this.sql += 'INSERT OR REPLACE INTO quicktag(url,subsong,fieldname,value) VALUES("' + url + '","-1","LASTFM_LOVED_DB","1");' + "\n";
- this.r++;
- }
- p.console("Loved tracks: completed page " + this.page + " of " + this.pages);
- } else {
- this.loved_page_errors++;
- }
- if (this.page < this.pages) {
- this.page++;
- this.sync_loved(this.page);
- } else {
- this.loved_working = false;
- switch(true) {
- case this.full_import:
- this.playcount_working = true;
- this.pages = 0;
- this.r = 1;
- this.sync_playcount(1);
- break;
- case this.sql == "BEGIN TRANSACTION;\n":
- p.console("Nothing found to import.");
- break;
- default:
- this.sql += "COMMIT;"
- p.save(this.sql, this.sql_file, 0);
- this.finish_import();
- break;
- }
- }
- }
- this.sync_playcount = function(p) {
- if (this.playcount_working == false) return p.console("Import aborted.");
- this.page = p;
- this.get(l.get_url() + "&method=library.gettracks&limit=100&page=" + this.page, function() {
- ps.update_playcount();
- });
- }
- this.update_playcount = function() {
- var artist, title, playcount, data, url;
- data = p.json_parse(ps.xmlhttp.responsetext);
- if (data && data.tracks && data.tracks.track) {
- if (this.page == 1) this.pages = data.tracks["@attr"].totalPages;
- data = data.tracks.track;
- if (typeof data.length == "undefined") data = [data];
- for (i in data) {
- artist = data[i].artist.name;
- title = data[i].name;
- playcount = data[i].playcount;
- if (playcount == 0) {
- this.page = this.pages;
- break;
- }
- p.console(this.r + ": " + artist + " - " + title + " " + playcount);
- url = tfe("$crc32($lower(" + p.fb2k_escape(artist) + p.fb2k_escape(title) + "))", true);
- this.sql += 'INSERT OR REPLACE INTO quicktag(url,subsong,fieldname,value) VALUES("' + url + '","-1","LASTFM_PLAYCOUNT_DB","' + playcount + '");' + "\n";
- this.r++;
- }
- p.console("Playcount: completed page " + this.page + " of " + this.pages);
- } else {
- this.playcount_page_errors++
- }
- if (this.page < this.pages) {
- this.page++;
- this.sync_playcount(this.page);
- } else {
- this.playcount_working = false;
- if (this.sql == "BEGIN TRANSACTION;\n") {
- p.console("Nothing found to import.");
- } else {
- this.sql += "COMMIT;"
- p.save(this.sql, this.sql_file, 0);
- this.finish_import();
- }
- }
- }
- this.finish_import = function() {
- switch(true) {
- case !this.full_import && this.loved_page_errors > 0:
- p.console("Loved track page errors: " + this.loved_page_errors + " (200 records are lost for every page that fails.)");
- break;
- case this.full_import && this.loved_page_errors + this.playcount_page_errors > 0:
- p.console("Loved track page errors: " + this.loved_page_errors + " (200 records are lost for every page that fails.)");
- p.console("Playcount page errors: " + this.playcount_page_errors + " (100 records are lost for every page that fails.)");
- break;
- default:
- p.console("There were no errors reported.");
- break;
- }
- var command = this.cmd_file.sp() + " ";
- command += this.sqlite3_file.sp() + " ";
- command += this.db_file.sp() + " ";
- command += this.sql_file.sp();
- p.run(command);
- }
- this.update_button = function() {
- switch(true) {
- case l.username.length == 0:
- this.n = this.cross_img;
- this.h = this.cross_img;
- this.tooltip = l.username_error;
- this.func = null;
- break;
- case l.sk.length != 32:
- this.n = this.cross_img;
- this.h = this.cross_img;
- this.tooltip = l.password_error;
- this.func = null;
- break;
- case !p.metadb:
- this.n = this.cross_img;
- this.h = this.cross_img;
- this.tooltip = "No selection";
- this.func = null;
- break;
- case !this.check_component:
- this.n = this.cross_img;
- this.h = this.cross_img;
- this.tooltip = this.error_message;
- this.func = null;
- break;
- case this.old_userloved == 1:
- this.n = this.loved_img;
- this.h = this.unloved_img;
- this.tooltip = "Unlove \"" + this.track + "\" by \"" + this.artist + "\".";
- this.func = function() { ps.love_track(); }
- break;
- default:
- this.n = this.unloved_img;
- this.h = this.loved_img;
- this.tooltip = "Love \"" + this.track + "\" by \"" + this.artist + "\".";
- this.func = function() { ps.love_track(); }
- break;
- }
- b.buttons.ps = new button(this.x, this.y, this.size, this.size, {normal: this.n, hover: this.h}, this.func, this.tooltip);
- window.RepaintRect(b.buttons.ps.x, b.buttons.ps.y, this.size, this.size);
- }
- var i;
- this.x = x;
- this.y = y;
- this.size = size;
- this.loved_working = false;
- this.playcount_working = false;
- this.sqlite3_file = p.script_path + "sqlite3.exe";
- this.cmd_file = p.script_path + "lastfm_sql.cmd";
- this.db_file = fb.ProfilePath + "customdb_sqlite.db";
- this.sql_file = p.data_folder + "lastfm.sql";
- this.page = 0;
- this.last_page = 0;
- this.auto_love = window.GetProperty("2k3.playcount_sync_auto_love", false);
- this.auto_love_tf = window.GetProperty("2k3.playcount_sync_auto_love_tf", "");
- this.show_console = window.GetProperty("2k3.playcount_sync_show_console", true);
- this.library = window.GetProperty("2k3.playcount_sync_library", false);
- this.logging = window.GetProperty("2k3.playcount_sync_logging", false);
- this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
- this.cross_img = gdi.Image(p.ip + "misc\\cross2.png");
- this.loved_img = gdi.Image(p.ip + "lastfm\\loved.png");
- this.unloved_img = gdi.Image(p.ip + "lastfm\\unloved.png");
- this.check_component = false;
- this.error_message = "One or more required files are missing. Please follow the readme again.";
- l.need_username = true;
- p.data_folder.create();
- p.settings_folder.create();
- p.selection_mode = 1;
- window.SetTimeout(function() {
- switch(true) {
- case !utils.CheckComponent("foo_customdb", true):
- p.console("foo_customdb is not installed.");
- break;
- case !ps.cmd_file.is_file():
- case !ps.sqlite3_file.is_file():
- case !ps.db_file.is_file():
- p.console(ps.error_message);
- break;
- default:
- ps.check_component = true;
- break;
- }
- if (fb.IsPlaying) ps.playback_new_track();
- else if (p.metadb) p.item_focus_change();
- else ps.update_button();
- }, 500);
- window.SetInterval(function() {
- if (!ps.loved_working && !ps.playcount_working) return;
- if (ps.page != ps.last_page) return ps.last_page = ps.page;
- var temp = ps.page > 1 ? ps.page - 1 : 1;
- ps.xmlhttp.abort();
- if (ps.loved_working ) ps.sync_loved(temp);
- else if (ps.playcount_working) ps.sync_playcount(temp);
- }, 15000);
- }
- function rating(x, y, s) {
- this.draw = function(gr) {
- if (!p.metadb) return;
- for (i = 1; i < 6; i++) {
- this.img = i > (this.hover ? this.lrating : this.rating) ? this.off_img : this.hover && this.rating == this.lrating ? this.cross_img : this.on_img;
- p.draw_image(gr, this.img, this.x + this.s * (i - 1), this.y, this.s, this.s);
- }
- }
- this.metadb_changed = function() {
- if (!p.metadb) return false;
- this.hover = false;
- this.rating = tf("$if2(%rating%,0)", p.metadb);
- this.tiptext = tf(this.tiptext_tf, p.metadb);
- this.lrating = this.rating;
- window.RepaintRect(this.x, this.y, this.w, this.s);
- return true;
- }
- this.trace = function(x, y) {
- return x > this.x && x < this.x + this.w && y > this.y && y < this.y + this.s;
- }
- this.move = function(x, y) {
- if (!this.trace(x, y)) {
- if (this.hover) this.leave();
- return false;
- }
- if (p.metadb) {
- p.tt(this.tiptext);
- this.hover = true;
- this.lrating = Math.ceil((x - this.x) / this.s);
- window.RepaintRect(this.x, this.y, this.w, this.s);
- }
- return true;
- }
- this.lbtn_up = function(x, y) {
- if (!this.trace(x, y)) return false;
- if (p.metadb && this.hover == 1) {
- if (this.check_component) {
- fb.RunContextCommandWithMetadb("Rating/" + (this.lrating == this.rating ? "<not set>" : this.lrating), p.metadb, 8);
- } else {
- if (p.MsgBox("This script requires foo_playcount. Visit the download page now?", 4, p.name) == 6) p.browser("http://www.foobar2000.org/components/view/foo_playcount");
- }
- }
- return true;
- }
- this.leave = function() {
- p.tt("");
- this.hover = false;
- window.RepaintRect(this.x, this.y, this.w, this.s);
- }
- var i;
- this.x = x;
- this.y = y;
- this.s = s;
- this.w = this.s * 5;
- this.hover = false;
- this.rating = null;
- this.lrating = null;
- this.img = null;
- this.off_img = gdi.Image(p.ip + "rating\\rating_grey.png");
- this.on_img = gdi.Image(p.ip + "rating\\rating_gold.png");
- this.cross_img = gdi.Image(p.ip + "misc\\cross2.png");
- this.tiptext_tf = 'Rate "%title%" by "%artist%."';
- this.check_component = utils.CheckComponent("foo_playcount", true);
- }
- function sb(x, y, w, h, img, v, func) {
- this.x = x;
- this.y = y;
- this.w = w;
- this.h = h;
- this.img = img;
- this.v = new Function("return " + v + ";");
- this.func = func;
- this.draw = function(gr) {
- if (this.v()) p.draw_image(gr, this.img, this.x, this.y, this.w, this.h);
- }
- this.trace = function(x, y) {
- return x > this.x && x < this.x + this.w && y > this.y && y < this.y + this.h && this.v();
- }
- this.lbtn_up = function(x, y) {
- if (!this.trace(x, y)) return false;
- this.func && this.func(x, y);
- return true;
- }
- }
- function seekbar(mode, x, y, w, h) {
- this.draw = function(gr) {
- switch(this.mode) {
- case "spectrogram":
- if (this.working) {
- p.draw_image(gr, this.hourglass_img, this.x, this.y + Math.round((this.h - 32) / 2), this.w, 32);
- } else {
- p.draw_image(gr, this.img, this.x, this.y, this.w, this.h, 2);
- }
- if (fb.IsPlaying && fb.PlaybackLength > 0) {
- this.calc_pos();
- gr.FillSolidRect(this.x + this.pos - 2, this.y, 2, this.h, p.splitRGB(this.marker));
- }
- break;
- case "nyan_cat":
- if (fb.IsPlaying && fb.PlaybackLength > 0) {
- this.calc_pos();
- for (i in this.offsets) {
- gr.FillSolidRect(this.x - 48, this.y + this.offsets[i], this.pos + 2, this.heights[i], this.colours[i]);
- }
- p.draw_image(gr, this.cat_img[this.z], this.pos, this.y, 48, 30);
- } else {
- p.draw_image(gr, this.cat_img[0], 0, this.y, 48, 30);
- }
- break;
- }
- }
- this.playback_new_track = function() {
- if (this.mode != "spectrogram") return;
- this.img && this.img.Dispose();
- this.img = null;
- var metadb = fb.GetNowPlaying();
- if (!metadb) return;
- this.png_filename = this.folder + this.sox_params + "_" + tfe("$crc32($lower($substr(%path%,4,$len(%path%))))") + ".png";
- switch(true) {
- case this.png_filename.is_file():
- this.img = gdi.Image(this.png_filename);
- break;
- case metadb.RawPath.indexOf("file") != 0:
- p.console("Skipping... Not a valid file type.");
- break;
- case fb.PlaybackLength == 0:
- p.console("Skipping... Unknown length.");
- break;
- case tfe("$if($or($strcmp(%__cue_embedded%,yes),$strcmp($right(%path%,3),cue)),cue,)") == "cue":
- p.console("Skipping... Cannot support cuesheets.");
- break;
- case tfe("%subsong%") > 0:
- p.console("Skipping... Cannot support tracks with chapters.");
- break;
- case this.library && !fb.IsMetadbInMediaLibrary(metadb):
- p.console("Skipping... Track not in library.");
- break;
- default:
- this.working = true;
- window.Repaint();
- var length = tfe("%length%");
- var cmd = "cmd /c \"\"" + ffmpeg_exe + "\" -i \"" + metadb.Path + "\" -t " + length + " -f sox - | \"" + sox_exe + "\" -p -n " + this.sox_params + " -d " + length + " -r -o \"" + this.png_filename + "\"\"";
- p.run_cmd(cmd, true);
- this.working = false;
- this.img = gdi.Image(this.png_filename);
- break;
- }
- window.Repaint();
- }
- this.playback_stop = function() {
- window.Repaint();
- }
- this.playback_seek = function() {
- this.update();
- }
- this.trace = function(x, y) {
- var m = this.drag ? 200 : 0;
- return x > this.x - m && x < this.x + this.w + m && y > this.y - m && y < this.y + this.h + m;
- }
- this.wheel = function(s) {
- if (!this.trace(p.mx, p.my)) return false;
- switch(true) {
- case !fb.IsPlaying:
- case fb.PlaybackLength == 0:
- break;
- case fb.PlaybackLength < 60:
- fb.PlaybackTime += s * 5;
- break;
- case fb.PlaybackLength < 600:
- fb.PlaybackTime += s * 10;
- break;
- default:
- fb.PlaybackTime += s * 60;
- break;
- }
- p.tt("");
- return true;
- }
- this.move = function(x, y) {
- if (this.trace(x, y)) {
- if (fb.IsPlaying && fb.PlaybackLength > 0) {
- x -= this.x;
- this.drag_seek = x < 0 ? 0 : x > this.w ? 1 : x / this.w;
- if (this.old_x != x || this.old_y != y) {
- this.old_x = x;
- this.old_y = y;
- p.tt(p.format_time(fb.PlaybackLength * this.drag_seek));
- }
- if (this.drag) this.update();
- }
- this.hover = true;
- return true;
- } else {
- if (this.hover) p.tt("");
- this.hover = false;
- this.drag = false;
- return false;
- }
- }
- this.lbtn_down = function(x, y) {
- if (!this.trace(x, y)) return false;
- if (fb.IsPlaying && fb.PlaybackLength > 0) this.drag = true;
- return true;
- }
- this.lbtn_up = function(x, y) {
- if (!this.trace(x, y)) return false;
- if (this.drag) {
- this.drag = false;
- fb.PlaybackTime = fb.PlaybackLength * this.drag_seek;
- }
- return true;
- }
- this.update = function() {
- if (this.mode == "spectrogram") window.RepaintRect(Math.max(this.pos - 60, 0), this.y, 120, this.h);
- else window.RepaintRect(0, this.y, p.w, this.h);
- }
- this.calc_pos = function() {
- this.pos = this.drag ? this.w * this.drag_seek : this.w * (fb.PlaybackTime / fb.PlaybackLength);
- }
- this.init = function() {
- switch(this.mode) {
- case "spectrogram":
- this.clear_images = function(period) {
- var images = this.folder.get_files(["png"]);
- for (i in images) {
- if (this.png_filename == images[i]) continue;
- if (images[i].expired(period)) {
- p.delete_file(images[i]);
- }
- }
- }
- this.library = window.GetProperty("2k3.seekbar_library", false);
- this.marker = window.GetProperty("2k3.seekbar_marker", "240-240-240");
- this.sox_params = window.GetProperty("2k3.seekbar_sox_params", "channels 1 spectrogram -Y 130").trim();
- this.working = false;
- this.img = false;
- this.hourglass_img = gdi.Image(p.ip + "seekbar\\hourglass.png");
- this.folder = p.data_folder + "spectrogram\\";
- p.data_folder.create();
- this.folder.create();
- window.SetTimeout(function() {
- var error = "";
- if (!sox_exe.is_file()) error += "SoX is missing\n";
- if (!ffmpeg_exe.is_file()) error += "ffmpeg is missing\n";
- if (error.length > 0) p.MsgBox(error + "\nPlease check the notes in the panel.", 0, p.name);
- else if (fb.IsPlaying) s.playback_new_track();
- }, 100);
- break;
- case "nyan_cat":
- this.cat_img = [gdi.Image(p.ip + "seekbar\\nyan cat.png"), gdi.Image(p.ip + "seekbar\\nyan cat 2.png")];
- this.offsets = [2, 6, 10, 15, 20, 24];
- this.heights = [4, 4, 5, 5, 4, 4];
- this.colours = [RGB(255, 0, 0), RGB(255, 153, 0), RGB(255, 255, 0), RGB(51, 255, 0), RGB(0, 153, 255), RGB(102, 51, 255)];
- break;
- }
- }
- var i;
- this.mode = mode;
- this.x = x;
- this.y = y;
- this.w = w;
- this.h = h;
- this.z = 0;
- this.pos = 0;
- this.hover = false;
- this.drag = false;
- this.drag_seek = 0;
- this.old_x = 0;
- this.old_y = 0;
- this.init();
- window.SetInterval(function() {
- s.z = s.z == 0 ? 1 : 0;
- if (!fb.IsPlaying || fb.IsPaused || fb.PlaybackLength == 0) return;
- s.update();
- }, 150);
- }
- function text(mode, x, y, w, h) {
- this.size = function() {
- this.rows = Math.floor((this.h - 30) / p.row_height);
- var but_x = this.x + Math.round((this.w - 15) / 2);
- this.up_btn = new sb(but_x, this.y, 15, 15, p.up_img, "t.offset > 0", function() { t.wheel(1); });
- this.down_btn = new sb(but_x, this.y + this.h - 15, 15, 15, p.down_img, "t.offset < t.text_rows - t.rows", function() { t.wheel(-1); });
- this.update();
- }
- this.draw = function(gr) {
- for (i = 0; i < Math.min(this.rows, this.text_rows); i++) {
- if (this.centre) p.centre_text(gr, this.text_array[i + this.offset], this.fixed ? p.fixed_font : p.normal_font, p.textcolour, this.x, 18 + this.y + (i * p.row_height), this.w, p.row_height);
- else p.left_text(gr, this.text_array[i + this.offset], this.fixed ? p.fixed_font : p.normal_font, p.textcolour, this.x, 18 + this.y + (i * p.row_height), this.w, p.row_height);
- }
- this.up_btn.draw(gr);
- this.down_btn.draw(gr);
- }
- this.metadb_changed = function() {
- if (!p.metadb) return false;
- switch(this.mode) {
- case "allmusic":
- var temp_artist = p.eval(this.allmusic_artist_tf);
- var temp_album = p.eval(this.allmusic_album_tf);
- if (this.artist == temp_artist && this.album == temp_album) return false;
- this.artist = temp_artist;
- this.album = temp_album;
- this.filename = p.new_artist_folder(this.artist) + "Allmusic - " + this.album.validate() + ".txt";
- this.text = "";
- if (this.filename.is_file()) {
- this.text = p.open(this.filename);
- } else {
- this.allmusic_url = false;
- this.get();
- }
- break;
- case "lastfm_wiki":
- p.artist = p.eval(p.artist_tf);
- if (this.artist == p.artist) return false;
- this.artist = p.artist;
- this.text = "";
- if (this.biography_lastfm) {
- this.filename = p.new_artist_folder(this.artist) + "bio." + this.biography_lastfm_sites[this.biography_lastfm_site] + ".txt";
- if (this.filename.is_file()) {
- this.text = p.open(this.filename);
- if (this.filename.expired(ONE_DAY)) this.get();
- } else {
- this.get();
- }
- } else {
- this.filename = p.new_artist_folder(this.artist) + "lastm_wiki.json";
- if (this.filename.is_file()) {
- var data = p.json_parse(p.open(this.filename), "response.biographies");
- for (i in data) {
- if (data[i].site == "wikipedia") {
- this.text = data[i].text;
- break;
- }
- }
- this.text = this.text.replace(/\. \n/g, ".\n\n").replace(/\n\n\n/g, "\n\n").replace(/ edit:\n/g , ":\n").replace(/edit:\n/g , ":\n");
- if (this.filename.expired(ONE_DAY)) this.get();
- } else {
- this.get();
- }
- }
- break;
- case "simple_tag":
- this.filename = p.metadb.Path;
- this.text = p.eval(this.tag_tf);
- break;
- case "simple_text":
- this.temp_filename = p.eval(this.filename_tf);
- if (this.filename == this.temp_filename) return false;
- this.filename = this.temp_filename;
- this.text = "";
- var files = [];
- if (this.filename.is_folder()) { //yes really!
- var folder = this.filename + "\\";
- files = folder.get_files(this.exts);
- files.sort();
- this.text = p.open(files[0]);
- } else {
- files = this.filename.split("|");
- for (i in files) {
- files[i] = files[i].trim();
- if (files[i].is_file()) {
- this.text = p.open(files[i]);
- break;
- }
- }
- }
- this.text = this.text.replace(/\t/g, " ");
- break;
- }
- this.update();
- window.Repaint();
- return true;
- }
- this.trace = function(x, y) {
- return x > this.x && x < this.x + this.w && y > this.y && y < this.y + this.h;
- }
- this.wheel = function(s) {
- if (!this.trace(p.mx, p.my)) return false;
- if (this.text_rows > this.rows) {
- this.offset -= s * 3;
- if (this.offset < 0) this.offset = 0;
- if (this.offset + this.rows > this.text_rows) this.offset = this.text_rows - this.rows;
- window.RepaintRect(this.x, this.y, this.w, this.h);
- }
- return true;
- }
- this.move = function(x, y) {
- switch(true) {
- case !this.trace(x, y):
- window.SetCursor(IDC_ARROW);
- return false;
- case this.up_btn.trace(x, y):
- case this.down_btn.trace(x, y):
- window.SetCursor(IDC_HAND);
- break;
- default:
- window.SetCursor(IDC_ARROW);
- break;
- }
- return true;
- }
- this.lbtn_up = function(x, y) {
- if (!this.trace(x, y)) return false;
- this.up_btn.lbtn_up(x, y);
- this.down_btn.lbtn_up(x, y);
- return true;
- }
- this.get = function() {
- var fn = this.filename;
- switch(this.mode) {
- case "allmusic":
- if (this.allmusic_url) {
- var func = function() {
- doc.open();
- var div = doc.createElement("div");
- div.innerHTML = t.xmlhttp.responsetext;
- var data = div.getElementsByTagName("div");
- var text = "";
- for (i in data) {
- if (data[i].itemprop == "reviewBody") {
- text = p.strip_tags(data[i].innerText);
- break;
- }
- }
- doc.close();
- if (text.length > 0) {
- p.console("A review was found and saved.");
- p.save(text, fn);
- t.artist = "";
- p.item_focus_change();
- } else {
- p.console("No review was found on the page for this album.");
- }
- }
- var url = this.allmusic_url;
- this.allmusic_url = false;
- } else {
- var func = function() {
- t.allmusic_get_page(t.xmlhttp.responsetext);
- }
- if (this.artist == "" || this.artist == "?" || this.album == "" || this.album == "?") return;
- var url = "http://www.allmusic.com/search/albums/" + encodeURIComponent(this.album + (this.artist.toLowerCase() == "various artists" ? "" : " " + this.artist));
- }
- break;
- case "lastfm_wiki":
- var func = function() {
- if (t.biography_lastfm) {
- doc.open();
- var div = doc.createElement("div");
- div.innerHTML = t.xmlhttp.responsetext;
- var data = div.getElementsByTagName("div");
- var text = "";
- try {
- for (i in data) {
- if (data[i].id == "wiki") {
- text = p.strip_tags(data[i].innerText);
- break;
- }
- }
- } catch(e) {}
- doc.close();
- p.save(text, fn);
- } else {
- p.save(t.xmlhttp.responsetext, fn);
- }
- t.artist = "";
- p.item_focus_change();
- }
- if (this.artist == "" || this.artist == "?") return;
- if (this.biography_lastfm) var url = "http://" + this.biography_lastfm_sites[this.biography_lastfm_site] + "/music/" + encodeURIComponent(this.artist) + "/+wiki";
- else var url = "http://developer.echonest.com/api/v4/artist/biographies?api_key=EKWS4ESQLKN3G2ZWV&format=json&name=" + encodeURIComponent(this.artist);
- break;
- default:
- return;
- }
- this.xmlhttp.open("GET", url, true);
- this.xmlhttp.send();
- this.xmlhttp.onreadystatechange = function() {
- if (t.xmlhttp.readyState == 4) {
- if (t.xmlhttp.status == 200) {
- func();
- } else {
- p.console(t.xmlhttp.responsetext || "HTTP error: " + t.xmlhttp.status);
- }
- }
- }
- }
- this.update = function() {
- this.offset = 0;
- this.text_rows = 0;
- if (this.w < 100 || this.text.length == 0) return;
- var temp_bmp = gdi.CreateImage(1, 1);
- var temp_gr = temp_bmp.GetGraphics();
- var paragraphs = this.text.split("\n");
- this.text_array = [];
- for (i in paragraphs) {
- if (this.fixed) {
- this.text_array.push(paragraphs[i]);
- } else {
- var lines = temp_gr.EstimateLineWrap(paragraphs[i], p.normal_font, this.w).toArray();
- for (var j = 0; j < lines.length; j += 2) {
- this.text_array.push(lines[j].trim());
- }
- }
- }
- this.text_rows = this.text_array.length;
- temp_bmp.ReleaseGraphics(temp_gr);
- temp_bmp.Dispose();
- temp_gr = null;
- temp_bmp = null;
- }
- this.header_text = function() {
- switch(this.mode) {
- case "allmusic":
- return p.eval("%album artist%[ - %album%]");
- break;
- case "lastfm_wiki":
- return this.artist;
- break;
- case "simple_text":
- case "simple_tag":
- return p.eval(this.title_tf);
- break;
- }
- }
- this.init = function() {
- switch(this.mode) {
- case "allmusic":
- this.allmusic_get_page = function(text) {
- var artist, title, divs, url, temp;
- var ar = this.allmusic_tidy(this.artist);
- var al = this.allmusic_tidy(this.album);
- doc.open();
- var div = doc.createElement("div");
- div.innerHTML = text;
- var data = div.getElementsByTagName("li");
- this.allmusic_url = "";
- for (i in data) {
- if (data[i].className == "album") {
- divs = data[i].getElementsByTagName("div");
- title = "", artist = "";
- for (var j = 0; j < divs.length; j++) {
- if (divs[j].className == "title") {
- title = divs[j].getElementsByTagName("a")[0].innerText;
- url = divs[j].getElementsByTagName("a")[0].href;
- }
- if (divs[j].className == "artist") {
- temp = divs[j].getElementsByTagName("a");
- if (temp.length > 0) artist = temp[0].innerText;
- else artist = "various artists";
- }
- }
- if (ar == this.allmusic_tidy(artist) && al == this.allmusic_tidy(title)) {
- this.allmusic_url = url;
- break;
- }
- }
- }
- doc.close();
- if (this.allmusic_url.length > 0) {
- p.console("A page was found for \"" + this.album + "\". Now checking for review...");
- this.get();
- } else {
- p.console("Could not match artist/album on the Allmusic website.");
- }
- }
- this.allmusic_tidy = function(t) {
- return tfe("$replace($lower($ascii(" + p.fb2k_escape(t) + ")), & ,, and ,)", true);
- }
- this.allmusic_artist_tf = window.GetProperty("2k3.allmusic_artist_tf", "%album artist%");
- this.allmusic_album_tf = window.GetProperty("2k3.allmusic_album_tf", "%album%");
- p.data_folder.create();
- p.artists_folder.create();
- break;
- case "lastfm_wiki":
- this.biography_lastfm_sites = ["www.last.fm", "www.lastfm.de", "www.lastfm.es", "www.lastfm.fr", "www.lastfm.it", "www.lastfm.jp", "www.lastfm.pl", "www.lastfm.com.br", "www.lastfm.ru", "www.lastfm.se", "www.lastfm.tr", "cn.last.fm"];
- this.biography_lastfm_site = window.GetProperty("2k3.biography_lastfm_site", 0);
- this.biography_lastfm = window.GetProperty("2k3.biography_lastfm", true);
- p.data_folder.create();
- p.artists_folder.create();
- break;
- case "simple_text":
- this.title_tf = window.GetProperty("2k3.text_title_tf", "$directory_path(%path%)");
- this.filename_tf = window.GetProperty("2k3.text_filename_tf", "$directory_path(%path%)");
- this.fixed = window.GetProperty("2k3.text_fixed_font", true);
- this.exts = "txt|log";
- break;
- case "simple_tag":
- this.title_tf = window.GetProperty("2k3.text_title_tf", "%title%");
- this.tag_tf = window.GetProperty("2k3.text_tag_tf", "[%lyrics%]");
- this.centre = window.GetProperty("2k3.text_centre", false);
- break;
- }
- }
- var i;
- this.mode = mode;
- this.x = x;
- this.y = y;
- this.w = w;
- this.h = h;
- this.text = "";
- this.artist = "";
- this.album = "";
- this.filename = "";
- this.fixed = false;
- this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
- this.init();
- this.size();
- }
- function thumbs(custom) {
- this.playback_time = function(t) {
- if (this.source == 0 && t == 1 && this.files.length == 0 && p.metadb.RawPath == fb.GetNowPlaying().RawPath && ((this.auto_download == 1 && fb.IsMetadbInMediaLibrary(p.metadb)) || this.auto_download == 2)) this.download();
- }
- this.size = function(f) {
- this.nc = f || this.nc;
- this.offset = 0;
- switch(true) {
- case p.w < this.px || p.h < this.px || this.mode == this.modes.off || this.mode == this.modes.disabled:
- this.nc = true;
- this.img && this.img.Dispose();
- this.img = null;
- break;
- case this.mode == this.modes.grid:
- this.x = 0;
- this.y = 0;
- this.w = p.w;
- this.h = p.h;
- if (!this.nc && this.columns != Math.floor(this.w / this.px)) this.nc = true;
- this.overlay = false;
- this.rows = Math.ceil(this.h / this.px);
- this.columns = Math.floor(this.w / this.px);
- this.img_rows = Math.ceil(this.images.length / this.columns);
- if (this.nc && this.images.length > 0) {
- this.nc = false;
- this.img && this.img.Dispose();
- this.img = null;
- this.img = gdi.CreateImage(Math.min(this.columns, this.images.length) * this.px, this.img_rows * this.px);
- var temp_gr = this.img.GetGraphics();
- temp_gr.SetInterpolationMode(7);
- var ci = 0;
- var row, col;
- for (row = 0; row < this.img_rows; row++) {
- for (col = 0; col < this.columns; col++) {
- if (ci == this.images.length) continue;
- p.draw_image(temp_gr, this.images[ci], col * this.px, row * this.px, this.px, this.px, 1);
- ci++;
- }
- }
- this.img.ReleaseGraphics(temp_gr);
- temp_gr = null;
- }
- break;
- case this.mode == this.modes.left:
- case this.mode == this.modes.right:
- this.x = this.mode == this.modes.left ? 0 : p.w - this.px;
- this.y = 0;
- this.w = this.px;
- this.h = p.h;
- this.rows = Math.ceil(this.h / this.px);
- if (this.nc && this.images.length > 0) {
- this.nc = false;
- this.img && this.img.Dispose();
- this.img = null;
- this.img = gdi.CreateImage(this.px, this.px * this.images.length);
- var temp_gr = this.img.GetGraphics();
- temp_gr.SetInterpolationMode(7);
- for (i in this.images) {
- p.draw_image(temp_gr, this.images[i], 0, i * this.px, this.px, this.px, 1);
- }
- this.img.ReleaseGraphics(temp_gr);
- temp_gr = null;
- }
- break;
- case this.mode == this.modes.top:
- case this.mode == this.modes.bottom:
- this.x = 0;
- this.y = this.mode == this.modes.top ? 0 : p.h - this.px;
- this.w = p.w;
- this.h = this.px;
- this.columns = Math.ceil(this.w / this.px);
- if (this.nc && this.images.length > 0) {
- this.nc = false;
- this.img && this.img.Dispose();
- this.img = null;
- this.img = gdi.CreateImage(this.px * this.images.length, this.px);
- var temp_gr = this.img.GetGraphics();
- temp_gr.SetInterpolationMode(7);
- for (i in this.images) {
- p.draw_image(temp_gr, this.images[i], i * this.px, 0, this.px, this.px, 1);
- }
- this.img.ReleaseGraphics(temp_gr);
- temp_gr = null;
- }
- break;
- }
- }
- this.draw = function(gr) {
- switch(true) {
- case this.images.length == 0:
- break;
- case this.mode == this.modes.disabled:
- case this.mode == this.modes.off:
- p.draw_image(gr, this.images[this.image], 0, 0, p.w, p.h, this.type);
- break;
- case !this.img:
- break;
- case this.mode == this.modes.grid:
- gr.DrawImage(this.img, this.x, this.y, this.w, this.h, 0, this.offset * this.px, this.w, this.h);
- if (this.overlay) {
- gr.FillSolidRect(this.x, this.y, this.w, this.h, RGBA(0, 0, 0, 126));
- p.draw_image(gr, this.images[this.image], 40, 40, p.w - 80, p.h - 80, "centre");
- }
- break;
- case this.mode == this.modes.left:
- var x = this.type == 3 ? this.px : 0;
- p.draw_image(gr, this.images[this.image], x, 0, p.w - x, p.h, this.type);
- gr.FillSolidRect(this.x, this.y, this.px, this.h, RGBA(0, 0, 0, 126));
- gr.DrawImage(this.img, this.x, this.y, this.w, this.h, 0, this.offset * this.px, this.w, this.h);
- break;
- case this.mode == this.modes.right:
- p.draw_image(gr, this.images[this.image], 0, 0, p.w - (this.type == 3 ? this.px : 0), p.h, this.type);
- gr.FillSolidRect(this.x, this.y, this.px, this.h, RGBA(0, 0, 0, 126));
- gr.DrawImage(this.img, this.x, this.y, this.w, this.h, 0, this.offset * this.px, this.w, this.h);
- break;
- case this.mode == this.modes.top:
- var y = this.type == 3 ? this.px : 0;
- p.draw_image(gr, this.images[this.image], 0, y, p.w, p.h - y, this.type);
- gr.FillSolidRect(this.x, this.y, this.w, this.px, RGBA(0, 0, 0, 126));
- gr.DrawImage(this.img, this.x, this.y, this.w, this.h, this.offset * this.px, 0, this.w, this.h);
- break;
- case this.mode == this.modes.bottom:
- p.draw_image(gr, this.images[this.image], 0, 0, p.w, p.h - (this.type == 3 ? this.px : 0), this.type);
- gr.FillSolidRect(this.x, this.y, this.w, this.px, RGBA(0, 0, 0, 126));
- gr.DrawImage(this.img, this.x, this.y, this.w, this.h, this.offset * this.px, 0, this.w, this.h);
- break;
- }
- }
- this.metadb_changed = function() {
- if (!p.metadb) return false;
- switch(this.source) {
- case 0: //last.fm
- p.artist = p.eval(p.artist_tf);
- if (this.artist == p.artist) return false;
- this.artist = p.artist;
- this.folder = p.new_artist_folder(this.artist);
- break;
- case 1: //custom folder
- this.temp_folder = p.eval(this.custom_folder_tf);
- if (this.temp_folder == this.folder) return false;
- this.folder = this.temp_folder;
- break;
- }
- this.update();
- return true;
- }
- this.trace = function(x, y) {
- return x > this.x && x < this.x + this.w && y > this.y && y < this.y + this.h;
- }
- this.wheel = function(s) {
- switch(true) {
- case !this.trace(p.mx, p.my):
- case this.overlay:
- if (this.images.length < 2) return;
- this.image -= s;
- if (this.image < 0) this.image = this.images.length - 1;
- if (this.image >= this.images.length) this.image = 0;
- window.Repaint();
- return;
- case this.mode == this.modes.grid:
- if (this.img_rows < this.rows) return;
- this.offset -= s;
- if (this.offset < 0) this.offset = 0;
- if (this.offset > this.img_rows - this.rows) this.offset = this.img_rows - this.rows + 1;
- break;
- case this.mode == this.modes.left:
- case this.mode == this.modes.right:
- if (this.images.length < this.rows) return;
- this.offset -= s;
- if (this.offset < 0) this.offset = 0;
- if (this.rows + this.offset > this.images.length) this.offset = this.images.length - this.rows + 1;
- break;
- case this.mode == this.modes.top:
- case this.mode == this.modes.bottom:
- if (this.images.length < this.columns) return;
- this.offset -= s;
- if (this.offset < 0) this.offset = 0;
- if (this.columns + this.offset > this.images.length) this.offset = this.images.length - this.columns + 1;
- break;
- }
- window.RepaintRect(this.x, this.y, this.w, this.h);
- }
- this.move = function(x, y) {
- this.index = this.images.length;
- switch(true) {
- case !this.trace(x, y):
- window.SetCursor(IDC_ARROW);
- return;
- case this.overlay:
- window.SetCursor(IDC_HAND);
- return;
- case this.mode == this.modes.grid:
- var temp = Math.floor((x - this.x) / this.px);
- this.index = temp >= this.columns ? this.images.length : temp + (Math.floor((y - this.y) / this.px) * this.columns) + (this.offset * this.columns);
- break;
- case this.mode == this.modes.left:
- case this.mode == this.modes.right:
- this.index = Math.floor((y - this.y) / this.px) + this.offset;
- break;
- case this.mode == this.modes.top:
- case this.mode == this.modes.bottom:
- this.index = Math.floor((x - this.x) / this.px) + this.offset;
- break;
- }
- window.SetCursor(this.index < this.images.length ? IDC_HAND : IDC_ARROW);
- }
- this.lbtn_up = function(x, y) {
- switch(true) {
- case !this.trace(x, y):
- break;
- case this.mode == this.modes.grid && this.overlay:
- this.overlay = false;
- window.Repaint();
- break;
- case this.mode == this.modes.grid && this.index < this.images.length && !this.overlay:
- this.overlay = true;
- this.image = this.index;
- window.Repaint();
- break;
- case this.index < this.images.length:
- this.image = this.index;
- window.Repaint();
- break;
- }
- }
- this.lbtn_dblclk = function(x, y) {
- if (!this.trace(x, y) && this.mode != this.modes.grid && this.images.length > 0) p.run("\"" + this.files[this.image] + "\"");
- }
- this.update = function() {
- this.image = 0;
- for (i in this.images) {
- try { this.images[i].Dispose(); } catch(e) {}
- }
- this.folders = this.folder.split("|");
- this.files = [];
- for (i in this.folders) {
- this.folders[i] = this.folders[i].trim();
- this.files = this.files.concat(this.folders[i].get_files(this.exts));
- }
- if (this.files.length > 1) {
- switch(this.sort) {
- case 0:
- case 1:
- this.files.sort(function(a, b) {
- var time_a = a.last_modified();
- var time_b = b.last_modified();
- if (time_a < time_b) return th.sort == 0 ? 1 : -1;
- if (time_a > time_b) return th.sort == 0 ? -1 : 1;
- return 0;
- });
- break;
- case 2:
- case 3:
- this.files.sort(function(a, b) {
- a = a.toLowerCase();
- b = b.toLowerCase();
- if (a > b) return th.sort == 2 ? 1 : -1;
- if (a < b) return th.sort == 2 ? -1 : 1;
- return 0;
- });
- break;
- }
- if (this.source == 0) {
- var temp_file = utils.ReadINI(this.ini_file, "Defaults", "\"" + this.artist.validate() + "\"");
- if (temp_file.charAt(1) == ":") { //convert absolute path to filename and save it
- temp_file = temp_file.split("\\").pop();
- utils.WriteIni(this.ini_file, "Defaults", "\"" + this.artist.validate() + "\"", "\"" + temp_file + "\"");
- }
- this.default_file = this.folder + temp_file;
- if (this.default_file.is_file()) {
- for (i in this.files) {
- if (this.files[i] == this.default_file) {
- this.files.splice(i, 1);
- this.files.unshift(this.default_file);
- break;
- }
- }
- }
- }
- }
- this.images = [];
- for (i in this.files) {
- this.images[i] = gdi.Image(this.files[i]);
- }
- this.size(true);
- window.Repaint();
- }
- this.set_default = function(t) {
- utils.WriteIni(this.ini_file, "Defaults", "\"" + this.artist.validate() + "\"", "\"" + t + "\"");
- this.update();
- }
- this.delete_image = function() {
- app.Namespace(10).MoveHere(this.files[this.image]);
- this.update();
- }
- this.download = function() {
- if (!this.folder.is_folder() || this.artist == "" || this.artist == "?") return;
- var folder = this.folder;
- var url = this.domain + "/music/" + encodeURIComponent(p.artist) + "/+images";
- this.xmlhttp.open("GET", url, true);
- this.xmlhttp.send();
- this.xmlhttp.onreadystatechange = function() {
- if (th.xmlhttp.readyState == 4) {
- if (th.xmlhttp.status == 200) {
- var text = th.xmlhttp.responsetext;
- doc.open();
- var div = doc.createElement("div");
- div.innerHTML = text;
- var data = div.getElementsByTagName("img");
- var urls = [];
- for (i = 0; i < data.length; i++) {
- if (data[i].src.indexOf("http://userserve-ak.last.fm/serve/126s") == 0) urls.push(data[i].src.replace("126s", th.download_size_replace[th.download_size]));
- }
- for (i = 0; i < Math.min(urls.length, th.limit, 5); i++) {
- p.run_cmd("cscript //nologo \"" + p.script_path + "download.vbs\" \"" + urls[i] + "\" \"" + folder + p.artist.validate() + "_" + urls[i].substring(urls[i].lastIndexOf("/") + 1) + "\"", false);
- }
- doc.close();
- } else {
- p.console("HTTP error: " + th.xmlhttp.status);
- }
- }
- }
- }
- var i;
- this.artist = "";
- this.folder = "";
- this.default_file = "";
- this.files = [];
- this.images = [];
- this.exts = "jpg|jpeg|png|gif";
- this.limit = window.GetProperty("2k3.thumbs_limit", 5);
- this.cycle = window.GetProperty("2k3.thumbs_cycle", 0);
- this.type = window.GetProperty("2k3.thumbs_type", 1);
- this.auto_download = window.GetProperty("2k3.thumbs_auto_download", 0); //0 off 1 library 2 all
- this.download_size = window.GetProperty("2k3.thumbs_download_size", 2); //0 small 1 medium 2 original
- this.download_size_replace = { "0" : 252, "1": 500, "2": "_" };
- this.custom_folder_tf = window.GetProperty("2k3.thumbs_custom_folder_tf", "$directory_path(%path%)");
- this.domain = window.GetProperty("2k3.thumbs_domain", "http://www.last.fm");
- this.modes = { grid: 0, left: 1, right: 2, top: 3, bottom: 4, off: 5, disabled: 6};
- this.mode = window.GetProperty("2k3.thumbs_mode", this.modes.bottom);
- this.px = window.GetProperty("2k3.thumbs_px", 75);
- this.sort = window.GetProperty("2k3.thumbs_sort", 0); //0 newest first 1 oldest first 2 a-z 3 z-a
- if (custom == "custom") {
- this.source = 2;
- } else {
- this.source = window.GetProperty("2k3.thumbs_source", 0); //0 last.fm 1 custom folder
- }
- p.data_folder.create();
- p.artists_folder.create();
- p.settings_folder.create();
- this.ini_file = p.settings_folder + "thumbs.ini";
- this.img = null;
- this.nc = false;
- this.image = 0;
- this.index = 0;
- this.time = 0;
- this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
- window.SetInterval(function() {
- th.time++;
- if (th.cycle > 0 && th.images.length > 1 && th.time % th.cycle == 0) {
- th.image++;
- if (th.image == th.images.length) th.image = 0;
- window.Repaint();
- }
- if (th.source != 1 && th.time % 3 == 0 && th.folder.get_files(th.exts).length != th.files.length) th.update();
- }, 1000);
- }
- function volume(x, y, w, h) {
- this.volume_change = function(val) {
- window.RepaintRect(this.x, this.y, this.w, this.h);
- }
- this.trace = function(x, y) {
- var m = this.drag ? 200 : 0;
- return x > this.x - m && x < this.x + this.w + m && y > this.y - m && y < this.y + this.h + m;
- }
- this.wheel = function(s) {
- if (!this.trace(p.mx, p.my)) return false;
- p.tt("");
- fb.Volume += s;
- return true;
- }
- this.move = function(x, y) {
- if (this.trace(x, y)) {
- x -= this.x;
- var pos = x < 0 ? 0 : x > this.w ? 1 : x / this.w;
- this.drag_vol = 50 * Math.log(0.99 * pos + 0.01) / Math.LN10;
- p.tt(this.drag_vol.toFixed(2) + " dB");
- if (this.drag) fb.Volume = this.drag_vol;
- this.hover = true;
- return true;
- } else {
- if (this.hover) p.tt("");
- this.hover = false;
- this.drag = false;
- return false;
- }
- }
- this.lbtn_down = function(x, y) {
- if (!this.trace(x, y)) return false;
- this.drag = true;
- return true;
- }
- this.lbtn_up = function(x, y) {
- if (!this.trace(x, y)) return false;
- this.drag = false;
- return true;
- }
- this.calc_pos = function() {
- this.pos = this.w * (Math.pow(10, fb.Volume / 50) - 0.01) / 0.99;
- }
- this.x = x;
- this.y = y;
- this.w = w;
- this.h = h;
- this.pos = 0;
- this.hover = false;
- this.drag = false;
- this.drag_vol = 0;
- }
- /*
- * A JavaScript implementation of the RSA Data Security, Inc. MD5 Message
- * Digest Algorithm, as defined in RFC 1321.
- * Version 2.2 Copyright (C) Paul Johnston 1999 - 2009
- * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
- * Distributed under the BSD License
- * See http://pajhome.org.uk/crypt/md5 for more info.
- */
- var hexcase=0;function hex_md5(a){return rstr2hex(rstr_md5(str2rstr_utf8(a)))}
- function hex_hmac_md5(a,b){return rstr2hex(rstr_hmac_md5(str2rstr_utf8(a),str2rstr_utf8(b)))}
- function md5_vm_test(){return hex_md5("abc").toLowerCase()=="900150983cd24fb0d6963f7d28e17f72"}
- function rstr_md5(a){return binl2rstr(binl_md5(rstr2binl(a),a.length*8))}
- function rstr_hmac_md5(c,f){var e=rstr2binl(c);if(e.length>16){e=binl_md5(e,c.length*8)}
- var a=Array(16),d=Array(16);for(var b=0;b<16;b++){a[b]=e[b]^909522486;d[b]=e[b]^1549556828}
- var g=binl_md5(a.concat(rstr2binl(f)),512+f.length*8);return binl2rstr(binl_md5(d.concat(g),512+128))}
- function rstr2hex(c){try{hexcase}catch(g){hexcase=0}
- var f=hexcase?"0123456789ABCDEF":"0123456789abcdef";var b="";var a;for(var d=0;d<c.length;d++){a=c.charCodeAt(d);b+=f.charAt((a>>>4)&15)+f.charAt(a&15)}
- return b}
- function str2rstr_utf8(c){var b="";var d=-1;var a,e;while(++d<c.length){a=c.charCodeAt(d);e=d+1<c.length?c.charCodeAt(d+1):0;if(55296<=a&&a<=56319&&56320<=e&&e<=57343){a=65536+((a&1023)<<10)+(e&1023);d++}
- if(a<=127){b+=String.fromCharCode(a)}else{if(a<=2047){b+=String.fromCharCode(192|((a>>>6)&31),128|(a&63))}else{if(a<=65535){b+=String.fromCharCode(224|((a>>>12)&15),128|((a>>>6)&63),128|(a&63))}else{if(a<=2097151){b+=String.fromCharCode(240|((a>>>18)&7),128|((a>>>12)&63),128|((a>>>6)&63),128|(a&63))}}}}}
- return b}
- function rstr2binl(b){var a=Array(b.length>>2);for(var c=0;c<a.length;c++){a[c]=0}
- for(var c=0;c<b.length*8;c+=8){a[c>>5]|=(b.charCodeAt(c/8)&255)<<(c%32)}
- return a}
- function binl2rstr(b){var a="";for(var c=0;c<b.length*32;c+=8){a+=String.fromCharCode((b[c>>5]>>>(c%32))&255)}
- return a}
- function binl_md5(p,k){p[k>>5]|=128<<((k)%32);p[(((k+64)>>>9)<<4)+14]=k;var o=1732584193;var n=-271733879;var m=-1732584194;var l=271733878;for(var g=0;g<p.length;g+=16){var j=o;var h=n;var f=m;var e=l;o=md5_ff(o,n,m,l,p[g+0],7,-680876936);l=md5_ff(l,o,n,m,p[g+1],12,-389564586);m=md5_ff(m,l,o,n,p[g+2],17,606105819);n=md5_ff(n,m,l,o,p[g+3],22,-1044525330);o=md5_ff(o,n,m,l,p[g+4],7,-176418897);l=md5_ff(l,o,n,m,p[g+5],12,1200080426);m=md5_ff(m,l,o,n,p[g+6],17,-1473231341);n=md5_ff(n,m,l,o,p[g+7],22,-45705983);o=md5_ff(o,n,m,l,p[g+8],7,1770035416);l=md5_ff(l,o,n,m,p[g+9],12,-1958414417);m=md5_ff(m,l,o,n,p[g+10],17,-42063);n=md5_ff(n,m,l,o,p[g+11],22,-1990404162);o=md5_ff(o,n,m,l,p[g+12],7,1804603682);l=md5_ff(l,o,n,m,p[g+13],12,-40341101);m=md5_ff(m,l,o,n,p[g+14],17,-1502002290);n=md5_ff(n,m,l,o,p[g+15],22,1236535329);o=md5_gg(o,n,m,l,p[g+1],5,-165796510);l=md5_gg(l,o,n,m,p[g+6],9,-1069501632);m=md5_gg(m,l,o,n,p[g+11],14,643717713);n=md5_gg(n,m,l,o,p[g+0],20,-373897302);o=md5_gg(o,n,m,l,p[g+5],5,-701558691);l=md5_gg(l,o,n,m,p[g+10],9,38016083);m=md5_gg(m,l,o,n,p[g+15],14,-660478335);n=md5_gg(n,m,l,o,p[g+4],20,-405537848);o=md5_gg(o,n,m,l,p[g+9],5,568446438);l=md5_gg(l,o,n,m,p[g+14],9,-1019803690);m=md5_gg(m,l,o,n,p[g+3],14,-187363961);n=md5_gg(n,m,l,o,p[g+8],20,1163531501);o=md5_gg(o,n,m,l,p[g+13],5,-1444681467);l=md5_gg(l,o,n,m,p[g+2],9,-51403784);m=md5_gg(m,l,o,n,p[g+7],14,1735328473);n=md5_gg(n,m,l,o,p[g+12],20,-1926607734);o=md5_hh(o,n,m,l,p[g+5],4,-378558);l=md5_hh(l,o,n,m,p[g+8],11,-2022574463);m=md5_hh(m,l,o,n,p[g+11],16,1839030562);n=md5_hh(n,m,l,o,p[g+14],23,-35309556);o=md5_hh(o,n,m,l,p[g+1],4,-1530992060);l=md5_hh(l,o,n,m,p[g+4],11,1272893353);m=md5_hh(m,l,o,n,p[g+7],16,-155497632);n=md5_hh(n,m,l,o,p[g+10],23,-1094730640);o=md5_hh(o,n,m,l,p[g+13],4,681279174);l=md5_hh(l,o,n,m,p[g+0],11,-358537222);m=md5_hh(m,l,o,n,p[g+3],16,-722521979);n=md5_hh(n,m,l,o,p[g+6],23,76029189);o=md5_hh(o,n,m,l,p[g+9],4,-640364487);l=md5_hh(l,o,n,m,p[g+12],11,-421815835);m=md5_hh(m,l,o,n,p[g+15],16,530742520);n=md5_hh(n,m,l,o,p[g+2],23,-995338651);o=md5_ii(o,n,m,l,p[g+0],6,-198630844);l=md5_ii(l,o,n,m,p[g+7],10,1126891415);m=md5_ii(m,l,o,n,p[g+14],15,-1416354905);n=md5_ii(n,m,l,o,p[g+5],21,-57434055);o=md5_ii(o,n,m,l,p[g+12],6,1700485571);l=md5_ii(l,o,n,m,p[g+3],10,-1894986606);m=md5_ii(m,l,o,n,p[g+10],15,-1051523);n=md5_ii(n,m,l,o,p[g+1],21,-2054922799);o=md5_ii(o,n,m,l,p[g+8],6,1873313359);l=md5_ii(l,o,n,m,p[g+15],10,-30611744);m=md5_ii(m,l,o,n,p[g+6],15,-1560198380);n=md5_ii(n,m,l,o,p[g+13],21,1309151649);o=md5_ii(o,n,m,l,p[g+4],6,-145523070);l=md5_ii(l,o,n,m,p[g+11],10,-1120210379);m=md5_ii(m,l,o,n,p[g+2],15,718787259);n=md5_ii(n,m,l,o,p[g+9],21,-343485551);o=safe_add(o,j);n=safe_add(n,h);m=safe_add(m,f);l=safe_add(l,e)}
- return Array(o,n,m,l)}
- function md5_cmn(h,e,d,c,g,f){return safe_add(bit_rol(safe_add(safe_add(e,h),safe_add(c,f)),g),d)}
- function md5_ff(g,f,k,j,e,i,h){return md5_cmn((f&k)|((~f)&j),g,f,e,i,h)}
- function md5_gg(g,f,k,j,e,i,h){return md5_cmn((f&j)|(k&(~j)),g,f,e,i,h)}
- function md5_hh(g,f,k,j,e,i,h){return md5_cmn(f^k^j,g,f,e,i,h)}
- function md5_ii(g,f,k,j,e,i,h){return md5_cmn(k^(f|(~j)),g,f,e,i,h)}
- function safe_add(a,d){var c=(a&65535)+(d&65535);var b=(a>>16)+(d>>16)+(c>>16);return(b<<16)|(c&65535)}
- function bit_rol(a,b){return(a<<b)|(a>>>(32-b))}
- function md5(a){return hex_md5(a)}
- //https://github.com/douglascrockford/JSON-js/blob/master/json2.js
- if(typeof JSON!=='object'){JSON={};}
- (function(){'use strict';function f(n){return n<10?'0'+n:n;}
- if(typeof Date.prototype.toJSON!=='function'){Date.prototype.toJSON=function(){return isFinite(this.valueOf())?this.getUTCFullYear()+'-'+
- f(this.getUTCMonth()+1)+'-'+
- f(this.getUTCDate())+'T'+
- f(this.getUTCHours())+':'+
- f(this.getUTCMinutes())+':'+
- f(this.getUTCSeconds())+'Z':null;};String.prototype.toJSON=Number.prototype.toJSON=Boolean.prototype.toJSON=function(){return this.valueOf();};}
- var cx,escapable,gap,indent,meta,rep;function quote(string){escapable.lastIndex=0;return escapable.test(string)?'"'+string.replace(escapable,function(a){var c=meta[a];return typeof c==='string'?c:'\\u'+('0000'+a.charCodeAt(0).toString(16)).slice(-4);})+'"':'"'+string+'"';}
- function str(key,holder){var i,k,v,length,mind=gap,partial,value=holder[key];if(value&&typeof value==='object'&&typeof value.toJSON==='function'){value=value.toJSON(key);}
- if(typeof rep==='function'){value=rep.call(holder,key,value);}
- switch(typeof value){case'string':return quote(value);case'number':return isFinite(value)?String(value):'null';case'boolean':case'null':return String(value);case'object':if(!value){return'null';}
- gap+=indent;partial=[];if(Object.prototype.toString.apply(value)==='[object Array]'){length=value.length;for(i=0;i<length;i+=1){partial[i]=str(i,value)||'null';}
- v=partial.length===0?'[]':gap?'[\n'+gap+partial.join(',\n'+gap)+'\n'+mind+']':'['+partial.join(',')+']';gap=mind;return v;}
- if(rep&&typeof rep==='object'){length=rep.length;for(i=0;i<length;i+=1){if(typeof rep[i]==='string'){k=rep[i];v=str(k,value);if(v){partial.push(quote(k)+(gap?': ':':')+v);}}}}else{for(k in value){if(Object.prototype.hasOwnProperty.call(value,k)){v=str(k,value);if(v){partial.push(quote(k)+(gap?': ':':')+v);}}}}
- v=partial.length===0?'{}':gap?'{\n'+gap+partial.join(',\n'+gap)+'\n'+mind+'}':'{'+partial.join(',')+'}';gap=mind;return v;}}
- if(typeof JSON.stringify!=='function'){escapable=/[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g;meta={'\b':'\\b','\t':'\\t','\n':'\\n','\f':'\\f','\r':'\\r','"':'\\"','\\':'\\\\'};JSON.stringify=function(value,replacer,space){var i;gap='';indent='';if(typeof space==='number'){for(i=0;i<space;i+=1){indent+=' ';}}else if(typeof space==='string'){indent=space;}
- rep=replacer;if(replacer&&typeof replacer!=='function'&&(typeof replacer!=='object'||typeof replacer.length!=='number')){throw new Error('JSON.stringify');}
- return str('',{'':value});};}
- if(typeof JSON.parse!=='function'){cx=/[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g;JSON.parse=function(text,reviver){var j;function walk(holder,key){var k,v,value=holder[key];if(value&&typeof value==='object'){for(k in value){if(Object.prototype.hasOwnProperty.call(value,k)){v=walk(value,k);if(v!==undefined){value[k]=v;}else{delete value[k];}}}}
- return reviver.call(holder,key,value);}
- text=String(text);cx.lastIndex=0;if(cx.test(text)){text=text.replace(cx,function(a){return'\\u'+
- ('0000'+a.charCodeAt(0).toString(16)).slice(-4);});}
- if(/^[\],:{}\s]*$/.test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g,'@').replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,']').replace(/(?:^|:|,)(?:\s*\[)+/g,''))){j=eval('('+text+')');return typeof reviver==='function'?walk({'':j},''):j;}
- throw new SyntaxError('JSON.parse');};}}());
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement