View difference between Paste ID: G76MuFjS and QdjNhAaN
SHOW: | | - or go back to the newest paste.
1
// ==PREPROCESSOR==
2
// @name "Youtube Radio"
3
// @author "Mire777"
4
// @feature "v1.4"
5
// @feature "watch-metadb"
6
// ==/PREPROCESSOR==
7
8
// Paths
9
var fbfolder = (fb.ProfilePath + "Artist_info");
10
var lfm_folder = fbfolder;
11
12
//image download size
13
size = "high";
14
15
//Download server
16
auto_yt = window.GetProperty("YT Radio", "0");
17
//auto_lfm = window.GetProperty("LFM Radio", "0");
18
19
ooo2 = window.GetProperty("YT Track", "");
20-
START_ARTIST = window.GetProperty("Artist Station", "");
20+
START_ARTIST = window.GetProperty("YT  Station", "");
21
22
//Download server
23
last_fm = window.GetProperty("YT Similar", "");
24
YT_URL = window.GetProperty("YT URL", "");
25
26
27
//Search terms(google,yahoo)
28
terms = "";
29
30
//Cycle
31
cycle2 = 15;
32
33
var VERSION = "7.2013-10-19.01";
34
var DT_LEFT = 0x00000000;
35
var DT_CENTER = 0x00000001;
36
var DT_RIGHT = 0x00000002;
37
var DT_VCENTER = 0x00000004;
38
var DT_WORDBREAK = 0x00000010;
39
var DT_CALCRECT = 0x00000400;
40
var DT_NOPREFIX = 0x00000800;
41
var DT_END_ELLIPSIS = 0x00008000;
42
43
var MF_GRAYED = 0x00000001;
44
var MF_STRING = 0x00000000;
45
46
var IDC_ARROW = 32512;
47
var IDC_HAND = 32649;
48
49
var ONE_DAY = 86400000;
50
var ONE_WEEK = 604800000;
51
52
String.prototype.addCommas = function() {
53
	return this.replace(/\B(?=(\d{3})+(?!\d))/g, ",");
54
}
55
56
String.prototype.trim = function() {
57
	return this.replace(/^\s+|\s+$/g, "");
58
}
59
60
String.prototype.ucfirst = function() {
61
	return this.charAt(0).toUpperCase() + this.substr(1);
62
}
63
64
function RGB(r, g, b) {
65
	return (0xff000000 | (r << 16) | (g << 8) | (b));
66
}
67
68
function RGBA(r, g, b, a) {
69
	return ((a << 24) | (r << 16) | (g << 8) | (b));
70
}
71
72
function on_colors_changed() {
73
	p.colors_changed();
74
}
75
76
function on_font_changed() {
77
	p.font_changed();
78
}
79
80
function on_selection_changed() {
81
	p.item_focus_change();
82
}
83
84
function on_playlist_switch() {
85
	p.item_focus_change();
86
}
87
88
function on_playback_new_track() {
89
	p.item_focus_change();
90
    //im.download();
91
    im.downloadLFM();
92
}
93
94
function on_playback_dynamic_info_track() {
95
	p.item_focus_change();
96
}
97
98
function on_playback_stop() {
99
	p.item_focus_change();
100
}
101
102
function on_item_focus_change() {
103
	p.item_focus_change();
104
}
105
106
function on_mouse_leave() {
107
	if (typeof b == "object") b.leave();
108
	if (typeof r == "object") r.leave();
109
	if (typeof li == "object") li.leave();
110
	if (typeof s == "object") s.leave();
111
}
112
113
function on_mouse_rbtn_up(x, y) {
114
	p.rbtn_up(x, y);
115
	return true;
116
}
117
118
function on_notify_data(name, data) {
119
	if (name == "lastfm" && data == "update" && typeof l == "object") l.notify_data(name, data);
120
	if (name == "autoplaylists" && data == "update" && typeof li == "object" && li.mode == "autoplaylists") li.update();
121
	if (name == "images" && data == "update" && typeof im == "object") im.update();
122
	if (name == "love" && typeof ps == "object") l.post(fb.TitleFormat("%LASTFM_LOVED_DB%").EvalWithMetadb(data) == 1 ? "track.unlove" : "track.love", data);
123
}
124
125
function panel(name, features) {
126
	this.item_focus_change = function() {
127
		if (!this.metadb_func) return;
128
		switch(this.selection_mode) {
129
			case 0:
130
				this.metadb = fb.GetSelection();
131
				break;
132
			case 1:
133
				this.metadb = fb.IsPlaying ? fb.GetNowPlaying() : fb.GetFocusItem();
134
				break;
135
			case 2:
136
				this.metadb = fb.GetFocusItem();
137
				break;
138
		}
139
		if (this.metadb) on_metadb_changed();
140
	}
141
	
142
this.colors_changed = function() {
143
		if (this.dui) {
144
            this.background_mode=(1);
145
			this.textcolour = window.GetColorDUI(0);
146
			this.textcolour_hl = window.GetColorDUI(2);
147
			this.backcolour = window.GetColorDUI(1);
148
		} else {
149
            this.background_mode=(0);
150
			this.textcolour = window.GetColorCUI(0);
151
			this.textcolour_hl = window.GetColorCUI(0);
152
			this.backcolour = window.GetColorCUI(3);
153
		}
154
		window.Repaint();
155
	}
156
	
157
	this.font_changed = function() {
158
		this.font = this.dui ? window.GetFontDUI(0) : window.GetFontCUI(0);
159
		try {
160
			this.font_name = this.font.Name;
161
		} catch(e) {
162
			this.console("Unable to use your default font. Using Segoe UI instead.");
163
			this.font_name = "Segoe ui";
164
		}
165
		this.title_font = gdi.Font(this.font_name, 16, 1);
166
		this.normal_font = gdi.Font("segoe ui", 12, 1);
167
		this.fixed_font = gdi.Font("Lucida Console", this.normal_font_size);
168
		this.list_font = gdi.Font(this.font_name, this.list_font_size);
169
		this.row_height = this.normal_font.Height + 2;
170
		if (typeof t == "object") t.size();
171
		window.Repaint();
172
	}
173
	
174
	this.size = function() {
175
		this.w = window.Width;
176
		this.h = window.Height;
177
	}
178
	
179
	this.move = function(x, y) {
180
		this.mx = x;
181
		this.my = y;
182
	}
183
	
184
	this.rbtn_up = function(x, y) {
185
		var _menu = window.CreatePopupMenu();
186
		var _custom_background = window.CreatePopupMenu();
187
		var _metadb = window.CreatePopupMenu();
188
		var _cover = window.CreatePopupMenu();
189
		var _font = window.CreatePopupMenu();
190
		var _sub1 = window.CreatePopupMenu();
191
		var _sub2 = window.CreatePopupMenu();
192
		var _sub3 = window.CreatePopupMenu();
193
		var _sub4 = window.CreatePopupMenu();
194
		var _sub5 = window.CreatePopupMenu();
195
		var idx;
196
		switch(true) {
197
			case typeof a == "object" && a.trace(x, y):
198
				/*_menu.AppendMenuItem(MF_STRING, 1, "Refresh");
199
				_menu.AppendMenuSeparator();
200
				_menu.AppendMenuItem(MF_STRING, 2, "Front");
201
				_menu.AppendMenuItem(MF_STRING, 3, "Back");
202
				_menu.AppendMenuItem(MF_STRING, 4, "Disc");
203
				_menu.AppendMenuItem(MF_STRING, 5, "Icon");
204
				_menu.AppendMenuItem(MF_STRING, 6, "Artist");
205
				_menu.CheckMenuRadioItem(2, 6, a.id + 2);
206
				_menu.AppendMenuSeparator();*/
207
				_menu.AppendMenuItem(MF_STRING, 15, "Crop (focus on centre)");
208
				_menu.AppendMenuItem(MF_STRING, 16, "Crop (focus on top)");
209
				_menu.AppendMenuItem(MF_STRING, 17, "adjust");
210
				_menu.AppendMenuItem(MF_STRING, 18, "Stretch");
211
				_menu.CheckMenuRadioItem(15, 18, a.type == "centre" ? 15 : a.type == "top" ? 16 : a.type == "adjust" ? 17 : 18);
212
				_menu.AppendMenuSeparator();
213
				_cover.AppendMenuItem(this.metadb ? MF_STRING : MF_GRAYED, 21, "Google images (launches browser)");
214
				_cover.AppendMenuItem(this.metadb ? MF_STRING : MF_GRAYED, 22, "Album Art Downloader");
215
				_cover.AppendMenuSeparator();
216
				//_cover.AppendMenuItem(MF_STRING, 23, "Help");
217
				//_cover.AppendTo(_menu, MF_STRING, "Cover search");
218
				//_menu.AppendMenuSeparator();
219
				break;
220
			case typeof c == "object" && c.trace(x, y):
221
				if (this.check_feature("now_playing") && !np_cd) break;
222
				/*_menu.AppendMenuItem(MF_STRING, 1, "Refresh");
223
				_menu.AppendMenuSeparator();
224
				_menu.AppendMenuItem(MF_STRING, 11, "Gloss effect");
225
				_menu.CheckMenuItem(11, c.gloss);
226
				_menu.AppendMenuItem(MF_STRING, 12, "Shadow effect");
227
				_menu.CheckMenuItem(12, c.shadow);
228
				_menu.AppendMenuSeparator();
229
				_cover.AppendMenuItem(this.metadb ? MF_STRING : MF_GRAYED, 21, "Google images (launches browser)");
230
				_cover.AppendMenuItem(this.metadb ? MF_STRING : MF_GRAYED, 22, "Album Art Downloader");
231
				_cover.AppendMenuSeparator();
232
				_cover.AppendMenuItem(MF_STRING, 23, "Help");
233
				_cover.AppendTo(_menu, MF_STRING, "Cover search");
234
				_menu.AppendMenuSeparator();*/
235
				break;
236
			case typeof li == "object" && li.trace(x, y):
237
				switch(li.mode) {
238
					case "autoplaylists":
239
						_menu.AppendMenuItem(MF_STRING, 600, "Change title...");
240
						_menu.AppendMenuSeparator();
241
						for (i = 1; i < 9; i++) {
242
							_sub1.AppendMenuItem(MF_STRING, i + 600, i);
243
						}
244
						_sub1.AppendTo(_menu, MF_STRING, "Save slot");
245
						_sub1.CheckMenuRadioItem(601, 608, li.autoplaylists_slot + 600);
246
						_menu.AppendMenuSeparator();
247
						_sub2.AppendMenuItem(MF_STRING, 610, "run query");
248
						_sub2.AppendMenuItem(MF_STRING, 611, "do nothing");
249
						_sub2.CheckMenuRadioItem(610, 611, li.autoplaylists_success ? 610 : 611);
250
						_sub2.AppendTo(_menu, MF_STRING, "On successful creation/edit");
251
						for (i = 0; i < li.autoplaylists_deleted_items.length; i++) {
252
							var temp = li.autoplaylists_deleted_items[i].split("¬");
253
							_sub3.AppendMenuItem(MF_STRING, i + 620, temp[0]);
254
						}
255
						if (li.autoplaylists_deleted_items.length > 0) _sub3.AppendTo(_menu, MF_STRING, "Restore");
256
						_menu.AppendMenuSeparator();
257
						_menu.AppendMenuItem(MF_STRING, 650, "Replace exisiting playlists with the same name");
258
						_menu.CheckMenuItem(650, li.autoplaylists_remove_duplicates);
259
						_menu.AppendMenuSeparator();
260
						break;
261
					case "discogs":
262
						_menu.AppendMenuItem(MF_STRING, 29, "Show exact artist matches only");
263
						_menu.CheckMenuItem(29, li.discogs_match);
264
						_menu.AppendMenuSeparator();
265
						_menu.AppendMenuItem(MF_STRING, 28, "Show timestamp");
266
						_menu.CheckMenuItem(28, li.show_timestamp);
267
						_menu.AppendMenuSeparator();
268
						break;
269
					case "echonest":
270
						for (i = 0; i < li.echonest_modes.length; i++) {
271
							_menu.AppendMenuItem(MF_STRING, i + 500, li.echonest_modes[i].ucfirst());
272
						}
273
						_menu.CheckMenuRadioItem(500, 502, li.echonest_mode + 500);
274
						_menu.AppendMenuSeparator();
275
						_menu.AppendMenuItem(MF_STRING, 28, "Show timestamp");
276
						_menu.CheckMenuItem(28, li.show_timestamp);
277
						_menu.AppendMenuSeparator();
278
						break;
279
					case "lastfm":
280
						for (i = 0; i < li.lastfm_modes.length; i++) {
281
							_menu.AppendMenuItem(MF_STRING, 801 + i, li.lastfm_modes[i].ucfirst());
282
						}
283
						_menu.CheckMenuRadioItem(801, 805, li.lastfm_mode + 801);
284
						_menu.AppendMenuSeparator();
285
						if (li.lastfm_mode == 0) {
286
							if (li.lastfm_button == "spotify") {
287
								_menu.AppendMenuItem(MF_STRING, 810, "Pause playback when launching Spotify");
288
								_menu.CheckMenuItem(810, li.lastfm_pause);
289
								_menu.AppendMenuSeparator();
290
							}
291
							/*_sub1.AppendMenuItem(MF_STRING, 811, "Spotify");
292
							_sub1.AppendMenuItem(MF_STRING, 812, "Autoplaylist");
293
							_sub1.CheckMenuRadioItem(811, 812, li.lastfm_button == "spotify" ? 811 : 812);
294
							_sub1.AppendTo(_menu, MF_STRING, "Buttons");
295
							_menu.AppendMenuSeparator();*/
296
						}
297
						/*_menu.AppendMenuItem(MF_STRING, 28, "Show timestamp");
298
						_menu.CheckMenuItem(28, li.show_timestamp);
299
						_menu.AppendMenuSeparator();
300
						_menu.AppendMenuItem(MF_STRING, 51, "Last.fm auto-correct");
301
						_menu.CheckMenuItem(51, l.auto_correct);
302
						_menu.AppendMenuSeparator();*/
303
						break;
304
					case "lastfm_charts":
305
						_menu.AppendMenuItem(l.username.length > 0 ? MF_STRING : MF_GRAYED, 1000, "Refresh");
306
						_menu.AppendMenuSeparator();
307
						for (i = 0; i < li.lastfm_charts_modes.length; i++) {
308
							_menu.AppendMenuItem(MF_STRING, i + 1001, li.lastfm_charts_modes[i].ucfirst());
309
						}
310
						_menu.CheckMenuRadioItem(1001, 1003, li.lastfm_charts_mode + 1001);
311
						_menu.AppendMenuSeparator();
312
						for (i = 0; i < li.lastfm_charts_periods_display.length; i++) {
313
							_menu.AppendMenuItem(MF_STRING, i + 1004, li.lastfm_charts_periods_display[i].ucfirst());
314
						}
315
						/*_menu.CheckMenuRadioItem(1004, 1009, li.lastfm_charts_period + 1004);
316
						_menu.AppendMenuSeparator();
317
						_menu.AppendMenuItem(MF_STRING, 1010, "Bar colour...");
318
						_menu.AppendMenuSeparator();
319
						_menu.AppendMenuItem(MF_STRING, 28, "Show timestamp");
320
						_menu.CheckMenuItem(28, li.show_timestamp);
321
						_menu.AppendMenuSeparator();*/
322
						break;
323
					case "musicbrainz":
324
						_menu.AppendMenuItem(MF_STRING, 700, "Releases");
325
						_menu.AppendMenuItem(MF_STRING, 701, "Links");
326
						_menu.CheckMenuRadioItem(700, 701, li.musicbrainz_mode == "releases" ? 700 : 701);
327
						_menu.AppendMenuSeparator();
328
						if (li.musicbrainz_mode == "releases") {
329
							/*_menu.AppendMenuItem(MF_STRING, 702, "Include albums");
330
							_menu.CheckMenuItem(702, li.musicbrainz_album);
331
							_menu.AppendMenuItem(MF_STRING, 703, "Include EPs");
332
							_menu.CheckMenuItem(703, li.musicbrainz_ep);
333
							_menu.AppendMenuItem(MF_STRING, 704, "Include singles");
334
							_menu.CheckMenuItem(704, li.musicbrainz_single);
335
							_menu.AppendMenuSeparator();
336
							_menu.AppendMenuItem(MF_STRING, 705, "Include 'Live' releases");
337
							_menu.CheckMenuItem(705, li.musicbrainz_live);
338
							_menu.AppendMenuItem(MF_STRING, 706, "Include 'Remix' releases");
339
							_menu.CheckMenuItem(706, li.musicbrainz_remix);
340
							_menu.AppendMenuItem(MF_STRING, 707, "Include 'Compilation' releases");
341
							_menu.CheckMenuItem(707, li.musicbrainz_compilation);
342
							_menu.AppendMenuSeparator();
343
							_menu.AppendMenuItem(MF_STRING, 708, "Show release type");
344
							_menu.CheckMenuItem(708, li.musicbrainz_show_release_type);
345
							_menu.AppendMenuSeparator();*/
346
						}
347
						/*_menu.AppendMenuItem(MF_STRING, 28, "Show timestamp");
348
						_menu.CheckMenuItem(28, li.show_timestamp);
349
						_menu.AppendMenuSeparator();*/
350
						break;
351
				}
352
				break;
353
			case typeof ps == "object" && b.buttons.ps.trace(x, y):
354
				/*_sub1.AppendMenuItem(utils.CheckComponent("foo_customdb", true) && !ps.loved_working && !ps.playcount_working && l.username.length > 0 ? MF_STRING : MF_GRAYED, 1100, "loved tracks and playcount");
355
				_sub1.AppendMenuItem(utils.CheckComponent("foo_customdb", true) && !ps.loved_working && !ps.playcount_working && l.username.length > 0 ? MF_STRING : MF_GRAYED, 1109, "loved tracks only");
356
				_sub1.AppendMenuSeparator();
357
				_sub1.AppendMenuItem(utils.CheckComponent("foo_customdb", true) && this.fso.FileExists(ps.sql_file) ? MF_STRING : MF_GRAYED, 1101, "from file");
358
				_sub1.AppendMenuSeparator();
359
				_sub1.AppendMenuItem(MF_STRING, 1102, "Show console");
360
				_sub1.CheckMenuItem(1102, ps.show_console);
361
				_sub1.AppendTo(_menu, MF_STRING, "Library import");
362
				_menu.AppendMenuSeparator();
363
				_sub2.AppendMenuItem(MF_STRING, 1103, "Only update tracks in library");
364
				_sub2.CheckMenuItem(1103, ps.library);
365
				_sub2.AppendMenuItem(MF_STRING, 52, "Last.fm auto-correct");
366
				_sub2.CheckMenuItem(52, l.auto_correct);
367
				_sub2.AppendTo(_menu, MF_STRING, "Auto-updates");
368
				_menu.AppendMenuSeparator();
369
				_sub3.AppendMenuItem(MF_STRING, 1104, "Off");
370
				_sub3.AppendMenuItem(MF_STRING, 1105, "On");
371
				_sub3.CheckMenuRadioItem(1104, 1105, ps.auto_love ? 1105 : 1104);
372
				_sub3.AppendMenuSeparator();
373
				_sub3.AppendMenuItem(ps.auto_love ? MF_STRING : MF_GRAYED, 1106, "Condition");
374
				_sub3.AppendTo(_menu, MF_STRING, "Automatically love tracks");
375
				_menu.AppendMenuSeparator();
376
				_sub4.AppendMenuItem(MF_STRING, 1107, "tango");
377
				_sub4.AppendMenuItem(MF_STRING, 1108, "silk");
378
				_sub4.CheckMenuRadioItem(1107, 1108, ps.icon == "tango" ? 1107 : 1108);
379
				_sub4.AppendTo(_menu, MF_STRING, "Icon");
380
				_menu.AppendMenuSeparator();*/
381
				break;
382
			case typeof s == "object" && s.mode == "spectrogram" && s.trace(x, y) :
383
				/*_menu.AppendMenuItem(MF_STRING, 1804, "SoX options...");
384
				_menu.AppendMenuSeparator();
385
				_menu.AppendMenuItem(MF_STRING, 1805, "Marker colour...");
386
				_menu.AppendMenuSeparator();
387
				_menu.AppendMenuItem(MF_STRING, 1803, "Only analyse tracks in library");
388
				_menu.CheckMenuItem(1803, s.library);
389
				_menu.AppendMenuSeparator();
390
				_sub1.AppendMenuItem(MF_STRING, 1800, "Clear all");
391
				_sub1.AppendMenuItem(MF_STRING, 1801, "Clear older than 1 day");
392
				_sub1.AppendMenuItem(MF_STRING, 1802, "Clear older than 1 week");
393
				_sub1.AppendMenuSeparator();
394
				_sub1.AppendMenuItem(MF_GRAYED, 1803, "In use: " + (this.fso.GetFolder(spectrogram_cache).size / 1048576).toFixed(2) + "MB");
395
				_sub1.AppendTo(_menu, MF_STRING, "Cached images");
396
				_menu.AppendMenuSeparator();*/
397
				break;
398
			case typeof t == "object" && t.trace(x, y):
399
				if (this.check_feature("now_playing") && !np_bio) break;
400
				/*_font.AppendMenuItem(MF_STRING, 30, 12);
401
				_font.AppendMenuItem(MF_STRING, 31, 14);
402
				_font.AppendMenuItem(MF_STRING, 32, 16);
403
				_font.AppendTo(_menu, MF_STRING, "Font size");
404
				_font.CheckMenuRadioItem(30, 33, this.normal_font_size == 12 ? 30 : this.normal_font_size == 14 ? 31 : 32);
405
				_menu.AppendMenuSeparator();*/
406
				switch(t.mode) {
407
					case "lastfm_album":
408
						/*_menu.AppendMenuItem(MF_STRING, 53, "Last.fm auto-correct");
409
						_menu.CheckMenuItem(53, l.auto_correct);
410
						_menu.AppendMenuSeparator();*/
411
						break;
412
					case "lastfm_wiki":
413
						/*_menu.AppendMenuItem(MF_STRING, 25, "Last.fm");
414
						_menu.AppendMenuItem(MF_STRING, 26, "Wikipedia");
415
						_menu.CheckMenuRadioItem(25, 26, t.source == "last.fm" ? 25 : 26);
416
						_menu.AppendMenuSeparator();*/
417
						break;
418
					case "simple_tag":
419
						/*_menu.AppendMenuItem(MF_STRING, 1700, "Custom title...");
420
						_menu.AppendMenuItem(MF_STRING, 1701, "Custom tag...");
421
						_menu.AppendMenuSeparator();
422
						_menu.AppendMenuItem(MF_STRING, 1702, "Centre text");
423
						_menu.CheckMenuItem(1702, t.centre);
424
						_menu.AppendMenuSeparator();*/
425
						break;
426
					case "simple_text":
427
						/*_menu.AppendMenuItem(MF_STRING, 1700, "Custom title...");
428
						_menu.AppendMenuItem(MF_STRING, 200, "Custom path...");
429
						_menu.AppendMenuSeparator();
430
						_menu.AppendMenuItem(MF_STRING, 201, "Fixed width font");
431
						_menu.CheckMenuItem(201, t.fixed);
432
						_menu.AppendMenuSeparator();*/
433
						break;
434
				}
435
				break;
436
			case typeof th == "object":
437
			case typeof im == "object" && im.trace(x, y):
438
				if (im.mode == "last.fm") {
439
					/*_menu.AppendMenuItem(this.metadb ? MF_STRING : MF_GRAYED, 450, "Download artist art from Last.fm");
440
					_menu.AppendMenuSeparator();
441
					_sub1.AppendMenuItem(MF_STRING, 451, "Off");
442
					_sub1.AppendMenuItem(MF_STRING, 452, "Library tracks only");
443
					_sub1.AppendMenuItem(MF_STRING, 453, "All tracks");
444
					_sub1.CheckMenuRadioItem(451, 453, im.auto_download == "off" ? 451 : im.auto_download == "library" ? 452 : 453);
445
					//_sub1.AppendTo(_menu, MF_STRING, "Automatic download");
446
					_sub2.AppendMenuItem(MF_STRING, 461, "1");
447
					_sub2.AppendMenuItem(MF_STRING, 463, "3");
448
					_sub2.AppendMenuItem(MF_STRING, 465, "5");
449
					//_sub2.AppendMenuItem(MF_STRING, 470, "10");
450
					//_sub2.AppendMenuItem(MF_STRING, 480, "20");
451
					_sub2.CheckMenuRadioItem(461, 480, im.limit + 460);
452
					//_sub2.AppendTo(_menu, MF_STRING, "Limit");*/
453
                    
454
				} else {
455
					//_menu.AppendMenuItem(MF_STRING, 442, "Set custom folder...");
456
				}
457
var _settings = window.CreatePopupMenu();
458
var _auto_cycle = window.CreatePopupMenu();
459
var _download_source = window.CreatePopupMenu();
460
var _download_limit = window.CreatePopupMenu();
461
var _download_quality = window.CreatePopupMenu();
462
var _thumbs = window.CreatePopupMenu();                
463
var MF_POPUP = 0x00000010;              
464
var MF_GRAYED = 0x00000001;                
465
				//_menu.AppendMenuSeparator();
466
//_menu.AppendMenuItem(MF_STRING, 403, "Auto YT");
467
				//_menu.AppendMenuSeparator();
468
469
470
//Settings Menu
471
//_menu.AppendMenuItem(MF_STRING | MF_POPUP, _settings.ID, "Auto YT");
472
473
//_menu.AppendMenuSeparator();
474
475
//_settings.AppendMenuItem(MF_STRING | MF_POPUP, _auto_cycle.ID, "Auto Cycle");
476
                
477
				//_auto_cycle.AppendMenuItem(MF_STRING, 415, "05 sec");
478
				//_auto_cycle.AppendMenuItem(MF_STRING, 420, "10 sec");
479
				//_auto_cycle.AppendMenuItem(MF_STRING, 425, "15 sec");
480
                //_auto_cycle.AppendMenuItem(MF_STRING, 430, "20 sec");
481
                //_auto_cycle.AppendMenuItem(MF_STRING, 410, "Off");
482
                //_auto_cycle.CheckMenuRadioItem(410, 430, cycle2 + 410);
483
				
484
485
//_settings.AppendMenuItem(MF_STRING | MF_POPUP, _download_source.ID, "Download Source");
486
                  
487
488
                  if(auto_yt==1) _menu.AppendMenuItem(MF_STRING, 1902, "Youtube Radio");
489
                  if(auto_yt==0) _menu.AppendMenuItem(MF_STRING, 1903, "Youtube Radio");
490
                  _menu.CheckMenuItem(1902, auto_yt?1:0);
491
                  
492
                  //if(auto_lfm==1) _menu.AppendMenuItem(MF_STRING, 1905, "Last.fm Radio");
493
                  //if(auto_lfm==0) _menu.AppendMenuItem(MF_STRING, 1906, "Last.fm Radio");
494
                  //_menu.CheckMenuItem(1905, auto_lfm?1:0);
495
                  
496
                  
497
                  _menu.AppendMenuSeparator();
498
499
500
//_settings.AppendMenuItem(MF_STRING | MF_POPUP, _download_limit.ID, "Download Limit");
501
                   
502
                   //_download_limit.AppendMenuItem(MF_STRING, 1905, "1x");
503
                   //_download_limit.AppendMenuItem(MF_STRING, 1906, "2x");
504
                   //_download_limit.AppendMenuItem(MF_STRING, 1907, "3x");
505
                   //_download_limit.AppendMenuItem(MF_STRING, 1908, "4x");
506
                   //_download_limit.AppendMenuItem(MF_STRING, 1909, "5x");
507
                   //_download_limit.AppendMenuItem(MF_STRING, 1910, "6x");
508
                   //_download_limit.CheckMenuRadioItem(1905, 1910, im.limit + 1904);
509
510
511
//if (server=="last.fm") _settings.AppendMenuItem(MF_STRING | MF_POPUP, _download_quality.ID, "Download Quality");
512
                       /*_download_quality.AppendMenuItem(MF_STRING, 1911, "Low");
513
                       _download_quality.AppendMenuItem(MF_STRING, 1912, "Medium");
514
                       _download_quality.AppendMenuItem(MF_STRING, 1913, "High");
515
                       _download_quality.CheckMenuRadioItem(1911, 1913, size == "low" ? 1911 : size == "medium" ? 1912 : size == "high" ? 1913 : 1913);
516
517
518
519
_settings.AppendMenuItem(MF_STRING | MF_POPUP, _thumbs.ID, "Thumbs");
520
                    
521
                    _thumbs.AppendMenuItem(MF_STRING, 1201, "Left");
522
					_thumbs.AppendMenuItem(MF_STRING, 1202, "Right");
523
					_thumbs.AppendMenuItem(MF_STRING, 1203, "Top");
524
					_thumbs.AppendMenuItem(MF_STRING, 1204, "Bottom");
525
					_thumbs.AppendMenuItem(MF_STRING, 1205, "Off");
526
					_thumbs.CheckMenuRadioItem(1200, 1205, th.mode == "grid" ? 1200 : th.mode == "left" ? 1201 : th.mode == "right" ? 1202 : th.mode == "top" ? 1203 : th.mode == "bottom" ? 1204 : 1205);
527
528
529
530
if (th.mode == "left" | th.mode == "right" | th.mode == "top" | th.mode == "bottom")
531
                    {
532
                  _thumbs.AppendMenuSeparator();
533
                  _thumbs.AppendMenuItem(MF_STRING, 1240, "40px");
534
                  _thumbs.AppendMenuItem(MF_STRING, 1250, "50px");
535
                  _thumbs.AppendMenuItem(MF_STRING, 1260, "60px");
536
                  _thumbs.AppendMenuItem(MF_STRING, 1270, "70px");
537
                  _thumbs.AppendMenuItem(MF_STRING, 1280, "80px");
538
                  _thumbs.AppendMenuItem(MF_STRING, 1290, "90px");
539
                  _thumbs.AppendMenuItem(MF_STRING, 1300, "100px");
540
                  _thumbs.AppendMenuItem(MF_STRING, 1350, "150px");
541
                  _thumbs.AppendMenuItem(MF_STRING, 1400, "200px");
542
                  _thumbs.AppendMenuItem(MF_STRING, 1450, "250px");
543
                  _thumbs.AppendMenuItem(MF_STRING, 1500, "300px");
544
                  _thumbs.CheckMenuRadioItem(1240, 1500, th.px + 1200);
545
              }*/
546
547
			/*	_sub3.AppendMenuItem(MF_STRING, 440, "Last.fm artist art");
548
				_sub3.AppendMenuItem(MF_STRING, 441, "Custom folder");
549
				_sub3.CheckMenuRadioItem(440, 441, im.mode == "last.fm" ? 440 : 441);
550
				//_sub3.AppendTo(_menu, MF_STRING, "Image source");
551
               
552
				_menu.AppendMenuSeparator();
553
				/*_sub4.AppendMenuItem(MF_STRING, 410, "Off");
554
				_sub4.AppendMenuItem(MF_STRING, 415, "5 seconds");
555
				_sub4.AppendMenuItem(MF_STRING, 420, "10 seconds");
556
				_sub4.AppendMenuItem(MF_STRING, 430, "20 seconds");
557
				_sub4.CheckMenuRadioItem(410, 430, im.cycle + 410);
558
				_sub4.CheckMenuRadioItem(410, 430, im.cycle + 410);
559
				_menu.AppendMenuSeparator();*/
560
				if (typeof th == "object") {
561
					if (!this.check_feature("now_playing")) _sub5.AppendMenuItem(MF_STRING, 1200, "Grid");
562
					/*_sub5.AppendMenuItem(MF_STRING, 1201, "Left");
563
					_sub5.AppendMenuItem(MF_STRING, 1202, "Right");
564
					_sub5.AppendMenuItem(MF_STRING, 1203, "Top");
565
					_sub5.AppendMenuItem(MF_STRING, 1204, "Bottom");
566
					_sub5.AppendMenuItem(MF_STRING, 1205, "Off");
567
					_sub5.CheckMenuRadioItem(1200, 1205, th.mode == "grid" ? 1200 : th.mode == "left" ? 1201 : th.mode == "right" ? 1202 : th.mode == "top" ? 1203 : th.mode == "bottom" ? 1204 : 1205);*/
568
					if (th.mode != "off") {
569
						/*_sub5.AppendMenuSeparator();
570
						_sub5.AppendMenuItem(MF_STRING, 1275, "75px");
571
						_sub5.AppendMenuItem(MF_STRING, 1300, "100px");
572
						_sub5.AppendMenuItem(MF_STRING, 1350, "150px");
573
						_sub5.AppendMenuItem(MF_STRING, 1400, "200px");
574
						_sub5.AppendMenuItem(MF_STRING, 1450, "250px");
575
						_sub5.AppendMenuItem(MF_STRING, 1500, "300px");
576
						_sub5.CheckMenuRadioItem(1275, 1500, th.px + 1200);*/
577
					}
578
					//_sub5.AppendTo(_menu, MF_STRING, "Thumbs");
579
					//_menu.AppendMenuSeparator();
580
				}
581
				//if (im.trace(x, y) && im.images.length > 0 && (!this.check_feature("thumbs") || th.mode != "grid")) 
582
                {
583
if (auto_yt=="1") _menu.AppendMenuItem(MF_STRING, 22, "Get Next Video");
584
//if (auto_lfm=="1") _menu.AppendMenuItem(MF_STRING, 22, "Get Next Video");
585
if (auto_yt=="0") _menu.AppendMenuItem(MF_STRING, 21, "Get Next Video");
586
//_menu.AppendMenuItem(MF_STRING, 400, "Get All Videos")
587
_menu.AppendMenuItem(MF_STRING, 401, "Search Videos");
588
_menu.AppendMenuSeparator();
589
//_menu.AppendMenuItem(MF_STRING, 402, "Search For Artist");
590-
_menu.AppendMenuItem(MF_STRING, 1914, "Start Artist Radio");
590+
_menu.AppendMenuItem(MF_STRING, 1914, "Start Radio Station");
591
p.artist = p.eval("%artist%");
592-
if (p.artist == "" || p.artist == "?") {_menu.AppendMenuItem(MF_STRING| MF_GRAYED, 2000, "Same Artist Radio");}
592+
if (p.artist == "" || p.artist == "?") {_menu.AppendMenuItem(MF_STRING| MF_GRAYED, 2000, "Same Artist Station");}
593
else
594-
{_menu.AppendMenuItem(MF_STRING, 1915, "Same Artist Radio");}
594+
{_menu.AppendMenuItem(MF_STRING, 1915, "Same Artist Station");}
595
596
_menu.AppendMenuSeparator();
597
_menu.AppendMenuItem(MF_STRING, 403, "Open Same Video");
598
_menu.AppendMenuItem(MF_STRING, 404, "Find in Browser");
599
					//_menu.AppendMenuItem(MF_STRING, 402, "Delete image");
600
					//_menu.AppendMenuSeparator();
601
					//_menu.AppendMenuItem(MF_STRING, 405, "Top");
602
                    //_menu.AppendMenuItem(MF_STRING, 404, "Centre");
603
					//_menu.AppendMenuItem(MF_STRING, 406, "Adjust");
604
					//_menu.AppendMenuItem(MF_STRING, 407, "Stretch");
605
					_menu.CheckMenuRadioItem(404, 407, im.type == "centre" ? 404 : im.type == "top" ? 405 : im.type == "adjust" ? 406 : 407);
606
					_menu.AppendMenuSeparator();
607
				}
608
				break;
609
		}
610
		if (this.check_feature("now_playing")) {
611
			/*_menu.AppendMenuItem(MF_STRING, 44, "Top style");
612
			_menu.AppendMenuItem(MF_STRING, 45, "Bottom style");
613
			_menu.CheckMenuRadioItem(44, 45, np_track_top ? 44 : 45);
614
			_menu.AppendMenuSeparator();
615
			_menu.AppendMenuItem(MF_STRING, 41, "Show CD cover");
616
			_menu.CheckMenuItem(41, np_cd);
617
			_menu.AppendMenuItem(MF_STRING, 42, "Show track info");
618
			_menu.CheckMenuItem(42, np_track);
619
			_menu.AppendMenuItem(MF_STRING, 46, "Show rating");
620
			_menu.CheckMenuItem(46, np_rating);
621
			_menu.AppendMenuItem(MF_STRING, 40, "Show web links");
622
			_menu.CheckMenuItem(40, np_buttons);
623
			_menu.AppendMenuItem(MF_STRING, 43, "Show biography");
624
			_menu.CheckMenuItem(43, np_bio);
625
			_menu.AppendMenuSeparator();*/
626
		}
627
		if (this.check_feature("custom_background")) {
628
			if (!this.dui) _custom_background.AppendMenuItem(MF_STRING, 100, "None");
629
			/*_custom_background.AppendMenuItem(MF_STRING, 101, this.dui ? "Use default UI setting" : "Use columns UI setting");
630
			_custom_background.AppendMenuItem(MF_STRING, 102, "Splitter");
631
			_custom_background.AppendMenuItem(MF_STRING, 104, "Pattern");
632
			_custom_background.AppendMenuItem(MF_STRING, 103, "Custom");
633
			_custom_background.AppendMenuSeparator();
634
			_custom_background.AppendMenuItem(this.background_mode == 3 ? MF_STRING : MF_GRAYED, 105, "Set custom colour...");
635
			_custom_background.CheckMenuRadioItem(101, 104, this.background_mode + 100);
636
			_custom_background.AppendTo(_menu, MF_STRING, "Background");
637
			_menu.AppendMenuSeparator();*/
638
		}
639
		if (typeof l == "object") {
640
			//_menu.AppendMenuItem(MF_STRING, 1900, "Last.fm username...");
641
			if (typeof ps == "object") _menu.AppendMenuItem(l.username.length > 0 ? MF_STRING : MF_GRAYED, 1901, "Last.fm password...");
642
			//_menu.AppendMenuSeparator();
643
		}
644
		if (this.check_feature("metadb")) {
645
			/*_metadb.AppendMenuItem(MF_STRING, 900, "Use display preferences");
646
			_metadb.AppendMenuItem(MF_STRING, 901, "Prefer now playing");
647
			_metadb.AppendMenuItem(MF_STRING, 902, "Follow selected track");
648
			_metadb.CheckMenuRadioItem(900, 903, this.selection_mode + 900);*/
649
			//_metadb.AppendTo(_menu, MF_STRING, "Selection mode");
650
			//_menu.AppendMenuSeparator();
651
		}
652
		if (this.check_feature("remap")) {
653
			//_menu.AppendMenuItem(MF_STRING, 7, "Artist field remapping...");
654
			//_menu.AppendMenuSeparator();
655
		}
656
		//_menu.AppendMenuItem(MF_STRING, 20, "Update script");
657
		//_menu.AppendMenuSeparator();
658
		//if (utils.IsKeyPressed(0x10)) _menu.AppendMenuItem(MF_STRING, 9, "Properties");
659
        _menu.AppendMenuItem(MF_STRING, 9, "Properties...");
660
        if (utils.IsKeyPressed(0x10)) _menu.AppendMenuItem(MF_STRING, 10, "Configure...");
661
		idx = _menu.TrackPopupMenu(x, y);
662
		switch(idx) {
663
			case 1:
664
				on_item_focus_change();
665
				break;
666
			case 2:
667
			case 3:
668
			case 4:
669
			case 5:
670
			case 6:
671
				a.id = idx - 2;
672
				window.SetProperty("artreader_id", a.id);
673
				on_item_focus_change();
674
				break;
675
			case 7:
676
				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);
677
				if (this.artist_tf == "") this.artist_tf = "%path%";
678
				window.SetProperty("YT Search", this.artist_tf);
679
				on_item_focus_change();
680
				break;
681
			case 9:
682
				window.ShowProperties();
683
				break;
684
			case 10:
685
				window.ShowConfigure();
686
				break;
687
			case 11:
688
				c.gloss = !c.gloss;
689
				window.SetProperty("cd_gloss", c.gloss);
690
				window.Repaint();
691
				break;
692
			case 12:
693
				c.shadow = !c.shadow;
694
				window.SetProperty("cd_shadow", c.shadow);
695
				window.Repaint();
696
				break;
697
			case 15:
698
			case 16:
699
			case 17:
700
			case 18:
701
				a.type = idx == 15 ? "centre" : idx == 16 ? "top" : idx == 17 ? "adjust" : "stretch";
702
				window.SetProperty("artreader_image_type", a.type);
703
				window.RepaintRect(a.x, a.y, a.w, a.h);
704
				break;
705
			case 20:
706
				this.update_script();
707
				break;
708
			case 21:
709
				im.downloadLFM1();
710
                break;
711
			case 22:
712
				im.downloadLFM1();
713
				break;
714
			case 23:
715
				fb.ShowPopupMessage("You can get Album Art Downloader here:\n\nhttp://www.hydrogenaudio.org/forums/index.php?showtopic=57392", this.name);
716
				break;
717
			case 25:
718
			case 26:
719
				t.source = idx == 25 ? "last.fm" : "wikipedia";
720
				window.SetProperty("biography_source", t.source);
721
				t.artist = "";
722
				on_item_focus_change();
723
				break;
724
			case 28:
725
				li.show_timestamp = !li.show_timestamp;
726
				window.SetProperty("show_timestamp", li.show_timestamp);
727
				window.RepaintRect(li.x, li.y, li.w, li.h);
728
				break;
729
			case 29:
730
				li.discogs_match = !li.discogs_match;
731
				window.SetProperty("discogs_match", li.discogs_match);
732
				li.artist = "";
733
				on_item_focus_change();
734
				break;
735
			case 30:
736
			case 31:
737
			case 32:
738
				this.normal_font_size = idx == 30 ? 12 : idx == 31 ? 14 : 16;
739
				window.SetProperty("normal_font_size", this.normal_font_size);
740
				this.font_changed();
741
				break;
742
			case 40:
743
				np_buttons = !np_buttons;
744
				window.SetProperty("np_buttons", np_buttons);
745
				on_size();
746
				window.Repaint();
747
				break;
748
			case 41:
749
				np_cd = !np_cd;
750
				window.SetProperty("np_cd", np_cd);
751
				window.Repaint();
752
				break;
753
			case 42:
754
				np_track = !np_track;
755
				window.SetProperty("np_track", np_track);
756
				on_size();
757
				window.Repaint();
758
				break;
759
			case 43:
760
				np_bio = !np_bio;
761
				window.SetProperty("np_bio", np_bio);
762
				window.Repaint();
763
				break;
764
			case 44:
765
			case 45:
766
				np_track_top = idx == 44 ? true : false;
767
				window.SetProperty("np_track_top", np_track_top);
768
				on_size();
769
				window.Repaint();
770
				break;
771
			case 46:
772
				np_rating = !np_rating;
773
				window.SetProperty("np_rating", np_rating);
774
				on_size();
775
				window.Repaint();
776
				break;
777
			case 51:
778
			case 52:
779
			case 53:
780
				l.auto_correct = !l.auto_correct;
781
				window.SetProperty("lastfm_auto_correct", l.auto_correct);
782
				if (this.metadb) {
783
					if (idx == 51) li.get();
784
					if (idx == 53) t.get();
785
				}
786
				break;
787
			case 100:
788
			case 101:
789
			case 102:
790
			case 103:
791
			case 104:
792
				this.background_mode = idx - 100;
793
				window.SetProperty("background_mode", this.background_mode);
794
				window.Repaint();
795
				break;
796
			case 105:
797
				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);
798
				window.SetProperty("background_custom_colour", this.background_custom_colour);
799
				window.Repaint();
800
				break;
801
			case 200:
802
				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);
803
				window.SetProperty("text_filename_tf", t.filename_tf);
804
				on_item_focus_change();
805
				break;
806
			case 201:
807
				t.fixed = !t.fixed;
808
				window.SetProperty("text_fixed_font", t.fixed);
809
				t.calc();
810
				window.RepaintRect(t.x, t.y, t.w, t.h);
811
				break;
812
			case 400:
813
				im.downloadALL();
814
				break;
815
			case 401:
816
				fb.RunMainMenuCommand("View/Youtube Source");
817
				break;
818
			case 402:
819
				im.downloadART();
820
				break;
821
			case 403:
822
				im.downloadART_TITLE();
823
				break;
824
			case 404:
825
            p.artist = p.eval("%artist% %title%");
826
            p.browser("http://www.youtube.com/results?search_query=" + encodeURIComponent(p.artist));
827
            break;
828
			case 405:
829
			case 406:
830
			case 407:
831
				im.type = idx == 404 ? "centre" : idx == 405 ? "top" : idx == 406 ? "adjust" : "stretch";
832
				//window.SetProperty("Image type", im.type);
833
				window.Repaint();
834
				break;
835
			case 410:
836
			case 415:
837
			case 420:
838
			case 425:
839
            case 430:
840
				cycle2 = idx - 410;
841
				window.SetProperty("Image cycle", cycle2);
842
                cicleTimer = undefined;
843
                cicleTimerStarted = false;
844
                stopTimer();
845
                startTimer();
846
                cicleTimerStarted = true;
847
                break;
848
			case 440:
849
			case 441:
850
				im.mode = idx == 440 ? "last.fm" : "custom";
851
				window.SetProperty("image_mode", im.mode);
852
				im.artist = "";
853
				im.folder = "";
854
				on_item_focus_change();
855
				break;
856
			case 442:
857
				im.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, im.custom_folder_tf);
858
				if (im.custom_folder_tf == "") im.custom_folder_tf = "$directory_path(%path%)";
859
				window.SetProperty("image_custom_folder_tf", im.custom_folder_tf);
860
				im.folder = "";
861
				on_item_focus_change();
862
				break;
863
			case 450:
864
				im.download();
865
				break;
866
			case 451:
867
			case 452:
868
			case 453:
869
				im.auto_download = idx == 451 ? "on" : idx == 452 ? "library" : "off";
870
				window.SetProperty("image_auto_download", im.auto_download);
871
				break;
872
			case 461:
873
			case 463:
874
			case 465:
875
				im.limit = idx - 460;
876
				window.SetProperty("image_limit", 50);
877
				break;
878
			case 490:
879
			case 491:
880
			case 492:
881
			case 493:
882
				im.type = idx == 490 ? "centre" : idx == 491 ? "top" : idx == 492 ? "adjust" : "stretch";
883
				window.SetProperty("image_type", im.type);
884
				window.RepaintRect(im.x, im.y, im.w, im.h);
885
				break;
886
			case 500:
887
			case 501:
888
			case 502:
889
				li.echonest_mode = idx - 500;
890
				window.SetProperty("echonest_mode", li.echonest_mode);
891
				li.artist = "";
892
				on_item_focus_change();
893
				break;
894
			case 600:
895
				li.autoplaylists_title = this.InputBox("Enter a new title", this.name, li.autoplaylists_title);
896
				if (li.autoplaylists_title == "") li.autoplaylists_title = "Autoplaylists";
897
				window.SetProperty("autoplaylists_title", li.autoplaylists_title);
898
				window.Repaint();
899
				break;
900
			case 601:
901
			case 602:
902
			case 603:
903
			case 604:
904
			case 605:
905
			case 606:
906
			case 607:
907
			case 608:
908
				li.autoplaylists_slot = idx - 600;
909
				window.SetProperty("autoplaylists_slot", li.autoplaylists_slot);
910
				li.filename = this.settings_folder + "autoplaylists" + li.autoplaylists_slot;
911
				li.offset = 0;
912
				li.update();
913
				break;
914
			case 610:
915
			case 611:
916
				li.autoplaylists_success = idx == 610 ? true : false;
917
				window.SetProperty("autoplaylists_success", li.autoplaylists_success);
918
				break;
919
			case 620:
920
			case 621:
921
			case 622:
922
			case 623:
923
			case 624:
924
			case 625:
925
			case 626:
926
			case 627:
927
				li.data.push(li.autoplaylists_deleted_items[idx - 620]);
928
				if (li.data.length > li.rows) li.offset = li.data.length - li.rows;
929
				li.autoplaylists_deleted_items.splice(idx - 620, 1);
930
				this.save(li.data.join("\n"), li.filename);
931
				window.NotifyOthers("autoplaylists", "update");
932
				li.update();
933
				break;
934
			case 650:
935
				li.autoplaylists_remove_duplicates = !li.autoplaylists_remove_duplicates
936
				window.SetProperty("autoplaylists_remove_duplicates", li.autoplaylists_remove_duplicates);
937
				break;
938
			case 700:
939
			case 701:
940
				li.musicbrainz_mode = idx == 700 ? "releases" : "URLs";
941
				window.SetProperty("musicbrainz_mode", li.musicbrainz_mode);
942
				li.artist = "";
943
				on_item_focus_change();
944
				break;
945
			case 702:
946
				li.musicbrainz_album = !li.musicbrainz_album;
947
				window.SetProperty("musicbrainz_album", li.musicbrainz_album);
948
				li.artist = "";
949
				on_item_focus_change();
950
				break;
951
			case 703:
952
				li.musicbrainz_ep = !li.musicbrainz_ep;
953
				window.SetProperty("musicbrainz_ep", li.musicbrainz_ep);
954
				li.artist = "";
955
				on_item_focus_change();
956
				break;
957
			case 704:
958
				li.musicbrainz_single = !li.musicbrainz_single;
959
				window.SetProperty("musicbrainz_single", li.musicbrainz_single);
960
				li.artist = "";
961
				on_item_focus_change();
962
				break;
963
			case 705:
964
				li.musicbrainz_live = !li.musicbrainz_live;
965
				window.SetProperty("musicbrainz_live", li.musicbrainz_live);
966
				li.artist = "";
967
				on_item_focus_change();
968
				break;
969
			case 706:
970
				li.musicbrainz_remix = !li.musicbrainz_remix;
971
				window.SetProperty("musicbrainz_remix", li.musicbrainz_remix);
972
				li.artist = "";
973
				on_item_focus_change();
974
				break;
975
			case 707:
976
				li.musicbrainz_compilation = !li.musicbrainz_compilation;
977
				window.SetProperty("musicbrainz_compilation", li.musicbrainz_compilation);
978
				li.artist = "";
979
				on_item_focus_change();
980
				break;
981
			case 708:
982
				li.musicbrainz_show_release_type = !li.musicbrainz_show_release_type;
983
				window.SetProperty("musicbrainz_show_release_type", li.musicbrainz_show_release_type);
984
				window.RepaintRect(li.x, li.y, li.w, li.h);
985
				break;
986
			case 801:
987
			case 802:
988
			case 803:
989
			case 804:
990
			case 805:
991
				li.lastfm_mode = idx - 801;
992
				window.SetProperty("lastfm_mode", li.lastfm_mode);
993
				li.artist = "";
994
				on_item_focus_change();
995
				break;
996
			case 810:
997
				li.lastfm_pause = !li.lastfm_pause;
998
				window.SetProperty("lastfm_pause", li.lastfm_pause);
999
				break;
1000
			case 811:
1001
			case 812:
1002
				li.lastfm_button = idx == 811 ? "spotify" : "auto";
1003
				window.SetProperty("lastfm_button", li.lastfm_button);
1004
				window.RepaintRect(li.x, li.y, li.w, li.h);
1005
				break;
1006
			case 900:
1007
			case 901:
1008
			case 902:
1009
				this.selection_mode = idx - 900;
1010
				window.SetProperty("selection_mode", this.selection_mode);
1011
				on_item_focus_change();
1012
				break;
1013
			case 1000:
1014
				li.get();
1015
				break;
1016
			case 1001:
1017
			case 1002:
1018
			case 1003:
1019
				li.lastfm_charts_mode = idx - 1001;
1020
				window.SetProperty("lastfm_charts_mode", li.lastfm_charts_mode);
1021
				li.update();
1022
				break;
1023
			case 1004:
1024
			case 1005:
1025
			case 1006:
1026
			case 1007:
1027
			case 1008:
1028
			case 1009:
1029
				li.lastfm_charts_period = idx - 1004;
1030
				window.SetProperty("lastfm_charts_period", li.lastfm_charts_period);
1031
				li.update();
1032
				break;
1033
			case 1010:
1034
				li.lastfm_charts_bar_colour = this.InputBox("Enter a custom colour for the bars. Uses RGB. Example usage:\n\n234-211-74", this.name, li.lastfm_charts_bar_colour);
1035
				window.SetProperty("lastfm_charts_bar_colour", li.lastfm_charts_bar_colour);
1036
				window.Repaint();
1037
				break;
1038
			case 1100:
1039
			case 1109:
1040
				ps.full_import = idx == 1100 ? true : false;
1041
				ps.start_import();
1042
				break;
1043
			case 1101:
1044
				ps.finish_import();
1045
				break;
1046
			case 1102:
1047
				ps.show_console = !ps.show_console;
1048
				window.SetProperty("playcount_sync_show_console", ps.show_console);
1049
				break;
1050
			case 1103:
1051
				ps.library = !ps.library;
1052
				window.SetProperty("playcount_sync_library", ps.library);
1053
				break;
1054
			case 1104:
1055
			case 1105:
1056
				ps.auto_love = idx == 1104 ? false : true;
1057
				window.SetProperty("playcount_sync_auto_love", ps.auto_love);
1058
				break;
1059
			case 1106:
1060
				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);
1061
				window.SetProperty("playcount_sync_auto_love_tf", ps.auto_love_tf);
1062
				break;
1063
			case 1107:
1064
			case 1108:
1065
				ps.icon = idx == 1107 ? "tango" : "silk";
1066
				window.SetProperty("playcount_sync_icon", ps.icon);
1067
				b.update();
1068
				break;
1069
			case 1200:
1070
			case 1201:
1071
			case 1202:
1072
			case 1203:
1073
			case 1204:
1074
			case 1205:
1075
				th.mode = idx == 1200 ? "grid" : idx == 1201 ? "left" : idx == 1202 ? "right" : idx == 1203 ? "top" : idx == 1204 ? "bottom" : "off";
1076
				//window.SetProperty("Thumbs mode", th.mode);
1077
				th.nc = true;
1078
				on_size();
1079
				window.Repaint();
1080
				break;
1081
			case 1240:
1082
			case 1250:
1083
			case 1260:
1084
			case 1270:
1085
			case 1280:
1086
			case 1290:
1087
            case 1300:
1088
			case 1350:
1089
			case 1400:
1090
			case 1450:
1091
			case 1500:
1092
				th.px = idx - 1200;
1093
				
1094
				th.nc = true;
1095
				on_size();
1096
				window.Repaint();
1097
				break;
1098
			case 1700:
1099
				t.title = this.InputBox("You can use full title formatting here.", this.name, t.title);
1100
				window.SetProperty("text_title", t.title);
1101
				window.Repaint();
1102
				break;
1103
			case 1701:
1104
				t.tag = this.InputBox("Enter a custom tag.", this.name, t.tag);
1105
				window.SetProperty("text_tag", t.tag);
1106
				t.filename = "";
1107
				on_item_focus_change();
1108
				break;
1109
			case 1702:
1110
				t.centre = !t.centre;
1111
				window.SetProperty("text_centre", t.centre);
1112
				window.RepaintRect(t.x, t.y, t.w, t.h);
1113
				break;
1114
			case 1800:
1115
			case 1801:
1116
			case 1802:
1117
				var period = idx == 1800 ? 0 : idx == 1801 ? ONE_DAY : ONE_WEEK;
1118
				s.clear_images(period);
1119
				break;
1120
			case 1803:
1121
				s.library = !s.library;
1122
				window.SetProperty("seekbar_library", s.library);
1123
				break;
1124
			case 1804:
1125
				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);
1126
				window.SetProperty("sox_params", s.sox_params);
1127
				if (fb.IsPlaying) s.playback_new_track();
1128
				break;
1129
			case 1805:
1130
				s.marker = this.InputBox("Enter a custom colour for the marker. Uses RGB. Example usage:\n\n234-211-74", this.name, s.marker);
1131
				window.SetProperty("seekbar_marker", s.marker);
1132
				break;
1133
			case 1900:
1134
				l.update_username();
1135
				break;
1136
			case 1901:
1137
				l.update_password();
1138
				break;
1139
            
1140
                
1141
           case 1902:
1142
                auto_yt = 0;
1143
                window.SetProperty("YT Radio", "0");
1144
                break;
1145
       
1146
           case 1903:
1147
                auto_yt = 1;
1148
                window.SetProperty("YT Radio", "1");
1149
                break; 
1150
  
1151
1152
            case 1904:
1153
            if (server=="on")server = window.SetProperty("YT Radio", "off");
1154
            if (server=="off")server = window.SetProperty("YT Radio", "on");
1155
            break;
1156
1157
            case 1905: 
1158
            auto_lfm = 0;
1159
            window.SetProperty("LFM Radio", "0");
1160
            break;
1161
            
1162
            case 1906:  
1163
             auto_lfm = 1;
1164
             window.SetProperty("LFM Radio", "1");
1165
             break;
1166
            
1167
            case 1907: 
1168
            case 1908:    
1169
            case 1909:    
1170
            case 1910: 
1171
            im.limit = idx - 1904;
1172
            //window.SetProperty("Download limit", im.limit);
1173
            break;
1174
            
1175
            case 1911:    
1176
            case 1912:    
1177
            case 1913: 
1178
            size = idx == 1911 ? "low" : idx == 1912 ? "medium" : idx == 1913 ? "high" : "high";
1179
		    window.SetProperty("Download quality", size);
1180
            break;
1181
            
1182
            case 1914:
1183
            Start = START_ARTIST;
1184-
            START_ARTIST = this.InputBox("Type Artist to Start Radio", this.name, START_ARTIST);
1184+
            START_ARTIST = this.InputBox("Type Artist to Start Station\n\n( *genre - will play genre station)", this.name, START_ARTIST);
1185-
            window.SetProperty("Artist Station", START_ARTIST);
1185+
            window.SetProperty("YT  Station", START_ARTIST);
1186
            if (START_ARTIST==Start)
1187
            {
1188
            }
1189
            else
1190
            {
1191
            auto_yt = 1;
1192
            window.SetProperty("YT Radio", "1");
1193
            im.downloadLFM0();
1194
            }
1195
            break;
1196
            
1197
            case 1915:
1198
            Start = START_ARTIST;
1199
            p.artist = p.eval("%artist%");
1200
            if (p.artist == "" || p.artist == "?") return;
1201
            START_ARTIST = p.artist;
1202-
            window.SetProperty("Artist Station", p.artist);
1202+
            window.SetProperty("YT  Station", p.artist);
1203
            auto_yt = 1;
1204
            window.SetProperty("YT Radio", "1");
1205
            on_item_focus_change();
1206
            /*if (START_ARTIST==Start)
1207
            {
1208
            }
1209
            else
1210
            {*/
1211
            im.downloadLFM0();
1212
            //}
1213
            break;
1214
            
1215
            
1216
        }
1217
		_menu.Dispose();
1218
		_custom_background.Dispose();
1219
		_metadb.Dispose();
1220
		_cover.Dispose();
1221
		_font.Dispose();
1222
		_sub1.Dispose();
1223
		_sub2.Dispose();
1224
		_sub3.Dispose();
1225
		_sub4.Dispose();
1226
		_sub5.Dispose();
1227
	}
1228
	
1229
	this.features_init = function() {
1230
		for (i = 0; i < this.features.length; i++) {
1231
			switch(this.features[i]) {
1232
				case "custom_background":
1233
					//this.background_mode = (0);
1234
                    //window.GetProperty("background_mode", 0);
1235
					//this.background_custom_colour = ("0-0-0");
1236
                    //window.GetProperty("background_custom_colour", "0-0-0");
1237
					break;
1238
				case "metadb":
1239
					this.selection_mode = 1;
1240
					break;
1241
				case "themes":
1242
					this.themed_seekbar = window.CreateThemeManager("Progress");
1243
					this.themed_header = window.CreateThemeManager("Header");
1244
					this.themed_header.SetPartAndStateId(1, 1);
1245
					this.themed_button = window.CreateThemeManager("Button");
1246
					break;
1247
				case "remap":
1248
					this.artist_tf = window.GetProperty("YT Search", "%path%");
1249
					break;
1250
			}
1251
		}
1252
	}
1253
	
1254
	this.check_feature = function(f) {
1255
		for (i = 0; i < this.features.length; i++) {
1256
			if (this.features[i] == f) return true;
1257
		}
1258
		return false;
1259
	}
1260
	
1261
	this.eval = function(tf) {
1262
		if (!this.metadb || tf == "") return "";
1263
		if (fb.IsPlaying && this.metadb.RawPath.indexOf("file://") != 0) {
1264
			return fb.TitleFormat(tf).Eval();
1265
		} else {
1266
			return fb.TitleFormat(tf).EvalWithMetadb(this.metadb);
1267
		}
1268
	}
1269
	
1270
	this.open = function(filename) {
1271
		return utils.ReadTextFile(filename);
1272
	}
1273
	
1274
	this.save = function(t, f) {
1275
		try {
1276
			var ts = this.fso.OpenTextFile(f, 2, true, -1);
1277
			ts.WriteLine(t);
1278
			ts.Close();
1279
			return true;
1280
		} catch(e) {
1281
			return false;
1282
		}
1283
	}
1284
	
1285
	this.console = function(message) {
1286
		fb.trace(this.name + ": " + message);
1287
	}
1288
	
1289
	this.strip_tags = function(value) {
1290
		if (!this.doc) this.doc = new ActiveXObject("htmlfile");
1291
		try {
1292
			this.doc.open();
1293
			var div = this.doc.createElement("div");
1294
			div.innerHTML = value.replace(/\n/g, "<br>");
1295
			return div.innerText.trim();
1296
		} catch(e) {
1297
			return "Error reading content.";
1298
		}
1299
	}
1300
	
1301
	this.InputBox = function(prompt, title, value) {
1302
		prompt = prompt.replace(/"/g, '" + Chr(34) + "').replace(/\n/g, '" + Chr(13) + "');
1303
		title = title.replace(/"/g, '" + Chr(34) + "');
1304
		value = value.replace(/"/g, '" + Chr(34) + "');
1305
		var temp_value = this.vb.eval('InputBox' + '("' + prompt + '", "' + title + '", "' + value + '")');
1306
		if (typeof temp_value == "undefined") return value;
1307
		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);
1308
		return temp_value.trim();
1309
	}
1310
	
1311
	this.MsgBox = function(prompt, buttons, title) {
1312
		prompt = prompt.replace(/"/g, '" + Chr(34) + "').replace(/\n/g, '" + Chr(13) + "');
1313
		title = title.replace(/"/g, '" + Chr(34) + "');
1314
		return this.vb.eval('MsgBox' + '("' + prompt + '", "' + buttons + '", "' + title + '")');
1315
	}
1316
	
1317
	this.browser = function(command) {
1318
		if (!this.run(command)) this.MsgBox("Unable to launch your default browser.", 0, this.name);
1319
	}
1320
	
1321
	this.run = function(command) {
1322
		try {
1323
			this.WshShell.Run(command);
1324
			return true;
1325
		} catch(e) {
1326
			return false;
1327
		}
1328
	}
1329
	
1330
	this.aad = function() {
1331
		if (!this.app) this.app = new ActiveXObject("Shell.Application");
1332
		var aad_path = window.GetProperty("aad_path", "");
1333
		if (!this.fso.FileExists(aad_path)) {
1334
			var folder = this.app.BrowseForFolder(0, "Locate Album Art Downloader", 0x00000200);
1335
			var file = folder ? folder.items().item().path + "\\AlbumArt.exe" : "";
1336
			if (this.fso.FileExists(file)) {
1337
				aad_path = file;
1338
				window.SetProperty("aad_path", file);
1339
			}
1340
		}
1341
		if (this.fso.FileExists(aad_path)) {
1342
			var album_artist = "/ar \"" + this.eval("[%album artist%]") + "\"";
1343
			var album = " /al \"" + this.eval("[%album%]") + "\"";
1344
			this.run("\"" + aad_path + "\"" + album_artist + album);
1345
		}
1346
	}
1347
	
1348
	this.tt = function(t) {
1349
		if (this.tooltip.Text == t) return;
1350
		this.tooltip.Text = t;
1351
		this.tooltip.Activate();
1352
	}
1353
	
1354
	this.ttd = function() {
1355
		this.tooltip.Text = "";
1356
		this.tooltip.Deactivate();
1357
	}
1358
	
1359
	this.splitRGB = function(value) {
1360
		var temp_col = value.split("-");
1361
		return RGB(temp_col[0], temp_col[1], temp_col[2]);
1362
	}
1363
	
1364
	this.draw_background = function(gr) {
1365
		if (this.check_feature("custom_background")) {
1366
			var col;
1367
			switch(this.background_mode) {
1368
				case 0:
1369
					col = null;
1370
					break;
1371
				case 1:
1372
					col = this.backcolour;
1373
					break;
1374
				case 2:
1375
					col = utils.GetSysColor(15);
1376
					break;
1377
				case 3:
1378
					col = this.splitRGB(this.background_custom_colour);
1379
					break;
1380
				case 4:
1381
					col = null;
1382
					var spacing = 3;
1383
					var line_thickness = 1;
1384
					var bg = RGB(65, 65, 65);
1385
					var colour = RGB(92, 92, 92);
1386
					gr.FillSolidRect(0, 0, this.w, this.h, bg);
1387
					for (i = 0; i < Math.ceil(this.w / spacing); i++) {
1388
						gr.DrawLine(i * spacing, 0, i * spacing, this.h, line_thickness, colour);
1389
					}
1390
					for (i = 0; i < Math.ceil(this.h / spacing); i++) {
1391
						gr.DrawLine(0, i * spacing, this.w, i * spacing, line_thickness, colour);
1392
					}
1393
					break;
1394
			}
1395
			if (col) gr.FillSolidRect(0, 0, this.w, this.h, col);
1396
		} else {
1397
			gr.FillSolidRect(0, 0, this.w, this.h, this.backcolour);
1398
		}
1399
	}
1400
	
1401
	this.draw_image = function(gr, img, pos_x, pos_y, width, height, type, border, alpha) {
1402
		if (!img) return;
1403
		gr.SetInterpolationMode(7);
1404
		switch(type) {
1405
			case "centre":
1406
			  case "top":
1407
               {
1408
                var sr = img.Width / img.Height;
1409
				var dr = width / height;
1410
				if (sr < dr) {
1411
					var r = img.Width / width;
1412
					var ch = height * r;
1413
					var sy = Math.round((img.Height - ch) / (type == "top" ? 1000 : 2));
1414
					var cw = img.Width;
1415
					var sx = 0;
1416
				} else {
1417
                    var r = img.Height / height;
1418
					var cw = width * r;
1419
					var sx = Math.round((img.Width - cw) / 2);
1420
					var ch = img.Height;
1421
					var sy = 0;
1422
				}
1423
                  { 
1424
                   gr.DrawImage(img, pos_x, pos_y, width, height, sx + 5, sy + 5, cw - 10, ch - 10, 0, alpha || 255);
1425
				   if (border) gr.DrawRect(pos_x, pos_y, width - 1, height - 1, 1, border);    
1426
                  }
1427
             }
1428
                break;
1429
			case "stretch":
1430
                //strech
1431
                
1432
                 gr.DrawImage(img, pos_x, pos_y, width, height, 5, 5, img.Width-10, img.Height-10, 0, alpha || 255);
1433
				 if (border) gr.DrawRect(pos_x, pos_y, width - 1, height - 1, 1, border);
1434
                 
1435
                break;
1436
			case "adjust":
1437
			default:
1438
                //adjust
1439
                var s = Math.min(width / img.Width, height / img.Height);
1440
				var nw = Math.round(img.Width * s);
1441
				var nh = Math.round(img.Height * s);
1442
				pos_x += Math.round((width - nw) / 2);
1443
				pos_y += Math.round((height - nh) / 2);
1444
                
1445
                
1446
                gr.DrawImage(img, pos_x, pos_y, nw, nh, 5, 5, img.Width-10, img.Height-10, 0, alpha || 255);
1447
                if (border) gr.DrawRect(pos_x, pos_y, nw - 1, nh - 1, 1, border);
1448
				break;
1449
		
1450
	}
1451
}
1452
	this.header = function(gr, text) {
1453
		this.left_text(gr, text, this.title_font, this.textcolour_hl, 6, 6, this.w - 77, 24);
1454
		gr.DrawLine(6, 29, this.w - 6, 29, 1, this.textcolour_hl);
1455
	}
1456
	
1457
	this.centre_text = function(gr, text, font, colour, x, y, w, h) {
1458
		gr.GdiDrawText(text, font, colour, x, y, w, h, DT_VCENTER | DT_CENTER | DT_WORDBREAK | DT_CALCRECT | DT_NOPREFIX);
1459
	}
1460
	
1461
	this.left_text = function(gr, text, font, colour, x, y, w, h) {
1462
		gr.GdiDrawText(text, font, colour, x, y, w, h, DT_VCENTER | DT_END_ELLIPSIS | DT_CALCRECT | DT_NOPREFIX);
1463
	}
1464
	
1465
	this.right_text = function(gr, text, font, colour, x, y, w, h) {
1466
		gr.GdiDrawText(text, font, colour, x, y, w, h, DT_VCENTER | DT_RIGHT | DT_END_ELLIPSIS | DT_CALCRECT | DT_NOPREFIX);
1467
	}
1468
	
1469
	this.format_time = function(t) {
1470
		var h = Math.floor(t / 3600);
1471
		var m = Math.floor((t -= h * 3600) / 60);
1472
		var s = Math.floor(t -= m * 60);
1473
		return((h > 0 ? h + ":" + (m < 10 ? "0" + m : m) : m) + ":" + (s < 10 ? "0" + s : s));
1474
	}
1475
	
1476
	this.check_version = function() {
1477
		//not used any more but will leave intact so old scripts don't crash.
1478
		return;
1479
	}
1480
	
1481
	this.update_script = function() {
1482
		if (!this.xmlhttp) this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
1483
		this.xmlhttp.open("GET", this.common_url, true);
1484
		this.xmlhttp.send();
1485
		this.xmlhttp.onreadystatechange = function() {
1486
			if (p.xmlhttp.readyState == 4) {
1487
				switch(p.xmlhttp.status) {
1488
					case 200:
1489
						var text = p.xmlhttp.responsetext;
1490
						switch (true) {
1491
							case text.indexOf("function panel") == -1:
1492
								p.MsgBox("Unexpected server error. Not updating.", 0, p.name);
1493
								break;
1494
							case text.indexOf('var VERSION = "' + VERSION) == 0:
1495
								p.MsgBox("Already using latest version.", 0, p.name);
1496
								break;
1497
							default:
1498
								if (p.save(text, p.common_filename)) {
1499
									if (p.MsgBox("Download successful. Restart foobar2000 now?", 4, p.name) == 6) fb.RunMainMenuCommand("File/Restart");
1500
								} else {
1501
									p.MsgBox("Unexpected error. Not updating.", 0, p.name);
1502
								}
1503
								break;
1504
						}
1505
						break;
1506
					case 404:
1507
						fb.ShowPopupMessage("The script reports that the update file has not been found. It could be a temporary problem with dropbox but if this error persists then it is most likely due to support stopping for this version. Check the hydrogenaudio thread or the full zip for updates.\n\nhttp://www.hydrogenaudio.org/forums/index.php?showtopic=77883\n" + p.root_url + "samples.zip", p.name);
1508
						break;
1509
					default:
1510
						p.console(p.xmlhttp.responsetext || "HTTP error: " + p.xmlhttp.status);
1511
						break;
1512
				}
1513
			}
1514
		}
1515
	}
1516
//remove false string from file names	
1517
    this.clean_filename = function(filename) {
1518
		return filename.replace(/[\/\\|:]/g, '-').replace(/\*/g, 'x').replace(/"/g, "''").replace(/[?<>]/g, '_');
1519
	}
1520
    
1521
    
1522
    
1523
	this.json_parse = function(text) {
1524
		try {
1525
			var data = JSON.parse(text);
1526
			return data;
1527
		} catch(e) {
1528
			this.console("JSON.parse error.");
1529
			return false;
1530
		}
1531
	}
1532
	
1533
	this.name = name;
1534
	this.features = features;
1535
	this.dui = window.InstanceType;
1536
	this.script_path = fb.ProfilePath;
1537
	this.images_path = this.script_path + "images\\";
1538
	this.root_url = "https://dl.dropboxusercontent.com/u/22801321/wsh/"
1539
	this.common_url = this.root_url + "marc2003/common7.js";
1540
	this.common_filename = this.script_path + "common7.js";
1541
	this.tooltip = window.CreateTooltip();
1542
	this.w = 0;
1543
	this.h = 0;
1544
	this.mx = 0;
1545
	this.my = 0;
1546
	this.metadb = fb.GetFocusItem();
1547
	this.WshShell = new ActiveXObject("WScript.Shell");
1548
	this.fso = new ActiveXObject("Scripting.FileSystemObject");
1549
	this.vb = new ActiveXObject("ScriptControl");
1550
	this.vb.Language = "VBScript";
1551
	//this.settings_folder = fb.ProfilePath + "last_fm\\";
1552
	//if (!this.fso.FolderExists(this.settings_folder)) this.fso.CreateFolder(this.settings_folder);
1553
	
1554
    //this.data_folder = lfm_folder + "\\";
1555
    //if (lfm_folder==fb.ProfilePath + "Artist_info") if (!this.fso.FolderExists(this.data_folder)) this.fso.CreateFolder(this.data_folder), this.data_folder=this.data_folder;
1556
    //if (!this.fso.FolderExists(this.data_folder)) return;   
1557
    this.artist = "";
1558
	this.artist_tf = "%path%";
1559
	this.normal_font_size = (12);
1560
    //window.GetProperty("normal_font_size", 12);
1561
	this.list_font_size = 11;
1562
	this.up_img = gdi.Image(this.images_path + "down.png");
1563
	this.down_img = gdi.Image(this.images_path + "down.png");
1564
	this.metadb_func = typeof on_metadb_changed == "function";
1565
	this.features_init();
1566
	this.colors_changed();
1567
	this.font_changed();
1568
}
1569
1570
function artreader(x, y, w, h) {
1571
	this.draw = function(gr) {
1572
		if (!this.img) return;
1573
		p.draw_image(gr, this.img, this.x, this.y, this.w, this.h, this.type);
1574
	}
1575
	
1576
	this.metadb_changed = function() {
1577
		if (!p.metadb) return;
1578
		this.img && this.img.Dispose();
1579
		this.path = "";
1580
		this.img = utils.GetAlbumArtV2(p.metadb, this.id);
1581
		window.RepaintRect(this.x, this.y, this.w, this.h);
1582
		utils.GetAlbumArtAsync(window.ID, p.metadb, this.id);
1583
	}
1584
	
1585
	this.get_album_art_done = function(ip) {
1586
		this.path = ip;
1587
	}
1588
	
1589
	this.trace = function(x, y) {
1590
		return (x > this.x && x < this.x + this.w && y > this.y && y < this.y + this.h);
1591
	}
1592
	
1593
	this.wheel = function(step) {
1594
		if (!this.trace(p.mx, p.my)) return false;
1595
		this.id -= step;
1596
		if (this.id < 0) this.id = 4;
1597
		if (this.id > 4) this.id = 0;
1598
		window.SetProperty("artreader_id", this.id);
1599
		this.metadb_changed();
1600
		return true;
1601
	}
1602
	
1603
	this.move = function(x, y) {
1604
		if (this.trace(x, y)) {
1605
			if (this.img) p.tt("Original size: " + this.img.Width + "x" + this.img.Height + "px");
1606
			return true;
1607
		} else {
1608
			p.ttd();
1609
			return false;
1610
		}
1611
	}
1612
	
1613
	this.lbtn_dblclk = function(x, y) {
1614
		if (!this.trace(x, y)) return false;
1615
		if (this.img) p.run("explorer /select,\"" + this.path + "\"");
1616
		return true;
1617
	}
1618
	
1619
	this.x = x;
1620
	this.y = y;
1621
	this.w = w;
1622
	this.h = h;
1623
	this.id = window.GetProperty("artreader_id", 0);
1624
	this.img = null;
1625
	this.path = null;
1626
	this.type = window.GetProperty("artreader_image_type", "top");
1627
}
1628
1629
function buttons() {
1630
	this.draw = function(gr) {
1631
		for (i in this.buttons) {
1632
			this.buttons[i].draw(gr);
1633
		}
1634
	}
1635
	
1636
	this.move = function(x, y) {
1637
		this.tmp_btn = null;
1638
		for (i in this.buttons) {
1639
			if (this.buttons[i].trace(x, y)) this.tmp_btn = i;
1640
		}
1641
		if (this.btn == this.tmp_btn) return this.btn;
1642
		if (this.tmp_btn) this.buttons[this.tmp_btn].state("hover");
1643
		if (this.btn) this.buttons[this.btn].state("normal");
1644
		this.btn = this.tmp_btn;
1645
		return this.btn;
1646
	}
1647
	
1648
	this.lbtn_up = function(x, y) {
1649
		if (!this.btn) return false;
1650
		this.buttons[this.btn].lbtn_up(x, y);
1651
		return true;
1652
	}
1653
	
1654
	this.leave = function() {
1655
		if (this.btn) this.buttons[this.btn].state("normal");
1656
		this.btn = null;
1657
	}
1658
	
1659
	this.buttons = [];
1660
	this.btn = null;
1661
}
1662
1663
function button(x, y, w, h, img_src, func, tiptext, themed) {
1664
	this.draw = function (gr) {
1665
		if (this.themed) {
1666
			p.themed_button.SetPartAndStateId(1, this.id);
1667
			p.themed_button.DrawThemeBackground(gr, this.x, this.y, this.w, this.h);
1668
			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, "adjust");
1669
		} else {
1670
			this.img && p.draw_image(gr, this.img, this.x, this.y, this.w, this.h, "adjust");
1671
		}
1672
	}
1673
	
1674
	this.trace = function(x, y) {
1675
		return (x > this.x && x < this.x + this.w && y > this.y && y < this.y + this.h);
1676
	}
1677
	
1678
	this.lbtn_up = function () {
1679
		this.func && this.func(x, y);
1680
	}
1681
	
1682
	this.state = function(s) {
1683
		if (s == "hover") {
1684
			this.img = this.img_hover;
1685
			this.id = 2;
1686
			p.tt(this.tiptext);
1687
		} else {
1688
			this.img = this.img_normal;
1689
			this.id = 0;
1690
			p.ttd();
1691
		}
1692
		window.RepaintRect(this.x, this.y, this.w, this.h);
1693
	}
1694
	
1695
	this.x = x;
1696
	this.y = y;
1697
	this.w = w;
1698
	this.h = h;
1699
	this.func = func;
1700
	this.tiptext = tiptext;
1701
	this.themed = themed;
1702
	this.id = 0;
1703
	this.img_normal = gdi.Image(p.images_path + img_src.normal);
1704
	this.img_hover = img_src.hover ? gdi.Image(p.images_path + img_src.hover) : this.img_normal;
1705
	this.img = this.img_normal;
1706
}
1707
1708
function cd(x, y, w, h) {
1709
	this.draw = function(gr) {
1710
		if (this.shadow) p.draw_image(gr, this.shadow_img, this.x, this.y, this.w, this.h, "adjust");
1711
		p.draw_image(gr, this.case_img, this.x, this.y, this.w, this.h, "adjust");
1712
		if (this.img) {
1713
			this.ratio = Math.min(this.w / this.case_img.Width, this.h / this.case_img.Height);
1714
			this.nw = 488 * this.ratio;
1715
			this.nh = 476 * this.ratio;
1716
			this.nx = Math.round((this.w - (452 * this.ratio)) / 2);
1717
			this.ny = Math.round((this.h - this.nh) / 2);
1718
			p.draw_image(gr, this.img, this.nx + this.x, this.ny + this.y, this.nw, this.nh, "top");
1719
		}
1720
		p.draw_image(gr, this.semi_img, this.x, this.y, this.w, this.h, "adjust");
1721
		if (this.gloss) p.draw_image(gr, this.gloss_img, this.x, this.y, this.w, this.h, "adjust");
1722
	}
1723
	
1724
	this.metadb_changed = function() {
1725
		if (!p.metadb) return;
1726
		this.img && this.img.Dispose();
1727
		this.path = "";
1728
		this.img = utils.GetAlbumArtV2(p.metadb, 0);
1729
		window.Repaint();
1730
		utils.GetAlbumArtAsync(window.ID, p.metadb, 0);
1731
	}
1732
	
1733
	this.get_album_art_done = function(ip) {;
1734
		this.path = ip;
1735
	}
1736
	
1737
	this.trace = function(x, y) {
1738
		return (x > this.x && x < this.x + this.w && y > this.y && y < this.y + this.h);
1739
	}
1740
	
1741
	this.move = function(x, y) {
1742
		if (this.trace(x, y)) {
1743
			if (this.img) p.tt("Original size: " + this.img.Width + "x" + this.img.Height + "px");
1744
			return true;
1745
		} else {
1746
			p.ttd();
1747
			return false;
1748
		}
1749
	}
1750
	
1751
	this.lbtn_dblclk = function(x, y) {
1752
		if (!this.trace(x, y)) return false;
1753
		if (this.img) p.run("explorer /select,\"" + this.path + "\"");
1754
		return true;
1755
	}
1756
	
1757
	this.x = x;
1758
	this.y = y;
1759
	this.w = w;
1760
	this.h = h;
1761
	this.shadow_img = gdi.Image(p.images_path + "shadow.png");
1762
	this.case_img = gdi.Image(p.images_path + "case.png");
1763
	this.semi_img = gdi.Image(p.images_path + "semi.png");
1764
	this.gloss_img = gdi.Image(p.images_path + "gloss.png");
1765
	this.gloss = window.GetProperty("cd_gloss", false);
1766
	this.shadow = window.GetProperty("cd_shadow", false);
1767
	this.img = null;
1768
	this.path = null;
1769
}
1770
1771
function images(x, y, w, h) {
1772
	this.playback_time = function(time) {
1773
		if (this.mode == "last.fm" && time == 1 && this.files.length == 0 && p.metadb.RawPath == fb.GetNowPlaying().RawPath && ((this.auto_download == "library" && fb.IsMetadbInMediaLibrary(p.metadb)) || this.auto_download == "on")) this.download();
1774
		if (this.cycle > 0 && this.images.length > 1 && time % this.cycle == 0) {
1775
			this.index++;
1776
			if (this.index == this.images.length) this.index = 0;
1777
			window.RepaintRect(this.x, this.y, this.w, this.h);
1778
		}
1779
	}
1780
	
1781
	this.draw = function (gr) {
1782
		if (this.images.length == 0) return;
1783
		p.draw_image(gr, this.images[this.index], this.x, this.y, this.w, this.h, this.type);
1784
	}
1785
	
1786
	this.metadb_changed = function() {
1787
		if (!p.metadb) return false;
1788
		switch(this.mode) {
1789
			case "last.fm":
1790
				p.artist = p.eval(p.artist_tf);
1791
				if (this.artist == p.artist) return false;
1792
				this.artist = p.artist;
1793
				//this.folder = p.data_folder + p.clean_filename(p.artist);
1794
				//if (!p.fso.FolderExists(this.folder)) p.fso.CreateFolder(this.folder);
1795
				break;
1796
			case "custom":
1797
				this.temp_folder = p.eval(this.custom_folder_tf);
1798
				if (this.temp_folder == this.folder) return false;
1799
				this.folder = this.temp_folder;
1800
				break;
1801
		}
1802
		this.update();
1803
		return true;
1804
	}
1805
	
1806
	this.trace = function(x, y) {
1807
		return (x > this.x && x < this.x + this.w && y > this.y && y < this.y + this.h);
1808
	}
1809
	
1810
	this.wheel = function(step) {
1811
		if (!p.metadb || this.images.length < 2 || !this.trace(p.mx, p.my) || (typeof th == "object" && th.mode == "grid" && !th.overlay)) return false;
1812
		this.index -= step;
1813
		if (this.index < 0) this.index = this.images.length - 1;
1814
		if (this.index >= this.images.length) this.index = 0;
1815
		window.RepaintRect(this.x, this.y, this.w, this.h);
1816
		return true;
1817
	}
1818
	
1819
	this.lbtn_dblclk = function(x, y) {
1820
		if (!this.trace(x, y)) return false;
1821
		p.run("\"" + this.files[this.index] + "\"");
1822
		return true;
1823
	}
1824
1825
//LAST.FM RADIO--------------------------------------------------------------------------------------------------
1826
1827
//open simmilar artist
1828
this.downloadLFM = function()
1829
     {
1830
     //if (!p.fso.FolderExists(this.folder))  return;
1831
        {
1832
        if (auto_yt=="1")
1833
        
1834
        {
1835
        if (p.artist.indexOf("3dydfy://")== 0 | p.artist.indexOf("www.youtube.com/")== 0 | p.artist.indexOf("youtube.com/")== 0 | p.artist.indexOf("http://www.youtube.com/")== 0 | p.artist.indexOf("3dydfy://www.youtube.com:80/")== 0 | p.artist.indexOf("www.youtube.com:80/")== 0 | p.artist.indexOf("youtube.com:80/")== 0 | p.artist.indexOf("http://www.youtube.com:80/")== 0)
1836
   
1837
    
1838
    { var randomnumber=Math.floor(Math.random()*18)
1839
      var a=randomnumber;
1840
        this.working=true;
1841
        if (START_ARTIST == "" || START_ARTIST == "?") return;
1842
        //var folder = this.folder + "\\";
1843
		if (!this.xmlhttp) this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
1844
		this.xmlhttp.open("GET", "http://www.last.fm/music/" + encodeURIComponent(START_ARTIST) + "/+similar"+ "?page=" + a, true);
1845
		this.xmlhttp.send();
1846
		this.xmlhttp.onreadystatechange = function() {
1847
			if (im.xmlhttp.readyState == 4) {
1848
				if (im.xmlhttp.status == 200) {
1849
					var text = im.xmlhttp.responsetext;
1850
					if (!im.doc) im.doc = new ActiveXObject("htmlfile");
1851
					im.doc.open();
1852
					var div = im.doc.createElement("div");
1853
					div.innerHTML = text;
1854
					var data = div.getElementsByTagName("a");
1855
					var urls = [];
1856
    
1857
			
1858
1859
for (i = 0; i < data.length; i++) {
1860
    if (data[i].href.indexOf("about:/music/") == 0) urls.push(data[i].href.replace(/about:\//,"").replace("music/","").replace("/_/"," - ").replace("+"," ").replace("+"," ").replace("+"," ").replace("+"," ").replace("+"," ").replace("+"," ").replace("+"," ").replace("+"," ").replace("+"," ").replace("+"," ").replace("+"," ").replace("+"," ").replace("+"," ").replace("+"," ").replace("+"," ").replace("+"," ").replace("+"," ").replace("+"," ").replace("+"," ").replace("+"," ").replace("free-music-downloads","").replace("/+similar?page=2","").replace("/+events","").replace("/+wiki","").replace("-+","").replace("/+albums","").replace("/+tags","").replace("/+images","").replace("/journal","").replace("/charts","").replace("/images","").replace("/listeners","").replace("/similar?page=17","").replace("/news","").replace("/groups","").replace("/albums","").replace("/videos","").replace("/tracks","").replace("/similar","").replace("/tags","").replace("noredirect/","").replace("listeners/+tracks","").replace("videos/+tracks","").replace("/+videos/","").replace("?page=1","").replace("?page=8","").replace("?page=5","").replace("?page=7","").replace("?page=9","").replace("?page=8","").replace(" wiki/edit","").replace("/ similar","").replace("?page=","'").replace("/ charts","'").replace("-","").replace("%2F%E3%82%A4%E3%83%95%E3%83%BB%E3%83%8E%E3%83%83%E3%83%88%E3%83%BB%E3%83%95%E3%82%A9%E3%83%BE3%83%BB%E3%83%A6%E3%83%BC","").replace("Ajoutez ce titre sur Deezer exclusivement sur www.hotmixradio.fr","").replace("www.Hituri.net","").replace("%E3%81%97%E3%82%83%E3%81%AB%E3%82%80%E3%81%AB%E3%82%B7%E3%82%A7%E3%82%A4%E3%82%AF%EF","").replace("%B81%E3%82%B7%E3%82%A7%E3%82%A4%E3%82%AF%EF%B81","").replace("%E4%BD%95%E3%82%88%E3%82%8A%E3%82%82%E5%83%95%E3%82%89%E3%81%97%E3%81%8F%E3%80%81%E4%BD%95%E3%82%88%E3%82%8A","").replace("%E3%82%82%E5%90%9B%E3%82%89%E3%81%97%E3%81%8F","").replace("%D0%91%D1%8D0%B5%D1%82 %D0%BF%D0%BE %D0%B3%D0%BB%D0%B0%D0%B7%D0%B0%D0%BC","").replace("%E3%83%9E%E3%82%A4%E3%83%BB%E3%83%9E3%83%87%E3%82%A3","").replace("%D0%9B%D0%B5%D1%82%D0%B5%D1%82%D1%8C","").replace("%2F%2F %D0%A1%D0%9B%D0%A3%D0%A8%D0%90%D0%AE%D0%A2","").replace("%D0%9F%D0%BE%D0%BF-%D0%A5%D0%B8%D1%82","").replace("/",""));   
1861
}
1862
1863
1864
//select random URL
1865
var randomnumber = Math.floor(Math.random()*(20-50)+50);
1866
do{
1867
randomnumber = Math.floor(Math.random()*(20-50)+50);
1868
} while(randomnumber%2!=1);
1869
i=randomnumber;
1870
1871
1872
//select all url
1873
//for (i = 0; i < urls.length; i++)
1874
{
1875
1876
//do something with urls[i]
1877
//if (START_ARTIST.indexOf("*")== 0) {} else {p.console("" + urls[i]);}
1878
1879
if (urls[i] > "") 
1880
{
1881
1882
last_fm = window.SetProperty("YT Similar", urls[i]);
1883
last_fm = urls[i];
1884
window.SetProperty("YT Similar", urls[i]);
1885
}
1886
else
1887
//if (urls[i] == "" || urls[i] == "?")
1888
{
1889
last_fm = window.SetProperty("YT Similar", "");
1890
last_fm = "";
1891
window.SetProperty("YT Similar", "");
1892
}
1893
//var tmppath = p.fso.GetFolder(fb.FoobarPath).ShortPath;
1894
//p.run(tmppath+"\\foobar2000.exe /immediate /add "+"\ " + urls[i] + "\"");                   
1895
                    
1896
1897
}
1898
        
1899
                 
1900
             
1901
            
1902
             
1903
//open YT in playlist
1904
//var tmppath = p.fso.GetFolder(fb.FoobarPath).ShortPath;
1905
//p.run(tmppath+"\\foobar2000.exe /immediate /add "+"\""+urls[i] + "\"");
1906
//fb.RunMainMenuCommand("File/Add Youtube URL(s)...") + ("/immediate /add "+"\""+ urls[i]);                       
1907
1908
1909
                im.doc.close();
1910
                im.working=false;
1911
                if (START_ARTIST.indexOf("*")== 0) {im.downloadGENRE2();}
1912
                else
1913
                if (last_fm == "" || last_fm == "?") {im.downloadLFM();}
1914
                else
1915
                im.downloadTRACK();
1916
				//im.update();
1917
				//window.NotifyOthers("images", "update");
1918
				} else {
1919-
                    im.downloadLFM();
1919+
					if (START_ARTIST.indexOf("*")== 0) {} else {p.console("HTTP error: " + im.xmlhttp.status);}
1920
                    
1921
                    if (START_ARTIST.indexOf("*")== 0) {im.downloadGENRE2();}
1922
                    else
1923
                    if (im.xmlhttp.status == 404) {im.downloadLFM();}
1924
                }
1925
			}
1926
		}
1927
	}
1928
}}                             
1929
1930
}
1931
1932
1933
//Open track
1934
this.downloadTRACK = function()
1935
     {
1936
     //if (!p.fso.FolderExists(this.folder))  return;
1937
        //if (server==ooo) return true;
1938
        //else
1939
        {
1940
        
1941
1942
        
1943
        
1944
        
1945
        {
1946
        
1947
  
1948
    
1949
    {var randomnumber=Math.floor(Math.random()*20)
1950
      var a=randomnumber;
1951
        this.working=true;
1952
        if (last_fm == "" || last_fm == "?") return;
1953
        //var folder = this.folder + "\\";
1954
		if (!this.xmlhttp) this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
1955
		this.xmlhttp.open("GET", "http://www.last.fm/music/" + encodeURIComponent(last_fm) + "/+tracks" + "?page=" + a, true);
1956
		this.xmlhttp.send();
1957
		this.xmlhttp.onreadystatechange = function() {
1958
			if (im.xmlhttp.readyState == 4) {
1959
				if (im.xmlhttp.status == 200) {
1960
					var text = im.xmlhttp.responsetext;
1961
					if (!im.doc) im.doc = new ActiveXObject("htmlfile");
1962
					im.doc.open();
1963
					var div = im.doc.createElement("tr");
1964
					div.innerHTML = text;
1965
					var data = div.getElementsByTagName("td");
1966
					var urls = [];
1967
    
1968
			
1969
1970
for (i = 0; i < data.length; i++) {
1971
    if (data[i].title) urls.push(data[i].title.replace(/about:\//,"").replace(",","").replace("1","").replace("2","").replace("3","").replace("4","").replace("5","").replace("6","").replace("7","").replace("8","").replace("9","").replace("0","").replace("listeners","").replace("listener","").split("(")[0].split("[")[0].split(",")[0].split("{")[0]);
1972
} 
1973
1974
1975
//select random URL
1976
var randomnumber = Math.floor(Math.random()*Math.max(urls.length));
1977
i=randomnumber;
1978
1979
{
1980
1981
//do something with urls[i]
1982
p.console("" + last_fm + " - " + urls[i]);
1983
1984
//var tmppath = p.fso.GetFolder(fb.FoobarPath).ShortPath;
1985
//p.run(tmppath+"\\foobar2000.exe /immediate /add "+"\ " + urls[i] + "\"");                   
1986
1987
1988
if (urls[i] > "") 
1989
{
1990
1991
ooo2 = window.SetProperty("YT Track", last_fm + " - " + urls[i]);
1992
ooo2 = urls[i];
1993
window.SetProperty("YT Track", last_fm + " - " + urls[i]);
1994
}
1995
else
1996
//if (urls[i] == "" || urls[i] == "?")
1997
{
1998
ooo2 = window.SetProperty("YT Track", "");
1999
ooo2 = "";
2000
window.SetProperty("YT Track", "");
2001
}
2002
}
2003
        
2004
                 
2005
             
2006
            
2007
             
2008
//open YT in playlist
2009
//var tmppath = p.fso.GetFolder(fb.FoobarPath).ShortPath;
2010
//p.run(tmppath+"\\foobar2000.exe /immediate /add "+"\""+urls[i] + "\"");
2011
//fb.RunMainMenuCommand("File/Add Youtube URL(s)...") + ("/immediate /add "+"\""+ urls[i]);                       
2012
2013
2014
                im.doc.close();
2015
                im.working=false;
2016
                if (ooo2 == "" || ooo2 == "?") {im.downloadLFM();}
2017
                else
2018
                im.downloadYT();
2019
				//im.update();
2020-
                    im.downloadLFM();
2020+
2021
				} else {
2022
					p.console("HTTP error: " + im.xmlhttp.status);
2023
                    if (START_ARTIST.indexOf("*")== 0) {im.downloadGENRE2();}
2024
                    else
2025
                    if (im.xmlhttp.status == 404) {im.downloadLFM();}
2026
                
2027
                }
2028
			}
2029
		}
2030
	}
2031
}}}
2032
2033
		
2034
	
2035
2036
2037
//open Youtube	
2038
this.downloadYT = function()
2039
     {
2040
     //if (!p.fso.FolderExists(this.folder))  return;
2041
        {
2042
        
2043
        //if (server=="last.fm")
2044
        {
2045
        
2046
   //if (p.artist.indexOf("3dydfy://")== 0)
2047
    
2048
    {
2049
        this.working=true;
2050
        if (ooo2 == "" || ooo2 == "?") return;
2051
        //var folder = this.folder + "\\";
2052
		if (!this.xmlhttp) this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
2053
		this.xmlhttp.open("GET", "http://www.youtube.com/results?search_query=" + encodeURIComponent(last_fm) +" - " + encodeURIComponent(ooo2), true);
2054
		this.xmlhttp.send();
2055
		this.xmlhttp.onreadystatechange = function() {
2056
			if (im.xmlhttp.readyState == 4) {
2057
				if (im.xmlhttp.status == 200) {
2058
					var text = im.xmlhttp.responsetext;
2059
					if (!im.doc) im.doc = new ActiveXObject("htmlfile");
2060
					im.doc.open();
2061
					var div = im.doc.createElement("div");
2062
					div.innerHTML = text;
2063
					var data = div.getElementsByTagName("a");
2064
					var urls = [];
2065
    
2066
			
2067
2068
for (i = 0; i < data.length; i++) {
2069
    if (data[i].href.indexOf("about:/watch?v=") == 0) urls.push("http://www.youtube.com/" + data[i].href.replace(/about:\//,""));
2070
}
2071
2072
//select random URL
2073
//var randomnumber = Math.floor(Math.random()*Math.max(urls.length-1))+1;
2074
//i=randomnumber;
2075
i = 1;
2076
2077
{
2078
2079
//do something with urls[i]
2080
p.console("" + urls[i]);
2081
2082
if (urls[i] > "" && ooo2 > "") 
2083
{
2084
YT_URL = window.SetProperty("YT URL", urls[i]);
2085
YT_URL = urls[i];
2086
window.SetProperty("YT URL", urls[i]);
2087
2088
var tmppath = p.fso.GetFolder(fb.FoobarPath).ShortPath;
2089
p.run(tmppath+"\\foobar2000.exe /add "+"\ " + urls[i] + "\"");                   
2090
}
2091
else
2092
//if (urls[i] == "" || urls[i] == "?")
2093
{
2094
YT_URL = window.SetProperty("YT URL", "");
2095
YT_URL = "";
2096
window.SetProperty("YT URL", "");
2097
}
2098
2099
2100
2101
 }
2102
        
2103
                 
2104
             
2105
            
2106
             
2107
//open YT in playlist
2108
//var tmppath = p.fso.GetFolder(fb.FoobarPath).ShortPath;
2109
//p.run(tmppath+"\\foobar2000.exe /immediate /add "+"\""+urls[i] + "\"");
2110
//fb.RunMainMenuCommand("File/Add Youtube URL(s)...") + ("/immediate /add "+"\""+ urls[i]);                       
2111
2112
2113
                im.doc.close();
2114
                im.working=false;
2115-
                    im.downloadLFM();
2115+
2116
                
2117
				} else {
2118
					p.console("HTTP error: " + im.xmlhttp.status);
2119
                    if (START_ARTIST.indexOf("*")== 0) {im.downloadGENRE2();}
2120
                    else
2121
                    if (im.xmlhttp.status == 404) {im.downloadLFM();}
2122
                }
2123
			}
2124
		}
2125
	}
2126
}}}
2127
2128
2129
2130
//LAST.FM RADIO(One)--------------------------------------------------------------------------------------------------
2131
2132
//open simmilar artist
2133
this.downloadLFM1 = function()
2134
     {
2135
     
2136
        {
2137
         
2138
        {
2139
        //if (p.artist.indexOf("3dydfy://")== 0 | p.artist.indexOf("www.youtube.com/")== 0 | p.artist.indexOf("youtube.com/")== 0 | p.artist.indexOf("http://www.youtube.com/")== 0 | p.artist.indexOf("3dydfy://www.youtube.com:80/")== 0 | p.artist.indexOf("www.youtube.com:80/")== 0 | p.artist.indexOf("youtube.com:80/")== 0 | p.artist.indexOf("http://www.youtube.com:80/")== 0)
2140
   
2141
    
2142
    { var randomnumber=Math.floor(Math.random()*18)
2143
      var a=randomnumber;
2144
        this.working=true;
2145
        if (START_ARTIST == "" || START_ARTIST == "?") return;
2146
        //var folder = this.folder + "\\";
2147
		if (!this.xmlhttp) this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
2148
		this.xmlhttp.open("GET", "http://www.last.fm/music/" + encodeURIComponent(START_ARTIST) + "/+similar"+ "?page=" + a, true);
2149
		this.xmlhttp.send();
2150
		this.xmlhttp.onreadystatechange = function() {
2151
			if (im.xmlhttp.readyState == 4) {
2152
				if (im.xmlhttp.status == 200) {
2153
					var text = im.xmlhttp.responsetext;
2154
					if (!im.doc) im.doc = new ActiveXObject("htmlfile");
2155
					im.doc.open();
2156
					var div = im.doc.createElement("div");
2157
					div.innerHTML = text;
2158
					var data = div.getElementsByTagName("a");
2159
					var urls = [];
2160
    
2161
			
2162
2163
for (i = 0; i < data.length; i++) {
2164
     if (data[i].href.indexOf("about:/music/") == 0) urls.push(data[i].href.replace(/about:\//,"").replace("music/","").replace("/_/"," - ").replace("+"," ").replace("+"," ").replace("+"," ").replace("+"," ").replace("+"," ").replace("+"," ").replace("+"," ").replace("+"," ").replace("+"," ").replace("+"," ").replace("+"," ").replace("+"," ").replace("+"," ").replace("+"," ").replace("+"," ").replace("+"," ").replace("+"," ").replace("+"," ").replace("+"," ").replace("+"," ").replace("free-music-downloads","").replace("/+similar?page=2","").replace("/+events","").replace("/+wiki","").replace("-+","").replace("/+albums","").replace("/+tags","").replace("/+images","").replace("/journal","").replace("/charts","").replace("/images","").replace("/listeners","").replace("/similar?page=17","").replace("/news","").replace("/groups","").replace("/albums","").replace("/videos","").replace("/tracks","").replace("/similar","").replace("/tags","").replace("noredirect/","").replace("listeners/+tracks","").replace("videos/+tracks","").replace("/+videos/","").replace("?page=1","").replace("?page=8","").replace("?page=5","").replace("?page=7","").replace("?page=9","").replace("?page=8","").replace(" wiki/edit","").replace("/ similar","").replace("?page=","'").replace("/ charts","'").replace("-","").replace("%2F%E3%82%A4%E3%83%95%E3%83%BB%E3%83%8E%E3%83%83%E3%83%88%E3%83%BB%E3%83%95%E3%82%A9%E3%83%BE3%83%BB%E3%83%A6%E3%83%BC","").replace("Ajoutez ce titre sur Deezer exclusivement sur www.hotmixradio.fr","").replace("www.Hituri.net","").replace("%E3%81%97%E3%82%83%E3%81%AB%E3%82%80%E3%81%AB%E3%82%B7%E3%82%A7%E3%82%A4%E3%82%AF%EF","").replace("%B81%E3%82%B7%E3%82%A7%E3%82%A4%E3%82%AF%EF%B81","").replace("%E4%BD%95%E3%82%88%E3%82%8A%E3%82%82%E5%83%95%E3%82%89%E3%81%97%E3%81%8F%E3%80%81%E4%BD%95%E3%82%88%E3%82%8A","").replace("%E3%82%82%E5%90%9B%E3%82%89%E3%81%97%E3%81%8F","").replace("%D0%91%D1%8D0%B5%D1%82 %D0%BF%D0%BE %D0%B3%D0%BB%D0%B0%D0%B7%D0%B0%D0%BC","").replace("%E3%83%9E%E3%82%A4%E3%83%BB%E3%83%9E3%83%87%E3%82%A3","").replace("%D0%9B%D0%B5%D1%82%D0%B5%D1%82%D1%8C","").replace("%2F%2F %D0%A1%D0%9B%D0%A3%D0%A8%D0%90%D0%AE%D0%A2","").replace("%D0%9F%D0%BE%D0%BF-%D0%A5%D0%B8%D1%82","").replace("/",""));   
2165
}
2166
2167
2168
//select random URL
2169
var randomnumber = Math.floor(Math.random()*(20-50)+50);
2170
do{
2171
randomnumber = Math.floor(Math.random()*(20-50)+50);
2172
} while(randomnumber%2!=1);
2173
i=randomnumber;
2174
2175
//select all url
2176
//for (i = 0; i < urls.length; i++)
2177
{
2178
2179
//do something with urls[i]
2180
//if (START_ARTIST.indexOf("*")== 0) {} else {p.console("" + urls[i]);}
2181
2182
if (urls[i] > "") 
2183
{
2184
2185
last_fm = window.SetProperty("YT Similar", urls[i]);
2186
last_fm = urls[i];
2187
window.SetProperty("YT Similar", urls[i]);
2188
}
2189
else
2190
//if (urls[i] == "" || urls[i] == "?")
2191
{
2192
last_fm = window.SetProperty("YT Similar", "");
2193
last_fm = "";
2194
window.SetProperty("YT Similar", "");
2195
}
2196
//var tmppath = p.fso.GetFolder(fb.FoobarPath).ShortPath;
2197
//p.run(tmppath+"\\foobar2000.exe /immediate /add "+"\ " + urls[i] + "\"");                   
2198
                    
2199
2200
}
2201
        
2202
                 
2203
             
2204
            
2205
             
2206
//open YT in playlist
2207
//var tmppath = p.fso.GetFolder(fb.FoobarPath).ShortPath;
2208
//p.run(tmppath+"\\foobar2000.exe /immediate /add "+"\""+urls[i] + "\"");
2209
//fb.RunMainMenuCommand("File/Add Youtube URL(s)...") + ("/immediate /add "+"\""+ urls[i]);                       
2210
2211
2212
                im.doc.close();
2213
                im.working=false;
2214
                if (START_ARTIST.indexOf("*")== 0) {im.downloadGENRE2();}
2215
                else
2216-
                    im.downloadLFM1();
2216+
2217
                else
2218
                im.downloadTRACK1();
2219
				//im.update();
2220
				//window.NotifyOthers("images", "update");
2221
				} else {
2222
					if (START_ARTIST.indexOf("*")== 0) {} else {p.console("HTTP error: " + im.xmlhttp.status);}
2223
                    if (START_ARTIST.indexOf("*")== 0) {im.downloadGENRE2();}
2224
                    else
2225
                    if (im.xmlhttp.status == 404) {im.downloadLFM1();}
2226
                }
2227
			}
2228
		}
2229
	}
2230
}}                             
2231
2232
}
2233
2234
2235
//Open track
2236
this.downloadTRACK1 = function()
2237
     {
2238
     //if (!p.fso.FolderExists(this.folder))  return;
2239
        //if (server==ooo) return true;
2240
        //else
2241
        {
2242
        
2243
2244
        
2245
        
2246
        
2247
        {
2248
        
2249
  
2250
    
2251
    {var randomnumber=Math.floor(Math.random()*20)
2252
      var a=randomnumber;
2253
        this.working=true;
2254
        if (last_fm == "" || last_fm == "?") return;
2255
        //var folder = this.folder + "\\";
2256
		if (!this.xmlhttp) this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
2257
		this.xmlhttp.open("GET", "http://www.last.fm/music/" + encodeURIComponent(last_fm) + "/+tracks" + "?page=" + a, true);
2258
		this.xmlhttp.send();
2259
		this.xmlhttp.onreadystatechange = function() {
2260
			if (im.xmlhttp.readyState == 4) {
2261
				if (im.xmlhttp.status == 200) {
2262
					var text = im.xmlhttp.responsetext;
2263
					if (!im.doc) im.doc = new ActiveXObject("htmlfile");
2264
					im.doc.open();
2265
					var div = im.doc.createElement("tr");
2266
					div.innerHTML = text;
2267
					var data = div.getElementsByTagName("td");
2268
					var urls = [];
2269
    
2270
			
2271
2272
for (i = 0; i < data.length; i++) {
2273
    if (data[i].title) urls.push(data[i].title.replace(/about:\//,"").replace(",","").replace("1","").replace("2","").replace("3","").replace("4","").replace("5","").replace("6","").replace("7","").replace("8","").replace("9","").replace("0","").replace("listeners","").replace("listener","").split("(")[0].split("[")[0].split(",")[0].split("{")[0]);
2274
}
2275
2276
//select random URL
2277
var randomnumber = Math.floor(Math.random()*Math.max(urls.length));
2278
i=randomnumber;
2279
2280
{
2281
2282
//do something with urls[i]
2283
p.console("" + last_fm + " - " + urls[i]);
2284
2285
//var tmppath = p.fso.GetFolder(fb.FoobarPath).ShortPath;
2286
//p.run(tmppath+"\\foobar2000.exe /immediate /add "+"\ " + urls[i] + "\"");                   
2287
2288
2289
if (urls[i] > "") 
2290
{
2291
2292
ooo2 = window.SetProperty("YT Track", last_fm + " - " + urls[i]);
2293
ooo2 = urls[i];
2294
window.SetProperty("YT Track", last_fm + " - " + urls[i]);
2295
}
2296
else
2297
//if (urls[i] == "" || urls[i] == "?")
2298
{
2299
ooo2 = window.SetProperty("YT Track", "");
2300
ooo2 = "";
2301
window.SetProperty("YT Track", "");
2302
}
2303
}
2304
        
2305
                 
2306
             
2307
            
2308
             
2309
//open YT in playlist
2310
//var tmppath = p.fso.GetFolder(fb.FoobarPath).ShortPath;
2311
//p.run(tmppath+"\\foobar2000.exe /immediate /add "+"\""+urls[i] + "\"");
2312
//fb.RunMainMenuCommand("File/Add Youtube URL(s)...") + ("/immediate /add "+"\""+ urls[i]);                       
2313
2314
2315
                im.doc.close();
2316-
                    im.downloadLFM1();
2316+
2317
                if (ooo2 == "" || ooo2 == "?") {im.downloadLFM1();}
2318
                else
2319
                im.downloadYT1();
2320
				//im.update();
2321
				//window.NotifyOthers("images", "update");
2322
				} else {
2323
					p.console("HTTP error: " + im.xmlhttp.status);
2324
                    if (START_ARTIST.indexOf("*")== 0) {im.downloadGENRE2();}
2325
                    else
2326
                    if (im.xmlhttp.status == 404) {im.downloadLFM1();}
2327
                
2328
                }
2329
			}
2330
		}
2331
	}
2332
}}}
2333
2334
		
2335
	
2336
2337
2338
//open Youtube	
2339
this.downloadYT1 = function()
2340
     {
2341
     //if (!p.fso.FolderExists(this.folder))  return;
2342
        {
2343
        
2344
        //if (server=="last.fm")
2345
        {
2346
        
2347
   //if (p.artist.indexOf("3dydfy://")== 0)
2348
    
2349
    {
2350
        this.working=true;
2351
        if (ooo2 == "" || ooo2 == "?") return;
2352
        //var folder = this.folder + "\\";
2353
		if (!this.xmlhttp) this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
2354
		this.xmlhttp.open("GET", "http://www.youtube.com/results?search_query=" + encodeURIComponent(last_fm) +" - " + encodeURIComponent(ooo2), true);
2355
		this.xmlhttp.send();
2356
		this.xmlhttp.onreadystatechange = function() {
2357
			if (im.xmlhttp.readyState == 4) {
2358
				if (im.xmlhttp.status == 200) {
2359
					var text = im.xmlhttp.responsetext;
2360
					if (!im.doc) im.doc = new ActiveXObject("htmlfile");
2361
					im.doc.open();
2362
					var div = im.doc.createElement("div");
2363
					div.innerHTML = text;
2364
					var data = div.getElementsByTagName("a");
2365
					var urls = [];
2366
    
2367
			
2368
2369
for (i = 0; i < data.length; i++) {
2370
    if (data[i].href.indexOf("about:/watch?v=") == 0) urls.push("http://www.youtube.com/" + data[i].href.replace(/about:\//,""));
2371
}
2372
2373
//select random URL
2374
//var randomnumber = Math.floor(Math.random()*Math.max(urls.length-1))+1;
2375
//i=randomnumber;
2376
i = 1;
2377
2378
{
2379
2380
//do something with urls[i]
2381
p.console("" + urls[i]);
2382
2383
if (urls[i] > "" && ooo2 > "") 
2384
{
2385
YT_URL = window.SetProperty("YT URL", urls[i]);
2386
YT_URL = urls[i];
2387
window.SetProperty("YT URL", urls[i]);
2388
2389
var tmppath = p.fso.GetFolder(fb.FoobarPath).ShortPath;
2390
p.run(tmppath+"\\foobar2000.exe /add "+"\ " + urls[i] + "\"");                   
2391
}
2392
else
2393
//if (urls[i] == "" || urls[i] == "?")
2394
{
2395
YT_URL = window.SetProperty("YT URL", "");
2396
YT_URL = "";
2397
window.SetProperty("YT URL", "");
2398
}
2399
2400
2401
2402
 }
2403
        
2404
                 
2405
             
2406
            
2407
             
2408
//open YT in playlist
2409
//var tmppath = p.fso.GetFolder(fb.FoobarPath).ShortPath;
2410
//p.run(tmppath+"\\foobar2000.exe /immediate /add "+"\""+urls[i] + "\"");
2411-
                    im.downloadLFM1();
2411+
2412
2413
2414
                im.doc.close();
2415
                im.working=false;
2416
				if (YT_URL == "" || YT_URL == "?") {im.downloadLFM1();}
2417
                
2418
				} else {
2419
					p.console("HTTP error: " + im.xmlhttp.status);
2420
                    if (START_ARTIST.indexOf("*")== 0) {im.downloadGENRE2();}
2421
                    else
2422
                    if (im.xmlhttp.status == 404) {im.downloadLFM1();}
2423
                }
2424
			}
2425
		}
2426
	}
2427
}}}
2428
2429
2430
2431
//CHECK IF ARTIST EXIST--------------------------------------------------------------------------------------------------
2432
2433
this.downloadLFM0 = function()
2434
    
2435
    {   
2436
        this.working=true;
2437
        if (START_ARTIST == "" || START_ARTIST == "?") return;
2438
        //var folder = this.folder + "\\";
2439
		if (!this.xmlhttp) this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
2440
		this.xmlhttp.open("GET", "http://www.last.fm/music/" + encodeURIComponent(START_ARTIST) + "/+similar", true);
2441
		this.xmlhttp.send();
2442
		this.xmlhttp.onreadystatechange = function() {
2443
			if (im.xmlhttp.readyState == 4) {
2444
				if (im.xmlhttp.status == 200) {
2445
					var text = im.xmlhttp.responsetext;
2446
					if (!im.doc) im.doc = new ActiveXObject("htmlfile");
2447
					im.doc.open();
2448
					var div = im.doc.createElement("div");
2449
					div.innerHTML = text;
2450
					var data = div.getElementsByTagName("a");
2451
					var urls = [];
2452
    
2453-
                    p.MsgBox("This Artist Not Exist!", 0, p.name);
2453+
2454
2455
2456
                im.doc.close();
2457
                im.working=false;
2458
                im.downloadLFM000();
2459
				
2460
				} else {
2461
					if (START_ARTIST.indexOf("*")== 0) {} else {p.console("HTTP error: " + im.xmlhttp.status);}
2462
                    if (START_ARTIST.indexOf("*")== 0) {im.downloadGENRE2();}
2463
                    else
2464
                    if (im.xmlhttp.status == 404)
2465
                    {
2466
                    p.MsgBox("This Artist Not Found!", 0, p.name);
2467
                    }
2468
                    
2469
                    
2470
                }
2471
			}
2472
		}
2473
	}
2474
                             
2475
2476
2477
//START ARTIST RADIO(same artist)--------------------------------------------------------------------------------------------------
2478
2479
//open simmilar artist
2480
this.downloadLFM000 = function()
2481
     {
2482
     
2483
        {
2484
       
2485
        {
2486
        //if (p.artist.indexOf("3dydfy://")== 0 | p.artist.indexOf("www.youtube.com/")== 0 | p.artist.indexOf("youtube.com/")== 0 | p.artist.indexOf("http://www.youtube.com/")== 0 | p.artist.indexOf("3dydfy://www.youtube.com:80/")== 0 | p.artist.indexOf("www.youtube.com:80/")== 0 | p.artist.indexOf("youtube.com:80/")== 0 | p.artist.indexOf("http://www.youtube.com:80/")== 0)
2487
   
2488
    
2489
    { var randomnumber=Math.floor(Math.random()*18)
2490
      var a=randomnumber;
2491
        this.working=true;
2492
        if (START_ARTIST == "" || START_ARTIST == "?") return;
2493
        //var folder = this.folder + "\\";
2494
		if (!this.xmlhttp) this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
2495
		this.xmlhttp.open("GET", "http://www.last.fm/music/" + encodeURIComponent(START_ARTIST) + "/+similar"+ "?page=" + a, true);
2496
		this.xmlhttp.send();
2497
		this.xmlhttp.onreadystatechange = function() {
2498
			if (im.xmlhttp.readyState == 4) {
2499
				if (im.xmlhttp.status == 200) {
2500
					var text = im.xmlhttp.responsetext;
2501
					if (!im.doc) im.doc = new ActiveXObject("htmlfile");
2502
					im.doc.open();
2503
					var div = im.doc.createElement("div");
2504
					div.innerHTML = text;
2505
					var data = div.getElementsByTagName("a");
2506
					var urls = [];
2507
    
2508
			
2509
2510
for (i = 0; i < data.length; i++) {
2511
     if (data[i].href.indexOf("about:/music/") == 0) urls.push(data[i].href.replace(/about:\//,"").replace("music/","").replace("/_/"," - ").replace("+"," ").replace("+"," ").replace("+"," ").replace("+"," ").replace("+"," ").replace("+"," ").replace("+"," ").replace("+"," ").replace("+"," ").replace("+"," ").replace("+"," ").replace("+"," ").replace("+"," ").replace("+"," ").replace("+"," ").replace("+"," ").replace("+"," ").replace("+"," ").replace("+"," ").replace("+"," ").replace("free-music-downloads","").replace("/+similar?page=2","").replace("/+events","").replace("/+wiki","").replace("-+","").replace("/+albums","").replace("/+tags","").replace("/+images","").replace("/journal","").replace("/charts","").replace("/images","").replace("/listeners","").replace("/similar?page=17","").replace("/news","").replace("/groups","").replace("/albums","").replace("/videos","").replace("/tracks","").replace("/similar","").replace("/tags","").replace("noredirect/","").replace("listeners/+tracks","").replace("videos/+tracks","").replace("/+videos/","").replace("?page=1","").replace("?page=8","").replace("?page=5","").replace("?page=7","").replace("?page=9","").replace("?page=8","").replace(" wiki/edit","").replace("/ similar","").replace("?page=","'").replace("/ charts","'").replace("-","").replace("%2F%E3%82%A4%E3%83%95%E3%83%BB%E3%83%8E%E3%83%83%E3%83%88%E3%83%BB%E3%83%95%E3%82%A9%E3%83%BE3%83%BB%E3%83%A6%E3%83%BC","").replace("Ajoutez ce titre sur Deezer exclusivement sur www.hotmixradio.fr","").replace("www.Hituri.net","").replace("%E3%81%97%E3%82%83%E3%81%AB%E3%82%80%E3%81%AB%E3%82%B7%E3%82%A7%E3%82%A4%E3%82%AF%EF","").replace("%B81%E3%82%B7%E3%82%A7%E3%82%A4%E3%82%AF%EF%B81","").replace("%E4%BD%95%E3%82%88%E3%82%8A%E3%82%82%E5%83%95%E3%82%89%E3%81%97%E3%81%8F%E3%80%81%E4%BD%95%E3%82%88%E3%82%8A","").replace("%E3%82%82%E5%90%9B%E3%82%89%E3%81%97%E3%81%8F","").replace("%D0%91%D1%8D0%B5%D1%82 %D0%BF%D0%BE %D0%B3%D0%BB%D0%B0%D0%B7%D0%B0%D0%BC","").replace("%E3%83%9E%E3%82%A4%E3%83%BB%E3%83%9E3%83%87%E3%82%A3","").replace("%D0%9B%D0%B5%D1%82%D0%B5%D1%82%D1%8C","").replace("%2F%2F %D0%A1%D0%9B%D0%A3%D0%A8%D0%90%D0%AE%D0%A2","").replace("%D0%9F%D0%BE%D0%BF-%D0%A5%D0%B8%D1%82","").replace("/",""));   
2512
}
2513
2514
2515
//select random URL
2516
var randomnumber = Math.floor(Math.random()*(20-50)+50);
2517
do{
2518
randomnumber = Math.floor(Math.random()*(20-50)+50);
2519
} while(randomnumber%2!=1);
2520
i=randomnumber;
2521
2522
//select all url
2523
//for (i = 0; i < urls.length; i++)
2524
{
2525
2526
//do something with urls[i]
2527
//if (START_ARTIST.indexOf("*")== 0) {} else {p.console("" + urls[i]);}
2528
2529
if (urls[i] > "") 
2530
{
2531
2532
last_fm = window.SetProperty("YT Similar", urls[i]);
2533
last_fm = urls[i];
2534
window.SetProperty("YT Similar", urls[i]);
2535
}
2536
else
2537
//if (urls[i] == "" || urls[i] == "?")
2538
{
2539
last_fm = window.SetProperty("YT Similar", "");
2540
last_fm = "";
2541
window.SetProperty("YT Similar", "");
2542
}                  
2543
2544
}
2545
2546
                im.doc.close();
2547
                im.working=false;
2548
                if (START_ARTIST.indexOf("*")== 0) {im.downloadGENRE2();}
2549
                else
2550
                if (last_fm == "" || last_fm == "?") {im.downloadLFM000();}
2551
                else
2552
                im.downloadTRACK11();
2553
				
2554
				} else {
2555
					if (START_ARTIST.indexOf("*")== 0) {} else {p.console("HTTP error: " + im.xmlhttp.status);}
2556-
                    im.downloadLFM000();
2556+
                    if (START_ARTIST.indexOf("*")== 0) {im.downloadGENRE2();}
2557
                    else
2558
                    if (im.xmlhttp.status == 404) {im.downloadLFM000();}
2559
2560
                }
2561
			}
2562
		}
2563
	}
2564
}}                             
2565
2566
}
2567
2568
2569
//Open track
2570
this.downloadTRACK11 = function()
2571
     {
2572
        {
2573
        
2574
2575
        
2576
        
2577
        
2578
        {
2579
        
2580
  
2581
    
2582
    {var randomnumber=Math.floor(Math.random()*20)
2583
      var a=randomnumber;
2584
        this.working=true;
2585
        if (last_fm == "" || last_fm == "?") return;
2586
        //var folder = this.folder + "\\";
2587
		if (!this.xmlhttp) this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
2588
		this.xmlhttp.open("GET", "http://www.last.fm/music/" + encodeURIComponent(last_fm) + "/+tracks" + "?page=" + a, true);
2589
		this.xmlhttp.send();
2590
		this.xmlhttp.onreadystatechange = function() {
2591
			if (im.xmlhttp.readyState == 4) {
2592
				if (im.xmlhttp.status == 200) {
2593
					var text = im.xmlhttp.responsetext;
2594
					if (!im.doc) im.doc = new ActiveXObject("htmlfile");
2595
					im.doc.open();
2596
					var div = im.doc.createElement("tr");
2597
					div.innerHTML = text;
2598
					var data = div.getElementsByTagName("td");
2599
					var urls = [];
2600
    
2601
			
2602
2603
for (i = 0; i < data.length; i++) {
2604
    if (data[i].title) urls.push(data[i].title.replace(/about:\//,"").replace(",","").replace("1","").replace("2","").replace("3","").replace("4","").replace("5","").replace("6","").replace("7","").replace("8","").replace("9","").replace("0","").replace("listeners","").replace("listener","").split("(")[0].split("[")[0].split(",")[0].split("{")[0]);
2605
}
2606
2607
//select random URL
2608
var randomnumber = Math.floor(Math.random()*Math.max(urls.length));
2609
i=randomnumber;
2610
2611
{
2612
2613
//do something with urls[i]
2614
p.console("" + last_fm + " - " + urls[i]);
2615
2616
//var tmppath = p.fso.GetFolder(fb.FoobarPath).ShortPath;
2617
//p.run(tmppath+"\\foobar2000.exe /immediate /add "+"\ " + urls[i] + "\"");                   
2618
2619
2620
if (urls[i] > "") 
2621
{
2622
2623
ooo2 = window.SetProperty("YT Track", last_fm + " - " + urls[i]);
2624
ooo2 = urls[i];
2625
window.SetProperty("YT Track", last_fm + " - " + urls[i]);
2626
}
2627
else
2628
//if (urls[i] == "" || urls[i] == "?")
2629
{
2630
ooo2 = window.SetProperty("YT Track", "");
2631
ooo2 = "";
2632
window.SetProperty("YT Track", "");
2633
}
2634
}
2635
        
2636
                 
2637
             
2638
            
2639
             
2640
//open YT in playlist
2641
//var tmppath = p.fso.GetFolder(fb.FoobarPath).ShortPath;
2642
//p.run(tmppath+"\\foobar2000.exe /immediate /add "+"\""+urls[i] + "\"");
2643
//fb.RunMainMenuCommand("File/Add Youtube URL(s)...") + ("/immediate /add "+"\""+ urls[i]);                       
2644
2645
2646
                im.doc.close();
2647
                im.working=false;
2648
                if (ooo2 == "" || ooo2 == "?") {im.downloadLFM000();}
2649
                else
2650
                im.downloadYT11();
2651
				//im.update();
2652
				//window.NotifyOthers("images", "update");
2653
				} else {
2654
					p.console("HTTP error: " + im.xmlhttp.status);
2655
                    if (START_ARTIST.indexOf("*")== 0) {im.downloadGENRE2();}
2656-
                    im.downloadLFM000();
2656+
                    else
2657
                    if (im.xmlhttp.status == 404) {im.downloadLFM000();}
2658
2659
                
2660
                }
2661
			}
2662
		}
2663
	}
2664
}}}
2665
2666
		
2667
	
2668
2669
2670
//open Youtube	
2671
this.downloadYT11 = function()
2672
     {
2673
     //if (!p.fso.FolderExists(this.folder))  return;
2674
        {
2675
        
2676
        //if (server=="last.fm")
2677
        {
2678
        
2679
   //if (p.artist.indexOf("3dydfy://")== 0)
2680
    
2681
    {
2682
        this.working=true;
2683
        if (ooo2 == "" || ooo2 == "?") return;
2684
        //var folder = this.folder + "\\";
2685
		if (!this.xmlhttp) this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
2686
		this.xmlhttp.open("GET", "http://www.youtube.com/results?search_query=" + encodeURIComponent(last_fm) +" - " + encodeURIComponent(ooo2), true);
2687
		this.xmlhttp.send();
2688
		this.xmlhttp.onreadystatechange = function() {
2689
			if (im.xmlhttp.readyState == 4) {
2690
				if (im.xmlhttp.status == 200) {
2691
					var text = im.xmlhttp.responsetext;
2692
					if (!im.doc) im.doc = new ActiveXObject("htmlfile");
2693
					im.doc.open();
2694
					var div = im.doc.createElement("div");
2695
					div.innerHTML = text;
2696
					var data = div.getElementsByTagName("a");
2697
					var urls = [];
2698
    
2699
			
2700
2701
for (i = 0; i < data.length; i++) {
2702
    if (data[i].href.indexOf("about:/watch?v=") == 0) urls.push("http://www.youtube.com/" + data[i].href.replace(/about:\//,""));
2703
}
2704
2705
//select random URL
2706
//var randomnumber = Math.floor(Math.random()*Math.max(urls.length-1))+1;
2707
//i=randomnumber;
2708
i = 1;
2709
2710
{
2711
2712
//do something with urls[i]
2713
p.console("" + urls[i]);
2714
2715
if (urls[i] > "" && ooo2 > "") 
2716
{
2717
YT_URL = window.SetProperty("YT URL", urls[i]);
2718
YT_URL = urls[i];
2719
window.SetProperty("YT URL", urls[i]);
2720
2721
var tmppath = p.fso.GetFolder(fb.FoobarPath).ShortPath;
2722
p.run(tmppath+"\\foobar2000.exe /add "+"\ " + urls[i] + "\"");                   
2723
}
2724
else
2725
//if (urls[i] == "" || urls[i] == "?")
2726
{
2727
YT_URL = window.SetProperty("YT URL", "");
2728
YT_URL = "";
2729
window.SetProperty("YT URL", "");
2730
}
2731
2732
2733
2734
 }
2735
        
2736
                 
2737
             
2738
            
2739
             
2740
//open YT in playlist
2741
//var tmppath = p.fso.GetFolder(fb.FoobarPath).ShortPath;
2742
//p.run(tmppath+"\\foobar2000.exe /immediate /add "+"\""+urls[i] + "\"");
2743
//fb.RunMainMenuCommand("File/Add Youtube URL(s)...") + ("/immediate /add "+"\""+ urls[i]);                       
2744
2745
2746
                im.doc.close();
2747
                im.working=false;
2748
				if (YT_URL == "" || YT_URL == "?") {im.downloadLFM000();}
2749
                
2750
				} else {
2751-
                    im.downloadLFM000();
2751+
2752
                    if (START_ARTIST.indexOf("*")== 0) {im.downloadGENRE2();}
2753
                    else
2754
                    if (im.xmlhttp.status == 404) {im.downloadLFM000();}
2755
2756
                }
2757
			}
2758
		}
2759
	}
2760
}}}
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
//Download Same Video------------------------------------------------------------------
2771
this.downloadART_TITLE = function()
2772
     {
2773
   
2774
        {
2775
        
2776
        
2777
        {
2778
        
2779
  
2780
    
2781
    {
2782
        this.working=true;
2783
        p.artist = p.eval("%artist% %title%");
2784
        if (p.artist == "" || p.artist == "?") return;
2785
        var folder = this.folder + "\\";
2786
		if (!this.xmlhttp) this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
2787
		this.xmlhttp.open("GET", "http://www.youtube.com/results?search_query=" + encodeURIComponent(p.artist), true);
2788
		this.xmlhttp.send();
2789
		this.xmlhttp.onreadystatechange = function() {
2790
			if (im.xmlhttp.readyState == 4) {
2791
				if (im.xmlhttp.status == 200) {
2792
					var text = im.xmlhttp.responsetext;
2793
					if (!im.doc) im.doc = new ActiveXObject("htmlfile");
2794
					im.doc.open();
2795
					var div = im.doc.createElement("div");
2796
					div.innerHTML = text;
2797
					var data = div.getElementsByTagName("a");
2798
					var urls = [];
2799
    
2800
			
2801
2802
for (i = 0; i < data.length; i++) {
2803
    if (data[i].href.indexOf("about:/watch?v=") == 0) urls.push("http://www.youtube.com/" + data[i].href.replace(/about:\//,""));
2804
}
2805
2806
//select random URL
2807
//var randomnumber = Math.floor(Math.random()*Math.max(urls.length-1))+1;
2808
//i=randomnumber;
2809
//i = Math.min(urls.length-38);
2810
i=1;
2811
{
2812
2813
//do something with urls[i]
2814
p.console("" + urls[i]);
2815
2816
var tmppath = p.fso.GetFolder(fb.FoobarPath).ShortPath;
2817
p.run(tmppath+"\\foobar2000.exe /add "+"\ " + urls[i] + "\"");                   
2818
                    
2819
2820
}
2821
        
2822
                 
2823
             
2824
            
2825
             
2826
//open YT in playlist
2827
//var tmppath = p.fso.GetFolder(fb.FoobarPath).ShortPath;
2828
//p.run(tmppath+"\\foobar2000.exe /immediate /add "+"\""+urls[i] + "\"");
2829
//fb.RunMainMenuCommand("File/Add Youtube URL(s)...") + ("/immediate /add "+"\""+ urls[i]);                       
2830
2831
2832
                im.doc.close();
2833
                im.working=false;
2834
				im.update();
2835
				window.NotifyOthers("images", "update");
2836
				} else {
2837
					p.console("HTTP error: " + im.xmlhttp.status);
2838
				}
2839
			}
2840
		}
2841
	}
2842
}}}
2843
2844
2845
2846
//GENRE--------------------------------------------------------------------------------------------------
2847
2848
//open Genre
2849
this.downloadGENRE2 = function()
2850
     {
2851
        {
2852
       
2853
        {
2854
        if (START_ARTIST.indexOf("*")== 0)
2855
   
2856
    
2857
    { var randomnumber=Math.floor(Math.random()*27)
2858
      var a=randomnumber;
2859
        this.working=true;
2860
        if (START_ARTIST == "" || START_ARTIST == "?") return;
2861
        //var folder = this.folder + "\\";
2862
		if (!this.xmlhttp) this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
2863
		this.xmlhttp.open("GET", "http://www.last.fm/music/+tag/" + encodeURIComponent(START_ARTIST).replace("*","") + "?page=" + a, true);
2864
		this.xmlhttp.send();
2865
		this.xmlhttp.onreadystatechange = function() {
2866
			if (im.xmlhttp.readyState == 4) {
2867
				if (im.xmlhttp.status == 200) {
2868
					var text = im.xmlhttp.responsetext;
2869
					if (!im.doc) im.doc = new ActiveXObject("htmlfile");
2870
					im.doc.open();
2871
					var div = im.doc.createElement("li");
2872
					div.innerHTML = text;
2873
					var data = div.getElementsByTagName("a");
2874
					var urls = [];
2875
    
2876
			
2877
2878
for (i = 0; i < data.length; i++) {
2879
     if (data[i].href.indexOf("about:/music/") == 0) urls.push(data[i].href.replace(/about:\//,"").replace("music/","").replace("+"," ").replace("+"," ").replace("+"," ").replace("+"," ").replace("+"," ").replace("+"," ").replace("+"," ").replace("+"," ").replace("+"," ").replace("+"," ").replace("+"," ").replace("+"," ").replace("+"," ").replace("+"," ").replace("+"," ").replace("+"," ").replace("+"," ").replace("+"," ").replace("+"," ").replace("+"," ").replace("free-music-downloads","").replace("/+similar?page=2","").replace("/+events","").replace("/+wiki","").replace("-+","").replace("/+albums","").replace("/+tags","").replace("/+images","").replace("/journal","").replace("/charts","").replace("/images","").replace("/listeners","").replace("/similar?page=17","").replace("/news","").replace("/groups","").replace("/albums","").replace("/videos","").replace("/tracks","").replace("/similar","").replace("/tags","").replace("noredirect/","").replace("listeners/+tracks","").replace("videos/+tracks","").replace("/+videos/","").replace("?page=1","").replace("?page=8","").replace("?page=5","").replace("?page=7","").replace("?page=9","").replace("?page=8","").replace(" wiki/edit","").replace("/ similar","").replace("?page=","'").replace("/ charts","'").replace("-","").replace("%2F%E3%82%A4%E3%83%95%E3%83%BB%E3%83%8E%E3%83%83%E3%83%88%E3%83%BB%E3%83%95%E3%82%A9%E3%83%BE3%83%BB%E3%83%A6%E3%83%BC","").replace("Ajoutez ce titre sur Deezer exclusivement sur www.hotmixradio.fr","").replace("www.Hituri.net","").replace("%E3%81%97%E3%82%83%E3%81%AB%E3%82%80%E3%81%AB%E3%82%B7%E3%82%A7%E3%82%A4%E3%82%AF%EF","").replace("%B81%E3%82%B7%E3%82%A7%E3%82%A4%E3%82%AF%EF%B81","").replace("%E4%BD%95%E3%82%88%E3%82%8A%E3%82%82%E5%83%95%E3%82%89%E3%81%97%E3%81%8F%E3%80%81%E4%BD%95%E3%82%88%E3%82%8A","").replace("%E3%82%82%E5%90%9B%E3%82%89%E3%81%97%E3%81%8F","").replace("%D0%91%D1%8D0%B5%D1%82 %D0%BF%D0%BE %D0%B3%D0%BB%D0%B0%D0%B7%D0%B0%D0%BC","").replace("%E3%83%9E%E3%82%A4%E3%83%BB%E3%83%9E3%83%87%E3%82%A3","").replace("%D0%9B%D0%B5%D1%82%D0%B5%D1%82%D1%8C","").replace("%2F%2F %D0%A1%D0%9B%D0%A3%D0%A8%D0%90%D0%AE%D0%A2","").replace("%D0%9F%D0%BE%D0%BF-%D0%A5%D0%B8%D1%82","").replace("/","").split("tag")[0].split("hype")[0].split("events")[0]);   
2880
}
2881
2882
2883
//select random URL
2884
var randomnumber = Math.floor(Math.random()*(34-96)+96);
2885
do{
2886
randomnumber = Math.floor(Math.random()*(34-96)+96);
2887
} while(randomnumber%2!=0);
2888
2889
i=randomnumber;
2890
2891
{
2892
2893
if (urls[i] > "") 
2894
//p.console("" + urls[i]);
2895
{
2896
2897
last_fm = window.SetProperty("YT Similar", urls[i]);
2898
last_fm = urls[i];
2899
window.SetProperty("YT Similar", urls[i]);
2900
}
2901
else
2902
{
2903
last_fm = window.SetProperty("YT Similar", "");
2904
last_fm = "";
2905
window.SetProperty("YT Similar", "");
2906
}
2907
2908
}
2909
2910
                im.doc.close();
2911
                im.working=false;
2912
                if (last_fm == "" || last_fm == "?") {im.downloadGENRE2();}
2913
                else
2914
                im.downloadTRACK1();
2915
				} else {
2916
					p.console("HTTP error: " + im.xmlhttp.status);
2917
				    if (im.xmlhttp.status == 404)
2918
                    {im.downloadGENRE2();}
2919
                }
2920
			}
2921
		}
2922
	}
2923
}}                             
2924
2925
}
2926
2927
2928
2929
2930
this.update0 = function() {
2931
		this.index = 0;
2932
		for (i = 0; i < this.images.length; i++) {
2933
			try { this.images[i].Dispose(); } catch(e) {}
2934
		}
2935
		this.folders = this.folder.split("|");
2936
		this.files = [];
2937
		for (i = 0; i < this.folders.length; i++) {
2938
			if (p.fso.FolderExists(this.folders[i])) this.files = this.files.concat(utils.Glob(this.folders[i] + "\\" + p.clean_filename(p.artist) + "_0" + "*.jpg").toArray(), utils.Glob(this.folders[i] + "\\" + p.clean_filename(p.artist) + "_0" + "*.jpeg").toArray(), utils.Glob(this.folders[i] + "\\" + p.clean_filename(p.artist) + "_0" + "*.png").toArray(), utils.Glob(this.folders[i] + "\\" + p.clean_filename(p.artist) + "_0" + "*.gif").toArray());
2939
		}
2940
		this.images = [];
2941
		for (i = 0; i < this.files.length; i++) {
2942
			this.images[i] = gdi.Image(this.files[i]);
2943
		}
2944
		if (typeof th == "object") {
2945
			th.nc = true;
2946
			th.calc();
2947
		}
2948
		window.Repaint();
2949
	}  
2950
    
2951
    
2952
    
2953
	this.update = function() {
2954
		this.index = 0;
2955
		for (i = 0; i < this.images.length; i++) {
2956
			try { this.images[i].Dispose(); } catch(e) {}
2957
		}
2958
		this.folders = this.folder.split("|");
2959
		this.files = [];
2960
		for (i = 0; i < this.folders.length; i++) {
2961
			if (p.fso.FolderExists(this.folders[i])) this.files = this.files.concat(utils.Glob(this.folders[i] + "\\*.jpg").toArray(), utils.Glob(this.folders[i] + "\\*.jpeg").toArray(), utils.Glob(this.folders[i] + "\\*.png").toArray(), utils.Glob(this.folders[i] + "\\*.gif").toArray());
2962
		}
2963
2964
		this.images = [];
2965
		for (i = 0; i < this.files.length; i++) {
2966
			this.images[i] = gdi.Image(this.files[i]);
2967
		}
2968
		if (typeof th == "object") {
2969
			th.nc = true;
2970
			th.calc();
2971
		}
2972
		window.Repaint();
2973
	}
2974
	
2975
	this.delete_image = function() {
2976
		if (!this.app) this.app = new ActiveXObject("Shell.Application");
2977
		this.app.Namespace(10).MoveHere(this.files[this.index]);
2978
        window.SetTimeout(function() {
2979
			im.update();
2980
			window.NotifyOthers("images", "update");
2981
		}, 100);
2982
	}
2983
	
2984
	this.x = x;
2985
	this.y = y;
2986
	this.w = w;
2987
	this.h = h;
2988
	this.files = [];
2989
	this.images = [];
2990
	this.index = 0;
2991
	this.artist = "";
2992
	this.folder = "";
2993
	this.limit = 0;
2994
	//this.cycle = window.GetProperty("image_cycle", 0);
2995
	this.mode = ("last.fm");
2996
    //window.GetProperty("image_mode", "last.fm");
2997
	this.type = "adjust";
2998
	this.auto_download = "off";
2999
	this.custom_folder_tf = "$directory_path(%path%)";
3000
}
3001
3002
function lastfm() {
3003
	this.notify_data = function(name, data) {
3004
		if (name == "lastfm" && data == "update") {
3005
			this.username = p.open(this.username_file).trim();
3006
			this.sk = p.open(this.sk_file).trim();
3007
			if (p.check_feature("lastfm_charts")) li.update();
3008
			if (typeof ps == "object") {
3009
				ps.loved_working = false;
3010
				ps.playcount_working = false;
3011
				b.update();
3012
				on_item_focus_change();
3013
			}
3014
			if (p.check_feature("lastfm")) {
3015
				li.artist = "";
3016
				on_item_focus_change();
3017
			}
3018
			if (p.check_feature("lastfm_album")) {
3019
				t.artist = "";
3020
				t.album = "";
3021
				on_item_focus_change();
3022
			}
3023
			window.Repaint();
3024
		}
3025
	}
3026
	
3027
	this.post = function(method, metadb) {
3028
		if (!this.xmlhttp) this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
3029
		switch(method) {
3030
			case "auth.getMobileSession":
3031
				var func = function() {
3032
					var json_data = p.json_parse(l.xmlhttp.responsetext);
3033
					if (!json_data) return;
3034
					if (json_data.error) {
3035
						p.MsgBox(json_data.message, 0, p.name);
3036
					} else if (json_data.session) {
3037
						p.save(json_data.session.key, l.sk_file);
3038
						window.NotifyOthers("lastfm", "update");
3039
						l.notify_data("lastfm", "update");
3040
					}
3041
				}
3042
				
3043
				this.authToken = hex_md5(this.username + hex_md5(this.password));
3044
				this.api_sig = hex_md5("api_key" + this.api_key + "authToken" + this.authToken + "method" + method + "username" + this.username + this.secret);
3045
				this.data = "method=" + method + "&api_key=" + this.api_key + "&api_sig=" + this.api_sig + "&format=json&authToken=" + this.authToken + "&username=" + this.username;
3046
				break;
3047
			case "track.love":
3048
			case "track.unlove":
3049
				var func = function() {
3050
					var json_data = p.json_parse(l.xmlhttp.responsetext);
3051
					if (!json_data) return;
3052
					if (json_data.error) {
3053
						p.console(json_data.message);
3054
					} else if (json_data.status && json_data.status == "ok") {
3055
						p.console("Track " + (method == "track.love" ? "loved successfully." : "unloved successfully."));
3056
						fb.RunContextCommandWithMetadb("Customdb Love " + (method == "track.love" ? 1 : 0), metadb, 8);
3057
					}
3058
				}
3059
				
3060
				if (!metadb || this.username.length == 0 || this.sk.length != 32) return;
3061
				this.artist = fb.TitleFormat(p.artist_tf).EvalWithMetadb(metadb);
3062
				this.track = fb.TitleFormat("%title%").EvalWithMetadb(metadb);
3063
				if (this.artist == "" || this.artist == "?" || this.track == "?") return;
3064
				p.console("Attempting to " + (method == "track.love" ? "love \"" : "unlove \"") + this.track + "\" by \"" + this.artist + "\"");
3065
				p.console("Contacting Last.fm....");
3066
				this.api_sig = hex_md5("api_key" + this.api_key + "artist" + this.artist + "method" + method + "sk" + this.sk + "track" + this.track + this.secret);
3067
				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);
3068
				break;
3069
			default:
3070
				return;
3071
		}
3072
		
3073
		this.xmlhttp.open("POST", "https://ws.audioscrobbler.com/2.0/", true);
3074
		this.xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
3075
		this.xmlhttp.setRequestHeader("User-Agent", this.user_agent);
3076
		this.xmlhttp.send(this.data);
3077
		this.xmlhttp.onreadystatechange = function() {
3078
			if (l.xmlhttp.readyState == 4) {
3079
				if (l.xmlhttp.status == 200) {
3080
					func();
3081
				} else {
3082
					p.console(l.xmlhttp.responsetext || "HTTP error: " + l.xmlhttp.status);
3083
				}
3084
			}
3085
		}
3086
	}
3087
	
3088
	this.update_username = function() {
3089
		var old_username = this.username;
3090
		this.username = p.InputBox("Enter your Last.fm username.", p.name, this.username);
3091
		if (this.username.length > 0 && this.username != old_username) p.save("", this.sk_file);
3092
		p.save(this.username, this.username_file);
3093
		window.NotifyOthers("lastfm", "update");
3094
		this.notify_data("lastfm", "update");
3095
	}
3096
	
3097
	this.update_password = function() {
3098
		this.password = p.InputBox("Enter your Last.fm password\n\nThis is only required to love/unlove tracks.", p.name, "");
3099
		if (this.password.length > 0) {
3100
			this.sk = "";
3101
			p.save(this.sk, this.sk_file);
3102
			window.NotifyOthers("lastfm", "update");
3103
			this.notify_data("lastfm", "update");
3104
			this.post("auth.getMobileSession");
3105
		}
3106
	}
3107
	
3108
	this.get_url = function() {
3109
		return "http://ws.audioscrobbler.com/2.0/?format=json&api_key=" + this.api_key + "&user=" + this.username + "&username=" + this.username + "&s=" + Math.random();
3110
	}
3111
	
3112
	this.username_error = "Use the right click menu to set your Last.fm username.";
3113
	this.password_error = "Use the right click menu to set your Last.fm password.";
3114
	this.url = "http://www.last.fm/";
3115
	this.api_key = "56d9e050cc2d6b36102c8b4a5fe6152d";
3116
	this.secret = "9f1f4346ce3ba206390074ff8cb4c6ce";
3117
	this.user_agent = "foobar2000_wsh_panel_mod_scripts";
3118
	this.username_file = p.settings_folder + "username";
3119
	this.username = p.open(this.username_file).trim();
3120
	this.sk_file = p.settings_folder + "sk";
3121
	this.sk = p.open(this.sk_file).trim();
3122
	this.auto_correct = window.GetProperty("lastfm_auto_correct", true);
3123
}
3124
3125
function list(x, y, w, h) {
3126
	this.size = function() {
3127
		this.row_height = this.mode == "echonest" ? 90 : 20;
3128
		this.rows = Math.floor((this.h - (this.mode == "echonest" ? 50 : 30)) / this.row_height);
3129
		this.index = 0;
3130
		this.offset = 0;
3131
		switch(true) {
3132
			case this.mode == "lastfm_charts":
3133
				this.text_width = Math.round(this.w / 3);
3134
				this.lastfm_charts_bar_x = this.text_width + 30;
3135
				break;
3136
			case this.mode == "musicbrainz" && this.musicbrainz_mode == "releases":
3137
				this.text_width = this.w - 120;
3138
				break;
3139
			default:
3140
				this.text_width = this.w - 50;
3141
				break;
3142
		}
3143
		this.but_x = this.x + Math.round((this.w - 15) / 2);
3144
		this.up_btn = new sb(this.but_x, this.y, 15, 15, p.up_img, "li.offset > 0", function() { li.wheel(1); });
3145
		this.down_btn = new sb(this.but_x, this.y + this.h - 15, 15, 15, p.down_img, "li.offset < li.items - li.rows", function() { li.wheel(-1); });
3146
	}
3147
	
3148
	this.draw = function(gr) {
3149
		switch(this.mode) {
3150
			case "discogs":
3151
				for (i = 0; i < Math.min(this.items, this.rows); i++) {
3152
					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, 20);
3153
					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, 20);
3154
				}
3155
				break;
3156
			case "lastfm_charts":
3157
				var max_bar_width = (this.w - this.lastfm_charts_bar_x - 40) / this.playcounts[0];
3158
				for (i = 0; i < Math.min(this.items, this.rows); i++) {
3159
					p.right_text(gr, this.ranks[i + this.offset] + ".", p.list_font, p.textcolour_hl, this.x, this.y + 15 + (i * this.row_height), 17, 20);
3160
					var bar_width = max_bar_width * this.playcounts[i + this.offset];
3161
					var bar_colour = p.splitRGB(this.lastfm_charts_bar_colour);
3162
					gr.FillSolidRect(this.lastfm_charts_bar_x + this.x, this.y + 16 + (i * this.row_height), bar_width, 18, bar_colour);
3163
					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, 20);
3164
					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, 20);
3165
				}
3166
				break;
3167
			case "lastfm":
3168
				for (i = 0; i < Math.min(this.items, this.rows); i++) {
3169
					if (this.lastfm_mode == 0) p.draw_image(gr, this.lastfm_button == "spotify" ? this.lastfm_spotify_img : this.autoplaylist_img, this.x, this.y + 16 + (i * this.row_height), 16, 16, "adjust");
3170
					if (this.lastfm_mode == 1 || this.lastfm_mode == 3 || this.lastfm_mode == 4) p.draw_image(gr, this.autoplaylist_img, this.x, this.y + 16 + (i * this.row_height), 16, 16, "adjust");
3171
					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, 20);
3172
				}
3173
				break;
3174
			case "musicbrainz":
3175
				for (i = 0; i < Math.min(this.items, this.rows); i++) {
3176
					if (this.musicbrainz_mode == "URLs") p.draw_image(gr, this.musicbrainz_images[this.images[i + this.offset]], this.x, this.y + 16 + (i * this.row_height), 16, 16, "adjust");
3177
					if (this.musicbrainz_mode == "releases") {
3178
						p.draw_image(gr, this.autoplaylist_img, this.x, this.y + 16 + (i * this.row_height), 16, 16, "adjust");
3179
						if (this.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 - 30, 20);
3180
						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, 20);
3181
					}
3182
					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, 20);
3183
				}
3184
				break;
3185
			case "autoplaylists":
3186
				for (i = 0; i < Math.min(this.items, this.rows); i++) {
3187
					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, 20);
3188
					if (!this.autoplaylists_editing && this.autoplaylists_hover && this.index == i + this.offset) {
3189
						p.draw_image(gr, this.autoplaylists_edit_img, this.x + this.w - 40, this.y + 16 + (i * this.row_height), 16, 16, "adjust");
3190
						p.draw_image(gr, this.autoplaylists_del_img, this.x + this.w - 20, this.y + 16 + (i * this.row_height), 16, 16, "adjust");
3191
					}
3192
				}
3193
				break;
3194
			case "echonest":
3195
				for (i = 0; i < Math.min(this.items, this.rows); i++) {
3196
					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);
3197
					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);
3198
					gr.GdiDrawText(this.summaries[i + this.offset], p.normal_font, p.textcolour, this.x, this.y + 37 + (i * this.row_height), this.w, p.normal_font.Height * Math.floor(64 / p.normal_font.Height), DT_WORDBREAK | DT_CALCRECT | DT_NOPREFIX);
3199
				}
3200
				break;
3201
		}
3202
		this.up_btn.draw(gr);
3203
		this.down_btn.draw(gr);
3204
		if (this.show_timestamp) p.left_text(gr, this.date, p.list_font, p.textcolour_hl, this.x, this.y + this.h - 15, this.w, 15);
3205
	}
3206
	
3207
	this.metadb_changed = function() {
3208
		p.artist = p.eval(p.artist_tf);
3209
		if (this.artist == p.artist) return false;
3210
		this.artist = p.artist;
3211
		this.folder = p.data_folder + p.artist_tf;
3212
		//if (!p.fso.FolderExists(this.folder)) p.fso.CreateFolder(this.folder);
3213
		this.update();
3214
		return true;
3215
	}
3216
	
3217
	this.trace = function(x, y) {
3218
		return (x > this.x && x < this.x + this.w && y > this.y && y < this.y + this.h);
3219
	}
3220
	
3221
	this.wheel = function(step) {
3222
		if (!this.trace(p.mx, p.my)) return false;
3223
		if (this.items > this.rows) {
3224
			this.offset -= step * (this.mode == "echonest" ? 1 : 3);
3225
			if (this.offset < 0) this.offset = 0;
3226
			if (this.rows + this.offset > this.items) this.offset = this.items - this.rows;
3227
			window.RepaintRect(this.x, this.y, this.w, this.h);
3228
		}
3229
		return true;
3230
	}
3231
	
3232
	this.move = function(x, y) {
3233
		this.index = Math.floor((y - this.y - 15) / this.row_height) + this.offset;
3234
		this.in_range = this.index >= this.offset && this.index < this.offset + Math.min(this.rows, this.items);
3235
		switch(true) {
3236
			case !this.trace(x, y):
3237
			case this.mode == "autoplaylists" && this.autoplaylists_editing:
3238
			case this.mode == "lastfm" && l.username.length == 0:
3239
				window.SetCursor(IDC_ARROW);
3240
				this.leave();
3241
				return false;
3242
			case this.up_btn.trace(x, y):
3243
			case this.down_btn.trace(x, y):
3244
				window.SetCursor(IDC_HAND);
3245
				break;
3246
			case !this.in_range:
3247
				window.SetCursor(IDC_ARROW);
3248
				this.leave();
3249
				break;
3250
			case this.mode == "musicbrainz" && this.musicbrainz_mode == "releases" && x > this.x && x < this.x + 20:
3251
			case this.mode == "lastfm" && this.text_x == 20 && x > this.x && x < this.x + 20:
3252
				window.SetCursor(IDC_HAND);
3253
				switch(true) {
3254
					case this.lastfm_mode == 0 && this.lastfm_button == "spotify":
3255
						p.tt('spotify:search:"' + this.names[this.index].replace(/\s+/g, "+") + '"');
3256
						break;
3257
					default:
3258
						p.tt("Autoplaylist: " + this.queries[this.index]);
3259
						break;
3260
				}
3261
				break;
3262
			case this.mode == "autoplaylists":
3263
				switch(true) {
3264
					case x > this.x && x < this.x + Math.min(this.names_widths[this.index], this.text_width):
3265
						window.SetCursor(IDC_HAND);
3266
						p.tt('Run "' + this.names[this.index] + '"');
3267
						break;
3268
					case x > this.x + this.w - 40 && x < this.x + this.w - 20:
3269
						window.SetCursor(IDC_HAND);
3270
						p.tt('Edit "' + this.names[this.index] + '"');
3271
						break;
3272
					case x > this.x + this.w - 20 && x < this.x + this.w:
3273
						window.SetCursor(IDC_HAND);
3274
						p.tt('Delete "' + this.names[this.index] + '"');
3275
						break;
3276
					default:
3277
						window.SetCursor(IDC_ARROW);
3278
						this.leave();
3279
						break;
3280
				}
3281
				this.autoplaylists_hover = true;
3282
				window.RepaintRect(this.x + this.w - 40, this.y + 15, 40, Math.min(this.rows, this.items) * this.row_height);
3283
				break;
3284
			case this.mode == "echonest":
3285
			case x > this.x + this.text_x && x < this.x + this.text_x + Math.min(this.names_widths[this.index], this.text_width):
3286
				window.SetCursor(IDC_HAND);
3287
				p.tt(this.urls[this.index]);
3288
				break;
3289
			default:
3290
				window.SetCursor(IDC_ARROW);
3291
				p.ttd();
3292
				break;
3293
		}
3294
		return true;
3295
	}
3296
	
3297
	this.lbtn_up = function(x, y) {
3298
		switch(true) {
3299
			case !this.trace(x, y):
3300
				return false;
3301
			case this.mode == "autoplaylists" && this.autoplaylists_editing:
3302
			case this.mode == "lastfm" && l.username.length == 0:
3303
			case this.up_btn.lbtn_up(x, y):
3304
			case this.down_btn.lbtn_up(x, y):
3305
			case !this.in_range:
3306
				break;
3307
			case this.mode == "musicbrainz" && this.musicbrainz_mode == "releases" && x > this.x && x < this.x + 20:
3308
			case this.mode == "lastfm" && this.text_x == 20 && x > this.x && x < this.x + 20:
3309
				switch(true) {
3310
					case this.lastfm_mode == 0 && this.lastfm_button == "spotify":
3311
						if (p.run('spotify:search:"' + this.names[this.index].replace(/\s+/g, "+") + '"')) {
3312
							if (fb.IsPlaying && !fb.IsPaused && this.lastfm_pause) fb.Pause();
3313
						} else {
3314
							p.MsgBox("Unable to launch Spotify.", 0, p.name);
3315
						}
3316
						break;
3317
					default:
3318
						fb.CreateAutoPlaylist(fb.PlaylistCount, this.names[this.index], this.queries[this.index]);
3319
						fb.ActivePlaylist = fb.PlaylistCount - 1;
3320
						break;
3321
				}
3322
				break;
3323
			case this.mode == "autoplaylists":
3324
				switch(true) {
3325
					case x > this.x && x < this.x + Math.min(this.names_widths[this.index], this.text_width):
3326
						this.autoplaylists_run(this.names[this.index], this.queries[this.index], this.sorts[this.index], this.forced[this.index]);
3327
						break;
3328
					case x > this.x + this.w - 40 && x < this.x + this.w - 20:
3329
						this.autoplaylists_edit(x, y);
3330
						break;
3331
					case x > this.x + this.w - 20 && x < this.x + this.w:
3332
						this.autoplaylists_delete();
3333
						break
3334
				}
3335
				break;
3336
			case this.mode == "echonest":
3337
			case x > this.x + this.text_x && x < this.x + this.text_x + Math.min(this.names_widths[this.index], this.text_width):
3338
				p.browser(this.urls[this.index]);
3339
				break;
3340
		}
3341
		return true;
3342
	}
3343
	
3344
	this.leave = function() {
3345
		p.ttd();
3346
		if (this.mode != "autoplaylists") return;
3347
		this.autoplaylists_hover = false;
3348
		window.RepaintRect(this.x, this.y, this.w, this.h);
3349
	}
3350
	
3351
	this.update = function() {
3352
		this.items = 0;
3353
		this.offset = 0;
3354
		this.index = 0;
3355
		this.names = [];
3356
		this.names_widths = [];
3357
		this.urls = [];
3358
		this.dates = [];
3359
		this.queries = [];
3360
		this.ranks = [];
3361
		this.playcounts = [];
3362
		this.sorts = [];
3363
		this.summaries = [];
3364
		this.release_types = [];
3365
		this.images = [];
3366
		this.forced = [];
3367
		this.data = [];
3368
		this.file = null;
3369
		this.date = "";
3370
		var temp_bmp = gdi.CreateImage(1, 1);
3371
		var temp_gr = temp_bmp.GetGraphics();
3372
		switch(this.mode) {
3373
			case "autoplaylists":
3374
				this.text = p.open(this.filename);
3375
				this.data = this.text.split(/\r?\n/g);
3376
				this.items = this.data.length;
3377
				for (i = 0; i < this.items; i++) {
3378
					var temp = this.data[i].split("¬");
3379
					this.names[i] = temp[0];
3380
					this.queries[i] = temp[1];
3381
					this.sorts[i] = temp[2];
3382
					this.forced[i] = temp[3];
3383
					this.names_widths[i] = temp_gr.CalcTextWidth(this.names[i], p.list_font);
3384
				}
3385
				break;
3386
			case "lastfm":
3387
				this.text_x = 20;
3388
				this.filename = this.folder + "\\" + this.lastfm_methods[this.lastfm_mode] + ".json";
3389
				if (p.fso.fileExists(this.filename)) {
3390
					this.file = p.fso.Getfile(this.filename);
3391
					this.json_text = p.open(this.filename);
3392
					this.json_data = p.json_parse(this.json_text);
3393
					if (this.json_data) {
3394
						switch(true) {
3395
							case this.json_data.error > 0:
3396
								p.console(this.json_data.message);
3397
								break;
3398
							case this.lastfm_mode == 0 && this.json_data.similarartists && typeof this.json_data.similarartists.artist == "object":
3399
								this.data = this.json_data.similarartists.artist;
3400
								break;
3401
							case this.lastfm_mode == 1 && this.json_data.toptags && typeof this.json_data.toptags.tag == "object":
3402
								this.data = this.json_data.toptags.tag;
3403
								break;
3404
							case this.lastfm_mode == 2 && this.json_data.topfans && typeof this.json_data.topfans.user == "object":
3405
								this.text_x = 0;
3406
								this.data = this.json_data.topfans.user;
3407
								break;
3408
							case this.lastfm_mode == 3 && this.json_data.topalbums && typeof this.json_data.topalbums.album == "object":
3409
								this.data = this.json_data.topalbums.album;
3410
								break;
3411
							case this.lastfm_mode == 4 && this.json_data.toptracks && typeof this.json_data.toptracks.track == "object":
3412
								this.data = this.json_data.toptracks.track;
3413
								break;
3414
						}
3415
						this.items = this.data.length;
3416
						for (i = 0; i < this.items; i++) {
3417
							this.names[i] = this.data[i].name;
3418
							this.urls[i] = this.data[i].url;
3419
							this.names_widths[i] = temp_gr.CalcTextWidth(this.names[i], p.list_font);
3420
							if (this.lastfm_mode == 0) this.queries[i] = "artist HAS " + this.names[i];
3421
							if (this.lastfm_mode == 1) this.queries[i] = "genre HAS " + this.names[i];
3422
							if (this.lastfm_mode == 3) this.queries[i] = "album HAS " + this.names[i] + " OR title HAS " + this.names[i];
3423
							if (this.lastfm_mode == 4) this.queries[i] = "title HAS " + this.names[i];
3424
						}
3425
					}
3426
					if (Date.parse(Date()) - Date.parse(this.file.DateLastModified) > ONE_DAY) this.get();
3427
				} else {
3428
					this.get();
3429
				}
3430
				break;
3431
			case "lastfm_charts":
3432
				this.filename = this.folder + "\\" + l.username + "_" + this.lastfm_charts_modes[this.lastfm_charts_mode] + "_" + this.lastfm_charts_periods[this.lastfm_charts_period] + ".json";
3433
				if (p.fso.fileExists(this.filename)) {
3434
					this.file = p.fso.Getfile(this.filename);
3435
					this.json_text = p.open(this.filename);
3436
					this.json_data = p.json_parse(this.json_text);
3437
					if (this.json_data) {
3438
						switch(true) {
3439
							case this.json_data.error > 0:
3440
								p.console(this.json_data.message);
3441
								break;
3442
							case this.lastfm_charts_mode == 0 && this.json_data.topartists && typeof this.json_data.topartists.artist == "object":
3443
								this.data = this.json_data.topartists.artist;
3444
								break;
3445
							case this.lastfm_charts_mode == 1 && this.json_data.topalbums && typeof this.json_data.topalbums.album == "object":
3446
								this.data = this.json_data.topalbums.album;
3447
								break;
3448
							case this.lastfm_charts_mode == 2 && this.json_data.toptracks && typeof this.json_data.toptracks.track == "object":
3449
								this.data = this.json_data.toptracks.track;
3450
								break;
3451
						}
3452
						this.items = this.data.length;
3453
						for (i = 0; i < this.items; i++) {
3454
							this.names[i] = this.lastfm_charts_mode != 0 ? this.data[i].artist.name + " - " + this.data[i].name : this.data[i].name;
3455
							this.ranks[i] = (i > 0 && this.data[i].playcount == this.data[i - 1].playcount) ? this.ranks[i - 1] : this.data[i]["@attr"].rank;
3456
							this.urls[i] = this.data[i].url;
3457
							this.names_widths[i] = temp_gr.CalcTextWidth(this.names[i], p.list_font);
3458
							this.playcounts[i] = this.data[i].playcount;
3459
						}
3460
					}
3461
					if (Date.parse(Date()) - Date.parse(this.file.DateLastModified) > ONE_DAY) this.get();
3462
				} else {
3463
					this.get();
3464
				}
3465
				break;
3466
			case "discogs":
3467
				this.filename = this.folder + "\\discogs.json";
3468
				if (p.fso.fileExists(this.filename)) {
3469
					this.file = p.fso.Getfile(this.filename);
3470
					this.json_text = p.open(this.filename);
3471
					this.json_data = p.json_parse(this.json_text);
3472
					if (this.json_data && this.json_data.results) {
3473
						this.data = this.json_reverse_sort(this.json_data.results, "year");
3474
						var swap_artist = fb.TitleFormat("$swapprefix($lower(" + p.artist + ")) - ").Eval(true);
3475
						for (i = 0; i < this.data.length; i++) {
3476
							var temp_artist = this.data[i].title.replace(/\s{2,}/g,' ');
3477
							if (this.discogs_match && temp_artist.toLowerCase().indexOf(swap_artist) != 0) continue;
3478
							this.dates.push(this.data[i].year || "");
3479
							this.urls.push("http://www.discogs.com" + this.data[i].uri);
3480
							this.names.push(temp_artist);
3481
							this.names_widths.push(temp_gr.CalcTextWidth(temp_artist, p.list_font));
3482
						}
3483
						this.items = this.names.length;
3484
					}
3485
					if (Date.parse(Date()) - Date.parse(this.file.DateLastModified) > ONE_DAY) this.get();
3486
				} else {
3487
					this.get();
3488
				}
3489
				break;
3490
			case "musicbrainz":
3491
				this.filename = this.folder + "\\musicbrainz_" + this.musicbrainz_mode + ".json";
3492
				if (p.fso.fileExists(this.filename)) {
3493
					this.file = p.fso.Getfile(this.filename);
3494
					this.json_text = p.open(this.filename);
3495
					this.json_data = p.json_parse(this.json_text);
3496
					if (this.json_data) {
3497
						switch(this.musicbrainz_mode) {
3498
							case "releases":
3499
								this.data = this.json_data["release-groups"] || [];
3500
								this.data = this.json_reverse_sort(this.data, "first-release-date");
3501
								var primary, secondary, name;
3502
								for (i = 0; i < this.data.length; i++) {
3503
									primary = this.data[i]["primary-type"];
3504
									secondary = this.data[i]["secondary-types"].join("").toLowerCase();
3505
									switch(true) {
3506
										case !this.musicbrainz_remix && secondary.indexOf("remix") > -1:
3507
										case !this.musicbrainz_compilation && secondary.indexOf("compilation") > -1:
3508
										case !this.musicbrainz_live && secondary.indexOf("live") > -1:
3509
											break;
3510
										case this.musicbrainz_single && primary == "Single":
3511
										case this.musicbrainz_ep && primary == "EP":
3512
										case this.musicbrainz_album && primary == "Album":
3513
											name = this.data[i].title;
3514
											this.dates.push(this.data[i]["first-release-date"].substring(0,4));
3515
											this.names.push(name);
3516
											this.urls.push("http://musicbrainz.org/release-group/" + this.data[i].id);
3517
											this.names_widths.push(temp_gr.CalcTextWidth(name, p.list_font));
3518
											this.queries.push("album HAS " + name + " OR title HAS " + name);
3519
											switch(true) {
3520
												case secondary.indexOf("remix") > -1:
3521
													this.release_types.push("Remix");
3522
													break;
3523
												case secondary.indexOf("compilation") > -1:
3524
													this.release_types.push("Compilation");
3525
													break;
3526
												case secondary.indexOf("live") > -1:
3527
													this.release_types.push("Live");
3528
													break;
3529
												default:
3530
													this.release_types.push(primary);
3531
													break;
3532
											}
3533
									}
3534
								}
3535
								this.items = this.names.length;
3536
								break;
3537
							case "URLs":
3538
								this.data = this.json_data.relations || [];
3539
								this.items = this.data.length;
3540
								for (i = 0; i < this.items; i++) {
3541
									this.urls[i] = this.data[i].url.resource;
3542
									this.images[i] = "";
3543
									if (this.data[i].type == "official homepage") {
3544
										this.images[i] = "home";
3545
									} else {
3546
										for (name in this.musicbrainz_images) {
3547
											if (this.urls[i].indexOf(name) > -1) {
3548
												this.images[i] = name;
3549
												break;
3550
											}
3551
										}
3552
										if (this.images[i].length == 0) this.images[i] = "external";
3553
									}
3554
									this.names[i] = decodeURIComponent(this.urls[i]);
3555
									this.names_widths[i] = temp_gr.CalcTextWidth(this.names[i], p.list_font);
3556
								}
3557
								break;
3558
						}
3559
					}
3560
					if (Date.parse(Date()) - Date.parse(this.file.DateLastModified) > ONE_DAY) this.get();
3561
				} else {
3562
					this.get();
3563
				}
3564
				break;
3565
			case "echonest":
3566
				this.filename = this.folder + "\\echonest_" + this.echonest_modes[this.echonest_mode] + ".json";
3567
				if (p.fso.fileExists(this.filename)) {
3568
					this.file = p.fso.Getfile(this.filename);
3569
					this.json_text = p.open(this.filename);
3570
					this.json_data = p.json_parse(this.json_text);
3571
					if (this.json_data && this.json_data.response && this.json_data.response.status && this.json_data.response.status.code == 0) {
3572
						this.data = this.json_data.response[this.echonest_modes[this.echonest_mode]] || [];
3573
						this.items = this.data.length;
3574
						for (i = 0; i < this.items; i++) {
3575
							this.names[i] = p.strip_tags(this.data[i].name);
3576
							this.urls[i] = (this.data[i].url || "").replace(/\\/g, "");
3577
							this.temp_date = (this.data[i].date_posted || this.data[i].date_reviewed || this.data[i].date_found || "").substring(0, 10);
3578
							this.dates[i] = this.temp_date.substring(8,10) + "-" + this.temp_date.substring(5,7) + "-" + this.temp_date.substring(0,4);
3579
							this.summaries[i] = p.strip_tags(this.data[i].summary);
3580
						}
3581
					}
3582
					if (Date.parse(Date()) - Date.parse(this.file.DateLastModified) > ONE_DAY) this.get();
3583
				} else {
3584
					this.get();
3585
				}
3586
				break;
3587
		}
3588
		temp_bmp.ReleaseGraphics(temp_gr);
3589
		temp_bmp.Dispose();
3590
		temp_gr = null;
3591
		temp_bmp = null;
3592
		if (this.file) {
3593
			var temp_date = new Date(this.file.DateLastModified);
3594
			this.date = "Updated: " + temp_date.toLocaleTimeString() + ", " + temp_date.toLocaleDateString();
3595
		}
3596
		window.Repaint();
3597
	}
3598
	
3599
	this.get = function() {
3600
		var fn = this.filename;
3601
		var func = function() {
3602
			if (!p.save(li.xmlhttp.responsetext, fn)) return;
3603
			li.update();
3604
		}
3605
		var url = "";
3606
		var user_agent = "";
3607
		switch(this.mode) {
3608
			case "discogs":
3609
				if (this.artist == "" || this.artist == "?") return;
3610
				url = "http://api.discogs.com/database/search?per_page=100&type=master&artist=" + encodeURIComponent(this.artist);
3611
				user_agent = "foobar2000_wsh_panel_mod_discogs +http://www.hydrogenaudio.org/forums/index.php?showuser=19379";
3612
				break;
3613
			case "lastfm_charts":
3614
				if (l.username.length == 0) return(p.console(l.username_error));
3615
				url = l.get_url() + "&method=user." + this.lastfm_charts_methods[this.lastfm_charts_mode] + "&period=" + this.lastfm_charts_periods[this.lastfm_charts_period];
3616
				user_agent = l.user_agent;
3617
				break;
3618
			case "lastfm":
3619
				if (this.artist == "" || this.artist == "?") return;
3620
				if (l.username.length == 0) return(p.console(l.username_error));
3621
				url = l.get_url() + "&method=" + this.lastfm_methods[this.lastfm_mode] + "&artist=" + encodeURIComponent(this.artist) + "&autocorrect=" + (l.auto_correct ? 1 : 0);
3622
				user_agent = l.user_agent;
3623
				break;
3624
			case "musicbrainz":
3625
				user_agent = "foobar2000_wsh_panel_mod_musicbrainz +http://www.hydrogenaudio.org/forums/index.php?showuser=19379";
3626
				var fn1 = this.folder + "\\MUSICBRAINZ_ARTISTID.txt";
3627
				this.musicbrainz_id = p.eval("$if3(%musicbrainz_artistid%,%musicbrainz artist id%,)");
3628
				this.musicbrainz_id = this.musicbrainz_id.substring(0, 36);
3629
				if (this.musicbrainz_id.length == 0) this.musicbrainz_id = p.open(fn1);
3630
				if (this.musicbrainz_id.length == 0) {
3631
					if (this.artist == "" || this.artist == "?") return;
3632
					url = "https://musicbrainz.org/ws/2/artist/?query=artist:" + encodeURIComponent(this.artist.toLowerCase()) + "&fmt=json";
3633
					var func = function() {
3634
						var json_data = p.json_parse(li.xmlhttp.responsetext);
3635
						if (!json_data) return;
3636
						var artist = li.artist.toLowerCase();
3637
						var artists = json_data.artist || [];
3638
						for (i = 0; i < artists.length; i++) {
3639
							if (artist == artists[i].name.toLowerCase()) {
3640
								if (!p.save(artists[i].id, fn1)) return;
3641
								li.get();
3642
								break;
3643
							}
3644
						}
3645
					}
3646
				} else {
3647
					if (this.musicbrainz_mode == "releases") url = "https://musicbrainz.org/ws/2/release-group?artist=" + this.musicbrainz_id + "&limit=100&offset=0&fmt=json";
3648
					else url = "https://musicbrainz.org/ws/2/artist/" + this.musicbrainz_id + "?inc=url-rels&fmt=json";
3649
				}
3650
				break;
3651
			case "echonest":
3652
				if (this.artist == "" || this.artist == "?") return;
3653
				url = "http://developer.echonest.com/api/v4/artist/" + this.echonest_modes[this.echonest_mode] + "/?name=" + encodeURIComponent(this.artist) + "&api_key=EKWS4ESQLKN3G2ZWV";
3654
				break;
3655
		}
3656
		if (url.length == 0) return;
3657
		this.xmlhttp.open("GET", url, true);
3658
		if (user_agent.length > 0) this.xmlhttp.setRequestHeader('User-Agent', user_agent);
3659
		this.xmlhttp.send();
3660
		this.xmlhttp.onreadystatechange = function() {
3661
			if (li.xmlhttp.readyState == 4) {
3662
				if (li.xmlhttp.status == 200) {
3663
					func();
3664
				} else {
3665
					p.console(li.xmlhttp.responsetext || "HTTP error: " + li.xmlhttp.status);
3666
				}
3667
			}
3668
		}
3669
	}
3670
	
3671
	this.json_reverse_sort = function(data, prop) {
3672
		data = data.sort(function(a, b) {
3673
			if (!a[prop] || b[prop] > a[prop]) return 1;
3674
			if (!b[prop] || b[prop] < a[prop]) return -1;
3675
			return 0;
3676
		});
3677
		return data;
3678
	}
3679
	
3680
	this.init = function() {
3681
		switch(true) {
3682
			case p.check_feature("discogs"):
3683
				this.mode = "discogs";
3684
				this.discogs_match = window.GetProperty("discogs_match", false);
3685
				break;
3686
			case p.check_feature("lastfm_charts"):
3687
				this.mode = "lastfm_charts";
3688
				this.text_x = 20;
3689
				this.lastfm_charts_modes = ["artist", "album", "track"];
3690
				this.lastfm_charts_mode = window.GetProperty("lastfm_charts_mode", 0);
3691
				this.lastfm_charts_methods = ["getTopArtists", "getTopAlbums", "getTopTracks"];
3692
				this.lastfm_charts_periods_display = ["overall", "last 7 days", "1 month", "3 month", "6 month", "12 month"];
3693
				this.lastfm_charts_periods = ["overall", "7day", "1month", "3month", "6month", "12month"];
3694
				this.lastfm_charts_period = window.GetProperty("lastfm_charts_period", 0);
3695
				this.lastfm_charts_bar_colour = window.GetProperty("lastfm_charts_bar_colour", "72-127-221");
3696
				this.folder = p.data_folder + "charts";
3697
				//if (!p.fso.FolderExists(this.folder)) p.fso.CreateFolder(this.folder);
3698
				break;
3699
			case p.check_feature("lastfm"):
3700
				this.mode = "lastfm";
3701
				this.lastfm_methods = ["artist.getSimilar", "artist.getTopTags", "artist.getTopFans", "artist.getTopAlbums", "artist.getTopTracks"];
3702
				this.lastfm_modes = ["similar artists", "top tags", "top fans", "top albums", "top tracks"];
3703
				this.lastfm_mode = window.GetProperty("lastfm_mode", 0);
3704
				this.lastfm_button = window.GetProperty("lastfm_button", "spotify");
3705
				this.lastfm_pause = window.GetProperty("lastfm_pause", true);
3706
				this.lastfm_spotify_img = gdi.Image(p.images_path + "spotify.png");
3707
				break;
3708
			case p.check_feature("musicbrainz"):
3709
				this.mode = "musicbrainz";
3710
				this.text_x = 20;
3711
				this.musicbrainz_images = {
3712
					"viaf.org": gdi.Image(p.images_path + "viaf_small.png"),
3713
					"allmusic.com": gdi.Image(p.images_path + "allmusic_small.png"),
3714
					"external": gdi.Image(p.images_path + "external_small.png"),
3715
					"bbc.co.uk": gdi.Image(p.images_path + "bbc_small.png"),
3716
					"facebook.com": gdi.Image(p.images_path + "facebook_small.png"),
3717
					"home": gdi.Image(p.images_path + "home_small.png"),
3718
					"last.fm": gdi.Image(p.images_path + "lastfm_small.png"),
3719
					"twitter.com": gdi.Image(p.images_path + "twitter_small.png"),
3720
					"soundcloud.com": gdi.Image(p.images_path + "soundcloud_small.png"),
3721
					"wikipedia.org": gdi.Image(p.images_path + "wikipedia_small.png"),
3722
					"discogs.com": gdi.Image(p.images_path + "discogs_small.png"),
3723
					"myspace.com": gdi.Image(p.images_path + "myspace_small.png"),
3724
					"youtube.com": gdi.Image(p.images_path + "youtube_small.png"),
3725
					"imdb.com": gdi.Image(p.images_path + "imdb_small.png"),
3726
					"plus.google.com": gdi.Image(p.images_path + "google_plus_small.png"),
3727
					"lyrics.wikia.com": gdi.Image(p.images_path + "lyrics_wikia_small.png"),
3728
					"flickr.com": gdi.Image(p.images_path + "flickr_small.png"),
3729
					"secondhandsongs.com": gdi.Image(p.images_path + "secondhandsongs_small.png"),
3730
					"vimeo.com": gdi.Image(p.images_path + "vimeo_small.png"),
3731
					"rateyourmusic.com": gdi.Image(p.images_path + "rateyourmusic_small.png"),
3732
					"instagram.com": gdi.Image(p.images_path + "instagram_small.png"),
3733
					"tumblr.com": gdi.Image(p.images_path + "tumblr_small.png"),
3734
					"decoda.com": gdi.Image(p.images_path + "decoda_small.png"),
3735
					"wikidata.org": gdi.Image(p.images_path + "wikidata_small.png")
3736
				}
3737
				this.musicbrainz_mode = window.GetProperty("musicbrainz_mode", "releases");
3738
				this.musicbrainz_show_release_type = window.GetProperty("musicbrainz_show_release_type", true);
3739
				this.musicbrainz_live = window.GetProperty("musicbrainz_live", false);
3740
				this.musicbrainz_ep = window.GetProperty("musicbrainz_ep", true);
3741
				this.musicbrainz_single = window.GetProperty("musicbrainz_single", true);
3742
				this.musicbrainz_album = window.GetProperty("musicbrainz_album", true);
3743
				this.musicbrainz_remix = window.GetProperty("musicbrainz_remix", true);
3744
				this.musicbrainz_compilation = window.GetProperty("musicbrainz_compilation", true);
3745
				break;
3746
			case p.check_feature("echonest"):
3747
				this.mode = "echonest";
3748
				this.echonest_modes = ["news", "reviews", "blogs"];
3749
				this.echonest_mode = window.GetProperty("echonest_mode", 0);
3750
				break;
3751
			case p.check_feature("autoplaylists"):
3752
				this.autoplaylists_add = function() {
3753
					if (this.autoplaylists_editing) return;
3754
					this.autoplaylists_editing = true;
3755
					var new_name = p.InputBox("Enter a name for your autoplaylist", p.name, "");
3756
					if (new_name == "") { this.autoplaylists_editing = false; return; }
3757
					var new_query = p.InputBox("Enter your autoplaylist query", p.name, "");
3758
					if (new_query == "") { this.autoplaylists_editing = false; return; }
3759
					var new_sort = p.InputBox("Enter a sort pattern\n\n(optional)", p.name, "");
3760
					var new_force = new_sort.length > 0 ? p.MsgBox("Force sort?", 4, p.name) : 7;
3761
					this.data.push(new_name + "¬" + new_query + "¬" + new_sort + "¬" + new_force);
3762
					if (this.data.length > this.rows) this.offset = this.data.length - this.rows;
3763
					p.save(this.data.join("\n"), this.filename);
3764
					if (this.autoplaylists_success) this.autoplaylists_run(new_name, new_query, new_sort, new_force);
3765
					window.NotifyOthers("autoplaylists", "update");
3766
					this.update();
3767
					this.autoplaylists_editing = false;
3768
				}
3769
				
3770
				this.autoplaylists_run = function(n, q, s, f) {
3771
					if (this.autoplaylists_remove_duplicates) {
3772
						i = 0;
3773
						while(i < fb.PlaylistCount) {
3774
							if (fb.GetPlaylistName(i) == n) fb.RemovePlaylist(i);
3775
							else i++;
3776
						}
3777
					}
3778
					fb.CreateAutoPlaylist(fb.PlaylistCount, n, q, s, f == 6 ? true : false);
3779
					fb.ActivePlaylist = fb.PlaylistCount - 1;
3780
				}
3781
				
3782
				this.autoplaylists_edit = function(x, y) {
3783
					var _menu = window.CreatePopupMenu();
3784
					var i = this.index;
3785
					_menu.AppendMenuItem(MF_STRING, 1, "Rename...");
3786
					_menu.AppendMenuItem(MF_STRING, 2, "Edit query...");
3787
					_menu.AppendMenuItem(MF_STRING, 3, "Edit sort pattern...");
3788
					_menu.AppendMenuItem(MF_STRING, 4, "Force Sort");
3789
					_menu.CheckMenuItem(4, this.forced[i] == 6 ? true : false);
3790
					this.autoplaylists_editing = true;
3791
					this.autoplaylists_hover = false;
3792
					window.RepaintRect(this.x + this.w - 40, this.y + 15, 40, Math.min(this.rows, this.items) * this.row_height);
3793
					idx = _menu.TrackPopupMenu(x, y);
3794
					switch(idx) {
3795
						case 0:
3796
							this.autoplaylists_editing = false;
3797
							_menu.Dispose();
3798
							return;
3799
						case 1:
3800
							var new_name = p.InputBox("Rename your autoplaylist", p.name, this.names[i]);
3801
							if (new_name != "") this.names[i] = new_name;
3802
							break;
3803
						case 2:
3804
							var new_query = p.InputBox("Enter your autoplaylist query", p.name, this.queries[i]);
3805
							if (new_query != "") this.queries[i] = new_query;
3806
							break;
3807
						case 3:
3808
							var new_sort = p.InputBox("Enter a sort pattern\n\n(optional)", p.name, this.sorts[i]);
3809
							this.sorts[i] = new_sort;
3810
							this.forced[i] = new_sort.length > 0 ? p.MsgBox("Force sort?", 4, p.name) : 7;
3811
							break;
3812
						case 4:
3813
							this.forced[i] = this.forced[i] == 6 ? 7 : 6;
3814
							break;
3815
					}
3816
					_menu.Dispose();
3817
					var temp = this.names[i] + "¬" + this.queries[i] + "¬" + this.sorts[i] + "¬" + this.forced[i];
3818
					if (this.data[i] != temp) {
3819
						this.data[i] = temp;
3820
						p.save(this.data.join("\n"), this.filename);
3821
						if (this.autoplaylists_success) this.autoplaylists_run(this.names[i], this.queries[i], this.sorts[i], this.forced[i]);
3822
						window.NotifyOthers("autoplaylists", "update");
3823
						this.update();
3824
					}
3825
					this.autoplaylists_editing = false;
3826
				}
3827
				
3828
				this.autoplaylists_delete = function() {
3829
					if (this.offset > 1) this.offset--;
3830
					this.autoplaylists_deleted_items.unshift(this.data[this.index]);
3831
					this.data.splice(this.index, 1);
3832
					p.save(this.data.join("\n"), this.filename);
3833
					window.NotifyOthers("autoplaylists", "update");
3834
					this.update();
3835
				}
3836
				
3837
				this.mode = "autoplaylists";
3838
				this.autoplaylists_del_img = gdi.Image(p.images_path + "cross.png");
3839
				this.autoplaylists_edit_img = gdi.Image(p.images_path + "edit.png");
3840
				this.autoplaylists_hover = false;
3841
				this.autoplaylists_editing = false;
3842
				this.autoplaylists_remove_duplicates = window.GetProperty("autoplaylists_remove_duplicates", true);
3843
				this.autoplaylists_success = window.GetProperty("autoplaylists_success", true);
3844
				this.autoplaylists_title = window.GetProperty("autoplaylists_title", "Autoplaylists");
3845
				this.autoplaylists_slot = window.GetProperty("autoplaylists_slot", 1);
3846
				this.filename = p.settings_folder + "autoplaylists" + this.autoplaylists_slot;
3847
				this.autoplaylists_deleted_items = [];
3848
				break;
3849
		}
3850
	}
3851
	
3852
	this.x = x;
3853
	this.y = y;
3854
	this.w = w;
3855
	this.h = h;
3856
	this.index = 0;
3857
	this.offset = 0;
3858
	this.items = 0;
3859
	this.text = "";
3860
	this.artist = "";
3861
	this.url = "";
3862
	this.text_x = 0;
3863
	this.show_timestamp = window.GetProperty("show_timestamp", true);
3864
	this.autoplaylist_img = gdi.Image(p.images_path + "search_small.png");
3865
	this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
3866
	this.init();
3867
}
3868
3869
function playcount_sync(x, y) {
3870
	this.playback_time = function() {
3871
		this.time_elapsed++;
3872
		if (this.time_elapsed == 3 && this.auto_love && fb.TitleFormat(this.auto_love_tf).Eval() == 1 && this.old_userloved == 0) {
3873
			p.console("Automatically loving this track....");
3874
			this.love_track();
3875
		}
3876
		if (this.time_elapsed == this.target_time) {
3877
			if (!this.library || fb.IsMetadbInMediaLibrary(p.metadb)) this.sync_track();
3878
			else p.console("Skipping... Track not in library.");
3879
		}
3880
	}
3881
	
3882
	this.metadb_changed = function() {
3883
		if (!p.metadb) return false;
3884
		this.artist = fb.TitleFormat(p.artist_tf).EvalWithMetadb(p.metadb);
3885
		this.track = fb.TitleFormat("%title%").EvalWithMetadb(p.metadb);
3886
		this.old_userloved = fb.TitleFormat("%LASTFM_LOVED_DB%").EvalWithMetadb(p.metadb) == 1 ? 1 : 0;
3887
		this.old_userplaycount = fb.TitleFormat("%LASTFM_PLAYCOUNT_DB%").EvalWithMetadb(p.metadb);
3888
		this.method = this.old_userloved == 1 ? "track.unlove" : "track.love";
3889
		this.tooltip = (this.old_userloved == 1 ? "Unlove" : "Love") + " \"" + this.track + "\" by \"" + this.artist + "\".";
3890
		this.crc32 = fb.TitleFormat("$crc32($lower(%artist%%title%))").EvalWithMetadb(p.metadb);
3891
		b.update();
3892
		return true;
3893
	}
3894
	
3895
	this.playback_new_track = function() {
3896
		this.auto_love_count = 0;
3897
		this.time_elapsed = 0;
3898
		switch(true) {
3899
			case fb.PlaybackLength == 0:
3900
				this.target_time = 240;
3901
				break;
3902
			case fb.PlaybackLength >= 30:
3903
				this.target_time = Math.min(Math.floor(fb.PlaybackLength / 2), 240);
3904
				break;
3905
			default:
3906
				this.target_time = 5;
3907
				break;
3908
		}
3909
		on_item_focus_change();
3910
	}
3911
	
3912
	this.playback_edited = function() {
3913
		if (this.auto_love && fb.TitleFormat(this.auto_love_tf).Eval() == 1 && this.old_userloved == 0 && this.auto_love_count == 0) {
3914
			this.auto_love_count = 1;
3915
			p.console("Automatically loving this track....");
3916
			this.love_track();
3917
		}
3918
	}
3919
	
3920
	this.tf = function(value) {
3921
		return(value.replace(/'/g, "''").replace(/,/g, "','").replace(/\//g, "'/'").replace(/\(/g, "'('").replace(/\)/g, "')'").replace(/\[/g, "'['").replace(/\]/g, "']'"));
3922
	}
3923
	
3924
	this.love_track = function() {
3925
		l.post(this.method, p.metadb);
3926
	}
3927
	
3928
	this.sync_track = function() {
3929
		switch(true) {
3930
			case this.loved_working || this.playcount_working:
3931
				return;
3932
			case !utils.CheckComponent("foo_customdb", true):
3933
				p.console("Not contacting Last.fm. foo_customdb is missing.");
3934
				return;
3935
			default:
3936
				p.console("Contacting Last.fm....");
3937
				this.get(l.get_url() + "&method=track.getinfo&artist=" + encodeURIComponent(this.artist) + "&track=" + encodeURIComponent(this.track) + "&autocorrect=" + (l.auto_correct ? 1 : 0), function() {
3938
					ps.update_track();
3939
				});
3940
		}
3941
	}
3942
	
3943
	this.get = function(url, func) {
3944
		if (l.username.length == 0) {
3945
			this.loved_working = false;
3946
			this.playcount_working = false;
3947
			p.console(l.username_error);
3948
			return;
3949
		}
3950
		this.xmlhttp.open("GET", url, true);
3951
		this.xmlhttp.setRequestHeader('User-Agent', l.user_agent);
3952
		this.xmlhttp.send();
3953
		this.xmlhttp.onreadystatechange = function() {
3954
			if (ps.xmlhttp.readyState == 4) {
3955
				if (ps.xmlhttp.status == 200) {
3956
					func();
3957
				} else {
3958
					p.console(ps.xmlhttp.responsetext || "HTTP error: " + ps.xmlhttp.status);
3959
				}
3960
			}
3961
		}
3962
	}
3963
	
3964
	this.update_track = function() {
3965
		this.json_data = p.json_parse(ps.xmlhttp.responsetext);
3966
		if (!this.json_data || this.json_data.error > 0 || !this.json_data.track) {
3967
			p.console(ps.xmlhttp.responsetext);
3968
			return;
3969
		}
3970
		this.userplaycount = this.json_data.track.userplaycount > 0 ? ++this.json_data.track.userplaycount : 1;
3971
		this.userloved = this.json_data.track.userloved == 1 ? 1 : 0;
3972
		if (fb.IsPlaying && this.time_elapsed >= this.target_time && fb.PlaybackLength > 29 && fb.PlaybackLength < 10800) {
3973
			switch(true) {
3974
				case this.userplaycount < this.old_userplaycount:
3975
					p.console("Playcount returned from Last.fm is lower than current value. Not updating.");
3976
					break;
3977
				case this.old_userplaycount == this.userplaycount:
3978
					p.console("No changes found. Not updating.");
3979
					break;
3980
				default:
3981
					p.console("Last.fm responded ok. Attempting to update playcount...");
3982
					fb.RunContextCommandWithMetadb("Customdb Delete Playcount", p.metadb, 8);
3983
					if (this.old_userloved == 1) fb.RunContextCommandWithMetadb("Customdb Love 0", p.metadb, 8);
3984
					var attempt = 0;
3985
					while(fb.TitleFormat("%LASTFM_PLAYCOUNT_DB%").EvalWithMetadb(p.metadb) != this.userplaycount && attempt <= 3) {
3986
						var query1 = '\"INSERT INTO quicktag(url,subsong,fieldname,value) VALUES(\\"' + this.crc32 + '\\",\\"-1\\",\\"LASTFM_PLAYCOUNT_DB\\",\\"' + this.userplaycount + '\\")\";';
3987
						p.WshShell.Run(p.fso.GetFile(p.script_path + "sqlite3.exe").ShortPath + " " + p.fso.GetFile(fb.ProfilePath + "customdb_sqlite.db").ShortPath + " " + query1, 0, true);
3988
						attempt++;
3989
					}
3990
					fb.RunContextCommandWithMetadb("Customdb Refresh", p.metadb, 8);
3991
					if (fb.TitleFormat("%LASTFM_PLAYCOUNT_DB%").EvalWithMetadb(p.metadb) == this.userplaycount) p.console("Playcount updated successfully.");
3992
					else p.console("Database error. Playcount not updated.");
3993
					break;
3994
			}
3995
		}
3996
		if (this.old_userloved != this.userloved) fb.RunContextCommandWithMetadb("Customdb Love " + this.userloved, p.metadb, 8);
3997
	}
3998
	
3999
	this.start_import = function() {
4000
		if (this.show_console) fb.ShowConsole();
4001
		this.loved_page_errors = 0;
4002
		this.playcount_page_errors = 0;
4003
		ps.pages = 0;
4004
		this.r = 1;
4005
		this.sql = "BEGIN TRANSACTION;\n";
4006
		this.loved_working = true;
4007
		this.sync_loved(1);
4008
	}
4009
	
4010
	this.sync_loved = function(page) {
4011
		if (!this.loved_working) return(p.console("Import aborted."));
4012
		this.page = page;
4013
		this.get(l.get_url() + "&method=user.getlovedtracks&limit=200&page=" + this.page, function() {
4014
			ps.update_loved();
4015
		});
4016
	}
4017
	
4018
	this.update_loved = function() {
4019
		this.json_data = p.json_parse(ps.xmlhttp.responsetext);
4020
		if (this.json_data && this.json_data.error > 0) {
4021
			this.loved_working = false;
4022
			p.MsgBox("There is a problem with the Last.fm web services. Please try again later.\n\n" + ps.xmlhttp.responsetext, 0, p.name);
4023
			return;
4024
		}
4025
		if (this.json_data && this.json_data.lovedtracks && this.json_data.lovedtracks.track) {
4026
			if (this.page == 1) this.pages = this.json_data.lovedtracks["@attr"].totalPages;
4027
			for (i = 0; i < this.json_data.lovedtracks.track.length; i++) {
4028
				var data = [];
4029
				data[0] = this.json_data.lovedtracks.track[i].artist.name;
4030
				data[1] = this.json_data.lovedtracks.track[i].name;
4031
				data[2] = 1;
4032
				if (data.length == 3) {
4033
					p.console(this.r + ": " + data[0] + " - " + data[1]);
4034
					var url = fb.TitleFormat("$crc32($lower(" + this.tf(data[0]) + this.tf(data[1]) + "))").Eval(true);
4035
					this.sql += 'INSERT OR REPLACE INTO quicktag(url,subsong,fieldname,value) VALUES("' + url + '","-1","LASTFM_LOVED_DB","' + data[2] + '");' + "\n";
4036
					this.r++;
4037
				}
4038
			}
4039
			p.console("Loved tracks: completed page " + this.page + " of " + this.pages);
4040
		} else if (this.pages > 0) {
4041
			this.loved_page_errors++;
4042
		}
4043
		if (this.page < this.pages) {
4044
			this.page++;
4045
			this.sync_loved(this.page);
4046
		} else {
4047
			this.loved_working = false;
4048
			if (this.full_import) {
4049
				this.playcount_working = true;
4050
				this.pages = 0;
4051
				this.r = 1;
4052
				this.sync_playcount(1);
4053
			} else {
4054
				try {
4055
					this.sql += "COMMIT;"
4056
					var ts = p.fso.OpenTextFile(this.sql_file, 2, true, 0);
4057
					ts.WriteLine(this.sql);
4058
					ts.Close();
4059
					this.finish_import();
4060
				} catch(e) {
4061
				}
4062
				if (this.loved_page_errors > 0) {
4063
					p.console("Loved track page errors: " + this.loved_page_errors + " (200 records are lost for every page that fails.)");
4064
				} else {
4065
					p.console("There were no errors reported.");
4066
				}
4067
			}
4068
		}
4069
	}
4070
	
4071
	this.sync_playcount = function(page) {
4072
		if (this.playcount_working == false) return(p.console("Import aborted."));
4073
		this.page = page;
4074
		this.get(l.get_url() + "&method=library.gettracks&limit=100&page=" + this.page, function() {
4075
			ps.update_playcount();
4076
		});
4077
	}
4078
	
4079
	this.update_playcount = function() {
4080
		this.json_data = p.json_parse(ps.xmlhttp.responsetext);
4081
		if (this.json_data && this.json_data.error > 0) {
4082
			this.playcount_working = false;
4083
			p.MsgBox("There is a problem with the Last.fm web services. Please try again later.\n\n" + ps.xmlhttp.responsetext, 0, p.name);
4084
			return;
4085
		}
4086
		if (this.json_data && this.json_data.tracks && this.json_data.tracks.track) {
4087
			if (this.page == 1) this.pages = this.json_data.tracks["@attr"].totalPages
4088
			for (i = 0; i < this.json_data.tracks.track.length; i++) {
4089
				var data = [];
4090
				data[0] = this.json_data.tracks.track[i].artist.name;
4091
				data[1] = this.json_data.tracks.track[i].name;
4092
				data[2] = this.json_data.tracks.track[i].playcount;
4093
				if (data[2] == 0) {
4094
					this.page = this.pages;
4095
					break;
4096
				}
4097
				if (data.length == 3) {
4098
					p.console(this.r + ": " + data[0] + " - " + data[1] + " " + data[2]);
4099
					var url = fb.TitleFormat("$crc32($lower(" + this.tf(data[0]) + this.tf(data[1]) + "))").Eval(true);
4100
					this.sql += 'INSERT OR REPLACE INTO quicktag(url,subsong,fieldname,value) VALUES("' + url + '","-1","LASTFM_PLAYCOUNT_DB","' + data[2] + '");' + "\n";
4101
					this.r++;
4102
				}
4103
			}
4104
			p.console("Playcount: completed page " + this.page + " of " + this.pages);
4105
		} else if (this.pages > 0) {
4106
			this.playcount_page_errors++;
4107
		}
4108
		if (this.page < this.pages) {
4109
			this.page++;
4110
			this.sync_playcount(this.page);
4111
		} else {
4112
			try {
4113
				this.sql += "COMMIT;"
4114
				var ts = p.fso.OpenTextFile(this.sql_file, 2, true, 0);
4115
				ts.WriteLine(this.sql);
4116
				ts.Close();
4117
				this.finish_import();
4118
			} catch(e) {
4119
			}
4120
			this.playcount_working = false;
4121
			if (this.loved_page_errors + this.playcount_page_errors > 0) {
4122
				p.console("Loved track page errors: " + this.loved_page_errors + " (200 records are lost for every page that fails.)");
4123
				p.console("Playcount page errors: " + this.playcount_page_errors + " (100 records are lost for every page that fails.)");
4124
			} else {
4125
				p.console("There were no errors reported.");
4126
			}
4127
		}
4128
	}
4129
	
4130
	this.finish_import = function() {
4131
		try {
4132
			var cmd_file = p.fso.GetFile(p.script_path + "lastfm_sql.cmd").ShortPath;
4133
			var db_file = p.fso.GetFile(fb.ProfilePath + "customdb_sqlite.db").ShortPath;
4134
			p.run(cmd_file + " " + p.fso.GetFile(p.script_path + "sqlite3.exe").ShortPath + " " + db_file + " " + p.fso.GetFile(this.sql_file).ShortPath);
4135
		} catch(e) {
4136
		}
4137
	}
4138
	
4139
	this.update_button = function() {
4140
		var exclamation = this.icon == "tango" ? "exclamation.png" : "exclamation_small.png";
4141
		var love = this.icon == "tango" ? "love.png" : "love_small.png";
4142
		var love_h = this.icon == "tango" ? "love_h.png" : "love_h_small.png";
4143
		this.size = this.icon == "tango" ? 32 : 20;
4144
		switch(true) {
4145
			case l.username.length == 0:
4146
				this.n = exclamation;
4147
				this.h = exclamation;
4148
				this.tooltip = l.username_error;
4149
				this.func = null;
4150
				break;
4151
			case l.sk.length != 32:
4152
				this.n = exclamation;
4153
				this.h = exclamation;
4154
				this.tooltip = l.password_error;
4155
				this.func = null;
4156
				break;
4157
			case !p.metadb:
4158
				this.n = exclamation;
4159
				this.h = exclamation;
4160
				this.tooltip = "No selection";
4161
				this.func = null;
4162
				break;
4163
			case !utils.CheckComponent("foo_customdb", true):
4164
				this.n = exclamation;
4165
				this.h = exclamation;
4166
				this.tooltip = "The foo_customdb component is not installed. Please refer to the readme.";
4167
				this.func = null;
4168
				break;
4169
			default:
4170
				this.n = this.old_userloved == 1 ? love_h : love;
4171
				this.h = this.old_userloved == 1 ? love : love_h;
4172
				this.func = function() { ps.love_track(); }
4173
				break;
4174
		}
4175
	}
4176
	
4177
	this.x = x;
4178
	this.y = y;
4179
	this.loved_working = false;
4180
	this.playcount_working = false;
4181
	this.sql_file = p.data_folder + "lastfm.sql";
4182
	this.page = 0;
4183
	this.last_page = 0;
4184
	this.auto_love = window.GetProperty("playcount_sync_auto_love", false);
4185
	this.auto_love_tf = window.GetProperty("playcount_sync_auto_love_tf", "");
4186
	this.icon = window.GetProperty("playcount_sync_icon", "tango");
4187
	this.show_console = window.GetProperty("playcount_sync_show_console", true);
4188
	this.library = window.GetProperty("playcount_sync_library", false);
4189
	this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
4190
	window.SetInterval(function() {
4191
		var temp = ps.page > 1 ? ps.page - 1 : 1;
4192
		if (ps.loved_working && ps.page == ps.last_page) {
4193
			ps.xmlhttp.abort();
4194
			ps.sync_loved(temp);
4195
		} else if (ps.playcount_working && ps.page == ps.last_page) {
4196
			ps.xmlhttp.abort();
4197
			ps.sync_playcount(temp);
4198
		} else {
4199
			ps.last_page = ps.page;
4200
		}
4201
	}, 15000);
4202
}
4203
4204
function rating(x, y, bs) {
4205
	this.draw = function(gr) {
4206
		if (!p.metadb) return;
4207
		for (i = 1; i < 6; i++) {
4208
			this.img = i > (this.hover ? this.lrating : this.rating) ? this.off_img : this.on_img;
4209
			p.draw_image(gr, this.img, this.x + this.bs * (i - 1), this.y, this.bs, this.bs, "adjust");
4210
		}
4211
	}
4212
	
4213
	this.metadb_changed = function() {
4214
		if (!p.metadb) return false;
4215
		this.hover = false;
4216
		this.rating = p.eval("$if2(%rating%,0)");
4217
		this.tiptext = p.eval(this.tiptext_tf);
4218
		this.lrating = this.rating;
4219
		window.RepaintRect(this.x, this.y, this.w, this.bs);
4220
		return true;
4221
	}
4222
	
4223
	this.trace = function(x, y) {
4224
		return x > this.x - this.bs && x < this.x + (this.bs * 5) && y > this.y && y < this.y + this.bs;
4225
	}
4226
	
4227
	this.move = function(x, y) {
4228
		if (!this.trace(x, y)) {
4229
			if (this.hover) this.leave();
4230
			return false;
4231
		}
4232
		if (p.metadb) {
4233
			if (x > this.x) p.tt(this.tiptext);
4234
			this.hover = true;
4235
			this.lrating = Math.ceil((x - this.x) / this.bs);
4236
			window.RepaintRect(this.x, this.y, this.w, this.bs);
4237
		}
4238
		return true;
4239
	}
4240
	
4241
	this.lbtn_up = function(x, y) {
4242
		if (!this.trace(x, y)) return false;
4243
		if (this.check) {
4244
			if (this.lrating != this.rating && this.hover == 1) fb.RunContextCommandWithMetadb("Rating/" + (this.lrating == 0 ? "<not set>" : this.lrating), p.metadb, 8);
4245
		} else {
4246
			p.MsgBox(this.error_text, 0, p.name);
4247
			p.browser("http://www.foobar2000.org/components/view/foo_playcount");
4248
		}
4249
		return true;
4250
	}
4251
	
4252
	this.leave = function() {
4253
		p.ttd();
4254
		this.hover = false;
4255
		window.RepaintRect(this.x, this.y, this.w, this.bs);
4256
	}
4257
	
4258
	this.x = x;
4259
	this.y = y;
4260
	this.bs = bs;
4261
	this.w = this.bs * 5;
4262
	this.hover = false;
4263
	this.rating = null;
4264
	this.lrating = null;
4265
	this.img = null;
4266
	this.off_img = gdi.Image(p.images_path + "off.png");
4267
	this.on_img = gdi.Image(p.images_path + "on.png");
4268
	this.check = utils.CheckComponent("foo_playcount", true);
4269
	this.error_text = "This script requires foo_playcount.";
4270
	this.tiptext_tf = this.check ? 'Rate "%title%" by "%artist%"' : this.error_text;
4271
}
4272
4273
function sb(x, y, w, h, img, isVisible, func) {
4274
	this.x = x;
4275
	this.y = y;
4276
	this.w = w;
4277
	this.h = h;
4278
	this.img = img;
4279
	this.isVisible = new Function("return (" + isVisible + ");");
4280
	this.func = func;
4281
	
4282
	this.draw = function(gr) {
4283
		if (this.isVisible()) p.draw_image(gr, this.img, this.x, this.y, this.w, this.h, "adjust");
4284
	}
4285
	
4286
	this.trace = function(x, y) {
4287
		return(x > this.x && x < this.x + this.w && y > this.y && y < this.y + this.h && this.isVisible());
4288
	}
4289
	
4290
	this.lbtn_up = function(x, y) {
4291
		if (!this.trace(x, y)) return false;
4292
		this.func && this.func(x, y);
4293
		return true;
4294
	}
4295
}
4296
4297
function seekbar(x, y, w, h) {
4298
	this.trace = function(x, y) {
4299
		return (x > this.x && x < this.x + this.w && y > this.y - (this.drag ? 200 : 0) && y < this.y + this.h + (this.drag ? 200 : 0));
4300
	}
4301
	
4302
	this.draw = function(gr) {
4303
		p.draw_background(gr);
4304
		switch(this.mode) {
4305
			case "spectrogram":
4306
				if (this.working) {
4307
					p.draw_image(gr, this.hourglass_img, this.x, this.y + Math.round((this.h - 32) / 2), this.w, 32, "adjust");
4308
				} else {
4309
					p.draw_image(gr, this.img, this.x, this.y, this.w, this.h, "stretch");
4310
				}
4311
				if (fb.IsPlaying && fb.PlaybackLength > 0) {
4312
					this.calc_pos();
4313
					gr.FillSolidRect(this.x + this.pos - 2, this.y, 2, this.h, p.splitRGB(this.marker));
4314
				}
4315
				break;
4316
			case "nyan_cat":
4317
				if (fb.IsPlaying && fb.PlaybackLength > 0) {
4318
					this.calc_pos();
4319
					for (i = 0; i < this.offsets.length; i++) {
4320
						gr.FillSolidRect(this.x - 48, this.y + this.offsets[i], this.pos + 2, this.heights[i], this.colours[i]);
4321
					}
4322
					p.draw_image(gr, this.cat_img[this.z], this.pos, this.y, 48, 30);
4323
				} else {
4324
					p.draw_image(gr, this.cat_img[0], 0, this.y, 48, 30);
4325
				}
4326
				break;
4327
		}
4328
	}
4329
	
4330
	this.playback_new_track = function() {
4331
		if (this.mode != "spectrogram") return;
4332
		var metadb = fb.GetNowPlaying();
4333
		this.img && this.img.Dispose();
4334
		this.img = null;
4335
		try {
4336
			this.png_filename = spectrogram_cache + "\\" + fb.TitleFormat("$crc32(%path%)").EvalWithMetadb(metadb) + this.sox_params + ".png";
4337
			switch(true) {
4338
				case !metadb:
4339
				case metadb.RawPath.indexOf("file") != 0:
4340
					p.console("Skipping... Not a valid file type.");
4341
					break;
4342
				case fb.PlaybackLength == 0:
4343
					p.console("Skipping... Unknown length.");
4344
					break;
4345
				case fb.TitleFormat("$if($or($strcmp(%__cue_embedded%,yes),$strcmp($right(%path%,3),cue)),cue,)").EvalWithMetadb(metadb) == "cue":
4346
					p.console("Skipping... Cannot support cuesheets.");
4347
					break;
4348
				case fb.TitleFormat("%subsong%").EvalWithMetadb(metadb) > 0:
4349
					p.console("Skipping... Cannot support tracks with chapters.");
4350
					break;
4351
				case this.library && !fb.IsMetadbInMediaLibrary(metadb):
4352
					p.console("Skipping... Track not in library.");
4353
					break;
4354
				case p.fso.FileExists(this.png_filename):
4355
					this.img = gdi.Image(this.png_filename);
4356
					break;
4357
				default:
4358
					this.working = true
4359
					window.Repaint();
4360
					var filename = metadb.Path;
4361
					var length = fb.TitleFormat("%length%").EvalWithMetadb(metadb);
4362
					var cmd = "cmd /c \"\"" + ffmpeg_exe + "\" -i \"" + filename + "\" -t " + length + " -f sox - | \"" + sox_exe + "\" -p -n " + this.sox_params + " -d " + length + " -r -o \"" + this.png_filename + "\"\"";
4363
					//p.console(cmd);
4364
					try { p.WshShell.Run(cmd, 0, true); } catch(e) {}
4365
					this.working = false;
4366
					this.img = gdi.Image(this.png_filename);
4367
					break;
4368
			}
4369
		} catch(e) {
4370
			//p.console(e);
4371
		}
4372
		window.Repaint();
4373
	}
4374
	
4375
	this.playback_stop = function() {
4376
		window.Repaint();
4377
	}
4378
	
4379
	this.playback_seek = function() {
4380
		this.update();
4381
	}
4382
	
4383
	this.move = function(x, y) {
4384
		if (this.drag) this.update();
4385
		if (this.trace(x, y)) {
4386
			if (fb.IsPlaying && fb.PlaybackLength > 0) {
4387
				x -= this.x;
4388
				this.drag_seek = x < 0 ? 0 : x > this.w ? 1 : x / this.w;
4389
				if (x != this.old_x || y != this.old_y) {
4390
					p.tt(p.format_time(fb.PlaybackLength * this.drag_seek));
4391
					this.old_x = x;
4392
					this.old_y = y;
4393
				}
4394
			}
4395
			return true;
4396
		} else {
4397
			this.leave();
4398
			return false;
4399
		}
4400
	}
4401
	
4402
	this.lbtn_down = function(x, y) {
4403
		if (!this.trace(x, y)) return false;
4404
		if (fb.IsPlaying && fb.PlaybackLength > 0) this.drag = true;
4405
		return true;
4406
	}
4407
	
4408
	this.lbtn_up = function(x, y) {
4409
		if (!this.trace(x, y)) return false;
4410
		if (this.drag) {
4411
			this.drag = false;
4412
			fb.PlaybackTime = fb.PlaybackLength * this.drag_seek;
4413
		}
4414
		return true;
4415
	}
4416
	
4417
	this.leave = function() {
4418
		this.drag = false;
4419
		p.ttd();
4420
	}
4421
	
4422
	this.update = function() {
4423
		window.RepaintRect(0, this.y, p.w, this.h);
4424
	}
4425
	
4426
	this.calc_pos = function() {
4427
		this.pos = this.drag ? this.w * this.drag_seek : this.w * (fb.PlaybackTime / fb.PlaybackLength);
4428
	}
4429
	
4430
	this.init = function() {
4431
		switch(true) {
4432
			case p.check_feature("spectrogram"):
4433
				this.clear_images = function(period) {
4434
					var now = Date.parse(Date());
4435
					images = utils.Glob(spectrogram_cache + "\\*.*").toArray();
4436
					for (i = 0; i < images.length; i++) {
4437
						if (this.png_filename == images[i]) continue;
4438
						var file = p.fso.Getfile(images[i]);
4439
						var file_date = Date.parse(file.DateLastModified);
4440
						if (now - file_date > period) {
4441
							try {
4442
								p.fso.DeleteFile(images[i]);
4443
							} catch(e) {
4444
								p.console("Could not delete " + images[i]);
4445
							}
4446
						}
4447
					}
4448
				}
4449
				
4450
				this.mode = "spectrogram";
4451
				this.library = window.GetProperty("seekbar_library", false);
4452
				this.marker = window.GetProperty("seekbar_marker", "240-240-240");
4453
				this.sox_params = window.GetProperty("sox_params", "channels 1 spectrogram -Y 130").trim();
4454
				this.working = false;
4455
				this.img = false;
4456
				this.hourglass_img = gdi.Image(p.images_path + "hourglass.png");
4457
				//if (!p.fso.FolderExists(spectrogram_cache)) p.fso.CreateFolder(spectrogram_cache);
4458
				if (fb.IsPlaying) {
4459
					window.SetTimeout(function() {
4460
						s.playback_new_track();
4461
					}, 100);
4462
				}
4463
				break;
4464
			case p.check_feature("nyan_cat"):
4465
				this.mode = "nyan_cat";
4466
				this.cat_img = [gdi.Image(p.images_path + "\\seekbar cat.png"), gdi.Image(p.images_path + "\\seekbar cat 2.png")];
4467
				this.offsets = [2, 6, 10, 15, 20, 24];
4468
				this.heights = [4, 4, 5, 5, 4, 4];
4469
				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)];
4470
				break;
4471
		}
4472
	}
4473
	
4474
	this.x = x;
4475
	this.y = y;
4476
	this.w = w;
4477
	this.h = h;
4478
	this.z = 0;
4479
	this.pos = 0;
4480
	this.drag = false;
4481
	this.drag_seek = 0;
4482
	this.old_x = 0;
4483
	this.old_y = 0;
4484
	this.init();
4485
	this.seekbar_timer = window.SetInterval(function() {
4486
		s.z = s.z == 0 ? 1 : 0;
4487
		if (!fb.IsPlaying || fb.IsPaused || fb.PlaybackLength == 0) return;
4488
		s.update();
4489
	}, 150);
4490
}
4491
4492
function text(x, y, w, h) {
4493
	this.size = function() {
4494
		this.rows = Math.floor((this.h - 36) / p.row_height);
4495
		this.but_x = this.x + Math.round((this.w - 15) / 2);
4496
		this.up_btn = new sb(this.but_x, this.y, 15, 15, p.up_img, "t.offset > 0", function() { t.wheel(1); });
4497
		this.down_btn = new sb(this.but_x, this.y + this.h - 15, 15, 15, p.down_img, "t.offset < t.text_rows - t.rows", function() { t.wheel(-1); });
4498
		this.calc();
4499
	}
4500
	
4501
	this.draw = function(gr, colour) {
4502
		for (i = 0; i < Math.min(this.rows, this.text_rows); i++) {
4503
			if (this.centre) p.centre_text(gr, this.text_array[i + this.offset], this.fixed ? p.fixed_font : p.normal_font, colour || p.textcolour, this.x, 18 + this.y + (i * p.row_height), this.w, p.row_height);
4504
			else p.left_text(gr, this.text_array[i + this.offset], this.fixed ? p.fixed_font : p.normal_font, colour || p.textcolour, this.x, 18 + this.y + (i * p.row_height), this.w, p.row_height);
4505
		}
4506
		this.up_btn.draw(gr);
4507
		this.down_btn.draw(gr);
4508
	}
4509
	
4510
	this.metadb_changed = function() {
4511
		if (!p.metadb) return false;
4512
		switch(this.mode) {
4513
			case "simple_tag":
4514
				this.temp_filename = p.metadb.Path;
4515
				if (this.filename == this.temp_filename) return false;
4516
				this.filename = this.temp_filename;
4517
				this.text = p.eval(this.tag);
4518
				break;
4519
			case "simple_text":
4520
				this.temp_filename = p.eval(this.filename_tf);
4521
				if (this.filename == this.temp_filename) return false;
4522
				this.text = "";
4523
				this.filename = this.temp_filename;
4524
				if (p.fso.FolderExists(this.filename)) {
4525
					this.files = [];
4526
					this.files = this.files.concat(utils.Glob(this.filename + "\\*.txt").toArray(), utils.Glob(this.filename + "\\*.log").toArray());
4527
					this.files.sort();
4528
					this.text = p.open(this.files[0]);
4529
				} else {
4530
					this.filenames = this.filename.split("|");
4531
					for (i = 0; i < this.filenames.length; i++) {
4532
						if (p.fso.fileExists(this.filenames[i])) {
4533
							this.text = p.open(this.filenames[i]);
4534
							break;
4535
						}
4536
					}
4537
				}
4538
				this.text = this.text.replace(/\t/g, "    ");
4539
				break;
4540
			case "lastfm_wiki":
4541
				p.artist = p.eval(p.artist_tf);
4542
				if (this.artist == p.artist) return false;
4543
				this.artist = p.artist;
4544
				this.folder = p.data_folder + p.artist;
4545
				if (!p.fso.FolderExists(this.folder)) p.fso.CreateFolder(this.folder);
4546
				this.filename = this.folder + "\\artist.getInfo_mod.json";
4547
				this.text = "Nothing found.";
4548
				this.url = "http://www.last.fm/";
4549
				if (p.fso.fileExists(this.filename)) {
4550
					this.json_text = p.open(this.filename);
4551
					this.json_data = p.json_parse(this.json_text);
4552
					if (this.json_data && this.json_data.response && this.json_data.response.biographies) {
4553
						this.items = this.json_data.response.biographies.length;
4554
						for (i = 0; i < this.items; i++) {
4555
							if (this.json_data.response.biographies[i].site == this.source) {
4556
								this.text = this.json_data.response.biographies[i].text;
4557
								this.url = this.json_data.response.biographies[i].license["attribution-url"];
4558
								break;
4559
							}
4560
						}
4561
						if (this.source == "last.fm") this.text = this.text.replace(/\.  /g, ".\n\n");
4562
						if (this.source == "wikipedia") 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");
4563
					}
4564
				} else {
4565
					this.get();
4566
				}
4567
				break;
4568
			case "lastfm_album":
4569
				var temp_album = p.eval("[%album%]");
4570
				var temp_artist = p.eval("[%album artist%]");
4571
				if (this.album == temp_album && this.artist == temp_artist) return false;
4572
				this.artist = temp_artist;
4573
				this.album = temp_album;
4574
				this.folder = p.data_folder + p.eval("$crc32(%album artist%)");
4575
				if (!p.fso.FolderExists(this.folder)) p.fso.CreateFolder(this.folder);
4576
				this.filename = this.folder + "\\album.getInfo_" + p.eval("$crc32(%album%)") + ".json";
4577
				this.text = "Nothing found.";
4578
				this.url = l.url;
4579
				if (p.fso.fileExists(this.filename)) {
4580
					this.file = p.fso.GetFile(this.filename);
4581
					this.json_text = p.open(this.filename);
4582
					this.json_data = p.json_parse(this.json_text);
4583
					if (this.json_data && this.json_data.album) {
4584
						if (this.json_data.album.url) this.url = this.json_data.album.url;
4585
						if (this.json_data.album.wiki && this.json_data.album.wiki.content) {
4586
							this.text = p.strip_tags(this.json_data.album.wiki.content);
4587
							this.text = this.text.replace("User-contributed text is available under the Creative Commons By-SA License and may also be available under the GNU FDL.", "").trim();
4588
						}
4589
					}
4590
					if (Date.parse(Date()) - Date.parse(this.file.DateLastModified) > ONE_DAY) this.get();
4591
				} else {
4592
					this.get();
4593
				}
4594
				break;
4595
		}
4596
		this.calc();
4597
		window.Repaint();
4598
		return true;
4599
	}
4600
	
4601
	this.trace = function(x, y) {
4602
		return (x > this.x && x < this.x + this.w && y > this.y && y < this.y + this.h);
4603
	}
4604
	
4605
	this.wheel = function(step) {
4606
		if (!this.trace(p.mx, p.my)) return false;
4607
		if (this.text_rows > this.rows) {
4608
			this.offset -= step * 3;
4609
			if (this.offset < 0) this.offset = 0;
4610
			if (this.offset + this.rows > this.text_rows) this.offset = this.text_rows - this.rows;
4611
			window.RepaintRect(this.x, this.y, this.w, this.h);
4612
		}
4613
		return true;
4614
	}
4615
	
4616
	this.move = function(x, y) {
4617
		switch(true) {
4618
			case !this.trace(x, y):
4619
				window.SetCursor(IDC_ARROW);
4620
				return false;
4621
			case this.up_btn.trace(x, y):
4622
			case this.down_btn.trace(x, y):
4623
				window.SetCursor(IDC_HAND);
4624
				return true;
4625
			default:
4626
				window.SetCursor(IDC_ARROW);
4627
				return false;
4628
		}
4629
	}
4630
	
4631
	this.lbtn_up = function(x, y) {
4632
		if (!this.trace(x, y)) return false;
4633
		this.up_btn.lbtn_up(x, y);
4634
		this.down_btn.lbtn_up(x, y);
4635
		return true;
4636
	}
4637
	
4638
	this.get = function() {
4639
		var fn = this.filename;
4640
		var func = function() {
4641
			if (!p.save(t.xmlhttp.responsetext, fn)) return;
4642
			t.artist = "";
4643
			t.album = "";
4644
			on_item_focus_change();
4645
		}
4646
		var url = "";
4647
		var user_agent = "";
4648
		switch(this.mode) {
4649
			case "lastfm_album":
4650
				if (this.artist == "" || this.album == "") return;
4651
				url = l.get_url() + "&method=album.getInfo&artist=" + encodeURIComponent(this.artist) + "&album=" + encodeURIComponent(this.album);
4652
				user_agent = l.user_agent;
4653
				break;
4654
			case "lastfm_wiki":
4655
				if (this.artist == "" || this.artist == "?") return;
4656
				url = "http://developer.echonest.com/api/v4/artist/biographies?api_key=EKWS4ESQLKN3G2ZWV&format=json&name=" + encodeURIComponent(this.artist);
4657
				break;
4658
		}
4659
		if (url.length == 0) return;
4660
		this.xmlhttp.open("GET", url, true);
4661
		if (user_agent.length > 0) this.xmlhttp.setRequestHeader('User-Agent', user_agent);
4662
		this.xmlhttp.send();
4663
		this.xmlhttp.onreadystatechange = function() {
4664
			if (t.xmlhttp.readyState == 4) {
4665
				if (t.xmlhttp.status == 200) {
4666
					func();
4667
				} else {
4668
					p.console(t.xmlhttp.responsetext || "HTTP error: " + t.xmlhttp.status);
4669
				}
4670
			}
4671
		}
4672
	}
4673
	
4674
	this.calc = function() {
4675
		this.offset = 0;
4676
		this.text_rows = 0;
4677
		if (this.w < 100 || this.text.length == 0) return;
4678
		var temp_bmp = gdi.CreateImage(1, 1);
4679
		var temp_gr = temp_bmp.GetGraphics();
4680
		var paragraphs = this.text.split("\n");
4681
		this.text_array = [];
4682
		for (i = 0; i < paragraphs.length; i++) {
4683
			if (this.fixed) {
4684
				this.text_array.push(paragraphs[i]);
4685
			} else {
4686
				var lines = temp_gr.EstimateLineWrap(paragraphs[i], p.normal_font, this.w).toArray();
4687
				for (j = 0; j < lines.length; j += 2) {
4688
					this.text_array.push(lines[j].trim());
4689
				}
4690
			}
4691
		}
4692
		this.text_rows = this.text_array.length;
4693
		temp_bmp.ReleaseGraphics(temp_gr);
4694
		temp_bmp.Dispose();
4695
		temp_gr = null;
4696
		temp_bmp = null;
4697
	}
4698
	
4699
	this.init = function() {
4700
		switch(true) {
4701
			case p.check_feature("lastfm_album"):
4702
				this.mode = "lastfm_album";
4703
				break;
4704
			case p.check_feature("lastfm_wiki"):
4705
				this.mode = "lastfm_wiki";
4706
				this.source = window.GetProperty("biography_source", "last.fm");
4707
				break;
4708
			case p.check_feature("simple_text"):
4709
				this.mode = "simple_text";
4710
				this.title = window.GetProperty("text_title", "$directory_path(%path%)");
4711
				this.filename_tf = window.GetProperty("text_filename_tf", "$directory_path(%path%)");
4712
				this.filename = "";
4713
				this.fixed = window.GetProperty("text_fixed_font", true);
4714
				break;
4715
			case p.check_feature("simple_tag"):
4716
				this.mode = "simple_tag";
4717
				this.title = window.GetProperty("text_title", "%title%");
4718
				this.filename = "";
4719
				this.centre = window.GetProperty("text_centre", false);
4720
				this.tag = window.GetProperty("text_tag", "[%lyrics%]");
4721
				break;
4722
		}
4723
	}
4724
	
4725
	this.x = x;
4726
	this.y = y;
4727
	this.w = w;
4728
	this.h = h;
4729
	this.text = "";
4730
	this.artist = "";
4731
	this.album = "";
4732
	this.url = "";
4733
	this.fixed = false;
4734
	this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
4735
	this.init();
4736
	this.size();
4737
}
4738
4739
function thumbs() {
4740
	this.trace = function(x, y) {
4741
		return (x > this.x && x < this.x + this.w && y > this.y && y < this.y + this.h);
4742
	}
4743
	
4744
	this.draw = function(gr) {
4745
		switch(true) {
4746
			case im.images.length == 0:
4747
				break;
4748
			case this.mode == "off":
4749
				p.draw_image(gr, im.images[im.index], im.x, im.y, im.w, im.h, im.type);
4750
				break;
4751
			case !this.img:
4752
				break;
4753
			case this.mode == "grid":
4754
				gr.DrawImage(this.img, this.x, this.y, this.w, this.h, 0, this.offset * this.px, this.w, this.h);
4755
				if (this.overlay) {
4756
					gr.FillSolidRect(this.x, this.y, this.w, this.h, RGBA(0, 0, 0, 126));
4757
					p.draw_image(gr, im.images[im.index], im.x, im.y, im.w, im.h, "adjust");
4758
				}
4759
				break;
4760
			case this.mode == "left":
4761
			case this.mode == "right":
4762
				gr.DrawImage(this.img, this.x, this.y, this.w, this.h, 0, this.offset * this.px, this.w, this.h);
4763
				p.draw_image(gr, im.images[im.index], im.x, im.y, im.w, im.h, im.type);
4764
				break;
4765
			case this.mode == "bottom":
4766
			case this.mode == "top":
4767
				gr.DrawImage(this.img, this.x, this.y, this.w, this.h, this.offset * this.px, 0, this.w, this.h);
4768
				p.draw_image(gr, im.images[im.index], im.x, im.y, im.w, im.h, im.type);
4769
				break;
4770
		}
4771
	}
4772
	
4773
	this.calc = function() {
4774
		this.offset = 0;
4775
		switch(true) {
4776
			case p.w < this.px || p.h < this.px || this.mode == "off":
4777
				this.nc = true;
4778
				this.img && this.img.Dispose();
4779
				this.img = null;
4780
				im.x = 0;
4781
				im.y = 0;
4782
				im.w = p.w;
4783
				im.h = p.h;
4784
				break;
4785
			case this.mode == "grid":
4786
				this.x = 0;
4787
				this.y = 0;
4788
				this.w = p.w;
4789
				this.h = p.h;
4790
				im.x = 40;
4791
				im.y = 40;
4792
				im.w = this.w - 80;
4793
				im.h = this.h - 80;
4794
				if (!this.nc && this.columns != Math.floor(this.w / this.px)) this.nc = true;
4795
				this.overlay = false;
4796
				this.rows = Math.ceil(this.h / this.px);
4797
				this.columns = Math.floor(this.w / this.px);
4798
				this.img_rows = Math.ceil(im.images.length / this.columns);
4799
				if (this.nc && im.images.length > 0) {
4800
					this.nc = false;
4801
					this.img && this.img.Dispose();
4802
					this.img = null;
4803
					this.img = gdi.CreateImage(Math.min(this.columns, im.images.length) * this.px, this.img_rows * this.px);
4804
					var temp_gr = this.img.GetGraphics();
4805
					temp_gr.SetInterpolationMode(7);
4806
					var ci = 0;
4807
					var row, col;
4808
					for (row = 0; row < this.img_rows; row++) {
4809
						for (col = 0; col < this.columns; col++) {
4810
							if (ci == im.images.length) continue;
4811
							p.draw_image(temp_gr, im.images[ci], col * this.px, row * this.px, this.px, this.px, "top");
4812
							ci++;
4813
						}
4814
					}
4815
					this.img.ReleaseGraphics(temp_gr);
4816
					temp_gr = null;
4817
				}
4818
				break;
4819
			case this.mode == "left":
4820
			case this.mode == "right":
4821
				this.x = this.mode == "left" ? 0 : p.w - this.px;
4822
				this.y = 0;
4823
				this.w = this.px;
4824
				this.h = p.h;
4825
				im.x = this.mode == "right" ? 0 : this.px;
4826
				im.y = 0;
4827
				im.w = p.w - this.px;
4828
				im.h = p.h;
4829
				this.rows = Math.ceil(this.h / this.px);
4830
				if (this.nc && im.images.length > 0) {
4831
					this.nc = false;
4832
					this.img && this.img.Dispose();
4833
					this.img = null;
4834
					this.img = gdi.CreateImage(this.px, this.px * im.images.length);
4835
					var temp_gr = this.img.GetGraphics();
4836
					temp_gr.SetInterpolationMode(7);
4837
					for (i = 0; i < im.images.length; i++) {
4838
						p.draw_image(temp_gr, im.images[i], 0, i * this.px, this.px, this.px, "top");
4839
					}
4840
					this.img.ReleaseGraphics(temp_gr);
4841
					temp_gr = null;
4842
				}
4843
				break;
4844
			case this.mode == "bottom":
4845
			case this.mode == "top":
4846
				this.x = 0;
4847
				this.y = this.mode == "top" ? 0 : p.h - this.px;
4848
				this.w = p.w;
4849
				this.h = this.px;
4850
				im.x = 0;
4851
				im.y = this.mode == "bottom" ? 0 : this.px;
4852
				im.w = p.w;
4853
				im.h = p.h - this.px;
4854
				this.columns = Math.ceil(this.w / this.px);
4855
				if (this.nc && im.images.length > 0) {
4856
					this.nc = false;
4857
					this.img && this.img.Dispose();
4858
					this.img = null;
4859
					this.img = gdi.CreateImage(this.px * im.images.length, this.px);
4860
					var temp_gr = this.img.GetGraphics();
4861
					temp_gr.SetInterpolationMode(7);
4862
					for (i = 0; i < im.images.length; i++) {
4863
						p.draw_image(temp_gr, im.images[i], i * this.px, 0, this.px, this.px, "top");
4864
					}
4865
					this.img.ReleaseGraphics(temp_gr);
4866
					temp_gr = null;
4867
				}
4868
				break;
4869
		}
4870
	}
4871
	
4872
	this.wheel = function(step) {
4873
		switch(true) {
4874
			case !this.trace(p.mx, p.my):
4875
			case this.overlay:
4876
				return false;
4877
			case this.mode == "grid":
4878
				if (this.img_rows < this.rows) return true;
4879
				this.offset -= step;
4880
				if (this.offset < 0) this.offset = 0;
4881
				if (this.offset > this.img_rows - this.rows) this.offset = this.img_rows - this.rows + 1;
4882
				break;
4883
			case this.mode == "left":
4884
			case this.mode == "right":
4885
				if (im.images.length < this.rows) return true;
4886
				this.offset -= step;
4887
				if (this.offset < 0) this.offset = 0;
4888
				if (this.rows + this.offset > im.images.length) this.offset = im.images.length - this.rows + 1;
4889
				break;
4890
			case this.mode == "bottom":
4891
			case this.mode == "top":
4892
				if (im.images.length < this.columns) return true;
4893
				this.offset -= step;
4894
				if (this.offset < 0) this.offset = 0;
4895
				if (this.columns + this.offset > im.images.length) this.offset = im.images.length - this.columns + 1;
4896
				break;
4897
		}
4898
		window.RepaintRect(this.x, this.y, this.w, this.h);
4899
		return true;
4900
	}
4901
	
4902
	this.move = function(x, y) {
4903
		switch(true) {
4904
			case !this.trace(x, y):
4905
				window.SetCursor(IDC_ARROW);
4906
				return false;
4907
			case this.overlay:
4908
				window.SetCursor(IDC_ARROW);
4909
				return true;
4910
			case this.mode == "grid":
4911
				this.index = Math.floor((x - this.x) / this.px) + (Math.floor((y - this.y) / this.px) * this.columns) + (this.offset * this.columns);
4912
				break;
4913
			case this.mode == "left":
4914
			case this.mode == "right":
4915
				this.index = Math.floor((y - this.y) / this.px) + this.offset;
4916
				break;
4917
			case this.mode == "bottom":
4918
			case this.mode == "top":
4919
				this.index = Math.floor((x - this.x) / this.px) + this.offset;
4920
				break;
4921
		}
4922
		window.SetCursor(this.index < im.images.length ? IDC_HAND : IDC_ARROW);
4923
		return true;
4924
	}
4925
	
4926
	this.lbtn_up = function(x, y) {
4927
		switch(true) {
4928
			case !this.trace(x, y):
4929
				return false;
4930
			case this.mode == "grid" && this.overlay && im.trace(x, y):
4931
				this.overlay = false;
4932
				window.Repaint();
4933
				break;
4934
			case this.mode == "grid" && this.index < im.images.length && !this.overlay:
4935
				this.overlay = true;
4936
				im.index = this.index;
4937
				window.Repaint();
4938
				break;
4939
			case this.overlay:
4940
				break;
4941
			case this.index < im.images.length:
4942
				im.index = this.index;
4943
				window.Repaint();
4944
		}
4945
		return true;
4946
	}
4947
	
4948
	this.lbtn_dblclk = function(x, y) {
4949
		if (!im.trace(x, y) || th.mode == "grid") return false;
4950
		p.run("\"" + im.files[im.index] + "\"");
4951
		return true;
4952
	}
4953
	
4954
	this.nc = false;
4955
	this.mode = "off";
4956
	this.px = 40;
4957
	this.img = null;
4958
}
4959
4960
//json2.js
4961
if(typeof JSON!=='object'){JSON={};}
4962
(function(){'use strict';function f(n){return n<10?'0'+n:n;}
4963
if(typeof Date.prototype.toJSON!=='function'){Date.prototype.toJSON=function(key){return isFinite(this.valueOf())?this.getUTCFullYear()+'-'+
4964
f(this.getUTCMonth()+1)+'-'+
4965
f(this.getUTCDate())+'T'+
4966
f(this.getUTCHours())+':'+
4967
f(this.getUTCMinutes())+':'+
4968
f(this.getUTCSeconds())+'Z':null;};String.prototype.toJSON=Number.prototype.toJSON=Boolean.prototype.toJSON=function(key){return this.valueOf();};}
4969
var cx=/[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,escapable=/[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,gap,indent,meta={'\b':'\\b','\t':'\\t','\n':'\\n','\f':'\\f','\r':'\\r','"':'\\"','\\':'\\\\'},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+'"';}
4970
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);}
4971
if(typeof rep==='function'){value=rep.call(holder,key,value);}
4972
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';}
4973
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';}
4974
v=partial.length===0?'[]':gap?'[\n'+gap+partial.join(',\n'+gap)+'\n'+mind+']':'['+partial.join(',')+']';gap=mind;return v;}
4975
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);}}}}
4976
v=partial.length===0?'{}':gap?'{\n'+gap+partial.join(',\n'+gap)+'\n'+mind+'}':'{'+partial.join(',')+'}';gap=mind;return v;}}
4977
if(typeof JSON.stringify!=='function'){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;}
4978
rep=replacer;if(replacer&&typeof replacer!=='function'&&(typeof replacer!=='object'||typeof replacer.length!=='number')){throw new Error('JSON.stringify');}
4979
return str('',{'':value});};}
4980
if(typeof JSON.parse!=='function'){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];}}}}
4981
return reviver.call(holder,key,value);}
4982
text=String(text);cx.lastIndex=0;if(cx.test(text)){text=text.replace(cx,function(a){return'\\u'+
4983
('0000'+a.charCodeAt(0).toString(16)).slice(-4);});}
4984
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;}
4985
throw new SyntaxError('JSON.parse');};}}());
4986
4987
/*
4988
 * A JavaScript implementation of the RSA Data Security, Inc. MD5 Message
4989
 * Digest Algorithm, as defined in RFC 1321.
4990
 * Version 2.2 Copyright (C) Paul Johnston 1999 - 2009
4991
 * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
4992
 * Distributed under the BSD License
4993
 * See http://pajhome.org.uk/crypt/md5 for more info.
4994
 */
4995
var hexcase=0;function hex_md5(a){return rstr2hex(rstr_md5(str2rstr_utf8(a)))}
4996
function hex_hmac_md5(a,b){return rstr2hex(rstr_hmac_md5(str2rstr_utf8(a),str2rstr_utf8(b)))}
4997
function md5_vm_test(){return hex_md5("abc").toLowerCase()=="900150983cd24fb0d6963f7d28e17f72"}
4998
function rstr_md5(a){return binl2rstr(binl_md5(rstr2binl(a),a.length*8))}
4999
function rstr_hmac_md5(c,f){var e=rstr2binl(c);if(e.length>16){e=binl_md5(e,c.length*8)}
5000
var a=Array(16),d=Array(16);for(var b=0;b<16;b++){a[b]=e[b]^909522486;d[b]=e[b]^1549556828}
5001
var g=binl_md5(a.concat(rstr2binl(f)),512+f.length*8);return binl2rstr(binl_md5(d.concat(g),512+128))}
5002
function rstr2hex(c){try{hexcase}catch(g){hexcase=0}
5003
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)}
5004
return b}
5005
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++}
5006
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))}}}}}
5007
return b}
5008
function rstr2binl(b){var a=Array(b.length>>2);for(var c=0;c<a.length;c++){a[c]=0}
5009
for(var c=0;c<b.length*8;c+=8){a[c>>5]|=(b.charCodeAt(c/8)&255)<<(c%32)}
5010
return a}
5011
function binl2rstr(b){var a="";for(var c=0;c<b.length*32;c+=8){a+=String.fromCharCode((b[c>>5]>>>(c%32))&255)}
5012
return a}
5013
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)}
5014
return Array(o,n,m,l)}
5015
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)}
5016
function md5_ff(g,f,k,j,e,i,h){return md5_cmn((f&k)|((~f)&j),g,f,e,i,h)}
5017
function md5_gg(g,f,k,j,e,i,h){return md5_cmn((f&j)|(k&(~j)),g,f,e,i,h)}
5018
function md5_hh(g,f,k,j,e,i,h){return md5_cmn(f^k^j,g,f,e,i,h)}
5019
function md5_ii(g,f,k,j,e,i,h){return md5_cmn(k^(f|(~j)),g,f,e,i,h)}
5020
function safe_add(a,d){var c=(a&65535)+(d&65535);var b=(a>>16)+(d>>16)+(c>>16);return(b<<16)|(c&65535)}
5021
function bit_rol(a,b){return(a<<b)|(a>>>(32-b))};
5022
5023
5024
5025
5026
5027
var p = new panel("Youtube Radio", ["custom_background", "remap", "metadb"]);
5028
var im = new images(0, 0, 0, 0);
5029
var th = new thumbs();
5030
5031
on_item_focus_change();
5032
5033
function on_playback_time(time) {
5034
    im.playback_time(time);
5035
//if (ooo2 == "" || ooo2 == "?") if (time==30) im.downloadLFM1();
5036
}
5037
5038
5039
function on_metadb_changed() {
5040
	im.metadb_changed();
5041
}
5042
5043
//Button
5044
5045
var Buttons;
5046
5047
var g_tooltip = window.CreateTooltip();
5048
var g_down = false;
5049
5050
var btn_down = null;
5051
var cur_btn = null;
5052
5053
ButtonStates = {
5054
	normal: 0,
5055
	hover: 1,
5056
	down: 2
5057
}
5058
5059
function Button(x, y, w, h, img_src, func, tiptext)  {
5060
	this.left = x;
5061
	this.top = y;
5062
	this.w = w;
5063
	this.h = h;
5064
	this.right = x + w;
5065
	this.bottom = y + h;
5066
	this.func = func;
5067
	this.tiptext = tiptext;
5068
	this.state = ButtonStates.normal;
5069
	this.img_normal = img_src && img_src.normal ? gdi.Image(img_src.normal) : null;
5070
	this.img_hover = img_src && img_src.hover ? gdi.Image(img_src.hover) : this.img_normal;
5071
	this.img_down = img_src && img_src.down ? gdi.Image(img_src.down) : this.img_hover;
5072
	this.img = this.img_normal;
5073
	
5074
	this.alterImage = function(img_src) {
5075
		this.img_normal = img_src && img_src.normal ? gdi.Image(img_src.normal) : null;
5076
		this.img_hover = img_src && img_src.hover ? gdi.Image(img_src.hover) : this.img_normal;
5077
		this.img_down = img_src && img_src.down ? gdi.Image(img_src.down) : this.img_hover;
5078
		
5079
		this.changeState(this.state);
5080
	}
5081
	
5082
	this.traceMouse = function (x, y) {
5083
		var b = (this.left < x) && (x < this.right) && (this.top < y) && (y < this.bottom);
5084
		if (b)
5085
			g_down ? this.changeState(ButtonStates.down) : this.changeState(ButtonStates.hover);
5086
		else
5087
			this.changeState(ButtonStates.normal);
5088
		return b;
5089
	}
5090
	
5091
	
5092
	this.changeState = function (newstate) {
5093
		if (newstate != this.state)
5094
			window.RepaintRect(this.left, this.top, this.w, this.h);
5095
		this.state = newstate;
5096
		switch (this.state)
5097
		{
5098
		case ButtonStates.normal:
5099
			this.img = this.img_normal;
5100
			break;
5101
			
5102
		case ButtonStates.hover:
5103
			this.img = this.img_hover;
5104
			break;
5105
			
5106
		case ButtonStates.down:
5107
			this.img = this.img_down;
5108
			break;
5109
			
5110
		default:
5111
			this.img = null;
5112
		}
5113
	}
5114
	
5115
	this.draw = function (gr) {
5116
		this.img && gr.DrawImage(this.img, this.left, this.top, this.w, this.h, 0, 0, this.w, this.h);
5117
	}
5118
	
5119
	this.onClick = function () {
5120
		this.func && this.func(x,y);
5121
	}
5122
	
5123
	this.onMouseIn = function() {
5124
		g_tooltip.Text = this.tiptext;
5125
		g_tooltip.Activate();
5126
	}
5127
	
5128
	this.onMouseOut = function() {
5129
		g_tooltip.Deactivate();
5130
	}
5131
}
5132
5133
function buttonsDraw(gr) {
5134
	for (i in Buttons) {
5135
		Buttons[i].draw(gr);
5136
	}
5137
}
5138
5139
function buttonsTraceMouse(x, y) {
5140
	var btn = null;
5141
	for (i in Buttons) {
5142
		if (Buttons[i].traceMouse(x, y) && !btn)
5143
			btn = Buttons[i];
5144
	}
5145
5146
	return btn;
5147
}
5148
5149
function on_mouse_move(x, y) {
5150
	var btn = buttonsTraceMouse(x, y);
5151
	
5152
	if (btn != cur_btn) {
5153
		cur_btn && cur_btn.onMouseOut();
5154
		btn && btn.onMouseIn();
5155
	}
5156
	
5157
	cur_btn = btn;
5158
}
5159
5160
function on_mouse_lbtn_down(x, y) {
5161
	g_down = true;
5162
	btn_down = cur_btn;
5163
5164
	if (cur_btn) {
5165
		cur_btn.changeState(ButtonStates.down);
5166
	}
5167
}
5168
5169
function on_mouse_lbtn_up(x, y) {
5170
	if (cur_btn) {
5171
		cur_btn.changeState(ButtonStates.hover);
5172
		if( btn_down == cur_btn )
5173
			cur_btn.onClick(x, y);
5174
	}
5175
	g_down = false;
5176
}
5177
5178
function on_mouse_leave() {
5179
	if (cur_btn) {
5180
		cur_btn.changeState(ButtonStates.normal);
5181
	}
5182
}
5183
5184
function on_size() {
5185
	ww = window.Width;
5186
	wh = window.Height;
5187
    window.Repaint();
5188
}
5189
5190
function on_paint(gr) {
5191
	/*switch(window.GetProperty("mode", 1)) {
5192
		case 1:
5193
			//col = window.GetColorDUI(1);
5194
			break;
5195
		case 2:
5196
			col = utils.GetSysColor(4);
5197
			break;
5198
		case 3:
5199
			col = custom;
5200
			break;
5201
	}*/
5202
	//gr.FillSolidRect(0, 0, ww, wh, col);
5203
	buttonsDraw(gr);
5204
	//gr.DrawRect(0,0, ww, wh, 1.0, -6250336);
5205
}
5206
5207
function RGB(r,g,b) {
5208
	return (0xff000000|(r<<16)|(g<<8)|(b)); 
5209
}
5210
5211
function on_colors_changed() {
5212
    window.Repaint();
5213
}
5214
5215
5216
//init Buttons
5217
5218
//custom colour accessed through the context menu
5219
var custom = RGB(255,255,255);
5220
5221
//button width
5222
var bw = 24;
5223
//button height
5224
var bh = 20;
5225
5226
//Button position
5227
var top_margin = -1;
5228
var left_margin = 0;
5229
5230
var image_path0 = window.GetProperty("Button Path", fb.ProfilePath + "image");
5231
var image_path = (image_path0 + "\\");
5232
5233
//these 2 lines of code lock the panel size. you can comment them out or change the dimensions to suit
5234
//window.MinWidth = window.MaxWidth = 24;
5235
//window.MinHeight = window.MaxHeight = 20;
5236
5237
5238
5239
Buttons = {
5240
	but1: new Button(left_margin,top_margin,bw,bh, {normal: image_path + "youtube0.png", hover: image_path + "youtube1.png"}, function(){
5241
        //if (p.artist.indexOf("3dydfy://")== 0 | p.artist.indexOf("www.youtube.com/")== 0 | p.artist.indexOf("youtube.com/")== 0 | p.artist.indexOf("http://www.youtube.com/")== 0)
5242
        p.rbtn_up(24, 17);
5243
        //im.downloadONE();
5244
        /*else
5245
        {
5246
        p.artist = p.eval("%artist% %title%");
5247
        p.browser("http://www.youtube.com/results?search_query=" + encodeURIComponent(p.artist) + "&ie=utf-8");
5248
    }*/
5249
        }, "Youtube")
5250
	
5251
}
5252
5253
//fb.RunMainMenuCommand("Library/Search");
5254
//fb.RunContextCommand("Open containing folder");
5255
5256
function on_mouse_rbtn_up(x, y) {
5257
return true;
5258
}