Advertisement
Guest User

common8.js

a guest
Sep 20th, 2017
299
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 148.66 KB | None | 0 0
  1. var VERSION = "8.2014-12-20.03";
  2.  
  3. /*
  4. (c) 2010-2014 marc2003
  5. Please do not distribute modified versions of this file with your own scripts or themes.
  6. You should be able to customise pretty much anything you want by editing the script
  7. in your panel, not in this file. Leaving this intact and in its correct location
  8. means you/other people can get bug fixes by using the "Update script" option on the
  9. right click menu. If you need any help with customising then just come and ask on
  10. hydrogenaudio.
  11.  
  12. http://www.hydrogenaud.io/forums/index.php?showtopic=77883
  13. */
  14.  
  15. var DT_LEFT = 0x00000000;
  16. var DT_CENTER = 0x00000001;
  17. var DT_RIGHT = 0x00000002;
  18. var DT_VCENTER = 0x00000004;
  19. var DT_WORDBREAK = 0x00000010;
  20. var DT_CALCRECT = 0x00000400;
  21. var DT_NOPREFIX = 0x00000800;
  22. var DT_END_ELLIPSIS = 0x00008000;
  23.  
  24. var MF_GRAYED = 0x00000001;
  25. var MF_STRING = 0x00000000;
  26.  
  27. var IDC_ARROW = 32512;
  28. var IDC_HAND = 32649;
  29.  
  30. var ONE_DAY = 86400000;
  31. var ONE_WEEK = 604800000;
  32.  
  33. var TPM_RIGHTALIGN = 0x0008;
  34.  
  35. try {
  36. var doc = new ActiveXObject("htmlfile");
  37. var app = new ActiveXObject("Shell.Application");
  38. var WshShell = new ActiveXObject("WScript.Shell");
  39. var fso = new ActiveXObject("Scripting.FileSystemObject");
  40. var vb = new ActiveXObject("ScriptControl");
  41. vb.Language = "VBScript";
  42. } catch(e) {
  43. fb.ShowPopupMessage("Failed to load required system components. Please check \"Safe mode\" has been turned off.\n\nFile>Preferences>Tools>WSH Panel Mod");
  44. }
  45.  
  46. String.prototype.addCommas = function() {
  47. return this.replace(/\B(?=(\d{3})+(?!\d))/g, ",");
  48. }
  49.  
  50. String.prototype.trim = function() {
  51. return this.replace(/^\s+|\s+$/g, "");
  52. }
  53.  
  54. String.prototype.ucfirst = function() {
  55. return this.charAt(0).toUpperCase() + this.substr(1);
  56. }
  57.  
  58. String.prototype.sp = function() {
  59. if (this.is_file()) {
  60. return fso.GetFile(this).ShortPath;
  61. } else {
  62. p.console("File not found: " + this);
  63. return this;
  64. }
  65. }
  66.  
  67. String.prototype.last_modified = function() {
  68. return Date.parse(fso.Getfile(this).DateLastModified);
  69. }
  70.  
  71. String.prototype.is_file = function() {
  72. return fso.FileExists(this);
  73. }
  74.  
  75. String.prototype.is_folder = function() {
  76. return fso.FolderExists(this);
  77. }
  78.  
  79. String.prototype.create = function() {
  80. if (!this.is_folder()) fso.CreateFolder(this);
  81. }
  82.  
  83. String.prototype.get_files = function(exts) {
  84. var files = [];
  85. if (this.is_folder()) {
  86. var f, fi, path, ext;
  87. f = fso.GetFolder(this);
  88. fi = new Enumerator(f.files);
  89. for (; !fi.atEnd(); fi.moveNext()) {
  90. path = fi.item().path;
  91. ext = path.split(".").pop().toLowerCase();
  92. if (exts.toLowerCase().indexOf(ext) > -1) files.push(path);
  93. }
  94. }
  95. return files;
  96. }
  97.  
  98. String.prototype.expired = function(p) {
  99. return Date.parse(Date()) - this.last_modified() > p;
  100. }
  101.  
  102. String.prototype.validate = function() {
  103. return this.replace(/[\/\\|:]/g, '-').replace(/\*/g, 'x').replace(/"/g, "''").replace(/[<>]/g, '_').replace(/\?/g, "");
  104. }
  105.  
  106. function tf(t, metadb) {
  107. return metadb ? fb.TitleFormat(t).EvalWithMetadb(metadb).trim() : "";
  108. }
  109.  
  110. function tfe(t, f) {
  111. return fb.TitleFormat(t).Eval(f).trim();
  112. }
  113.  
  114. function RGB(r, g, b) {
  115. return 0xff000000 | r << 16 | g << 8 | b;
  116. }
  117.  
  118. function RGBA(r, g, b, a) {
  119. return a << 24 | r << 16 | g << 8 | b;
  120. }
  121.  
  122. function toRGB(c) {
  123. return [c >> 16, c >> 8 & 0xFF, c & 0xFF];
  124. }
  125.  
  126. function blend_colours(c1, c2, f) {
  127. c1 = toRGB(c1);
  128. c2 = toRGB(c2);
  129. var r = Math.round(c1[0] + f * (c2[0] - c1[0]));
  130. var g = Math.round(c1[1] + f * (c2[1] - c1[1]));
  131. var b = Math.round(c1[2] + f * (c2[2] - c1[2]));
  132. return RGB(r, g, b);
  133. }
  134.  
  135. function on_colors_changed() {
  136. p.colours_changed();
  137. }
  138.  
  139. function on_font_changed() {
  140. p.font_changed();
  141. }
  142.  
  143. function on_selection_changed() {
  144. p.item_focus_change();
  145. }
  146.  
  147. function on_playlist_switch() {
  148. p.item_focus_change();
  149. }
  150.  
  151. function on_playback_new_track() {
  152. p.item_focus_change();
  153. }
  154.  
  155. function on_playback_dynamic_info_track() {
  156. p.item_focus_change();
  157. }
  158.  
  159. function on_playback_stop() {
  160. p.item_focus_change();
  161. }
  162.  
  163. function on_item_focus_change() {
  164. p.item_focus_change();
  165. }
  166.  
  167. function on_mouse_leave() {
  168. if (typeof p.menu_btn == "object") p.menu_btn.leave();
  169. if (typeof b == "object") b.leave();
  170. if (typeof r == "object") r.leave();
  171. if (typeof li == "object") li.leave();
  172. p.tt("");
  173. }
  174.  
  175. function on_mouse_rbtn_up(x, y) {
  176. p.rbtn_up(x, y);
  177. return true;
  178. }
  179.  
  180. function on_notify_data(name, data) {
  181. if (name == "lastfm" && data == "update" && typeof l == "object") l.notify_data();
  182. if (name == "autoplaylists" && data == "update" && typeof li == "object" && li.mode == "autoplaylists") li.update();
  183. if (name == "love" && typeof ps == "object") l.post(tf("%LASTFM_LOVED_DB%", data) == 1 ? "track.unlove" : "track.love", data);
  184. }
  185.  
  186. function panel(name, features) {
  187. this.item_focus_change = function() {
  188. if (!this.metadb_func) return;
  189. switch(true) {
  190. case typeof ps == "object":
  191. case this.selection_mode == 1:
  192. this.metadb = fb.IsPlaying ? fb.GetNowPlaying() : fb.GetFocusItem();
  193. break;
  194. case this.selection_mode == 0:
  195. this.metadb = fb.GetSelection();
  196. break;
  197. case this.selection_mode == 2:
  198. this.metadb = fb.GetFocusItem();
  199. break;
  200. }
  201. if (this.metadb) on_metadb_changed();
  202. }
  203.  
  204. this.colours_changed = function() {
  205. if (this.is_dui) {
  206. this.textcolour = window.GetColorDUI(0);
  207. this.backcolour = window.GetColorDUI(1);
  208. this.textcolour_hl = window.GetColorDUI(2);
  209. } else {
  210. this.textcolour = window.GetColorCUI(0);
  211. this.backcolour = window.GetColorCUI(3);
  212. this.textcolour_hl = blend_colours(this.textcolour, this.backcolour, 0.4);
  213. }
  214. window.Repaint();
  215. }
  216.  
  217. this.font_changed = function() {
  218. this.font = this.is_dui ? window.GetFontDUI(0) : window.GetFontCUI(0);
  219. try {
  220. this.font_name = this.font.Name;
  221. } catch(e) {
  222. this.console("Unable to use your default font. Using Segoe UI instead.");
  223. this.font_name = "Segoe UI";
  224. }
  225. this.title_font = gdi.Font(this.font_name, 16, 1);
  226. this.normal_font = gdi.Font(this.font_name, this.normal_font_size);
  227. this.list_font = gdi.Font(this.font_name, this.list_font_size);
  228. this.fixed_font = gdi.Font("Lucida Console", this.normal_font_size);
  229. this.row_height = this.normal_font.Height + 2;
  230. if (typeof t == "object") t.size();
  231. if (typeof li == "object") {
  232. switch(li.mode) {
  233. case "lastfm_charts":
  234. case "autoplaylists":
  235. li.update();
  236. break;
  237. default:
  238. li.artist = "";
  239. this.item_focus_change();
  240. break;
  241. }
  242. }
  243. window.Repaint();
  244. }
  245.  
  246. this.size = function() {
  247. this.w = window.Width;
  248. this.h = window.Height;
  249. }
  250.  
  251. this.move = function(x, y) {
  252. if (typeof this.menu_btn == "object" && !this.hover) {
  253. this.hover = true;
  254. window.RepaintRect(this.menu_btn.x, this.menu_btn.y, this.menu_btn.w, this.menu_btn.h);
  255. }
  256. this.mx = x;
  257. this.my = y;
  258. }
  259.  
  260. this.rbtn_up = function(x, y) {
  261. var _menu = window.CreatePopupMenu();
  262. var _custom_background = window.CreatePopupMenu();
  263. var _metadb = window.CreatePopupMenu();
  264. var _cover = window.CreatePopupMenu();
  265. var _font = window.CreatePopupMenu();
  266. var _sub1 = window.CreatePopupMenu();
  267. var _sub2 = window.CreatePopupMenu();
  268. var _sub3 = window.CreatePopupMenu();
  269. var _sub4 = window.CreatePopupMenu();
  270. var _sub5 = window.CreatePopupMenu();
  271. var _sub6 = window.CreatePopupMenu();
  272. var _sub7 = window.CreatePopupMenu();
  273. switch(true) {
  274. case typeof a == "object" && a.trace(x, y):
  275. _menu.AppendMenuItem(MF_STRING, 100, "Refresh");
  276. _menu.AppendMenuSeparator();
  277. _menu.AppendMenuItem(MF_STRING, 101, "Front");
  278. _menu.AppendMenuItem(MF_STRING, 102, "Back");
  279. _menu.AppendMenuItem(MF_STRING, 103, "Disc");
  280. _menu.AppendMenuItem(MF_STRING, 104, "Icon");
  281. _menu.AppendMenuItem(MF_STRING, 105, "Artist");
  282. _menu.CheckMenuRadioItem(101, 105, a.id + 101);
  283. _menu.AppendMenuSeparator();
  284. _menu.AppendMenuItem(MF_STRING, 110, "Crop (focus on centre)");
  285. _menu.AppendMenuItem(MF_STRING, 111, "Crop (focus on top)");
  286. _menu.AppendMenuItem(MF_STRING, 112, "Stretch");
  287. _menu.AppendMenuItem(MF_STRING, 113, "Centre");
  288. _menu.CheckMenuRadioItem(110, 113, a.type + 110);
  289. _menu.AppendMenuSeparator();
  290. _cover.AppendMenuItem(this.metadb ? MF_STRING : MF_GRAYED, 120, "Google images (launches browser)");
  291. _cover.AppendMenuItem(this.metadb ? MF_STRING : MF_GRAYED, 121, "Album Art Downloader");
  292. _cover.AppendMenuSeparator();
  293. _cover.AppendMenuItem(MF_STRING, 122, "Help");
  294. _cover.AppendTo(_menu, MF_STRING, "Cover search");
  295. _menu.AppendMenuSeparator();
  296. _sub1.AppendMenuItem(MF_STRING, 123, "Opens image");
  297. _sub1.AppendMenuItem(MF_STRING, 124, "Opens containing folder");
  298. _sub1.CheckMenuRadioItem(123, 124, a.dblclk == 0 ? 123 : 124);
  299. _sub1.AppendTo(_menu, MF_STRING, "Double click");
  300. _menu.AppendMenuSeparator();
  301. break;
  302. case typeof c == "object" && c.trace(x, y):
  303. _menu.AppendMenuItem(MF_STRING, 100, "Refresh");
  304. _menu.AppendMenuSeparator();
  305. _menu.AppendMenuItem(MF_STRING, 130, "Gloss effect");
  306. _menu.CheckMenuItem(130, c.gloss);
  307. _menu.AppendMenuItem(MF_STRING, 131, "Shadow effect");
  308. _menu.CheckMenuItem(131, c.shadow);
  309. _menu.AppendMenuSeparator();
  310. _cover.AppendMenuItem(this.metadb ? MF_STRING : MF_GRAYED, 120, "Google images (launches browser)");
  311. _cover.AppendMenuItem(this.metadb ? MF_STRING : MF_GRAYED, 121, "Album Art Downloader");
  312. _cover.AppendMenuSeparator();
  313. _cover.AppendMenuItem(MF_STRING, 122, "Help");
  314. _cover.AppendTo(_menu, MF_STRING, "Cover search");
  315. _menu.AppendMenuSeparator();
  316. _sub1.AppendMenuItem(MF_STRING, 125, "Opens image");
  317. _sub1.AppendMenuItem(MF_STRING, 126, "Opens containing folder");
  318. _sub1.CheckMenuRadioItem(125, 126, c.dblclk == 0 ? 125 : 126);
  319. _sub1.AppendTo(_menu, MF_STRING, "Double click");
  320. _menu.AppendMenuSeparator();
  321. break;
  322. case typeof li == "object" && li.trace(x, y):
  323. switch(li.mode) {
  324. case "autoplaylists":
  325. _menu.AppendMenuItem(MF_STRING, 240, "Add new autoplaylist...");
  326. _menu.AppendMenuSeparator();
  327. _menu.AppendMenuItem(MF_STRING, 200, "Change title...");
  328. _menu.AppendMenuSeparator();
  329. for (i = 1; i < 9; i++) {
  330. _sub1.AppendMenuItem(MF_STRING, i + 200, i);
  331. }
  332. _sub1.AppendTo(_menu, MF_STRING, "Save slot");
  333. _sub1.CheckMenuRadioItem(201, 208, li.autoplaylists_slot + 200);
  334. _menu.AppendMenuSeparator();
  335. _sub2.AppendMenuItem(MF_STRING, 210, "run query");
  336. _sub2.AppendMenuItem(MF_STRING, 211, "do nothing");
  337. _sub2.CheckMenuRadioItem(210, 211, li.autoplaylists_success ? 210 : 211);
  338. _sub2.AppendTo(_menu, MF_STRING, "On successful creation/edit");
  339. for (i = 0; i < li.autoplaylists_deleted_items.length; i++) {
  340. var temp = li.autoplaylists_deleted_items[i].split("¬");
  341. _sub3.AppendMenuItem(MF_STRING, i + 220, temp[0]);
  342. }
  343. if (li.autoplaylists_deleted_items.length > 0) _sub3.AppendTo(_menu, MF_STRING, "Restore");
  344. _menu.AppendMenuSeparator();
  345. _menu.AppendMenuItem(MF_STRING, 230, "Replace exisiting playlists with the same name");
  346. _menu.CheckMenuItem(230, li.autoplaylists_remove_duplicates);
  347. _menu.AppendMenuSeparator();
  348. break;
  349. case "echonest":
  350. for (i = 0; i < li.echonest_modes.length; i++) {
  351. _menu.AppendMenuItem(MF_STRING, i + 290, li.echonest_modes[i].ucfirst());
  352. }
  353. _menu.CheckMenuRadioItem(290, 292, li.echonest_mode + 290);
  354. _menu.AppendMenuSeparator();
  355. break;
  356. case "lastfm":
  357. for (i = 0; i < li.lastfm_modes.length; i++) {
  358. _menu.AppendMenuItem(MF_STRING, 300 + i, li.lastfm_modes[i].ucfirst());
  359. }
  360. _menu.CheckMenuRadioItem(300, 304, li.lastfm_mode + 300);
  361. _menu.AppendMenuSeparator();
  362. if (li.lastfm_mode != 2) {
  363. _sub1.AppendMenuItem(MF_STRING, 310, "Last.fm");
  364. _sub1.AppendMenuItem(MF_STRING, 311, "Autoplaylist");
  365. _sub1.CheckMenuRadioItem(310, 311, li.lastfm_link ? 310 : 311);
  366. _sub1.AppendTo(_menu, MF_STRING, "Links");
  367. _menu.AppendMenuSeparator();
  368. }
  369. _menu.AppendMenuItem(MF_STRING, 320, "Last.fm auto-correct");
  370. _menu.CheckMenuItem(320, l.auto_correct);
  371. _menu.AppendMenuSeparator();
  372. break;
  373. case "lastfm_charts":
  374. for (i = 0; i < li.lastfm_charts_modes.length; i++) {
  375. _menu.AppendMenuItem(MF_STRING, i + 350, li.lastfm_charts_modes[i].ucfirst());
  376. }
  377. _menu.CheckMenuRadioItem(350, 352, li.lastfm_charts_mode + 350);
  378. _menu.AppendMenuSeparator();
  379. for (i = 0; i < li.lastfm_charts_periods_display.length; i++) {
  380. _menu.AppendMenuItem(MF_STRING, i + 360, li.lastfm_charts_periods_display[i].ucfirst());
  381. }
  382. _menu.CheckMenuRadioItem(360, 365, li.lastfm_charts_period + 360);
  383. _menu.AppendMenuSeparator();
  384. _sub1.AppendMenuItem(MF_STRING, 310, "Last.fm");
  385. _sub1.AppendMenuItem(MF_STRING, 311, "Autoplaylist");
  386. _sub1.CheckMenuRadioItem(310, 311, li.lastfm_link ? 310 : 311);
  387. _sub1.AppendTo(_menu, MF_STRING, "Links");
  388. _menu.AppendMenuSeparator();
  389. _menu.AppendMenuItem(MF_STRING, 370, "Bar colour...");
  390. _menu.AppendMenuSeparator();
  391. break;
  392. case "musicbrainz":
  393. _menu.AppendMenuItem(MF_STRING, 400, "Releases");
  394. _menu.AppendMenuItem(MF_STRING, 401, "Links");
  395. _menu.CheckMenuRadioItem(400, 401, li.mbs["2k3.musicbrainz_releases"] ? 400 : 401);
  396. _menu.AppendMenuSeparator();
  397. if (li.mbs["2k3.musicbrainz_releases"]) {
  398. for (i = 0; i < li.mbm.length; i++) {
  399. _menu.AppendMenuItem(li.mbs["2k3.musicbrainz_show_all"] && i > 0 && i <= 6 ? MF_GRAYED : MF_STRING, i + 410, li.mbm[i]);
  400. _menu.CheckMenuItem(i + 410, li.mbs[li.mbl[i]]);
  401. if (i == 3 || i == 6) _menu.AppendMenuSeparator();
  402. }
  403. _menu.AppendMenuSeparator();
  404. } else {
  405. _menu.AppendMenuItem(MF_STRING, 420, "Show icons");
  406. _menu.CheckMenuItem(420, li.mbs["2k3.musicbrainz_show_icons"]);
  407. _menu.AppendMenuSeparator();
  408. }
  409. break;
  410. }
  411. if (li.filename.is_file()) {
  412. _menu.AppendMenuItem(MF_STRING, 499, "Open containing folder");
  413. _menu.AppendMenuSeparator();
  414. }
  415. if (li.mode != "echonest") {
  416. _font.AppendMenuItem(MF_STRING, 490, 11);
  417. _font.AppendMenuItem(MF_STRING, 492, 13);
  418. _font.AppendMenuItem(MF_STRING, 494, 15);
  419. _font.AppendTo(_menu, MF_STRING, "Font size");
  420. _font.CheckMenuRadioItem(490, 494, this.list_font_size + 479);
  421. _menu.AppendMenuSeparator();
  422. }
  423. break;
  424. case typeof ps == "object" && b.buttons.ps.trace(x, y):
  425. var ok = ps.check_component && !ps.loved_working && !ps.playcount_working && l.username.length > 0;
  426. _sub1.AppendMenuItem(ok ? MF_STRING : MF_GRAYED, 500, "loved tracks and playcount");
  427. _sub1.AppendMenuItem(ok ? MF_STRING : MF_GRAYED, 501, "loved tracks only");
  428. _sub1.AppendMenuSeparator();
  429. _sub1.AppendMenuItem(MF_STRING, 502, "Show console");
  430. _sub1.CheckMenuItem(502, ps.show_console);
  431. _sub1.AppendTo(_menu, MF_STRING, "Library import");
  432. _menu.AppendMenuSeparator();
  433. _sub2.AppendMenuItem(MF_STRING, 321, "Last.fm auto-correct");
  434. _sub2.CheckMenuItem(321, l.auto_correct);
  435. _sub2.AppendMenuItem(MF_STRING, 511, "Only update tracks in Media Library");
  436. _sub2.CheckMenuItem(511, ps.library);
  437. _sub2.AppendMenuItem(MF_STRING, 512, "Extended logging");
  438. _sub2.CheckMenuItem(512, ps.logging);
  439. _sub2.AppendTo(_menu, MF_STRING, "Auto-updates");
  440. _menu.AppendMenuSeparator();
  441. _sub3.AppendMenuItem(MF_STRING, 520, "Enabled");
  442. _sub3.CheckMenuItem(520, ps.auto_love);
  443. _sub3.AppendMenuSeparator();
  444. _sub3.AppendMenuItem(ps.auto_love ? MF_STRING : MF_GRAYED, 521, "Condition");
  445. _sub3.AppendTo(_menu, MF_STRING, "Automatically love tracks");
  446. _menu.AppendMenuSeparator();
  447. break;
  448. case typeof s == "object" && s.mode == "spectrogram" && s.trace(x, y) :
  449. _menu.AppendMenuItem(MF_STRING, 580, "SoX options...");
  450. _menu.AppendMenuSeparator();
  451. _menu.AppendMenuItem(MF_STRING, 581, "Marker colour...");
  452. _menu.AppendMenuSeparator();
  453. _menu.AppendMenuItem(MF_STRING, 582, "Only analyse tracks in library");
  454. _menu.CheckMenuItem(582, s.library);
  455. _menu.AppendMenuSeparator();
  456. _sub1.AppendMenuItem(MF_STRING, 590, "Clear all");
  457. _sub1.AppendMenuItem(MF_STRING, 591, "Clear older than 1 day");
  458. _sub1.AppendMenuItem(MF_STRING, 592, "Clear older than 1 week");
  459. _sub1.AppendMenuSeparator();
  460. _sub1.AppendMenuItem(MF_GRAYED, 593, "In use: " + (fso.GetFolder(s.folder).size / 1048576).toFixed(2) + "MB");
  461. _sub1.AppendTo(_menu, MF_STRING, "Cached images");
  462. _menu.AppendMenuSeparator();
  463. break;
  464. case typeof t == "object" && t.trace(x, y):
  465. switch(t.mode) {
  466. case "allmusic":
  467. _sub1.AppendMenuItem(MF_STRING, 600, "Artist...");
  468. _sub1.AppendMenuItem(MF_STRING, 601, "Album...");
  469. _sub1.AppendTo(_menu, MF_STRING, "Field remapping");
  470. _menu.AppendMenuSeparator();
  471. _menu.AppendMenuItem(this.metadb ? MF_STRING : MF_GRAYED, 602, "Paste text from clipboard");
  472. _menu.AppendMenuSeparator();
  473. break;
  474. case "lastfm_wiki":
  475. _menu.AppendMenuItem(MF_STRING, 650, "Last.fm");
  476. _menu.AppendMenuItem(MF_STRING, 651, "Wikipedia");
  477. _menu.CheckMenuRadioItem(650, 651, t.biography_lastfm ? 650 : 651);
  478. _menu.AppendMenuSeparator();
  479. if (t.biography_lastfm) {
  480. for (i = 0; i < t.biography_lastfm_sites.length; i++) {
  481. _sub1.AppendMenuItem(MF_STRING, i + 660, t.biography_lastfm_sites[i]);
  482. }
  483. _sub1.CheckMenuRadioItem(660, 671, t.biography_lastfm_site + 660);
  484. _sub1.AppendTo(_menu, MF_STRING, "Last.fm site");
  485. _menu.AppendMenuSeparator();
  486. }
  487. break;
  488. case "simple_tag":
  489. _menu.AppendMenuItem(MF_STRING, 620, "Custom title...");
  490. _menu.AppendMenuItem(MF_STRING, 621, "Custom tag...");
  491. _menu.AppendMenuSeparator();
  492. _menu.AppendMenuItem(MF_STRING, 622, "Centre text");
  493. _menu.CheckMenuItem(622, t.centre);
  494. _menu.AppendMenuSeparator();
  495. break;
  496. case "simple_text":
  497. _menu.AppendMenuItem(MF_STRING, 630, "Refresh");
  498. _menu.AppendMenuSeparator();
  499. _menu.AppendMenuItem(MF_STRING, 620, "Custom title...");
  500. _menu.AppendMenuItem(MF_STRING, 632, "Custom path...");
  501. _menu.AppendMenuSeparator();
  502. _menu.AppendMenuItem(MF_STRING, 633, "Fixed width font");
  503. _menu.CheckMenuItem(633, t.fixed);
  504. _menu.AppendMenuSeparator();
  505. break;
  506. }
  507. if (t.filename.is_file()) {
  508. _menu.AppendMenuItem(MF_STRING, 699, "Open containing folder");
  509. _menu.AppendMenuSeparator();
  510. }
  511. _font.AppendMenuItem(MF_STRING, 680, 12);
  512. _font.AppendMenuItem(MF_STRING, 682, 14);
  513. _font.AppendMenuItem(MF_STRING, 684, 16);
  514. _font.AppendTo(_menu, MF_STRING, "Font size");
  515. _font.CheckMenuRadioItem(680, 684, this.normal_font_size + 668);
  516. _menu.AppendMenuSeparator();
  517. break;
  518. case typeof th == "object":
  519. if (th.source == 0) { //last.fm
  520. _menu.AppendMenuItem(this.metadb ? MF_STRING : MF_GRAYED, 700, "Download artist art from Last.fm");
  521. _menu.AppendMenuItem(MF_STRING, 701, "Help");
  522. _menu.AppendMenuSeparator();
  523. _sub1.AppendMenuItem(MF_STRING, 705, "Off");
  524. _sub1.AppendMenuItem(MF_STRING, 706, "Library tracks only");
  525. _sub1.AppendMenuItem(MF_STRING, 707, "All tracks");
  526. _sub1.CheckMenuRadioItem(705, 707, th.auto_download + 705);
  527. _sub1.AppendTo(_menu, MF_STRING, "Automatic download");
  528. _sub2.AppendMenuItem(MF_STRING, 710, "Small");
  529. _sub2.AppendMenuItem(MF_STRING, 711, "Medium");
  530. _sub2.AppendMenuItem(MF_STRING, 712, "Original");
  531. _sub2.CheckMenuRadioItem(710, 712, th.download_size + 710);
  532. _sub2.AppendTo(_menu, MF_STRING, "Download size");
  533. _sub3.AppendMenuItem(MF_STRING, 721, "1");
  534. _sub3.AppendMenuItem(MF_STRING, 723, "3");
  535. _sub3.AppendMenuItem(MF_STRING, 725, "5");
  536. _sub3.CheckMenuRadioItem(721, 725, th.limit + 720);
  537. _sub3.AppendTo(_menu, MF_STRING, "Limit");
  538. } else if (th.source == 1) { //custom folder
  539. _menu.AppendMenuItem(MF_STRING, 730, "Refresh");
  540. _menu.AppendMenuSeparator();
  541. _menu.AppendMenuItem(MF_STRING, 731, "Set custom folder...");
  542. }
  543. if (th.source != 2) {
  544. _menu.AppendMenuSeparator();
  545. _sub4.AppendMenuItem(MF_STRING, 735, "Last.fm artist art");
  546. _sub4.AppendMenuItem(MF_STRING, 736, "Custom folder");
  547. _sub4.CheckMenuRadioItem(735, 736, th.source + 735);
  548. _sub4.AppendTo(_menu, MF_STRING, "Image source");
  549. _menu.AppendMenuSeparator();
  550. }
  551. _sub5.AppendMenuItem(MF_STRING, 740, "Off");
  552. _sub5.AppendMenuItem(MF_STRING, 745, "5 seconds");
  553. _sub5.AppendMenuItem(MF_STRING, 750, "10 seconds");
  554. _sub5.AppendMenuItem(MF_STRING, 760, "20 seconds");
  555. _sub5.CheckMenuRadioItem(740, 760, th.cycle + 740);
  556. _sub5.AppendTo(_menu, MF_STRING, "Cycle");
  557. _menu.AppendMenuSeparator();
  558. if (th.mode != th.modes.disabled) {
  559. _sub6.AppendMenuItem(MF_STRING, 765, "Grid");
  560. _sub6.AppendMenuItem(MF_STRING, 766, "Left");
  561. _sub6.AppendMenuItem(MF_STRING, 767, "Right");
  562. _sub6.AppendMenuItem(MF_STRING, 768, "Top");
  563. _sub6.AppendMenuItem(MF_STRING, 769, "Bottom");
  564. _sub6.AppendMenuItem(MF_STRING, 770, "Off");
  565. _sub6.CheckMenuRadioItem(765, 770, th.mode + 765);
  566. if (th.mode != th.modes.off) {
  567. _sub6.AppendMenuSeparator();
  568. _sub6.AppendMenuItem(MF_STRING, 775, "75px");
  569. _sub6.AppendMenuItem(MF_STRING, 800, "100px");
  570. _sub6.AppendMenuItem(MF_STRING, 850, "150px");
  571. _sub6.AppendMenuItem(MF_STRING, 900, "200px");
  572. _sub6.AppendMenuItem(MF_STRING, 950, "250px");
  573. _sub6.AppendMenuItem(MF_STRING, 1000, "300px");
  574. _sub6.CheckMenuRadioItem(775, 1000, th.px + 700);
  575. }
  576. _sub6.AppendTo(_menu, MF_STRING, "Thumbs");
  577. _menu.AppendMenuSeparator();
  578. }
  579. _sub7.AppendMenuItem(MF_STRING, 1001, "Newest first");
  580. _sub7.AppendMenuItem(MF_STRING, 1002, "Oldest first");
  581. _sub7.AppendMenuItem(MF_STRING, 1003, "A-Z");
  582. _sub7.AppendMenuItem(MF_STRING, 1004, "Z-A");
  583. _sub7.CheckMenuRadioItem(1001, 1004, th.sort + 1001);
  584. _sub7.AppendTo(_menu, MF_STRING, "Sorting");
  585. _menu.AppendMenuSeparator();
  586. if (!th.trace(x, y) || th.mode == th.modes.grid && th.overlay) {
  587. if (this.metadb) {
  588. _menu.AppendMenuItem(MF_STRING, 1010, "Open containing folder");
  589. _menu.AppendMenuSeparator();
  590. }
  591. if (th.images.length > 0) {
  592. _menu.AppendMenuItem(MF_STRING, 1011, "Open image");
  593. _menu.AppendMenuItem(MF_STRING, 1012, "Delete image");
  594. _menu.AppendMenuSeparator();
  595. _menu.AppendMenuItem(MF_STRING, 1013, "Crop (focus on centre)");
  596. _menu.AppendMenuItem(MF_STRING, 1014, "Crop (focus on top)");
  597. _menu.AppendMenuItem(MF_STRING, 1015, "Stretch");
  598. _menu.AppendMenuItem(MF_STRING, 1016, "Centre");
  599. _menu.CheckMenuRadioItem(1013, 1016, th.type + 1013);
  600. _menu.AppendMenuSeparator();
  601. if (th.source == 0 && th.images.length > 1) {
  602. _menu.AppendMenuItem(th.default_file == th.files[th.image] ? MF_GRAYED : MF_STRING, 1017, "Set as default");
  603. _menu.AppendMenuItem(MF_STRING, 1018, "Clear default");
  604. _menu.AppendMenuSeparator();
  605. }
  606. }
  607. }
  608. break;
  609. }
  610. if (this.check_feature("custom_background")) {
  611. if (!this.is_dui) _custom_background.AppendMenuItem(MF_STRING, 1, "None");
  612. _custom_background.AppendMenuItem(MF_STRING, 2, this.is_dui ? "Use default UI setting" : "Use columns UI setting");
  613. _custom_background.AppendMenuItem(MF_STRING, 3, "Splitter");
  614. _custom_background.AppendMenuItem(MF_STRING, 4, "Custom");
  615. _custom_background.CheckMenuRadioItem(1, 4, this.background_mode + 1);
  616. _custom_background.AppendMenuSeparator();
  617. _custom_background.AppendMenuItem(this.background_mode == 3 ? MF_STRING : MF_GRAYED, 5, "Set custom colour...");
  618. _custom_background.AppendTo(_menu, MF_STRING, "Background");
  619. _menu.AppendMenuSeparator();
  620. }
  621. if (typeof l == "object" && l.need_username) {
  622. _menu.AppendMenuItem(MF_STRING, 10, "Last.fm username...");
  623. if (typeof ps == "object") _menu.AppendMenuItem(l.username.length > 0 ? MF_STRING : MF_GRAYED, 11, "Last.fm password...");
  624. _menu.AppendMenuSeparator();
  625. }
  626. if (this.check_feature("metadb")) {
  627. _metadb.AppendMenuItem(MF_STRING, 20, "Use display preferences");
  628. _metadb.AppendMenuItem(MF_STRING, 21, "Prefer now playing");
  629. _metadb.AppendMenuItem(MF_STRING, 22, "Follow selected track");
  630. _metadb.CheckMenuRadioItem(20, 22, this.selection_mode + 20);
  631. _metadb.AppendTo(_menu, MF_STRING, "Selection mode");
  632. _menu.AppendMenuSeparator();
  633. }
  634. if (this.check_feature("remap")) {
  635. _menu.AppendMenuItem(MF_STRING, 30, "Artist field remapping...");
  636. _menu.AppendMenuSeparator();
  637. }
  638. _menu.AppendMenuItem(MF_STRING, 31, "Update script");
  639. _menu.AppendMenuItem(MF_STRING, 32, "About");
  640. _menu.AppendMenuSeparator();
  641. if (utils.IsKeyPressed(0x10)) _menu.AppendMenuItem(MF_STRING, 49, "Properties");
  642. _menu.AppendMenuItem(MF_STRING, 50, "Configure...");
  643. var idx = _menu.TrackPopupMenu(x, y);
  644. switch(idx) {
  645. case 1:
  646. case 2:
  647. case 3:
  648. case 4:
  649. this.background_mode = idx - 1;
  650. window.SetProperty("2k3.background_mode", this.background_mode);
  651. window.Repaint();
  652. break;
  653. case 5:
  654. 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);
  655. window.SetProperty("2k3.background_custom_colour", this.background_custom_colour);
  656. window.Repaint();
  657. break;
  658. case 10:
  659. l.update_username();
  660. break;
  661. case 11:
  662. l.update_password();
  663. break;
  664. case 20:
  665. case 21:
  666. case 22:
  667. this.selection_mode = idx - 20;
  668. window.SetProperty("2k3.selection_mode", this.selection_mode);
  669. this.item_focus_change();
  670. break;
  671. case 30:
  672. 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);
  673. if (this.artist_tf == "") this.artist_tf = "%artist%";
  674. window.SetProperty("2k3.artist_tf", this.artist_tf);
  675. this.item_focus_change();
  676. break;
  677. case 31:
  678. this.update_script();
  679. break;
  680. case 32:
  681. this.MsgBox("Common file: " + VERSION + "\n(c) 2014 marc2003", 0, this.name);
  682. break;
  683. case 49:
  684. window.ShowProperties();
  685. break;
  686. case 50:
  687. window.ShowConfigure();
  688. break;
  689. case 100: //artreader /cd refresh
  690. this.item_focus_change();
  691. break;
  692. case 101:
  693. case 102:
  694. case 103:
  695. case 104:
  696. case 105:
  697. a.id = idx - 101;
  698. window.SetProperty("2k3.artreader_id", a.id);
  699. this.item_focus_change();
  700. break;
  701. case 110:
  702. case 111:
  703. case 112:
  704. case 113:
  705. a.type = idx - 110;
  706. window.SetProperty("2k3.artreader_type", a.type);
  707. window.RepaintRect(a.x, a.y, a.w, a.h);
  708. break;
  709. case 120:
  710. this.browser("https://www.google.com/search?tbm=isch&q=" + encodeURIComponent(this.eval("%album artist%[ %album%]")));
  711. break;
  712. case 121:
  713. this.aad();
  714. break;
  715. case 122:
  716. fb.ShowPopupMessage("You can get Album Art Downloader here:\n\nhttp://www.hydrogenaud.io/forums/index.php?showtopic=57392", this.name);
  717. break;
  718. case 123:
  719. case 124:
  720. a.dblclk = idx - 123;
  721. window.SetProperty("2k3.artreader_dblclk", a.dblclk);
  722. break;
  723. case 125:
  724. case 126:
  725. c.dblclk = idx -125;
  726. window.SetProperty("2k3.cd_dblclk", c.dblclk);
  727. break;
  728. case 130:
  729. c.gloss = !c.gloss;
  730. window.SetProperty("2k3.cd_gloss", c.gloss);
  731. window.Repaint();
  732. break;
  733. case 131:
  734. c.shadow = !c.shadow;
  735. window.SetProperty("2k3.cd_shadow", c.shadow);
  736. window.Repaint();
  737. break;
  738. case 200:
  739. li.autoplaylists_title = this.InputBox("Enter a new title", this.name, li.autoplaylists_title);
  740. if (li.autoplaylists_title == "") li.autoplaylists_title = "Autoplaylists";
  741. window.SetProperty("2k3.autoplaylists_title", li.autoplaylists_title);
  742. window.Repaint();
  743. break;
  744. case 201:
  745. case 202:
  746. case 203:
  747. case 204:
  748. case 205:
  749. case 206:
  750. case 207:
  751. case 208:
  752. li.autoplaylists_slot = idx - 200;
  753. window.SetProperty("2k3.autoplaylists_slot", li.autoplaylists_slot);
  754. li.filename = this.settings_folder + "autoplaylists" + li.autoplaylists_slot;
  755. li.update();
  756. break;
  757. case 210:
  758. case 211:
  759. li.autoplaylists_success = idx == 210;
  760. window.SetProperty("2k3.autoplaylists_success", li.autoplaylists_success);
  761. break;
  762. case 220:
  763. case 221:
  764. case 222:
  765. case 223:
  766. case 224:
  767. case 225:
  768. case 226:
  769. case 227:
  770. li.data.push(li.autoplaylists_deleted_items[idx - 220]);
  771. li.autoplaylists_deleted_items.splice(idx - 220, 1);
  772. this.save(li.data.join("\n"), li.filename);
  773. window.NotifyOthers("autoplaylists", "update");
  774. li.update();
  775. break;
  776. case 230:
  777. li.autoplaylists_remove_duplicates = !li.autoplaylists_remove_duplicates;
  778. window.SetProperty("2k3.autoplaylists_remove_duplicates", li.autoplaylists_remove_duplicates);
  779. break;
  780. case 240:
  781. li.autoplaylists_add();
  782. break;
  783. case 290:
  784. case 291:
  785. case 292:
  786. li.echonest_mode = idx - 290;
  787. window.SetProperty("2k3.echonest_mode", li.echonest_mode);
  788. li.artist = "";
  789. this.item_focus_change();
  790. break;
  791. case 300:
  792. case 301:
  793. case 302:
  794. case 303:
  795. case 304:
  796. li.lastfm_mode = idx - 300;
  797. window.SetProperty("2k3.lastfm_mode", li.lastfm_mode);
  798. li.artist = "";
  799. this.item_focus_change();
  800. break;
  801. case 310:
  802. case 311:
  803. li.lastfm_link = idx == 310;
  804. window.SetProperty("2k3.lastfm_link", li.lastfm_link);
  805. break;
  806. case 320:
  807. case 321:
  808. l.auto_correct = !l.auto_correct;
  809. window.SetProperty("2k3.lastfm_auto_correct", l.auto_correct);
  810. if (this.metadb && idx == 320) li.get();
  811. break;
  812. case 350:
  813. case 351:
  814. case 352:
  815. li.lastfm_charts_mode = idx - 350;
  816. window.SetProperty("2k3.lastfm_charts_mode", li.lastfm_charts_mode);
  817. li.update();
  818. break;
  819. case 360:
  820. case 361:
  821. case 362:
  822. case 363:
  823. case 364:
  824. case 365:
  825. li.lastfm_charts_period = idx - 360;
  826. window.SetProperty("2k3.lastfm_charts_period", li.lastfm_charts_period);
  827. li.update();
  828. break;
  829. case 370:
  830. 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);
  831. window.SetProperty("2k3.lastfm_charts_bar_colour", li.lastfm_charts_bar_colour);
  832. window.Repaint();
  833. break;
  834. case 400:
  835. case 401:
  836. li.mb_set("2k3.musicbrainz_releases", idx == 400);
  837. break;
  838. case 410:
  839. case 411:
  840. case 412:
  841. case 413:
  842. case 414:
  843. case 415:
  844. case 416:
  845. case 417:
  846. case 418:
  847. li.mb_set(li.mbl[idx - 410], !li.mbs[li.mbl[idx - 410]]);
  848. break;
  849. case 420:
  850. li.mb_set("2k3.musicbrainz_show_icons", !li.mbs["2k3.musicbrainz_show_icons"]);
  851. break;
  852. case 490:
  853. case 492:
  854. case 494:
  855. this.list_font_size = idx - 479;
  856. window.SetProperty("2k3.list_font_size", this.list_font_size);
  857. this.font_changed();
  858. break;
  859. case 499:
  860. this.explorer(li.filename);
  861. break;
  862. case 500:
  863. case 501:
  864. ps.full_import = idx == 500;
  865. ps.start_import();
  866. break;
  867. case 502:
  868. ps.show_console = !ps.show_console;
  869. window.SetProperty("2k3.playcount_sync_show_console", ps.show_console);
  870. break;
  871. case 511:
  872. ps.library = !ps.library;
  873. window.SetProperty("2k3.playcount_sync_library", ps.library);
  874. break;
  875. case 512:
  876. ps.logging = !ps.logging;
  877. window.SetProperty("2k3.playcount_sync_logging", ps.logging);
  878. break;
  879. case 520:
  880. ps.auto_love = !ps.auto_love;
  881. window.SetProperty("2k3.playcount_sync_auto_love", ps.auto_love);
  882. break;
  883. case 521:
  884. 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);
  885. window.SetProperty("2k3.playcount_sync_auto_love_tf", ps.auto_love_tf);
  886. break;
  887. case 580:
  888. 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);
  889. window.SetProperty("2k3.seekbar_sox_params", s.sox_params);
  890. if (fb.IsPlaying) s.playback_new_track();
  891. break;
  892. case 581:
  893. s.marker = this.InputBox("Enter a custom colour for the marker. Uses RGB. Example usage:\n\n234-211-74", this.name, s.marker);
  894. window.SetProperty("2k3.seekbar_marker", s.marker);
  895. break;
  896. case 582:
  897. s.library = !s.library;
  898. window.SetProperty("2k3.seekbar_library", s.library);
  899. break;
  900. case 590:
  901. s.clear_images(0);
  902. break;
  903. case 591:
  904. s.clear_images(ONE_DAY);
  905. break;
  906. case 592:
  907. s.clear_images(ONE_WEEK);
  908. break;
  909. case 600:
  910. 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);
  911. if (t.allmusic_artist_tf == "") t.allmusic_artist_tf = "%album artist%";
  912. window.SetProperty("2k3.allmusic_artist_tf", t.allmusic_artist_tf);
  913. this.item_focus_change();
  914. break;
  915. case 601:
  916. 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);
  917. if (t.allmusic_album_tf == "") t.allmusic_album_tf = "%album%";
  918. window.SetProperty("2k3.allmusic_album_tf", t.allmusic_album_tf);
  919. this.item_focus_change();
  920. break;
  921. case 602:
  922. var text = doc.parentWindow.clipboardData.getData("Text");
  923. if (typeof text == "string") {
  924. this.save(text, t.filename);
  925. t.text = text;
  926. t.update();
  927. window.Repaint();
  928. }
  929. break;
  930. case 620:
  931. t.title_tf = this.InputBox("You can use full title formatting here.", this.name, t.title_tf);
  932. window.SetProperty("2k3.text_title_tf", t.title_tf);
  933. window.Repaint();
  934. break;
  935. case 621:
  936. t.tag_tf = this.InputBox("Enter a custom tag.", this.name, t.tag_tf);
  937. window.SetProperty("2k3.text_tag_tf", t.tag_tf);
  938. t.filename = "";
  939. this.item_focus_change();
  940. break;
  941. case 622:
  942. t.centre = !t.centre;
  943. window.SetProperty("2k3.text_centre", t.centre);
  944. window.RepaintRect(t.x, t.y, t.w, t.h);
  945. break;
  946. case 630:
  947. t.filename = "";
  948. this.item_focus_change();
  949. break;
  950. case 632:
  951. 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);
  952. window.SetProperty("2k3.text_filename_tf", t.filename_tf);
  953. this.item_focus_change();
  954. break;
  955. case 633:
  956. t.fixed = !t.fixed;
  957. window.SetProperty("2k3.text_fixed_font", t.fixed);
  958. t.update();
  959. window.RepaintRect(t.x, t.y, t.w, t.h);
  960. break;
  961. case 650:
  962. case 651:
  963. t.biography_lastfm = idx == 650;
  964. window.SetProperty("2k3.biography_lastfm", t.biography_lastfm);
  965. t.artist = "";
  966. this.item_focus_change();
  967. break;
  968. case 660:
  969. case 661:
  970. case 662:
  971. case 663:
  972. case 664:
  973. case 665:
  974. case 666:
  975. case 667:
  976. case 668:
  977. case 669:
  978. case 670:
  979. case 671:
  980. t.biography_lastfm_site = idx - 660;
  981. window.SetProperty("2k3.biography_lastfm_site", t.biography_lastfm_site);
  982. t.artist = "";
  983. this.item_focus_change();
  984. break;
  985. case 680:
  986. case 682:
  987. case 684:
  988. this.normal_font_size = idx - 668;
  989. window.SetProperty("2k3.normal_font_size", this.normal_font_size);
  990. this.font_changed();
  991. break;
  992. case 699:
  993. this.explorer(t.filename);
  994. break;
  995. case 700:
  996. th.download();
  997. break;
  998. case 701:
  999. 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);
  1000. break;
  1001. case 705:
  1002. case 706:
  1003. case 707:
  1004. th.auto_download = idx - 705;
  1005. window.SetProperty("2k3.thumbs_auto_download", th.auto_download);
  1006. break;
  1007. case 710:
  1008. case 711:
  1009. case 712:
  1010. th.download_size = idx - 710;
  1011. window.SetProperty("2k3.thumbs_download_size", thumbs.download_size);
  1012. break;
  1013. case 721:
  1014. case 723:
  1015. case 725:
  1016. th.limit = idx - 720;
  1017. window.SetProperty("2k3.thumbs_limit", th.limit);
  1018. break;
  1019. case 730:
  1020. th.update();
  1021. break;
  1022. case 731:
  1023. 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);
  1024. if (th.custom_folder_tf == "") th.custom_folder_tf = "$directory_path(%path%)";
  1025. window.SetProperty("2k3.thumbs_custom_folder_tf", th.custom_folder_tf);
  1026. th.folder = "";
  1027. this.item_focus_change();
  1028. break;
  1029. case 735:
  1030. case 736:
  1031. th.source = idx - 735;
  1032. window.SetProperty("2k3.thumbs_source", th.source);
  1033. th.artist = "";
  1034. th.folder = "";
  1035. this.item_focus_change();
  1036. break;
  1037. case 740:
  1038. case 745:
  1039. case 750:
  1040. case 760:
  1041. th.cycle = idx - 740;
  1042. window.SetProperty("2k3.thumbs_cycle", th.cycle);
  1043. break;
  1044. case 765:
  1045. case 766:
  1046. case 767:
  1047. case 768:
  1048. case 769:
  1049. case 770:
  1050. th.mode = idx - 765;
  1051. window.SetProperty("2k3.thumbs_mode", th.mode);
  1052. th.size(true);
  1053. window.Repaint();
  1054. break;
  1055. case 775:
  1056. case 800:
  1057. case 850:
  1058. case 900:
  1059. case 950:
  1060. case 1000:
  1061. th.px = idx - 700;
  1062. window.SetProperty("2k3.thumbs_px", th.px);
  1063. th.size(true);
  1064. window.Repaint();
  1065. break;
  1066. case 1001:
  1067. case 1002:
  1068. case 1003:
  1069. case 1004:
  1070. th.sort = idx - 1001;
  1071. if (th.images.length > 0) th.update();
  1072. break;
  1073. case 1010:
  1074. if (th.images.length == 0) this.run("\"" + th.folders[0] + "\"");
  1075. else this.explorer(th.files[th.image]);
  1076. break;
  1077. case 1011:
  1078. this.run("\"" + th.files[th.image] + "\"");
  1079. break;
  1080. case 1012:
  1081. th.delete_image();
  1082. break;
  1083. case 1013:
  1084. case 1014:
  1085. case 1015:
  1086. case 1016:
  1087. th.type = idx - 1013;
  1088. window.SetProperty("2k3.thumbs_type", th.type);
  1089. window.Repaint();
  1090. break;
  1091. case 1017:
  1092. th.set_default(th.files[th.image].split("\\").pop());
  1093. break;
  1094. case 1018:
  1095. th.set_default("");
  1096. break;
  1097. }
  1098. _menu.Dispose();
  1099. _custom_background.Dispose();
  1100. _metadb.Dispose();
  1101. _cover.Dispose();
  1102. _font.Dispose();
  1103. _sub1.Dispose();
  1104. _sub2.Dispose();
  1105. _sub3.Dispose();
  1106. _sub4.Dispose();
  1107. _sub5.Dispose();
  1108. _sub6.Dispose();
  1109. _sub7.Dispose();
  1110. }
  1111.  
  1112. this.features_init = function() {
  1113. for (i in this.features) {
  1114. switch(this.features[i]) {
  1115. case "custom_menu":
  1116. this.hover = false;
  1117. this.menu_btn = new sb(0, 0, 20, 20, gdi.Image(this.ip + "buttons\\cog.png"), "p.hover", function() { p.menu(); });
  1118. this.menu_btn.leave = function() {
  1119. p.hover = false;
  1120. window.RepaintRect(this.x, this.y, this.w, this.h);
  1121. }
  1122. break;
  1123. case "custom_background":
  1124. this.background_mode = window.GetProperty("2k3.background_mode", 1);
  1125. this.background_custom_colour = window.GetProperty("2k3.background_custom_colour", "0-0-0");
  1126. break;
  1127. case "metadb":
  1128. this.selection_mode = window.GetProperty("2k3.selection_mode", 1);
  1129. break;
  1130. case "themes":
  1131. try {
  1132. this.themed_header = window.CreateThemeManager("Header");
  1133. this.themed_header.SetPartAndStateId(1, 1);
  1134. this.themed_button = window.CreateThemeManager("Button");
  1135. } catch(e) {
  1136. this.MsgBox("Your Windows theme does not support this script.", 0, this.name);
  1137. }
  1138. break;
  1139. case "remap":
  1140. this.artist_tf = window.GetProperty("2k3.artist_tf", "%artist%");
  1141. break;
  1142. }
  1143. }
  1144. }
  1145.  
  1146. this.check_feature = function(f) {
  1147. for (i in this.features) {
  1148. if (this.features[i] == f) return true;
  1149. }
  1150. return false;
  1151. }
  1152.  
  1153. this.eval = function(t) {
  1154. if (!this.metadb) return "";
  1155. if (fb.IsPlaying && this.is_stream()) {
  1156. t = tfe(t);
  1157. try { t = decodeURIComponent(t); } catch(e) {}
  1158. return t;
  1159. } else {
  1160. return tf(t, this.metadb);
  1161. }
  1162. }
  1163.  
  1164. this.is_stream = function() {
  1165. //support m-TAGS (foo_tags.dll)
  1166. var path = tf("$if2(%__@%,%path%)", this.metadb);
  1167. switch(true) {
  1168. case path.indexOf("http") == 0:
  1169. case path.indexOf("mms") == 0:
  1170. return true;
  1171. default:
  1172. return false;
  1173. }
  1174. }
  1175.  
  1176. this.open = function(f) {
  1177. return utils.ReadTextFile(f);
  1178. }
  1179.  
  1180. this.save = function(t, f, m) {
  1181. if (typeof m == "undefined") m = -1;
  1182. try {
  1183. var ts = fso.OpenTextFile(f, 2, true, m);
  1184. ts.WriteLine(t);
  1185. ts.Close();
  1186. return true;
  1187. } catch(e) {
  1188. return false;
  1189. }
  1190. }
  1191.  
  1192. this.console = function(t) {
  1193. fb.trace(this.name + ": " + t);
  1194. }
  1195.  
  1196. this.strip_tags = function(t) {
  1197. doc.open();
  1198. var div = doc.createElement("div");
  1199. div.innerHTML = t.replace(/\n/g, "<br>");
  1200. var text = div.innerText.trim();
  1201. doc.close();
  1202. return text;
  1203. }
  1204.  
  1205. this.InputBox = function(prompt, title, value) {
  1206. prompt = prompt.replace(/"/g, '" + Chr(34) + "').replace(/\n/g, '" + Chr(13) + "');
  1207. title = title.replace(/"/g, '" + Chr(34) + "');
  1208. value = value.replace(/"/g, '" + Chr(34) + "');
  1209. var temp_value = vb.eval('InputBox' + '("' + prompt + '", "' + title + '", "' + value + '")');
  1210. if (typeof temp_value == "undefined") return value;
  1211. 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);
  1212. return temp_value.trim();
  1213. }
  1214.  
  1215. this.MsgBox = function(prompt, buttons, title) {
  1216. prompt = prompt.replace(/"/g, '" + Chr(34) + "').replace(/\n/g, '" + Chr(13) + "');
  1217. title = title.replace(/"/g, '" + Chr(34) + "');
  1218. return vb.eval('MsgBox' + '("' + prompt + '", "' + buttons + '", "' + title + '")');
  1219. }
  1220.  
  1221. this.browser = function(c) {
  1222. if (!this.run(c)) this.MsgBox("Unable to launch your default browser.", 0, this.name);
  1223. }
  1224.  
  1225. this.run = function(c) {
  1226. try {
  1227. WshShell.Run(c);
  1228. return true;
  1229. } catch(e) {
  1230. return false;
  1231. }
  1232. }
  1233.  
  1234. this.run_cmd = function(c, w) {
  1235. try { WshShell.Run(c, 0, w); } catch(e) {}
  1236. }
  1237.  
  1238. this.explorer = function(f) {
  1239. if (f.is_file()) this.run("explorer /select,\"" + f + "\"");
  1240. }
  1241.  
  1242. this.aad = function() {
  1243. var aad_path = window.GetProperty("2k3.aad_path", "");
  1244. if (!aad_path.is_file()) {
  1245. var folder = app.BrowseForFolder(0, "Locate Album Art Downloader", 0x00000200);
  1246. var file = folder ? folder.items().item().path + "\\AlbumArt.exe" : "";
  1247. if (file.is_file()) {
  1248. aad_path = file;
  1249. window.SetProperty("2k3.aad_path", aad_path);
  1250. }
  1251. }
  1252. if (aad_path.is_file()) {
  1253. var album_artist = "/ar \"" + this.eval("[%album artist%]") + "\"";
  1254. var album = " /al \"" + this.eval("[%album%]") + "\"";
  1255. this.run("\"" + aad_path + "\"" + album_artist + album);
  1256. }
  1257. }
  1258.  
  1259. this.tt = function(t) {
  1260. if (this.tooltip.Text == t) return;
  1261. this.tooltip.Text = t;
  1262. this.tooltip.Activate();
  1263. }
  1264.  
  1265. this.splitRGB = function(c) {
  1266. var temp_col = c.split("-");
  1267. return RGB(temp_col[0], temp_col[1], temp_col[2]);
  1268. }
  1269.  
  1270. this.draw_background = function(gr) {
  1271. if (this.check_feature("custom_background")) {
  1272. var col;
  1273. switch(this.background_mode) {
  1274. case 0:
  1275. col = null;
  1276. break;
  1277. case 1:
  1278. col = this.backcolour;
  1279. break;
  1280. case 2:
  1281. col = utils.GetSysColor(15);
  1282. break;
  1283. case 3:
  1284. col = this.splitRGB(this.background_custom_colour);
  1285. break;
  1286. }
  1287. if (col) gr.FillSolidRect(0, 0, this.w, this.h, col);
  1288. } else {
  1289. gr.FillSolidRect(0, 0, this.w, this.h, this.backcolour);
  1290. }
  1291. }
  1292.  
  1293. this.draw_image = function(gr, img, pos_x, pos_y, width, height, type, border, alpha) {
  1294. if (!img) return;
  1295. gr.SetInterpolationMode(7);
  1296. switch(type) {
  1297. case 0: //crop
  1298. case 1: //crop top
  1299. var sr = img.Width / img.Height;
  1300. var dr = width / height;
  1301. if (sr < dr) {
  1302. var r = img.Width / width;
  1303. var ch = height * r;
  1304. var sy = Math.round((img.Height - ch) / (type == 1 ? 4 : 2));
  1305. var cw = img.Width;
  1306. var sx = 0;
  1307. } else {
  1308. var r = img.Height / height;
  1309. var cw = width * r;
  1310. var sx = Math.round((img.Width - cw) / 2);
  1311. var ch = img.Height;
  1312. var sy = 0;
  1313. }
  1314. gr.DrawImage(img, pos_x, pos_y, width, height, sx + 5, sy + 5, cw - 10, ch - 10, 0, alpha || 255);
  1315. if (border) gr.DrawRect(pos_x, pos_y, width - 1, height - 1, 1, border);
  1316. break;
  1317. case 2: //stretch
  1318. gr.DrawImage(img, pos_x, pos_y, width, height, 0, 0, img.Width, img.Height, 0, alpha || 255);
  1319. if (border) gr.DrawRect(pos_x, pos_y, width - 1, height - 1, 1, border);
  1320. break;
  1321. case 3: //centre
  1322. default:
  1323. var s = Math.min(width / img.Width, height / img.Height);
  1324. var nw = Math.floor(img.Width * s);
  1325. var nh = Math.floor(img.Height * s);
  1326. pos_x += Math.round((width - nw) / 2);
  1327. pos_y += Math.round((height - nh) / 2);
  1328. if (type == "centre") gr.DrawImage(img, pos_x, pos_y, nw, nh, 5, 5, img.Width - 10, img.Height - 10, 0, alpha || 255);
  1329. else gr.DrawImage(img, pos_x, pos_y, nw, nh, 0, 0, img.Width, img.Height, 0, alpha || 255);
  1330. if (border) gr.DrawRect(pos_x, pos_y, nw - 1, nh - 1, 1, border);
  1331. break;
  1332. }
  1333. }
  1334.  
  1335. this.centre_text = function(gr, text, font, colour, x, y, w, h) {
  1336. gr.GdiDrawText(text, font, colour, x, y, w, h, DT_VCENTER | DT_CENTER | DT_WORDBREAK | DT_CALCRECT | DT_NOPREFIX);
  1337. }
  1338.  
  1339. this.left_text = function(gr, text, font, colour, x, y, w, h) {
  1340. gr.GdiDrawText(text, font, colour, x, y, w, h, DT_VCENTER | DT_END_ELLIPSIS | DT_CALCRECT | DT_NOPREFIX);
  1341. }
  1342.  
  1343. this.right_text = function(gr, text, font, colour, x, y, w, h) {
  1344. gr.GdiDrawText(text, font, colour, x, y, w, h, DT_VCENTER | DT_RIGHT | DT_END_ELLIPSIS | DT_CALCRECT | DT_NOPREFIX);
  1345. }
  1346.  
  1347. this.format_time = function(t) {
  1348. t = Math.round(t);
  1349. var w = Math.floor(t / 604800);
  1350. var d = Math.floor((t -= w * 604800) / 86400);
  1351. var h = Math.floor((t -= d * 86400) / 3600);
  1352. var m = Math.floor((t -= h * 3600) / 60);
  1353. var s = t -= m * 60;
  1354. var temp = "";
  1355. if (w > 0) temp += w + "wk ";
  1356. if (w > 0 || d > 0) temp += d + "d ";
  1357. if (w > 0 || d > 0 || h > 0) temp += h + ":";
  1358. temp += (m < 10 && h > 0 ? "0" + m : m) + ":";
  1359. temp += (s < 10 ? "0" + s : s);
  1360. return temp;
  1361. }
  1362.  
  1363. this.update_script = function() {
  1364. this.xmlhttp.open("GET", this.common_js_url, true);
  1365. this.xmlhttp.send();
  1366. this.xmlhttp.onreadystatechange = function() {
  1367. if (p.xmlhttp.readyState == 4) {
  1368. if (p.xmlhttp.status == 200) {
  1369. var text = p.xmlhttp.responsetext;
  1370. switch(true) {
  1371. case text.indexOf("function panel") == -1:
  1372. p.MsgBox("Unexpected server error. Not updating.", 0, p.name);
  1373. break;
  1374. case text.indexOf("var VERSION = \"" + VERSION) == 0:
  1375. p.MsgBox("Already using latest version.", 0, p.name);
  1376. break;
  1377. default:
  1378. if (p.save(text, p.common_js_file)) {
  1379. if (p.MsgBox("Download successful. Restart foobar2000 now?", 4, p.name) == 6) fb.RunMainMenuCommand("File/Restart");
  1380. } else {
  1381. p.MsgBox("Unexpected error. Not updating.", 0, p.name);
  1382. }
  1383. break;
  1384. }
  1385. } else {
  1386. p.console(p.xmlhttp.responsetext || "HTTP error: " + p.xmlhttp.status);
  1387. }
  1388. }
  1389. }
  1390. }
  1391.  
  1392. this.json_parse = function(a, b, c, d) {
  1393. try {
  1394. var data = JSON.parse(a);
  1395. } catch(e) {
  1396. this.console("JSON.parse error.");
  1397. return false;
  1398. }
  1399. if (b) {
  1400. b = b.split(".");
  1401. for (i in b) {
  1402. if (data === null || typeof data[b[i]] === 'undefined') return [];
  1403. data = data[b[i]];
  1404. }
  1405. }
  1406. if (c) {
  1407. data = data.sort(function(e, f) {
  1408. if (!e[c]) return 1;
  1409. if (!f[c]) return -1;
  1410. if (e[c] < f[c]) return d ? 1 : -1;
  1411. if (e[c] > f[c]) return d ? -1 : 1;
  1412. return 0;
  1413. });
  1414. }
  1415. return data;
  1416. }
  1417.  
  1418. this.new_artist_folder = function(t) {
  1419. var folder = this.artists_folder + t.validate() + "\\";
  1420. folder.create();
  1421. return folder;
  1422. }
  1423.  
  1424. this.delete_file = function(f) {
  1425. if (!f.is_file()) return;
  1426. try {
  1427. fso.DeleteFile(f);
  1428. } catch(e) {
  1429. this.console("Could not delete " + f);
  1430. }
  1431. }
  1432.  
  1433. this.fb2k_escape = function(t) {
  1434. return t.replace(/'/g, "''").replace(/[\(\)\[\],$]/g, "'$&'");
  1435. }
  1436.  
  1437. var i;
  1438. this.name = name;
  1439. this.features = features;
  1440. this.is_dui = window.InstanceType;
  1441. this.script_path = fb.ProfilePath + "marc2003\\";
  1442. this.ip = this.script_path + "images8\\";
  1443. this.common_js_url = "https://dl.dropboxusercontent.com/u/22801321/wsh/marc2003/common8.js";
  1444. this.common_js_file = this.script_path + "common8.js";
  1445. this.tooltip = window.CreateTooltip();
  1446. this.w = 0;
  1447. this.h = 0;
  1448. this.mx = 0;
  1449. this.my = 0;
  1450. this.metadb = fb.GetFocusItem();
  1451. this.data_folder = fb.ProfilePath + "wsh_data\\";
  1452. this.artists_folder = this.data_folder + "artists\\"
  1453. this.settings_folder = fb.ProfilePath + "wsh_settings\\";
  1454. this.artist = "";
  1455. this.artist_tf = "%artist%";
  1456. this.normal_font_size = window.GetProperty("2k3.normal_font_size", 14);
  1457. this.list_font_size = window.GetProperty("2k3.list_font_size", 11);
  1458. this.up_img = gdi.Image(this.ip + "buttons\\up.png");
  1459. this.down_img = gdi.Image(this.ip + "buttons\\down.png");
  1460. this.selection_mode = 1;
  1461. this.metadb_func = typeof on_metadb_changed == "function";
  1462. this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  1463. this.features_init();
  1464. this.colours_changed();
  1465. this.font_changed();
  1466. }
  1467.  
  1468. function artreader(x, y, w, h) {
  1469. this.draw = function(gr) {
  1470. if (!this.img) return;
  1471. p.draw_image(gr, this.img, this.x, this.y, this.w, this.h, this.type);
  1472. }
  1473.  
  1474. this.metadb_changed = function() {
  1475. if (!p.metadb) return;
  1476. this.img && this.img.Dispose();
  1477. this.path = "";
  1478. this.img = utils.GetAlbumArtV2(p.metadb, this.id);
  1479. window.RepaintRect(this.x, this.y, this.w, this.h);
  1480. utils.GetAlbumArtAsync(window.ID, p.metadb, this.id);
  1481. }
  1482.  
  1483. this.get_album_art_done = function(p) {
  1484. this.path = p;
  1485. }
  1486.  
  1487. this.trace = function(x, y) {
  1488. return x > this.x && x < this.x + this.w && y > this.y && y < this.y + this.h;
  1489. }
  1490.  
  1491. this.wheel = function(s) {
  1492. if (!this.trace(p.mx, p.my)) return false;
  1493. this.id -= s;
  1494. if (this.id < 0) this.id = 4;
  1495. if (this.id > 4) this.id = 0;
  1496. window.SetProperty("2k3.artreader_id", this.id);
  1497. p.item_focus_change();
  1498. return true;
  1499. }
  1500.  
  1501. this.move = function(x, y) {
  1502. if (this.trace(x, y)) {
  1503. if (this.img) p.tt("Original size: " + this.img.Width + "x" + this.img.Height + "px");
  1504. this.hover = true;
  1505. return true;
  1506. } else {
  1507. if (this.hover) p.tt("");
  1508. this.hover = false;
  1509. return false;
  1510. }
  1511. }
  1512.  
  1513. this.lbtn_dblclk = function(x, y) {
  1514. switch(true) {
  1515. case !this.trace(x, y):
  1516. return false;
  1517. case this.path == p.metadb.path:
  1518. case this.dblclk == 1:
  1519. p.explorer(this.path);
  1520. break;
  1521. case this.path.is_file():
  1522. p.run("\"" + this.path + "\"");
  1523. break;
  1524. }
  1525. return true;
  1526. }
  1527.  
  1528. this.x = x;
  1529. this.y = y;
  1530. this.w = w;
  1531. this.h = h;
  1532. this.id = window.GetProperty("2k3.artreader_id", 0);
  1533. this.type = window.GetProperty("2k3.artreader_type", 0);
  1534. this.dblclk = window.GetProperty("2k3.artreader_dblclk", 0);
  1535. this.img = null;
  1536. this.path = null;
  1537. this.hover = false;
  1538. }
  1539.  
  1540. function buttons(type) {
  1541. this.draw = function(gr) {
  1542. for (i in this.buttons) {
  1543. this.buttons[i].draw(gr);
  1544. }
  1545. }
  1546.  
  1547. this.move = function(x, y) {
  1548. this.tmp_btn = null;
  1549. for (i in this.buttons) {
  1550. if (this.buttons[i].trace(x, y)) this.tmp_btn = i;
  1551. }
  1552. if (this.btn == this.tmp_btn) return this.btn;
  1553. if (this.tmp_btn) this.buttons[this.tmp_btn].cs("hover");
  1554. if (this.btn) this.buttons[this.btn].cs("normal");
  1555. this.btn = this.tmp_btn;
  1556. if (!this.btn) p.tt("");
  1557. return this.btn;
  1558. }
  1559.  
  1560. this.lbtn_up = function(x, y) {
  1561. if (!this.btn) return false;
  1562. this.buttons[this.btn].lbtn_up(x, y);
  1563. return true;
  1564. }
  1565.  
  1566. this.leave = function() {
  1567. if (this.btn) this.buttons[this.btn].cs("normal");
  1568. this.btn = null;
  1569. }
  1570.  
  1571. var i;
  1572. this.buttons = [];
  1573. this.btn = null;
  1574. if (type == "playback") {
  1575. this.images = {
  1576. play: gdi.Image(p.ip + "buttons\\play.png"),
  1577. stop: gdi.Image(p.ip + "buttons\\stop.png"),
  1578. pause: gdi.Image(p.ip + "buttons\\pause.png"),
  1579. previous: gdi.Image(p.ip + "buttons\\previous.png"),
  1580. next: gdi.Image(p.ip + "buttons\\next.png"),
  1581. preferences: gdi.Image(p.ip + "buttons\\preferences.png"),
  1582. search: gdi.Image(p.ip + "buttons\\search.png"),
  1583. help: gdi.Image(p.ip + "buttons\\help.png")
  1584. }
  1585. }
  1586. }
  1587.  
  1588. function button(x, y, w, h, img_src, func, tiptext, themed) {
  1589. this.draw = function (gr) {
  1590. if (this.themed) {
  1591. p.themed_button.SetPartAndStateId(1, this.id);
  1592. p.themed_button.DrawThemeBackground(gr, this.x, this.y, this.w, this.h);
  1593. 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);
  1594. } else {
  1595. this.img && p.draw_image(gr, this.img, this.x, this.y, this.w, this.h);
  1596. }
  1597. }
  1598.  
  1599. this.trace = function(x, y) {
  1600. return x > this.x && x < this.x + this.w && y > this.y && y < this.y + this.h;
  1601. }
  1602.  
  1603. this.lbtn_up = function () {
  1604. this.func && this.func(x, y);
  1605. }
  1606.  
  1607. this.cs = function(s) {
  1608. if (s == "hover") {
  1609. this.img = this.img_hover;
  1610. this.id = 2;
  1611. p.tt(this.tiptext);
  1612. } else {
  1613. this.img = this.img_normal;
  1614. this.id = 0;
  1615. }
  1616. window.RepaintRect(this.x, this.y, this.w, this.h);
  1617. }
  1618.  
  1619. this.x = x;
  1620. this.y = y;
  1621. this.w = w;
  1622. this.h = h;
  1623. this.func = func;
  1624. this.tiptext = tiptext;
  1625. this.themed = themed;
  1626. this.id = 0;
  1627. this.img_normal = img_src.normal;
  1628. this.img_hover = img_src.hover || this.img_normal;
  1629. this.img = this.img_normal;
  1630. }
  1631.  
  1632. function cd(x, y, w, h) {
  1633. this.draw = function(gr) {
  1634. if (this.shadow) p.draw_image(gr, this.shadow_img, this.x, this.y, this.w, this.h);
  1635. p.draw_image(gr, this.case_img, this.x, this.y, this.w, this.h);
  1636. if (this.img) {
  1637. this.ratio = Math.min(this.w / this.case_img.Width, this.h / this.case_img.Height);
  1638. this.nw = 488 * this.ratio;
  1639. this.nh = 476 * this.ratio;
  1640. this.nx = Math.round((this.w - (452 * this.ratio)) / 2);
  1641. this.ny = Math.round((this.h - this.nh) / 2);
  1642. p.draw_image(gr, this.img, this.nx + this.x, this.ny + this.y, this.nw, this.nh, 1);
  1643. }
  1644. p.draw_image(gr, this.semi_img, this.x, this.y, this.w, this.h);
  1645. if (this.gloss) p.draw_image(gr, this.gloss_img, this.x, this.y, this.w, this.h);
  1646. }
  1647.  
  1648. this.metadb_changed = function() {
  1649. if (!p.metadb) return;
  1650. this.img && this.img.Dispose();
  1651. this.path = "";
  1652. this.img = utils.GetAlbumArtV2(p.metadb, 0);
  1653. window.Repaint();
  1654. utils.GetAlbumArtAsync(window.ID, p.metadb, 0);
  1655. }
  1656.  
  1657. this.get_album_art_done = function(ip) {;
  1658. this.path = ip;
  1659. }
  1660.  
  1661. this.trace = function(x, y) {
  1662. return x > this.x && x < this.x + this.w && y > this.y && y < this.y + this.h;
  1663. }
  1664.  
  1665. this.move = function(x, y) {
  1666. if (this.trace(x, y)) {
  1667. if (this.img) p.tt("Original size: " + this.img.Width + "x" + this.img.Height + "px");
  1668. this.hover = true;
  1669. return true;
  1670. } else {
  1671. if (this.hover) p.tt("");
  1672. this.hover = false;
  1673. return false;
  1674. }
  1675. }
  1676.  
  1677. this.lbtn_dblclk = function(x, y) {
  1678. switch(true) {
  1679. case !this.trace(x, y):
  1680. return false;
  1681. case this.path == p.metadb.path:
  1682. case this.dblclk == 1:
  1683. p.explorer(this.path);
  1684. break;
  1685. case this.path.is_file():
  1686. p.run("\"" + this.path + "\"");
  1687. break;
  1688. }
  1689. return true;
  1690. }
  1691.  
  1692. this.x = x;
  1693. this.y = y;
  1694. this.w = w;
  1695. this.h = h;
  1696. this.shadow_img = gdi.Image(p.ip + "cd\\shadow.png");
  1697. this.case_img = gdi.Image(p.ip + "cd\\case.png");
  1698. this.semi_img = gdi.Image(p.ip + "cd\\semi.png");
  1699. this.gloss_img = gdi.Image(p.ip + "cd\\gloss.png");
  1700. this.gloss = window.GetProperty("2k3.cd_gloss", false);
  1701. this.shadow = window.GetProperty("2k3.cd_shadow", false);
  1702. this.dblclk = window.GetProperty("2k3.cd_dblclk", 0);
  1703. this.img = null;
  1704. this.path = null;
  1705. this.hover = false;
  1706. }
  1707.  
  1708. function lastfm() {
  1709. this.notify_data = function() {
  1710. this.username = p.open(this.username_file).trim();
  1711. this.sk = p.open(this.sk_file).trim();
  1712. if (typeof li == "object" && li.mode == "lastfm_charts") li.update();
  1713. if (typeof ps == "object") {
  1714. ps.loved_working = false;
  1715. ps.playcount_working = false;
  1716. if (p.metadb) p.item_focus_change();
  1717. else ps.update_button();
  1718. }
  1719. window.Repaint();
  1720. }
  1721.  
  1722. this.post = function(method, metadb) {
  1723. switch(method) {
  1724. case "auth.getMobileSession":
  1725. var func = function() {
  1726. var data = p.json_parse(l.xmlhttp.responsetext);
  1727. if (!data) return;
  1728. if (data.error) {
  1729. p.MsgBox(data.message, 0, p.name);
  1730. } else if (data.session && data.session.key.length == 32) {
  1731. p.MsgBox("Your password was verified successfully. It will not be saved anywhere.", 0, p.name);
  1732. p.save(data.session.key, l.sk_file, 0);
  1733. window.NotifyOthers("lastfm", "update");
  1734. l.notify_data();
  1735. }
  1736. }
  1737.  
  1738. this.authToken = md5(this.username + md5(this.password));
  1739. this.api_sig = md5("api_key" + this.api_key + "authToken" + this.authToken + "method" + method + "username" + this.username + this.secret);
  1740. this.data = "method=" + method + "&api_key=" + this.api_key + "&api_sig=" + this.api_sig + "&format=json&authToken=" + this.authToken + "&username=" + this.username;
  1741. break;
  1742. case "track.love":
  1743. case "track.unlove":
  1744. var func = function() {
  1745. var data = p.json_parse(l.xmlhttp.responsetext);
  1746. if (!data) return;
  1747. if (data.error) {
  1748. p.console(data.message);
  1749. } else if (data.status && data.status == "ok") {
  1750. p.console("Track " + (method == "track.love" ? "loved successfully." : "unloved successfully."));
  1751. fb.RunContextCommandWithMetadb("Customdb Love " + (method == "track.love" ? 1 : 0), metadb, 8);
  1752. }
  1753. }
  1754.  
  1755. if (!ps.check_component || !metadb || this.username.length == 0 || this.sk.length != 32) return;
  1756. this.artist = tf(p.artist_tf, metadb);
  1757. this.track = tf("%title%", metadb);
  1758. if (this.artist == "" || this.artist == "?") return;
  1759. p.console("Attempting to " + (method == "track.love" ? "love \"" : "unlove \"") + this.track + "\" by \"" + this.artist + "\"");
  1760. p.console("Contacting Last.fm....");
  1761. this.api_sig = md5("api_key" + this.api_key + "artist" + this.artist + "method" + method + "sk" + this.sk + "track" + this.track + this.secret);
  1762. 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);
  1763. break;
  1764. default:
  1765. return;
  1766. }
  1767.  
  1768. this.xmlhttp.open("POST", "https://ws.audioscrobbler.com/2.0/", true);
  1769. this.xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  1770. this.xmlhttp.setRequestHeader("User-Agent", this.ua);
  1771. this.xmlhttp.send(this.data);
  1772. this.xmlhttp.onreadystatechange = function() {
  1773. if (l.xmlhttp.readyState == 4) {
  1774. if (l.xmlhttp.status == 200) {
  1775. func();
  1776. } else {
  1777. p.console(l.xmlhttp.responsetext || "HTTP error: " + l.xmlhttp.status);
  1778. }
  1779. }
  1780. }
  1781. }
  1782.  
  1783. this.update_username = function() {
  1784. var old_username = this.username;
  1785. this.username = p.InputBox("Enter your Last.fm username", p.name, this.username);
  1786. if (this.username != old_username) {
  1787. p.save(this.username, this.username_file);
  1788. p.save("", this.sk_file, 0);
  1789. window.NotifyOthers("lastfm", "update");
  1790. this.notify_data();
  1791. }
  1792. }
  1793.  
  1794. this.update_password = function() {
  1795. this.password = p.InputBox("Enter your Last.fm password", p.name, "");
  1796. if (this.password.length > 0) {
  1797. this.sk = "";
  1798. p.save(this.sk, this.sk_file, 0);
  1799. window.NotifyOthers("lastfm", "update");
  1800. this.notify_data();
  1801. this.post("auth.getMobileSession");
  1802. }
  1803. }
  1804.  
  1805. this.get_url = function() {
  1806. var url = "http://ws.audioscrobbler.com/2.0/?format=json&api_key=" + this.api_key + "&s=" + Math.random();
  1807. if (this.need_username) url += "&user=" + this.username + "&username=" + this.username;
  1808. return url;
  1809. }
  1810.  
  1811. this.username_error = "Use the right click menu to set your Last.fm username.";
  1812. this.password_error = "Use the right click menu to set your Last.fm password.";
  1813. this.api_key = "56d9e050cc2d6b36102c8b4a5fe6152d";
  1814. this.secret = "9f1f4346ce3ba206390074ff8cb4c6ce";
  1815. this.ua = "foobar2000_wsh_panel_mod_lastfm";
  1816. this.username_file = p.settings_folder + "username";
  1817. this.username = p.open(this.username_file).trim();
  1818. this.sk_file = p.settings_folder + "sk";
  1819. this.sk = p.open(this.sk_file).trim();
  1820. this.auto_correct = window.GetProperty("2k3.lastfm_auto_correct", true);
  1821. this.need_username = false;
  1822. this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  1823. }
  1824.  
  1825. function list(mode, x, y, w, h) {
  1826. this.size = function() {
  1827. this.row_height = this.mode == "echonest" ? 90 : 20;
  1828. this.rows = Math.floor((this.h - 30) / this.row_height);
  1829. this.index = 0;
  1830. this.offset = 0;
  1831. switch(true) {
  1832. case this.mode == "lastfm_charts":
  1833. this.text_width = Math.round(this.w / 3);
  1834. this.lastfm_charts_bar_x = this.text_width + 40;
  1835. break;
  1836. case this.mode == "musicbrainz" && this.mbs["2k3.musicbrainz_releases"]:
  1837. this.text_width = this.w - 130;
  1838. break;
  1839. default:
  1840. this.text_width = this.w - 50;
  1841. break;
  1842. }
  1843. var but_x = this.x + Math.round((this.w - 15) / 2);
  1844. this.up_btn = new sb(but_x, this.y, 15, 15, p.up_img, "li.offset > 0", function() { li.wheel(1); });
  1845. 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); });
  1846. }
  1847.  
  1848. this.draw = function(gr) {
  1849. switch(this.mode) {
  1850. case "autoplaylists":
  1851. for (i = 0; i < Math.min(this.items, this.rows); i++) {
  1852. 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);
  1853. if (!this.autoplaylists_editing && this.autoplaylists_hover && this.index == i + this.offset) {
  1854. p.draw_image(gr, this.autoplaylists_edit_img, this.x + this.w - 40, this.y + 16 + (i * this.row_height), 16, 16);
  1855. p.draw_image(gr, this.autoplaylists_del_img, this.x + this.w - 20, this.y + 16 + (i * this.row_height), 16, 16);
  1856. }
  1857. }
  1858. break;
  1859. case "echonest":
  1860. for (i = 0; i < Math.min(this.items, this.rows); i++) {
  1861. 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);
  1862. 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);
  1863. 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);
  1864. }
  1865. break;
  1866. case "lastfm":
  1867. for (i = 0; i < Math.min(this.items, this.rows); i++) {
  1868. 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);
  1869. }
  1870. break;
  1871. case "lastfm_charts":
  1872. var max_bar_width = (this.w - this.lastfm_charts_bar_x - 50) / this.playcounts[0];
  1873. for (i = 0; i < Math.min(this.items, this.rows); i++) {
  1874. 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);
  1875. var bar_width = max_bar_width * this.playcounts[i + this.offset];
  1876. var bar_colour = p.splitRGB(this.lastfm_charts_bar_colour);
  1877. gr.FillSolidRect(this.lastfm_charts_bar_x + this.x, this.y + 16 + (i * this.row_height), bar_width, 18, bar_colour);
  1878. 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);
  1879. 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);
  1880. }
  1881. break;
  1882. case "musicbrainz":
  1883. this.text_x = !this.mbs["2k3.musicbrainz_releases"] && this.mbs["2k3.musicbrainz_show_icons"] ? 20 : 0;
  1884. for (i = 0; i < Math.min(this.items, this.rows); i++) {
  1885. if (this.mbs["2k3.musicbrainz_releases"]) {
  1886. 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);
  1887. 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);
  1888. } else {
  1889. 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);
  1890. }
  1891. 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);
  1892. }
  1893. break;
  1894. case "properties":
  1895. for (i = 0; i < Math.min(this.items, this.rows); i++) {
  1896. 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);
  1897. 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);
  1898. }
  1899. break;
  1900. }
  1901. this.up_btn.draw(gr);
  1902. this.down_btn.draw(gr);
  1903. }
  1904.  
  1905. this.metadb_changed = function() {
  1906. if (!p.metadb) return false;
  1907. if (this.mode != "properties") {
  1908. p.artist = p.eval(p.artist_tf);
  1909. if (this.artist == p.artist) return false;
  1910. this.artist = p.artist;
  1911. this.folder = p.new_artist_folder(this.artist);
  1912. }
  1913. this.update();
  1914. return true;
  1915. }
  1916.  
  1917. this.trace = function(x, y) {
  1918. return x > this.x && x < this.x + this.w && y > this.y && y < this.y + this.h;
  1919. }
  1920.  
  1921. this.wheel = function(s) {
  1922. if (!this.trace(p.mx, p.my)) return false;
  1923. if (this.items > this.rows) {
  1924. this.offset -= s * (this.mode == "echonest" ? 1 : 5);
  1925. if (this.offset < 0) this.offset = 0;
  1926. if (this.rows + this.offset > this.items) this.offset = this.items - this.rows;
  1927. window.RepaintRect(this.x, this.y, this.w, this.h);
  1928. }
  1929. return true;
  1930. }
  1931.  
  1932. this.move = function(x, y) {
  1933. this.index = Math.floor((y - this.y - 15) / this.row_height) + this.offset;
  1934. this.in_range = this.index >= this.offset && this.index < this.offset + Math.min(this.rows, this.items);
  1935. switch(true) {
  1936. case !this.trace(x, y):
  1937. case this.mode == "autoplaylists" && this.autoplaylists_editing:
  1938. window.SetCursor(IDC_ARROW);
  1939. this.leave();
  1940. return false;
  1941. case this.up_btn.trace(x, y):
  1942. case this.down_btn.trace(x, y):
  1943. window.SetCursor(IDC_HAND);
  1944. break;
  1945. case !this.in_range:
  1946. window.SetCursor(IDC_ARROW);
  1947. this.leave();
  1948. break;
  1949. case this.mode == "autoplaylists":
  1950. switch(true) {
  1951. case x > this.x && x < this.x + Math.min(this.names_widths[this.index], this.text_width):
  1952. window.SetCursor(IDC_HAND);
  1953. p.tt('Run "' + this.names[this.index] + '"');
  1954. break;
  1955. case x > this.x + this.w - 40 && x < this.x + this.w - 20:
  1956. window.SetCursor(IDC_HAND);
  1957. p.tt('Edit "' + this.names[this.index] + '"');
  1958. break;
  1959. case x > this.x + this.w - 20 && x < this.x + this.w:
  1960. window.SetCursor(IDC_HAND);
  1961. p.tt('Delete "' + this.names[this.index] + '"');
  1962. break;
  1963. default:
  1964. window.SetCursor(IDC_ARROW);
  1965. p.tt("");
  1966. this.leave();
  1967. break;
  1968. }
  1969. this.autoplaylists_hover = true;
  1970. window.RepaintRect(this.x + this.w - 40, this.y + 15, 40, Math.min(this.rows, this.items) * this.row_height);
  1971. break;
  1972. case this.mode == "echonest":
  1973. case x > this.x + this.text_x && x < this.x + this.text_x + Math.min(this.names_widths[this.index], this.text_width):
  1974. window.SetCursor(IDC_HAND);
  1975. switch(true) {
  1976. case this.mode == "lastfm" && this.lastfm_mode != 2 && !this.lastfm_link:
  1977. case this.mode == "lastfm_charts" && !this.lastfm_link:
  1978. case this.mode == "properties":
  1979. p.tt("Autoplaylist: " + this.queries[this.index]);
  1980. break;
  1981. default:
  1982. p.tt(this.urls[this.index]);
  1983. break;
  1984. }
  1985. break;
  1986. default:
  1987. window.SetCursor(IDC_ARROW);
  1988. p.tt("");
  1989. break;
  1990. }
  1991. return true;
  1992. }
  1993.  
  1994. this.lbtn_up = function(x, y) {
  1995. switch(true) {
  1996. case !this.trace(x, y):
  1997. return false;
  1998. case this.mode == "autoplaylists" && this.autoplaylists_editing:
  1999. case this.up_btn.lbtn_up(x, y):
  2000. case this.down_btn.lbtn_up(x, y):
  2001. case !this.in_range:
  2002. break;
  2003. case this.mode == "autoplaylists":
  2004. switch(true) {
  2005. case x > this.x && x < this.x + Math.min(this.names_widths[this.index], this.text_width):
  2006. this.autoplaylists_run(this.names[this.index], this.queries[this.index], this.sorts[this.index], this.forced[this.index]);
  2007. break;
  2008. case x > this.x + this.w - 40 && x < this.x + this.w - 20:
  2009. this.autoplaylists_edit(x, y);
  2010. break;
  2011. case x > this.x + this.w - 20 && x < this.x + this.w:
  2012. this.autoplaylists_delete();
  2013. break;
  2014. }
  2015. break;
  2016. case this.mode == "echonest":
  2017. case x > this.x + this.text_x && x < this.x + this.text_x + Math.min(this.names_widths[this.index], this.text_width):
  2018. switch(true) {
  2019. case this.mode == "lastfm" && this.lastfm_mode != 2 && !this.lastfm_link:
  2020. case this.mode == "lastfm_charts" && !this.lastfm_link:
  2021. case this.mode == "properties":
  2022. fb.CreateAutoPlaylist(fb.PlaylistCount, this.names[this.index], this.queries[this.index]);
  2023. fb.ActivePlaylist = fb.PlaylistCount - 1;
  2024. break;
  2025. default:
  2026. p.browser(this.urls[this.index]);
  2027. break;
  2028. }
  2029. break;
  2030. }
  2031. return true;
  2032. }
  2033.  
  2034. this.leave = function() {
  2035. if (this.mode == "autoplaylists") {
  2036. this.autoplaylists_hover = false;
  2037. window.RepaintRect(this.x, this.y, this.w, this.h);
  2038. }
  2039. }
  2040.  
  2041. this.update = function() {
  2042. this.items = 0;
  2043. this.offset = 0;
  2044. this.index = 0;
  2045. var temp_bmp = gdi.CreateImage(1, 1);
  2046. var temp_gr = temp_bmp.GetGraphics();
  2047. switch(this.mode) {
  2048. case "autoplaylists":
  2049. this.data = [];
  2050. this.names = [];
  2051. this.queries = [];
  2052. this.sorts = [];
  2053. this.forced = [];
  2054. this.names_widths = [];
  2055. var text = p.open(this.filename);
  2056. if (text.length > 0) this.data = text.split(/\r?\n/g);
  2057. for (i in this.data) {
  2058. var temp = this.data[i].split("¬");
  2059. this.names[i] = temp[0];
  2060. this.queries[i] = temp[1];
  2061. this.sorts[i] = temp[2];
  2062. this.forced[i] = temp[3];
  2063. this.names_widths[i] = temp_gr.CalcTextWidth(this.names[i], p.list_font);
  2064. }
  2065. this.items = this.data.length;
  2066. break;
  2067. case "echonest":
  2068. this.names = [];
  2069. this.urls = [];
  2070. this.dates = [];
  2071. this.summaries = [];
  2072. this.filename = this.folder + "echonest_" + this.echonest_modes[this.echonest_mode] + ".json";
  2073. if (this.filename.is_file()) {
  2074. var temp_date;
  2075. var data = p.json_parse(p.open(this.filename), "response." + this.echonest_modes[this.echonest_mode]);
  2076. for (i in data) {
  2077. this.names[i] = p.strip_tags(data[i].name).replace(/\s{2,}/g,' ');
  2078. this.urls[i] = (data[i].url || "").replace(/\\/g, "");
  2079. temp_date = (data[i].date_posted || data[i].date_reviewed || data[i].date_found || "").substring(0, 10);
  2080. this.dates[i] = temp_date.substring(8,10) + "-" + temp_date.substring(5,7) + "-" + temp_date.substring(0,4);
  2081. this.summaries[i] = p.strip_tags(data[i].summary);
  2082. }
  2083. this.items = data.length;
  2084. if (this.filename.expired(ONE_DAY)) this.get();
  2085. } else {
  2086. this.get();
  2087. }
  2088. break;
  2089. case "lastfm":
  2090. this.names = [];
  2091. this.names_widths = [];
  2092. this.urls = [];
  2093. this.queries = [];
  2094. this.filename = this.folder + this.lastfm_methods[this.lastfm_mode] + ".json";
  2095. if (this.filename.is_file()) {
  2096. var data = p.json_parse(p.open(this.filename), this.lastfm_json[this.lastfm_mode]);
  2097. var query_text = this.lastfm_queries[this.lastfm_mode] + " HAS ";
  2098. if (typeof data.length == "undefined") data = [data];
  2099. for (i in data) {
  2100. this.names[i] = data[i].name;
  2101. this.names_widths[i] = temp_gr.CalcTextWidth(this.names[i], p.list_font);
  2102. this.urls[i] = data[i].url;
  2103. if (this.lastfm_mode != 2) this.queries[i] = query_text + data[i].name;
  2104. }
  2105. this.items = data.length;
  2106. if (this.filename.expired(ONE_DAY)) this.get();
  2107. } else {
  2108. this.get();
  2109. }
  2110. break;
  2111. case "lastfm_charts":
  2112. this.names = [];
  2113. this.names_widths = [];
  2114. this.urls = [];
  2115. this.queries = [];
  2116. this.ranks = [];
  2117. this.playcounts = [];
  2118. this.filename = this.folder + l.username + "_" + this.lastfm_charts_modes[this.lastfm_charts_mode] + "_" + this.lastfm_charts_periods[this.lastfm_charts_period] + ".json";
  2119. if (this.filename.is_file()) {
  2120. var data = p.json_parse(p.open(this.filename), this.lastfm_charts_json[this.lastfm_charts_mode]);
  2121. var query_text = this.lastfm_charts_queries[this.lastfm_charts_mode] + " HAS ";
  2122. if (typeof data.length == "undefined") data = [data];
  2123. for (i in data) {
  2124. this.names[i] = this.lastfm_charts_mode == 0 ? data[i].name : data[i].name + " - " + data[i].artist.name;
  2125. this.names_widths[i] = temp_gr.CalcTextWidth(this.names[i], p.list_font);
  2126. this.urls[i] = data[i].url;
  2127. this.queries[i] = query_text + data[i].name;
  2128. this.playcounts[i] = data[i].playcount;
  2129. this.ranks[i] = i > 0 && this.playcounts[i] == this.playcounts[i - 1] ? this.ranks[i - 1] : data[i]["@attr"].rank;
  2130. }
  2131. this.items = data.length;
  2132. if (this.filename.expired(ONE_DAY)) this.get();
  2133. } else {
  2134. this.get();
  2135. }
  2136. break;
  2137. case "musicbrainz":
  2138. this.names = [];
  2139. this.names_widths = [];
  2140. this.urls = [];
  2141. this.dates = [];
  2142. this.release_types = [];
  2143. this.images = [];
  2144. this.mb_temp = [];
  2145. this.page = 1;
  2146. this.filename = this.folder + "musicbrainz_" + (this.mbs["2k3.musicbrainz_releases"] ? "releases1.json" : "links.json");
  2147. if (this.filename.is_file()) {
  2148. if (this.mbs["2k3.musicbrainz_releases"]) {
  2149. p.delete_file(this.folder + "musicbrainz_releases.json");
  2150. var data = p.json_parse(p.open(this.filename), "", "first-release-date", this.mbs["2k3.musicbrainz_newest_first"]);
  2151. var primary, secondary, name;
  2152. for (i in data) {
  2153. primary = data[i]["primary-type"];
  2154. secondary = data[i]["secondary-types"].join("").toLowerCase();
  2155. switch(true) {
  2156. case !this.mbs["2k3.musicbrainz_remix"] && secondary.indexOf("remix") > -1:
  2157. case !this.mbs["2k3.musicbrainz_compilation"] && secondary.indexOf("compilation") > -1:
  2158. case !this.mbs["2k3.musicbrainz_live"] && secondary.indexOf("live") > -1:
  2159. break;
  2160. case this.mbs["2k3.musicbrainz_other"] && (primary == null || primary == "Other" || primary == "Broadcast"):
  2161. case this.mbs["2k3.musicbrainz_single"] && primary == "Single":
  2162. case this.mbs["2k3.musicbrainz_ep"] && primary == "EP":
  2163. case this.mbs["2k3.musicbrainz_album"] && primary == "Album":
  2164. name = data[i].title;
  2165. this.names.push(name);
  2166. this.names_widths.push(temp_gr.CalcTextWidth(name, p.list_font));
  2167. this.urls.push("http://musicbrainz.org/release-group/" + data[i].id);
  2168. this.dates.push(data[i]["first-release-date"].substring(0,4));
  2169. switch(true) {
  2170. case secondary.indexOf("remix") > -1:
  2171. this.release_types.push("Remix");
  2172. break;
  2173. case secondary.indexOf("compilation") > -1:
  2174. this.release_types.push("Compilation");
  2175. break;
  2176. case secondary.indexOf("live") > -1:
  2177. this.release_types.push("Live");
  2178. break;
  2179. default:
  2180. this.release_types.push(primary || "Unknown");
  2181. break;
  2182. }
  2183. }
  2184. }
  2185. this.items = this.names.length;
  2186. } else {
  2187. var data = p.json_parse(p.open(this.filename), "relations");
  2188. for (i in data) {
  2189. this.urls[i] = data[i].url.resource;
  2190. this.images[i] = "external";
  2191. if (data[i].type == "official homepage") {
  2192. this.images[i] = "home";
  2193. } else {
  2194. for (var name in this.musicbrainz_images) {
  2195. if (this.urls[i].indexOf(name) > -1) {
  2196. this.images[i] = name;
  2197. break;
  2198. }
  2199. }
  2200. }
  2201. this.names[i] = this.urls[i];
  2202. this.names_widths[i] = temp_gr.CalcTextWidth(this.names[i], p.list_font);
  2203. }
  2204. this.items = data.length;
  2205. }
  2206. if (this.filename.expired(ONE_DAY)) this.get();
  2207. } else {
  2208. this.get();
  2209. }
  2210. break;
  2211. case "properties":
  2212. this.names = [];
  2213. this.names_widths = [];
  2214. this.urls = [];
  2215. this.queries = [];
  2216. this.img = false;
  2217. this.filename = p.metadb.Path;
  2218. var fileinfo = p.metadb.GetFileInfo();
  2219. var name;
  2220. for (i = 0; i < fileinfo.MetaCount; i++) {
  2221. name = fileinfo.MetaName(i);
  2222. this.names[i] = name.toUpperCase();
  2223. this.urls[i] = p.eval("$meta(" + name + ")").replace(/\s{2,}/g,' ');
  2224. this.queries[i] = this.names[i].toLowerCase() + " IS " + this.urls[i];
  2225. }
  2226. this.names = this.names.concat(["", "PATH", "FILE SIZE", "LAST MODIFIED", "", "DURATION"]);
  2227. this.urls = this.urls.concat(["", p.metadb.Path, p.eval("[%filesize_natural%]"), p.eval("[%last_modified%]"), "", p.eval("[%length%]")]);
  2228. 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%]")]);
  2229. for (i = 0; i < fileinfo.InfoCount; i++) {
  2230. name = fileinfo.InfoName(i);
  2231. this.names.push(name.toUpperCase());
  2232. this.urls.push(p.eval("%__" + name + "%"));
  2233. this.queries.push("%__" + name + "%" + " IS " + p.eval("%__" + name + "%"));
  2234. }
  2235. for (i in this.names) {
  2236. this.names_widths[i] = temp_gr.CalcTextWidth(this.urls[i], p.list_font);
  2237. }
  2238. fileinfo.Dispose();
  2239. this.items = this.names.length;
  2240. break;
  2241. }
  2242. temp_bmp.ReleaseGraphics(temp_gr);
  2243. temp_bmp.Dispose();
  2244. temp_gr = null;
  2245. temp_bmp = null;
  2246. window.Repaint();
  2247. }
  2248.  
  2249. this.get = function() {
  2250. var fn = this.filename;
  2251. var func = function() {
  2252. p.save(li.xmlhttp.responsetext, fn);
  2253. if (li.mode == "lastfm_charts") {
  2254. li.update();
  2255. } else {
  2256. li.artist = "";
  2257. p.item_focus_change();
  2258. }
  2259. }
  2260. switch(this.mode) {
  2261. case "echonest":
  2262. if (this.artist == "" || this.artist == "?") return;
  2263. var url = "http://developer.echonest.com/api/v4/artist/" + this.echonest_modes[this.echonest_mode] + "/?name=" + encodeURIComponent(this.artist) + "&api_key=EKWS4ESQLKN3G2ZWV";
  2264. break;
  2265. case "lastfm":
  2266. if (this.artist == "" || this.artist == "?") return;
  2267. var url = l.get_url() + "&method=" + this.lastfm_methods[this.lastfm_mode] + "&artist=" + encodeURIComponent(this.artist) + "&autocorrect=" + (l.auto_correct ? 1 : 0);
  2268. break;
  2269. case "lastfm_charts":
  2270. if (l.username.length == 0) return p.console(l.username_error);
  2271. var url = l.get_url() + "&method=user." + this.lastfm_charts_methods[this.lastfm_charts_mode] + "&period=" + this.lastfm_charts_periods[this.lastfm_charts_period];
  2272. break;
  2273. case "musicbrainz":
  2274. var fn1 = this.folder + "musicbrainz_artistid.txt";
  2275. this.musicbrainz_id = p.eval("$if3(%musicbrainz_artistid%,%musicbrainz artist id%,)");
  2276. this.musicbrainz_id = this.musicbrainz_id.substring(0, 36);
  2277. if (this.musicbrainz_id.length == 0) this.musicbrainz_id = p.open(fn1);
  2278. if (this.musicbrainz_id.length == 0) {
  2279. func = function() {
  2280. li.musicbrainz_save_id(li.xmlhttp.responsetext, fn1);
  2281. }
  2282.  
  2283. if (this.artist == "" || this.artist == "?") return;
  2284. var url = "https://musicbrainz.org/ws/2/artist/?query=artist:" + encodeURIComponent(this.musicbrainz_escape(this.artist)) + "&fmt=json";
  2285. } else {
  2286. if (this.mbs["2k3.musicbrainz_releases"]) {
  2287. var func = function() {
  2288. var data = p.json_parse(li.xmlhttp.responsetext);
  2289. var count = data["release-group-count"];
  2290. var pages = Math.min(5, Math.ceil(count / 100));
  2291. li.mb_temp = li.mb_temp.concat(data["release-groups"]);
  2292. if (count == 0 || li.page == pages) {
  2293. p.save(JSON.stringify(li.mb_temp), fn);
  2294. li.artist = "";
  2295. p.item_focus_change();
  2296. } else {
  2297. li.page++;
  2298. li.get();
  2299. }
  2300. }
  2301.  
  2302. var url = "https://musicbrainz.org/ws/2/release-group?artist=" + this.musicbrainz_id + "&limit=100&offset=" + ((this.page - 1) * 100) + "&fmt=json";
  2303. } else {
  2304. var url = "https://musicbrainz.org/ws/2/artist/" + this.musicbrainz_id + "?inc=url-rels&fmt=json";
  2305. }
  2306. }
  2307. break;
  2308. default:
  2309. return;
  2310. }
  2311. this.xmlhttp.open("GET", url, true);
  2312. this.xmlhttp.setRequestHeader("User-Agent", this.ua);
  2313. this.xmlhttp.send();
  2314. this.xmlhttp.onreadystatechange = function() {
  2315. if (li.xmlhttp.readyState == 4) {
  2316. if (li.xmlhttp.status == 200) {
  2317. func();
  2318. } else {
  2319. p.console(li.xmlhttp.responsetext || "HTTP error: " + li.xmlhttp.status);
  2320. }
  2321. }
  2322. }
  2323. }
  2324.  
  2325. this.header_text = function() {
  2326. switch(this.mode) {
  2327. case "autoplaylists":
  2328. return this.autoplaylists_title;
  2329. case "echonest":
  2330. return this.artist + ": " + this.echonest_modes[this.echonest_mode];
  2331. case "lastfm":
  2332. return this.artist + ": " + this.lastfm_modes[this.lastfm_mode];
  2333. case "lastfm_charts":
  2334. return l.username + ": " + this.lastfm_charts_periods_display[this.lastfm_charts_period] + " " + this.lastfm_charts_modes[this.lastfm_charts_mode] + " charts";
  2335. case "musicbrainz":
  2336. return this.artist + ": " + (this.mbs["2k3.musicbrainz_releases"] ? "releases" : "links");
  2337. case "properties":
  2338. return p.eval("%artist% - %title%");
  2339. }
  2340. }
  2341.  
  2342. this.init = function() {
  2343. switch(this.mode) {
  2344. case "autoplaylists":
  2345. this.autoplaylists_add = function() {
  2346. if (this.autoplaylists_editing) return;
  2347. this.autoplaylists_editing = true;
  2348. var new_name = p.InputBox("Enter a name for your autoplaylist", p.name, "");
  2349. if (new_name == "") return this.autoplaylists_editing = false;
  2350. var new_query = p.InputBox("Enter your autoplaylist query", p.name, "");
  2351. if (new_query == "") return this.autoplaylists_editing = false;
  2352. var new_sort = p.InputBox("Enter a sort pattern\n\n(optional)", p.name, "");
  2353. var new_force = new_sort.length > 0 ? p.MsgBox("Force sort?", 4, p.name) : 7;
  2354. this.data.push(new_name + "¬" + new_query + "¬" + new_sort + "¬" + new_force);
  2355. if (this.data.length > this.rows) this.offset = this.data.length - this.rows;
  2356. p.save(this.data.join("\n"), this.filename);
  2357. if (this.autoplaylists_success) this.autoplaylists_run(new_name, new_query, new_sort, new_force);
  2358. window.NotifyOthers("autoplaylists", "update");
  2359. this.update();
  2360. this.autoplaylists_editing = false;
  2361. }
  2362.  
  2363. this.autoplaylists_edit = function(x, y) {
  2364. var _menu = window.CreatePopupMenu();
  2365. var i = this.index;
  2366. _menu.AppendMenuItem(MF_STRING, 1, "Rename...");
  2367. _menu.AppendMenuItem(MF_STRING, 2, "Edit query...");
  2368. _menu.AppendMenuItem(MF_STRING, 3, "Edit sort pattern...");
  2369. _menu.AppendMenuItem(MF_STRING, 4, "Force Sort");
  2370. _menu.CheckMenuItem(4, this.forced[i] == 6);
  2371. this.autoplaylists_editing = true;
  2372. this.autoplaylists_hover = false;
  2373. window.RepaintRect(this.x + this.w - 40, this.y + 15, 40, Math.min(this.rows, this.items) * this.row_height);
  2374. var idx = _menu.TrackPopupMenu(x, y);
  2375. switch(idx) {
  2376. case 0:
  2377. this.autoplaylists_editing = false;
  2378. _menu.Dispose();
  2379. return;
  2380. case 1:
  2381. var new_name = p.InputBox("Rename your autoplaylist", p.name, this.names[i]);
  2382. if (new_name != "") this.names[i] = new_name;
  2383. break;
  2384. case 2:
  2385. var new_query = p.InputBox("Enter your autoplaylist query", p.name, this.queries[i]);
  2386. if (new_query != "") this.queries[i] = new_query;
  2387. break;
  2388. case 3:
  2389. var new_sort = p.InputBox("Enter a sort pattern\n\n(optional)", p.name, this.sorts[i]);
  2390. this.sorts[i] = new_sort;
  2391. this.forced[i] = new_sort.length > 0 ? p.MsgBox("Force sort?", 4, p.name) : 7;
  2392. break;
  2393. case 4:
  2394. this.forced[i] = this.forced[i] == 6 ? 7 : 6;
  2395. break;
  2396. }
  2397. _menu.Dispose();
  2398. var temp = this.names[i] + "¬" + this.queries[i] + "¬" + this.sorts[i] + "¬" + this.forced[i];
  2399. if (this.data[i] != temp) {
  2400. this.data[i] = temp;
  2401. p.save(this.data.join("\n"), this.filename);
  2402. if (this.autoplaylists_success) this.autoplaylists_run(this.names[i], this.queries[i], this.sorts[i], this.forced[i]);
  2403. window.NotifyOthers("autoplaylists", "update");
  2404. this.update();
  2405. }
  2406. this.autoplaylists_editing = false;
  2407. }
  2408.  
  2409. this.autoplaylists_delete = function() {
  2410. if (this.offset > 1) this.offset--;
  2411. this.autoplaylists_deleted_items.unshift(this.data[this.index]);
  2412. this.data.splice(this.index, 1);
  2413. p.save(this.data.join("\n"), this.filename);
  2414. window.NotifyOthers("autoplaylists", "update");
  2415. this.update();
  2416. }
  2417.  
  2418. this.autoplaylists_run = function(n, q, s, f) {
  2419. if (this.autoplaylists_remove_duplicates) {
  2420. var i = 0;
  2421. while(i < fb.PlaylistCount) {
  2422. if (fb.GetPlaylistName(i) == n) fb.RemovePlaylist(i);
  2423. else i++;
  2424. }
  2425. }
  2426. fb.CreateAutoPlaylist(fb.PlaylistCount, n, q, s, f == 6);
  2427. fb.ActivePlaylist = fb.PlaylistCount - 1;
  2428. }
  2429.  
  2430. this.autoplaylists_del_img = gdi.Image(p.ip + "misc\\cross2.png");
  2431. this.autoplaylists_edit_img = gdi.Image(p.ip + "misc\\edit.png");
  2432. this.autoplaylists_hover = false;
  2433. this.autoplaylists_editing = false;
  2434. this.autoplaylists_remove_duplicates = window.GetProperty("2k3.autoplaylists_remove_duplicates", true);
  2435. this.autoplaylists_success = window.GetProperty("2k3.autoplaylists_success", true);
  2436. this.autoplaylists_title = window.GetProperty("2k3.autoplaylists_title", "Autoplaylists");
  2437. this.autoplaylists_slot = window.GetProperty("2k3.autoplaylists_slot", 1);
  2438. this.filename = p.settings_folder + "autoplaylists" + this.autoplaylists_slot;
  2439. this.autoplaylists_deleted_items = [];
  2440. p.settings_folder.create();
  2441. break;
  2442. case "echonest":
  2443. this.echonest_modes = ["news", "reviews", "blogs"];
  2444. this.echonest_mode = window.GetProperty("2k3.echonest_mode", 0);
  2445. this.ua = "";
  2446. p.data_folder.create();
  2447. p.artists_folder.create();
  2448. break;
  2449. case "lastfm":
  2450. this.mode = "lastfm";
  2451. this.lastfm_json = ["similarartists.artist", "toptags.tag", "topfans.user", "topalbums.album", "toptracks.track"];
  2452. this.lastfm_queries = ["artist", "genre", "", "album", "title"];
  2453. this.lastfm_methods = ["artist.getSimilar", "artist.getTopTags", "artist.getTopFans", "artist.getTopAlbums", "artist.getTopTracks"];
  2454. this.lastfm_modes = ["similar artists", "top tags", "top fans", "top albums", "top tracks"];
  2455. this.lastfm_mode = window.GetProperty("2k3.lastfm_mode", 0);
  2456. this.lastfm_link = window.GetProperty("2k3.lastfm_link", true);
  2457. this.ua = l.ua;
  2458. p.data_folder.create();
  2459. p.artists_folder.create();
  2460. break;
  2461. case "lastfm_charts":
  2462. this.mode = "lastfm_charts";
  2463. this.text_x = 30;
  2464. this.lastfm_charts_json = ["topartists.artist", "topalbums.album", "toptracks.track"];
  2465. this.lastfm_charts_queries = ["artist", "album", "title"];
  2466. this.lastfm_charts_modes = ["artist", "album", "track"];
  2467. this.lastfm_charts_mode = window.GetProperty("2k3.lastfm_charts_mode", 0);
  2468. this.lastfm_charts_methods = ["getTopArtists", "getTopAlbums", "getTopTracks"];
  2469. this.lastfm_charts_periods_display = ["overall", "last 7 days", "1 month", "3 month", "6 month", "12 month"];
  2470. this.lastfm_charts_periods = ["overall", "7day", "1month", "3month", "6month", "12month"];
  2471. this.lastfm_charts_period = window.GetProperty("2k3.lastfm_charts_period", 0);
  2472. this.lastfm_charts_bar_colour = window.GetProperty("2k3.lastfm_charts_bar_colour", "72-127-221");
  2473. this.lastfm_link = window.GetProperty("2k3.lastfm_link", true);
  2474. l.need_username = true;
  2475. this.ua = l.ua;
  2476. this.folder = p.data_folder + "charts\\";
  2477. p.data_folder.create();
  2478. p.settings_folder.create();
  2479. this.folder.create();
  2480. break;
  2481. case "musicbrainz":
  2482. this.musicbrainz_save_id = function(t, f) {
  2483. var artist = li.musicbrainz_tidy(li.artist);
  2484. var data = p.json_parse(t, "artists");
  2485. for (i in data) {
  2486. if (artist == li.musicbrainz_tidy(data[i].name)) {
  2487. p.save(data[i].id, f, 0);
  2488. li.artist = "";
  2489. p.item_focus_change();
  2490. break;
  2491. }
  2492. }
  2493. }
  2494.  
  2495. this.musicbrainz_tidy = function(t) {
  2496. return t.replace(/’/g, "'").toLowerCase();
  2497. }
  2498.  
  2499. this.musicbrainz_escape = function(t) {
  2500. return t.replace(/[+!(){}\[\]^"~*?:\\\/-]/g, "\\$&");
  2501. }
  2502.  
  2503. this.musicbrainz_images = {
  2504. "viaf.org": gdi.Image(p.ip + "mb\\viaf_small.png"),
  2505. "allmusic.com": gdi.Image(p.ip + "mb\\allmusic_small.png"),
  2506. "external": gdi.Image(p.ip + "mb\\external_small.png"),
  2507. "bbc.co.uk": gdi.Image(p.ip + "mb\\bbc_small.png"),
  2508. "facebook.com": gdi.Image(p.ip + "mb\\facebook_small.png"),
  2509. "home": gdi.Image(p.ip + "mb\\home_small.png"),
  2510. "last.fm": gdi.Image(p.ip + "mb\\lastfm_small.png"),
  2511. "twitter.com": gdi.Image(p.ip + "mb\\twitter_small.png"),
  2512. "soundcloud.com": gdi.Image(p.ip + "mb\\soundcloud_small.png"),
  2513. "wikipedia.org": gdi.Image(p.ip + "mb\\wikipedia_small.png"),
  2514. "discogs.com": gdi.Image(p.ip + "mb\\discogs_small.png"),
  2515. "myspace.com": gdi.Image(p.ip + "mb\\myspace_small.png"),
  2516. "youtube.com": gdi.Image(p.ip + "mb\\youtube_small.png"),
  2517. "imdb.com": gdi.Image(p.ip + "mb\\imdb_small.png"),
  2518. "plus.google.com": gdi.Image(p.ip + "mb\\google_plus_small.png"),
  2519. "lyrics.wikia.com": gdi.Image(p.ip + "mb\\lyrics_wikia_small.png"),
  2520. "flickr.com": gdi.Image(p.ip + "mb\\flickr_small.png"),
  2521. "secondhandsongs.com": gdi.Image(p.ip + "mb\\secondhandsongs_small.png"),
  2522. "vimeo.com": gdi.Image(p.ip + "mb\\vimeo_small.png"),
  2523. "rateyourmusic.com": gdi.Image(p.ip + "mb\\rateyourmusic_small.png"),
  2524. "instagram.com": gdi.Image(p.ip + "mb\\instagram_small.png"),
  2525. "tumblr.com": gdi.Image(p.ip + "mb\\tumblr_small.png"),
  2526. "decoda.com": gdi.Image(p.ip + "mb\\decoda_small.png"),
  2527. "wikidata.org": gdi.Image(p.ip + "mb\\wikidata_small.png")
  2528. };
  2529.  
  2530. this.mb_set = function(s, v) {
  2531. this.mbs[s] = v;
  2532. window.SetProperty(s, v);
  2533. this.artist = "";
  2534. p.item_focus_change();
  2535. }
  2536.  
  2537. 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"];
  2538. this.mbm = ["Include albums", "Include EPs", "Include singles", "Include others", "Include 'Live' releases", "Include 'Remix' releases", "Include 'Compilation' releases", "Show release type", "Newest first"];
  2539. this.mbs = {"2k3.musicbrainz_show_icons": window.GetProperty("2k3.musicbrainz_show_icons", true), "2k3.musicbrainz_releases": window.GetProperty("2k3.musicbrainz_releases", true)};
  2540. for (i in this.mbl) {
  2541. this.mbs[this.mbl[i]] = window.GetProperty(this.mbl[i], true);
  2542. }
  2543. this.ua = "foobar2000_wsh_panel_mod_musicbrainz +http://www.hydrogenaud.io/forums/index.php?showuser=19379";
  2544. p.data_folder.create();
  2545. p.artists_folder.create();
  2546. break;
  2547. case "properties":
  2548. this.mode = "properties";
  2549. this.text_x = 200;
  2550. break;
  2551. }
  2552. }
  2553.  
  2554. var i;
  2555. this.mode = mode;
  2556. this.x = x;
  2557. this.y = y;
  2558. this.w = w;
  2559. this.h = h;
  2560. this.index = 0;
  2561. this.offset = 0;
  2562. this.items = 0;
  2563. this.artist = "";
  2564. this.filename = "";
  2565. this.text_x = 0;
  2566. this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  2567. this.init();
  2568. }
  2569.  
  2570. function playcount_sync(x, y, size) {
  2571. this.playback_time = function() {
  2572. this.time_elapsed++;
  2573. if (this.time_elapsed == 3 && this.auto_love && tfe(this.auto_love_tf) == 1 && this.old_userloved == 0) {
  2574. p.console("Automatically loving this track....");
  2575. this.love_track();
  2576. }
  2577. if (this.time_elapsed == this.target_time) {
  2578. if (!this.library || fb.IsMetadbInMediaLibrary(p.metadb)) {
  2579. switch(true) {
  2580. case this.loved_working || this.playcount_working:
  2581. return;
  2582. case !this.check_component:
  2583. p.console(this.error_message);
  2584. return;
  2585. default:
  2586. p.console("Contacting Last.fm....");
  2587. this.get(l.get_url() + "&method=track.getinfo&artist=" + encodeURIComponent(this.artist) + "&track=" + encodeURIComponent(this.track) + "&autocorrect=" + (l.auto_correct ? 1 : 0), function() {
  2588. ps.update_track();
  2589. });
  2590. }
  2591. } else {
  2592. p.console("Skipping... Track not in library.");
  2593. }
  2594. }
  2595. }
  2596.  
  2597. this.metadb_changed = function() {
  2598. if (!p.metadb) return false;
  2599. this.artist = tf(p.artist_tf, p.metadb);
  2600. this.track = tf("%title%", p.metadb);
  2601. this.old_userloved = tf("%LASTFM_LOVED_DB%", p.metadb) == 1 ? 1 : 0;
  2602. this.old_userplaycount = tf("%LASTFM_PLAYCOUNT_DB%", p.metadb);
  2603. this.method = this.old_userloved == 1 ? "track.unlove" : "track.love";
  2604. this.crc32 = tf("$crc32($lower(%artist%%title%))", p.metadb);
  2605. this.update_button();
  2606. return true;
  2607. }
  2608.  
  2609. this.playback_new_track = function() {
  2610. this.auto_love_count = 0;
  2611. this.time_elapsed = 0;
  2612. switch(true) {
  2613. case fb.PlaybackLength == 0:
  2614. this.target_time = 240;
  2615. break;
  2616. case fb.PlaybackLength >= 30:
  2617. this.target_time = Math.min(Math.floor(fb.PlaybackLength / 2), 240);
  2618. break;
  2619. default:
  2620. this.target_time = 5;
  2621. break;
  2622. }
  2623. p.item_focus_change();
  2624. }
  2625.  
  2626. this.playback_edited = function() {
  2627. if (this.auto_love && tfe(this.auto_love_tf) == 1 && this.old_userloved == 0 && this.auto_love_count == 0) {
  2628. this.auto_love_count = 1;
  2629. p.console("Automatically loving this track....");
  2630. this.love_track();
  2631. }
  2632. }
  2633.  
  2634. this.love_track = function() {
  2635. l.post(this.method, p.metadb);
  2636. }
  2637.  
  2638. this.get = function(url, func) {
  2639. if (l.username.length == 0) {
  2640. this.loved_working = false;
  2641. this.playcount_working = false;
  2642. p.console(l.username_error);
  2643. return;
  2644. }
  2645. this.xmlhttp.open("GET", url, true);
  2646. this.xmlhttp.setRequestHeader("User-Agent", l.ua);
  2647. this.xmlhttp.send();
  2648. this.xmlhttp.onreadystatechange = function() {
  2649. if (ps.xmlhttp.readyState == 4) {
  2650. if (ps.xmlhttp.status == 200) {
  2651. func();
  2652. } else {
  2653. p.console(ps.xmlhttp.responsetext || "HTTP error: " + ps.xmlhttp.status);
  2654. }
  2655. }
  2656. }
  2657. }
  2658.  
  2659. this.update_track = function() {
  2660. var data = p.json_parse(ps.xmlhttp.responsetext, "track");
  2661. if (data.length == 0) return p.console(ps.xmlhttp.responsetext);
  2662. this.userplaycount = data.userplaycount > 0 ? ++data.userplaycount : 1;
  2663. this.userloved = data.userloved == 1 ? 1 : 0;
  2664. switch(true) {
  2665. case fb.PlaybackLength < 30:
  2666. case fb.PlaybackLength > 10800:
  2667. fb.RunContextCommandWithMetadb("Customdb Love " + this.userloved, p.metadb, 8);
  2668. break;
  2669. case this.userplaycount < this.old_userplaycount:
  2670. p.console("Playcount returned from Last.fm is lower than current value. Not updating.");
  2671. fb.RunContextCommandWithMetadb("Customdb Love " + this.userloved, p.metadb, 8);
  2672. break;
  2673. case this.userplaycount == this.old_userplaycount:
  2674. p.console("No changes found. Not updating.");
  2675. fb.RunContextCommandWithMetadb("Customdb Love " + this.userloved, p.metadb, 8);
  2676. break;
  2677. default:
  2678. p.console("Last.fm responded ok. Attempting to update playcount...");
  2679. if (this.logging) {
  2680. p.console("Old value: " + this.old_userplaycount);
  2681. p.console("New value: " + this.userplaycount);
  2682. }
  2683. fb.RunContextCommandWithMetadb("Customdb Delete Playcount", p.metadb, 8);
  2684. fb.RunContextCommandWithMetadb("Customdb Love 0", p.metadb, 8);
  2685. window.SetTimeout(function() {
  2686. var query = '\"INSERT INTO quicktag(url,subsong,fieldname,value) VALUES(\\"' + ps.crc32 + '\\",\\"-1\\",\\"LASTFM_PLAYCOUNT_DB\\",\\"' + ps.userplaycount + '\\")\";';
  2687. var command = ps.sqlite3_file.sp() + " ";
  2688. command += ps.db_file.sp() + " ";
  2689. command += query;
  2690. var attempt = 1;
  2691. while(tf("%LASTFM_PLAYCOUNT_DB%", p.metadb) != ps.userplaycount && attempt <= 5) {
  2692. if (ps.logging) p.console("Attempt: " + attempt);
  2693. p.run_cmd(command, true);
  2694. attempt++;
  2695. }
  2696. fb.RunContextCommandWithMetadb("Customdb Refresh", p.metadb, 8);
  2697. if (tf("%LASTFM_PLAYCOUNT_DB%", p.metadb) == ps.userplaycount) p.console("Playcount updated successfully.");
  2698. else p.console("Database error. Playcount not updated.");
  2699. if (ps.userloved == 1) fb.RunContextCommandWithMetadb("Customdb Love 1", p.metadb, 8);
  2700. }, 100);
  2701. break;
  2702. }
  2703. }
  2704.  
  2705. this.start_import = function() {
  2706. if (this.show_console) fb.ShowConsole();
  2707. this.loved_page_errors = 0;
  2708. this.playcount_page_errors = 0;
  2709. this.pages = 0;
  2710. this.r = 1;
  2711. this.sql = "BEGIN TRANSACTION;\n";
  2712. this.loved_working = true;
  2713. p.console("Starting import...");
  2714. this.sync_loved(1);
  2715. }
  2716.  
  2717. this.sync_loved = function(p) {
  2718. if (!this.loved_working) return p.console("Import aborted.");
  2719. this.page = p;
  2720. this.get(l.get_url() + "&method=user.getlovedtracks&limit=200&page=" + this.page, function() {
  2721. ps.update_loved();
  2722. });
  2723. }
  2724.  
  2725. this.update_loved = function() {
  2726. var artist, title, data, url;
  2727. data = p.json_parse(ps.xmlhttp.responsetext);
  2728. if (data && data.lovedtracks && data.lovedtracks.track) {
  2729. if (this.page == 1) this.pages = data.lovedtracks["@attr"].totalPages;
  2730. data = data.lovedtracks.track;
  2731. if (typeof data.length == "undefined") data = [data];
  2732. for (i in data) {
  2733. artist = data[i].artist.name;
  2734. title = data[i].name;
  2735. p.console(this.r + ": " + artist + " - " + title);
  2736. url = tfe("$crc32($lower(" + p.fb2k_escape(artist) + p.fb2k_escape(title) + "))", true);
  2737. this.sql += 'INSERT OR REPLACE INTO quicktag(url,subsong,fieldname,value) VALUES("' + url + '","-1","LASTFM_LOVED_DB","1");' + "\n";
  2738. this.r++;
  2739. }
  2740. p.console("Loved tracks: completed page " + this.page + " of " + this.pages);
  2741. } else {
  2742. this.loved_page_errors++;
  2743. }
  2744. if (this.page < this.pages) {
  2745. this.page++;
  2746. this.sync_loved(this.page);
  2747. } else {
  2748. this.loved_working = false;
  2749. switch(true) {
  2750. case this.full_import:
  2751. this.playcount_working = true;
  2752. this.pages = 0;
  2753. this.r = 1;
  2754. this.sync_playcount(1);
  2755. break;
  2756. case this.sql == "BEGIN TRANSACTION;\n":
  2757. p.console("Nothing found to import.");
  2758. break;
  2759. default:
  2760. this.sql += "COMMIT;"
  2761. p.save(this.sql, this.sql_file, 0);
  2762. this.finish_import();
  2763. break;
  2764. }
  2765. }
  2766. }
  2767.  
  2768. this.sync_playcount = function(p) {
  2769. if (this.playcount_working == false) return p.console("Import aborted.");
  2770. this.page = p;
  2771. this.get(l.get_url() + "&method=library.gettracks&limit=100&page=" + this.page, function() {
  2772. ps.update_playcount();
  2773. });
  2774. }
  2775.  
  2776. this.update_playcount = function() {
  2777. var artist, title, playcount, data, url;
  2778. data = p.json_parse(ps.xmlhttp.responsetext);
  2779. if (data && data.tracks && data.tracks.track) {
  2780. if (this.page == 1) this.pages = data.tracks["@attr"].totalPages;
  2781. data = data.tracks.track;
  2782. if (typeof data.length == "undefined") data = [data];
  2783. for (i in data) {
  2784. artist = data[i].artist.name;
  2785. title = data[i].name;
  2786. playcount = data[i].playcount;
  2787. if (playcount == 0) {
  2788. this.page = this.pages;
  2789. break;
  2790. }
  2791. p.console(this.r + ": " + artist + " - " + title + " " + playcount);
  2792. url = tfe("$crc32($lower(" + p.fb2k_escape(artist) + p.fb2k_escape(title) + "))", true);
  2793. this.sql += 'INSERT OR REPLACE INTO quicktag(url,subsong,fieldname,value) VALUES("' + url + '","-1","LASTFM_PLAYCOUNT_DB","' + playcount + '");' + "\n";
  2794. this.r++;
  2795. }
  2796. p.console("Playcount: completed page " + this.page + " of " + this.pages);
  2797. } else {
  2798. this.playcount_page_errors++
  2799. }
  2800. if (this.page < this.pages) {
  2801. this.page++;
  2802. this.sync_playcount(this.page);
  2803. } else {
  2804. this.playcount_working = false;
  2805. if (this.sql == "BEGIN TRANSACTION;\n") {
  2806. p.console("Nothing found to import.");
  2807. } else {
  2808. this.sql += "COMMIT;"
  2809. p.save(this.sql, this.sql_file, 0);
  2810. this.finish_import();
  2811. }
  2812. }
  2813. }
  2814.  
  2815. this.finish_import = function() {
  2816. switch(true) {
  2817. case !this.full_import && this.loved_page_errors > 0:
  2818. p.console("Loved track page errors: " + this.loved_page_errors + " (200 records are lost for every page that fails.)");
  2819. break;
  2820. case this.full_import && this.loved_page_errors + this.playcount_page_errors > 0:
  2821. p.console("Loved track page errors: " + this.loved_page_errors + " (200 records are lost for every page that fails.)");
  2822. p.console("Playcount page errors: " + this.playcount_page_errors + " (100 records are lost for every page that fails.)");
  2823. break;
  2824. default:
  2825. p.console("There were no errors reported.");
  2826. break;
  2827. }
  2828. var command = this.cmd_file.sp() + " ";
  2829. command += this.sqlite3_file.sp() + " ";
  2830. command += this.db_file.sp() + " ";
  2831. command += this.sql_file.sp();
  2832. p.run(command);
  2833. }
  2834.  
  2835. this.update_button = function() {
  2836. switch(true) {
  2837. case l.username.length == 0:
  2838. this.n = this.cross_img;
  2839. this.h = this.cross_img;
  2840. this.tooltip = l.username_error;
  2841. this.func = null;
  2842. break;
  2843. case l.sk.length != 32:
  2844. this.n = this.cross_img;
  2845. this.h = this.cross_img;
  2846. this.tooltip = l.password_error;
  2847. this.func = null;
  2848. break;
  2849. case !p.metadb:
  2850. this.n = this.cross_img;
  2851. this.h = this.cross_img;
  2852. this.tooltip = "No selection";
  2853. this.func = null;
  2854. break;
  2855. case !this.check_component:
  2856. this.n = this.cross_img;
  2857. this.h = this.cross_img;
  2858. this.tooltip = this.error_message;
  2859. this.func = null;
  2860. break;
  2861. case this.old_userloved == 1:
  2862. this.n = this.loved_img;
  2863. this.h = this.unloved_img;
  2864. this.tooltip = "Unlove \"" + this.track + "\" by \"" + this.artist + "\".";
  2865. this.func = function() { ps.love_track(); }
  2866. break;
  2867. default:
  2868. this.n = this.unloved_img;
  2869. this.h = this.loved_img;
  2870. this.tooltip = "Love \"" + this.track + "\" by \"" + this.artist + "\".";
  2871. this.func = function() { ps.love_track(); }
  2872. break;
  2873. }
  2874. b.buttons.ps = new button(this.x, this.y, this.size, this.size, {normal: this.n, hover: this.h}, this.func, this.tooltip);
  2875. window.RepaintRect(b.buttons.ps.x, b.buttons.ps.y, this.size, this.size);
  2876. }
  2877.  
  2878. var i;
  2879. this.x = x;
  2880. this.y = y;
  2881. this.size = size;
  2882. this.loved_working = false;
  2883. this.playcount_working = false;
  2884. this.sqlite3_file = p.script_path + "sqlite3.exe";
  2885. this.cmd_file = p.script_path + "lastfm_sql.cmd";
  2886. this.db_file = fb.ProfilePath + "customdb_sqlite.db";
  2887. this.sql_file = p.data_folder + "lastfm.sql";
  2888. this.page = 0;
  2889. this.last_page = 0;
  2890. this.auto_love = window.GetProperty("2k3.playcount_sync_auto_love", false);
  2891. this.auto_love_tf = window.GetProperty("2k3.playcount_sync_auto_love_tf", "");
  2892. this.show_console = window.GetProperty("2k3.playcount_sync_show_console", true);
  2893. this.library = window.GetProperty("2k3.playcount_sync_library", false);
  2894. this.logging = window.GetProperty("2k3.playcount_sync_logging", false);
  2895. this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  2896. this.cross_img = gdi.Image(p.ip + "misc\\cross2.png");
  2897. this.loved_img = gdi.Image(p.ip + "lastfm\\loved.png");
  2898. this.unloved_img = gdi.Image(p.ip + "lastfm\\unloved.png");
  2899. this.check_component = false;
  2900. this.error_message = "One or more required files are missing. Please follow the readme again.";
  2901. l.need_username = true;
  2902. p.data_folder.create();
  2903. p.settings_folder.create();
  2904. p.selection_mode = 1;
  2905. window.SetTimeout(function() {
  2906. switch(true) {
  2907. case !utils.CheckComponent("foo_customdb", true):
  2908. p.console("foo_customdb is not installed.");
  2909. break;
  2910. case !ps.cmd_file.is_file():
  2911. case !ps.sqlite3_file.is_file():
  2912. case !ps.db_file.is_file():
  2913. p.console(ps.error_message);
  2914. break;
  2915. default:
  2916. ps.check_component = true;
  2917. break;
  2918. }
  2919. if (fb.IsPlaying) ps.playback_new_track();
  2920. else if (p.metadb) p.item_focus_change();
  2921. else ps.update_button();
  2922. }, 500);
  2923. window.SetInterval(function() {
  2924. if (!ps.loved_working && !ps.playcount_working) return;
  2925. if (ps.page != ps.last_page) return ps.last_page = ps.page;
  2926. var temp = ps.page > 1 ? ps.page - 1 : 1;
  2927. ps.xmlhttp.abort();
  2928. if (ps.loved_working ) ps.sync_loved(temp);
  2929. else if (ps.playcount_working) ps.sync_playcount(temp);
  2930. }, 15000);
  2931. }
  2932.  
  2933. function rating(x, y, s) {
  2934. this.draw = function(gr) {
  2935. if (!p.metadb) return;
  2936. for (i = 1; i < 6; i++) {
  2937. this.img = i > (this.hover ? this.lrating : this.rating) ? this.off_img : this.hover && this.rating == this.lrating ? this.cross_img : this.on_img;
  2938. p.draw_image(gr, this.img, this.x + this.s * (i - 1), this.y, this.s, this.s);
  2939. }
  2940. }
  2941.  
  2942. this.metadb_changed = function() {
  2943. if (!p.metadb) return false;
  2944. this.hover = false;
  2945. this.rating = tf("$if2(%rating%,0)", p.metadb);
  2946. this.tiptext = tf(this.tiptext_tf, p.metadb);
  2947. this.lrating = this.rating;
  2948. window.RepaintRect(this.x, this.y, this.w, this.s);
  2949. return true;
  2950. }
  2951.  
  2952. this.trace = function(x, y) {
  2953. return x > this.x && x < this.x + this.w && y > this.y && y < this.y + this.s;
  2954. }
  2955.  
  2956. this.move = function(x, y) {
  2957. if (!this.trace(x, y)) {
  2958. if (this.hover) this.leave();
  2959. return false;
  2960. }
  2961. if (p.metadb) {
  2962. p.tt(this.tiptext);
  2963. this.hover = true;
  2964. this.lrating = Math.ceil((x - this.x) / this.s);
  2965. window.RepaintRect(this.x, this.y, this.w, this.s);
  2966. }
  2967. return true;
  2968. }
  2969.  
  2970. this.lbtn_up = function(x, y) {
  2971. if (!this.trace(x, y)) return false;
  2972. if (p.metadb && this.hover == 1) {
  2973. if (this.check_component) {
  2974. fb.RunContextCommandWithMetadb("Rating/" + (this.lrating == this.rating ? "<not set>" : this.lrating), p.metadb, 8);
  2975. } else {
  2976. 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");
  2977. }
  2978. }
  2979. return true;
  2980. }
  2981.  
  2982. this.leave = function() {
  2983. p.tt("");
  2984. this.hover = false;
  2985. window.RepaintRect(this.x, this.y, this.w, this.s);
  2986. }
  2987.  
  2988. var i;
  2989. this.x = x;
  2990. this.y = y;
  2991. this.s = s;
  2992. this.w = this.s * 5;
  2993. this.hover = false;
  2994. this.rating = null;
  2995. this.lrating = null;
  2996. this.img = null;
  2997. this.off_img = gdi.Image(p.ip + "rating\\rating_grey.png");
  2998. this.on_img = gdi.Image(p.ip + "rating\\rating_gold.png");
  2999. this.cross_img = gdi.Image(p.ip + "misc\\cross2.png");
  3000. this.tiptext_tf = 'Rate "%title%" by "%artist%."';
  3001. this.check_component = utils.CheckComponent("foo_playcount", true);
  3002. }
  3003.  
  3004. function sb(x, y, w, h, img, v, func) {
  3005. this.x = x;
  3006. this.y = y;
  3007. this.w = w;
  3008. this.h = h;
  3009. this.img = img;
  3010. this.v = new Function("return " + v + ";");
  3011. this.func = func;
  3012.  
  3013. this.draw = function(gr) {
  3014. if (this.v()) p.draw_image(gr, this.img, this.x, this.y, this.w, this.h);
  3015. }
  3016.  
  3017. this.trace = function(x, y) {
  3018. return x > this.x && x < this.x + this.w && y > this.y && y < this.y + this.h && this.v();
  3019. }
  3020.  
  3021. this.lbtn_up = function(x, y) {
  3022. if (!this.trace(x, y)) return false;
  3023. this.func && this.func(x, y);
  3024. return true;
  3025. }
  3026. }
  3027.  
  3028. function seekbar(mode, x, y, w, h) {
  3029. this.draw = function(gr) {
  3030. switch(this.mode) {
  3031. case "spectrogram":
  3032. if (this.working) {
  3033. p.draw_image(gr, this.hourglass_img, this.x, this.y + Math.round((this.h - 32) / 2), this.w, 32);
  3034. } else {
  3035. p.draw_image(gr, this.img, this.x, this.y, this.w, this.h, 2);
  3036. }
  3037. if (fb.IsPlaying && fb.PlaybackLength > 0) {
  3038. this.calc_pos();
  3039. gr.FillSolidRect(this.x + this.pos - 2, this.y, 2, this.h, p.splitRGB(this.marker));
  3040. }
  3041. break;
  3042. case "nyan_cat":
  3043. if (fb.IsPlaying && fb.PlaybackLength > 0) {
  3044. this.calc_pos();
  3045. for (i in this.offsets) {
  3046. gr.FillSolidRect(this.x - 48, this.y + this.offsets[i], this.pos + 2, this.heights[i], this.colours[i]);
  3047. }
  3048. p.draw_image(gr, this.cat_img[this.z], this.pos, this.y, 48, 30);
  3049. } else {
  3050. p.draw_image(gr, this.cat_img[0], 0, this.y, 48, 30);
  3051. }
  3052. break;
  3053. }
  3054. }
  3055.  
  3056. this.playback_new_track = function() {
  3057. if (this.mode != "spectrogram") return;
  3058. this.img && this.img.Dispose();
  3059. this.img = null;
  3060. var metadb = fb.GetNowPlaying();
  3061. if (!metadb) return;
  3062. this.png_filename = this.folder + this.sox_params + "_" + tfe("$crc32($lower($substr(%path%,4,$len(%path%))))") + ".png";
  3063. switch(true) {
  3064. case this.png_filename.is_file():
  3065. this.img = gdi.Image(this.png_filename);
  3066. break;
  3067. case metadb.RawPath.indexOf("file") != 0:
  3068. p.console("Skipping... Not a valid file type.");
  3069. break;
  3070. case fb.PlaybackLength == 0:
  3071. p.console("Skipping... Unknown length.");
  3072. break;
  3073. case tfe("$if($or($strcmp(%__cue_embedded%,yes),$strcmp($right(%path%,3),cue)),cue,)") == "cue":
  3074. p.console("Skipping... Cannot support cuesheets.");
  3075. break;
  3076. case tfe("%subsong%") > 0:
  3077. p.console("Skipping... Cannot support tracks with chapters.");
  3078. break;
  3079. case this.library && !fb.IsMetadbInMediaLibrary(metadb):
  3080. p.console("Skipping... Track not in library.");
  3081. break;
  3082. default:
  3083. this.working = true;
  3084. window.Repaint();
  3085. var length = tfe("%length%");
  3086. 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 + "\"\"";
  3087. p.run_cmd(cmd, true);
  3088. this.working = false;
  3089. this.img = gdi.Image(this.png_filename);
  3090. break;
  3091. }
  3092. window.Repaint();
  3093. }
  3094.  
  3095. this.playback_stop = function() {
  3096. window.Repaint();
  3097. }
  3098.  
  3099. this.playback_seek = function() {
  3100. this.update();
  3101. }
  3102.  
  3103. this.trace = function(x, y) {
  3104. var m = this.drag ? 200 : 0;
  3105. return x > this.x - m && x < this.x + this.w + m && y > this.y - m && y < this.y + this.h + m;
  3106. }
  3107.  
  3108. this.wheel = function(s) {
  3109. if (!this.trace(p.mx, p.my)) return false;
  3110. switch(true) {
  3111. case !fb.IsPlaying:
  3112. case fb.PlaybackLength == 0:
  3113. break;
  3114. case fb.PlaybackLength < 60:
  3115. fb.PlaybackTime += s * 5;
  3116. break;
  3117. case fb.PlaybackLength < 600:
  3118. fb.PlaybackTime += s * 10;
  3119. break;
  3120. default:
  3121. fb.PlaybackTime += s * 60;
  3122. break;
  3123. }
  3124. p.tt("");
  3125. return true;
  3126. }
  3127.  
  3128. this.move = function(x, y) {
  3129. if (this.trace(x, y)) {
  3130. if (fb.IsPlaying && fb.PlaybackLength > 0) {
  3131. x -= this.x;
  3132. this.drag_seek = x < 0 ? 0 : x > this.w ? 1 : x / this.w;
  3133. if (this.old_x != x || this.old_y != y) {
  3134. this.old_x = x;
  3135. this.old_y = y;
  3136. p.tt(p.format_time(fb.PlaybackLength * this.drag_seek));
  3137. }
  3138. if (this.drag) this.update();
  3139. }
  3140. this.hover = true;
  3141. return true;
  3142. } else {
  3143. if (this.hover) p.tt("");
  3144. this.hover = false;
  3145. this.drag = false;
  3146. return false;
  3147. }
  3148. }
  3149.  
  3150. this.lbtn_down = function(x, y) {
  3151. if (!this.trace(x, y)) return false;
  3152. if (fb.IsPlaying && fb.PlaybackLength > 0) this.drag = true;
  3153. return true;
  3154. }
  3155.  
  3156. this.lbtn_up = function(x, y) {
  3157. if (!this.trace(x, y)) return false;
  3158. if (this.drag) {
  3159. this.drag = false;
  3160. fb.PlaybackTime = fb.PlaybackLength * this.drag_seek;
  3161. }
  3162. return true;
  3163. }
  3164.  
  3165. this.update = function() {
  3166. if (this.mode == "spectrogram") window.RepaintRect(Math.max(this.pos - 60, 0), this.y, 120, this.h);
  3167. else window.RepaintRect(0, this.y, p.w, this.h);
  3168. }
  3169.  
  3170. this.calc_pos = function() {
  3171. this.pos = this.drag ? this.w * this.drag_seek : this.w * (fb.PlaybackTime / fb.PlaybackLength);
  3172. }
  3173.  
  3174. this.init = function() {
  3175. switch(this.mode) {
  3176. case "spectrogram":
  3177. this.clear_images = function(period) {
  3178. var images = this.folder.get_files(["png"]);
  3179. for (i in images) {
  3180. if (this.png_filename == images[i]) continue;
  3181. if (images[i].expired(period)) {
  3182. p.delete_file(images[i]);
  3183. }
  3184. }
  3185. }
  3186.  
  3187. this.library = window.GetProperty("2k3.seekbar_library", false);
  3188. this.marker = window.GetProperty("2k3.seekbar_marker", "240-240-240");
  3189. this.sox_params = window.GetProperty("2k3.seekbar_sox_params", "channels 1 spectrogram -Y 130").trim();
  3190. this.working = false;
  3191. this.img = false;
  3192. this.hourglass_img = gdi.Image(p.ip + "seekbar\\hourglass.png");
  3193. this.folder = p.data_folder + "spectrogram\\";
  3194. p.data_folder.create();
  3195. this.folder.create();
  3196. window.SetTimeout(function() {
  3197. var error = "";
  3198. if (!sox_exe.is_file()) error += "SoX is missing\n";
  3199. if (!ffmpeg_exe.is_file()) error += "ffmpeg is missing\n";
  3200. if (error.length > 0) p.MsgBox(error + "\nPlease check the notes in the panel.", 0, p.name);
  3201. else if (fb.IsPlaying) s.playback_new_track();
  3202. }, 100);
  3203. break;
  3204. case "nyan_cat":
  3205. this.cat_img = [gdi.Image(p.ip + "seekbar\\nyan cat.png"), gdi.Image(p.ip + "seekbar\\nyan cat 2.png")];
  3206. this.offsets = [2, 6, 10, 15, 20, 24];
  3207. this.heights = [4, 4, 5, 5, 4, 4];
  3208. 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)];
  3209. break;
  3210. }
  3211. }
  3212.  
  3213. var i;
  3214. this.mode = mode;
  3215. this.x = x;
  3216. this.y = y;
  3217. this.w = w;
  3218. this.h = h;
  3219. this.z = 0;
  3220. this.pos = 0;
  3221. this.hover = false;
  3222. this.drag = false;
  3223. this.drag_seek = 0;
  3224. this.old_x = 0;
  3225. this.old_y = 0;
  3226. this.init();
  3227. window.SetInterval(function() {
  3228. s.z = s.z == 0 ? 1 : 0;
  3229. if (!fb.IsPlaying || fb.IsPaused || fb.PlaybackLength == 0) return;
  3230. s.update();
  3231. }, 150);
  3232. }
  3233.  
  3234. function text(mode, x, y, w, h) {
  3235. this.size = function() {
  3236. this.rows = Math.floor((this.h - 30) / p.row_height);
  3237. var but_x = this.x + Math.round((this.w - 15) / 2);
  3238. this.up_btn = new sb(but_x, this.y, 15, 15, p.up_img, "t.offset > 0", function() { t.wheel(1); });
  3239. 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); });
  3240. this.update();
  3241. }
  3242.  
  3243. this.draw = function(gr) {
  3244. for (i = 0; i < Math.min(this.rows, this.text_rows); i++) {
  3245. 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);
  3246. 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);
  3247. }
  3248. this.up_btn.draw(gr);
  3249. this.down_btn.draw(gr);
  3250. }
  3251.  
  3252. this.metadb_changed = function() {
  3253. if (!p.metadb) return false;
  3254. switch(this.mode) {
  3255. case "allmusic":
  3256. var temp_artist = p.eval(this.allmusic_artist_tf);
  3257. var temp_album = p.eval(this.allmusic_album_tf);
  3258. if (this.artist == temp_artist && this.album == temp_album) return false;
  3259. this.artist = temp_artist;
  3260. this.album = temp_album;
  3261. this.filename = p.new_artist_folder(this.artist) + "Allmusic - " + this.album.validate() + ".txt";
  3262. this.text = "";
  3263. if (this.filename.is_file()) {
  3264. this.text = p.open(this.filename);
  3265. } else {
  3266. this.allmusic_url = false;
  3267. this.get();
  3268. }
  3269. break;
  3270. case "lastfm_wiki":
  3271. p.artist = p.eval(p.artist_tf);
  3272. if (this.artist == p.artist) return false;
  3273. this.artist = p.artist;
  3274. this.text = "";
  3275. if (this.biography_lastfm) {
  3276. this.filename = p.new_artist_folder(this.artist) + "bio." + this.biography_lastfm_sites[this.biography_lastfm_site] + ".txt";
  3277. if (this.filename.is_file()) {
  3278. this.text = p.open(this.filename);
  3279. if (this.filename.expired(ONE_DAY)) this.get();
  3280. } else {
  3281. this.get();
  3282. }
  3283. } else {
  3284. this.filename = p.new_artist_folder(this.artist) + "lastm_wiki.json";
  3285. if (this.filename.is_file()) {
  3286. var data = p.json_parse(p.open(this.filename), "response.biographies");
  3287. for (i in data) {
  3288. if (data[i].site == "wikipedia") {
  3289. this.text = data[i].text;
  3290. break;
  3291. }
  3292. }
  3293. 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");
  3294. if (this.filename.expired(ONE_DAY)) this.get();
  3295. } else {
  3296. this.get();
  3297. }
  3298. }
  3299. break;
  3300. case "simple_tag":
  3301. this.filename = p.metadb.Path;
  3302. this.text = p.eval(this.tag_tf);
  3303. break;
  3304. case "simple_text":
  3305. this.temp_filename = p.eval(this.filename_tf);
  3306. if (this.filename == this.temp_filename) return false;
  3307. this.filename = this.temp_filename;
  3308. this.text = "";
  3309. var files = [];
  3310. if (this.filename.is_folder()) { //yes really!
  3311. var folder = this.filename + "\\";
  3312. files = folder.get_files(this.exts);
  3313. files.sort();
  3314. this.text = p.open(files[0]);
  3315. } else {
  3316. files = this.filename.split("|");
  3317. for (i in files) {
  3318. files[i] = files[i].trim();
  3319. if (files[i].is_file()) {
  3320. this.text = p.open(files[i]);
  3321. break;
  3322. }
  3323. }
  3324. }
  3325. this.text = this.text.replace(/\t/g, " ");
  3326. break;
  3327. }
  3328. this.update();
  3329. window.Repaint();
  3330. return true;
  3331. }
  3332.  
  3333. this.trace = function(x, y) {
  3334. return x > this.x && x < this.x + this.w && y > this.y && y < this.y + this.h;
  3335. }
  3336.  
  3337. this.wheel = function(s) {
  3338. if (!this.trace(p.mx, p.my)) return false;
  3339. if (this.text_rows > this.rows) {
  3340. this.offset -= s * 3;
  3341. if (this.offset < 0) this.offset = 0;
  3342. if (this.offset + this.rows > this.text_rows) this.offset = this.text_rows - this.rows;
  3343. window.RepaintRect(this.x, this.y, this.w, this.h);
  3344. }
  3345. return true;
  3346. }
  3347.  
  3348. this.move = function(x, y) {
  3349. switch(true) {
  3350. case !this.trace(x, y):
  3351. window.SetCursor(IDC_ARROW);
  3352. return false;
  3353. case this.up_btn.trace(x, y):
  3354. case this.down_btn.trace(x, y):
  3355. window.SetCursor(IDC_HAND);
  3356. break;
  3357. default:
  3358. window.SetCursor(IDC_ARROW);
  3359. break;
  3360. }
  3361. return true;
  3362. }
  3363.  
  3364. this.lbtn_up = function(x, y) {
  3365. if (!this.trace(x, y)) return false;
  3366. this.up_btn.lbtn_up(x, y);
  3367. this.down_btn.lbtn_up(x, y);
  3368. return true;
  3369. }
  3370.  
  3371. this.get = function() {
  3372. var fn = this.filename;
  3373. switch(this.mode) {
  3374. case "allmusic":
  3375. if (this.allmusic_url) {
  3376. var func = function() {
  3377. doc.open();
  3378. var div = doc.createElement("div");
  3379. div.innerHTML = t.xmlhttp.responsetext;
  3380. var data = div.getElementsByTagName("div");
  3381. var text = "";
  3382. for (i in data) {
  3383. if (data[i].itemprop == "reviewBody") {
  3384. text = p.strip_tags(data[i].innerText);
  3385. break;
  3386. }
  3387. }
  3388. doc.close();
  3389. if (text.length > 0) {
  3390. p.console("A review was found and saved.");
  3391. p.save(text, fn);
  3392. t.artist = "";
  3393. p.item_focus_change();
  3394. } else {
  3395. p.console("No review was found on the page for this album.");
  3396. }
  3397. }
  3398.  
  3399. var url = this.allmusic_url;
  3400. this.allmusic_url = false;
  3401. } else {
  3402. var func = function() {
  3403. t.allmusic_get_page(t.xmlhttp.responsetext);
  3404. }
  3405.  
  3406. if (this.artist == "" || this.artist == "?" || this.album == "" || this.album == "?") return;
  3407. var url = "http://www.allmusic.com/search/albums/" + encodeURIComponent(this.album + (this.artist.toLowerCase() == "various artists" ? "" : " " + this.artist));
  3408. }
  3409. break;
  3410. case "lastfm_wiki":
  3411. var func = function() {
  3412. if (t.biography_lastfm) {
  3413. doc.open();
  3414. var div = doc.createElement("div");
  3415. div.innerHTML = t.xmlhttp.responsetext;
  3416. var data = div.getElementsByTagName("div");
  3417. var text = "";
  3418. try {
  3419. for (i in data) {
  3420. if (data[i].id == "wiki") {
  3421. text = p.strip_tags(data[i].innerText);
  3422. break;
  3423. }
  3424. }
  3425. } catch(e) {}
  3426. doc.close();
  3427. p.save(text, fn);
  3428. } else {
  3429. p.save(t.xmlhttp.responsetext, fn);
  3430. }
  3431. t.artist = "";
  3432. p.item_focus_change();
  3433. }
  3434.  
  3435. if (this.artist == "" || this.artist == "?") return;
  3436. if (this.biography_lastfm) var url = "http://" + this.biography_lastfm_sites[this.biography_lastfm_site] + "/music/" + encodeURIComponent(this.artist) + "/+wiki";
  3437. else var url = "http://developer.echonest.com/api/v4/artist/biographies?api_key=EKWS4ESQLKN3G2ZWV&format=json&name=" + encodeURIComponent(this.artist);
  3438. break;
  3439. default:
  3440. return;
  3441. }
  3442. this.xmlhttp.open("GET", url, true);
  3443. this.xmlhttp.send();
  3444. this.xmlhttp.onreadystatechange = function() {
  3445. if (t.xmlhttp.readyState == 4) {
  3446. if (t.xmlhttp.status == 200) {
  3447. func();
  3448. } else {
  3449. p.console(t.xmlhttp.responsetext || "HTTP error: " + t.xmlhttp.status);
  3450. }
  3451. }
  3452. }
  3453. }
  3454.  
  3455. this.update = function() {
  3456. this.offset = 0;
  3457. this.text_rows = 0;
  3458. if (this.w < 100 || this.text.length == 0) return;
  3459. var temp_bmp = gdi.CreateImage(1, 1);
  3460. var temp_gr = temp_bmp.GetGraphics();
  3461. var paragraphs = this.text.split("\n");
  3462. this.text_array = [];
  3463. for (i in paragraphs) {
  3464. if (this.fixed) {
  3465. this.text_array.push(paragraphs[i]);
  3466. } else {
  3467. var lines = temp_gr.EstimateLineWrap(paragraphs[i], p.normal_font, this.w).toArray();
  3468. for (var j = 0; j < lines.length; j += 2) {
  3469. this.text_array.push(lines[j].trim());
  3470. }
  3471. }
  3472. }
  3473. this.text_rows = this.text_array.length;
  3474. temp_bmp.ReleaseGraphics(temp_gr);
  3475. temp_bmp.Dispose();
  3476. temp_gr = null;
  3477. temp_bmp = null;
  3478. }
  3479.  
  3480. this.header_text = function() {
  3481. switch(this.mode) {
  3482. case "allmusic":
  3483. return p.eval("%album artist%[ - %album%]");
  3484. break;
  3485. case "lastfm_wiki":
  3486. return this.artist;
  3487. break;
  3488. case "simple_text":
  3489. case "simple_tag":
  3490. return p.eval(this.title_tf);
  3491. break;
  3492. }
  3493. }
  3494.  
  3495. this.init = function() {
  3496. switch(this.mode) {
  3497. case "allmusic":
  3498. this.allmusic_get_page = function(text) {
  3499. var artist, title, divs, url, temp;
  3500. var ar = this.allmusic_tidy(this.artist);
  3501. var al = this.allmusic_tidy(this.album);
  3502. doc.open();
  3503. var div = doc.createElement("div");
  3504. div.innerHTML = text;
  3505. var data = div.getElementsByTagName("li");
  3506. this.allmusic_url = "";
  3507. for (i in data) {
  3508. if (data[i].className == "album") {
  3509. divs = data[i].getElementsByTagName("div");
  3510. title = "", artist = "";
  3511. for (var j = 0; j < divs.length; j++) {
  3512. if (divs[j].className == "title") {
  3513. title = divs[j].getElementsByTagName("a")[0].innerText;
  3514. url = divs[j].getElementsByTagName("a")[0].href;
  3515. }
  3516. if (divs[j].className == "artist") {
  3517. temp = divs[j].getElementsByTagName("a");
  3518. if (temp.length > 0) artist = temp[0].innerText;
  3519. else artist = "various artists";
  3520. }
  3521. }
  3522. if (ar == this.allmusic_tidy(artist) && al == this.allmusic_tidy(title)) {
  3523. this.allmusic_url = url;
  3524. break;
  3525. }
  3526. }
  3527. }
  3528. doc.close();
  3529. if (this.allmusic_url.length > 0) {
  3530. p.console("A page was found for \"" + this.album + "\". Now checking for review...");
  3531. this.get();
  3532. } else {
  3533. p.console("Could not match artist/album on the Allmusic website.");
  3534. }
  3535. }
  3536.  
  3537. this.allmusic_tidy = function(t) {
  3538. return tfe("$replace($lower($ascii(" + p.fb2k_escape(t) + ")), & ,, and ,)", true);
  3539. }
  3540.  
  3541. this.allmusic_artist_tf = window.GetProperty("2k3.allmusic_artist_tf", "%album artist%");
  3542. this.allmusic_album_tf = window.GetProperty("2k3.allmusic_album_tf", "%album%");
  3543. p.data_folder.create();
  3544. p.artists_folder.create();
  3545. break;
  3546. case "lastfm_wiki":
  3547. 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"];
  3548. this.biography_lastfm_site = window.GetProperty("2k3.biography_lastfm_site", 0);
  3549. this.biography_lastfm = window.GetProperty("2k3.biography_lastfm", true);
  3550. p.data_folder.create();
  3551. p.artists_folder.create();
  3552. break;
  3553. case "simple_text":
  3554. this.title_tf = window.GetProperty("2k3.text_title_tf", "$directory_path(%path%)");
  3555. this.filename_tf = window.GetProperty("2k3.text_filename_tf", "$directory_path(%path%)");
  3556. this.fixed = window.GetProperty("2k3.text_fixed_font", true);
  3557. this.exts = "txt|log";
  3558. break;
  3559. case "simple_tag":
  3560. this.title_tf = window.GetProperty("2k3.text_title_tf", "%title%");
  3561. this.tag_tf = window.GetProperty("2k3.text_tag_tf", "[%lyrics%]");
  3562. this.centre = window.GetProperty("2k3.text_centre", false);
  3563. break;
  3564. }
  3565. }
  3566.  
  3567. var i;
  3568. this.mode = mode;
  3569. this.x = x;
  3570. this.y = y;
  3571. this.w = w;
  3572. this.h = h;
  3573. this.text = "";
  3574. this.artist = "";
  3575. this.album = "";
  3576. this.filename = "";
  3577. this.fixed = false;
  3578. this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  3579. this.init();
  3580. this.size();
  3581. }
  3582.  
  3583. function thumbs(custom) {
  3584. this.playback_time = function(t) {
  3585. 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();
  3586. }
  3587.  
  3588. this.size = function(f) {
  3589. this.nc = f || this.nc;
  3590. this.offset = 0;
  3591. switch(true) {
  3592. case p.w < this.px || p.h < this.px || this.mode == this.modes.off || this.mode == this.modes.disabled:
  3593. this.nc = true;
  3594. this.img && this.img.Dispose();
  3595. this.img = null;
  3596. break;
  3597. case this.mode == this.modes.grid:
  3598. this.x = 0;
  3599. this.y = 0;
  3600. this.w = p.w;
  3601. this.h = p.h;
  3602. if (!this.nc && this.columns != Math.floor(this.w / this.px)) this.nc = true;
  3603. this.overlay = false;
  3604. this.rows = Math.ceil(this.h / this.px);
  3605. this.columns = Math.floor(this.w / this.px);
  3606. this.img_rows = Math.ceil(this.images.length / this.columns);
  3607. if (this.nc && this.images.length > 0) {
  3608. this.nc = false;
  3609. this.img && this.img.Dispose();
  3610. this.img = null;
  3611. this.img = gdi.CreateImage(Math.min(this.columns, this.images.length) * this.px, this.img_rows * this.px);
  3612. var temp_gr = this.img.GetGraphics();
  3613. temp_gr.SetInterpolationMode(7);
  3614. var ci = 0;
  3615. var row, col;
  3616. for (row = 0; row < this.img_rows; row++) {
  3617. for (col = 0; col < this.columns; col++) {
  3618. if (ci == this.images.length) continue;
  3619. p.draw_image(temp_gr, this.images[ci], col * this.px, row * this.px, this.px, this.px, 1);
  3620. ci++;
  3621. }
  3622. }
  3623. this.img.ReleaseGraphics(temp_gr);
  3624. temp_gr = null;
  3625. }
  3626. break;
  3627. case this.mode == this.modes.left:
  3628. case this.mode == this.modes.right:
  3629. this.x = this.mode == this.modes.left ? 0 : p.w - this.px;
  3630. this.y = 0;
  3631. this.w = this.px;
  3632. this.h = p.h;
  3633. this.rows = Math.ceil(this.h / this.px);
  3634. if (this.nc && this.images.length > 0) {
  3635. this.nc = false;
  3636. this.img && this.img.Dispose();
  3637. this.img = null;
  3638. this.img = gdi.CreateImage(this.px, this.px * this.images.length);
  3639. var temp_gr = this.img.GetGraphics();
  3640. temp_gr.SetInterpolationMode(7);
  3641. for (i in this.images) {
  3642. p.draw_image(temp_gr, this.images[i], 0, i * this.px, this.px, this.px, 1);
  3643. }
  3644. this.img.ReleaseGraphics(temp_gr);
  3645. temp_gr = null;
  3646. }
  3647. break;
  3648. case this.mode == this.modes.top:
  3649. case this.mode == this.modes.bottom:
  3650. this.x = 0;
  3651. this.y = this.mode == this.modes.top ? 0 : p.h - this.px;
  3652. this.w = p.w;
  3653. this.h = this.px;
  3654. this.columns = Math.ceil(this.w / this.px);
  3655. if (this.nc && this.images.length > 0) {
  3656. this.nc = false;
  3657. this.img && this.img.Dispose();
  3658. this.img = null;
  3659. this.img = gdi.CreateImage(this.px * this.images.length, this.px);
  3660. var temp_gr = this.img.GetGraphics();
  3661. temp_gr.SetInterpolationMode(7);
  3662. for (i in this.images) {
  3663. p.draw_image(temp_gr, this.images[i], i * this.px, 0, this.px, this.px, 1);
  3664. }
  3665. this.img.ReleaseGraphics(temp_gr);
  3666. temp_gr = null;
  3667. }
  3668. break;
  3669. }
  3670. }
  3671.  
  3672. this.draw = function(gr) {
  3673. switch(true) {
  3674. case this.images.length == 0:
  3675. break;
  3676. case this.mode == this.modes.disabled:
  3677. case this.mode == this.modes.off:
  3678. p.draw_image(gr, this.images[this.image], 0, 0, p.w, p.h, this.type);
  3679. break;
  3680. case !this.img:
  3681. break;
  3682. case this.mode == this.modes.grid:
  3683. gr.DrawImage(this.img, this.x, this.y, this.w, this.h, 0, this.offset * this.px, this.w, this.h);
  3684. if (this.overlay) {
  3685. gr.FillSolidRect(this.x, this.y, this.w, this.h, RGBA(0, 0, 0, 126));
  3686. p.draw_image(gr, this.images[this.image], 40, 40, p.w - 80, p.h - 80, "centre");
  3687. }
  3688. break;
  3689. case this.mode == this.modes.left:
  3690. var x = this.type == 3 ? this.px : 0;
  3691. p.draw_image(gr, this.images[this.image], x, 0, p.w - x, p.h, this.type);
  3692. gr.FillSolidRect(this.x, this.y, this.px, this.h, RGBA(0, 0, 0, 126));
  3693. gr.DrawImage(this.img, this.x, this.y, this.w, this.h, 0, this.offset * this.px, this.w, this.h);
  3694. break;
  3695. case this.mode == this.modes.right:
  3696. p.draw_image(gr, this.images[this.image], 0, 0, p.w - (this.type == 3 ? this.px : 0), p.h, this.type);
  3697. gr.FillSolidRect(this.x, this.y, this.px, this.h, RGBA(0, 0, 0, 126));
  3698. gr.DrawImage(this.img, this.x, this.y, this.w, this.h, 0, this.offset * this.px, this.w, this.h);
  3699. break;
  3700. case this.mode == this.modes.top:
  3701. var y = this.type == 3 ? this.px : 0;
  3702. p.draw_image(gr, this.images[this.image], 0, y, p.w, p.h - y, this.type);
  3703. gr.FillSolidRect(this.x, this.y, this.w, this.px, RGBA(0, 0, 0, 126));
  3704. gr.DrawImage(this.img, this.x, this.y, this.w, this.h, this.offset * this.px, 0, this.w, this.h);
  3705. break;
  3706. case this.mode == this.modes.bottom:
  3707. p.draw_image(gr, this.images[this.image], 0, 0, p.w, p.h - (this.type == 3 ? this.px : 0), this.type);
  3708. gr.FillSolidRect(this.x, this.y, this.w, this.px, RGBA(0, 0, 0, 126));
  3709. gr.DrawImage(this.img, this.x, this.y, this.w, this.h, this.offset * this.px, 0, this.w, this.h);
  3710. break;
  3711. }
  3712. }
  3713.  
  3714. this.metadb_changed = function() {
  3715. if (!p.metadb) return false;
  3716. switch(this.source) {
  3717. case 0: //last.fm
  3718. p.artist = p.eval(p.artist_tf);
  3719. if (this.artist == p.artist) return false;
  3720. this.artist = p.artist;
  3721. this.folder = p.new_artist_folder(this.artist);
  3722. break;
  3723. case 1: //custom folder
  3724. this.temp_folder = p.eval(this.custom_folder_tf);
  3725. if (this.temp_folder == this.folder) return false;
  3726. this.folder = this.temp_folder;
  3727. break;
  3728. }
  3729. this.update();
  3730. return true;
  3731. }
  3732.  
  3733. this.trace = function(x, y) {
  3734. return x > this.x && x < this.x + this.w && y > this.y && y < this.y + this.h;
  3735. }
  3736.  
  3737. this.wheel = function(s) {
  3738. switch(true) {
  3739. case !this.trace(p.mx, p.my):
  3740. case this.overlay:
  3741. if (this.images.length < 2) return;
  3742. this.image -= s;
  3743. if (this.image < 0) this.image = this.images.length - 1;
  3744. if (this.image >= this.images.length) this.image = 0;
  3745. window.Repaint();
  3746. return;
  3747. case this.mode == this.modes.grid:
  3748. if (this.img_rows < this.rows) return;
  3749. this.offset -= s;
  3750. if (this.offset < 0) this.offset = 0;
  3751. if (this.offset > this.img_rows - this.rows) this.offset = this.img_rows - this.rows + 1;
  3752. break;
  3753. case this.mode == this.modes.left:
  3754. case this.mode == this.modes.right:
  3755. if (this.images.length < this.rows) return;
  3756. this.offset -= s;
  3757. if (this.offset < 0) this.offset = 0;
  3758. if (this.rows + this.offset > this.images.length) this.offset = this.images.length - this.rows + 1;
  3759. break;
  3760. case this.mode == this.modes.top:
  3761. case this.mode == this.modes.bottom:
  3762. if (this.images.length < this.columns) return;
  3763. this.offset -= s;
  3764. if (this.offset < 0) this.offset = 0;
  3765. if (this.columns + this.offset > this.images.length) this.offset = this.images.length - this.columns + 1;
  3766. break;
  3767. }
  3768. window.RepaintRect(this.x, this.y, this.w, this.h);
  3769. }
  3770.  
  3771. this.move = function(x, y) {
  3772. this.index = this.images.length;
  3773. switch(true) {
  3774. case !this.trace(x, y):
  3775. window.SetCursor(IDC_ARROW);
  3776. return;
  3777. case this.overlay:
  3778. window.SetCursor(IDC_HAND);
  3779. return;
  3780. case this.mode == this.modes.grid:
  3781. var temp = Math.floor((x - this.x) / this.px);
  3782. this.index = temp >= this.columns ? this.images.length : temp + (Math.floor((y - this.y) / this.px) * this.columns) + (this.offset * this.columns);
  3783. break;
  3784. case this.mode == this.modes.left:
  3785. case this.mode == this.modes.right:
  3786. this.index = Math.floor((y - this.y) / this.px) + this.offset;
  3787. break;
  3788. case this.mode == this.modes.top:
  3789. case this.mode == this.modes.bottom:
  3790. this.index = Math.floor((x - this.x) / this.px) + this.offset;
  3791. break;
  3792. }
  3793. window.SetCursor(this.index < this.images.length ? IDC_HAND : IDC_ARROW);
  3794. }
  3795.  
  3796. this.lbtn_up = function(x, y) {
  3797. switch(true) {
  3798. case !this.trace(x, y):
  3799. break;
  3800. case this.mode == this.modes.grid && this.overlay:
  3801. this.overlay = false;
  3802. window.Repaint();
  3803. break;
  3804. case this.mode == this.modes.grid && this.index < this.images.length && !this.overlay:
  3805. this.overlay = true;
  3806. this.image = this.index;
  3807. window.Repaint();
  3808. break;
  3809. case this.index < this.images.length:
  3810. this.image = this.index;
  3811. window.Repaint();
  3812. break;
  3813. }
  3814. }
  3815.  
  3816. this.lbtn_dblclk = function(x, y) {
  3817. if (!this.trace(x, y) && this.mode != this.modes.grid && this.images.length > 0) p.run("\"" + this.files[this.image] + "\"");
  3818. }
  3819.  
  3820. this.update = function() {
  3821. this.image = 0;
  3822. for (i in this.images) {
  3823. try { this.images[i].Dispose(); } catch(e) {}
  3824. }
  3825. this.folders = this.folder.split("|");
  3826. this.files = [];
  3827. for (i in this.folders) {
  3828. this.folders[i] = this.folders[i].trim();
  3829. this.files = this.files.concat(this.folders[i].get_files(this.exts));
  3830. }
  3831. if (this.files.length > 1) {
  3832. switch(this.sort) {
  3833. case 0:
  3834. case 1:
  3835. this.files.sort(function(a, b) {
  3836. var time_a = a.last_modified();
  3837. var time_b = b.last_modified();
  3838. if (time_a < time_b) return th.sort == 0 ? 1 : -1;
  3839. if (time_a > time_b) return th.sort == 0 ? -1 : 1;
  3840. return 0;
  3841. });
  3842. break;
  3843. case 2:
  3844. case 3:
  3845. this.files.sort(function(a, b) {
  3846. a = a.toLowerCase();
  3847. b = b.toLowerCase();
  3848. if (a > b) return th.sort == 2 ? 1 : -1;
  3849. if (a < b) return th.sort == 2 ? -1 : 1;
  3850. return 0;
  3851. });
  3852. break;
  3853. }
  3854. if (this.source == 0) {
  3855. var temp_file = utils.ReadINI(this.ini_file, "Defaults", "\"" + this.artist.validate() + "\"");
  3856. if (temp_file.charAt(1) == ":") { //convert absolute path to filename and save it
  3857. temp_file = temp_file.split("\\").pop();
  3858. utils.WriteIni(this.ini_file, "Defaults", "\"" + this.artist.validate() + "\"", "\"" + temp_file + "\"");
  3859. }
  3860. this.default_file = this.folder + temp_file;
  3861. if (this.default_file.is_file()) {
  3862. for (i in this.files) {
  3863. if (this.files[i] == this.default_file) {
  3864. this.files.splice(i, 1);
  3865. this.files.unshift(this.default_file);
  3866. break;
  3867. }
  3868. }
  3869. }
  3870. }
  3871. }
  3872. this.images = [];
  3873. for (i in this.files) {
  3874. this.images[i] = gdi.Image(this.files[i]);
  3875. }
  3876. this.size(true);
  3877. window.Repaint();
  3878. }
  3879.  
  3880. this.set_default = function(t) {
  3881. utils.WriteIni(this.ini_file, "Defaults", "\"" + this.artist.validate() + "\"", "\"" + t + "\"");
  3882. this.update();
  3883. }
  3884.  
  3885. this.delete_image = function() {
  3886. app.Namespace(10).MoveHere(this.files[this.image]);
  3887. this.update();
  3888. }
  3889.  
  3890. this.download = function() {
  3891. if (!this.folder.is_folder() || this.artist == "" || this.artist == "?") return;
  3892. var folder = this.folder;
  3893. var url = this.domain + "/music/" + encodeURIComponent(p.artist) + "/+images";
  3894. this.xmlhttp.open("GET", url, true);
  3895. this.xmlhttp.send();
  3896. this.xmlhttp.onreadystatechange = function() {
  3897. if (th.xmlhttp.readyState == 4) {
  3898. if (th.xmlhttp.status == 200) {
  3899. var text = th.xmlhttp.responsetext;
  3900. doc.open();
  3901. var div = doc.createElement("div");
  3902. div.innerHTML = text;
  3903. var data = div.getElementsByTagName("img");
  3904. var urls = [];
  3905. for (i = 0; i < data.length; i++) {
  3906. 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]));
  3907. }
  3908. for (i = 0; i < Math.min(urls.length, th.limit, 5); i++) {
  3909. p.run_cmd("cscript //nologo \"" + p.script_path + "download.vbs\" \"" + urls[i] + "\" \"" + folder + p.artist.validate() + "_" + urls[i].substring(urls[i].lastIndexOf("/") + 1) + "\"", false);
  3910. }
  3911. doc.close();
  3912. } else {
  3913. p.console("HTTP error: " + th.xmlhttp.status);
  3914. }
  3915. }
  3916. }
  3917. }
  3918.  
  3919. var i;
  3920. this.artist = "";
  3921. this.folder = "";
  3922. this.default_file = "";
  3923. this.files = [];
  3924. this.images = [];
  3925. this.exts = "jpg|jpeg|png|gif";
  3926. this.limit = window.GetProperty("2k3.thumbs_limit", 5);
  3927. this.cycle = window.GetProperty("2k3.thumbs_cycle", 0);
  3928. this.type = window.GetProperty("2k3.thumbs_type", 1);
  3929. this.auto_download = window.GetProperty("2k3.thumbs_auto_download", 0); //0 off 1 library 2 all
  3930. this.download_size = window.GetProperty("2k3.thumbs_download_size", 2); //0 small 1 medium 2 original
  3931. this.download_size_replace = { "0" : 252, "1": 500, "2": "_" };
  3932. this.custom_folder_tf = window.GetProperty("2k3.thumbs_custom_folder_tf", "$directory_path(%path%)");
  3933. this.domain = window.GetProperty("2k3.thumbs_domain", "http://www.last.fm");
  3934. this.modes = { grid: 0, left: 1, right: 2, top: 3, bottom: 4, off: 5, disabled: 6};
  3935. this.mode = window.GetProperty("2k3.thumbs_mode", this.modes.bottom);
  3936. this.px = window.GetProperty("2k3.thumbs_px", 75);
  3937. this.sort = window.GetProperty("2k3.thumbs_sort", 0); //0 newest first 1 oldest first 2 a-z 3 z-a
  3938. if (custom == "custom") {
  3939. this.source = 2;
  3940. } else {
  3941. this.source = window.GetProperty("2k3.thumbs_source", 0); //0 last.fm 1 custom folder
  3942. }
  3943. p.data_folder.create();
  3944. p.artists_folder.create();
  3945. p.settings_folder.create();
  3946. this.ini_file = p.settings_folder + "thumbs.ini";
  3947. this.img = null;
  3948. this.nc = false;
  3949. this.image = 0;
  3950. this.index = 0;
  3951. this.time = 0;
  3952. this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  3953. window.SetInterval(function() {
  3954. th.time++;
  3955. if (th.cycle > 0 && th.images.length > 1 && th.time % th.cycle == 0) {
  3956. th.image++;
  3957. if (th.image == th.images.length) th.image = 0;
  3958. window.Repaint();
  3959. }
  3960. if (th.source != 1 && th.time % 3 == 0 && th.folder.get_files(th.exts).length != th.files.length) th.update();
  3961. }, 1000);
  3962. }
  3963.  
  3964. function volume(x, y, w, h) {
  3965. this.volume_change = function(val) {
  3966. window.RepaintRect(this.x, this.y, this.w, this.h);
  3967. }
  3968.  
  3969. this.trace = function(x, y) {
  3970. var m = this.drag ? 200 : 0;
  3971. return x > this.x - m && x < this.x + this.w + m && y > this.y - m && y < this.y + this.h + m;
  3972. }
  3973.  
  3974. this.wheel = function(s) {
  3975. if (!this.trace(p.mx, p.my)) return false;
  3976. p.tt("");
  3977. fb.Volume += s;
  3978. return true;
  3979. }
  3980.  
  3981. this.move = function(x, y) {
  3982. if (this.trace(x, y)) {
  3983. x -= this.x;
  3984. var pos = x < 0 ? 0 : x > this.w ? 1 : x / this.w;
  3985. this.drag_vol = 50 * Math.log(0.99 * pos + 0.01) / Math.LN10;
  3986. p.tt(this.drag_vol.toFixed(2) + " dB");
  3987. if (this.drag) fb.Volume = this.drag_vol;
  3988. this.hover = true;
  3989. return true;
  3990. } else {
  3991. if (this.hover) p.tt("");
  3992. this.hover = false;
  3993. this.drag = false;
  3994. return false;
  3995. }
  3996. }
  3997.  
  3998. this.lbtn_down = function(x, y) {
  3999. if (!this.trace(x, y)) return false;
  4000. this.drag = true;
  4001. return true;
  4002. }
  4003.  
  4004. this.lbtn_up = function(x, y) {
  4005. if (!this.trace(x, y)) return false;
  4006. this.drag = false;
  4007. return true;
  4008. }
  4009.  
  4010. this.calc_pos = function() {
  4011. this.pos = this.w * (Math.pow(10, fb.Volume / 50) - 0.01) / 0.99;
  4012. }
  4013.  
  4014. this.x = x;
  4015. this.y = y;
  4016. this.w = w;
  4017. this.h = h;
  4018. this.pos = 0;
  4019. this.hover = false;
  4020. this.drag = false;
  4021. this.drag_vol = 0;
  4022. }
  4023.  
  4024. /*
  4025. * A JavaScript implementation of the RSA Data Security, Inc. MD5 Message
  4026. * Digest Algorithm, as defined in RFC 1321.
  4027. * Version 2.2 Copyright (C) Paul Johnston 1999 - 2009
  4028. * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
  4029. * Distributed under the BSD License
  4030. * See http://pajhome.org.uk/crypt/md5 for more info.
  4031. */
  4032. var hexcase=0;function hex_md5(a){return rstr2hex(rstr_md5(str2rstr_utf8(a)))}
  4033. function hex_hmac_md5(a,b){return rstr2hex(rstr_hmac_md5(str2rstr_utf8(a),str2rstr_utf8(b)))}
  4034. function md5_vm_test(){return hex_md5("abc").toLowerCase()=="900150983cd24fb0d6963f7d28e17f72"}
  4035. function rstr_md5(a){return binl2rstr(binl_md5(rstr2binl(a),a.length*8))}
  4036. function rstr_hmac_md5(c,f){var e=rstr2binl(c);if(e.length>16){e=binl_md5(e,c.length*8)}
  4037. var a=Array(16),d=Array(16);for(var b=0;b<16;b++){a[b]=e[b]^909522486;d[b]=e[b]^1549556828}
  4038. var g=binl_md5(a.concat(rstr2binl(f)),512+f.length*8);return binl2rstr(binl_md5(d.concat(g),512+128))}
  4039. function rstr2hex(c){try{hexcase}catch(g){hexcase=0}
  4040. 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)}
  4041. return b}
  4042. 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++}
  4043. 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))}}}}}
  4044. return b}
  4045. function rstr2binl(b){var a=Array(b.length>>2);for(var c=0;c<a.length;c++){a[c]=0}
  4046. for(var c=0;c<b.length*8;c+=8){a[c>>5]|=(b.charCodeAt(c/8)&255)<<(c%32)}
  4047. return a}
  4048. function binl2rstr(b){var a="";for(var c=0;c<b.length*32;c+=8){a+=String.fromCharCode((b[c>>5]>>>(c%32))&255)}
  4049. return a}
  4050. 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)}
  4051. return Array(o,n,m,l)}
  4052. 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)}
  4053. function md5_ff(g,f,k,j,e,i,h){return md5_cmn((f&k)|((~f)&j),g,f,e,i,h)}
  4054. function md5_gg(g,f,k,j,e,i,h){return md5_cmn((f&j)|(k&(~j)),g,f,e,i,h)}
  4055. function md5_hh(g,f,k,j,e,i,h){return md5_cmn(f^k^j,g,f,e,i,h)}
  4056. function md5_ii(g,f,k,j,e,i,h){return md5_cmn(k^(f|(~j)),g,f,e,i,h)}
  4057. function safe_add(a,d){var c=(a&65535)+(d&65535);var b=(a>>16)+(d>>16)+(c>>16);return(b<<16)|(c&65535)}
  4058. function bit_rol(a,b){return(a<<b)|(a>>>(32-b))}
  4059. function md5(a){return hex_md5(a)}
  4060.  
  4061. //https://github.com/douglascrockford/JSON-js/blob/master/json2.js
  4062. if(typeof JSON!=='object'){JSON={};}
  4063. (function(){'use strict';function f(n){return n<10?'0'+n:n;}
  4064. if(typeof Date.prototype.toJSON!=='function'){Date.prototype.toJSON=function(){return isFinite(this.valueOf())?this.getUTCFullYear()+'-'+
  4065. f(this.getUTCMonth()+1)+'-'+
  4066. f(this.getUTCDate())+'T'+
  4067. f(this.getUTCHours())+':'+
  4068. f(this.getUTCMinutes())+':'+
  4069. f(this.getUTCSeconds())+'Z':null;};String.prototype.toJSON=Number.prototype.toJSON=Boolean.prototype.toJSON=function(){return this.valueOf();};}
  4070. 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+'"';}
  4071. 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);}
  4072. if(typeof rep==='function'){value=rep.call(holder,key,value);}
  4073. 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';}
  4074. 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';}
  4075. v=partial.length===0?'[]':gap?'[\n'+gap+partial.join(',\n'+gap)+'\n'+mind+']':'['+partial.join(',')+']';gap=mind;return v;}
  4076. 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);}}}}
  4077. v=partial.length===0?'{}':gap?'{\n'+gap+partial.join(',\n'+gap)+'\n'+mind+'}':'{'+partial.join(',')+'}';gap=mind;return v;}}
  4078. 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;}
  4079. rep=replacer;if(replacer&&typeof replacer!=='function'&&(typeof replacer!=='object'||typeof replacer.length!=='number')){throw new Error('JSON.stringify');}
  4080. return str('',{'':value});};}
  4081. 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];}}}}
  4082. return reviver.call(holder,key,value);}
  4083. text=String(text);cx.lastIndex=0;if(cx.test(text)){text=text.replace(cx,function(a){return'\\u'+
  4084. ('0000'+a.charCodeAt(0).toString(16)).slice(-4);});}
  4085. 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;}
  4086. throw new SyntaxError('JSON.parse');};}}());
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement