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