Last active
August 29, 2015 14:27
-
-
Save mire777/5463968b477b753e6d96 to your computer and use it in GitHub Desktop.
Biography Photos
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==PREPROCESSOR== | |
// @name "Biography Photos" | |
// @author "Mire777" | |
// @feature "v1.4" | |
// @feature "watch-metadb" | |
// ==/PREPROCESSOR== | |
// Paths | |
var fbfolder = (fb.ProfilePath + "Artist_info"); | |
var lfm_folder = window.GetProperty("Custom folder", fbfolder); | |
//Image download size | |
size = window.GetProperty("Download quality","medium"); | |
//Download server | |
server = window.GetProperty("Download source", "last.fm"); | |
//Search terms(google) | |
terms = window.GetProperty("Custom search terms", ""); | |
//Google domen | |
g_domain = window.GetProperty("Google domain", "com"); | |
//Cycle | |
cycle2 = window.GetProperty("Image cycle", 10); | |
var VERSION = "7.2013-10-19.01"; | |
var DT_LEFT = 0x00000000; | |
var DT_CENTER = 0x00000001; | |
var DT_RIGHT = 0x00000002; | |
var DT_VCENTER = 0x00000004; | |
var DT_WORDBREAK = 0x00000010; | |
var DT_CALCRECT = 0x00000400; | |
var DT_NOPREFIX = 0x00000800; | |
var DT_END_ELLIPSIS = 0x00008000; | |
var MF_GRAYED = 0x00000001; | |
var MF_STRING = 0x00000000; | |
var IDC_ARROW = 32512; | |
var IDC_HAND = 32649; | |
var ONE_DAY = 86400000; | |
var ONE_WEEK = 604800000; | |
String.prototype.addCommas = function() { | |
return this.replace(/\B(?=(\d{3})+(?!\d))/g, ","); | |
} | |
String.prototype.trim = function() { | |
return this.replace(/^\s+|\s+$/g, ""); | |
} | |
String.prototype.ucfirst = function() { | |
return this.charAt(0).toUpperCase() + this.substr(1); | |
} | |
function RGB(r, g, b) { | |
return (0xff000000 | (r << 16) | (g << 8) | (b)); | |
} | |
function RGBA(r, g, b, a) { | |
return ((a << 24) | (r << 16) | (g << 8) | (b)); | |
} | |
function on_colors_changed() { | |
p.colors_changed(); | |
} | |
function on_font_changed() { | |
p.font_changed(); | |
} | |
function on_selection_changed() { | |
p.item_focus_change(); | |
} | |
function on_playlist_switch() { | |
p.item_focus_change(); | |
} | |
function on_playback_new_track() { | |
p.item_focus_change(); | |
} | |
function on_playback_dynamic_info_track() { | |
p.item_focus_change(); | |
} | |
function on_playback_stop() { | |
p.item_focus_change(); | |
} | |
function on_item_focus_change() { | |
p.item_focus_change(); | |
} | |
function on_mouse_leave() { | |
if (typeof b == "object") b.leave(); | |
if (typeof r == "object") r.leave(); | |
if (typeof li == "object") li.leave(); | |
if (typeof s == "object") s.leave(); | |
} | |
function on_mouse_rbtn_up(x, y) { | |
p.rbtn_up(x, y); | |
return true; | |
} | |
function on_notify_data(name, data) { | |
if (name == "lastfm" && data == "update" && typeof l == "object") l.notify_data(name, data); | |
if (name == "autoplaylists" && data == "update" && typeof li == "object" && li.mode == "autoplaylists") li.update(); | |
if (name == "images" && data == "update" && typeof im == "object") im.update(); | |
if (name == "love" && typeof ps == "object") l.post(fb.TitleFormat("%LASTFM_LOVED_DB%").EvalWithMetadb(data) == 1 ? "track.unlove" : "track.love", data); | |
} | |
function panel(name, features) { | |
this.item_focus_change = function() { | |
if (!this.metadb_func) return; | |
switch(this.selection_mode) { | |
case 0: | |
this.metadb = fb.GetSelection(); | |
break; | |
case 1: | |
this.metadb = fb.IsPlaying ? fb.GetNowPlaying() : fb.GetFocusItem(); | |
break; | |
case 2: | |
this.metadb = fb.GetFocusItem(); | |
break; | |
} | |
if (this.metadb) on_metadb_changed(); | |
} | |
this.colors_changed = function() { | |
if (this.dui) { | |
this.background_mode=(1); | |
this.textcolour = window.GetColorDUI(0); | |
this.textcolour_hl = window.GetColorDUI(2); | |
this.backcolour = window.GetColorDUI(1); | |
} else { | |
this.background_mode=(0); | |
this.textcolour = window.GetColorCUI(0); | |
this.textcolour_hl = window.GetColorCUI(0); | |
this.backcolour = window.GetColorCUI(3); | |
} | |
window.Repaint(); | |
} | |
this.font_changed = function() { | |
this.font = this.dui ? window.GetFontDUI(0) : window.GetFontCUI(0); | |
try { | |
this.font_name = this.font.Name; | |
} catch(e) { | |
this.console("Unable to use your default font. Using Segoe UI instead."); | |
this.font_name = "Segoe ui"; | |
} | |
this.title_font = gdi.Font(this.font_name, 16, 1); | |
this.normal_font = gdi.Font("segoe ui", 12, 1); | |
this.fixed_font = gdi.Font("Lucida Console", this.normal_font_size); | |
this.list_font = gdi.Font(this.font_name, this.list_font_size); | |
this.row_height = this.normal_font.Height + 2; | |
if (typeof t == "object") t.size(); | |
window.Repaint(); | |
} | |
this.size = function() { | |
this.w = window.Width; | |
this.h = window.Height; | |
} | |
this.move = function(x, y) { | |
this.mx = x; | |
this.my = y; | |
} | |
//Menu | |
this.rbtn_up = function(x, y) { | |
var _menu = window.CreatePopupMenu(); | |
var idx; | |
switch(true) { | |
case typeof a == "object" && a.trace(x, y): | |
_menu.AppendMenuItem(MF_STRING, 17, "adjust"); | |
_menu.AppendMenuItem(MF_STRING, 18, "Stretch"); | |
_menu.CheckMenuRadioItem(15, 18, a.type == "centre" ? 15 : a.type == "top" ? 16 : a.type == "adjust" ? 17 : 18); | |
_menu.AppendMenuSeparator(); | |
break; | |
case typeof th == "object": | |
case typeof im == "object" && im.trace(x, y): | |
var _settings = window.CreatePopupMenu(); | |
var _auto_cycle = window.CreatePopupMenu(); | |
var _download_source = window.CreatePopupMenu(); | |
var _download_limit = window.CreatePopupMenu(); | |
var _download_quality = window.CreatePopupMenu(); | |
var _thumbs = window.CreatePopupMenu(); | |
var MF_POPUP = 0x00000010; | |
_menu.AppendMenuItem(MF_STRING, 403, "Refresh"); | |
_menu.AppendMenuSeparator(); | |
//Settings Menu | |
_menu.AppendMenuItem(MF_STRING | MF_POPUP, _settings.ID, "Settings"); | |
_menu.AppendMenuSeparator(); | |
_settings.AppendMenuItem(MF_STRING | MF_POPUP, _auto_cycle.ID, "Auto Cycle"); | |
_auto_cycle.AppendMenuItem(MF_STRING, 415, "05 sec"); | |
_auto_cycle.AppendMenuItem(MF_STRING, 420, "10 sec"); | |
_auto_cycle.AppendMenuItem(MF_STRING, 425, "15 sec"); | |
_auto_cycle.AppendMenuItem(MF_STRING, 430, "20 sec"); | |
_auto_cycle.AppendMenuItem(MF_STRING, 410, "Off"); | |
_auto_cycle.CheckMenuRadioItem(410, 430, cycle2 + 410); | |
_settings.AppendMenuItem(MF_STRING | MF_POPUP, _download_source.ID, "Download Source"); | |
_download_source.AppendMenuItem(MF_STRING, 1902, "Last.fm"); | |
_download_source.AppendMenuItem(MF_STRING, 1903, "Google"); | |
_download_source.CheckMenuRadioItem(1902, 1904, server == "last.fm" ? 1902 : server == "google" ? 1903 : 1903); | |
_settings.AppendMenuItem(MF_STRING | MF_POPUP, _download_limit.ID, "Download Limit"); | |
_download_limit.AppendMenuItem(MF_STRING, 1905, "1x"); | |
_download_limit.AppendMenuItem(MF_STRING, 1906, "2x"); | |
_download_limit.AppendMenuItem(MF_STRING, 1907, "3x"); | |
_download_limit.AppendMenuItem(MF_STRING, 1908, "4x"); | |
_download_limit.AppendMenuItem(MF_STRING, 1909, "5x"); | |
_download_limit.AppendMenuItem(MF_STRING, 1910, "6x"); | |
_download_limit.CheckMenuRadioItem(1905, 1910, im.limit + 1904); | |
if (server=="last.fm") _settings.AppendMenuItem(MF_STRING | MF_POPUP, _download_quality.ID, "Download Quality"); | |
_download_quality.AppendMenuItem(MF_STRING, 1911, "Low"); | |
_download_quality.AppendMenuItem(MF_STRING, 1912, "Medium"); | |
_download_quality.AppendMenuItem(MF_STRING, 1913, "High"); | |
_download_quality.CheckMenuRadioItem(1911, 1913, size == "low" ? 1911 : size == "medium" ? 1912 : size == "high" ? 1913 : 1913); | |
_settings.AppendMenuItem(MF_STRING | MF_POPUP, _thumbs.ID, "Thumbs"); | |
_thumbs.AppendMenuItem(MF_STRING, 1201, "Left"); | |
_thumbs.AppendMenuItem(MF_STRING, 1202, "Right"); | |
_thumbs.AppendMenuItem(MF_STRING, 1203, "Top"); | |
_thumbs.AppendMenuItem(MF_STRING, 1204, "Bottom"); | |
_thumbs.AppendMenuItem(MF_STRING, 1205, "Off"); | |
_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); | |
if (th.mode == "left" | th.mode == "right" | th.mode == "top" | th.mode == "bottom") | |
{ | |
_thumbs.AppendMenuSeparator(); | |
_thumbs.AppendMenuItem(MF_STRING, 1240, "40px"); | |
_thumbs.AppendMenuItem(MF_STRING, 1250, "50px"); | |
_thumbs.AppendMenuItem(MF_STRING, 1260, "60px"); | |
_thumbs.AppendMenuItem(MF_STRING, 1270, "70px"); | |
_thumbs.AppendMenuItem(MF_STRING, 1280, "80px"); | |
_thumbs.AppendMenuItem(MF_STRING, 1290, "90px"); | |
_thumbs.AppendMenuItem(MF_STRING, 1300, "100px"); | |
_thumbs.AppendMenuItem(MF_STRING, 1350, "150px"); | |
_thumbs.AppendMenuItem(MF_STRING, 1400, "200px"); | |
_thumbs.AppendMenuItem(MF_STRING, 1450, "250px"); | |
_thumbs.AppendMenuItem(MF_STRING, 1500, "300px"); | |
_thumbs.CheckMenuRadioItem(1240, 1500, th.px + 1200); | |
} | |
{ | |
_menu.AppendMenuItem(MF_STRING, 400, "Open Folder"); | |
if (server=="last.fm") _menu.AppendMenuItem(MF_STRING, 21, "Open Last.fm"); | |
if (server=="google") _menu.AppendMenuItem(MF_STRING, 21, "Open Google"); | |
//_menu.AppendMenuItem(MF_STRING, 402, "Delete image"); | |
_menu.AppendMenuSeparator(); | |
_menu.AppendMenuItem(MF_STRING, 405, "Top"); | |
_menu.AppendMenuItem(MF_STRING, 404, "Centre"); | |
_menu.AppendMenuItem(MF_STRING, 406, "Adjust"); | |
_menu.AppendMenuItem(MF_STRING, 407, "Stretch"); | |
_menu.CheckMenuRadioItem(404, 407, im.type == "centre" ? 404 : im.type == "top" ? 405 : im.type == "adjust" ? 406 : 407); | |
_menu.AppendMenuSeparator(); | |
} | |
break; | |
} | |
if (typeof ps == "object") _menu.AppendMenuItem(l.username.length > 0 ? MF_STRING : MF_GRAYED, 1901, "Last.fm password..."); | |
_menu.AppendMenuItem(MF_STRING, 9, "Properties..."); | |
if (utils.IsKeyPressed(0x10)) _menu.AppendMenuItem(MF_STRING, 10, "Configure..."); | |
idx = _menu.TrackPopupMenu(x, y); | |
switch(idx) { | |
case 9: | |
window.ShowProperties(); | |
break; | |
case 10: | |
window.ShowConfigure(); | |
break; | |
case 15: | |
case 16: | |
case 17: | |
case 18: | |
a.type = idx == 15 ? "centre" : idx == 16 ? "top" : idx == 17 ? "adjust" : "stretch"; | |
window.SetProperty("artreader_image_type", a.type); | |
window.RepaintRect(a.x, a.y, a.w, a.h); | |
break; | |
case 21: | |
if (server=="last.fm") this.browser("http://www.last.fm/music/" + encodeURIComponent(p.artist)); | |
else | |
if (server=="google") this.browser("https://www.google.rs/search?&tbm=isch&q=" + encodeURIComponent(p.artist) + "+" + terms + "&tbs=isz:m"); | |
break; | |
case 400: | |
this.run("explorer /select,\"" + im.files[im.index] + "\""); | |
break; | |
case 403: | |
if (im.images.length < im.limit) | |
{ | |
p.run("RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 8"); | |
//fix_limit = im.limit; | |
im.download(); | |
im.update(); | |
} | |
else | |
p.run("RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 8"); | |
im.update(); | |
break; | |
case 404: | |
case 405: | |
case 406: | |
case 407: | |
im.type = idx == 404 ? "centre" : idx == 405 ? "top" : idx == 406 ? "adjust" : "stretch"; | |
window.SetProperty("Image type", im.type); | |
window.Repaint(); | |
break; | |
case 410: | |
case 415: | |
case 420: | |
case 425: | |
case 430: | |
cycle2 = idx - 410; | |
window.SetProperty("Image cycle", cycle2); | |
cicleTimer = undefined; | |
cicleTimerStarted = false; | |
stopTimer(); | |
startTimer(); | |
cicleTimerStarted = true; | |
break; | |
case 1200: | |
case 1201: | |
case 1202: | |
case 1203: | |
case 1204: | |
case 1205: | |
th.mode = idx == 1200 ? "grid" : idx == 1201 ? "left" : idx == 1202 ? "right" : idx == 1203 ? "top" : idx == 1204 ? "bottom" : "off"; | |
window.SetProperty("Thumbs mode", th.mode); | |
th.nc = true; | |
on_size(); | |
window.Repaint(); | |
break; | |
case 1240: | |
case 1250: | |
case 1260: | |
case 1270: | |
case 1280: | |
case 1290: | |
case 1300: | |
case 1350: | |
case 1400: | |
case 1450: | |
case 1500: | |
th.px = idx - 1200; | |
window.SetProperty("Thumbs px", th.px); | |
th.nc = true; | |
on_size(); | |
window.Repaint(); | |
break; | |
case 1902: | |
case 1903: | |
case 1904: | |
server = idx == 1902 ? "last.fm" : idx == 1903 ? "google" : "google"; | |
window.SetProperty("Download source", server); | |
break; | |
case 1905: | |
case 1906: | |
case 1907: | |
case 1908: | |
case 1909: | |
case 1910: | |
im.limit = idx - 1904; | |
window.SetProperty("Download limit", im.limit); | |
break; | |
case 1911: | |
case 1912: | |
case 1913: | |
size = idx == 1911 ? "low" : idx == 1912 ? "medium" : idx == 1913 ? "high" : "high"; | |
window.SetProperty("Download quality", size); | |
break; | |
} | |
_menu.Dispose(); | |
} | |
this.features_init = function() { | |
for (i = 0; i < this.features.length; i++) { | |
switch(this.features[i]) { | |
case "custom_background": | |
//this.background_mode = (0); | |
//window.GetProperty("background_mode", 0); | |
//this.background_custom_colour = ("0-0-0"); | |
//window.GetProperty("background_custom_colour", "0-0-0"); | |
break; | |
case "metadb": | |
this.selection_mode = window.GetProperty("Selection mode", 1); | |
break; | |
case "themes": | |
this.themed_seekbar = window.CreateThemeManager("Progress"); | |
this.themed_header = window.CreateThemeManager("Header"); | |
this.themed_header.SetPartAndStateId(1, 1); | |
this.themed_button = window.CreateThemeManager("Button"); | |
break; | |
case "remap": | |
this.artist_tf = window.GetProperty("Artist format", "%artist%"); | |
break; | |
} | |
} | |
} | |
this.check_feature = function(f) { | |
for (i = 0; i < this.features.length; i++) { | |
if (this.features[i] == f) return true; | |
} | |
return false; | |
} | |
this.eval = function(tf) { | |
if (!this.metadb || tf == "") return ""; | |
if (fb.IsPlaying && this.metadb.RawPath.indexOf("file://") != 0) { | |
return fb.TitleFormat(tf).Eval(); | |
} else { | |
return fb.TitleFormat(tf).EvalWithMetadb(this.metadb); | |
} | |
} | |
this.open = function(filename) { | |
return utils.ReadTextFile(filename); | |
} | |
this.save = function(t, f) { | |
try { | |
var ts = this.fso.OpenTextFile(f, 2, true, -1); | |
ts.WriteLine(t); | |
ts.Close(); | |
return true; | |
} catch(e) { | |
return false; | |
} | |
} | |
this.console = function(message) { | |
fb.trace(this.name + ": " + message); | |
} | |
this.strip_tags = function(value) { | |
if (!this.doc) this.doc = new ActiveXObject("htmlfile"); | |
try { | |
this.doc.open(); | |
var div = this.doc.createElement("div"); | |
div.innerHTML = value.replace(/\n/g, "<br>"); | |
return div.innerText.trim(); | |
} catch(e) { | |
return "Error reading content."; | |
} | |
} | |
this.InputBox = function(prompt, title, value) { | |
prompt = prompt.replace(/"/g, '" + Chr(34) + "').replace(/\n/g, '" + Chr(13) + "'); | |
title = title.replace(/"/g, '" + Chr(34) + "'); | |
value = value.replace(/"/g, '" + Chr(34) + "'); | |
var temp_value = this.vb.eval('InputBox' + '("' + prompt + '", "' + title + '", "' + value + '")'); | |
if (typeof temp_value == "undefined") return value; | |
if (temp_value.length == 254) this.MsgBox("Your entry was too long and will be truncated.\n\nSee the WSH panel mod script discussion thread on hydrogenaudio forums for help.", 0, this.name); | |
return temp_value.trim(); | |
} | |
this.MsgBox = function(prompt, buttons, title) { | |
prompt = prompt.replace(/"/g, '" + Chr(34) + "').replace(/\n/g, '" + Chr(13) + "'); | |
title = title.replace(/"/g, '" + Chr(34) + "'); | |
return this.vb.eval('MsgBox' + '("' + prompt + '", "' + buttons + '", "' + title + '")'); | |
} | |
this.browser = function(command) { | |
if (!this.run(command)) this.MsgBox("Unable to launch your default browser.", 0, this.name); | |
} | |
this.run = function(command) { | |
try { | |
this.WshShell.Run(command); | |
return true; | |
} catch(e) { | |
return false; | |
} | |
} | |
this.aad = function() { | |
if (!this.app) this.app = new ActiveXObject("Shell.Application"); | |
var aad_path = window.GetProperty("aad_path", ""); | |
if (!this.fso.FileExists(aad_path)) { | |
var folder = this.app.BrowseForFolder(0, "Locate Album Art Downloader", 0x00000200); | |
var file = folder ? folder.items().item().path + "\\AlbumArt.exe" : ""; | |
if (this.fso.FileExists(file)) { | |
aad_path = file; | |
window.SetProperty("aad_path", file); | |
} | |
} | |
if (this.fso.FileExists(aad_path)) { | |
var album_artist = "/ar \"" + this.eval("[%album artist%]") + "\""; | |
var album = " /al \"" + this.eval("[%album%]") + "\""; | |
this.run("\"" + aad_path + "\"" + album_artist + album); | |
} | |
} | |
this.tt = function(t) { | |
if (this.tooltip.Text == t) return; | |
this.tooltip.Text = t; | |
this.tooltip.Activate(); | |
} | |
this.ttd = function() { | |
this.tooltip.Text = ""; | |
this.tooltip.Deactivate(); | |
} | |
this.splitRGB = function(value) { | |
var temp_col = value.split("-"); | |
return RGB(temp_col[0], temp_col[1], temp_col[2]); | |
} | |
this.draw_background = function(gr) { | |
if (this.check_feature("custom_background")) { | |
var col; | |
switch(this.background_mode) { | |
case 0: | |
col = null; | |
break; | |
case 1: | |
col = this.backcolour; | |
break; | |
case 2: | |
col = utils.GetSysColor(15); | |
break; | |
case 3: | |
col = this.splitRGB(this.background_custom_colour); | |
break; | |
case 4: | |
col = null; | |
var spacing = 3; | |
var line_thickness = 1; | |
var bg = RGB(65, 65, 65); | |
var colour = RGB(92, 92, 92); | |
gr.FillSolidRect(0, 0, this.w, this.h, bg); | |
for (i = 0; i < Math.ceil(this.w / spacing); i++) { | |
gr.DrawLine(i * spacing, 0, i * spacing, this.h, line_thickness, colour); | |
} | |
for (i = 0; i < Math.ceil(this.h / spacing); i++) { | |
gr.DrawLine(0, i * spacing, this.w, i * spacing, line_thickness, colour); | |
} | |
break; | |
} | |
if (col) gr.FillSolidRect(0, 0, this.w, this.h, col); | |
} else { | |
gr.FillSolidRect(0, 0, this.w, this.h, this.backcolour); | |
} | |
} | |
this.draw_image = function(gr, img, pos_x, pos_y, width, height, type, border, alpha) { | |
if (!img) return; | |
gr.SetInterpolationMode(7); | |
switch(type) { | |
case "centre": | |
case "top": | |
{ | |
var sr = img.Width / img.Height; | |
var dr = width / height; | |
if (sr < dr) { | |
var r = img.Width / width; | |
var ch = height * r; | |
var sy = Math.round((img.Height - ch) / (type == "top" ? 1000 : 2)); | |
var cw = img.Width; | |
var sx = 0; | |
} else { | |
var r = img.Height / height; | |
var cw = width * r; | |
var sx = Math.round((img.Width - cw) / 2); | |
var ch = img.Height; | |
var sy = 0; | |
} | |
{ | |
gr.DrawImage(img, pos_x, pos_y, width, height, sx + 5, sy + 5, cw - 10, ch - 10, 0, alpha || 255); | |
if (border) gr.DrawRect(pos_x, pos_y, width - 1, height - 1, 1, border); | |
} | |
} | |
break; | |
case "stretch": | |
//strech | |
gr.DrawImage(img, pos_x, pos_y, width, height, 5, 5, img.Width-10, img.Height-10, 0, alpha || 255); | |
if (border) gr.DrawRect(pos_x, pos_y, width - 1, height - 1, 1, border); | |
break; | |
case "adjust": | |
default: | |
//adjust | |
var s = Math.min(width / img.Width, height / img.Height); | |
var nw = Math.round(img.Width * s); | |
var nh = Math.round(img.Height * s); | |
pos_x += Math.round((width - nw) / 2); | |
pos_y += Math.round((height - nh) / 2); | |
gr.DrawImage(img, pos_x, pos_y, nw, nh, 5, 5, img.Width-10, img.Height-10, 0, alpha || 255); | |
if (border) gr.DrawRect(pos_x, pos_y, nw - 1, nh - 1, 1, border); | |
break; | |
} | |
} | |
this.header = function(gr, text) { | |
this.left_text(gr, text, this.title_font, this.textcolour_hl, 6, 6, this.w - 77, 24); | |
gr.DrawLine(6, 29, this.w - 6, 29, 1, this.textcolour_hl); | |
} | |
this.centre_text = function(gr, text, font, colour, x, y, w, h) { | |
gr.GdiDrawText(text, font, colour, x, y, w, h, DT_VCENTER | DT_CENTER | DT_WORDBREAK | DT_CALCRECT | DT_NOPREFIX); | |
} | |
this.left_text = function(gr, text, font, colour, x, y, w, h) { | |
gr.GdiDrawText(text, font, colour, x, y, w, h, DT_VCENTER | DT_END_ELLIPSIS | DT_CALCRECT | DT_NOPREFIX); | |
} | |
this.right_text = function(gr, text, font, colour, x, y, w, h) { | |
gr.GdiDrawText(text, font, colour, x, y, w, h, DT_VCENTER | DT_RIGHT | DT_END_ELLIPSIS | DT_CALCRECT | DT_NOPREFIX); | |
} | |
this.format_time = function(t) { | |
var h = Math.floor(t / 3600); | |
var m = Math.floor((t -= h * 3600) / 60); | |
var s = Math.floor(t -= m * 60); | |
return((h > 0 ? h + ":" + (m < 10 ? "0" + m : m) : m) + ":" + (s < 10 ? "0" + s : s)); | |
} | |
this.check_version = function() { | |
//not used any more but will leave intact so old scripts don't crash. | |
return; | |
} | |
this.update_script = function() { | |
if (!this.xmlhttp) this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); | |
this.xmlhttp.open("GET", this.common_url, true); | |
this.xmlhttp.send(); | |
this.xmlhttp.onreadystatechange = function() { | |
if (p.xmlhttp.readyState == 4) { | |
switch(p.xmlhttp.status) { | |
case 200: | |
var text = p.xmlhttp.responsetext; | |
switch (true) { | |
case text.indexOf("function panel") == -1: | |
p.MsgBox("Unexpected server error. Not updating.", 0, p.name); | |
break; | |
case text.indexOf('var VERSION = "' + VERSION) == 0: | |
p.MsgBox("Already using latest version.", 0, p.name); | |
break; | |
default: | |
if (p.save(text, p.common_filename)) { | |
if (p.MsgBox("Download successful. Restart foobar2000 now?", 4, p.name) == 6) fb.RunMainMenuCommand("File/Restart"); | |
} else { | |
p.MsgBox("Unexpected error. Not updating.", 0, p.name); | |
} | |
break; | |
} | |
break; | |
case 404: | |
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); | |
break; | |
default: | |
p.console(p.xmlhttp.responsetext || "HTTP error: " + p.xmlhttp.status); | |
break; | |
} | |
} | |
} | |
} | |
//remove false string from file names | |
this.clean_filename = function(filename) { | |
return filename.replace(/[\/\\|:]/g, '-').replace(/\*/g, 'x').replace(/"/g, "''").replace(/[?<>]/g, '_'); | |
} | |
this.json_parse = function(text) { | |
try { | |
var data = JSON.parse(text); | |
return data; | |
} catch(e) { | |
this.console("JSON.parse error."); | |
return false; | |
} | |
} | |
this.name = name; | |
this.features = features; | |
this.dui = window.InstanceType; | |
this.script_path = fb.ProfilePath; | |
this.images_path = this.script_path + "images\\"; | |
this.root_url = "https://dl.dropboxusercontent.com/u/22801321/wsh/" | |
this.common_url = this.root_url + "marc2003/common7.js"; | |
this.common_filename = this.script_path + "common7.js"; | |
this.tooltip = window.CreateTooltip(); | |
this.w = 0; | |
this.h = 0; | |
this.mx = 0; | |
this.my = 0; | |
this.metadb = fb.GetFocusItem(); | |
this.WshShell = new ActiveXObject("WScript.Shell"); | |
this.fso = new ActiveXObject("Scripting.FileSystemObject"); | |
this.vb = new ActiveXObject("ScriptControl"); | |
this.vb.Language = "VBScript"; | |
//this.settings_folder = fb.ProfilePath + "last_fm\\"; | |
//if (!this.fso.FolderExists(this.settings_folder)) this.fso.CreateFolder(this.settings_folder); | |
this.data_folder = lfm_folder + "\\"; | |
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; | |
if (!this.fso.FolderExists(this.data_folder)) return; | |
this.artist = ""; | |
this.artist_tf = "%artist%"; | |
this.normal_font_size = (12); | |
//window.GetProperty("normal_font_size", 12); | |
this.list_font_size = 11; | |
this.up_img = gdi.Image(this.images_path + "up.png"); | |
this.down_img = gdi.Image(this.images_path + "down.png"); | |
this.metadb_func = typeof on_metadb_changed == "function"; | |
this.features_init(); | |
this.colors_changed(); | |
this.font_changed(); | |
} | |
function artreader(x, y, w, h) { | |
this.draw = function(gr) { | |
if (!this.img) return; | |
p.draw_image(gr, this.img, this.x, this.y, this.w, this.h, this.type); | |
} | |
this.metadb_changed = function() { | |
if (!p.metadb) return; | |
this.img && this.img.Dispose(); | |
this.path = ""; | |
this.img = utils.GetAlbumArtV2(p.metadb, this.id); | |
window.RepaintRect(this.x, this.y, this.w, this.h); | |
utils.GetAlbumArtAsync(window.ID, p.metadb, this.id); | |
} | |
this.get_album_art_done = function(ip) { | |
this.path = ip; | |
} | |
this.trace = function(x, y) { | |
return (x > this.x && x < this.x + this.w && y > this.y && y < this.y + this.h); | |
} | |
this.wheel = function(step) { | |
if (!this.trace(p.mx, p.my)) return false; | |
this.id -= step; | |
if (this.id < 0) this.id = 4; | |
if (this.id > 4) this.id = 0; | |
window.SetProperty("artreader_id", this.id); | |
this.metadb_changed(); | |
return true; | |
} | |
this.move = function(x, y) { | |
if (this.trace(x, y)) { | |
if (this.img) p.tt("Original size: " + this.img.Width + "x" + this.img.Height + "px"); | |
return true; | |
} else { | |
p.ttd(); | |
return false; | |
} | |
} | |
this.lbtn_dblclk = function(x, y) { | |
if (!this.trace(x, y)) return false; | |
if (this.img) p.run("explorer /select,\"" + this.path + "\""); | |
return true; | |
} | |
this.x = x; | |
this.y = y; | |
this.w = w; | |
this.h = h; | |
this.id = window.GetProperty("artreader_id", 0); | |
this.img = null; | |
this.path = null; | |
this.type = window.GetProperty("artreader_image_type", "top"); | |
} | |
function buttons() { | |
this.draw = function(gr) { | |
for (i in this.buttons) { | |
this.buttons[i].draw(gr); | |
} | |
} | |
this.move = function(x, y) { | |
this.tmp_btn = null; | |
for (i in this.buttons) { | |
if (this.buttons[i].trace(x, y)) this.tmp_btn = i; | |
} | |
if (this.btn == this.tmp_btn) return this.btn; | |
if (this.tmp_btn) this.buttons[this.tmp_btn].state("hover"); | |
if (this.btn) this.buttons[this.btn].state("normal"); | |
this.btn = this.tmp_btn; | |
return this.btn; | |
} | |
this.lbtn_up = function(x, y) { | |
if (!this.btn) return false; | |
this.buttons[this.btn].lbtn_up(x, y); | |
return true; | |
} | |
this.leave = function() { | |
if (this.btn) this.buttons[this.btn].state("normal"); | |
this.btn = null; | |
} | |
this.buttons = []; | |
this.btn = null; | |
} | |
function button(x, y, w, h, img_src, func, tiptext, themed) { | |
this.draw = function (gr) { | |
if (this.themed) { | |
p.themed_button.SetPartAndStateId(1, this.id); | |
p.themed_button.DrawThemeBackground(gr, this.x, this.y, this.w, this.h); | |
this.img && p.draw_image(gr, this.img, this.x + Math.round((this.w - this.img.Width) / 2), this.y + Math.round((this.h - this.img.Height) / 2), this.img.Width, this.img.Height, "adjust"); | |
} else { | |
this.img && p.draw_image(gr, this.img, this.x, this.y, this.w, this.h, "adjust"); | |
} | |
} | |
this.trace = function(x, y) { | |
return (x > this.x && x < this.x + this.w && y > this.y && y < this.y + this.h); | |
} | |
this.lbtn_up = function () { | |
this.func && this.func(x, y); | |
} | |
this.state = function(s) { | |
if (s == "hover") { | |
this.img = this.img_hover; | |
this.id = 2; | |
p.tt(this.tiptext); | |
} else { | |
this.img = this.img_normal; | |
this.id = 0; | |
p.ttd(); | |
} | |
window.RepaintRect(this.x, this.y, this.w, this.h); | |
} | |
this.x = x; | |
this.y = y; | |
this.w = w; | |
this.h = h; | |
this.func = func; | |
this.tiptext = tiptext; | |
this.themed = themed; | |
this.id = 0; | |
this.img_normal = gdi.Image(p.images_path + img_src.normal); | |
this.img_hover = img_src.hover ? gdi.Image(p.images_path + img_src.hover) : this.img_normal; | |
this.img = this.img_normal; | |
} | |
function cd(x, y, w, h) { | |
this.draw = function(gr) { | |
if (this.shadow) p.draw_image(gr, this.shadow_img, this.x, this.y, this.w, this.h, "adjust"); | |
p.draw_image(gr, this.case_img, this.x, this.y, this.w, this.h, "adjust"); | |
if (this.img) { | |
this.ratio = Math.min(this.w / this.case_img.Width, this.h / this.case_img.Height); | |
this.nw = 488 * this.ratio; | |
this.nh = 476 * this.ratio; | |
this.nx = Math.round((this.w - (452 * this.ratio)) / 2); | |
this.ny = Math.round((this.h - this.nh) / 2); | |
p.draw_image(gr, this.img, this.nx + this.x, this.ny + this.y, this.nw, this.nh, "top"); | |
} | |
p.draw_image(gr, this.semi_img, this.x, this.y, this.w, this.h, "adjust"); | |
if (this.gloss) p.draw_image(gr, this.gloss_img, this.x, this.y, this.w, this.h, "adjust"); | |
} | |
this.metadb_changed = function() { | |
if (!p.metadb) return; | |
this.img && this.img.Dispose(); | |
this.path = ""; | |
this.img = utils.GetAlbumArtV2(p.metadb, 0); | |
window.Repaint(); | |
utils.GetAlbumArtAsync(window.ID, p.metadb, 0); | |
} | |
this.get_album_art_done = function(ip) {; | |
this.path = ip; | |
} | |
this.trace = function(x, y) { | |
return (x > this.x && x < this.x + this.w && y > this.y && y < this.y + this.h); | |
} | |
this.move = function(x, y) { | |
if (this.trace(x, y)) { | |
if (this.img) p.tt("Original size: " + this.img.Width + "x" + this.img.Height + "px"); | |
return true; | |
} else { | |
p.ttd(); | |
return false; | |
} | |
} | |
this.lbtn_dblclk = function(x, y) { | |
if (!this.trace(x, y)) return false; | |
if (this.img) p.run("explorer /select,\"" + this.path + "\""); | |
return true; | |
} | |
this.x = x; | |
this.y = y; | |
this.w = w; | |
this.h = h; | |
this.shadow_img = gdi.Image(p.images_path + "shadow.png"); | |
this.case_img = gdi.Image(p.images_path + "case.png"); | |
this.semi_img = gdi.Image(p.images_path + "semi.png"); | |
this.gloss_img = gdi.Image(p.images_path + "gloss.png"); | |
this.gloss = window.GetProperty("cd_gloss", false); | |
this.shadow = window.GetProperty("cd_shadow", false); | |
this.img = null; | |
this.path = null; | |
} | |
function images(x, y, w, h) { | |
/*this.playback_time = function(time) { | |
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(); | |
if (this.cycle > 0 && this.images.length > 1 && time % this.cycle == 0) { | |
this.index++; | |
if (this.index == this.images.length) this.index = 0; | |
window.RepaintRect(this.x, this.y, this.w, this.h); | |
} | |
}*/ | |
this.draw = function (gr) { | |
if (this.images.length == 0) return; | |
p.draw_image(gr, this.images[this.index], this.x, this.y, this.w, this.h, this.type); | |
} | |
this.metadb_changed = function() { | |
if (!p.metadb) return false; | |
switch(this.mode) { | |
case "last.fm": | |
p.artist = p.eval(p.artist_tf); | |
if (this.artist == p.artist) return false; | |
this.artist = p.artist; | |
this.folder = p.data_folder + p.clean_filename(p.artist); | |
if (!p.fso.FolderExists(this.folder)) p.fso.CreateFolder(this.folder); | |
break; | |
case "custom": | |
this.temp_folder = p.eval(this.custom_folder_tf); | |
if (this.temp_folder == this.folder) return false; | |
this.folder = this.temp_folder; | |
break; | |
} | |
this.update(); | |
return true; | |
} | |
this.trace = function(x, y) { | |
return (x > this.x && x < this.x + this.w && y > this.y && y < this.y + this.h); | |
} | |
this.wheel = function(step) { | |
if (!p.metadb || this.images.length < 2 || !this.trace(p.mx, p.my) || (typeof th == "object" && th.mode == "grid" && !th.overlay)) return false; | |
this.index -= step; | |
if (this.index < 0) this.index = this.images.length - 1; | |
if (this.index >= this.images.length) this.index = 0; | |
window.RepaintRect(this.x, this.y, this.w, this.h); | |
return true; | |
} | |
this.lbtn_dblclk = function(x, y) { | |
if (!this.trace(x, y)) return false; | |
p.run("\"" + this.files[this.index] + "\""); | |
return true; | |
} | |
//Download Image | |
this.download = function() | |
{ | |
if (!p.fso.FolderExists(this.folder)) return; | |
{ | |
if (server=="last.fm") | |
{{ | |
this.working=true; | |
if (p.artist == "" || p.artist == "?") return; | |
var folder = this.folder + "\\"; | |
if (!this.xmlhttp) this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); | |
this.xmlhttp.open("GET", "http://www.last.fm/music/" + encodeURIComponent(p.artist) + "/+images", true); | |
this.xmlhttp.send(); | |
this.xmlhttp.onreadystatechange = function() { | |
if (im.xmlhttp.readyState == 4) { | |
if (im.xmlhttp.status == 200) { | |
var text = im.xmlhttp.responsetext; | |
if (!im.doc) im.doc = new ActiveXObject("htmlfile"); | |
im.doc.open(); | |
var div = im.doc.createElement("div"); | |
div.innerHTML = text; | |
var data = div.getElementsByTagName("img"); | |
var urls = []; | |
for (i = 0; i < data.length; i++) { | |
if (data[i].src.indexOf("http://img2-ak.lst.fm/i/u/60x60/") == 0) urls.push(data[i].src.replace("60x60", size == "low" ? "252x252" : size == "medium" ? "500x500" : size == "high" ? "_" : "_")); | |
} | |
for (i = 0; i < Math.min(urls.length, im.limit, 50); i++) { | |
p.WshShell.Run("cscript //nologo \"" + p.script_path + "bio_photos.vbs\" \"" + urls[i] + "\" \"" + [folder + p.clean_filename(p.artist) + "_" + i] + urls[i].substring(urls[i].lastIndexOf("/")+1000) + ".jpg" + "\"" , 0, true); | |
if (im.images.length == 0) {im.update();} | |
if (im.images.length == 0) {return;} | |
} | |
im.doc.close(); | |
im.working=false; | |
im.update(); | |
window.NotifyOthers("images", "update"); | |
} else { | |
p.console("HTTP error: " + im.xmlhttp.status); | |
}}}}} | |
else | |
if (server=="google") | |
{{ | |
this.working=true; | |
if (p.artist == "" || p.artist == "?") return; | |
var folder = this.folder + "\\"; | |
if (!this.xmlhttp) this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); | |
this.xmlhttp.open("GET", "https://www.google." + g_domain + "/search?&tbm=isch&q=" + encodeURIComponent(p.artist) + terms + "&tbs=isz:m", true); | |
this.xmlhttp.send(); | |
this.xmlhttp.onreadystatechange = function() { | |
if (im.xmlhttp.readyState == 4) { | |
if (im.xmlhttp.status == 200) { | |
var text = im.xmlhttp.responsetext; | |
if (!im.doc) im.doc = new ActiveXObject("htmlfile"); | |
im.doc.open(); | |
var div = im.doc.createElement("div"); | |
div.innerHTML = text; | |
var data = div.getElementsByTagName("a"); | |
var urls = []; | |
for (i = 0; i < data.length; i++) { | |
if (data[i].href.indexOf("imgurl=") > 0) urls.push(data[i].href.split("imgurl=")[1].split("&imgrefurl")[0]); | |
} | |
for (i = 0; i < Math.min(urls.length, im.limit, 50); i++) { | |
urls[i] = decodeURIComponent(urls[i]); | |
p.console("HTTP: " + urls[i]); | |
p.WshShell.Run("cscript //nologo \"" + p.script_path + "bio_photos.vbs\" \"" + decodeURIComponent(urls[i]) + "\" \"" + [folder + p.clean_filename(p.artist) + "_" + i] + decodeURIComponent(urls[i]).substring(decodeURIComponent(urls[i]).lastIndexOf("d")+1000) + ".jpg" + "\"" , 0, true); | |
if (im.images.length == 0) {im.update();} | |
if (im.images.length == 0) {return;} | |
} | |
im.doc.close(); | |
im.working=false; | |
im.update(); | |
window.NotifyOthers("images", "update"); | |
} else { | |
p.console("HTTP error: " + im.xmlhttp.status + urls); | |
}}}}}}} | |
this.update0 = function() { | |
this.index = 0; | |
for (i = 0; i < this.images.length; i++) { | |
try { this.images[i].Dispose(); } catch(e) {} | |
} | |
this.folders = this.folder.split("|"); | |
this.files = []; | |
for (i = 0; i < this.folders.length; i++) { | |
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()); | |
} | |
this.images = []; | |
for (i = 0; i < this.files.length; i++) { | |
this.images[i] = gdi.Image(this.files[i]); | |
} | |
if (typeof th == "object") { | |
th.nc = true; | |
th.calc(); | |
} | |
window.Repaint(); | |
} | |
this.update = function() { | |
this.index = 0; | |
for (i = 0; i < this.images.length; i++) { | |
try { this.images[i].Dispose(); } catch(e) {} | |
} | |
this.folders = this.folder.split("|"); | |
this.files = []; | |
for (i = 0; i < this.folders.length; i++) { | |
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()); | |
} | |
this.images = []; | |
for (i = 0; i < this.files.length; i++) { | |
this.images[i] = gdi.Image(this.files[i]); | |
} | |
if (typeof th == "object") { | |
th.nc = true; | |
th.calc(); | |
} | |
window.Repaint(); | |
} | |
this.delete_image = function() { | |
if (!this.app) this.app = new ActiveXObject("Shell.Application"); | |
this.app.Namespace(10).MoveHere(this.files[this.index]); | |
window.SetTimeout(function() { | |
im.update(); | |
window.NotifyOthers("images", "update"); | |
}, 100); | |
} | |
this.x = x; | |
this.y = y; | |
this.w = w; | |
this.h = h; | |
this.files = []; | |
this.images = []; | |
this.index = 0; | |
this.artist = ""; | |
this.folder = ""; | |
this.limit = window.GetProperty("Download limit", 6); | |
//this.cycle = window.GetProperty("image_cycle", 0); | |
this.mode = ("last.fm"); | |
//window.GetProperty("image_mode", "last.fm"); | |
this.type = window.GetProperty("Image type", "adjust"); | |
this.auto_download = window.GetProperty("Download [on/off]", "on"); | |
this.custom_folder_tf = "$directory_path(%path%)"; | |
} | |
function lastfm() { | |
this.notify_data = function(name, data) { | |
if (name == "lastfm" && data == "update") { | |
this.username = p.open(this.username_file).trim(); | |
this.sk = p.open(this.sk_file).trim(); | |
if (p.check_feature("lastfm_charts")) li.update(); | |
if (typeof ps == "object") { | |
ps.loved_working = false; | |
ps.playcount_working = false; | |
b.update(); | |
on_item_focus_change(); | |
} | |
if (p.check_feature("lastfm")) { | |
li.artist = ""; | |
on_item_focus_change(); | |
} | |
if (p.check_feature("lastfm_album")) { | |
t.artist = ""; | |
t.album = ""; | |
on_item_focus_change(); | |
} | |
window.Repaint(); | |
} | |
} | |
this.post = function(method, metadb) { | |
if (!this.xmlhttp) this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); | |
switch(method) { | |
case "auth.getMobileSession": | |
var func = function() { | |
var json_data = p.json_parse(l.xmlhttp.responsetext); | |
if (!json_data) return; | |
if (json_data.error) { | |
p.MsgBox(json_data.message, 0, p.name); | |
} else if (json_data.session) { | |
p.save(json_data.session.key, l.sk_file); | |
window.NotifyOthers("lastfm", "update"); | |
l.notify_data("lastfm", "update"); | |
} | |
} | |
this.authToken = hex_md5(this.username + hex_md5(this.password)); | |
this.api_sig = hex_md5("api_key" + this.api_key + "authToken" + this.authToken + "method" + method + "username" + this.username + this.secret); | |
this.data = "method=" + method + "&api_key=" + this.api_key + "&api_sig=" + this.api_sig + "&format=json&authToken=" + this.authToken + "&username=" + this.username; | |
break; | |
case "track.love": | |
case "track.unlove": | |
var func = function() { | |
var json_data = p.json_parse(l.xmlhttp.responsetext); | |
if (!json_data) return; | |
if (json_data.error) { | |
p.console(json_data.message); | |
} else if (json_data.status && json_data.status == "ok") { | |
p.console("Track " + (method == "track.love" ? "loved successfully." : "unloved successfully.")); | |
fb.RunContextCommandWithMetadb("Customdb Love " + (method == "track.love" ? 1 : 0), metadb, 8); | |
} | |
} | |
if (!metadb || this.username.length == 0 || this.sk.length != 32) return; | |
this.artist = fb.TitleFormat(p.artist_tf).EvalWithMetadb(metadb); | |
this.track = fb.TitleFormat("%title%").EvalWithMetadb(metadb); | |
if (this.artist == "" || this.artist == "?" || this.track == "?") return; | |
p.console("Attempting to " + (method == "track.love" ? "love \"" : "unlove \"") + this.track + "\" by \"" + this.artist + "\""); | |
p.console("Contacting Last.fm...."); | |
this.api_sig = hex_md5("api_key" + this.api_key + "artist" + this.artist + "method" + method + "sk" + this.sk + "track" + this.track + this.secret); | |
this.data = "method=" + method + "&api_key=" + this.api_key + "&api_sig=" + this.api_sig + "&format=json&sk=" + this.sk + "&artist=" + encodeURIComponent(this.artist) + "&track=" + encodeURIComponent(this.track); | |
break; | |
default: | |
return; | |
} | |
this.xmlhttp.open("POST", "https://ws.audioscrobbler.com/2.0/", true); | |
this.xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); | |
this.xmlhttp.setRequestHeader("User-Agent", this.user_agent); | |
this.xmlhttp.send(this.data); | |
this.xmlhttp.onreadystatechange = function() { | |
if (l.xmlhttp.readyState == 4) { | |
if (l.xmlhttp.status == 200) { | |
func(); | |
} else { | |
p.console(l.xmlhttp.responsetext || "HTTP error: " + l.xmlhttp.status); | |
} | |
} | |
} | |
} | |
this.update_username = function() { | |
var old_username = this.username; | |
this.username = p.InputBox("Enter your Last.fm username.", p.name, this.username); | |
if (this.username.length > 0 && this.username != old_username) p.save("", this.sk_file); | |
p.save(this.username, this.username_file); | |
window.NotifyOthers("lastfm", "update"); | |
this.notify_data("lastfm", "update"); | |
} | |
this.update_password = function() { | |
this.password = p.InputBox("Enter your Last.fm password\n\nThis is only required to love/unlove tracks.", p.name, ""); | |
if (this.password.length > 0) { | |
this.sk = ""; | |
p.save(this.sk, this.sk_file); | |
window.NotifyOthers("lastfm", "update"); | |
this.notify_data("lastfm", "update"); | |
this.post("auth.getMobileSession"); | |
} | |
} | |
this.get_url = function() { | |
return "http://ws.audioscrobbler.com/2.0/?format=json&api_key=" + this.api_key + "&user=" + this.username + "&username=" + this.username + "&s=" + Math.random(); | |
} | |
this.username_error = "Use the right click menu to set your Last.fm username."; | |
this.password_error = "Use the right click menu to set your Last.fm password."; | |
this.url = "http://www.last.fm/"; | |
this.api_key = "56d9e050cc2d6b36102c8b4a5fe6152d"; | |
this.secret = "9f1f4346ce3ba206390074ff8cb4c6ce"; | |
this.user_agent = "foobar2000_wsh_panel_mod_scripts"; | |
this.username_file = p.settings_folder + "username"; | |
this.username = p.open(this.username_file).trim(); | |
this.sk_file = p.settings_folder + "sk"; | |
this.sk = p.open(this.sk_file).trim(); | |
this.auto_correct = window.GetProperty("lastfm_auto_correct", true); | |
} | |
function list(x, y, w, h) { | |
this.size = function() { | |
this.row_height = this.mode == "echonest" ? 90 : 20; | |
this.rows = Math.floor((this.h - (this.mode == "echonest" ? 50 : 30)) / this.row_height); | |
this.index = 0; | |
this.offset = 0; | |
switch(true) { | |
case this.mode == "lastfm_charts": | |
this.text_width = Math.round(this.w / 3); | |
this.lastfm_charts_bar_x = this.text_width + 30; | |
break; | |
case this.mode == "musicbrainz" && this.musicbrainz_mode == "releases": | |
this.text_width = this.w - 120; | |
break; | |
default: | |
this.text_width = this.w - 50; | |
break; | |
} | |
this.but_x = this.x + Math.round((this.w - 15) / 2); | |
this.up_btn = new sb(this.but_x, this.y, 15, 15, p.up_img, "li.offset > 0", function() { li.wheel(1); }); | |
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); }); | |
} | |
this.draw = function(gr) { | |
switch(this.mode) { | |
case "discogs": | |
for (i = 0; i < Math.min(this.items, this.rows); i++) { | |
p.left_text(gr, this.names[i + this.offset], p.list_font, p.textcolour, this.x + this.text_x, this.y + 15 + (i * this.row_height), this.text_width, 20); | |
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); | |
} | |
break; | |
case "lastfm_charts": | |
var max_bar_width = (this.w - this.lastfm_charts_bar_x - 40) / this.playcounts[0]; | |
for (i = 0; i < Math.min(this.items, this.rows); i++) { | |
p.right_text(gr, this.ranks[i + this.offset] + ".", p.list_font, p.textcolour_hl, this.x, this.y + 15 + (i * this.row_height), 17, 20); | |
var bar_width = max_bar_width * this.playcounts[i + this.offset]; | |
var bar_colour = p.splitRGB(this.lastfm_charts_bar_colour); | |
gr.FillSolidRect(this.lastfm_charts_bar_x + this.x, this.y + 16 + (i * this.row_height), bar_width, 18, bar_colour); | |
p.left_text(gr, this.playcounts[i + this.offset].addCommas(), p.list_font, p.textcolour, this.x + 5 + this.lastfm_charts_bar_x + bar_width, this.y + 15 + (i * this.row_height), 50, 20); | |
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); | |
} | |
break; | |
case "lastfm": | |
for (i = 0; i < Math.min(this.items, this.rows); i++) { | |
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"); | |
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"); | |
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); | |
} | |
break; | |
case "musicbrainz": | |
for (i = 0; i < Math.min(this.items, this.rows); i++) { | |
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"); | |
if (this.musicbrainz_mode == "releases") { | |
p.draw_image(gr, this.autoplaylist_img, this.x, this.y + 16 + (i * this.row_height), 16, 16, "adjust"); | |
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); | |
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); | |
} | |
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); | |
} | |
break; | |
case "autoplaylists": | |
for (i = 0; i < Math.min(this.items, this.rows); i++) { | |
p.left_text(gr, this.names[i + this.offset], p.list_font, p.textcolour, this.x, this.y + 15 + (i * this.row_height), this.text_width, 20); | |
if (!this.autoplaylists_editing && this.autoplaylists_hover && this.index == i + this.offset) { | |
p.draw_image(gr, this.autoplaylists_edit_img, this.x + this.w - 40, this.y + 16 + (i * this.row_height), 16, 16, "adjust"); | |
p.draw_image(gr, this.autoplaylists_del_img, this.x + this.w - 20, this.y + 16 + (i * this.row_height), 16, 16, "adjust"); | |
} | |
} | |
break; | |
case "echonest": | |
for (i = 0; i < Math.min(this.items, this.rows); i++) { | |
p.left_text(gr, this.names[i + this.offset], p.title_font, p.textcolour_hl, this.x, this.y + 15 + (i * this.row_height), this.w - 110, 24); | |
p.right_text(gr, this.dates[i + this.offset], p.title_font, p.textcolour_hl, this.x, this.y + 15 + (i * this.row_height), this.w, 24); | |
gr.GdiDrawText(this.summaries[i + this.offset], p.normal_font, p.textcolour, this.x, this.y + 37 + (i * this.row_height), this.w, p.normal_font.Height * Math.floor(64 / p.normal_font.Height), DT_WORDBREAK | DT_CALCRECT | DT_NOPREFIX); | |
} | |
break; | |
} | |
this.up_btn.draw(gr); | |
this.down_btn.draw(gr); | |
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); | |
} | |
this.metadb_changed = function() { | |
p.artist = p.eval(p.artist_tf); | |
if (this.artist == p.artist) return false; | |
this.artist = p.artist; | |
this.folder = p.data_folder + p.artist_tf; | |
if (!p.fso.FolderExists(this.folder)) p.fso.CreateFolder(this.folder); | |
this.update(); | |
return true; | |
} | |
this.trace = function(x, y) { | |
return (x > this.x && x < this.x + this.w && y > this.y && y < this.y + this.h); | |
} | |
this.wheel = function(step) { | |
if (!this.trace(p.mx, p.my)) return false; | |
if (this.items > this.rows) { | |
this.offset -= step * (this.mode == "echonest" ? 1 : 3); | |
if (this.offset < 0) this.offset = 0; | |
if (this.rows + this.offset > this.items) this.offset = this.items - this.rows; | |
window.RepaintRect(this.x, this.y, this.w, this.h); | |
} | |
return true; | |
} | |
this.move = function(x, y) { | |
this.index = Math.floor((y - this.y - 15) / this.row_height) + this.offset; | |
this.in_range = this.index >= this.offset && this.index < this.offset + Math.min(this.rows, this.items); | |
switch(true) { | |
case !this.trace(x, y): | |
case this.mode == "autoplaylists" && this.autoplaylists_editing: | |
case this.mode == "lastfm" && l.username.length == 0: | |
window.SetCursor(IDC_ARROW); | |
this.leave(); | |
return false; | |
case this.up_btn.trace(x, y): | |
case this.down_btn.trace(x, y): | |
window.SetCursor(IDC_HAND); | |
break; | |
case !this.in_range: | |
window.SetCursor(IDC_ARROW); | |
this.leave(); | |
break; | |
case this.mode == "musicbrainz" && this.musicbrainz_mode == "releases" && x > this.x && x < this.x + 20: | |
case this.mode == "lastfm" && this.text_x == 20 && x > this.x && x < this.x + 20: | |
window.SetCursor(IDC_HAND); | |
switch(true) { | |
case this.lastfm_mode == 0 && this.lastfm_button == "spotify": | |
p.tt('spotify:search:"' + this.names[this.index].replace(/\s+/g, "+") + '"'); | |
break; | |
default: | |
p.tt("Autoplaylist: " + this.queries[this.index]); | |
break; | |
} | |
break; | |
case this.mode == "autoplaylists": | |
switch(true) { | |
case x > this.x && x < this.x + Math.min(this.names_widths[this.index], this.text_width): | |
window.SetCursor(IDC_HAND); | |
p.tt('Run "' + this.names[this.index] + '"'); | |
break; | |
case x > this.x + this.w - 40 && x < this.x + this.w - 20: | |
window.SetCursor(IDC_HAND); | |
p.tt('Edit "' + this.names[this.index] + '"'); | |
break; | |
case x > this.x + this.w - 20 && x < this.x + this.w: | |
window.SetCursor(IDC_HAND); | |
p.tt('Delete "' + this.names[this.index] + '"'); | |
break; | |
default: | |
window.SetCursor(IDC_ARROW); | |
this.leave(); | |
break; | |
} | |
this.autoplaylists_hover = true; | |
window.RepaintRect(this.x + this.w - 40, this.y + 15, 40, Math.min(this.rows, this.items) * this.row_height); | |
break; | |
case this.mode == "echonest": | |
case x > this.x + this.text_x && x < this.x + this.text_x + Math.min(this.names_widths[this.index], this.text_width): | |
window.SetCursor(IDC_HAND); | |
p.tt(this.urls[this.index]); | |
break; | |
default: | |
window.SetCursor(IDC_ARROW); | |
p.ttd(); | |
break; | |
} | |
return true; | |
} | |
this.lbtn_up = function(x, y) { | |
switch(true) { | |
case !this.trace(x, y): | |
return false; | |
case this.mode == "autoplaylists" && this.autoplaylists_editing: | |
case this.mode == "lastfm" && l.username.length == 0: | |
case this.up_btn.lbtn_up(x, y): | |
case this.down_btn.lbtn_up(x, y): | |
case !this.in_range: | |
break; | |
case this.mode == "musicbrainz" && this.musicbrainz_mode == "releases" && x > this.x && x < this.x + 20: | |
case this.mode == "lastfm" && this.text_x == 20 && x > this.x && x < this.x + 20: | |
switch(true) { | |
case this.lastfm_mode == 0 && this.lastfm_button == "spotify": | |
if (p.run('spotify:search:"' + this.names[this.index].replace(/\s+/g, "+") + '"')) { | |
if (fb.IsPlaying && !fb.IsPaused && this.lastfm_pause) fb.Pause(); | |
} else { | |
p.MsgBox("Unable to launch Spotify.", 0, p.name); | |
} | |
break; | |
default: | |
fb.CreateAutoPlaylist(fb.PlaylistCount, this.names[this.index], this.queries[this.index]); | |
fb.ActivePlaylist = fb.PlaylistCount - 1; | |
break; | |
} | |
break; | |
case this.mode == "autoplaylists": | |
switch(true) { | |
case x > this.x && x < this.x + Math.min(this.names_widths[this.index], this.text_width): | |
this.autoplaylists_run(this.names[this.index], this.queries[this.index], this.sorts[this.index], this.forced[this.index]); | |
break; | |
case x > this.x + this.w - 40 && x < this.x + this.w - 20: | |
this.autoplaylists_edit(x, y); | |
break; | |
case x > this.x + this.w - 20 && x < this.x + this.w: | |
this.autoplaylists_delete(); | |
break | |
} | |
break; | |
case this.mode == "echonest": | |
case x > this.x + this.text_x && x < this.x + this.text_x + Math.min(this.names_widths[this.index], this.text_width): | |
p.browser(this.urls[this.index]); | |
break; | |
} | |
return true; | |
} | |
this.leave = function() { | |
p.ttd(); | |
if (this.mode != "autoplaylists") return; | |
this.autoplaylists_hover = false; | |
window.RepaintRect(this.x, this.y, this.w, this.h); | |
} | |
this.update = function() { | |
this.items = 0; | |
this.offset = 0; | |
this.index = 0; | |
this.names = []; | |
this.names_widths = []; | |
this.urls = []; | |
this.dates = []; | |
this.queries = []; | |
this.ranks = []; | |
this.playcounts = []; | |
this.sorts = []; | |
this.summaries = []; | |
this.release_types = []; | |
this.images = []; | |
this.forced = []; | |
this.data = []; | |
this.file = null; | |
this.date = ""; | |
var temp_bmp = gdi.CreateImage(1, 1); | |
var temp_gr = temp_bmp.GetGraphics(); | |
switch(this.mode) { | |
case "autoplaylists": | |
this.text = p.open(this.filename); | |
this.data = this.text.split(/\r?\n/g); | |
this.items = this.data.length; | |
for (i = 0; i < this.items; i++) { | |
var temp = this.data[i].split("¬"); | |
this.names[i] = temp[0]; | |
this.queries[i] = temp[1]; | |
this.sorts[i] = temp[2]; | |
this.forced[i] = temp[3]; | |
this.names_widths[i] = temp_gr.CalcTextWidth(this.names[i], p.list_font); | |
} | |
break; | |
case "lastfm": | |
this.text_x = 20; | |
this.filename = this.folder + "\\" + this.lastfm_methods[this.lastfm_mode] + ".json"; | |
if (p.fso.fileExists(this.filename)) { | |
this.file = p.fso.Getfile(this.filename); | |
this.json_text = p.open(this.filename); | |
this.json_data = p.json_parse(this.json_text); | |
if (this.json_data) { | |
switch(true) { | |
case this.json_data.error > 0: | |
p.console(this.json_data.message); | |
break; | |
case this.lastfm_mode == 0 && this.json_data.similarartists && typeof this.json_data.similarartists.artist == "object": | |
this.data = this.json_data.similarartists.artist; | |
break; | |
case this.lastfm_mode == 1 && this.json_data.toptags && typeof this.json_data.toptags.tag == "object": | |
this.data = this.json_data.toptags.tag; | |
break; | |
case this.lastfm_mode == 2 && this.json_data.topfans && typeof this.json_data.topfans.user == "object": | |
this.text_x = 0; | |
this.data = this.json_data.topfans.user; | |
break; | |
case this.lastfm_mode == 3 && this.json_data.topalbums && typeof this.json_data.topalbums.album == "object": | |
this.data = this.json_data.topalbums.album; | |
break; | |
case this.lastfm_mode == 4 && this.json_data.toptracks && typeof this.json_data.toptracks.track == "object": | |
this.data = this.json_data.toptracks.track; | |
break; | |
} | |
this.items = this.data.length; | |
for (i = 0; i < this.items; i++) { | |
this.names[i] = this.data[i].name; | |
this.urls[i] = this.data[i].url; | |
this.names_widths[i] = temp_gr.CalcTextWidth(this.names[i], p.list_font); | |
if (this.lastfm_mode == 0) this.queries[i] = "artist HAS " + this.names[i]; | |
if (this.lastfm_mode == 1) this.queries[i] = "genre HAS " + this.names[i]; | |
if (this.lastfm_mode == 3) this.queries[i] = "album HAS " + this.names[i] + " OR title HAS " + this.names[i]; | |
if (this.lastfm_mode == 4) this.queries[i] = "title HAS " + this.names[i]; | |
} | |
} | |
if (Date.parse(Date()) - Date.parse(this.file.DateLastModified) > ONE_DAY) this.get(); | |
} else { | |
this.get(); | |
} | |
break; | |
case "lastfm_charts": | |
this.filename = this.folder + "\\" + l.username + "_" + this.lastfm_charts_modes[this.lastfm_charts_mode] + "_" + this.lastfm_charts_periods[this.lastfm_charts_period] + ".json"; | |
if (p.fso.fileExists(this.filename)) { | |
this.file = p.fso.Getfile(this.filename); | |
this.json_text = p.open(this.filename); | |
this.json_data = p.json_parse(this.json_text); | |
if (this.json_data) { | |
switch(true) { | |
case this.json_data.error > 0: | |
p.console(this.json_data.message); | |
break; | |
case this.lastfm_charts_mode == 0 && this.json_data.topartists && typeof this.json_data.topartists.artist == "object": | |
this.data = this.json_data.topartists.artist; | |
break; | |
case this.lastfm_charts_mode == 1 && this.json_data.topalbums && typeof this.json_data.topalbums.album == "object": | |
this.data = this.json_data.topalbums.album; | |
break; | |
case this.lastfm_charts_mode == 2 && this.json_data.toptracks && typeof this.json_data.toptracks.track == "object": | |
this.data = this.json_data.toptracks.track; | |
break; | |
} | |
this.items = this.data.length; | |
for (i = 0; i < this.items; i++) { | |
this.names[i] = this.lastfm_charts_mode != 0 ? this.data[i].artist.name + " - " + this.data[i].name : this.data[i].name; | |
this.ranks[i] = (i > 0 && this.data[i].playcount == this.data[i - 1].playcount) ? this.ranks[i - 1] : this.data[i]["@attr"].rank; | |
this.urls[i] = this.data[i].url; | |
this.names_widths[i] = temp_gr.CalcTextWidth(this.names[i], p.list_font); | |
this.playcounts[i] = this.data[i].playcount; | |
} | |
} | |
if (Date.parse(Date()) - Date.parse(this.file.DateLastModified) > ONE_DAY) this.get(); | |
} else { | |
this.get(); | |
} | |
break; | |
case "discogs": | |
this.filename = this.folder + "\\discogs.json"; | |
if (p.fso.fileExists(this.filename)) { | |
this.file = p.fso.Getfile(this.filename); | |
this.json_text = p.open(this.filename); | |
this.json_data = p.json_parse(this.json_text); | |
if (this.json_data && this.json_data.results) { | |
this.data = this.json_reverse_sort(this.json_data.results, "year"); | |
var swap_artist = fb.TitleFormat("$swapprefix($lower(" + p.artist + ")) - ").Eval(true); | |
for (i = 0; i < this.data.length; i++) { | |
var temp_artist = this.data[i].title.replace(/\s{2,}/g,' '); | |
if (this.discogs_match && temp_artist.toLowerCase().indexOf(swap_artist) != 0) continue; | |
this.dates.push(this.data[i].year || ""); | |
this.urls.push("http://www.discogs.com" + this.data[i].uri); | |
this.names.push(temp_artist); | |
this.names_widths.push(temp_gr.CalcTextWidth(temp_artist, p.list_font)); | |
} | |
this.items = this.names.length; | |
} | |
if (Date.parse(Date()) - Date.parse(this.file.DateLastModified) > ONE_DAY) this.get(); | |
} else { | |
this.get(); | |
} | |
break; | |
case "musicbrainz": | |
this.filename = this.folder + "\\musicbrainz_" + this.musicbrainz_mode + ".json"; | |
if (p.fso.fileExists(this.filename)) { | |
this.file = p.fso.Getfile(this.filename); | |
this.json_text = p.open(this.filename); | |
this.json_data = p.json_parse(this.json_text); | |
if (this.json_data) { | |
switch(this.musicbrainz_mode) { | |
case "releases": | |
this.data = this.json_data["release-groups"] || []; | |
this.data = this.json_reverse_sort(this.data, "first-release-date"); | |
var primary, secondary, name; | |
for (i = 0; i < this.data.length; i++) { | |
primary = this.data[i]["primary-type"]; | |
secondary = this.data[i]["secondary-types"].join("").toLowerCase(); | |
switch(true) { | |
case !this.musicbrainz_remix && secondary.indexOf("remix") > -1: | |
case !this.musicbrainz_compilation && secondary.indexOf("compilation") > -1: | |
case !this.musicbrainz_live && secondary.indexOf("live") > -1: | |
break; | |
case this.musicbrainz_single && primary == "Single": | |
case this.musicbrainz_ep && primary == "EP": | |
case this.musicbrainz_album && primary == "Album": | |
name = this.data[i].title; | |
this.dates.push(this.data[i]["first-release-date"].substring(0,4)); | |
this.names.push(name); | |
this.urls.push("http://musicbrainz.org/release-group/" + this.data[i].id); | |
this.names_widths.push(temp_gr.CalcTextWidth(name, p.list_font)); | |
this.queries.push("album HAS " + name + " OR title HAS " + name); | |
switch(true) { | |
case secondary.indexOf("remix") > -1: | |
this.release_types.push("Remix"); | |
break; | |
case secondary.indexOf("compilation") > -1: | |
this.release_types.push("Compilation"); | |
break; | |
case secondary.indexOf("live") > -1: | |
this.release_types.push("Live"); | |
break; | |
default: | |
this.release_types.push(primary); | |
break; | |
} | |
} | |
} | |
this.items = this.names.length; | |
break; | |
case "URLs": | |
this.data = this.json_data.relations || []; | |
this.items = this.data.length; | |
for (i = 0; i < this.items; i++) { | |
this.urls[i] = this.data[i].url.resource; | |
this.images[i] = ""; | |
if (this.data[i].type == "official homepage") { | |
this.images[i] = "home"; | |
} else { | |
for (name in this.musicbrainz_images) { | |
if (this.urls[i].indexOf(name) > -1) { | |
this.images[i] = name; | |
break; | |
} | |
} | |
if (this.images[i].length == 0) this.images[i] = "external"; | |
} | |
this.names[i] = decodeURIComponent(this.urls[i]); | |
this.names_widths[i] = temp_gr.CalcTextWidth(this.names[i], p.list_font); | |
} | |
break; | |
} | |
} | |
if (Date.parse(Date()) - Date.parse(this.file.DateLastModified) > ONE_DAY) this.get(); | |
} else { | |
this.get(); | |
} | |
break; | |
case "echonest": | |
this.filename = this.folder + "\\echonest_" + this.echonest_modes[this.echonest_mode] + ".json"; | |
if (p.fso.fileExists(this.filename)) { | |
this.file = p.fso.Getfile(this.filename); | |
this.json_text = p.open(this.filename); | |
this.json_data = p.json_parse(this.json_text); | |
if (this.json_data && this.json_data.response && this.json_data.response.status && this.json_data.response.status.code == 0) { | |
this.data = this.json_data.response[this.echonest_modes[this.echonest_mode]] || []; | |
this.items = this.data.length; | |
for (i = 0; i < this.items; i++) { | |
this.names[i] = p.strip_tags(this.data[i].name); | |
this.urls[i] = (this.data[i].url || "").replace(/\\/g, ""); | |
this.temp_date = (this.data[i].date_posted || this.data[i].date_reviewed || this.data[i].date_found || "").substring(0, 10); | |
this.dates[i] = this.temp_date.substring(8,10) + "-" + this.temp_date.substring(5,7) + "-" + this.temp_date.substring(0,4); | |
this.summaries[i] = p.strip_tags(this.data[i].summary); | |
} | |
} | |
if (Date.parse(Date()) - Date.parse(this.file.DateLastModified) > ONE_DAY) this.get(); | |
} else { | |
this.get(); | |
} | |
break; | |
} | |
temp_bmp.ReleaseGraphics(temp_gr); | |
temp_bmp.Dispose(); | |
temp_gr = null; | |
temp_bmp = null; | |
if (this.file) { | |
var temp_date = new Date(this.file.DateLastModified); | |
this.date = "Updated: " + temp_date.toLocaleTimeString() + ", " + temp_date.toLocaleDateString(); | |
} | |
window.Repaint(); | |
} | |
this.get = function() { | |
var fn = this.filename; | |
var func = function() { | |
if (!p.save(li.xmlhttp.responsetext, fn)) return; | |
li.update(); | |
} | |
var url = ""; | |
var user_agent = ""; | |
switch(this.mode) { | |
case "discogs": | |
if (this.artist == "" || this.artist == "?") return; | |
url = "http://api.discogs.com/database/search?per_page=100&type=master&artist=" + encodeURIComponent(this.artist); | |
user_agent = "foobar2000_wsh_panel_mod_discogs +http://www.hydrogenaudio.org/forums/index.php?showuser=19379"; | |
break; | |
case "lastfm_charts": | |
if (l.username.length == 0) return(p.console(l.username_error)); | |
url = l.get_url() + "&method=user." + this.lastfm_charts_methods[this.lastfm_charts_mode] + "&period=" + this.lastfm_charts_periods[this.lastfm_charts_period]; | |
user_agent = l.user_agent; | |
break; | |
case "lastfm": | |
if (this.artist == "" || this.artist == "?") return; | |
if (l.username.length == 0) return(p.console(l.username_error)); | |
url = l.get_url() + "&method=" + this.lastfm_methods[this.lastfm_mode] + "&artist=" + encodeURIComponent(this.artist) + "&autocorrect=" + (l.auto_correct ? 1 : 0); | |
user_agent = l.user_agent; | |
break; | |
case "musicbrainz": | |
user_agent = "foobar2000_wsh_panel_mod_musicbrainz +http://www.hydrogenaudio.org/forums/index.php?showuser=19379"; | |
var fn1 = this.folder + "\\MUSICBRAINZ_ARTISTID.txt"; | |
this.musicbrainz_id = p.eval("$if3(%musicbrainz_artistid%,%musicbrainz artist id%,)"); | |
this.musicbrainz_id = this.musicbrainz_id.substring(0, 36); | |
if (this.musicbrainz_id.length == 0) this.musicbrainz_id = p.open(fn1); | |
if (this.musicbrainz_id.length == 0) { | |
if (this.artist == "" || this.artist == "?") return; | |
url = "https://musicbrainz.org/ws/2/artist/?query=artist:" + encodeURIComponent(this.artist.toLowerCase()) + "&fmt=json"; | |
var func = function() { | |
var json_data = p.json_parse(li.xmlhttp.responsetext); | |
if (!json_data) return; | |
var artist = li.artist.toLowerCase(); | |
var artists = json_data.artist || []; | |
for (i = 0; i < artists.length; i++) { | |
if (artist == artists[i].name.toLowerCase()) { | |
if (!p.save(artists[i].id, fn1)) return; | |
li.get(); | |
break; | |
} | |
} | |
} | |
} else { | |
if (this.musicbrainz_mode == "releases") url = "https://musicbrainz.org/ws/2/release-group?artist=" + this.musicbrainz_id + "&limit=100&offset=0&fmt=json"; | |
else url = "https://musicbrainz.org/ws/2/artist/" + this.musicbrainz_id + "?inc=url-rels&fmt=json"; | |
} | |
break; | |
case "echonest": | |
if (this.artist == "" || this.artist == "?") return; | |
url = "http://developer.echonest.com/api/v4/artist/" + this.echonest_modes[this.echonest_mode] + "/?name=" + encodeURIComponent(this.artist) + "&api_key=EKWS4ESQLKN3G2ZWV"; | |
break; | |
} | |
if (url.length == 0) return; | |
this.xmlhttp.open("GET", url, true); | |
if (user_agent.length > 0) this.xmlhttp.setRequestHeader('User-Agent', user_agent); | |
this.xmlhttp.send(); | |
this.xmlhttp.onreadystatechange = function() { | |
if (li.xmlhttp.readyState == 4) { | |
if (li.xmlhttp.status == 200) { | |
func(); | |
} else { | |
p.console(li.xmlhttp.responsetext || "HTTP error: " + li.xmlhttp.status); | |
} | |
} | |
} | |
} | |
this.json_reverse_sort = function(data, prop) { | |
data = data.sort(function(a, b) { | |
if (!a[prop] || b[prop] > a[prop]) return 1; | |
if (!b[prop] || b[prop] < a[prop]) return -1; | |
return 0; | |
}); | |
return data; | |
} | |
this.init = function() { | |
switch(true) { | |
case p.check_feature("discogs"): | |
this.mode = "discogs"; | |
this.discogs_match = window.GetProperty("discogs_match", false); | |
break; | |
case p.check_feature("lastfm_charts"): | |
this.mode = "lastfm_charts"; | |
this.text_x = 20; | |
this.lastfm_charts_modes = ["artist", "album", "track"]; | |
this.lastfm_charts_mode = window.GetProperty("lastfm_charts_mode", 0); | |
this.lastfm_charts_methods = ["getTopArtists", "getTopAlbums", "getTopTracks"]; | |
this.lastfm_charts_periods_display = ["overall", "last 7 days", "1 month", "3 month", "6 month", "12 month"]; | |
this.lastfm_charts_periods = ["overall", "7day", "1month", "3month", "6month", "12month"]; | |
this.lastfm_charts_period = window.GetProperty("lastfm_charts_period", 0); | |
this.lastfm_charts_bar_colour = window.GetProperty("lastfm_charts_bar_colour", "72-127-221"); | |
this.folder = p.data_folder + "charts"; | |
if (!p.fso.FolderExists(this.folder)) p.fso.CreateFolder(this.folder); | |
break; | |
case p.check_feature("lastfm"): | |
this.mode = "lastfm"; | |
this.lastfm_methods = ["artist.getSimilar", "artist.getTopTags", "artist.getTopFans", "artist.getTopAlbums", "artist.getTopTracks"]; | |
this.lastfm_modes = ["similar artists", "top tags", "top fans", "top albums", "top tracks"]; | |
this.lastfm_mode = window.GetProperty("lastfm_mode", 0); | |
this.lastfm_button = window.GetProperty("lastfm_button", "spotify"); | |
this.lastfm_pause = window.GetProperty("lastfm_pause", true); | |
this.lastfm_spotify_img = gdi.Image(p.images_path + "spotify.png"); | |
break; | |
case p.check_feature("musicbrainz"): | |
this.mode = "musicbrainz"; | |
this.text_x = 20; | |
this.musicbrainz_images = { | |
"viaf.org": gdi.Image(p.images_path + "viaf_small.png"), | |
"allmusic.com": gdi.Image(p.images_path + "allmusic_small.png"), | |
"external": gdi.Image(p.images_path + "external_small.png"), | |
"bbc.co.uk": gdi.Image(p.images_path + "bbc_small.png"), | |
"facebook.com": gdi.Image(p.images_path + "facebook_small.png"), | |
"home": gdi.Image(p.images_path + "home_small.png"), | |
"last.fm": gdi.Image(p.images_path + "lastfm_small.png"), | |
"twitter.com": gdi.Image(p.images_path + "twitter_small.png"), | |
"soundcloud.com": gdi.Image(p.images_path + "soundcloud_small.png"), | |
"wikipedia.org": gdi.Image(p.images_path + "wikipedia_small.png"), | |
"discogs.com": gdi.Image(p.images_path + "discogs_small.png"), | |
"myspace.com": gdi.Image(p.images_path + "myspace_small.png"), | |
"youtube.com": gdi.Image(p.images_path + "youtube_small.png"), | |
"imdb.com": gdi.Image(p.images_path + "imdb_small.png"), | |
"plus.google.com": gdi.Image(p.images_path + "google_plus_small.png"), | |
"lyrics.wikia.com": gdi.Image(p.images_path + "lyrics_wikia_small.png"), | |
"flickr.com": gdi.Image(p.images_path + "flickr_small.png"), | |
"secondhandsongs.com": gdi.Image(p.images_path + "secondhandsongs_small.png"), | |
"vimeo.com": gdi.Image(p.images_path + "vimeo_small.png"), | |
"rateyourmusic.com": gdi.Image(p.images_path + "rateyourmusic_small.png"), | |
"instagram.com": gdi.Image(p.images_path + "instagram_small.png"), | |
"tumblr.com": gdi.Image(p.images_path + "tumblr_small.png"), | |
"decoda.com": gdi.Image(p.images_path + "decoda_small.png"), | |
"wikidata.org": gdi.Image(p.images_path + "wikidata_small.png") | |
} | |
this.musicbrainz_mode = window.GetProperty("musicbrainz_mode", "releases"); | |
this.musicbrainz_show_release_type = window.GetProperty("musicbrainz_show_release_type", true); | |
this.musicbrainz_live = window.GetProperty("musicbrainz_live", false); | |
this.musicbrainz_ep = window.GetProperty("musicbrainz_ep", true); | |
this.musicbrainz_single = window.GetProperty("musicbrainz_single", true); | |
this.musicbrainz_album = window.GetProperty("musicbrainz_album", true); | |
this.musicbrainz_remix = window.GetProperty("musicbrainz_remix", true); | |
this.musicbrainz_compilation = window.GetProperty("musicbrainz_compilation", true); | |
break; | |
case p.check_feature("echonest"): | |
this.mode = "echonest"; | |
this.echonest_modes = ["news", "reviews", "blogs"]; | |
this.echonest_mode = window.GetProperty("echonest_mode", 0); | |
break; | |
case p.check_feature("autoplaylists"): | |
this.autoplaylists_add = function() { | |
if (this.autoplaylists_editing) return; | |
this.autoplaylists_editing = true; | |
var new_name = p.InputBox("Enter a name for your autoplaylist", p.name, ""); | |
if (new_name == "") { this.autoplaylists_editing = false; return; } | |
var new_query = p.InputBox("Enter your autoplaylist query", p.name, ""); | |
if (new_query == "") { this.autoplaylists_editing = false; return; } | |
var new_sort = p.InputBox("Enter a sort pattern\n\n(optional)", p.name, ""); | |
var new_force = new_sort.length > 0 ? p.MsgBox("Force sort?", 4, p.name) : 7; | |
this.data.push(new_name + "¬" + new_query + "¬" + new_sort + "¬" + new_force); | |
if (this.data.length > this.rows) this.offset = this.data.length - this.rows; | |
p.save(this.data.join("\n"), this.filename); | |
if (this.autoplaylists_success) this.autoplaylists_run(new_name, new_query, new_sort, new_force); | |
window.NotifyOthers("autoplaylists", "update"); | |
this.update(); | |
this.autoplaylists_editing = false; | |
} | |
this.autoplaylists_run = function(n, q, s, f) { | |
if (this.autoplaylists_remove_duplicates) { | |
i = 0; | |
while(i < fb.PlaylistCount) { | |
if (fb.GetPlaylistName(i) == n) fb.RemovePlaylist(i); | |
else i++; | |
} | |
} | |
fb.CreateAutoPlaylist(fb.PlaylistCount, n, q, s, f == 6 ? true : false); | |
fb.ActivePlaylist = fb.PlaylistCount - 1; | |
} | |
this.autoplaylists_edit = function(x, y) { | |
var _menu = window.CreatePopupMenu(); | |
var i = this.index; | |
_menu.AppendMenuItem(MF_STRING, 1, "Rename..."); | |
_menu.AppendMenuItem(MF_STRING, 2, "Edit query..."); | |
_menu.AppendMenuItem(MF_STRING, 3, "Edit sort pattern..."); | |
_menu.AppendMenuItem(MF_STRING, 4, "Force Sort"); | |
_menu.CheckMenuItem(4, this.forced[i] == 6 ? true : false); | |
this.autoplaylists_editing = true; | |
this.autoplaylists_hover = false; | |
window.RepaintRect(this.x + this.w - 40, this.y + 15, 40, Math.min(this.rows, this.items) * this.row_height); | |
idx = _menu.TrackPopupMenu(x, y); | |
switch(idx) { | |
case 0: | |
this.autoplaylists_editing = false; | |
_menu.Dispose(); | |
return; | |
case 1: | |
var new_name = p.InputBox("Rename your autoplaylist", p.name, this.names[i]); | |
if (new_name != "") this.names[i] = new_name; | |
break; | |
case 2: | |
var new_query = p.InputBox("Enter your autoplaylist query", p.name, this.queries[i]); | |
if (new_query != "") this.queries[i] = new_query; | |
break; | |
case 3: | |
var new_sort = p.InputBox("Enter a sort pattern\n\n(optional)", p.name, this.sorts[i]); | |
this.sorts[i] = new_sort; | |
this.forced[i] = new_sort.length > 0 ? p.MsgBox("Force sort?", 4, p.name) : 7; | |
break; | |
case 4: | |
this.forced[i] = this.forced[i] == 6 ? 7 : 6; | |
break; | |
} | |
_menu.Dispose(); | |
var temp = this.names[i] + "¬" + this.queries[i] + "¬" + this.sorts[i] + "¬" + this.forced[i]; | |
if (this.data[i] != temp) { | |
this.data[i] = temp; | |
p.save(this.data.join("\n"), this.filename); | |
if (this.autoplaylists_success) this.autoplaylists_run(this.names[i], this.queries[i], this.sorts[i], this.forced[i]); | |
window.NotifyOthers("autoplaylists", "update"); | |
this.update(); | |
} | |
this.autoplaylists_editing = false; | |
} | |
this.autoplaylists_delete = function() { | |
if (this.offset > 1) this.offset--; | |
this.autoplaylists_deleted_items.unshift(this.data[this.index]); | |
this.data.splice(this.index, 1); | |
p.save(this.data.join("\n"), this.filename); | |
window.NotifyOthers("autoplaylists", "update"); | |
this.update(); | |
} | |
this.mode = "autoplaylists"; | |
this.autoplaylists_del_img = gdi.Image(p.images_path + "cross.png"); | |
this.autoplaylists_edit_img = gdi.Image(p.images_path + "edit.png"); | |
this.autoplaylists_hover = false; | |
this.autoplaylists_editing = false; | |
this.autoplaylists_remove_duplicates = window.GetProperty("autoplaylists_remove_duplicates", true); | |
this.autoplaylists_success = window.GetProperty("autoplaylists_success", true); | |
this.autoplaylists_title = window.GetProperty("autoplaylists_title", "Autoplaylists"); | |
this.autoplaylists_slot = window.GetProperty("autoplaylists_slot", 1); | |
this.filename = p.settings_folder + "autoplaylists" + this.autoplaylists_slot; | |
this.autoplaylists_deleted_items = []; | |
break; | |
} | |
} | |
this.x = x; | |
this.y = y; | |
this.w = w; | |
this.h = h; | |
this.index = 0; | |
this.offset = 0; | |
this.items = 0; | |
this.text = ""; | |
this.artist = ""; | |
this.url = ""; | |
this.text_x = 0; | |
this.show_timestamp = window.GetProperty("show_timestamp", true); | |
this.autoplaylist_img = gdi.Image(p.images_path + "search_small.png"); | |
this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); | |
this.init(); | |
} | |
function playcount_sync(x, y) { | |
this.playback_time = function() { | |
this.time_elapsed++; | |
if (this.time_elapsed == 3 && this.auto_love && fb.TitleFormat(this.auto_love_tf).Eval() == 1 && this.old_userloved == 0) { | |
p.console("Automatically loving this track...."); | |
this.love_track(); | |
} | |
if (this.time_elapsed == this.target_time) { | |
if (!this.library || fb.IsMetadbInMediaLibrary(p.metadb)) this.sync_track(); | |
else p.console("Skipping... Track not in library."); | |
} | |
} | |
this.metadb_changed = function() { | |
if (!p.metadb) return false; | |
this.artist = fb.TitleFormat(p.artist_tf).EvalWithMetadb(p.metadb); | |
this.track = fb.TitleFormat("%title%").EvalWithMetadb(p.metadb); | |
this.old_userloved = fb.TitleFormat("%LASTFM_LOVED_DB%").EvalWithMetadb(p.metadb) == 1 ? 1 : 0; | |
this.old_userplaycount = fb.TitleFormat("%LASTFM_PLAYCOUNT_DB%").EvalWithMetadb(p.metadb); | |
this.method = this.old_userloved == 1 ? "track.unlove" : "track.love"; | |
this.tooltip = (this.old_userloved == 1 ? "Unlove" : "Love") + " \"" + this.track + "\" by \"" + this.artist + "\"."; | |
this.crc32 = fb.TitleFormat("$crc32($lower(%artist%%title%))").EvalWithMetadb(p.metadb); | |
b.update(); | |
return true; | |
} | |
this.playback_new_track = function() { | |
this.auto_love_count = 0; | |
this.time_elapsed = 0; | |
switch(true) { | |
case fb.PlaybackLength == 0: | |
this.target_time = 240; | |
break; | |
case fb.PlaybackLength >= 30: | |
this.target_time = Math.min(Math.floor(fb.PlaybackLength / 2), 240); | |
break; | |
default: | |
this.target_time = 5; | |
break; | |
} | |
on_item_focus_change(); | |
} | |
this.playback_edited = function() { | |
if (this.auto_love && fb.TitleFormat(this.auto_love_tf).Eval() == 1 && this.old_userloved == 0 && this.auto_love_count == 0) { | |
this.auto_love_count = 1; | |
p.console("Automatically loving this track...."); | |
this.love_track(); | |
} | |
} | |
this.tf = function(value) { | |
return(value.replace(/'/g, "''").replace(/,/g, "','").replace(/\//g, "'/'").replace(/\(/g, "'('").replace(/\)/g, "')'").replace(/\[/g, "'['").replace(/\]/g, "']'")); | |
} | |
this.love_track = function() { | |
l.post(this.method, p.metadb); | |
} | |
this.sync_track = function() { | |
switch(true) { | |
case this.loved_working || this.playcount_working: | |
return; | |
case !utils.CheckComponent("foo_customdb", true): | |
p.console("Not contacting Last.fm. foo_customdb is missing."); | |
return; | |
default: | |
p.console("Contacting Last.fm...."); | |
this.get(l.get_url() + "&method=track.getinfo&artist=" + encodeURIComponent(this.artist) + "&track=" + encodeURIComponent(this.track) + "&autocorrect=" + (l.auto_correct ? 1 : 0), function() { | |
ps.update_track(); | |
}); | |
} | |
} | |
this.get = function(url, func) { | |
if (l.username.length == 0) { | |
this.loved_working = false; | |
this.playcount_working = false; | |
p.console(l.username_error); | |
return; | |
} | |
this.xmlhttp.open("GET", url, true); | |
this.xmlhttp.setRequestHeader('User-Agent', l.user_agent); | |
this.xmlhttp.send(); | |
this.xmlhttp.onreadystatechange = function() { | |
if (ps.xmlhttp.readyState == 4) { | |
if (ps.xmlhttp.status == 200) { | |
func(); | |
} else { | |
p.console(ps.xmlhttp.responsetext || "HTTP error: " + ps.xmlhttp.status); | |
} | |
} | |
} | |
} | |
this.update_track = function() { | |
this.json_data = p.json_parse(ps.xmlhttp.responsetext); | |
if (!this.json_data || this.json_data.error > 0 || !this.json_data.track) { | |
p.console(ps.xmlhttp.responsetext); | |
return; | |
} | |
this.userplaycount = this.json_data.track.userplaycount > 0 ? ++this.json_data.track.userplaycount : 1; | |
this.userloved = this.json_data.track.userloved == 1 ? 1 : 0; | |
if (fb.IsPlaying && this.time_elapsed >= this.target_time && fb.PlaybackLength > 29 && fb.PlaybackLength < 10800) { | |
switch(true) { | |
case this.userplaycount < this.old_userplaycount: | |
p.console("Playcount returned from Last.fm is lower than current value. Not updating."); | |
break; | |
case this.old_userplaycount == this.userplaycount: | |
p.console("No changes found. Not updating."); | |
break; | |
default: | |
p.console("Last.fm responded ok. Attempting to update playcount..."); | |
fb.RunContextCommandWithMetadb("Customdb Delete Playcount", p.metadb, 8); | |
if (this.old_userloved == 1) fb.RunContextCommandWithMetadb("Customdb Love 0", p.metadb, 8); | |
var attempt = 0; | |
while(fb.TitleFormat("%LASTFM_PLAYCOUNT_DB%").EvalWithMetadb(p.metadb) != this.userplaycount && attempt <= 3) { | |
var query1 = '\"INSERT INTO quicktag(url,subsong,fieldname,value) VALUES(\\"' + this.crc32 + '\\",\\"-1\\",\\"LASTFM_PLAYCOUNT_DB\\",\\"' + this.userplaycount + '\\")\";'; | |
p.WshShell.Run(p.fso.GetFile(p.script_path + "sqlite3.exe").ShortPath + " " + p.fso.GetFile(fb.ProfilePath + "customdb_sqlite.db").ShortPath + " " + query1, 0, true); | |
attempt++; | |
} | |
fb.RunContextCommandWithMetadb("Customdb Refresh", p.metadb, 8); | |
if (fb.TitleFormat("%LASTFM_PLAYCOUNT_DB%").EvalWithMetadb(p.metadb) == this.userplaycount) p.console("Playcount updated successfully."); | |
else p.console("Database error. Playcount not updated."); | |
break; | |
} | |
} | |
if (this.old_userloved != this.userloved) fb.RunContextCommandWithMetadb("Customdb Love " + this.userloved, p.metadb, 8); | |
} | |
this.start_import = function() { | |
if (this.show_console) fb.ShowConsole(); | |
this.loved_page_errors = 0; | |
this.playcount_page_errors = 0; | |
ps.pages = 0; | |
this.r = 1; | |
this.sql = "BEGIN TRANSACTION;\n"; | |
this.loved_working = true; | |
this.sync_loved(1); | |
} | |
this.sync_loved = function(page) { | |
if (!this.loved_working) return(p.console("Import aborted.")); | |
this.page = page; | |
this.get(l.get_url() + "&method=user.getlovedtracks&limit=200&page=" + this.page, function() { | |
ps.update_loved(); | |
}); | |
} | |
this.update_loved = function() { | |
this.json_data = p.json_parse(ps.xmlhttp.responsetext); | |
if (this.json_data && this.json_data.error > 0) { | |
this.loved_working = false; | |
p.MsgBox("There is a problem with the Last.fm web services. Please try again later.\n\n" + ps.xmlhttp.responsetext, 0, p.name); | |
return; | |
} | |
if (this.json_data && this.json_data.lovedtracks && this.json_data.lovedtracks.track) { | |
if (this.page == 1) this.pages = this.json_data.lovedtracks["@attr"].totalPages; | |
for (i = 0; i < this.json_data.lovedtracks.track.length; i++) { | |
var data = []; | |
data[0] = this.json_data.lovedtracks.track[i].artist.name; | |
data[1] = this.json_data.lovedtracks.track[i].name; | |
data[2] = 1; | |
if (data.length == 3) { | |
p.console(this.r + ": " + data[0] + " - " + data[1]); | |
var url = fb.TitleFormat("$crc32($lower(" + this.tf(data[0]) + this.tf(data[1]) + "))").Eval(true); | |
this.sql += 'INSERT OR REPLACE INTO quicktag(url,subsong,fieldname,value) VALUES("' + url + '","-1","LASTFM_LOVED_DB","' + data[2] + '");' + "\n"; | |
this.r++; | |
} | |
} | |
p.console("Loved tracks: completed page " + this.page + " of " + this.pages); | |
} else if (this.pages > 0) { | |
this.loved_page_errors++; | |
} | |
if (this.page < this.pages) { | |
this.page++; | |
this.sync_loved(this.page); | |
} else { | |
this.loved_working = false; | |
if (this.full_import) { | |
this.playcount_working = true; | |
this.pages = 0; | |
this.r = 1; | |
this.sync_playcount(1); | |
} else { | |
try { | |
this.sql += "COMMIT;" | |
var ts = p.fso.OpenTextFile(this.sql_file, 2, true, 0); | |
ts.WriteLine(this.sql); | |
ts.Close(); | |
this.finish_import(); | |
} catch(e) { | |
} | |
if (this.loved_page_errors > 0) { | |
p.console("Loved track page errors: " + this.loved_page_errors + " (200 records are lost for every page that fails.)"); | |
} else { | |
p.console("There were no errors reported."); | |
} | |
} | |
} | |
} | |
this.sync_playcount = function(page) { | |
if (this.playcount_working == false) return(p.console("Import aborted.")); | |
this.page = page; | |
this.get(l.get_url() + "&method=library.gettracks&limit=100&page=" + this.page, function() { | |
ps.update_playcount(); | |
}); | |
} | |
this.update_playcount = function() { | |
this.json_data = p.json_parse(ps.xmlhttp.responsetext); | |
if (this.json_data && this.json_data.error > 0) { | |
this.playcount_working = false; | |
p.MsgBox("There is a problem with the Last.fm web services. Please try again later.\n\n" + ps.xmlhttp.responsetext, 0, p.name); | |
return; | |
} | |
if (this.json_data && this.json_data.tracks && this.json_data.tracks.track) { | |
if (this.page == 1) this.pages = this.json_data.tracks["@attr"].totalPages | |
for (i = 0; i < this.json_data.tracks.track.length; i++) { | |
var data = []; | |
data[0] = this.json_data.tracks.track[i].artist.name; | |
data[1] = this.json_data.tracks.track[i].name; | |
data[2] = this.json_data.tracks.track[i].playcount; | |
if (data[2] == 0) { | |
this.page = this.pages; | |
break; | |
} | |
if (data.length == 3) { | |
p.console(this.r + ": " + data[0] + " - " + data[1] + " " + data[2]); | |
var url = fb.TitleFormat("$crc32($lower(" + this.tf(data[0]) + this.tf(data[1]) + "))").Eval(true); | |
this.sql += 'INSERT OR REPLACE INTO quicktag(url,subsong,fieldname,value) VALUES("' + url + '","-1","LASTFM_PLAYCOUNT_DB","' + data[2] + '");' + "\n"; | |
this.r++; | |
} | |
} | |
p.console("Playcount: completed page " + this.page + " of " + this.pages); | |
} else if (this.pages > 0) { | |
this.playcount_page_errors++; | |
} | |
if (this.page < this.pages) { | |
this.page++; | |
this.sync_playcount(this.page); | |
} else { | |
try { | |
this.sql += "COMMIT;" | |
var ts = p.fso.OpenTextFile(this.sql_file, 2, true, 0); | |
ts.WriteLine(this.sql); | |
ts.Close(); | |
this.finish_import(); | |
} catch(e) { | |
} | |
this.playcount_working = false; | |
if (this.loved_page_errors + this.playcount_page_errors > 0) { | |
p.console("Loved track page errors: " + this.loved_page_errors + " (200 records are lost for every page that fails.)"); | |
p.console("Playcount page errors: " + this.playcount_page_errors + " (100 records are lost for every page that fails.)"); | |
} else { | |
p.console("There were no errors reported."); | |
} | |
} | |
} | |
this.finish_import = function() { | |
try { | |
var cmd_file = p.fso.GetFile(p.script_path + "lastfm_sql.cmd").ShortPath; | |
var db_file = p.fso.GetFile(fb.ProfilePath + "customdb_sqlite.db").ShortPath; | |
p.run(cmd_file + " " + p.fso.GetFile(p.script_path + "sqlite3.exe").ShortPath + " " + db_file + " " + p.fso.GetFile(this.sql_file).ShortPath); | |
} catch(e) { | |
} | |
} | |
this.update_button = function() { | |
var exclamation = this.icon == "tango" ? "exclamation.png" : "exclamation_small.png"; | |
var love = this.icon == "tango" ? "love.png" : "love_small.png"; | |
var love_h = this.icon == "tango" ? "love_h.png" : "love_h_small.png"; | |
this.size = this.icon == "tango" ? 32 : 20; | |
switch(true) { | |
case l.username.length == 0: | |
this.n = exclamation; | |
this.h = exclamation; | |
this.tooltip = l.username_error; | |
this.func = null; | |
break; | |
case l.sk.length != 32: | |
this.n = exclamation; | |
this.h = exclamation; | |
this.tooltip = l.password_error; | |
this.func = null; | |
break; | |
case !p.metadb: | |
this.n = exclamation; | |
this.h = exclamation; | |
this.tooltip = "No selection"; | |
this.func = null; | |
break; | |
case !utils.CheckComponent("foo_customdb", true): | |
this.n = exclamation; | |
this.h = exclamation; | |
this.tooltip = "The foo_customdb component is not installed. Please refer to the readme."; | |
this.func = null; | |
break; | |
default: | |
this.n = this.old_userloved == 1 ? love_h : love; | |
this.h = this.old_userloved == 1 ? love : love_h; | |
this.func = function() { ps.love_track(); } | |
break; | |
} | |
} | |
this.x = x; | |
this.y = y; | |
this.loved_working = false; | |
this.playcount_working = false; | |
this.sql_file = p.data_folder + "lastfm.sql"; | |
this.page = 0; | |
this.last_page = 0; | |
this.auto_love = window.GetProperty("playcount_sync_auto_love", false); | |
this.auto_love_tf = window.GetProperty("playcount_sync_auto_love_tf", ""); | |
this.icon = window.GetProperty("playcount_sync_icon", "tango"); | |
this.show_console = window.GetProperty("playcount_sync_show_console", true); | |
this.library = window.GetProperty("playcount_sync_library", false); | |
this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); | |
window.SetInterval(function() { | |
var temp = ps.page > 1 ? ps.page - 1 : 1; | |
if (ps.loved_working && ps.page == ps.last_page) { | |
ps.xmlhttp.abort(); | |
ps.sync_loved(temp); | |
} else if (ps.playcount_working && ps.page == ps.last_page) { | |
ps.xmlhttp.abort(); | |
ps.sync_playcount(temp); | |
} else { | |
ps.last_page = ps.page; | |
} | |
}, 15000); | |
} | |
function rating(x, y, bs) { | |
this.draw = function(gr) { | |
if (!p.metadb) return; | |
for (i = 1; i < 6; i++) { | |
this.img = i > (this.hover ? this.lrating : this.rating) ? this.off_img : this.on_img; | |
p.draw_image(gr, this.img, this.x + this.bs * (i - 1), this.y, this.bs, this.bs, "adjust"); | |
} | |
} | |
this.metadb_changed = function() { | |
if (!p.metadb) return false; | |
this.hover = false; | |
this.rating = p.eval("$if2(%rating%,0)"); | |
this.tiptext = p.eval(this.tiptext_tf); | |
this.lrating = this.rating; | |
window.RepaintRect(this.x, this.y, this.w, this.bs); | |
return true; | |
} | |
this.trace = function(x, y) { | |
return x > this.x - this.bs && x < this.x + (this.bs * 5) && y > this.y && y < this.y + this.bs; | |
} | |
this.move = function(x, y) { | |
if (!this.trace(x, y)) { | |
if (this.hover) this.leave(); | |
return false; | |
} | |
if (p.metadb) { | |
if (x > this.x) p.tt(this.tiptext); | |
this.hover = true; | |
this.lrating = Math.ceil((x - this.x) / this.bs); | |
window.RepaintRect(this.x, this.y, this.w, this.bs); | |
} | |
return true; | |
} | |
this.lbtn_up = function(x, y) { | |
if (!this.trace(x, y)) return false; | |
if (this.check) { | |
if (this.lrating != this.rating && this.hover == 1) fb.RunContextCommandWithMetadb("Rating/" + (this.lrating == 0 ? "<not set>" : this.lrating), p.metadb, 8); | |
} else { | |
p.MsgBox(this.error_text, 0, p.name); | |
p.browser("http://www.foobar2000.org/components/view/foo_playcount"); | |
} | |
return true; | |
} | |
this.leave = function() { | |
p.ttd(); | |
this.hover = false; | |
window.RepaintRect(this.x, this.y, this.w, this.bs); | |
} | |
this.x = x; | |
this.y = y; | |
this.bs = bs; | |
this.w = this.bs * 5; | |
this.hover = false; | |
this.rating = null; | |
this.lrating = null; | |
this.img = null; | |
this.off_img = gdi.Image(p.images_path + "off.png"); | |
this.on_img = gdi.Image(p.images_path + "on.png"); | |
this.check = utils.CheckComponent("foo_playcount", true); | |
this.error_text = "This script requires foo_playcount."; | |
this.tiptext_tf = this.check ? 'Rate "%title%" by "%artist%"' : this.error_text; | |
} | |
function sb(x, y, w, h, img, isVisible, func) { | |
this.x = x; | |
this.y = y; | |
this.w = w; | |
this.h = h; | |
this.img = img; | |
this.isVisible = new Function("return (" + isVisible + ");"); | |
this.func = func; | |
this.draw = function(gr) { | |
if (this.isVisible()) p.draw_image(gr, this.img, this.x, this.y, this.w, this.h, "adjust"); | |
} | |
this.trace = function(x, y) { | |
return(x > this.x && x < this.x + this.w && y > this.y && y < this.y + this.h && this.isVisible()); | |
} | |
this.lbtn_up = function(x, y) { | |
if (!this.trace(x, y)) return false; | |
this.func && this.func(x, y); | |
return true; | |
} | |
} | |
function seekbar(x, y, w, h) { | |
this.trace = function(x, y) { | |
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)); | |
} | |
this.draw = function(gr) { | |
p.draw_background(gr); | |
switch(this.mode) { | |
case "spectrogram": | |
if (this.working) { | |
p.draw_image(gr, this.hourglass_img, this.x, this.y + Math.round((this.h - 32) / 2), this.w, 32, "adjust"); | |
} else { | |
p.draw_image(gr, this.img, this.x, this.y, this.w, this.h, "stretch"); | |
} | |
if (fb.IsPlaying && fb.PlaybackLength > 0) { | |
this.calc_pos(); | |
gr.FillSolidRect(this.x + this.pos - 2, this.y, 2, this.h, p.splitRGB(this.marker)); | |
} | |
break; | |
case "nyan_cat": | |
if (fb.IsPlaying && fb.PlaybackLength > 0) { | |
this.calc_pos(); | |
for (i = 0; i < this.offsets.length; i++) { | |
gr.FillSolidRect(this.x - 48, this.y + this.offsets[i], this.pos + 2, this.heights[i], this.colours[i]); | |
} | |
p.draw_image(gr, this.cat_img[this.z], this.pos, this.y, 48, 30); | |
} else { | |
p.draw_image(gr, this.cat_img[0], 0, this.y, 48, 30); | |
} | |
break; | |
} | |
} | |
this.playback_new_track = function() { | |
if (this.mode != "spectrogram") return; | |
var metadb = fb.GetNowPlaying(); | |
this.img && this.img.Dispose(); | |
this.img = null; | |
try { | |
this.png_filename = spectrogram_cache + "\\" + fb.TitleFormat("$crc32(%path%)").EvalWithMetadb(metadb) + this.sox_params + ".png"; | |
switch(true) { | |
case !metadb: | |
case metadb.RawPath.indexOf("file") != 0: | |
p.console("Skipping... Not a valid file type."); | |
break; | |
case fb.PlaybackLength == 0: | |
p.console("Skipping... Unknown length."); | |
break; | |
case fb.TitleFormat("$if($or($strcmp(%__cue_embedded%,yes),$strcmp($right(%path%,3),cue)),cue,)").EvalWithMetadb(metadb) == "cue": | |
p.console("Skipping... Cannot support cuesheets."); | |
break; | |
case fb.TitleFormat("%subsong%").EvalWithMetadb(metadb) > 0: | |
p.console("Skipping... Cannot support tracks with chapters."); | |
break; | |
case this.library && !fb.IsMetadbInMediaLibrary(metadb): | |
p.console("Skipping... Track not in library."); | |
break; | |
case p.fso.FileExists(this.png_filename): | |
this.img = gdi.Image(this.png_filename); | |
break; | |
default: | |
this.working = true | |
window.Repaint(); | |
var filename = metadb.Path; | |
var length = fb.TitleFormat("%length%").EvalWithMetadb(metadb); | |
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 + "\"\""; | |
//p.console(cmd); | |
try { p.WshShell.Run(cmd, 0, true); } catch(e) {} | |
this.working = false; | |
this.img = gdi.Image(this.png_filename); | |
break; | |
} | |
} catch(e) { | |
//p.console(e); | |
} | |
window.Repaint(); | |
} | |
this.playback_stop = function() { | |
window.Repaint(); | |
} | |
this.playback_seek = function() { | |
this.update(); | |
} | |
this.move = function(x, y) { | |
if (this.drag) this.update(); | |
if (this.trace(x, y)) { | |
if (fb.IsPlaying && fb.PlaybackLength > 0) { | |
x -= this.x; | |
this.drag_seek = x < 0 ? 0 : x > this.w ? 1 : x / this.w; | |
if (x != this.old_x || y != this.old_y) { | |
p.tt(p.format_time(fb.PlaybackLength * this.drag_seek)); | |
this.old_x = x; | |
this.old_y = y; | |
} | |
} | |
return true; | |
} else { | |
this.leave(); | |
return false; | |
} | |
} | |
this.lbtn_down = function(x, y) { | |
if (!this.trace(x, y)) return false; | |
if (fb.IsPlaying && fb.PlaybackLength > 0) this.drag = true; | |
return true; | |
} | |
this.lbtn_up = function(x, y) { | |
if (!this.trace(x, y)) return false; | |
if (this.drag) { | |
this.drag = false; | |
fb.PlaybackTime = fb.PlaybackLength * this.drag_seek; | |
} | |
return true; | |
} | |
this.leave = function() { | |
this.drag = false; | |
p.ttd(); | |
} | |
this.update = function() { | |
window.RepaintRect(0, this.y, p.w, this.h); | |
} | |
this.calc_pos = function() { | |
this.pos = this.drag ? this.w * this.drag_seek : this.w * (fb.PlaybackTime / fb.PlaybackLength); | |
} | |
this.init = function() { | |
switch(true) { | |
case p.check_feature("spectrogram"): | |
this.clear_images = function(period) { | |
var now = Date.parse(Date()); | |
images = utils.Glob(spectrogram_cache + "\\*.*").toArray(); | |
for (i = 0; i < images.length; i++) { | |
if (this.png_filename == images[i]) continue; | |
var file = p.fso.Getfile(images[i]); | |
var file_date = Date.parse(file.DateLastModified); | |
if (now - file_date > period) { | |
try { | |
p.fso.DeleteFile(images[i]); | |
} catch(e) { | |
p.console("Could not delete " + images[i]); | |
} | |
} | |
} | |
} | |
this.mode = "spectrogram"; | |
this.library = window.GetProperty("seekbar_library", false); | |
this.marker = window.GetProperty("seekbar_marker", "240-240-240"); | |
this.sox_params = window.GetProperty("sox_params", "channels 1 spectrogram -Y 130").trim(); | |
this.working = false; | |
this.img = false; | |
this.hourglass_img = gdi.Image(p.images_path + "hourglass.png"); | |
if (!p.fso.FolderExists(spectrogram_cache)) p.fso.CreateFolder(spectrogram_cache); | |
if (fb.IsPlaying) { | |
window.SetTimeout(function() { | |
s.playback_new_track(); | |
}, 100); | |
} | |
break; | |
case p.check_feature("nyan_cat"): | |
this.mode = "nyan_cat"; | |
this.cat_img = [gdi.Image(p.images_path + "\\seekbar cat.png"), gdi.Image(p.images_path + "\\seekbar cat 2.png")]; | |
this.offsets = [2, 6, 10, 15, 20, 24]; | |
this.heights = [4, 4, 5, 5, 4, 4]; | |
this.colours = [RGB(255, 0, 0), RGB(255, 153, 0), RGB(255, 255, 0), RGB(51, 255, 0), RGB(0, 153, 255), RGB(102, 51, 255)]; | |
break; | |
} | |
} | |
this.x = x; | |
this.y = y; | |
this.w = w; | |
this.h = h; | |
this.z = 0; | |
this.pos = 0; | |
this.drag = false; | |
this.drag_seek = 0; | |
this.old_x = 0; | |
this.old_y = 0; | |
this.init(); | |
this.seekbar_timer = window.SetInterval(function() { | |
s.z = s.z == 0 ? 1 : 0; | |
if (!fb.IsPlaying || fb.IsPaused || fb.PlaybackLength == 0) return; | |
s.update(); | |
}, 150); | |
} | |
function text(x, y, w, h) { | |
this.size = function() { | |
this.rows = Math.floor((this.h - 36) / p.row_height); | |
this.but_x = this.x + Math.round((this.w - 15) / 2); | |
this.up_btn = new sb(this.but_x, this.y, 15, 15, p.up_img, "t.offset > 0", function() { t.wheel(1); }); | |
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); }); | |
this.calc(); | |
} | |
this.draw = function(gr, colour) { | |
for (i = 0; i < Math.min(this.rows, this.text_rows); i++) { | |
if (this.centre) p.centre_text(gr, this.text_array[i + this.offset], this.fixed ? p.fixed_font : p.normal_font, colour || p.textcolour, this.x, 18 + this.y + (i * p.row_height), this.w, p.row_height); | |
else p.left_text(gr, this.text_array[i + this.offset], this.fixed ? p.fixed_font : p.normal_font, colour || p.textcolour, this.x, 18 + this.y + (i * p.row_height), this.w, p.row_height); | |
} | |
this.up_btn.draw(gr); | |
this.down_btn.draw(gr); | |
} | |
this.metadb_changed = function() { | |
if (!p.metadb) return false; | |
switch(this.mode) { | |
case "simple_tag": | |
this.temp_filename = p.metadb.Path; | |
if (this.filename == this.temp_filename) return false; | |
this.filename = this.temp_filename; | |
this.text = p.eval(this.tag); | |
break; | |
case "simple_text": | |
this.temp_filename = p.eval(this.filename_tf); | |
if (this.filename == this.temp_filename) return false; | |
this.text = ""; | |
this.filename = this.temp_filename; | |
if (p.fso.FolderExists(this.filename)) { | |
this.files = []; | |
this.files = this.files.concat(utils.Glob(this.filename + "\\*.txt").toArray(), utils.Glob(this.filename + "\\*.log").toArray()); | |
this.files.sort(); | |
this.text = p.open(this.files[0]); | |
} else { | |
this.filenames = this.filename.split("|"); | |
for (i = 0; i < this.filenames.length; i++) { | |
if (p.fso.fileExists(this.filenames[i])) { | |
this.text = p.open(this.filenames[i]); | |
break; | |
} | |
} | |
} | |
this.text = this.text.replace(/\t/g, " "); | |
break; | |
case "lastfm_wiki": | |
p.artist = p.eval(p.artist_tf); | |
if (this.artist == p.artist) return false; | |
this.artist = p.artist; | |
this.folder = p.data_folder + p.artist; | |
if (!p.fso.FolderExists(this.folder)) p.fso.CreateFolder(this.folder); | |
this.filename = this.folder + "\\artist.getInfo_mod.json"; | |
this.text = "Nothing found."; | |
this.url = "http://www.last.fm/"; | |
if (p.fso.fileExists(this.filename)) { | |
this.json_text = p.open(this.filename); | |
this.json_data = p.json_parse(this.json_text); | |
if (this.json_data && this.json_data.response && this.json_data.response.biographies) { | |
this.items = this.json_data.response.biographies.length; | |
for (i = 0; i < this.items; i++) { | |
if (this.json_data.response.biographies[i].site == this.source) { | |
this.text = this.json_data.response.biographies[i].text; | |
this.url = this.json_data.response.biographies[i].license["attribution-url"]; | |
break; | |
} | |
} | |
if (this.source == "last.fm") this.text = this.text.replace(/\. /g, ".\n\n"); | |
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"); | |
} | |
} else { | |
this.get(); | |
} | |
break; | |
case "lastfm_album": | |
var temp_album = p.eval("[%album%]"); | |
var temp_artist = p.eval("[%album artist%]"); | |
if (this.album == temp_album && this.artist == temp_artist) return false; | |
this.artist = temp_artist; | |
this.album = temp_album; | |
this.folder = p.data_folder + p.eval("$crc32(%album artist%)"); | |
if (!p.fso.FolderExists(this.folder)) p.fso.CreateFolder(this.folder); | |
this.filename = this.folder + "\\album.getInfo_" + p.eval("$crc32(%album%)") + ".json"; | |
this.text = "Nothing found."; | |
this.url = l.url; | |
if (p.fso.fileExists(this.filename)) { | |
this.file = p.fso.GetFile(this.filename); | |
this.json_text = p.open(this.filename); | |
this.json_data = p.json_parse(this.json_text); | |
if (this.json_data && this.json_data.album) { | |
if (this.json_data.album.url) this.url = this.json_data.album.url; | |
if (this.json_data.album.wiki && this.json_data.album.wiki.content) { | |
this.text = p.strip_tags(this.json_data.album.wiki.content); | |
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(); | |
} | |
} | |
if (Date.parse(Date()) - Date.parse(this.file.DateLastModified) > ONE_DAY) this.get(); | |
} else { | |
this.get(); | |
} | |
break; | |
} | |
this.calc(); | |
window.Repaint(); | |
return true; | |
} | |
this.trace = function(x, y) { | |
return (x > this.x && x < this.x + this.w && y > this.y && y < this.y + this.h); | |
} | |
this.wheel = function(step) { | |
if (!this.trace(p.mx, p.my)) return false; | |
if (this.text_rows > this.rows) { | |
this.offset -= step * 3; | |
if (this.offset < 0) this.offset = 0; | |
if (this.offset + this.rows > this.text_rows) this.offset = this.text_rows - this.rows; | |
window.RepaintRect(this.x, this.y, this.w, this.h); | |
} | |
return true; | |
} | |
this.move = function(x, y) { | |
switch(true) { | |
case !this.trace(x, y): | |
window.SetCursor(IDC_ARROW); | |
return false; | |
case this.up_btn.trace(x, y): | |
case this.down_btn.trace(x, y): | |
window.SetCursor(IDC_HAND); | |
return true; | |
default: | |
window.SetCursor(IDC_ARROW); | |
return false; | |
} | |
} | |
this.lbtn_up = function(x, y) { | |
if (!this.trace(x, y)) return false; | |
this.up_btn.lbtn_up(x, y); | |
this.down_btn.lbtn_up(x, y); | |
return true; | |
} | |
this.get = function() { | |
var fn = this.filename; | |
var func = function() { | |
if (!p.save(t.xmlhttp.responsetext, fn)) return; | |
t.artist = ""; | |
t.album = ""; | |
on_item_focus_change(); | |
} | |
var url = ""; | |
var user_agent = ""; | |
switch(this.mode) { | |
case "lastfm_album": | |
if (this.artist == "" || this.album == "") return; | |
url = l.get_url() + "&method=album.getInfo&artist=" + encodeURIComponent(this.artist) + "&album=" + encodeURIComponent(this.album); | |
user_agent = l.user_agent; | |
break; | |
case "lastfm_wiki": | |
if (this.artist == "" || this.artist == "?") return; | |
url = "http://developer.echonest.com/api/v4/artist/biographies?api_key=EKWS4ESQLKN3G2ZWV&format=json&name=" + encodeURIComponent(this.artist); | |
break; | |
} | |
if (url.length == 0) return; | |
this.xmlhttp.open("GET", url, true); | |
if (user_agent.length > 0) this.xmlhttp.setRequestHeader('User-Agent', user_agent); | |
this.xmlhttp.send(); | |
this.xmlhttp.onreadystatechange = function() { | |
if (t.xmlhttp.readyState == 4) { | |
if (t.xmlhttp.status == 200) { | |
func(); | |
} else { | |
p.console(t.xmlhttp.responsetext || "HTTP error: " + t.xmlhttp.status); | |
} | |
} | |
} | |
} | |
this.calc = function() { | |
this.offset = 0; | |
this.text_rows = 0; | |
if (this.w < 100 || this.text.length == 0) return; | |
var temp_bmp = gdi.CreateImage(1, 1); | |
var temp_gr = temp_bmp.GetGraphics(); | |
var paragraphs = this.text.split("\n"); | |
this.text_array = []; | |
for (i = 0; i < paragraphs.length; i++) { | |
if (this.fixed) { | |
this.text_array.push(paragraphs[i]); | |
} else { | |
var lines = temp_gr.EstimateLineWrap(paragraphs[i], p.normal_font, this.w).toArray(); | |
for (j = 0; j < lines.length; j += 2) { | |
this.text_array.push(lines[j].trim()); | |
} | |
} | |
} | |
this.text_rows = this.text_array.length; | |
temp_bmp.ReleaseGraphics(temp_gr); | |
temp_bmp.Dispose(); | |
temp_gr = null; | |
temp_bmp = null; | |
} | |
this.init = function() { | |
switch(true) { | |
case p.check_feature("lastfm_album"): | |
this.mode = "lastfm_album"; | |
break; | |
case p.check_feature("lastfm_wiki"): | |
this.mode = "lastfm_wiki"; | |
this.source = window.GetProperty("biography_source", "last.fm"); | |
break; | |
case p.check_feature("simple_text"): | |
this.mode = "simple_text"; | |
this.title = window.GetProperty("text_title", "$directory_path(%path%)"); | |
this.filename_tf = window.GetProperty("text_filename_tf", "$directory_path(%path%)"); | |
this.filename = ""; | |
this.fixed = window.GetProperty("text_fixed_font", true); | |
break; | |
case p.check_feature("simple_tag"): | |
this.mode = "simple_tag"; | |
this.title = window.GetProperty("text_title", "%title%"); | |
this.filename = ""; | |
this.centre = window.GetProperty("text_centre", false); | |
this.tag = window.GetProperty("text_tag", "[%lyrics%]"); | |
break; | |
} | |
} | |
this.x = x; | |
this.y = y; | |
this.w = w; | |
this.h = h; | |
this.text = ""; | |
this.artist = ""; | |
this.album = ""; | |
this.url = ""; | |
this.fixed = false; | |
this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); | |
this.init(); | |
this.size(); | |
} | |
function thumbs() { | |
this.trace = function(x, y) { | |
return (x > this.x && x < this.x + this.w && y > this.y && y < this.y + this.h); | |
} | |
this.draw = function(gr) { | |
switch(true) { | |
case im.images.length == 0: | |
break; | |
case this.mode == "off": | |
p.draw_image(gr, im.images[im.index], im.x, im.y, im.w, im.h, im.type); | |
break; | |
case !this.img: | |
break; | |
case this.mode == "grid": | |
gr.DrawImage(this.img, this.x, this.y, this.w, this.h, 0, this.offset * this.px, this.w, this.h); | |
if (this.overlay) { | |
gr.FillSolidRect(this.x, this.y, this.w, this.h, RGBA(0, 0, 0, 126)); | |
p.draw_image(gr, im.images[im.index], im.x, im.y, im.w, im.h, "adjust"); | |
} | |
break; | |
case this.mode == "left": | |
case this.mode == "right": | |
gr.DrawImage(this.img, this.x, this.y, this.w, this.h, 0, this.offset * this.px, this.w, this.h); | |
p.draw_image(gr, im.images[im.index], im.x, im.y, im.w, im.h, im.type); | |
break; | |
case this.mode == "bottom": | |
case this.mode == "top": | |
gr.DrawImage(this.img, this.x, this.y, this.w, this.h, this.offset * this.px, 0, this.w, this.h); | |
p.draw_image(gr, im.images[im.index], im.x, im.y, im.w, im.h, im.type); | |
break; | |
} | |
} | |
this.calc = function() { | |
this.offset = 0; | |
switch(true) { | |
case p.w < this.px || p.h < this.px || this.mode == "off": | |
this.nc = true; | |
this.img && this.img.Dispose(); | |
this.img = null; | |
im.x = 0; | |
im.y = 0; | |
im.w = p.w; | |
im.h = p.h; | |
break; | |
case this.mode == "grid": | |
this.x = 0; | |
this.y = 0; | |
this.w = p.w; | |
this.h = p.h; | |
im.x = 40; | |
im.y = 40; | |
im.w = this.w - 80; | |
im.h = this.h - 80; | |
if (!this.nc && this.columns != Math.floor(this.w / this.px)) this.nc = true; | |
this.overlay = false; | |
this.rows = Math.ceil(this.h / this.px); | |
this.columns = Math.floor(this.w / this.px); | |
this.img_rows = Math.ceil(im.images.length / this.columns); | |
if (this.nc && im.images.length > 0) { | |
this.nc = false; | |
this.img && this.img.Dispose(); | |
this.img = null; | |
this.img = gdi.CreateImage(Math.min(this.columns, im.images.length) * this.px, this.img_rows * this.px); | |
var temp_gr = this.img.GetGraphics(); | |
temp_gr.SetInterpolationMode(7); | |
var ci = 0; | |
var row, col; | |
for (row = 0; row < this.img_rows; row++) { | |
for (col = 0; col < this.columns; col++) { | |
if (ci == im.images.length) continue; | |
p.draw_image(temp_gr, im.images[ci], col * this.px, row * this.px, this.px, this.px, "top"); | |
ci++; | |
} | |
} | |
this.img.ReleaseGraphics(temp_gr); | |
temp_gr = null; | |
} | |
break; | |
case this.mode == "left": | |
case this.mode == "right": | |
this.x = this.mode == "left" ? 0 : p.w - this.px; | |
this.y = 0; | |
this.w = this.px; | |
this.h = p.h; | |
im.x = this.mode == "right" ? 0 : this.px; | |
im.y = 0; | |
im.w = p.w - this.px; | |
im.h = p.h; | |
this.rows = Math.ceil(this.h / this.px); | |
if (this.nc && im.images.length > 0) { | |
this.nc = false; | |
this.img && this.img.Dispose(); | |
this.img = null; | |
this.img = gdi.CreateImage(this.px, this.px * im.images.length); | |
var temp_gr = this.img.GetGraphics(); | |
temp_gr.SetInterpolationMode(7); | |
for (i = 0; i < im.images.length; i++) { | |
p.draw_image(temp_gr, im.images[i], 0, i * this.px, this.px, this.px, "top"); | |
} | |
this.img.ReleaseGraphics(temp_gr); | |
temp_gr = null; | |
} | |
break; | |
case this.mode == "bottom": | |
case this.mode == "top": | |
this.x = 0; | |
this.y = this.mode == "top" ? 0 : p.h - this.px; | |
this.w = p.w; | |
this.h = this.px; | |
im.x = 0; | |
im.y = this.mode == "bottom" ? 0 : this.px; | |
im.w = p.w; | |
im.h = p.h - this.px; | |
this.columns = Math.ceil(this.w / this.px); | |
if (this.nc && im.images.length > 0) { | |
this.nc = false; | |
this.img && this.img.Dispose(); | |
this.img = null; | |
this.img = gdi.CreateImage(this.px * im.images.length, this.px); | |
var temp_gr = this.img.GetGraphics(); | |
temp_gr.SetInterpolationMode(7); | |
for (i = 0; i < im.images.length; i++) { | |
p.draw_image(temp_gr, im.images[i], i * this.px, 0, this.px, this.px, "top"); | |
} | |
this.img.ReleaseGraphics(temp_gr); | |
temp_gr = null; | |
} | |
break; | |
} | |
} | |
this.wheel = function(step) { | |
switch(true) { | |
case !this.trace(p.mx, p.my): | |
case this.overlay: | |
return false; | |
case this.mode == "grid": | |
if (this.img_rows < this.rows) return true; | |
this.offset -= step; | |
if (this.offset < 0) this.offset = 0; | |
if (this.offset > this.img_rows - this.rows) this.offset = this.img_rows - this.rows + 1; | |
break; | |
case this.mode == "left": | |
case this.mode == "right": | |
if (im.images.length < this.rows) return true; | |
this.offset -= step; | |
if (this.offset < 0) this.offset = 0; | |
if (this.rows + this.offset > im.images.length) this.offset = im.images.length - this.rows + 1; | |
break; | |
case this.mode == "bottom": | |
case this.mode == "top": | |
if (im.images.length < this.columns) return true; | |
this.offset -= step; | |
if (this.offset < 0) this.offset = 0; | |
if (this.columns + this.offset > im.images.length) this.offset = im.images.length - this.columns + 1; | |
break; | |
} | |
window.RepaintRect(this.x, this.y, this.w, this.h); | |
return true; | |
} | |
this.move = function(x, y) { | |
switch(true) { | |
case !this.trace(x, y): | |
window.SetCursor(IDC_ARROW); | |
return false; | |
case this.overlay: | |
window.SetCursor(IDC_ARROW); | |
return true; | |
case this.mode == "grid": | |
this.index = Math.floor((x - this.x) / this.px) + (Math.floor((y - this.y) / this.px) * this.columns) + (this.offset * this.columns); | |
break; | |
case this.mode == "left": | |
case this.mode == "right": | |
this.index = Math.floor((y - this.y) / this.px) + this.offset; | |
break; | |
case this.mode == "bottom": | |
case this.mode == "top": | |
this.index = Math.floor((x - this.x) / this.px) + this.offset; | |
break; | |
} | |
window.SetCursor(this.index < im.images.length ? IDC_HAND : IDC_ARROW); | |
return true; | |
} | |
this.lbtn_up = function(x, y) { | |
switch(true) { | |
case !this.trace(x, y): | |
return false; | |
case this.mode == "grid" && this.overlay && im.trace(x, y): | |
this.overlay = false; | |
window.Repaint(); | |
break; | |
case this.mode == "grid" && this.index < im.images.length && !this.overlay: | |
this.overlay = true; | |
im.index = this.index; | |
window.Repaint(); | |
break; | |
case this.overlay: | |
break; | |
case this.index < im.images.length: | |
im.index = this.index; | |
window.Repaint(); | |
} | |
return true; | |
} | |
this.lbtn_dblclk = function(x, y) { | |
if (!im.trace(x, y) || th.mode == "grid") return false; | |
p.run("\"" + im.files[im.index] + "\""); | |
return true; | |
} | |
this.nc = false; | |
this.mode = window.GetProperty("Thumbs mode", p.check_feature("now_playing") ? "off" : "off"); | |
this.px = window.GetProperty("Thumbs px", 40); | |
this.img = null; | |
} | |
//json2.js | |
if(typeof JSON!=='object'){JSON={};} | |
(function(){'use strict';function f(n){return n<10?'0'+n:n;} | |
if(typeof Date.prototype.toJSON!=='function'){Date.prototype.toJSON=function(key){return isFinite(this.valueOf())?this.getUTCFullYear()+'-'+ | |
f(this.getUTCMonth()+1)+'-'+ | |
f(this.getUTCDate())+'T'+ | |
f(this.getUTCHours())+':'+ | |
f(this.getUTCMinutes())+':'+ | |
f(this.getUTCSeconds())+'Z':null;};String.prototype.toJSON=Number.prototype.toJSON=Boolean.prototype.toJSON=function(key){return this.valueOf();};} | |
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+'"';} | |
function str(key,holder){var i,k,v,length,mind=gap,partial,value=holder[key];if(value&&typeof value==='object'&&typeof value.toJSON==='function'){value=value.toJSON(key);} | |
if(typeof rep==='function'){value=rep.call(holder,key,value);} | |
switch(typeof value){case'string':return quote(value);case'number':return isFinite(value)?String(value):'null';case'boolean':case'null':return String(value);case'object':if(!value){return'null';} | |
gap+=indent;partial=[];if(Object.prototype.toString.apply(value)==='[object Array]'){length=value.length;for(i=0;i<length;i+=1){partial[i]=str(i,value)||'null';} | |
v=partial.length===0?'[]':gap?'[\n'+gap+partial.join(',\n'+gap)+'\n'+mind+']':'['+partial.join(',')+']';gap=mind;return v;} | |
if(rep&&typeof rep==='object'){length=rep.length;for(i=0;i<length;i+=1){if(typeof rep[i]==='string'){k=rep[i];v=str(k,value);if(v){partial.push(quote(k)+(gap?': ':':')+v);}}}}else{for(k in value){if(Object.prototype.hasOwnProperty.call(value,k)){v=str(k,value);if(v){partial.push(quote(k)+(gap?': ':':')+v);}}}} | |
v=partial.length===0?'{}':gap?'{\n'+gap+partial.join(',\n'+gap)+'\n'+mind+'}':'{'+partial.join(',')+'}';gap=mind;return v;}} | |
if(typeof JSON.stringify!=='function'){JSON.stringify=function(value,replacer,space){var i;gap='';indent='';if(typeof space==='number'){for(i=0;i<space;i+=1){indent+=' ';}}else if(typeof space==='string'){indent=space;} | |
rep=replacer;if(replacer&&typeof replacer!=='function'&&(typeof replacer!=='object'||typeof replacer.length!=='number')){throw new Error('JSON.stringify');} | |
return str('',{'':value});};} | |
if(typeof JSON.parse!=='function'){JSON.parse=function(text,reviver){var j;function walk(holder,key){var k,v,value=holder[key];if(value&&typeof value==='object'){for(k in value){if(Object.prototype.hasOwnProperty.call(value,k)){v=walk(value,k);if(v!==undefined){value[k]=v;}else{delete value[k];}}}} | |
return reviver.call(holder,key,value);} | |
text=String(text);cx.lastIndex=0;if(cx.test(text)){text=text.replace(cx,function(a){return'\\u'+ | |
('0000'+a.charCodeAt(0).toString(16)).slice(-4);});} | |
if(/^[\],:{}\s]*$/.test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g,'@').replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,']').replace(/(?:^|:|,)(?:\s*\[)+/g,''))){j=eval('('+text+')');return typeof reviver==='function'?walk({'':j},''):j;} | |
throw new SyntaxError('JSON.parse');};}}()); | |
/* | |
* A JavaScript implementation of the RSA Data Security, Inc. MD5 Message | |
* Digest Algorithm, as defined in RFC 1321. | |
* Version 2.2 Copyright (C) Paul Johnston 1999 - 2009 | |
* Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet | |
* Distributed under the BSD License | |
* See http://pajhome.org.uk/crypt/md5 for more info. | |
*/ | |
var hexcase=0;function hex_md5(a){return rstr2hex(rstr_md5(str2rstr_utf8(a)))} | |
function hex_hmac_md5(a,b){return rstr2hex(rstr_hmac_md5(str2rstr_utf8(a),str2rstr_utf8(b)))} | |
function md5_vm_test(){return hex_md5("abc").toLowerCase()=="900150983cd24fb0d6963f7d28e17f72"} | |
function rstr_md5(a){return binl2rstr(binl_md5(rstr2binl(a),a.length*8))} | |
function rstr_hmac_md5(c,f){var e=rstr2binl(c);if(e.length>16){e=binl_md5(e,c.length*8)} | |
var a=Array(16),d=Array(16);for(var b=0;b<16;b++){a[b]=e[b]^909522486;d[b]=e[b]^1549556828} | |
var g=binl_md5(a.concat(rstr2binl(f)),512+f.length*8);return binl2rstr(binl_md5(d.concat(g),512+128))} | |
function rstr2hex(c){try{hexcase}catch(g){hexcase=0} | |
var f=hexcase?"0123456789ABCDEF":"0123456789abcdef";var b="";var a;for(var d=0;d<c.length;d++){a=c.charCodeAt(d);b+=f.charAt((a>>>4)&15)+f.charAt(a&15)} | |
return b} | |
function str2rstr_utf8(c){var b="";var d=-1;var a,e;while(++d<c.length){a=c.charCodeAt(d);e=d+1<c.length?c.charCodeAt(d+1):0;if(55296<=a&&a<=56319&&56320<=e&&e<=57343){a=65536+((a&1023)<<10)+(e&1023);d++} | |
if(a<=127){b+=String.fromCharCode(a)}else{if(a<=2047){b+=String.fromCharCode(192|((a>>>6)&31),128|(a&63))}else{if(a<=65535){b+=String.fromCharCode(224|((a>>>12)&15),128|((a>>>6)&63),128|(a&63))}else{if(a<=2097151){b+=String.fromCharCode(240|((a>>>18)&7),128|((a>>>12)&63),128|((a>>>6)&63),128|(a&63))}}}}} | |
return b} | |
function rstr2binl(b){var a=Array(b.length>>2);for(var c=0;c<a.length;c++){a[c]=0} | |
for(var c=0;c<b.length*8;c+=8){a[c>>5]|=(b.charCodeAt(c/8)&255)<<(c%32)} | |
return a} | |
function binl2rstr(b){var a="";for(var c=0;c<b.length*32;c+=8){a+=String.fromCharCode((b[c>>5]>>>(c%32))&255)} | |
return a} | |
function binl_md5(p,k){p[k>>5]|=128<<((k)%32);p[(((k+64)>>>9)<<4)+14]=k;var o=1732584193;var n=-271733879;var m=-1732584194;var l=271733878;for(var g=0;g<p.length;g+=16){var j=o;var h=n;var f=m;var e=l;o=md5_ff(o,n,m,l,p[g+0],7,-680876936);l=md5_ff(l,o,n,m,p[g+1],12,-389564586);m=md5_ff(m,l,o,n,p[g+2],17,606105819);n=md5_ff(n,m,l,o,p[g+3],22,-1044525330);o=md5_ff(o,n,m,l,p[g+4],7,-176418897);l=md5_ff(l,o,n,m,p[g+5],12,1200080426);m=md5_ff(m,l,o,n,p[g+6],17,-1473231341);n=md5_ff(n,m,l,o,p[g+7],22,-45705983);o=md5_ff(o,n,m,l,p[g+8],7,1770035416);l=md5_ff(l,o,n,m,p[g+9],12,-1958414417);m=md5_ff(m,l,o,n,p[g+10],17,-42063);n=md5_ff(n,m,l,o,p[g+11],22,-1990404162);o=md5_ff(o,n,m,l,p[g+12],7,1804603682);l=md5_ff(l,o,n,m,p[g+13],12,-40341101);m=md5_ff(m,l,o,n,p[g+14],17,-1502002290);n=md5_ff(n,m,l,o,p[g+15],22,1236535329);o=md5_gg(o,n,m,l,p[g+1],5,-165796510);l=md5_gg(l,o,n,m,p[g+6],9,-1069501632);m=md5_gg(m,l,o,n,p[g+11],14,643717713);n=md5_gg(n,m,l,o,p[g+0],20,-373897302);o=md5_gg(o,n,m,l,p[g+5],5,-701558691);l=md5_gg(l,o,n,m,p[g+10],9,38016083);m=md5_gg(m,l,o,n,p[g+15],14,-660478335);n=md5_gg(n,m,l,o,p[g+4],20,-405537848);o=md5_gg(o,n,m,l,p[g+9],5,568446438);l=md5_gg(l,o,n,m,p[g+14],9,-1019803690);m=md5_gg(m,l,o,n,p[g+3],14,-187363961);n=md5_gg(n,m,l,o,p[g+8],20,1163531501);o=md5_gg(o,n,m,l,p[g+13],5,-1444681467);l=md5_gg(l,o,n,m,p[g+2],9,-51403784);m=md5_gg(m,l,o,n,p[g+7],14,1735328473);n=md5_gg(n,m,l,o,p[g+12],20,-1926607734);o=md5_hh(o,n,m,l,p[g+5],4,-378558);l=md5_hh(l,o,n,m,p[g+8],11,-2022574463);m=md5_hh(m,l,o,n,p[g+11],16,1839030562);n=md5_hh(n,m,l,o,p[g+14],23,-35309556);o=md5_hh(o,n,m,l,p[g+1],4,-1530992060);l=md5_hh(l,o,n,m,p[g+4],11,1272893353);m=md5_hh(m,l,o,n,p[g+7],16,-155497632);n=md5_hh(n,m,l,o,p[g+10],23,-1094730640);o=md5_hh(o,n,m,l,p[g+13],4,681279174);l=md5_hh(l,o,n,m,p[g+0],11,-358537222);m=md5_hh(m,l,o,n,p[g+3],16,-722521979);n=md5_hh(n,m,l,o,p[g+6],23,76029189);o=md5_hh(o,n,m,l,p[g+9],4,-640364487);l=md5_hh(l,o,n,m,p[g+12],11,-421815835);m=md5_hh(m,l,o,n,p[g+15],16,530742520);n=md5_hh(n,m,l,o,p[g+2],23,-995338651);o=md5_ii(o,n,m,l,p[g+0],6,-198630844);l=md5_ii(l,o,n,m,p[g+7],10,1126891415);m=md5_ii(m,l,o,n,p[g+14],15,-1416354905);n=md5_ii(n,m,l,o,p[g+5],21,-57434055);o=md5_ii(o,n,m,l,p[g+12],6,1700485571);l=md5_ii(l,o,n,m,p[g+3],10,-1894986606);m=md5_ii(m,l,o,n,p[g+10],15,-1051523);n=md5_ii(n,m,l,o,p[g+1],21,-2054922799);o=md5_ii(o,n,m,l,p[g+8],6,1873313359);l=md5_ii(l,o,n,m,p[g+15],10,-30611744);m=md5_ii(m,l,o,n,p[g+6],15,-1560198380);n=md5_ii(n,m,l,o,p[g+13],21,1309151649);o=md5_ii(o,n,m,l,p[g+4],6,-145523070);l=md5_ii(l,o,n,m,p[g+11],10,-1120210379);m=md5_ii(m,l,o,n,p[g+2],15,718787259);n=md5_ii(n,m,l,o,p[g+9],21,-343485551);o=safe_add(o,j);n=safe_add(n,h);m=safe_add(m,f);l=safe_add(l,e)} | |
return Array(o,n,m,l)} | |
function md5_cmn(h,e,d,c,g,f){return safe_add(bit_rol(safe_add(safe_add(e,h),safe_add(c,f)),g),d)} | |
function md5_ff(g,f,k,j,e,i,h){return md5_cmn((f&k)|((~f)&j),g,f,e,i,h)} | |
function md5_gg(g,f,k,j,e,i,h){return md5_cmn((f&j)|(k&(~j)),g,f,e,i,h)} | |
function md5_hh(g,f,k,j,e,i,h){return md5_cmn(f^k^j,g,f,e,i,h)} | |
function md5_ii(g,f,k,j,e,i,h){return md5_cmn(k^(f|(~j)),g,f,e,i,h)} | |
function safe_add(a,d){var c=(a&65535)+(d&65535);var b=(a>>16)+(d>>16)+(c>>16);return(b<<16)|(c&65535)} | |
function bit_rol(a,b){return(a<<b)|(a>>>(32-b))}; | |
var p = new panel("Thumbs", ["custom_background", "remap", "metadb"]); | |
var im = new images(0, 0, 0, 0); | |
var th = new thumbs(); | |
on_item_focus_change(); | |
function on_playback_time(time) { | |
//im.playback_time(time); | |
} | |
function on_size() { | |
p.size(); | |
th.calc(); | |
} | |
function on_paint(gr) { | |
p.draw_background(gr); | |
th.draw(gr); | |
//if (im.working==true && im.images.length==0) p.centre_text(gr, p.metadb ? "Please wait.." : "", p.normal_font, p.textcolour, 0, 0, p.w, p.h); | |
} | |
function on_metadb_changed() { | |
im.metadb_changed(); | |
if (im.images.length == 0 && im.auto_download=="on") | |
im.download(); | |
} | |
function on_mouse_wheel(step) { | |
if (th.wheel(step)) return; | |
if (im.wheel(step)) return; | |
} | |
function on_mouse_move(x, y) { | |
p.move(x, y); | |
th.move(x, y); | |
} | |
function on_mouse_lbtn_up(x, y) { | |
th.lbtn_up(x, y); | |
} | |
function on_mouse_lbtn_dblclk(x, y) { | |
th.lbtn_dblclk(x, y); | |
} | |
//Auto Cycle Image | |
var cicleTimerStarted = false; | |
var cicleTimer = null; | |
(function startTimer(){ | |
if(!cicleTimerStarted){ | |
cicleTimer = window.CreateTimerInterval(cycle2+"000"); | |
cicleTimerStarted = true; | |
} | |
})(); | |
function stopTimer(){ | |
if(!cicleTimerStarted) return; | |
window.KillTimer(cicleTimer); | |
cicleTimer = undefined; | |
cicleTimerStarted = false; | |
} | |
function on_timer(id) { | |
if(cicleTimer && id == cicleTimer.ID){ | |
{ | |
do{ | |
im.index++ | |
if (im.index == im.images.length) im.index=0; | |
window.Repaint(); | |
}while (im.index==-1); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment