View difference between Paste ID: uxGmjCyK and G76MuFjS
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("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 Radio Station");
591
p.artist = p.eval("%artist%");
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 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 Station\n\n( *genre - will play genre station)", this.name, 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("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("/",""));   
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("/","").replace("%27","'").replace("%27","'").replace("%27","'").replace("%27","'").replace("%27","'").replace("%27","'").replace("%27","'").replace("%27","'").replace("%27","'").replace("%27","'").replace("%27","'").replace("%27","'").replace("%27","'").replace("%27","'").replace("%27","'"));   
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;
1893+
1894-
//p.run(tmppath+"\\foobar2000.exe /immediate /add "+"\ " + urls[i] + "\"");                   
1894+
1895
1896
                im.doc.close();
1897
                im.working=false;
1898
                if (START_ARTIST.indexOf("*")== 0) {im.downloadGENRE2();}
1899
                else
1900
                if (last_fm == "" || last_fm == "?") {im.downloadLFM();}
1901
                else
1902
                im.downloadTRACK();
1903-
//open YT in playlist
1903+
1904-
//var tmppath = p.fso.GetFolder(fb.FoobarPath).ShortPath;
1904+
1905-
//p.run(tmppath+"\\foobar2000.exe /immediate /add "+"\""+urls[i] + "\"");
1905+
1906-
//fb.RunMainMenuCommand("File/Add Youtube URL(s)...") + ("/immediate /add "+"\""+ urls[i]);                       
1906+
1907
                    
1908
                    if (START_ARTIST.indexOf("*")== 0) {im.downloadGENRE2();}
1909
                    else
1910
                    if (im.xmlhttp.status == 404) {im.downloadLFM();}
1911
                }
1912
			}
1913
		}
1914
	}
1915
}}                             
1916
1917
}
1918
1919
1920
//Open track
1921
this.downloadTRACK = function()
1922
     {
1923
     //if (!p.fso.FolderExists(this.folder))  return;
1924
        //if (server==ooo) return true;
1925
        //else
1926
        {
1927
        
1928
1929
        
1930
        
1931
        
1932
        {
1933
        
1934
  
1935
    
1936
    {var randomnumber=Math.floor(Math.random()*20)
1937
      var a=randomnumber;
1938
        this.working=true;
1939
        if (last_fm == "" || last_fm == "?") return;
1940
        //var folder = this.folder + "\\";
1941
		if (!this.xmlhttp) this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
1942
		this.xmlhttp.open("GET", "http://www.last.fm/music/" + encodeURIComponent(last_fm) + "/+tracks" + "?page=" + a, true);
1943
		this.xmlhttp.send();
1944
		this.xmlhttp.onreadystatechange = function() {
1945
			if (im.xmlhttp.readyState == 4) {
1946
				if (im.xmlhttp.status == 200) {
1947
					var text = im.xmlhttp.responsetext;
1948
					if (!im.doc) im.doc = new ActiveXObject("htmlfile");
1949
					im.doc.open();
1950
					var div = im.doc.createElement("tr");
1951
					div.innerHTML = text;
1952
					var data = div.getElementsByTagName("td");
1953
					var urls = [];
1954
    
1955
			
1956
1957
for (i = 0; i < data.length; i++) {
1958
    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].replace("%27","'").replace("%27","'").replace("%27","'").replace("%27","'").replace("%27","'").replace("%27","'").replace("%27","'").replace("%27","'").replace("%27","'").replace("%27","'").replace("%27","'").replace("%27","'").replace("%27","'").replace("%27","'").replace("%27","'")); 
1959
} 
1960
1961
1962
//select random URL
1963
var randomnumber = Math.floor(Math.random()*Math.max(urls.length));
1964
i=randomnumber;
1965
1966
{
1967
1968
//do something with urls[i]
1969
p.console("" + last_fm + " - " + urls[i]);
1970
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]);
1971+
1972
{
1973
1974
ooo2 = window.SetProperty("YT Track", last_fm + " - " + urls[i]);
1975
ooo2 = urls[i];
1976
window.SetProperty("YT Track", last_fm + " - " + urls[i]);
1977
}
1978
else
1979
//if (urls[i] == "" || urls[i] == "?")
1980
{
1981
ooo2 = window.SetProperty("YT Track", "");
1982
ooo2 = "";
1983
window.SetProperty("YT Track", "");
1984-
//var tmppath = p.fso.GetFolder(fb.FoobarPath).ShortPath;
1984+
1985-
//p.run(tmppath+"\\foobar2000.exe /immediate /add "+"\ " + urls[i] + "\"");                   
1985+
1986
1987
                im.doc.close();
1988
                im.working=false;
1989
                if (ooo2 == "" || ooo2 == "?") {im.downloadLFM();}
1990
                else
1991
                im.downloadYT();
1992
				//im.update();
1993
				//window.NotifyOthers("images", "update");
1994
				} else {
1995
					p.console("HTTP error: " + im.xmlhttp.status);
1996
                    if (START_ARTIST.indexOf("*")== 0) {im.downloadGENRE2();}
1997
                    else
1998
                    if (im.xmlhttp.status == 404) {im.downloadLFM();}
1999
                
2000
                }
2001
			}
2002
		}
2003
	}
2004
}}}
2005
2006
		
2007
	
2008-
//open YT in playlist
2008+
2009-
//var tmppath = p.fso.GetFolder(fb.FoobarPath).ShortPath;
2009+
2010-
//p.run(tmppath+"\\foobar2000.exe /immediate /add "+"\""+urls[i] + "\"");
2010+
2011-
//fb.RunMainMenuCommand("File/Add Youtube URL(s)...") + ("/immediate /add "+"\""+ urls[i]);                       
2011+
2012
     {
2013
        {
2014
        
2015
        
2016
        {
2017
        
2018
   //if (p.artist.indexOf("3dydfy://")== 0)
2019
    
2020
    {
2021
        this.working=true;
2022
        if (ooo2 == "" || ooo2 == "?") return;
2023
        //var folder = this.folder + "\\";
2024
		if (!this.xmlhttp) this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
2025
		this.xmlhttp.open("GET", "http://www.youtube.com/results?search_query=" + last_fm.replace(" & ", " %26 ") +" %2D " + encodeURIComponent(ooo2).replace(" & ", " %26 "), true);
2026
		this.xmlhttp.send();
2027
		this.xmlhttp.onreadystatechange = function() {
2028
			if (im.xmlhttp.readyState == 4) {
2029
				if (im.xmlhttp.status == 200) {
2030
					var text = im.xmlhttp.responsetext;
2031
					if (!im.doc) im.doc = new ActiveXObject("htmlfile");
2032
					im.doc.open();
2033
					var div = im.doc.createElement("div");
2034
					div.innerHTML = text;
2035
					var data = div.getElementsByTagName("a");
2036
					var urls = [];
2037
    
2038
			
2039
2040
for (i = 0; i < data.length; i++) {
2041
    if (data[i].href.indexOf("about:/watch?v=") == 0) urls.push("http://www.youtube.com/" + data[i].href.replace(/about:\//,""));
2042
}
2043-
        //if (server=="last.fm")
2043+
2044
//select random URL
2045
//var randomnumber = Math.floor(Math.random()*Math.max(urls.length-1))+1;
2046
//i=randomnumber;
2047
i = 1;
2048
2049
{
2050
2051
//do something with urls[i]
2052
p.console("" + urls[i]);
2053-
		this.xmlhttp.open("GET", "http://www.youtube.com/results?search_query=" + encodeURIComponent(last_fm) +" - " + encodeURIComponent(ooo2), true);
2053+
2054
if (urls[i] > "" && ooo2 > "") 
2055
{
2056
YT_URL = window.SetProperty("YT URL", urls[i]);
2057
YT_URL = urls[i];
2058
window.SetProperty("YT URL", urls[i]);
2059
2060
var tmppath = p.fso.GetFolder(fb.FoobarPath).ShortPath;
2061
var str = tmppath + "\\foobar2000.exe /add ";
2062
var go = str + urls[i];
2063
p.run(go);
2064
}
2065
else
2066
//if (urls[i] == "" || urls[i] == "?")
2067
{
2068
YT_URL = window.SetProperty("YT URL", "");
2069
YT_URL = "";
2070
window.SetProperty("YT URL", "");
2071
}
2072
2073
2074
2075
 }
2076
2077
                im.doc.close();
2078
                im.working=false;
2079
				if (YT_URL == "" || YT_URL == "?") {im.downloadLFM();}
2080
                
2081
				} else {
2082
					p.console("HTTP error: " + im.xmlhttp.status);
2083
                    if (START_ARTIST.indexOf("*")== 0) {im.downloadGENRE2();}
2084
                    else
2085
                    if (im.xmlhttp.status == 404) {im.downloadLFM();}
2086
                }
2087
			}
2088
		}
2089-
p.run(tmppath+"\\foobar2000.exe /add "+"\ " + urls[i] + "\"");                   
2089+
2090
}}}
2091
2092
2093
2094
//LAST.FM RADIO(One)--------------------------------------------------------------------------------------------------
2095
2096
//open simmilar artist
2097
this.downloadLFM1 = function()
2098
     {
2099
     
2100
        {
2101
         
2102
        {
2103
        //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)
2104
   
2105
    
2106
    { var randomnumber=Math.floor(Math.random()*18)
2107-
//open YT in playlist
2107+
2108-
//var tmppath = p.fso.GetFolder(fb.FoobarPath).ShortPath;
2108+
2109-
//p.run(tmppath+"\\foobar2000.exe /immediate /add "+"\""+urls[i] + "\"");
2109+
2110-
//fb.RunMainMenuCommand("File/Add Youtube URL(s)...") + ("/immediate /add "+"\""+ urls[i]);                       
2110+
2111
		this.xmlhttp.open("GET", "http://www.last.fm/music/" + encodeURIComponent(START_ARTIST) + "/+similar"+ "?page=" + a, true);
2112
		this.xmlhttp.send();
2113
		this.xmlhttp.onreadystatechange = function() {
2114
			if (im.xmlhttp.readyState == 4) {
2115
				if (im.xmlhttp.status == 200) {
2116
					var text = im.xmlhttp.responsetext;
2117
					if (!im.doc) im.doc = new ActiveXObject("htmlfile");
2118
					im.doc.open();
2119
					var div = im.doc.createElement("div");
2120
					div.innerHTML = text;
2121
					var data = div.getElementsByTagName("a");
2122
					var urls = [];
2123
    
2124
			
2125
2126
for (i = 0; i < data.length; i++) {
2127
     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("/","").replace("%27","'").replace("%27","'").replace("%27","'").replace("%27","'").replace("%27","'").replace("%27","'").replace("%27","'").replace("%27","'").replace("%27","'").replace("%27","'").replace("%27","'").replace("%27","'").replace("%27","'").replace("%27","'").replace("%27","'"));    
2128
}
2129
2130
2131
//select random URL
2132
var randomnumber = Math.floor(Math.random()*(20-50)+50);
2133
do{
2134
randomnumber = Math.floor(Math.random()*(20-50)+50);
2135
} while(randomnumber%2!=1);
2136
i=randomnumber;
2137
2138
//select all url
2139
//for (i = 0; i < urls.length; i++)
2140
{
2141
2142
//do something with urls[i]
2143
//if (START_ARTIST.indexOf("*")== 0) {} else {p.console("" + urls[i]);}
2144
2145
if (urls[i] > "") 
2146
{
2147
2148
last_fm = window.SetProperty("YT Similar", urls[i]);
2149
last_fm = urls[i];
2150
window.SetProperty("YT Similar", urls[i]);
2151
}
2152
else
2153
//if (urls[i] == "" || urls[i] == "?")
2154
{
2155
last_fm = window.SetProperty("YT Similar", "");
2156
last_fm = "";
2157
window.SetProperty("YT Similar", "");
2158
}                   
2159
2160
}
2161
            
2162
                im.doc.close();
2163
                im.working=false;
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("/",""));   
2164+
2165
                else
2166
                if (last_fm == "" || last_fm == "?") {im.downloadLFM1();}
2167
                else
2168
                im.downloadTRACK1();
2169
				//im.update();
2170
				//window.NotifyOthers("images", "update");
2171
				} else {
2172
					if (START_ARTIST.indexOf("*")== 0) {} else {p.console("HTTP error: " + im.xmlhttp.status);}
2173
                    if (START_ARTIST.indexOf("*")== 0) {im.downloadGENRE2();}
2174
                    else
2175
                    if (im.xmlhttp.status == 404) {im.downloadLFM1();}
2176
                }
2177
			}
2178
		}
2179
	}
2180
}}                             
2181
2182
}
2183
2184
2185
//Open track
2186
this.downloadTRACK1 = function()
2187
     {
2188
        {
2189
        
2190
2191
        
2192
        
2193
        
2194
        {
2195
        
2196-
//var tmppath = p.fso.GetFolder(fb.FoobarPath).ShortPath;
2196+
2197-
//p.run(tmppath+"\\foobar2000.exe /immediate /add "+"\ " + urls[i] + "\"");                   
2197+
2198
    {var randomnumber=Math.floor(Math.random()*20)
2199
      var a=randomnumber;
2200
        this.working=true;
2201
        if (last_fm == "" || last_fm == "?") return;
2202
        //var folder = this.folder + "\\";
2203
		if (!this.xmlhttp) this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
2204
		this.xmlhttp.open("GET", "http://www.last.fm/music/" + encodeURIComponent(last_fm) + "/+tracks" + "?page=" + a, true);
2205
		this.xmlhttp.send();
2206-
//open YT in playlist
2206+
2207-
//var tmppath = p.fso.GetFolder(fb.FoobarPath).ShortPath;
2207+
2208-
//p.run(tmppath+"\\foobar2000.exe /immediate /add "+"\""+urls[i] + "\"");
2208+
2209-
//fb.RunMainMenuCommand("File/Add Youtube URL(s)...") + ("/immediate /add "+"\""+ urls[i]);                       
2209+
2210
					if (!im.doc) im.doc = new ActiveXObject("htmlfile");
2211
					im.doc.open();
2212
					var div = im.doc.createElement("tr");
2213
					div.innerHTML = text;
2214
					var data = div.getElementsByTagName("td");
2215
					var urls = [];
2216
    
2217
			
2218
2219
for (i = 0; i < data.length; i++) {
2220
    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].replace("%27","'").replace("%27","'").replace("%27","'").replace("%27","'").replace("%27","'").replace("%27","'").replace("%27","'").replace("%27","'").replace("%27","'").replace("%27","'").replace("%27","'").replace("%27","'").replace("%27","'").replace("%27","'").replace("%27","'")); 
2221
}
2222
2223
//select random URL
2224
var randomnumber = Math.floor(Math.random()*Math.max(urls.length));
2225
i=randomnumber;
2226
2227
{
2228
2229
//do something with urls[i]
2230
p.console("" + last_fm + " - " + urls[i]);
2231
2232
if (urls[i] > "") 
2233
{
2234
2235
ooo2 = window.SetProperty("YT Track", last_fm + " - " + urls[i]);
2236
ooo2 = urls[i];
2237
window.SetProperty("YT Track", last_fm + " - " + urls[i]);
2238
}
2239
else
2240
//if (urls[i] == "" || urls[i] == "?")
2241
{
2242
ooo2 = window.SetProperty("YT Track", "");
2243
ooo2 = "";
2244
window.SetProperty("YT Track", "");
2245
}
2246
}
2247
2248
                im.doc.close();
2249
                im.working=false;
2250
                if (ooo2 == "" || ooo2 == "?") {im.downloadLFM1();}
2251
                else
2252
                im.downloadYT1();
2253
				} else {
2254
					p.console("HTTP error: " + im.xmlhttp.status);
2255
                    if (START_ARTIST.indexOf("*")== 0) {im.downloadGENRE2();}
2256
                    else
2257
                    if (im.xmlhttp.status == 404) {im.downloadLFM1();}
2258
                
2259
                }
2260
			}
2261
		}
2262
	}
2263
}}}
2264
2265
		
2266
	
2267
2268
2269
//open Youtube	
2270
this.downloadYT1 = function()
2271
     {
2272
        {
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]);
2273+
2274
        {
2275
        
2276
   //if (p.artist.indexOf("3dydfy://")== 0)
2277
    
2278
    {
2279
        this.working=true;
2280
        if (ooo2 == "" || ooo2 == "?") return;
2281
		if (!this.xmlhttp) this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
2282
		this.xmlhttp.open("GET", "http://www.youtube.com/results?search_query=" + last_fm.replace(" & ", " %26 ") +" %2D " + encodeURIComponent(ooo2).replace(" & ", " %26 "), true);
2283
		this.xmlhttp.send();
2284
		this.xmlhttp.onreadystatechange = function() {
2285-
//var tmppath = p.fso.GetFolder(fb.FoobarPath).ShortPath;
2285+
2286-
//p.run(tmppath+"\\foobar2000.exe /immediate /add "+"\ " + urls[i] + "\"");                   
2286+
2287
					var text = im.xmlhttp.responsetext;
2288
					if (!im.doc) im.doc = new ActiveXObject("htmlfile");
2289
					im.doc.open();
2290
					var div = im.doc.createElement("div");
2291
					div.innerHTML = text;
2292
					var data = div.getElementsByTagName("a");
2293
					var urls = [];
2294
    
2295
			
2296
2297
for (i = 0; i < data.length; i++) {
2298
    if (data[i].href.indexOf("about:/watch?v=") == 0) urls.push("http://www.youtube.com/" + data[i].href.replace(/about:\//,""));
2299
}
2300
2301
//select random URL
2302
//var randomnumber = Math.floor(Math.random()*Math.max(urls.length-1))+1;
2303
//i=randomnumber;
2304
i = 1;
2305
2306
{
2307
2308
//do something with urls[i]
2309-
//open YT in playlist
2309+
2310-
//var tmppath = p.fso.GetFolder(fb.FoobarPath).ShortPath;
2310+
2311-
//p.run(tmppath+"\\foobar2000.exe /immediate /add "+"\""+urls[i] + "\"");
2311+
2312-
//fb.RunMainMenuCommand("File/Add Youtube URL(s)...") + ("/immediate /add "+"\""+ urls[i]);                       
2312+
2313
YT_URL = window.SetProperty("YT URL", urls[i]);
2314
YT_URL = urls[i];
2315
window.SetProperty("YT URL", urls[i]);
2316
2317
var tmppath = p.fso.GetFolder(fb.FoobarPath).ShortPath;
2318
var str = tmppath + "\\foobar2000.exe /add ";
2319
var go = str + urls[i];
2320
p.run(go);
2321
}
2322
else
2323
//if (urls[i] == "" || urls[i] == "?")
2324
{
2325
YT_URL = window.SetProperty("YT URL", "");
2326
YT_URL = "";
2327
window.SetProperty("YT URL", "");
2328
}
2329
2330
2331
2332
 }
2333
2334
                im.doc.close();
2335
                im.working=false;
2336
				if (YT_URL == "" || YT_URL == "?") {im.downloadLFM1();}
2337
                
2338
				} else {
2339
					p.console("HTTP error: " + im.xmlhttp.status);
2340
                    if (START_ARTIST.indexOf("*")== 0) {im.downloadGENRE2();}
2341
                    else
2342
                    if (im.xmlhttp.status == 404) {im.downloadLFM1();}
2343
                }
2344-
        //if (server=="last.fm")
2344+
2345
		}
2346
	}
2347
}}}
2348
2349
2350
2351
//CHECK IF ARTIST EXIST--------------------------------------------------------------------------------------------------
2352
2353
this.downloadLFM0 = function()
2354-
		this.xmlhttp.open("GET", "http://www.youtube.com/results?search_query=" + encodeURIComponent(last_fm) +" - " + encodeURIComponent(ooo2), true);
2354+
2355
    {   
2356
        this.working=true;
2357
        if (START_ARTIST == "" || START_ARTIST == "?") return;
2358
        if (!this.xmlhttp) this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
2359
		this.xmlhttp.open("GET", "http://www.last.fm/music/" + encodeURIComponent(START_ARTIST) + "/+similar", true);
2360
		this.xmlhttp.send();
2361
		this.xmlhttp.onreadystatechange = function() {
2362
			if (im.xmlhttp.readyState == 4) {
2363
				if (im.xmlhttp.status == 200) {
2364
					var text = im.xmlhttp.responsetext;
2365
					if (!im.doc) im.doc = new ActiveXObject("htmlfile");
2366
					im.doc.open();
2367
					var div = im.doc.createElement("div");
2368
					div.innerHTML = text;
2369
					var data = div.getElementsByTagName("a");
2370
					var urls = [];
2371
    
2372
			
2373
2374
2375
                im.doc.close();
2376
                im.working=false;
2377
                im.downloadLFM000();
2378
				
2379
				} else {
2380
					if (START_ARTIST.indexOf("*")== 0) {} else {p.console("HTTP error: " + im.xmlhttp.status);}
2381
                    if (START_ARTIST.indexOf("*")== 0) {im.downloadGENRE2();}
2382
                    else
2383
                    if (im.xmlhttp.status == 404)
2384
                    {
2385
                    p.MsgBox("This Artist Not Found!", 0, p.name);
2386
                    }
2387
                    
2388
                    
2389
                }
2390-
p.run(tmppath+"\\foobar2000.exe /add "+"\ " + urls[i] + "\"");                   
2390+
2391
		}
2392
	}
2393
                             
2394
2395
2396
//START ARTIST RADIO(same artist)--------------------------------------------------------------------------------------------------
2397
2398
//open simmilar artist
2399
this.downloadLFM000 = function()
2400
     {
2401
     
2402
        {
2403
       
2404
        {
2405
        //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)
2406
   
2407
    
2408-
//open YT in playlist
2408+
2409-
//var tmppath = p.fso.GetFolder(fb.FoobarPath).ShortPath;
2409+
2410-
//p.run(tmppath+"\\foobar2000.exe /immediate /add "+"\""+urls[i] + "\"");
2410+
2411-
//fb.RunMainMenuCommand("File/Add Youtube URL(s)...") + ("/immediate /add "+"\""+ urls[i]);                       
2411+
2412
		if (!this.xmlhttp) this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
2413
		this.xmlhttp.open("GET", "http://www.last.fm/music/" + encodeURIComponent(START_ARTIST) + "/+similar"+ "?page=" + a, true);
2414
		this.xmlhttp.send();
2415
		this.xmlhttp.onreadystatechange = function() {
2416
			if (im.xmlhttp.readyState == 4) {
2417
				if (im.xmlhttp.status == 200) {
2418
					var text = im.xmlhttp.responsetext;
2419
					if (!im.doc) im.doc = new ActiveXObject("htmlfile");
2420
					im.doc.open();
2421
					var div = im.doc.createElement("div");
2422
					div.innerHTML = text;
2423
					var data = div.getElementsByTagName("a");
2424
					var urls = [];
2425
    
2426
			
2427
2428
for (i = 0; i < data.length; i++) {
2429
     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("/","").replace("%27","'").replace("%27","'").replace("%27","'").replace("%27","'").replace("%27","'").replace("%27","'").replace("%27","'").replace("%27","'").replace("%27","'").replace("%27","'").replace("%27","'").replace("%27","'").replace("%27","'").replace("%27","'").replace("%27","'"));    
2430
}
2431
2432
2433
//select random URL
2434
var randomnumber = Math.floor(Math.random()*(20-50)+50);
2435
do{
2436
randomnumber = Math.floor(Math.random()*(20-50)+50);
2437
} while(randomnumber%2!=1);
2438
i=randomnumber;
2439
2440
//select all url
2441
//for (i = 0; i < urls.length; i++)
2442
{
2443
2444
//do something with urls[i]
2445
//if (START_ARTIST.indexOf("*")== 0) {} else {p.console("" + urls[i]);}
2446
2447
if (urls[i] > "") 
2448
{
2449
2450
last_fm = window.SetProperty("YT Similar", urls[i]);
2451
last_fm = urls[i];
2452
window.SetProperty("YT Similar", urls[i]);
2453
}
2454
else
2455
//if (urls[i] == "" || urls[i] == "?")
2456
{
2457
last_fm = window.SetProperty("YT Similar", "");
2458
last_fm = "";
2459
window.SetProperty("YT Similar", "");
2460
}                  
2461
2462
}
2463
2464
                im.doc.close();
2465
                im.working=false;
2466
                if (START_ARTIST.indexOf("*")== 0) {im.downloadGENRE2();}
2467
                else
2468
                if (last_fm == "" || last_fm == "?") {im.downloadLFM000();}
2469
                else
2470
                im.downloadTRACK11();
2471
				
2472
				} else {
2473
					if (START_ARTIST.indexOf("*")== 0) {} else {p.console("HTTP error: " + im.xmlhttp.status);}
2474
                    if (START_ARTIST.indexOf("*")== 0) {im.downloadGENRE2();}
2475
                    else
2476
                    if (im.xmlhttp.status == 404) {im.downloadLFM000();}
2477
2478
                }
2479
			}
2480
		}
2481
	}
2482
}}                             
2483
2484
}
2485
2486
2487
//Open track
2488
this.downloadTRACK11 = function()
2489
     {
2490
        {
2491
        {
2492
        
2493
    
2494
    {var randomnumber=Math.floor(Math.random()*20)
2495
      var a=randomnumber;
2496
        this.working=true;
2497
        if (last_fm == "" || last_fm == "?") return;
2498
        //var folder = this.folder + "\\";
2499
		if (!this.xmlhttp) this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
2500
		this.xmlhttp.open("GET", "http://www.last.fm/music/" + encodeURIComponent(last_fm) + "/+tracks" + "?page=" + a, true);
2501
		this.xmlhttp.send();
2502
		this.xmlhttp.onreadystatechange = function() {
2503
			if (im.xmlhttp.readyState == 4) {
2504
				if (im.xmlhttp.status == 200) {
2505
					var text = im.xmlhttp.responsetext;
2506
					if (!im.doc) im.doc = new ActiveXObject("htmlfile");
2507
					im.doc.open();
2508
					var div = im.doc.createElement("tr");
2509
					div.innerHTML = text;
2510
					var data = div.getElementsByTagName("td");
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("/",""));   
2511+
2512
    
2513
			
2514
2515
for (i = 0; i < data.length; i++) {
2516
    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].replace("%27","'").replace("%27","'").replace("%27","'").replace("%27","'").replace("%27","'").replace("%27","'").replace("%27","'").replace("%27","'").replace("%27","'").replace("%27","'").replace("%27","'").replace("%27","'").replace("%27","'").replace("%27","'").replace("%27","'")); 
2517
}
2518
2519
//select random URL
2520
var randomnumber = Math.floor(Math.random()*Math.max(urls.length));
2521
i=randomnumber;
2522
2523
{
2524
2525
//do something with urls[i]
2526
p.console("" + last_fm + " - " + urls[i]);
2527
2528
if (urls[i] > "") 
2529
{
2530
2531
ooo2 = window.SetProperty("YT Track", last_fm + " - " + urls[i]);
2532
ooo2 = urls[i];
2533
window.SetProperty("YT Track", last_fm + " - " + urls[i]);
2534
}
2535
else
2536
//if (urls[i] == "" || urls[i] == "?")
2537
{
2538
ooo2 = window.SetProperty("YT Track", "");
2539
ooo2 = "";
2540
window.SetProperty("YT Track", "");
2541
}
2542
}
2543
2544
                im.doc.close();
2545
                im.working=false;
2546
                if (ooo2 == "" || ooo2 == "?") {im.downloadLFM000();}
2547
                else
2548
                im.downloadYT11();
2549
				} else {
2550
					p.console("HTTP error: " + im.xmlhttp.status);
2551
                    if (START_ARTIST.indexOf("*")== 0) {im.downloadGENRE2();}
2552
                    else
2553
                    if (im.xmlhttp.status == 404) {im.downloadLFM000();}
2554
2555
                
2556
                }
2557
			}
2558
		}
2559
	}
2560
}}}
2561
2562
		
2563
	
2564
2565
2566
//open Youtube	
2567
this.downloadYT11 = function()
2568
     {
2569
        {
2570
        
2571
        {
2572
        
2573
   //if (p.artist.indexOf("3dydfy://")== 0)
2574
    
2575
    {
2576
        this.working=true;
2577
        if (ooo2 == "" || ooo2 == "?") return;
2578
        //var folder = this.folder + "\\";
2579
		if (!this.xmlhttp) this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
2580
		this.xmlhttp.open("GET", "http://www.youtube.com/results?search_query=" + last_fm.replace(" & ", " %26 ") +" %2D " + encodeURIComponent(ooo2).replace(" & ", " %26 "), true);
2581
		this.xmlhttp.send();
2582
		this.xmlhttp.onreadystatechange = function() {
2583
			if (im.xmlhttp.readyState == 4) {
2584
				if (im.xmlhttp.status == 200) {
2585
					var text = im.xmlhttp.responsetext;
2586
					if (!im.doc) im.doc = new ActiveXObject("htmlfile");
2587
					im.doc.open();
2588
					var div = im.doc.createElement("div");
2589
					div.innerHTML = text;
2590
					var data = div.getElementsByTagName("a");
2591
					var urls = [];
2592
    
2593
			
2594
2595
for (i = 0; i < data.length; i++) {
2596
    if (data[i].href.indexOf("about:/watch?v=") == 0) urls.push("http://www.youtube.com/" + data[i].href.replace(/about:\//,""));
2597
}
2598
2599
//select random URL
2600
//var randomnumber = Math.floor(Math.random()*Math.max(urls.length-1))+1;
2601
//i=randomnumber;
2602
i = 1;
2603
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]);
2604+
2605
2606
//do something with urls[i]
2607
p.console("" + urls[i]);
2608
2609
if (urls[i] > "" && ooo2 > "") 
2610
{
2611
YT_URL = window.SetProperty("YT URL", urls[i]);
2612
YT_URL = urls[i];
2613
window.SetProperty("YT URL", urls[i]);
2614
2615
var tmppath = p.fso.GetFolder(fb.FoobarPath).ShortPath;
2616-
//var tmppath = p.fso.GetFolder(fb.FoobarPath).ShortPath;
2616+
var str = tmppath + "\\foobar2000.exe /add ";
2617-
//p.run(tmppath+"\\foobar2000.exe /immediate /add "+"\ " + urls[i] + "\"");                   
2617+
var go = str + urls[i];
2618
p.run(go);
2619
}
2620
else
2621
//if (urls[i] == "" || urls[i] == "?")
2622
{
2623
YT_URL = window.SetProperty("YT URL", "");
2624
YT_URL = "";
2625
window.SetProperty("YT URL", "");
2626
}
2627
2628
2629
2630
 }
2631
                im.doc.close();
2632
                im.working=false;
2633
				if (YT_URL == "" || YT_URL == "?") {im.downloadLFM000();}
2634
                
2635
				} else {
2636
					p.console("HTTP error: " + im.xmlhttp.status);
2637
                    if (START_ARTIST.indexOf("*")== 0) {im.downloadGENRE2();}
2638
                    else
2639
                    if (im.xmlhttp.status == 404) {im.downloadLFM000();}
2640-
//open YT in playlist
2640+
2641-
//var tmppath = p.fso.GetFolder(fb.FoobarPath).ShortPath;
2641+
2642-
//p.run(tmppath+"\\foobar2000.exe /immediate /add "+"\""+urls[i] + "\"");
2642+
2643-
//fb.RunMainMenuCommand("File/Add Youtube URL(s)...") + ("/immediate /add "+"\""+ urls[i]);                       
2643+
2644
	}
2645
}}}
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
//Download Same Video------------------------------------------------------------------
2656
this.downloadART_TITLE = function()
2657
     {
2658
   
2659
        {
2660
        
2661
        
2662
        {
2663
        
2664
  
2665
    
2666
    {
2667
        this.working=true;
2668
        p.artist = p.eval("%artist% %title%");
2669
        if (p.artist == "" || p.artist == "?") return;
2670
        var folder = this.folder + "\\";
2671
		if (!this.xmlhttp) this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
2672
		this.xmlhttp.open("GET", "http://www.youtube.com/results?search_query=" + encodeURIComponent(p.artist), true);
2673
		this.xmlhttp.send();
2674
		this.xmlhttp.onreadystatechange = function() {
2675
			if (im.xmlhttp.readyState == 4) {
2676-
        //if (server=="last.fm")
2676+
2677
					var text = im.xmlhttp.responsetext;
2678
					if (!im.doc) im.doc = new ActiveXObject("htmlfile");
2679
					im.doc.open();
2680
					var div = im.doc.createElement("div");
2681
					div.innerHTML = text;
2682
					var data = div.getElementsByTagName("a");
2683
					var urls = [];
2684
    
2685
			
2686-
		this.xmlhttp.open("GET", "http://www.youtube.com/results?search_query=" + encodeURIComponent(last_fm) +" - " + encodeURIComponent(ooo2), true);
2686+
2687
for (i = 0; i < data.length; i++) {
2688
    if (data[i].href.indexOf("about:/watch?v=") == 0) urls.push("http://www.youtube.com/" + data[i].href.replace(/about:\//,""));
2689
}
2690
2691
i=1;
2692
{
2693
2694
//do something with urls[i]
2695
p.console("" + urls[i]);
2696
2697
var tmppath = p.fso.GetFolder(fb.FoobarPath).ShortPath;
2698
var str = tmppath + "\\foobar2000.exe /add ";
2699
var go = str + urls[i];
2700
p.run(go);                 
2701
2702
}
2703
        
2704
                 
2705
             
2706
            
2707
                im.doc.close();
2708
                im.working=false;
2709
				im.update();
2710
				window.NotifyOthers("images", "update");
2711
				} else {
2712
					p.console("HTTP error: " + im.xmlhttp.status);
2713
				}
2714
			}
2715
		}
2716
	}
2717
}}}
2718
2719
2720
2721
//GENRE--------------------------------------------------------------------------------------------------
2722-
p.run(tmppath+"\\foobar2000.exe /add "+"\ " + urls[i] + "\"");                   
2722+
2723
//open Genre
2724
this.downloadGENRE2 = function()
2725
     {
2726
        {
2727
       
2728
        {
2729
        if (START_ARTIST.indexOf("*")== 0)
2730
   
2731
    
2732
    { var randomnumber=Math.floor(Math.random()*27)
2733
      var a=randomnumber;
2734
        this.working=true;
2735
        if (START_ARTIST == "" || START_ARTIST == "?") return;
2736
        //var folder = this.folder + "\\";
2737
		if (!this.xmlhttp) this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
2738
		this.xmlhttp.open("GET", "http://www.last.fm/music/+tag/" + encodeURIComponent(START_ARTIST).replace("*","") + "?page=" + a, true);
2739
		this.xmlhttp.send();
2740-
//open YT in playlist
2740+
2741-
//var tmppath = p.fso.GetFolder(fb.FoobarPath).ShortPath;
2741+
2742-
//p.run(tmppath+"\\foobar2000.exe /immediate /add "+"\""+urls[i] + "\"");
2742+
2743-
//fb.RunMainMenuCommand("File/Add Youtube URL(s)...") + ("/immediate /add "+"\""+ urls[i]);                       
2743+
2744
					if (!im.doc) im.doc = new ActiveXObject("htmlfile");
2745
					im.doc.open();
2746
					var div = im.doc.createElement("li");
2747
					div.innerHTML = text;
2748
					var data = div.getElementsByTagName("a");
2749
					var urls = [];
2750
    
2751
			
2752
2753
for (i = 0; i < data.length; i++) {
2754
     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]);   
2755
}
2756
2757
2758
//select random URL
2759
var randomnumber = Math.floor(Math.random()*(34-96)+96);
2760
do{
2761
randomnumber = Math.floor(Math.random()*(34-96)+96);
2762
} while(randomnumber%2!=0);
2763
2764
i=randomnumber;
2765
2766
{
2767
2768
if (urls[i] > "") 
2769
//p.console("" + urls[i]);
2770
{
2771
2772
last_fm = window.SetProperty("YT Similar", urls[i]);
2773
last_fm = urls[i];
2774
window.SetProperty("YT Similar", urls[i]);
2775
}
2776
else
2777
{
2778
last_fm = window.SetProperty("YT Similar", "");
2779
last_fm = "";
2780
window.SetProperty("YT Similar", "");
2781
}
2782
2783
}
2784
2785
                im.doc.close();
2786
                im.working=false;
2787
                if (last_fm == "" || last_fm == "?") {im.downloadGENRE2();}
2788
                else
2789
                im.downloadTRACK1();
2790
				} else {
2791
					p.console("HTTP error: " + im.xmlhttp.status);
2792
				    if (im.xmlhttp.status == 404)
2793
                    {im.downloadGENRE2();}
2794
                }
2795
			}
2796
		}
2797
	}
2798
}}                             
2799
2800
}
2801
2802
2803
2804
2805
this.update0 = function() {
2806
		this.index = 0;
2807
		for (i = 0; i < this.images.length; i++) {
2808
			try { this.images[i].Dispose(); } catch(e) {}
2809-
//i = Math.min(urls.length-38);
2809+
2810
		this.folders = this.folder.split("|");
2811
		this.files = [];
2812
		for (i = 0; i < this.folders.length; i++) {
2813
			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());
2814
		}
2815
		this.images = [];
2816
		for (i = 0; i < this.files.length; i++) {
2817-
p.run(tmppath+"\\foobar2000.exe /add "+"\ " + urls[i] + "\"");                   
2817+
2818
		}
2819
		if (typeof th == "object") {
2820
			th.nc = true;
2821
			th.calc();
2822
		}
2823
		window.Repaint();
2824
	}  
2825
    
2826-
//open YT in playlist
2826+
2827-
//var tmppath = p.fso.GetFolder(fb.FoobarPath).ShortPath;
2827+
2828-
//p.run(tmppath+"\\foobar2000.exe /immediate /add "+"\""+urls[i] + "\"");
2828+
2829-
//fb.RunMainMenuCommand("File/Add Youtube URL(s)...") + ("/immediate /add "+"\""+ urls[i]);                       
2829+
2830
		for (i = 0; i < this.images.length; i++) {
2831
			try { this.images[i].Dispose(); } catch(e) {}
2832
		}
2833
		this.folders = this.folder.split("|");
2834
		this.files = [];
2835
		for (i = 0; i < this.folders.length; i++) {
2836
			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());
2837
		}
2838
2839
		this.images = [];
2840
		for (i = 0; i < this.files.length; i++) {
2841
			this.images[i] = gdi.Image(this.files[i]);
2842
		}
2843
		if (typeof th == "object") {
2844
			th.nc = true;
2845
			th.calc();
2846
		}
2847
		window.Repaint();
2848
	}
2849
	
2850
	this.delete_image = function() {
2851
		if (!this.app) this.app = new ActiveXObject("Shell.Application");
2852
		this.app.Namespace(10).MoveHere(this.files[this.index]);
2853
        window.SetTimeout(function() {
2854
			im.update();
2855
			window.NotifyOthers("images", "update");
2856
		}, 100);
2857
	}
2858
	
2859
	this.x = x;
2860
	this.y = y;
2861
	this.w = w;
2862
	this.h = h;
2863
	this.files = [];
2864
	this.images = [];
2865
	this.index = 0;
2866
	this.artist = "";
2867
	this.folder = "";
2868
	this.limit = 0;
2869
	//this.cycle = window.GetProperty("image_cycle", 0);
2870
	this.mode = ("last.fm");
2871
    //window.GetProperty("image_mode", "last.fm");
2872
	this.type = "adjust";
2873
	this.auto_download = "off";
2874
	this.custom_folder_tf = "$directory_path(%path%)";
2875
}
2876
2877
function lastfm() {
2878
	this.notify_data = function(name, data) {
2879
		if (name == "lastfm" && data == "update") {
2880
			this.username = p.open(this.username_file).trim();
2881
			this.sk = p.open(this.sk_file).trim();
2882
			if (p.check_feature("lastfm_charts")) li.update();
2883
			if (typeof ps == "object") {
2884
				ps.loved_working = false;
2885
				ps.playcount_working = false;
2886
				b.update();
2887
				on_item_focus_change();
2888
			}
2889
			if (p.check_feature("lastfm")) {
2890
				li.artist = "";
2891
				on_item_focus_change();
2892
			}
2893
			if (p.check_feature("lastfm_album")) {
2894
				t.artist = "";
2895
				t.album = "";
2896
				on_item_focus_change();
2897
			}
2898
			window.Repaint();
2899
		}
2900
	}
2901
	
2902
	this.post = function(method, metadb) {
2903
		if (!this.xmlhttp) this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
2904
		switch(method) {
2905
			case "auth.getMobileSession":
2906
				var func = function() {
2907
					var json_data = p.json_parse(l.xmlhttp.responsetext);
2908
					if (!json_data) return;
2909
					if (json_data.error) {
2910
						p.MsgBox(json_data.message, 0, p.name);
2911
					} else if (json_data.session) {
2912
						p.save(json_data.session.key, l.sk_file);
2913
						window.NotifyOthers("lastfm", "update");
2914
						l.notify_data("lastfm", "update");
2915
					}
2916
				}
2917
				
2918
				this.authToken = hex_md5(this.username + hex_md5(this.password));
2919
				this.api_sig = hex_md5("api_key" + this.api_key + "authToken" + this.authToken + "method" + method + "username" + this.username + this.secret);
2920
				this.data = "method=" + method + "&api_key=" + this.api_key + "&api_sig=" + this.api_sig + "&format=json&authToken=" + this.authToken + "&username=" + this.username;
2921
				break;
2922
			case "track.love":
2923
			case "track.unlove":
2924
				var func = function() {
2925
					var json_data = p.json_parse(l.xmlhttp.responsetext);
2926
					if (!json_data) return;
2927
					if (json_data.error) {
2928
						p.console(json_data.message);
2929
					} else if (json_data.status && json_data.status == "ok") {
2930
						p.console("Track " + (method == "track.love" ? "loved successfully." : "unloved successfully."));
2931
						fb.RunContextCommandWithMetadb("Customdb Love " + (method == "track.love" ? 1 : 0), metadb, 8);
2932
					}
2933
				}
2934
				
2935
				if (!metadb || this.username.length == 0 || this.sk.length != 32) return;
2936
				this.artist = fb.TitleFormat(p.artist_tf).EvalWithMetadb(metadb);
2937
				this.track = fb.TitleFormat("%title%").EvalWithMetadb(metadb);
2938
				if (this.artist == "" || this.artist == "?" || this.track == "?") return;
2939
				p.console("Attempting to " + (method == "track.love" ? "love \"" : "unlove \"") + this.track + "\" by \"" + this.artist + "\"");
2940
				p.console("Contacting Last.fm....");
2941
				this.api_sig = hex_md5("api_key" + this.api_key + "artist" + this.artist + "method" + method + "sk" + this.sk + "track" + this.track + this.secret);
2942
				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);
2943
				break;
2944
			default:
2945
				return;
2946
		}
2947
		
2948
		this.xmlhttp.open("POST", "https://ws.audioscrobbler.com/2.0/", true);
2949
		this.xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
2950
		this.xmlhttp.setRequestHeader("User-Agent", this.user_agent);
2951
		this.xmlhttp.send(this.data);
2952
		this.xmlhttp.onreadystatechange = function() {
2953
			if (l.xmlhttp.readyState == 4) {
2954
				if (l.xmlhttp.status == 200) {
2955
					func();
2956
				} else {
2957
					p.console(l.xmlhttp.responsetext || "HTTP error: " + l.xmlhttp.status);
2958
				}
2959
			}
2960
		}
2961
	}
2962
	
2963
	this.update_username = function() {
2964
		var old_username = this.username;
2965
		this.username = p.InputBox("Enter your Last.fm username.", p.name, this.username);
2966
		if (this.username.length > 0 && this.username != old_username) p.save("", this.sk_file);
2967
		p.save(this.username, this.username_file);
2968
		window.NotifyOthers("lastfm", "update");
2969
		this.notify_data("lastfm", "update");
2970
	}
2971
	
2972
	this.update_password = function() {
2973
		this.password = p.InputBox("Enter your Last.fm password\n\nThis is only required to love/unlove tracks.", p.name, "");
2974
		if (this.password.length > 0) {
2975
			this.sk = "";
2976
			p.save(this.sk, this.sk_file);
2977
			window.NotifyOthers("lastfm", "update");
2978
			this.notify_data("lastfm", "update");
2979
			this.post("auth.getMobileSession");
2980
		}
2981
	}
2982
	
2983
	this.get_url = function() {
2984
		return "http://ws.audioscrobbler.com/2.0/?format=json&api_key=" + this.api_key + "&user=" + this.username + "&username=" + this.username + "&s=" + Math.random();
2985
	}
2986
	
2987
	this.username_error = "Use the right click menu to set your Last.fm username.";
2988
	this.password_error = "Use the right click menu to set your Last.fm password.";
2989
	this.url = "http://www.last.fm/";
2990
	this.api_key = "56d9e050cc2d6b36102c8b4a5fe6152d";
2991
	this.secret = "9f1f4346ce3ba206390074ff8cb4c6ce";
2992
	this.user_agent = "foobar2000_wsh_panel_mod_scripts";
2993
	this.username_file = p.settings_folder + "username";
2994
	this.username = p.open(this.username_file).trim();
2995
	this.sk_file = p.settings_folder + "sk";
2996
	this.sk = p.open(this.sk_file).trim();
2997
	this.auto_correct = window.GetProperty("lastfm_auto_correct", true);
2998
}
2999
3000
function list(x, y, w, h) {
3001
	this.size = function() {
3002
		this.row_height = this.mode == "echonest" ? 90 : 20;
3003
		this.rows = Math.floor((this.h - (this.mode == "echonest" ? 50 : 30)) / this.row_height);
3004
		this.index = 0;
3005
		this.offset = 0;
3006
		switch(true) {
3007
			case this.mode == "lastfm_charts":
3008
				this.text_width = Math.round(this.w / 3);
3009
				this.lastfm_charts_bar_x = this.text_width + 30;
3010
				break;
3011
			case this.mode == "musicbrainz" && this.musicbrainz_mode == "releases":
3012
				this.text_width = this.w - 120;
3013
				break;
3014
			default:
3015
				this.text_width = this.w - 50;
3016
				break;
3017
		}
3018
		this.but_x = this.x + Math.round((this.w - 15) / 2);
3019
		this.up_btn = new sb(this.but_x, this.y, 15, 15, p.up_img, "li.offset > 0", function() { li.wheel(1); });
3020
		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); });
3021
	}
3022
	
3023
	this.draw = function(gr) {
3024
		switch(this.mode) {
3025
			case "discogs":
3026
				for (i = 0; i < Math.min(this.items, this.rows); i++) {
3027
					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);
3028
					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);
3029
				}
3030
				break;
3031
			case "lastfm_charts":
3032
				var max_bar_width = (this.w - this.lastfm_charts_bar_x - 40) / this.playcounts[0];
3033
				for (i = 0; i < Math.min(this.items, this.rows); i++) {
3034
					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);
3035
					var bar_width = max_bar_width * this.playcounts[i + this.offset];
3036
					var bar_colour = p.splitRGB(this.lastfm_charts_bar_colour);
3037
					gr.FillSolidRect(this.lastfm_charts_bar_x + this.x, this.y + 16 + (i * this.row_height), bar_width, 18, bar_colour);
3038
					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);
3039
					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);
3040
				}
3041
				break;
3042
			case "lastfm":
3043
				for (i = 0; i < Math.min(this.items, this.rows); i++) {
3044
					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");
3045
					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");
3046
					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);
3047
				}
3048
				break;
3049
			case "musicbrainz":
3050
				for (i = 0; i < Math.min(this.items, this.rows); i++) {
3051
					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");
3052
					if (this.musicbrainz_mode == "releases") {
3053
						p.draw_image(gr, this.autoplaylist_img, this.x, this.y + 16 + (i * this.row_height), 16, 16, "adjust");
3054
						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);
3055
						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);
3056
					}
3057
					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);
3058
				}
3059
				break;
3060
			case "autoplaylists":
3061
				for (i = 0; i < Math.min(this.items, this.rows); i++) {
3062
					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);
3063
					if (!this.autoplaylists_editing && this.autoplaylists_hover && this.index == i + this.offset) {
3064
						p.draw_image(gr, this.autoplaylists_edit_img, this.x + this.w - 40, this.y + 16 + (i * this.row_height), 16, 16, "adjust");
3065
						p.draw_image(gr, this.autoplaylists_del_img, this.x + this.w - 20, this.y + 16 + (i * this.row_height), 16, 16, "adjust");
3066
					}
3067
				}
3068
				break;
3069
			case "echonest":
3070
				for (i = 0; i < Math.min(this.items, this.rows); i++) {
3071
					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);
3072
					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);
3073
					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);
3074
				}
3075
				break;
3076
		}
3077
		this.up_btn.draw(gr);
3078
		this.down_btn.draw(gr);
3079
		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);
3080
	}
3081
	
3082
	this.metadb_changed = function() {
3083
		p.artist = p.eval(p.artist_tf);
3084
		if (this.artist == p.artist) return false;
3085
		this.artist = p.artist;
3086
		this.folder = p.data_folder + p.artist_tf;
3087
		//if (!p.fso.FolderExists(this.folder)) p.fso.CreateFolder(this.folder);
3088
		this.update();
3089
		return true;
3090
	}
3091
	
3092
	this.trace = function(x, y) {
3093
		return (x > this.x && x < this.x + this.w && y > this.y && y < this.y + this.h);
3094
	}
3095
	
3096
	this.wheel = function(step) {
3097
		if (!this.trace(p.mx, p.my)) return false;
3098
		if (this.items > this.rows) {
3099
			this.offset -= step * (this.mode == "echonest" ? 1 : 3);
3100
			if (this.offset < 0) this.offset = 0;
3101
			if (this.rows + this.offset > this.items) this.offset = this.items - this.rows;
3102
			window.RepaintRect(this.x, this.y, this.w, this.h);
3103
		}
3104
		return true;
3105
	}
3106
	
3107
	this.move = function(x, y) {
3108
		this.index = Math.floor((y - this.y - 15) / this.row_height) + this.offset;
3109
		this.in_range = this.index >= this.offset && this.index < this.offset + Math.min(this.rows, this.items);
3110
		switch(true) {
3111
			case !this.trace(x, y):
3112
			case this.mode == "autoplaylists" && this.autoplaylists_editing:
3113
			case this.mode == "lastfm" && l.username.length == 0:
3114
				window.SetCursor(IDC_ARROW);
3115
				this.leave();
3116
				return false;
3117
			case this.up_btn.trace(x, y):
3118
			case this.down_btn.trace(x, y):
3119
				window.SetCursor(IDC_HAND);
3120
				break;
3121
			case !this.in_range:
3122
				window.SetCursor(IDC_ARROW);
3123
				this.leave();
3124
				break;
3125
			case this.mode == "musicbrainz" && this.musicbrainz_mode == "releases" && x > this.x && x < this.x + 20:
3126
			case this.mode == "lastfm" && this.text_x == 20 && x > this.x && x < this.x + 20:
3127
				window.SetCursor(IDC_HAND);
3128
				switch(true) {
3129
					case this.lastfm_mode == 0 && this.lastfm_button == "spotify":
3130
						p.tt('spotify:search:"' + this.names[this.index].replace(/\s+/g, "+") + '"');
3131
						break;
3132
					default:
3133
						p.tt("Autoplaylist: " + this.queries[this.index]);
3134
						break;
3135
				}
3136
				break;
3137
			case this.mode == "autoplaylists":
3138
				switch(true) {
3139
					case x > this.x && x < this.x + Math.min(this.names_widths[this.index], this.text_width):
3140
						window.SetCursor(IDC_HAND);
3141
						p.tt('Run "' + this.names[this.index] + '"');
3142
						break;
3143
					case x > this.x + this.w - 40 && x < this.x + this.w - 20:
3144
						window.SetCursor(IDC_HAND);
3145
						p.tt('Edit "' + this.names[this.index] + '"');
3146
						break;
3147
					case x > this.x + this.w - 20 && x < this.x + this.w:
3148
						window.SetCursor(IDC_HAND);
3149
						p.tt('Delete "' + this.names[this.index] + '"');
3150
						break;
3151
					default:
3152
						window.SetCursor(IDC_ARROW);
3153
						this.leave();
3154
						break;
3155
				}
3156
				this.autoplaylists_hover = true;
3157
				window.RepaintRect(this.x + this.w - 40, this.y + 15, 40, Math.min(this.rows, this.items) * this.row_height);
3158
				break;
3159
			case this.mode == "echonest":
3160
			case x > this.x + this.text_x && x < this.x + this.text_x + Math.min(this.names_widths[this.index], this.text_width):
3161
				window.SetCursor(IDC_HAND);
3162
				p.tt(this.urls[this.index]);
3163
				break;
3164
			default:
3165
				window.SetCursor(IDC_ARROW);
3166
				p.ttd();
3167
				break;
3168
		}
3169
		return true;
3170
	}
3171
	
3172
	this.lbtn_up = function(x, y) {
3173
		switch(true) {
3174
			case !this.trace(x, y):
3175
				return false;
3176
			case this.mode == "autoplaylists" && this.autoplaylists_editing:
3177
			case this.mode == "lastfm" && l.username.length == 0:
3178
			case this.up_btn.lbtn_up(x, y):
3179
			case this.down_btn.lbtn_up(x, y):
3180
			case !this.in_range:
3181
				break;
3182
			case this.mode == "musicbrainz" && this.musicbrainz_mode == "releases" && x > this.x && x < this.x + 20:
3183
			case this.mode == "lastfm" && this.text_x == 20 && x > this.x && x < this.x + 20:
3184
				switch(true) {
3185
					case this.lastfm_mode == 0 && this.lastfm_button == "spotify":
3186
						if (p.run('spotify:search:"' + this.names[this.index].replace(/\s+/g, "+") + '"')) {
3187
							if (fb.IsPlaying && !fb.IsPaused && this.lastfm_pause) fb.Pause();
3188
						} else {
3189
							p.MsgBox("Unable to launch Spotify.", 0, p.name);
3190
						}
3191
						break;
3192
					default:
3193
						fb.CreateAutoPlaylist(fb.PlaylistCount, this.names[this.index], this.queries[this.index]);
3194
						fb.ActivePlaylist = fb.PlaylistCount - 1;
3195
						break;
3196
				}
3197
				break;
3198
			case this.mode == "autoplaylists":
3199
				switch(true) {
3200
					case x > this.x && x < this.x + Math.min(this.names_widths[this.index], this.text_width):
3201
						this.autoplaylists_run(this.names[this.index], this.queries[this.index], this.sorts[this.index], this.forced[this.index]);
3202
						break;
3203
					case x > this.x + this.w - 40 && x < this.x + this.w - 20:
3204
						this.autoplaylists_edit(x, y);
3205
						break;
3206
					case x > this.x + this.w - 20 && x < this.x + this.w:
3207
						this.autoplaylists_delete();
3208
						break
3209
				}
3210
				break;
3211
			case this.mode == "echonest":
3212
			case x > this.x + this.text_x && x < this.x + this.text_x + Math.min(this.names_widths[this.index], this.text_width):
3213
				p.browser(this.urls[this.index]);
3214
				break;
3215
		}
3216
		return true;
3217
	}
3218
	
3219
	this.leave = function() {
3220
		p.ttd();
3221
		if (this.mode != "autoplaylists") return;
3222
		this.autoplaylists_hover = false;
3223
		window.RepaintRect(this.x, this.y, this.w, this.h);
3224
	}
3225
	
3226
	this.update = function() {
3227
		this.items = 0;
3228
		this.offset = 0;
3229
		this.index = 0;
3230
		this.names = [];
3231
		this.names_widths = [];
3232
		this.urls = [];
3233
		this.dates = [];
3234
		this.queries = [];
3235
		this.ranks = [];
3236
		this.playcounts = [];
3237
		this.sorts = [];
3238
		this.summaries = [];
3239
		this.release_types = [];
3240
		this.images = [];
3241
		this.forced = [];
3242
		this.data = [];
3243
		this.file = null;
3244
		this.date = "";
3245
		var temp_bmp = gdi.CreateImage(1, 1);
3246
		var temp_gr = temp_bmp.GetGraphics();
3247
		switch(this.mode) {
3248
			case "autoplaylists":
3249
				this.text = p.open(this.filename);
3250
				this.data = this.text.split(/\r?\n/g);
3251
				this.items = this.data.length;
3252
				for (i = 0; i < this.items; i++) {
3253
					var temp = this.data[i].split("¬");
3254
					this.names[i] = temp[0];
3255
					this.queries[i] = temp[1];
3256
					this.sorts[i] = temp[2];
3257
					this.forced[i] = temp[3];
3258
					this.names_widths[i] = temp_gr.CalcTextWidth(this.names[i], p.list_font);
3259
				}
3260
				break;
3261
			case "lastfm":
3262
				this.text_x = 20;
3263
				this.filename = this.folder + "\\" + this.lastfm_methods[this.lastfm_mode] + ".json";
3264
				if (p.fso.fileExists(this.filename)) {
3265
					this.file = p.fso.Getfile(this.filename);
3266
					this.json_text = p.open(this.filename);
3267
					this.json_data = p.json_parse(this.json_text);
3268
					if (this.json_data) {
3269
						switch(true) {
3270
							case this.json_data.error > 0:
3271
								p.console(this.json_data.message);
3272
								break;
3273
							case this.lastfm_mode == 0 && this.json_data.similarartists && typeof this.json_data.similarartists.artist == "object":
3274
								this.data = this.json_data.similarartists.artist;
3275
								break;
3276
							case this.lastfm_mode == 1 && this.json_data.toptags && typeof this.json_data.toptags.tag == "object":
3277
								this.data = this.json_data.toptags.tag;
3278
								break;
3279
							case this.lastfm_mode == 2 && this.json_data.topfans && typeof this.json_data.topfans.user == "object":
3280
								this.text_x = 0;
3281
								this.data = this.json_data.topfans.user;
3282
								break;
3283
							case this.lastfm_mode == 3 && this.json_data.topalbums && typeof this.json_data.topalbums.album == "object":
3284
								this.data = this.json_data.topalbums.album;
3285
								break;
3286
							case this.lastfm_mode == 4 && this.json_data.toptracks && typeof this.json_data.toptracks.track == "object":
3287
								this.data = this.json_data.toptracks.track;
3288
								break;
3289
						}
3290
						this.items = this.data.length;
3291
						for (i = 0; i < this.items; i++) {
3292
							this.names[i] = this.data[i].name;
3293
							this.urls[i] = this.data[i].url;
3294
							this.names_widths[i] = temp_gr.CalcTextWidth(this.names[i], p.list_font);
3295
							if (this.lastfm_mode == 0) this.queries[i] = "artist HAS " + this.names[i];
3296
							if (this.lastfm_mode == 1) this.queries[i] = "genre HAS " + this.names[i];
3297
							if (this.lastfm_mode == 3) this.queries[i] = "album HAS " + this.names[i] + " OR title HAS " + this.names[i];
3298
							if (this.lastfm_mode == 4) this.queries[i] = "title HAS " + this.names[i];
3299
						}
3300
					}
3301
					if (Date.parse(Date()) - Date.parse(this.file.DateLastModified) > ONE_DAY) this.get();
3302
				} else {
3303
					this.get();
3304
				}
3305
				break;
3306
			case "lastfm_charts":
3307
				this.filename = this.folder + "\\" + l.username + "_" + this.lastfm_charts_modes[this.lastfm_charts_mode] + "_" + this.lastfm_charts_periods[this.lastfm_charts_period] + ".json";
3308
				if (p.fso.fileExists(this.filename)) {
3309
					this.file = p.fso.Getfile(this.filename);
3310
					this.json_text = p.open(this.filename);
3311
					this.json_data = p.json_parse(this.json_text);
3312
					if (this.json_data) {
3313
						switch(true) {
3314
							case this.json_data.error > 0:
3315
								p.console(this.json_data.message);
3316
								break;
3317
							case this.lastfm_charts_mode == 0 && this.json_data.topartists && typeof this.json_data.topartists.artist == "object":
3318
								this.data = this.json_data.topartists.artist;
3319
								break;
3320
							case this.lastfm_charts_mode == 1 && this.json_data.topalbums && typeof this.json_data.topalbums.album == "object":
3321
								this.data = this.json_data.topalbums.album;
3322
								break;
3323
							case this.lastfm_charts_mode == 2 && this.json_data.toptracks && typeof this.json_data.toptracks.track == "object":
3324
								this.data = this.json_data.toptracks.track;
3325
								break;
3326
						}
3327
						this.items = this.data.length;
3328
						for (i = 0; i < this.items; i++) {
3329
							this.names[i] = this.lastfm_charts_mode != 0 ? this.data[i].artist.name + " - " + this.data[i].name : this.data[i].name;
3330
							this.ranks[i] = (i > 0 && this.data[i].playcount == this.data[i - 1].playcount) ? this.ranks[i - 1] : this.data[i]["@attr"].rank;
3331
							this.urls[i] = this.data[i].url;
3332
							this.names_widths[i] = temp_gr.CalcTextWidth(this.names[i], p.list_font);
3333
							this.playcounts[i] = this.data[i].playcount;
3334
						}
3335
					}
3336
					if (Date.parse(Date()) - Date.parse(this.file.DateLastModified) > ONE_DAY) this.get();
3337
				} else {
3338
					this.get();
3339
				}
3340
				break;
3341
			case "discogs":
3342
				this.filename = this.folder + "\\discogs.json";
3343
				if (p.fso.fileExists(this.filename)) {
3344
					this.file = p.fso.Getfile(this.filename);
3345
					this.json_text = p.open(this.filename);
3346
					this.json_data = p.json_parse(this.json_text);
3347
					if (this.json_data && this.json_data.results) {
3348
						this.data = this.json_reverse_sort(this.json_data.results, "year");
3349
						var swap_artist = fb.TitleFormat("$swapprefix($lower(" + p.artist + ")) - ").Eval(true);
3350
						for (i = 0; i < this.data.length; i++) {
3351
							var temp_artist = this.data[i].title.replace(/\s{2,}/g,' ');
3352
							if (this.discogs_match && temp_artist.toLowerCase().indexOf(swap_artist) != 0) continue;
3353
							this.dates.push(this.data[i].year || "");
3354
							this.urls.push("http://www.discogs.com" + this.data[i].uri);
3355
							this.names.push(temp_artist);
3356
							this.names_widths.push(temp_gr.CalcTextWidth(temp_artist, p.list_font));
3357
						}
3358
						this.items = this.names.length;
3359
					}
3360
					if (Date.parse(Date()) - Date.parse(this.file.DateLastModified) > ONE_DAY) this.get();
3361
				} else {
3362
					this.get();
3363
				}
3364
				break;
3365
			case "musicbrainz":
3366
				this.filename = this.folder + "\\musicbrainz_" + this.musicbrainz_mode + ".json";
3367
				if (p.fso.fileExists(this.filename)) {
3368
					this.file = p.fso.Getfile(this.filename);
3369
					this.json_text = p.open(this.filename);
3370
					this.json_data = p.json_parse(this.json_text);
3371
					if (this.json_data) {
3372
						switch(this.musicbrainz_mode) {
3373
							case "releases":
3374
								this.data = this.json_data["release-groups"] || [];
3375
								this.data = this.json_reverse_sort(this.data, "first-release-date");
3376
								var primary, secondary, name;
3377
								for (i = 0; i < this.data.length; i++) {
3378
									primary = this.data[i]["primary-type"];
3379
									secondary = this.data[i]["secondary-types"].join("").toLowerCase();
3380
									switch(true) {
3381
										case !this.musicbrainz_remix && secondary.indexOf("remix") > -1:
3382
										case !this.musicbrainz_compilation && secondary.indexOf("compilation") > -1:
3383
										case !this.musicbrainz_live && secondary.indexOf("live") > -1:
3384
											break;
3385
										case this.musicbrainz_single && primary == "Single":
3386
										case this.musicbrainz_ep && primary == "EP":
3387
										case this.musicbrainz_album && primary == "Album":
3388
											name = this.data[i].title;
3389
											this.dates.push(this.data[i]["first-release-date"].substring(0,4));
3390
											this.names.push(name);
3391
											this.urls.push("http://musicbrainz.org/release-group/" + this.data[i].id);
3392
											this.names_widths.push(temp_gr.CalcTextWidth(name, p.list_font));
3393
											this.queries.push("album HAS " + name + " OR title HAS " + name);
3394
											switch(true) {
3395
												case secondary.indexOf("remix") > -1:
3396
													this.release_types.push("Remix");
3397
													break;
3398
												case secondary.indexOf("compilation") > -1:
3399
													this.release_types.push("Compilation");
3400
													break;
3401
												case secondary.indexOf("live") > -1:
3402
													this.release_types.push("Live");
3403
													break;
3404
												default:
3405
													this.release_types.push(primary);
3406
													break;
3407
											}
3408
									}
3409
								}
3410
								this.items = this.names.length;
3411
								break;
3412
							case "URLs":
3413
								this.data = this.json_data.relations || [];
3414
								this.items = this.data.length;
3415
								for (i = 0; i < this.items; i++) {
3416
									this.urls[i] = this.data[i].url.resource;
3417
									this.images[i] = "";
3418
									if (this.data[i].type == "official homepage") {
3419
										this.images[i] = "home";
3420
									} else {
3421
										for (name in this.musicbrainz_images) {
3422
											if (this.urls[i].indexOf(name) > -1) {
3423
												this.images[i] = name;
3424
												break;
3425
											}
3426
										}
3427
										if (this.images[i].length == 0) this.images[i] = "external";
3428
									}
3429
									this.names[i] = decodeURIComponent(this.urls[i]);
3430
									this.names_widths[i] = temp_gr.CalcTextWidth(this.names[i], p.list_font);
3431
								}
3432
								break;
3433
						}
3434
					}
3435
					if (Date.parse(Date()) - Date.parse(this.file.DateLastModified) > ONE_DAY) this.get();
3436
				} else {
3437
					this.get();
3438
				}
3439
				break;
3440
			case "echonest":
3441
				this.filename = this.folder + "\\echonest_" + this.echonest_modes[this.echonest_mode] + ".json";
3442
				if (p.fso.fileExists(this.filename)) {
3443
					this.file = p.fso.Getfile(this.filename);
3444
					this.json_text = p.open(this.filename);
3445
					this.json_data = p.json_parse(this.json_text);
3446
					if (this.json_data && this.json_data.response && this.json_data.response.status && this.json_data.response.status.code == 0) {
3447
						this.data = this.json_data.response[this.echonest_modes[this.echonest_mode]] || [];
3448
						this.items = this.data.length;
3449
						for (i = 0; i < this.items; i++) {
3450
							this.names[i] = p.strip_tags(this.data[i].name);
3451
							this.urls[i] = (this.data[i].url || "").replace(/\\/g, "");
3452
							this.temp_date = (this.data[i].date_posted || this.data[i].date_reviewed || this.data[i].date_found || "").substring(0, 10);
3453
							this.dates[i] = this.temp_date.substring(8,10) + "-" + this.temp_date.substring(5,7) + "-" + this.temp_date.substring(0,4);
3454
							this.summaries[i] = p.strip_tags(this.data[i].summary);
3455
						}
3456
					}
3457
					if (Date.parse(Date()) - Date.parse(this.file.DateLastModified) > ONE_DAY) this.get();
3458
				} else {
3459
					this.get();
3460
				}
3461
				break;
3462
		}
3463
		temp_bmp.ReleaseGraphics(temp_gr);
3464
		temp_bmp.Dispose();
3465
		temp_gr = null;
3466
		temp_bmp = null;
3467
		if (this.file) {
3468
			var temp_date = new Date(this.file.DateLastModified);
3469
			this.date = "Updated: " + temp_date.toLocaleTimeString() + ", " + temp_date.toLocaleDateString();
3470
		}
3471
		window.Repaint();
3472
	}
3473
	
3474
	this.get = function() {
3475
		var fn = this.filename;
3476
		var func = function() {
3477
			if (!p.save(li.xmlhttp.responsetext, fn)) return;
3478
			li.update();
3479
		}
3480
		var url = "";
3481
		var user_agent = "";
3482
		switch(this.mode) {
3483
			case "discogs":
3484
				if (this.artist == "" || this.artist == "?") return;
3485
				url = "http://api.discogs.com/database/search?per_page=100&type=master&artist=" + encodeURIComponent(this.artist);
3486
				user_agent = "foobar2000_wsh_panel_mod_discogs +http://www.hydrogenaudio.org/forums/index.php?showuser=19379";
3487
				break;
3488
			case "lastfm_charts":
3489
				if (l.username.length == 0) return(p.console(l.username_error));
3490
				url = l.get_url() + "&method=user." + this.lastfm_charts_methods[this.lastfm_charts_mode] + "&period=" + this.lastfm_charts_periods[this.lastfm_charts_period];
3491
				user_agent = l.user_agent;
3492
				break;
3493
			case "lastfm":
3494
				if (this.artist == "" || this.artist == "?") return;
3495
				if (l.username.length == 0) return(p.console(l.username_error));
3496
				url = l.get_url() + "&method=" + this.lastfm_methods[this.lastfm_mode] + "&artist=" + encodeURIComponent(this.artist) + "&autocorrect=" + (l.auto_correct ? 1 : 0);
3497
				user_agent = l.user_agent;
3498
				break;
3499
			case "musicbrainz":
3500
				user_agent = "foobar2000_wsh_panel_mod_musicbrainz +http://www.hydrogenaudio.org/forums/index.php?showuser=19379";
3501
				var fn1 = this.folder + "\\MUSICBRAINZ_ARTISTID.txt";
3502
				this.musicbrainz_id = p.eval("$if3(%musicbrainz_artistid%,%musicbrainz artist id%,)");
3503
				this.musicbrainz_id = this.musicbrainz_id.substring(0, 36);
3504
				if (this.musicbrainz_id.length == 0) this.musicbrainz_id = p.open(fn1);
3505
				if (this.musicbrainz_id.length == 0) {
3506
					if (this.artist == "" || this.artist == "?") return;
3507
					url = "https://musicbrainz.org/ws/2/artist/?query=artist:" + encodeURIComponent(this.artist.toLowerCase()) + "&fmt=json";
3508
					var func = function() {
3509
						var json_data = p.json_parse(li.xmlhttp.responsetext);
3510
						if (!json_data) return;
3511
						var artist = li.artist.toLowerCase();
3512
						var artists = json_data.artist || [];
3513
						for (i = 0; i < artists.length; i++) {
3514
							if (artist == artists[i].name.toLowerCase()) {
3515
								if (!p.save(artists[i].id, fn1)) return;
3516
								li.get();
3517
								break;
3518
							}
3519
						}
3520
					}
3521
				} else {
3522
					if (this.musicbrainz_mode == "releases") url = "https://musicbrainz.org/ws/2/release-group?artist=" + this.musicbrainz_id + "&limit=100&offset=0&fmt=json";
3523
					else url = "https://musicbrainz.org/ws/2/artist/" + this.musicbrainz_id + "?inc=url-rels&fmt=json";
3524
				}
3525
				break;
3526
			case "echonest":
3527
				if (this.artist == "" || this.artist == "?") return;
3528
				url = "http://developer.echonest.com/api/v4/artist/" + this.echonest_modes[this.echonest_mode] + "/?name=" + encodeURIComponent(this.artist) + "&api_key=EKWS4ESQLKN3G2ZWV";
3529
				break;
3530
		}
3531
		if (url.length == 0) return;
3532
		this.xmlhttp.open("GET", url, true);
3533
		if (user_agent.length > 0) this.xmlhttp.setRequestHeader('User-Agent', user_agent);
3534
		this.xmlhttp.send();
3535
		this.xmlhttp.onreadystatechange = function() {
3536
			if (li.xmlhttp.readyState == 4) {
3537
				if (li.xmlhttp.status == 200) {
3538
					func();
3539
				} else {
3540
					p.console(li.xmlhttp.responsetext || "HTTP error: " + li.xmlhttp.status);
3541
				}
3542
			}
3543
		}
3544
	}
3545
	
3546
	this.json_reverse_sort = function(data, prop) {
3547
		data = data.sort(function(a, b) {
3548
			if (!a[prop] || b[prop] > a[prop]) return 1;
3549
			if (!b[prop] || b[prop] < a[prop]) return -1;
3550
			return 0;
3551
		});
3552
		return data;
3553
	}
3554
	
3555
	this.init = function() {
3556
		switch(true) {
3557
			case p.check_feature("discogs"):
3558
				this.mode = "discogs";
3559
				this.discogs_match = window.GetProperty("discogs_match", false);
3560
				break;
3561
			case p.check_feature("lastfm_charts"):
3562
				this.mode = "lastfm_charts";
3563
				this.text_x = 20;
3564
				this.lastfm_charts_modes = ["artist", "album", "track"];
3565
				this.lastfm_charts_mode = window.GetProperty("lastfm_charts_mode", 0);
3566
				this.lastfm_charts_methods = ["getTopArtists", "getTopAlbums", "getTopTracks"];
3567
				this.lastfm_charts_periods_display = ["overall", "last 7 days", "1 month", "3 month", "6 month", "12 month"];
3568
				this.lastfm_charts_periods = ["overall", "7day", "1month", "3month", "6month", "12month"];
3569
				this.lastfm_charts_period = window.GetProperty("lastfm_charts_period", 0);
3570
				this.lastfm_charts_bar_colour = window.GetProperty("lastfm_charts_bar_colour", "72-127-221");
3571
				this.folder = p.data_folder + "charts";
3572
				//if (!p.fso.FolderExists(this.folder)) p.fso.CreateFolder(this.folder);
3573
				break;
3574
			case p.check_feature("lastfm"):
3575
				this.mode = "lastfm";
3576
				this.lastfm_methods = ["artist.getSimilar", "artist.getTopTags", "artist.getTopFans", "artist.getTopAlbums", "artist.getTopTracks"];
3577
				this.lastfm_modes = ["similar artists", "top tags", "top fans", "top albums", "top tracks"];
3578
				this.lastfm_mode = window.GetProperty("lastfm_mode", 0);
3579
				this.lastfm_button = window.GetProperty("lastfm_button", "spotify");
3580
				this.lastfm_pause = window.GetProperty("lastfm_pause", true);
3581
				this.lastfm_spotify_img = gdi.Image(p.images_path + "spotify.png");
3582
				break;
3583
			case p.check_feature("musicbrainz"):
3584
				this.mode = "musicbrainz";
3585
				this.text_x = 20;
3586
				this.musicbrainz_images = {
3587
					"viaf.org": gdi.Image(p.images_path + "viaf_small.png"),
3588
					"allmusic.com": gdi.Image(p.images_path + "allmusic_small.png"),
3589
					"external": gdi.Image(p.images_path + "external_small.png"),
3590
					"bbc.co.uk": gdi.Image(p.images_path + "bbc_small.png"),
3591
					"facebook.com": gdi.Image(p.images_path + "facebook_small.png"),
3592
					"home": gdi.Image(p.images_path + "home_small.png"),
3593
					"last.fm": gdi.Image(p.images_path + "lastfm_small.png"),
3594
					"twitter.com": gdi.Image(p.images_path + "twitter_small.png"),
3595
					"soundcloud.com": gdi.Image(p.images_path + "soundcloud_small.png"),
3596
					"wikipedia.org": gdi.Image(p.images_path + "wikipedia_small.png"),
3597
					"discogs.com": gdi.Image(p.images_path + "discogs_small.png"),
3598
					"myspace.com": gdi.Image(p.images_path + "myspace_small.png"),
3599
					"youtube.com": gdi.Image(p.images_path + "youtube_small.png"),
3600
					"imdb.com": gdi.Image(p.images_path + "imdb_small.png"),
3601
					"plus.google.com": gdi.Image(p.images_path + "google_plus_small.png"),
3602
					"lyrics.wikia.com": gdi.Image(p.images_path + "lyrics_wikia_small.png"),
3603
					"flickr.com": gdi.Image(p.images_path + "flickr_small.png"),
3604
					"secondhandsongs.com": gdi.Image(p.images_path + "secondhandsongs_small.png"),
3605
					"vimeo.com": gdi.Image(p.images_path + "vimeo_small.png"),
3606
					"rateyourmusic.com": gdi.Image(p.images_path + "rateyourmusic_small.png"),
3607
					"instagram.com": gdi.Image(p.images_path + "instagram_small.png"),
3608
					"tumblr.com": gdi.Image(p.images_path + "tumblr_small.png"),
3609
					"decoda.com": gdi.Image(p.images_path + "decoda_small.png"),
3610
					"wikidata.org": gdi.Image(p.images_path + "wikidata_small.png")
3611
				}
3612
				this.musicbrainz_mode = window.GetProperty("musicbrainz_mode", "releases");
3613
				this.musicbrainz_show_release_type = window.GetProperty("musicbrainz_show_release_type", true);
3614
				this.musicbrainz_live = window.GetProperty("musicbrainz_live", false);
3615
				this.musicbrainz_ep = window.GetProperty("musicbrainz_ep", true);
3616
				this.musicbrainz_single = window.GetProperty("musicbrainz_single", true);
3617
				this.musicbrainz_album = window.GetProperty("musicbrainz_album", true);
3618
				this.musicbrainz_remix = window.GetProperty("musicbrainz_remix", true);
3619
				this.musicbrainz_compilation = window.GetProperty("musicbrainz_compilation", true);
3620
				break;
3621
			case p.check_feature("echonest"):
3622
				this.mode = "echonest";
3623
				this.echonest_modes = ["news", "reviews", "blogs"];
3624
				this.echonest_mode = window.GetProperty("echonest_mode", 0);
3625
				break;
3626
			case p.check_feature("autoplaylists"):
3627
				this.autoplaylists_add = function() {
3628
					if (this.autoplaylists_editing) return;
3629
					this.autoplaylists_editing = true;
3630
					var new_name = p.InputBox("Enter a name for your autoplaylist", p.name, "");
3631
					if (new_name == "") { this.autoplaylists_editing = false; return; }
3632
					var new_query = p.InputBox("Enter your autoplaylist query", p.name, "");
3633
					if (new_query == "") { this.autoplaylists_editing = false; return; }
3634
					var new_sort = p.InputBox("Enter a sort pattern\n\n(optional)", p.name, "");
3635
					var new_force = new_sort.length > 0 ? p.MsgBox("Force sort?", 4, p.name) : 7;
3636
					this.data.push(new_name + "¬" + new_query + "¬" + new_sort + "¬" + new_force);
3637
					if (this.data.length > this.rows) this.offset = this.data.length - this.rows;
3638
					p.save(this.data.join("\n"), this.filename);
3639
					if (this.autoplaylists_success) this.autoplaylists_run(new_name, new_query, new_sort, new_force);
3640
					window.NotifyOthers("autoplaylists", "update");
3641
					this.update();
3642
					this.autoplaylists_editing = false;
3643
				}
3644
				
3645
				this.autoplaylists_run = function(n, q, s, f) {
3646
					if (this.autoplaylists_remove_duplicates) {
3647
						i = 0;
3648
						while(i < fb.PlaylistCount) {
3649
							if (fb.GetPlaylistName(i) == n) fb.RemovePlaylist(i);
3650
							else i++;
3651
						}
3652
					}
3653
					fb.CreateAutoPlaylist(fb.PlaylistCount, n, q, s, f == 6 ? true : false);
3654
					fb.ActivePlaylist = fb.PlaylistCount - 1;
3655
				}
3656
				
3657
				this.autoplaylists_edit = function(x, y) {
3658
					var _menu = window.CreatePopupMenu();
3659
					var i = this.index;
3660
					_menu.AppendMenuItem(MF_STRING, 1, "Rename...");
3661
					_menu.AppendMenuItem(MF_STRING, 2, "Edit query...");
3662
					_menu.AppendMenuItem(MF_STRING, 3, "Edit sort pattern...");
3663
					_menu.AppendMenuItem(MF_STRING, 4, "Force Sort");
3664
					_menu.CheckMenuItem(4, this.forced[i] == 6 ? true : false);
3665
					this.autoplaylists_editing = true;
3666
					this.autoplaylists_hover = false;
3667
					window.RepaintRect(this.x + this.w - 40, this.y + 15, 40, Math.min(this.rows, this.items) * this.row_height);
3668
					idx = _menu.TrackPopupMenu(x, y);
3669
					switch(idx) {
3670
						case 0:
3671
							this.autoplaylists_editing = false;
3672
							_menu.Dispose();
3673
							return;
3674
						case 1:
3675
							var new_name = p.InputBox("Rename your autoplaylist", p.name, this.names[i]);
3676
							if (new_name != "") this.names[i] = new_name;
3677
							break;
3678
						case 2:
3679
							var new_query = p.InputBox("Enter your autoplaylist query", p.name, this.queries[i]);
3680
							if (new_query != "") this.queries[i] = new_query;
3681
							break;
3682
						case 3:
3683
							var new_sort = p.InputBox("Enter a sort pattern\n\n(optional)", p.name, this.sorts[i]);
3684
							this.sorts[i] = new_sort;
3685
							this.forced[i] = new_sort.length > 0 ? p.MsgBox("Force sort?", 4, p.name) : 7;
3686
							break;
3687
						case 4:
3688
							this.forced[i] = this.forced[i] == 6 ? 7 : 6;
3689
							break;
3690
					}
3691
					_menu.Dispose();
3692
					var temp = this.names[i] + "¬" + this.queries[i] + "¬" + this.sorts[i] + "¬" + this.forced[i];
3693
					if (this.data[i] != temp) {
3694
						this.data[i] = temp;
3695
						p.save(this.data.join("\n"), this.filename);
3696
						if (this.autoplaylists_success) this.autoplaylists_run(this.names[i], this.queries[i], this.sorts[i], this.forced[i]);
3697
						window.NotifyOthers("autoplaylists", "update");
3698
						this.update();
3699
					}
3700
					this.autoplaylists_editing = false;
3701
				}
3702
				
3703
				this.autoplaylists_delete = function() {
3704
					if (this.offset > 1) this.offset--;
3705
					this.autoplaylists_deleted_items.unshift(this.data[this.index]);
3706
					this.data.splice(this.index, 1);
3707
					p.save(this.data.join("\n"), this.filename);
3708
					window.NotifyOthers("autoplaylists", "update");
3709
					this.update();
3710
				}
3711
				
3712
				this.mode = "autoplaylists";
3713
				this.autoplaylists_del_img = gdi.Image(p.images_path + "cross.png");
3714
				this.autoplaylists_edit_img = gdi.Image(p.images_path + "edit.png");
3715
				this.autoplaylists_hover = false;
3716
				this.autoplaylists_editing = false;
3717
				this.autoplaylists_remove_duplicates = window.GetProperty("autoplaylists_remove_duplicates", true);
3718
				this.autoplaylists_success = window.GetProperty("autoplaylists_success", true);
3719
				this.autoplaylists_title = window.GetProperty("autoplaylists_title", "Autoplaylists");
3720
				this.autoplaylists_slot = window.GetProperty("autoplaylists_slot", 1);
3721
				this.filename = p.settings_folder + "autoplaylists" + this.autoplaylists_slot;
3722
				this.autoplaylists_deleted_items = [];
3723
				break;
3724
		}
3725
	}
3726
	
3727
	this.x = x;
3728
	this.y = y;
3729
	this.w = w;
3730
	this.h = h;
3731
	this.index = 0;
3732
	this.offset = 0;
3733
	this.items = 0;
3734
	this.text = "";
3735
	this.artist = "";
3736
	this.url = "";
3737
	this.text_x = 0;
3738
	this.show_timestamp = window.GetProperty("show_timestamp", true);
3739
	this.autoplaylist_img = gdi.Image(p.images_path + "search_small.png");
3740
	this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
3741
	this.init();
3742
}
3743
3744
function playcount_sync(x, y) {
3745
	this.playback_time = function() {
3746
		this.time_elapsed++;
3747
		if (this.time_elapsed == 3 && this.auto_love && fb.TitleFormat(this.auto_love_tf).Eval() == 1 && this.old_userloved == 0) {
3748
			p.console("Automatically loving this track....");
3749
			this.love_track();
3750
		}
3751
		if (this.time_elapsed == this.target_time) {
3752
			if (!this.library || fb.IsMetadbInMediaLibrary(p.metadb)) this.sync_track();
3753
			else p.console("Skipping... Track not in library.");
3754
		}
3755
	}
3756
	
3757
	this.metadb_changed = function() {
3758
		if (!p.metadb) return false;
3759
		this.artist = fb.TitleFormat(p.artist_tf).EvalWithMetadb(p.metadb);
3760
		this.track = fb.TitleFormat("%title%").EvalWithMetadb(p.metadb);
3761
		this.old_userloved = fb.TitleFormat("%LASTFM_LOVED_DB%").EvalWithMetadb(p.metadb) == 1 ? 1 : 0;
3762
		this.old_userplaycount = fb.TitleFormat("%LASTFM_PLAYCOUNT_DB%").EvalWithMetadb(p.metadb);
3763
		this.method = this.old_userloved == 1 ? "track.unlove" : "track.love";
3764
		this.tooltip = (this.old_userloved == 1 ? "Unlove" : "Love") + " \"" + this.track + "\" by \"" + this.artist + "\".";
3765
		this.crc32 = fb.TitleFormat("$crc32($lower(%artist%%title%))").EvalWithMetadb(p.metadb);
3766
		b.update();
3767
		return true;
3768
	}
3769
	
3770
	this.playback_new_track = function() {
3771
		this.auto_love_count = 0;
3772
		this.time_elapsed = 0;
3773
		switch(true) {
3774
			case fb.PlaybackLength == 0:
3775
				this.target_time = 240;
3776
				break;
3777
			case fb.PlaybackLength >= 30:
3778
				this.target_time = Math.min(Math.floor(fb.PlaybackLength / 2), 240);
3779
				break;
3780
			default:
3781
				this.target_time = 5;
3782
				break;
3783
		}
3784
		on_item_focus_change();
3785
	}
3786
	
3787
	this.playback_edited = function() {
3788
		if (this.auto_love && fb.TitleFormat(this.auto_love_tf).Eval() == 1 && this.old_userloved == 0 && this.auto_love_count == 0) {
3789
			this.auto_love_count = 1;
3790
			p.console("Automatically loving this track....");
3791
			this.love_track();
3792
		}
3793
	}
3794
	
3795
	this.tf = function(value) {
3796
		return(value.replace(/'/g, "''").replace(/,/g, "','").replace(/\//g, "'/'").replace(/\(/g, "'('").replace(/\)/g, "')'").replace(/\[/g, "'['").replace(/\]/g, "']'"));
3797
	}
3798
	
3799
	this.love_track = function() {
3800
		l.post(this.method, p.metadb);
3801
	}
3802
	
3803
	this.sync_track = function() {
3804
		switch(true) {
3805
			case this.loved_working || this.playcount_working:
3806
				return;
3807
			case !utils.CheckComponent("foo_customdb", true):
3808
				p.console("Not contacting Last.fm. foo_customdb is missing.");
3809
				return;
3810
			default:
3811
				p.console("Contacting Last.fm....");
3812
				this.get(l.get_url() + "&method=track.getinfo&artist=" + encodeURIComponent(this.artist) + "&track=" + encodeURIComponent(this.track) + "&autocorrect=" + (l.auto_correct ? 1 : 0), function() {
3813
					ps.update_track();
3814
				});
3815
		}
3816
	}
3817
	
3818
	this.get = function(url, func) {
3819
		if (l.username.length == 0) {
3820
			this.loved_working = false;
3821
			this.playcount_working = false;
3822
			p.console(l.username_error);
3823
			return;
3824
		}
3825
		this.xmlhttp.open("GET", url, true);
3826
		this.xmlhttp.setRequestHeader('User-Agent', l.user_agent);
3827
		this.xmlhttp.send();
3828
		this.xmlhttp.onreadystatechange = function() {
3829
			if (ps.xmlhttp.readyState == 4) {
3830
				if (ps.xmlhttp.status == 200) {
3831
					func();
3832
				} else {
3833
					p.console(ps.xmlhttp.responsetext || "HTTP error: " + ps.xmlhttp.status);
3834
				}
3835
			}
3836
		}
3837
	}
3838
	
3839
	this.update_track = function() {
3840
		this.json_data = p.json_parse(ps.xmlhttp.responsetext);
3841
		if (!this.json_data || this.json_data.error > 0 || !this.json_data.track) {
3842
			p.console(ps.xmlhttp.responsetext);
3843
			return;
3844
		}
3845
		this.userplaycount = this.json_data.track.userplaycount > 0 ? ++this.json_data.track.userplaycount : 1;
3846
		this.userloved = this.json_data.track.userloved == 1 ? 1 : 0;
3847
		if (fb.IsPlaying && this.time_elapsed >= this.target_time && fb.PlaybackLength > 29 && fb.PlaybackLength < 10800) {
3848
			switch(true) {
3849
				case this.userplaycount < this.old_userplaycount:
3850
					p.console("Playcount returned from Last.fm is lower than current value. Not updating.");
3851
					break;
3852
				case this.old_userplaycount == this.userplaycount:
3853
					p.console("No changes found. Not updating.");
3854
					break;
3855
				default:
3856
					p.console("Last.fm responded ok. Attempting to update playcount...");
3857
					fb.RunContextCommandWithMetadb("Customdb Delete Playcount", p.metadb, 8);
3858
					if (this.old_userloved == 1) fb.RunContextCommandWithMetadb("Customdb Love 0", p.metadb, 8);
3859
					var attempt = 0;
3860
					while(fb.TitleFormat("%LASTFM_PLAYCOUNT_DB%").EvalWithMetadb(p.metadb) != this.userplaycount && attempt <= 3) {
3861
						var query1 = '\"INSERT INTO quicktag(url,subsong,fieldname,value) VALUES(\\"' + this.crc32 + '\\",\\"-1\\",\\"LASTFM_PLAYCOUNT_DB\\",\\"' + this.userplaycount + '\\")\";';
3862
						p.WshShell.Run(p.fso.GetFile(p.script_path + "sqlite3.exe").ShortPath + " " + p.fso.GetFile(fb.ProfilePath + "customdb_sqlite.db").ShortPath + " " + query1, 0, true);
3863
						attempt++;
3864
					}
3865
					fb.RunContextCommandWithMetadb("Customdb Refresh", p.metadb, 8);
3866
					if (fb.TitleFormat("%LASTFM_PLAYCOUNT_DB%").EvalWithMetadb(p.metadb) == this.userplaycount) p.console("Playcount updated successfully.");
3867
					else p.console("Database error. Playcount not updated.");
3868
					break;
3869
			}
3870
		}
3871
		if (this.old_userloved != this.userloved) fb.RunContextCommandWithMetadb("Customdb Love " + this.userloved, p.metadb, 8);
3872
	}
3873
	
3874
	this.start_import = function() {
3875
		if (this.show_console) fb.ShowConsole();
3876
		this.loved_page_errors = 0;
3877
		this.playcount_page_errors = 0;
3878
		ps.pages = 0;
3879
		this.r = 1;
3880
		this.sql = "BEGIN TRANSACTION;\n";
3881
		this.loved_working = true;
3882
		this.sync_loved(1);
3883
	}
3884
	
3885
	this.sync_loved = function(page) {
3886
		if (!this.loved_working) return(p.console("Import aborted."));
3887
		this.page = page;
3888
		this.get(l.get_url() + "&method=user.getlovedtracks&limit=200&page=" + this.page, function() {
3889
			ps.update_loved();
3890
		});
3891
	}
3892
	
3893
	this.update_loved = function() {
3894
		this.json_data = p.json_parse(ps.xmlhttp.responsetext);
3895
		if (this.json_data && this.json_data.error > 0) {
3896
			this.loved_working = false;
3897
			p.MsgBox("There is a problem with the Last.fm web services. Please try again later.\n\n" + ps.xmlhttp.responsetext, 0, p.name);
3898
			return;
3899
		}
3900
		if (this.json_data && this.json_data.lovedtracks && this.json_data.lovedtracks.track) {
3901
			if (this.page == 1) this.pages = this.json_data.lovedtracks["@attr"].totalPages;
3902
			for (i = 0; i < this.json_data.lovedtracks.track.length; i++) {
3903
				var data = [];
3904
				data[0] = this.json_data.lovedtracks.track[i].artist.name;
3905
				data[1] = this.json_data.lovedtracks.track[i].name;
3906
				data[2] = 1;
3907
				if (data.length == 3) {
3908
					p.console(this.r + ": " + data[0] + " - " + data[1]);
3909
					var url = fb.TitleFormat("$crc32($lower(" + this.tf(data[0]) + this.tf(data[1]) + "))").Eval(true);
3910
					this.sql += 'INSERT OR REPLACE INTO quicktag(url,subsong,fieldname,value) VALUES("' + url + '","-1","LASTFM_LOVED_DB","' + data[2] + '");' + "\n";
3911
					this.r++;
3912
				}
3913
			}
3914
			p.console("Loved tracks: completed page " + this.page + " of " + this.pages);
3915
		} else if (this.pages > 0) {
3916
			this.loved_page_errors++;
3917
		}
3918
		if (this.page < this.pages) {
3919
			this.page++;
3920
			this.sync_loved(this.page);
3921
		} else {
3922
			this.loved_working = false;
3923
			if (this.full_import) {
3924
				this.playcount_working = true;
3925
				this.pages = 0;
3926
				this.r = 1;
3927
				this.sync_playcount(1);
3928
			} else {
3929
				try {
3930
					this.sql += "COMMIT;"
3931
					var ts = p.fso.OpenTextFile(this.sql_file, 2, true, 0);
3932
					ts.WriteLine(this.sql);
3933
					ts.Close();
3934
					this.finish_import();
3935
				} catch(e) {
3936
				}
3937
				if (this.loved_page_errors > 0) {
3938
					p.console("Loved track page errors: " + this.loved_page_errors + " (200 records are lost for every page that fails.)");
3939
				} else {
3940
					p.console("There were no errors reported.");
3941
				}
3942
			}
3943
		}
3944
	}
3945
	
3946
	this.sync_playcount = function(page) {
3947
		if (this.playcount_working == false) return(p.console("Import aborted."));
3948
		this.page = page;
3949
		this.get(l.get_url() + "&method=library.gettracks&limit=100&page=" + this.page, function() {
3950
			ps.update_playcount();
3951
		});
3952
	}
3953
	
3954
	this.update_playcount = function() {
3955
		this.json_data = p.json_parse(ps.xmlhttp.responsetext);
3956
		if (this.json_data && this.json_data.error > 0) {
3957
			this.playcount_working = false;
3958
			p.MsgBox("There is a problem with the Last.fm web services. Please try again later.\n\n" + ps.xmlhttp.responsetext, 0, p.name);
3959
			return;
3960
		}
3961
		if (this.json_data && this.json_data.tracks && this.json_data.tracks.track) {
3962
			if (this.page == 1) this.pages = this.json_data.tracks["@attr"].totalPages
3963
			for (i = 0; i < this.json_data.tracks.track.length; i++) {
3964
				var data = [];
3965
				data[0] = this.json_data.tracks.track[i].artist.name;
3966
				data[1] = this.json_data.tracks.track[i].name;
3967
				data[2] = this.json_data.tracks.track[i].playcount;
3968
				if (data[2] == 0) {
3969
					this.page = this.pages;
3970
					break;
3971
				}
3972
				if (data.length == 3) {
3973
					p.console(this.r + ": " + data[0] + " - " + data[1] + " " + data[2]);
3974
					var url = fb.TitleFormat("$crc32($lower(" + this.tf(data[0]) + this.tf(data[1]) + "))").Eval(true);
3975
					this.sql += 'INSERT OR REPLACE INTO quicktag(url,subsong,fieldname,value) VALUES("' + url + '","-1","LASTFM_PLAYCOUNT_DB","' + data[2] + '");' + "\n";
3976
					this.r++;
3977
				}
3978
			}
3979
			p.console("Playcount: completed page " + this.page + " of " + this.pages);
3980
		} else if (this.pages > 0) {
3981
			this.playcount_page_errors++;
3982
		}
3983
		if (this.page < this.pages) {
3984
			this.page++;
3985
			this.sync_playcount(this.page);
3986
		} else {
3987
			try {
3988
				this.sql += "COMMIT;"
3989
				var ts = p.fso.OpenTextFile(this.sql_file, 2, true, 0);
3990
				ts.WriteLine(this.sql);
3991
				ts.Close();
3992
				this.finish_import();
3993
			} catch(e) {
3994
			}
3995
			this.playcount_working = false;
3996
			if (this.loved_page_errors + this.playcount_page_errors > 0) {
3997
				p.console("Loved track page errors: " + this.loved_page_errors + " (200 records are lost for every page that fails.)");
3998
				p.console("Playcount page errors: " + this.playcount_page_errors + " (100 records are lost for every page that fails.)");
3999
			} else {
4000
				p.console("There were no errors reported.");
4001
			}
4002
		}
4003
	}
4004
	
4005
	this.finish_import = function() {
4006
		try {
4007
			var cmd_file = p.fso.GetFile(p.script_path + "lastfm_sql.cmd").ShortPath;
4008
			var db_file = p.fso.GetFile(fb.ProfilePath + "customdb_sqlite.db").ShortPath;
4009
			p.run(cmd_file + " " + p.fso.GetFile(p.script_path + "sqlite3.exe").ShortPath + " " + db_file + " " + p.fso.GetFile(this.sql_file).ShortPath);
4010
		} catch(e) {
4011
		}
4012
	}
4013
	
4014
	this.update_button = function() {
4015
		var exclamation = this.icon == "tango" ? "exclamation.png" : "exclamation_small.png";
4016
		var love = this.icon == "tango" ? "love.png" : "love_small.png";
4017
		var love_h = this.icon == "tango" ? "love_h.png" : "love_h_small.png";
4018
		this.size = this.icon == "tango" ? 32 : 20;
4019
		switch(true) {
4020
			case l.username.length == 0:
4021
				this.n = exclamation;
4022
				this.h = exclamation;
4023
				this.tooltip = l.username_error;
4024
				this.func = null;
4025
				break;
4026
			case l.sk.length != 32:
4027
				this.n = exclamation;
4028
				this.h = exclamation;
4029
				this.tooltip = l.password_error;
4030
				this.func = null;
4031
				break;
4032
			case !p.metadb:
4033
				this.n = exclamation;
4034
				this.h = exclamation;
4035
				this.tooltip = "No selection";
4036
				this.func = null;
4037
				break;
4038
			case !utils.CheckComponent("foo_customdb", true):
4039
				this.n = exclamation;
4040
				this.h = exclamation;
4041
				this.tooltip = "The foo_customdb component is not installed. Please refer to the readme.";
4042
				this.func = null;
4043
				break;
4044
			default:
4045
				this.n = this.old_userloved == 1 ? love_h : love;
4046
				this.h = this.old_userloved == 1 ? love : love_h;
4047
				this.func = function() { ps.love_track(); }
4048
				break;
4049
		}
4050
	}
4051
	
4052
	this.x = x;
4053
	this.y = y;
4054
	this.loved_working = false;
4055
	this.playcount_working = false;
4056
	this.sql_file = p.data_folder + "lastfm.sql";
4057
	this.page = 0;
4058
	this.last_page = 0;
4059
	this.auto_love = window.GetProperty("playcount_sync_auto_love", false);
4060
	this.auto_love_tf = window.GetProperty("playcount_sync_auto_love_tf", "");
4061
	this.icon = window.GetProperty("playcount_sync_icon", "tango");
4062
	this.show_console = window.GetProperty("playcount_sync_show_console", true);
4063
	this.library = window.GetProperty("playcount_sync_library", false);
4064
	this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
4065
	window.SetInterval(function() {
4066
		var temp = ps.page > 1 ? ps.page - 1 : 1;
4067
		if (ps.loved_working && ps.page == ps.last_page) {
4068
			ps.xmlhttp.abort();
4069
			ps.sync_loved(temp);
4070
		} else if (ps.playcount_working && ps.page == ps.last_page) {
4071
			ps.xmlhttp.abort();
4072
			ps.sync_playcount(temp);
4073
		} else {
4074
			ps.last_page = ps.page;
4075
		}
4076
	}, 15000);
4077
}
4078
4079
function rating(x, y, bs) {
4080
	this.draw = function(gr) {
4081
		if (!p.metadb) return;
4082
		for (i = 1; i < 6; i++) {
4083
			this.img = i > (this.hover ? this.lrating : this.rating) ? this.off_img : this.on_img;
4084
			p.draw_image(gr, this.img, this.x + this.bs * (i - 1), this.y, this.bs, this.bs, "adjust");
4085
		}
4086
	}
4087
	
4088
	this.metadb_changed = function() {
4089
		if (!p.metadb) return false;
4090
		this.hover = false;
4091
		this.rating = p.eval("$if2(%rating%,0)");
4092
		this.tiptext = p.eval(this.tiptext_tf);
4093
		this.lrating = this.rating;
4094
		window.RepaintRect(this.x, this.y, this.w, this.bs);
4095
		return true;
4096
	}
4097
	
4098
	this.trace = function(x, y) {
4099
		return x > this.x - this.bs && x < this.x + (this.bs * 5) && y > this.y && y < this.y + this.bs;
4100
	}
4101
	
4102
	this.move = function(x, y) {
4103
		if (!this.trace(x, y)) {
4104
			if (this.hover) this.leave();
4105
			return false;
4106
		}
4107
		if (p.metadb) {
4108
			if (x > this.x) p.tt(this.tiptext);
4109
			this.hover = true;
4110
			this.lrating = Math.ceil((x - this.x) / this.bs);
4111
			window.RepaintRect(this.x, this.y, this.w, this.bs);
4112
		}
4113
		return true;
4114
	}
4115
	
4116
	this.lbtn_up = function(x, y) {
4117
		if (!this.trace(x, y)) return false;
4118
		if (this.check) {
4119
			if (this.lrating != this.rating && this.hover == 1) fb.RunContextCommandWithMetadb("Rating/" + (this.lrating == 0 ? "<not set>" : this.lrating), p.metadb, 8);
4120
		} else {
4121
			p.MsgBox(this.error_text, 0, p.name);
4122
			p.browser("http://www.foobar2000.org/components/view/foo_playcount");
4123
		}
4124
		return true;
4125
	}
4126
	
4127
	this.leave = function() {
4128
		p.ttd();
4129
		this.hover = false;
4130
		window.RepaintRect(this.x, this.y, this.w, this.bs);
4131
	}
4132
	
4133
	this.x = x;
4134
	this.y = y;
4135
	this.bs = bs;
4136
	this.w = this.bs * 5;
4137
	this.hover = false;
4138
	this.rating = null;
4139
	this.lrating = null;
4140
	this.img = null;
4141
	this.off_img = gdi.Image(p.images_path + "off.png");
4142
	this.on_img = gdi.Image(p.images_path + "on.png");
4143
	this.check = utils.CheckComponent("foo_playcount", true);
4144
	this.error_text = "This script requires foo_playcount.";
4145
	this.tiptext_tf = this.check ? 'Rate "%title%" by "%artist%"' : this.error_text;
4146
}
4147
4148
function sb(x, y, w, h, img, isVisible, func) {
4149
	this.x = x;
4150
	this.y = y;
4151
	this.w = w;
4152
	this.h = h;
4153
	this.img = img;
4154
	this.isVisible = new Function("return (" + isVisible + ");");
4155
	this.func = func;
4156
	
4157
	this.draw = function(gr) {
4158
		if (this.isVisible()) p.draw_image(gr, this.img, this.x, this.y, this.w, this.h, "adjust");
4159
	}
4160
	
4161
	this.trace = function(x, y) {
4162
		return(x > this.x && x < this.x + this.w && y > this.y && y < this.y + this.h && this.isVisible());
4163
	}
4164
	
4165
	this.lbtn_up = function(x, y) {
4166
		if (!this.trace(x, y)) return false;
4167
		this.func && this.func(x, y);
4168
		return true;
4169
	}
4170
}
4171
4172
function seekbar(x, y, w, h) {
4173
	this.trace = function(x, y) {
4174
		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));
4175
	}
4176
	
4177
	this.draw = function(gr) {
4178
		p.draw_background(gr);
4179
		switch(this.mode) {
4180
			case "spectrogram":
4181
				if (this.working) {
4182
					p.draw_image(gr, this.hourglass_img, this.x, this.y + Math.round((this.h - 32) / 2), this.w, 32, "adjust");
4183
				} else {
4184
					p.draw_image(gr, this.img, this.x, this.y, this.w, this.h, "stretch");
4185
				}
4186
				if (fb.IsPlaying && fb.PlaybackLength > 0) {
4187
					this.calc_pos();
4188
					gr.FillSolidRect(this.x + this.pos - 2, this.y, 2, this.h, p.splitRGB(this.marker));
4189
				}
4190
				break;
4191
			case "nyan_cat":
4192
				if (fb.IsPlaying && fb.PlaybackLength > 0) {
4193
					this.calc_pos();
4194
					for (i = 0; i < this.offsets.length; i++) {
4195
						gr.FillSolidRect(this.x - 48, this.y + this.offsets[i], this.pos + 2, this.heights[i], this.colours[i]);
4196
					}
4197
					p.draw_image(gr, this.cat_img[this.z], this.pos, this.y, 48, 30);
4198
				} else {
4199
					p.draw_image(gr, this.cat_img[0], 0, this.y, 48, 30);
4200
				}
4201
				break;
4202
		}
4203
	}
4204
	
4205
	this.playback_new_track = function() {
4206
		if (this.mode != "spectrogram") return;
4207
		var metadb = fb.GetNowPlaying();
4208
		this.img && this.img.Dispose();
4209
		this.img = null;
4210
		try {
4211
			this.png_filename = spectrogram_cache + "\\" + fb.TitleFormat("$crc32(%path%)").EvalWithMetadb(metadb) + this.sox_params + ".png";
4212
			switch(true) {
4213
				case !metadb:
4214
				case metadb.RawPath.indexOf("file") != 0:
4215
					p.console("Skipping... Not a valid file type.");
4216
					break;
4217
				case fb.PlaybackLength == 0:
4218
					p.console("Skipping... Unknown length.");
4219
					break;
4220
				case fb.TitleFormat("$if($or($strcmp(%__cue_embedded%,yes),$strcmp($right(%path%,3),cue)),cue,)").EvalWithMetadb(metadb) == "cue":
4221
					p.console("Skipping... Cannot support cuesheets.");
4222
					break;
4223
				case fb.TitleFormat("%subsong%").EvalWithMetadb(metadb) > 0:
4224
					p.console("Skipping... Cannot support tracks with chapters.");
4225
					break;
4226
				case this.library && !fb.IsMetadbInMediaLibrary(metadb):
4227
					p.console("Skipping... Track not in library.");
4228
					break;
4229
				case p.fso.FileExists(this.png_filename):
4230
					this.img = gdi.Image(this.png_filename);
4231
					break;
4232
				default:
4233
					this.working = true
4234
					window.Repaint();
4235
					var filename = metadb.Path;
4236
					var length = fb.TitleFormat("%length%").EvalWithMetadb(metadb);
4237
					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 + "\"\"";
4238
					//p.console(cmd);
4239
					try { p.WshShell.Run(cmd, 0, true); } catch(e) {}
4240
					this.working = false;
4241
					this.img = gdi.Image(this.png_filename);
4242
					break;
4243
			}
4244
		} catch(e) {
4245
			//p.console(e);
4246
		}
4247
		window.Repaint();
4248
	}
4249
	
4250
	this.playback_stop = function() {
4251
		window.Repaint();
4252
	}
4253
	
4254
	this.playback_seek = function() {
4255
		this.update();
4256
	}
4257
	
4258
	this.move = function(x, y) {
4259
		if (this.drag) this.update();
4260
		if (this.trace(x, y)) {
4261
			if (fb.IsPlaying && fb.PlaybackLength > 0) {
4262
				x -= this.x;
4263
				this.drag_seek = x < 0 ? 0 : x > this.w ? 1 : x / this.w;
4264
				if (x != this.old_x || y != this.old_y) {
4265
					p.tt(p.format_time(fb.PlaybackLength * this.drag_seek));
4266
					this.old_x = x;
4267
					this.old_y = y;
4268
				}
4269
			}
4270
			return true;
4271
		} else {
4272
			this.leave();
4273
			return false;
4274
		}
4275
	}
4276
	
4277
	this.lbtn_down = function(x, y) {
4278
		if (!this.trace(x, y)) return false;
4279
		if (fb.IsPlaying && fb.PlaybackLength > 0) this.drag = true;
4280
		return true;
4281
	}
4282
	
4283
	this.lbtn_up = function(x, y) {
4284
		if (!this.trace(x, y)) return false;
4285
		if (this.drag) {
4286
			this.drag = false;
4287
			fb.PlaybackTime = fb.PlaybackLength * this.drag_seek;
4288
		}
4289
		return true;
4290
	}
4291
	
4292
	this.leave = function() {
4293
		this.drag = false;
4294
		p.ttd();
4295
	}
4296
	
4297
	this.update = function() {
4298
		window.RepaintRect(0, this.y, p.w, this.h);
4299
	}
4300
	
4301
	this.calc_pos = function() {
4302
		this.pos = this.drag ? this.w * this.drag_seek : this.w * (fb.PlaybackTime / fb.PlaybackLength);
4303
	}
4304
	
4305
	this.init = function() {
4306
		switch(true) {
4307
			case p.check_feature("spectrogram"):
4308
				this.clear_images = function(period) {
4309
					var now = Date.parse(Date());
4310
					images = utils.Glob(spectrogram_cache + "\\*.*").toArray();
4311
					for (i = 0; i < images.length; i++) {
4312
						if (this.png_filename == images[i]) continue;
4313
						var file = p.fso.Getfile(images[i]);
4314
						var file_date = Date.parse(file.DateLastModified);
4315
						if (now - file_date > period) {
4316
							try {
4317
								p.fso.DeleteFile(images[i]);
4318
							} catch(e) {
4319
								p.console("Could not delete " + images[i]);
4320
							}
4321
						}
4322
					}
4323
				}
4324
				
4325
				this.mode = "spectrogram";
4326
				this.library = window.GetProperty("seekbar_library", false);
4327
				this.marker = window.GetProperty("seekbar_marker", "240-240-240");
4328
				this.sox_params = window.GetProperty("sox_params", "channels 1 spectrogram -Y 130").trim();
4329
				this.working = false;
4330
				this.img = false;
4331
				this.hourglass_img = gdi.Image(p.images_path + "hourglass.png");
4332
				//if (!p.fso.FolderExists(spectrogram_cache)) p.fso.CreateFolder(spectrogram_cache);
4333
				if (fb.IsPlaying) {
4334
					window.SetTimeout(function() {
4335
						s.playback_new_track();
4336
					}, 100);
4337
				}
4338
				break;
4339
			case p.check_feature("nyan_cat"):
4340
				this.mode = "nyan_cat";
4341
				this.cat_img = [gdi.Image(p.images_path + "\\seekbar cat.png"), gdi.Image(p.images_path + "\\seekbar cat 2.png")];
4342
				this.offsets = [2, 6, 10, 15, 20, 24];
4343
				this.heights = [4, 4, 5, 5, 4, 4];
4344
				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)];
4345
				break;
4346
		}
4347
	}
4348
	
4349
	this.x = x;
4350
	this.y = y;
4351
	this.w = w;
4352
	this.h = h;
4353
	this.z = 0;
4354
	this.pos = 0;
4355
	this.drag = false;
4356
	this.drag_seek = 0;
4357
	this.old_x = 0;
4358
	this.old_y = 0;
4359
	this.init();
4360
	this.seekbar_timer = window.SetInterval(function() {
4361
		s.z = s.z == 0 ? 1 : 0;
4362
		if (!fb.IsPlaying || fb.IsPaused || fb.PlaybackLength == 0) return;
4363
		s.update();
4364
	}, 150);
4365
}
4366
4367
function text(x, y, w, h) {
4368
	this.size = function() {
4369
		this.rows = Math.floor((this.h - 36) / p.row_height);
4370
		this.but_x = this.x + Math.round((this.w - 15) / 2);
4371
		this.up_btn = new sb(this.but_x, this.y, 15, 15, p.up_img, "t.offset > 0", function() { t.wheel(1); });
4372
		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); });
4373
		this.calc();
4374
	}
4375
	
4376
	this.draw = function(gr, colour) {
4377
		for (i = 0; i < Math.min(this.rows, this.text_rows); i++) {
4378
			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);
4379
			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);
4380
		}
4381
		this.up_btn.draw(gr);
4382
		this.down_btn.draw(gr);
4383
	}
4384
	
4385
	this.metadb_changed = function() {
4386
		if (!p.metadb) return false;
4387
		switch(this.mode) {
4388
			case "simple_tag":
4389
				this.temp_filename = p.metadb.Path;
4390
				if (this.filename == this.temp_filename) return false;
4391
				this.filename = this.temp_filename;
4392
				this.text = p.eval(this.tag);
4393
				break;
4394
			case "simple_text":
4395
				this.temp_filename = p.eval(this.filename_tf);
4396
				if (this.filename == this.temp_filename) return false;
4397
				this.text = "";
4398
				this.filename = this.temp_filename;
4399
				if (p.fso.FolderExists(this.filename)) {
4400
					this.files = [];
4401
					this.files = this.files.concat(utils.Glob(this.filename + "\\*.txt").toArray(), utils.Glob(this.filename + "\\*.log").toArray());
4402
					this.files.sort();
4403
					this.text = p.open(this.files[0]);
4404
				} else {
4405
					this.filenames = this.filename.split("|");
4406
					for (i = 0; i < this.filenames.length; i++) {
4407
						if (p.fso.fileExists(this.filenames[i])) {
4408
							this.text = p.open(this.filenames[i]);
4409
							break;
4410
						}
4411
					}
4412
				}
4413
				this.text = this.text.replace(/\t/g, "    ");
4414
				break;
4415
			case "lastfm_wiki":
4416
				p.artist = p.eval(p.artist_tf);
4417
				if (this.artist == p.artist) return false;
4418
				this.artist = p.artist;
4419
				this.folder = p.data_folder + p.artist;
4420
				if (!p.fso.FolderExists(this.folder)) p.fso.CreateFolder(this.folder);
4421
				this.filename = this.folder + "\\artist.getInfo_mod.json";
4422
				this.text = "Nothing found.";
4423
				this.url = "http://www.last.fm/";
4424
				if (p.fso.fileExists(this.filename)) {
4425
					this.json_text = p.open(this.filename);
4426
					this.json_data = p.json_parse(this.json_text);
4427
					if (this.json_data && this.json_data.response && this.json_data.response.biographies) {
4428
						this.items = this.json_data.response.biographies.length;
4429
						for (i = 0; i < this.items; i++) {
4430
							if (this.json_data.response.biographies[i].site == this.source) {
4431
								this.text = this.json_data.response.biographies[i].text;
4432
								this.url = this.json_data.response.biographies[i].license["attribution-url"];
4433
								break;
4434
							}
4435
						}
4436
						if (this.source == "last.fm") this.text = this.text.replace(/\.  /g, ".\n\n");
4437
						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");
4438
					}
4439
				} else {
4440
					this.get();
4441
				}
4442
				break;
4443
			case "lastfm_album":
4444
				var temp_album = p.eval("[%album%]");
4445
				var temp_artist = p.eval("[%album artist%]");
4446
				if (this.album == temp_album && this.artist == temp_artist) return false;
4447
				this.artist = temp_artist;
4448
				this.album = temp_album;
4449
				this.folder = p.data_folder + p.eval("$crc32(%album artist%)");
4450
				if (!p.fso.FolderExists(this.folder)) p.fso.CreateFolder(this.folder);
4451
				this.filename = this.folder + "\\album.getInfo_" + p.eval("$crc32(%album%)") + ".json";
4452
				this.text = "Nothing found.";
4453
				this.url = l.url;
4454
				if (p.fso.fileExists(this.filename)) {
4455
					this.file = p.fso.GetFile(this.filename);
4456
					this.json_text = p.open(this.filename);
4457
					this.json_data = p.json_parse(this.json_text);
4458
					if (this.json_data && this.json_data.album) {
4459
						if (this.json_data.album.url) this.url = this.json_data.album.url;
4460
						if (this.json_data.album.wiki && this.json_data.album.wiki.content) {
4461
							this.text = p.strip_tags(this.json_data.album.wiki.content);
4462
							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();
4463
						}
4464
					}
4465
					if (Date.parse(Date()) - Date.parse(this.file.DateLastModified) > ONE_DAY) this.get();
4466
				} else {
4467
					this.get();
4468
				}
4469
				break;
4470
		}
4471
		this.calc();
4472
		window.Repaint();
4473
		return true;
4474
	}
4475
	
4476
	this.trace = function(x, y) {
4477
		return (x > this.x && x < this.x + this.w && y > this.y && y < this.y + this.h);
4478
	}
4479
	
4480
	this.wheel = function(step) {
4481
		if (!this.trace(p.mx, p.my)) return false;
4482
		if (this.text_rows > this.rows) {
4483
			this.offset -= step * 3;
4484
			if (this.offset < 0) this.offset = 0;
4485
			if (this.offset + this.rows > this.text_rows) this.offset = this.text_rows - this.rows;
4486
			window.RepaintRect(this.x, this.y, this.w, this.h);
4487
		}
4488
		return true;
4489
	}
4490
	
4491
	this.move = function(x, y) {
4492
		switch(true) {
4493
			case !this.trace(x, y):
4494
				window.SetCursor(IDC_ARROW);
4495
				return false;
4496
			case this.up_btn.trace(x, y):
4497
			case this.down_btn.trace(x, y):
4498
				window.SetCursor(IDC_HAND);
4499
				return true;
4500
			default:
4501
				window.SetCursor(IDC_ARROW);
4502
				return false;
4503
		}
4504
	}
4505
	
4506
	this.lbtn_up = function(x, y) {
4507
		if (!this.trace(x, y)) return false;
4508
		this.up_btn.lbtn_up(x, y);
4509
		this.down_btn.lbtn_up(x, y);
4510
		return true;
4511
	}
4512
	
4513
	this.get = function() {
4514
		var fn = this.filename;
4515
		var func = function() {
4516
			if (!p.save(t.xmlhttp.responsetext, fn)) return;
4517
			t.artist = "";
4518
			t.album = "";
4519
			on_item_focus_change();
4520
		}
4521
		var url = "";
4522
		var user_agent = "";
4523
		switch(this.mode) {
4524
			case "lastfm_album":
4525
				if (this.artist == "" || this.album == "") return;
4526
				url = l.get_url() + "&method=album.getInfo&artist=" + encodeURIComponent(this.artist) + "&album=" + encodeURIComponent(this.album);
4527
				user_agent = l.user_agent;
4528
				break;
4529
			case "lastfm_wiki":
4530
				if (this.artist == "" || this.artist == "?") return;
4531
				url = "http://developer.echonest.com/api/v4/artist/biographies?api_key=EKWS4ESQLKN3G2ZWV&format=json&name=" + encodeURIComponent(this.artist);
4532
				break;
4533
		}
4534
		if (url.length == 0) return;
4535
		this.xmlhttp.open("GET", url, true);
4536
		if (user_agent.length > 0) this.xmlhttp.setRequestHeader('User-Agent', user_agent);
4537
		this.xmlhttp.send();
4538
		this.xmlhttp.onreadystatechange = function() {
4539
			if (t.xmlhttp.readyState == 4) {
4540
				if (t.xmlhttp.status == 200) {
4541
					func();
4542
				} else {
4543
					p.console(t.xmlhttp.responsetext || "HTTP error: " + t.xmlhttp.status);
4544
				}
4545
			}
4546
		}
4547
	}
4548
	
4549
	this.calc = function() {
4550
		this.offset = 0;
4551
		this.text_rows = 0;
4552
		if (this.w < 100 || this.text.length == 0) return;
4553
		var temp_bmp = gdi.CreateImage(1, 1);
4554
		var temp_gr = temp_bmp.GetGraphics();
4555
		var paragraphs = this.text.split("\n");
4556
		this.text_array = [];
4557
		for (i = 0; i < paragraphs.length; i++) {
4558
			if (this.fixed) {
4559
				this.text_array.push(paragraphs[i]);
4560
			} else {
4561
				var lines = temp_gr.EstimateLineWrap(paragraphs[i], p.normal_font, this.w).toArray();
4562
				for (j = 0; j < lines.length; j += 2) {
4563
					this.text_array.push(lines[j].trim());
4564
				}
4565
			}
4566
		}
4567
		this.text_rows = this.text_array.length;
4568
		temp_bmp.ReleaseGraphics(temp_gr);
4569
		temp_bmp.Dispose();
4570
		temp_gr = null;
4571
		temp_bmp = null;
4572
	}
4573
	
4574
	this.init = function() {
4575
		switch(true) {
4576
			case p.check_feature("lastfm_album"):
4577
				this.mode = "lastfm_album";
4578
				break;
4579
			case p.check_feature("lastfm_wiki"):
4580
				this.mode = "lastfm_wiki";
4581
				this.source = window.GetProperty("biography_source", "last.fm");
4582
				break;
4583
			case p.check_feature("simple_text"):
4584
				this.mode = "simple_text";
4585
				this.title = window.GetProperty("text_title", "$directory_path(%path%)");
4586
				this.filename_tf = window.GetProperty("text_filename_tf", "$directory_path(%path%)");
4587
				this.filename = "";
4588
				this.fixed = window.GetProperty("text_fixed_font", true);
4589
				break;
4590
			case p.check_feature("simple_tag"):
4591
				this.mode = "simple_tag";
4592
				this.title = window.GetProperty("text_title", "%title%");
4593
				this.filename = "";
4594
				this.centre = window.GetProperty("text_centre", false);
4595
				this.tag = window.GetProperty("text_tag", "[%lyrics%]");
4596
				break;
4597
		}
4598
	}
4599
	
4600
	this.x = x;
4601
	this.y = y;
4602
	this.w = w;
4603
	this.h = h;
4604
	this.text = "";
4605
	this.artist = "";
4606
	this.album = "";
4607
	this.url = "";
4608
	this.fixed = false;
4609
	this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
4610
	this.init();
4611
	this.size();
4612
}
4613
4614
function thumbs() {
4615
	this.trace = function(x, y) {
4616
		return (x > this.x && x < this.x + this.w && y > this.y && y < this.y + this.h);
4617
	}
4618
	
4619
	this.draw = function(gr) {
4620
		switch(true) {
4621
			case im.images.length == 0:
4622
				break;
4623
			case this.mode == "off":
4624
				p.draw_image(gr, im.images[im.index], im.x, im.y, im.w, im.h, im.type);
4625
				break;
4626
			case !this.img:
4627
				break;
4628
			case this.mode == "grid":
4629
				gr.DrawImage(this.img, this.x, this.y, this.w, this.h, 0, this.offset * this.px, this.w, this.h);
4630
				if (this.overlay) {
4631
					gr.FillSolidRect(this.x, this.y, this.w, this.h, RGBA(0, 0, 0, 126));
4632
					p.draw_image(gr, im.images[im.index], im.x, im.y, im.w, im.h, "adjust");
4633
				}
4634
				break;
4635
			case this.mode == "left":
4636
			case this.mode == "right":
4637
				gr.DrawImage(this.img, this.x, this.y, this.w, this.h, 0, this.offset * this.px, this.w, this.h);
4638
				p.draw_image(gr, im.images[im.index], im.x, im.y, im.w, im.h, im.type);
4639
				break;
4640
			case this.mode == "bottom":
4641
			case this.mode == "top":
4642
				gr.DrawImage(this.img, this.x, this.y, this.w, this.h, this.offset * this.px, 0, this.w, this.h);
4643
				p.draw_image(gr, im.images[im.index], im.x, im.y, im.w, im.h, im.type);
4644
				break;
4645
		}
4646
	}
4647
	
4648
	this.calc = function() {
4649
		this.offset = 0;
4650
		switch(true) {
4651
			case p.w < this.px || p.h < this.px || this.mode == "off":
4652
				this.nc = true;
4653
				this.img && this.img.Dispose();
4654
				this.img = null;
4655
				im.x = 0;
4656
				im.y = 0;
4657
				im.w = p.w;
4658
				im.h = p.h;
4659
				break;
4660
			case this.mode == "grid":
4661
				this.x = 0;
4662
				this.y = 0;
4663
				this.w = p.w;
4664
				this.h = p.h;
4665
				im.x = 40;
4666
				im.y = 40;
4667
				im.w = this.w - 80;
4668
				im.h = this.h - 80;
4669
				if (!this.nc && this.columns != Math.floor(this.w / this.px)) this.nc = true;
4670
				this.overlay = false;
4671
				this.rows = Math.ceil(this.h / this.px);
4672
				this.columns = Math.floor(this.w / this.px);
4673
				this.img_rows = Math.ceil(im.images.length / this.columns);
4674
				if (this.nc && im.images.length > 0) {
4675
					this.nc = false;
4676
					this.img && this.img.Dispose();
4677
					this.img = null;
4678
					this.img = gdi.CreateImage(Math.min(this.columns, im.images.length) * this.px, this.img_rows * this.px);
4679
					var temp_gr = this.img.GetGraphics();
4680
					temp_gr.SetInterpolationMode(7);
4681
					var ci = 0;
4682
					var row, col;
4683
					for (row = 0; row < this.img_rows; row++) {
4684
						for (col = 0; col < this.columns; col++) {
4685
							if (ci == im.images.length) continue;
4686
							p.draw_image(temp_gr, im.images[ci], col * this.px, row * this.px, this.px, this.px, "top");
4687
							ci++;
4688
						}
4689
					}
4690
					this.img.ReleaseGraphics(temp_gr);
4691
					temp_gr = null;
4692
				}
4693
				break;
4694
			case this.mode == "left":
4695
			case this.mode == "right":
4696
				this.x = this.mode == "left" ? 0 : p.w - this.px;
4697
				this.y = 0;
4698
				this.w = this.px;
4699
				this.h = p.h;
4700
				im.x = this.mode == "right" ? 0 : this.px;
4701
				im.y = 0;
4702
				im.w = p.w - this.px;
4703
				im.h = p.h;
4704
				this.rows = Math.ceil(this.h / this.px);
4705
				if (this.nc && im.images.length > 0) {
4706
					this.nc = false;
4707
					this.img && this.img.Dispose();
4708
					this.img = null;
4709
					this.img = gdi.CreateImage(this.px, this.px * im.images.length);
4710
					var temp_gr = this.img.GetGraphics();
4711
					temp_gr.SetInterpolationMode(7);
4712
					for (i = 0; i < im.images.length; i++) {
4713
						p.draw_image(temp_gr, im.images[i], 0, i * this.px, this.px, this.px, "top");
4714
					}
4715
					this.img.ReleaseGraphics(temp_gr);
4716
					temp_gr = null;
4717
				}
4718
				break;
4719
			case this.mode == "bottom":
4720
			case this.mode == "top":
4721
				this.x = 0;
4722
				this.y = this.mode == "top" ? 0 : p.h - this.px;
4723
				this.w = p.w;
4724
				this.h = this.px;
4725
				im.x = 0;
4726
				im.y = this.mode == "bottom" ? 0 : this.px;
4727
				im.w = p.w;
4728
				im.h = p.h - this.px;
4729
				this.columns = Math.ceil(this.w / this.px);
4730
				if (this.nc && im.images.length > 0) {
4731
					this.nc = false;
4732
					this.img && this.img.Dispose();
4733
					this.img = null;
4734
					this.img = gdi.CreateImage(this.px * im.images.length, this.px);
4735
					var temp_gr = this.img.GetGraphics();
4736
					temp_gr.SetInterpolationMode(7);
4737
					for (i = 0; i < im.images.length; i++) {
4738
						p.draw_image(temp_gr, im.images[i], i * this.px, 0, this.px, this.px, "top");
4739
					}
4740
					this.img.ReleaseGraphics(temp_gr);
4741
					temp_gr = null;
4742
				}
4743
				break;
4744
		}
4745
	}
4746
	
4747
	this.wheel = function(step) {
4748
		switch(true) {
4749
			case !this.trace(p.mx, p.my):
4750
			case this.overlay:
4751
				return false;
4752
			case this.mode == "grid":
4753
				if (this.img_rows < this.rows) return true;
4754
				this.offset -= step;
4755
				if (this.offset < 0) this.offset = 0;
4756
				if (this.offset > this.img_rows - this.rows) this.offset = this.img_rows - this.rows + 1;
4757
				break;
4758
			case this.mode == "left":
4759
			case this.mode == "right":
4760
				if (im.images.length < this.rows) return true;
4761
				this.offset -= step;
4762
				if (this.offset < 0) this.offset = 0;
4763
				if (this.rows + this.offset > im.images.length) this.offset = im.images.length - this.rows + 1;
4764
				break;
4765
			case this.mode == "bottom":
4766
			case this.mode == "top":
4767
				if (im.images.length < this.columns) return true;
4768
				this.offset -= step;
4769
				if (this.offset < 0) this.offset = 0;
4770
				if (this.columns + this.offset > im.images.length) this.offset = im.images.length - this.columns + 1;
4771
				break;
4772
		}
4773
		window.RepaintRect(this.x, this.y, this.w, this.h);
4774
		return true;
4775
	}
4776
	
4777
	this.move = function(x, y) {
4778
		switch(true) {
4779
			case !this.trace(x, y):
4780
				window.SetCursor(IDC_ARROW);
4781
				return false;
4782
			case this.overlay:
4783
				window.SetCursor(IDC_ARROW);
4784
				return true;
4785
			case this.mode == "grid":
4786
				this.index = Math.floor((x - this.x) / this.px) + (Math.floor((y - this.y) / this.px) * this.columns) + (this.offset * this.columns);
4787
				break;
4788
			case this.mode == "left":
4789
			case this.mode == "right":
4790
				this.index = Math.floor((y - this.y) / this.px) + this.offset;
4791
				break;
4792
			case this.mode == "bottom":
4793
			case this.mode == "top":
4794
				this.index = Math.floor((x - this.x) / this.px) + this.offset;
4795
				break;
4796
		}
4797
		window.SetCursor(this.index < im.images.length ? IDC_HAND : IDC_ARROW);
4798
		return true;
4799
	}
4800
	
4801
	this.lbtn_up = function(x, y) {
4802
		switch(true) {
4803
			case !this.trace(x, y):
4804
				return false;
4805
			case this.mode == "grid" && this.overlay && im.trace(x, y):
4806
				this.overlay = false;
4807
				window.Repaint();
4808
				break;
4809
			case this.mode == "grid" && this.index < im.images.length && !this.overlay:
4810
				this.overlay = true;
4811
				im.index = this.index;
4812
				window.Repaint();
4813
				break;
4814
			case this.overlay:
4815
				break;
4816
			case this.index < im.images.length:
4817
				im.index = this.index;
4818
				window.Repaint();
4819
		}
4820
		return true;
4821
	}
4822
	
4823
	this.lbtn_dblclk = function(x, y) {
4824
		if (!im.trace(x, y) || th.mode == "grid") return false;
4825
		p.run("\"" + im.files[im.index] + "\"");
4826
		return true;
4827
	}
4828
	
4829
	this.nc = false;
4830
	this.mode = "off";
4831
	this.px = 40;
4832
	this.img = null;
4833
}
4834
4835
//json2.js
4836
if(typeof JSON!=='object'){JSON={};}
4837
(function(){'use strict';function f(n){return n<10?'0'+n:n;}
4838
if(typeof Date.prototype.toJSON!=='function'){Date.prototype.toJSON=function(key){return isFinite(this.valueOf())?this.getUTCFullYear()+'-'+
4839
f(this.getUTCMonth()+1)+'-'+
4840
f(this.getUTCDate())+'T'+
4841
f(this.getUTCHours())+':'+
4842
f(this.getUTCMinutes())+':'+
4843
f(this.getUTCSeconds())+'Z':null;};String.prototype.toJSON=Number.prototype.toJSON=Boolean.prototype.toJSON=function(key){return this.valueOf();};}
4844
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+'"';}
4845
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);}
4846
if(typeof rep==='function'){value=rep.call(holder,key,value);}
4847
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';}
4848
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';}
4849
v=partial.length===0?'[]':gap?'[\n'+gap+partial.join(',\n'+gap)+'\n'+mind+']':'['+partial.join(',')+']';gap=mind;return v;}
4850
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);}}}}
4851
v=partial.length===0?'{}':gap?'{\n'+gap+partial.join(',\n'+gap)+'\n'+mind+'}':'{'+partial.join(',')+'}';gap=mind;return v;}}
4852
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;}
4853
rep=replacer;if(replacer&&typeof replacer!=='function'&&(typeof replacer!=='object'||typeof replacer.length!=='number')){throw new Error('JSON.stringify');}
4854
return str('',{'':value});};}
4855
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];}}}}
4856
return reviver.call(holder,key,value);}
4857
text=String(text);cx.lastIndex=0;if(cx.test(text)){text=text.replace(cx,function(a){return'\\u'+
4858
('0000'+a.charCodeAt(0).toString(16)).slice(-4);});}
4859
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;}
4860
throw new SyntaxError('JSON.parse');};}}());
4861
4862
/*
4863
 * A JavaScript implementation of the RSA Data Security, Inc. MD5 Message
4864
 * Digest Algorithm, as defined in RFC 1321.
4865
 * Version 2.2 Copyright (C) Paul Johnston 1999 - 2009
4866
 * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
4867
 * Distributed under the BSD License
4868
 * See http://pajhome.org.uk/crypt/md5 for more info.
4869
 */
4870
var hexcase=0;function hex_md5(a){return rstr2hex(rstr_md5(str2rstr_utf8(a)))}
4871
function hex_hmac_md5(a,b){return rstr2hex(rstr_hmac_md5(str2rstr_utf8(a),str2rstr_utf8(b)))}
4872
function md5_vm_test(){return hex_md5("abc").toLowerCase()=="900150983cd24fb0d6963f7d28e17f72"}
4873
function rstr_md5(a){return binl2rstr(binl_md5(rstr2binl(a),a.length*8))}
4874
function rstr_hmac_md5(c,f){var e=rstr2binl(c);if(e.length>16){e=binl_md5(e,c.length*8)}
4875
var a=Array(16),d=Array(16);for(var b=0;b<16;b++){a[b]=e[b]^909522486;d[b]=e[b]^1549556828}
4876
var g=binl_md5(a.concat(rstr2binl(f)),512+f.length*8);return binl2rstr(binl_md5(d.concat(g),512+128))}
4877
function rstr2hex(c){try{hexcase}catch(g){hexcase=0}
4878
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)}
4879
return b}
4880
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++}
4881
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))}}}}}
4882
return b}
4883
function rstr2binl(b){var a=Array(b.length>>2);for(var c=0;c<a.length;c++){a[c]=0}
4884
for(var c=0;c<b.length*8;c+=8){a[c>>5]|=(b.charCodeAt(c/8)&255)<<(c%32)}
4885
return a}
4886
function binl2rstr(b){var a="";for(var c=0;c<b.length*32;c+=8){a+=String.fromCharCode((b[c>>5]>>>(c%32))&255)}
4887
return a}
4888
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)}
4889
return Array(o,n,m,l)}
4890
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)}
4891
function md5_ff(g,f,k,j,e,i,h){return md5_cmn((f&k)|((~f)&j),g,f,e,i,h)}
4892
function md5_gg(g,f,k,j,e,i,h){return md5_cmn((f&j)|(k&(~j)),g,f,e,i,h)}
4893
function md5_hh(g,f,k,j,e,i,h){return md5_cmn(f^k^j,g,f,e,i,h)}
4894
function md5_ii(g,f,k,j,e,i,h){return md5_cmn(k^(f|(~j)),g,f,e,i,h)}
4895
function safe_add(a,d){var c=(a&65535)+(d&65535);var b=(a>>16)+(d>>16)+(c>>16);return(b<<16)|(c&65535)}
4896
function bit_rol(a,b){return(a<<b)|(a>>>(32-b))};
4897
4898
4899
4900
4901
4902
var p = new panel("Youtube Radio", ["custom_background", "remap", "metadb"]);
4903
var im = new images(0, 0, 0, 0);
4904
var th = new thumbs();
4905
4906
on_item_focus_change();
4907
4908
function on_playback_time(time) {
4909
    im.playback_time(time);
4910
//if (ooo2 == "" || ooo2 == "?") if (time==30) im.downloadLFM1();
4911
}
4912
4913
4914
function on_metadb_changed() {
4915
	im.metadb_changed();
4916
}
4917
4918
//Button
4919
4920
var Buttons;
4921
4922
var g_tooltip = window.CreateTooltip();
4923
var g_down = false;
4924
4925
var btn_down = null;
4926
var cur_btn = null;
4927
4928
ButtonStates = {
4929
	normal: 0,
4930
	hover: 1,
4931
	down: 2
4932
}
4933
4934
function Button(x, y, w, h, img_src, func, tiptext)  {
4935
	this.left = x;
4936
	this.top = y;
4937
	this.w = w;
4938
	this.h = h;
4939
	this.right = x + w;
4940
	this.bottom = y + h;
4941
	this.func = func;
4942
	this.tiptext = tiptext;
4943
	this.state = ButtonStates.normal;
4944
	this.img_normal = img_src && img_src.normal ? gdi.Image(img_src.normal) : null;
4945
	this.img_hover = img_src && img_src.hover ? gdi.Image(img_src.hover) : this.img_normal;
4946
	this.img_down = img_src && img_src.down ? gdi.Image(img_src.down) : this.img_hover;
4947
	this.img = this.img_normal;
4948
	
4949
	this.alterImage = function(img_src) {
4950
		this.img_normal = img_src && img_src.normal ? gdi.Image(img_src.normal) : null;
4951
		this.img_hover = img_src && img_src.hover ? gdi.Image(img_src.hover) : this.img_normal;
4952
		this.img_down = img_src && img_src.down ? gdi.Image(img_src.down) : this.img_hover;
4953
		
4954
		this.changeState(this.state);
4955
	}
4956
	
4957
	this.traceMouse = function (x, y) {
4958
		var b = (this.left < x) && (x < this.right) && (this.top < y) && (y < this.bottom);
4959
		if (b)
4960
			g_down ? this.changeState(ButtonStates.down) : this.changeState(ButtonStates.hover);
4961
		else
4962
			this.changeState(ButtonStates.normal);
4963
		return b;
4964
	}
4965
	
4966
	
4967
	this.changeState = function (newstate) {
4968
		if (newstate != this.state)
4969
			window.RepaintRect(this.left, this.top, this.w, this.h);
4970
		this.state = newstate;
4971
		switch (this.state)
4972
		{
4973
		case ButtonStates.normal:
4974
			this.img = this.img_normal;
4975
			break;
4976
			
4977
		case ButtonStates.hover:
4978
			this.img = this.img_hover;
4979
			break;
4980
			
4981
		case ButtonStates.down:
4982
			this.img = this.img_down;
4983
			break;
4984
			
4985
		default:
4986
			this.img = null;
4987
		}
4988
	}
4989
	
4990
	this.draw = function (gr) {
4991
		this.img && gr.DrawImage(this.img, this.left, this.top, this.w, this.h, 0, 0, this.w, this.h);
4992
	}
4993
	
4994
	this.onClick = function () {
4995
		this.func && this.func(x,y);
4996
	}
4997
	
4998
	this.onMouseIn = function() {
4999
		g_tooltip.Text = this.tiptext;
5000
		g_tooltip.Activate();
5001
	}
5002
	
5003
	this.onMouseOut = function() {
5004
		g_tooltip.Deactivate();
5005
	}
5006
}
5007
5008
function buttonsDraw(gr) {
5009
	for (i in Buttons) {
5010
		Buttons[i].draw(gr);
5011
	}
5012
}
5013
5014
function buttonsTraceMouse(x, y) {
5015
	var btn = null;
5016
	for (i in Buttons) {
5017
		if (Buttons[i].traceMouse(x, y) && !btn)
5018
			btn = Buttons[i];
5019
	}
5020
5021
	return btn;
5022
}
5023
5024
function on_mouse_move(x, y) {
5025
	var btn = buttonsTraceMouse(x, y);
5026
	
5027
	if (btn != cur_btn) {
5028
		cur_btn && cur_btn.onMouseOut();
5029
		btn && btn.onMouseIn();
5030
	}
5031
	
5032
	cur_btn = btn;
5033
}
5034
5035
function on_mouse_lbtn_down(x, y) {
5036
	g_down = true;
5037
	btn_down = cur_btn;
5038
5039
	if (cur_btn) {
5040
		cur_btn.changeState(ButtonStates.down);
5041
	}
5042
}
5043
5044
function on_mouse_lbtn_up(x, y) {
5045
	if (cur_btn) {
5046
		cur_btn.changeState(ButtonStates.hover);
5047
		if( btn_down == cur_btn )
5048
			cur_btn.onClick(x, y);
5049
	}
5050
	g_down = false;
5051
}
5052
5053
function on_mouse_leave() {
5054
	if (cur_btn) {
5055
		cur_btn.changeState(ButtonStates.normal);
5056
	}
5057
}
5058
5059
function on_size() {
5060
	ww = window.Width;
5061
	wh = window.Height;
5062
    window.Repaint();
5063
}
5064
5065
function on_paint(gr) {
5066
	/*switch(window.GetProperty("mode", 1)) {
5067
		case 1:
5068
			//col = window.GetColorDUI(1);
5069
			break;
5070
		case 2:
5071
			col = utils.GetSysColor(4);
5072
			break;
5073
		case 3:
5074
			col = custom;
5075
			break;
5076
	}*/
5077
	//gr.FillSolidRect(0, 0, ww, wh, col);
5078
	buttonsDraw(gr);
5079
	//gr.DrawRect(0,0, ww, wh, 1.0, -6250336);
5080
}
5081
5082
function RGB(r,g,b) {
5083
	return (0xff000000|(r<<16)|(g<<8)|(b)); 
5084
}
5085
5086
function on_colors_changed() {
5087
    window.Repaint();
5088
}
5089
5090
5091
//init Buttons
5092
5093
//custom colour accessed through the context menu
5094
var custom = RGB(255,255,255);
5095
5096
//button width
5097
var bw = 24;
5098
//button height
5099
var bh = 20;
5100
5101
//Button position
5102
var top_margin = -1;
5103
var left_margin = 0;
5104
5105
var image_path0 = window.GetProperty("Button Path", fb.ProfilePath + "image");
5106
var image_path = (image_path0 + "\\");
5107
5108
//these 2 lines of code lock the panel size. you can comment them out or change the dimensions to suit
5109
//window.MinWidth = window.MaxWidth = 24;
5110
//window.MinHeight = window.MaxHeight = 20;
5111
5112
5113
5114
Buttons = {
5115
	but1: new Button(left_margin,top_margin,bw,bh, {normal: image_path + "youtube0.png", hover: image_path + "youtube1.png"}, function(){
5116
        //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)
5117
        p.rbtn_up(24, 17);
5118
        //im.downloadONE();
5119
        /*else
5120
        {
5121
        p.artist = p.eval("%artist% %title%");
5122
        p.browser("http://www.youtube.com/results?search_query=" + encodeURIComponent(p.artist) + "&ie=utf-8");
5123
    }*/
5124
        }, "Youtube")
5125
	
5126
}
5127
5128
//fb.RunMainMenuCommand("Library/Search");
5129
//fb.RunContextCommand("Open containing folder");
5130
5131
function on_mouse_rbtn_up(x, y) {
5132
return true;
5133
}