Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==PREPROCESSOR==
- // @import "%fb2k_profile_path%scripts\common.js"
- // @import "%fb2k_profile_path%scripts\md5.js"
- // @import "%fb2k_profile_path%scripts\utf8encode.js"
- // @name "Biography, Last.fm main panel"
- // Required for other Last.fm panels
- // ==/PREPROCESSOR==
- var username = utils.ReadINI(inifile, "default", "username", "");
- var api_key = utils.ReadINI(inifile, "default", "api_key", "");
- var lfm_secret = utils.ReadINI(inifile, "default", "secret", "");
- var lfm_sk = utils.ReadINI(inifile, "default", "session_key", "");
- var cache_life = utils.ReadINI(inifile, "default", "cache_life", 0);
- var data_folder = utils.ReadINI(inifile, "default", "data_folder", "/");
- var proxy_file = script_path + "wget.ini";
- var languages = new Array("English", "日本語", "Deutsch", "Español", "Français", "Italiano", "Polski", "Português", "Руccкий", "Türkçe", "Svenska", "简体中文");
- var langs = new Array("en", "jp", "de", "es", "fr", "it", "pl", "pt", "ru", "tr", "sv", "zh");
- var lang = langs[window.GetProperty("language",100) - 100];
- var artist = alartist = album = title = lastfm_artist = lastfm_artist_url = p_title = '';
- var p_title_width = 0;
- var p_title_need_calc = true;
- var lfm_token = '';
- var g_text = '';
- var trackxml = '';
- var working = 0;
- var simartist_height = 0;
- var simartists_height = 0;
- var simartists = [];
- var simartist_widths = [];
- var simartist_urls = [];
- var simartist_urls_ori = [];
- var sc_cache = [];
- var scrobbling = lfm_np_updating = false;
- var sc_np_timer = null;
- var sc_cache_file = fb.ProfilePath + "wsh_lfm_scrobble_cache.txt";
- var need_calc_simartists_dim = true;
- var g_drag = false;
- var g_drag_y = 0;
- var g_need_calc = true;
- var g_offset = 0;
- var g_textheight = 0;
- var defoffset = 51;
- var start_y = 0;
- var dlartistart = false;
- var startplay = true;
- var token_timer = null;
- var pf = fb.CreateProfiler("");
- var pb_time = 0;
- var playing = pausing = false;
- var useragent = "thuan's foobar2000 lastfm wsh panels";
- var g_tooltip = window.CreateTooltip();
- var sc_hint_font = gdi.Font(font, 9, 0);
- var p_title_font = gdi.Font(font, 16, 1);
- g_tooltip.SetMaxWidth(600);
- window.GetProperty("auto", true);
- window.GetProperty("artistartcacherefresh", true);
- window.GetProperty("offline", false);
- window.GetProperty("scrobble", false);
- window.GetProperty("onlymlfile", false);
- window.GetProperty("walbum", true);
- window.GetProperty("walbumartist", true);
- window.GetProperty("wduration", true);
- window.GetProperty("wtracknumber", true);
- var limit = window.GetProperty("limit", 305) - 300;
- var artistartsizes = ["Original", "Small", "Medium", "Large square", "Large", "Extra large"];
- var artistartsizetext = ["original", "small", "medium", "largesquare", "large", "extralarge"];
- var artistartsize = artistartsizetext[window.GetProperty("artistartsize",400) - 400];
- var tf_artist = utils.ReadINI(inifile, "scrobbler", "tf_artist", "%artist%");
- var tf_title = utils.ReadINI(inifile, "scrobbler", "tf_title", "$meta(title)");
- cache_life = (!cache_life.match(/^(\d+)$/)) ? 0 : (parseInt(cache_life) * 86400000);
- if (window.GetProperty("scrobble")) sc_cache_restore();
- function on_notify_data(name, data) {
- if (name == "getplayinginfo" && !window.GetProperty("offline")) {
- get_playing_track_info(data[0], data[1]);
- }
- if (name == "getlastfmchart") {
- refreshlastfmchart = false;
- get_lastfm_chart(data[0], data[1], data[2], data[3]);
- }
- if (name == "refreshlastfmchart") {
- refreshlastfmchart = true;
- get_lastfm_chart(data[0], data[1], data[2], data[3]);
- }
- if (name == "getrecenttracks") {
- if (!window.GetProperty("offline"))
- get_recent_tracks();
- else
- window.NotifyOthers("recenttracks", "offline");
- }
- if (name == "getartistart") {
- dlartistart = true;
- load();
- dlartistart = false;
- }
- if (name == "altlastfmlovedstate") {
- alt_lastfm_loved_state(data[0], data[1], data[2]);
- }
- }
- function on_timer(timer_id) {
- if (token_timer && token_timer.ID == timer_id) {
- window.KillTimer(token_timer) && token_timer.Dispose();
- lfm_token = "";
- }
- if (sc_np_timer && sc_np_timer.ID == timer_id) {
- window.KillTimer(sc_np_timer) && sc_np_timer.Dispose();
- /*fb.trace("NP Total " + sc_cache.length + ":")
- for (i in sc_cache) {
- fb.trace(i + ":")
- fb.trace(sc_cache[i].join("\n"));
- }*/
- if (fb.IsPlaying && !lfm_np_updating && !window.GetProperty("offline")) {
- lfm_np_updating = true;
- set_lfm_np(sc_cache.slice());
- }
- }
- }
- function on_size() {
- ww = window.Width;
- wh = window.Height;
- reset();
- }
- function on_script_unload() {
- if (window.GetProperty("scrobble")) sc_cache_save();
- }
- function on_paint(gr) {
- gr.FillSolidRect( 0, 0, ww, wh, g_backcolor);
- if(username.length == 0 || api_key.length != 32) {
- gr.GdiDrawText("Please use the context menu to set your Last.fm username and API KEY.", g_font, g_textcolor, 0, 0, ww, wh, DT_VCENTER | DT_CENTER | DT_WORDBREAK | DT_CALCRECT | DT_NOPREFIX);
- } else if(fb.IsPlaying) {
- if (g_need_calc) {
- calc(g_text, g_font, 6, 40, ww-16, wh - defoffset);
- }
- if (need_calc_simartists_dim) calc_simartists_dim();
- if (simartists_height > 0) {
- start_y = 40 + g_textheight - simartists_height + g_offset;
- }
- gr.GdiDrawText(g_text, g_font, g_textcolor, 6, g_offset + 40, ww-16, wh - g_offset - defoffset, DT_WORDBREAK | DT_NOPREFIX);
- gr.FillSolidRect(0, 0, ww, 40, g_backcolor);
- gr.FillSolidRect(0, wh-11, ww, 11, g_backcolor);
- if (g_textheight > wh - defoffset) {
- if (g_offset == 0) {
- gr.GdiDrawText("▼", sc_hint_font, g_textcolor, 0, wh-12, ww, 12, DT_TOP | DT_CENTER | DT_NOPREFIX);
- }
- if (g_offset < 0 && g_offset > -g_textheight + wh - defoffset) {
- gr.GdiDrawText("▲", sc_hint_font, g_textcolor, 0, 28, ww, 12, DT_TOP | DT_CENTER);
- gr.GdiDrawText("▼", sc_hint_font, g_textcolor, 0, wh-12, ww, 12, DT_TOP | DT_CENTER);
- }
- if (g_offset == -g_textheight + wh - defoffset) {
- gr.GdiDrawText("▲", sc_hint_font, g_textcolor, 0, 28, ww, 12, DT_TOP | DT_CENTER);
- }
- }
- if (p_title_need_calc) {
- p_title_width = gr.CalcTextWidth(p_title, p_title_font);
- p_title_width = (p_title_width > ww-12) ? ww-12 : p_title_width;
- p_title_need_calc = false;
- }
- gr.GdiDrawText(p_title, p_title_font, g_textcolor_hl, 6, 6, ww-12, 24, DT_VCENTER | DT_END_ELLIPSIS | DT_CALCRECT | DT_NOPREFIX);
- gr.DrawLine(10, 29, ww-20, 29, 1, g_textcolor_hl);
- gr.FillGradRect(5, 29,10, 1, 0, RGB(255,255,255), g_textcolor_hl);
- gr.FillGradRect(ww-20, 29,10, 1, 0, g_textcolor_hl,RGB(255,255,255));
- } else {
- gr.GdiDrawText("[playback stopped]", g_font, g_textcolor, 0, 0, ww, wh, DT_VCENTER | DT_CENTER | DT_WORDBREAK | DT_CALCRECT | DT_NOPREFIX);
- }
- }
- function on_playback_new_track(mdb) {
- playing = true;
- if (!pausing) pb_time += pf.Time;
- pausing = false;
- pb_time = Math.round(pb_time / 1000);
- if (sc_cache.length > 0) {
- if (window.GetProperty("scrobble")) {
- entry = sc_cache[sc_cache.length-1];
- if (pb_time <= 5 || entry[0] == -1)
- sc_cache.pop();
- else {
- if (entry.length == 9) entry.push(pb_time);
- if (!scrobbling && !window.GetProperty("offline")) {
- //fb.trace("==============scrobble=======");
- scrobbling = true;
- lastfm_scrobble(get_sc_list());
- }
- }
- } else sc_cache.pop();
- }
- pb_time = 0;
- pf.Reset();
- sc_cache_add(mdb, pb_start_time = Math.round(Date.parse(Date()) / 1000));
- g_metadb && g_metadb.Dispose();
- g_metadb = mdb;
- alartist = fb.TitleFormat("%album artist%").EvalWithMetadb(g_metadb);
- album = fb.TitleFormat("%album%").EvalWithMetadb(g_metadb);
- title = fb.TitleFormat("%title%").EvalWithMetadb(g_metadb);
- if (startplay) {
- artist = fb.TitleFormat("%artist%").EvalWithMetadb(g_metadb);
- load();
- return;
- }
- if (artist == fb.TitleFormat("%artist%").EvalWithMetadb(g_metadb)) return;
- artist = fb.TitleFormat("%artist%").EvalWithMetadb(g_metadb);
- load();
- }
- function on_playback_seek() {
- pb_time += pf.Time;
- pf.Reset();
- }
- function on_playback_pause(state) {
- if (state) {
- pb_time += pf.Time;
- if (pb_time <= 5000)
- sc_np_timer && window.KillTimer(sc_np_timer) && sc_np_timer.Dispose();
- pausing = true;
- } else {
- if (pb_time <= 5000)
- sc_np_timer = window.CreateTimerTimeout(5000 - pb_time);
- pausing = false;
- pf.Reset();
- }
- }
- function on_playback_edited() {
- if (artist != fb.TitleFormat("%artist%").EvalWithMetadb(g_metadb)) load();
- if (!window.GetProperty("scrobble")) return;
- if (artist != fb.TitleFormat("%artist%").EvalWithMetadb(g_metadb) || alartist != fb.TitleFormat("%album artist%").EvalWithMetadb(g_metadb) || album != fb.TitleFormat("%album%").EvalWithMetadb(g_metadb) || title != fb.TitleFormat("%title%").EvalWithMetadb(g_metadb)) {
- artist = fb.TitleFormat(tf_artist).EvalWithMetadb(g_metadb);
- alartist = fb.TitleFormat("%album artist%").EvalWithMetadb(g_metadb);
- album = fb.TitleFormat("%album%").EvalWithMetadb(g_metadb);
- title = fb.TitleFormat(tf_title).EvalWithMetadb(g_metadb);
- entry = sc_cache[sc_cache.length-1];
- entry[1] = false;
- entry[3] = album;
- entry[4] = alartist;
- entry[5] = artist;
- entry[7] = title;
- if (!lfm_np_updating && !window.GetProperty("offline")) {
- lfm_np_updating = true;
- set_lfm_np(sc_cache.slice());
- }
- }
- }
- function on_playback_stop(reason) {
- if (reason == 0) startplay = true;
- if (reason != 2) {
- sc_np_timer && window.KillTimer(sc_np_timer) && sc_np_timer.Dispose();
- if (reason != 3) playing = false;
- if (!pausing) pb_time += pf.Time;
- pausing = false;
- pb_time = Math.round(pb_time / 1000);
- if (window.GetProperty("scrobble")) {
- entry = sc_cache[sc_cache.length-1];
- if (pb_time <= 5 || entry[0] == -1)
- sc_cache.pop();
- else {
- if (entry.length == 9) entry.push(pb_time);
- }
- } else sc_cache.pop();
- window.Repaint();
- }
- }
- function get_playing_track_info(tartist, ttitle) {
- if (username.length == 0 || api_key.length != 32) return(fb.trace("Can't contact Last.fm. Check your username / API KEY settings."));
- var listeners = 0;
- var playcount = 0;
- var userplaycount = 0;
- var userloved = 0;
- var lfm_artist = '';
- var lfm_track = '';
- trackxmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
- qs = "&method=track.getinfo&autocorrect=1&username=" + username + "&artist=" + encodeURIComponent(tartist) + "&track=" + encodeURIComponent(ttitle);
- trackxmlhttp.open("GET", "http://ws.audioscrobbler.com/2.0/?api_key=" + api_key + "&user=" + username + qs + "&s=" + Math.random(), true);
- trackxmlhttp.setRequestHeader('User-Agent', useragent);
- trackxmlhttp.send();
- trackxmlhttp.onreadystatechange = function() {
- if (trackxmlhttp.readyState == 4) {
- if (trackxmlhttp.status == 200) {
- trackxml = trackxmlhttp.responseText;
- var trackxmldom= new ActiveXObject("Microsoft.XMLDOM");
- trackxmldom.async="false";
- trackxmldom.loadXML(trackxml);
- try {
- lfm_artist = trackxmldom.getElementsByTagName("artist")[0].childNodes[0].childNodes[0].nodeValue;
- } catch (e) {};
- try {
- lfm_track = trackxmldom.getElementsByTagName("track")[0].childNodes[1].childNodes[0].nodeValue;
- } catch (e) {};
- try {
- listeners = trackxmldom.getElementsByTagName("listeners")[0].childNodes[0].nodeValue;
- } catch (e) {};
- try {
- playcount = trackxmldom.getElementsByTagName("playcount")[0].childNodes[0].nodeValue;
- } catch (e) {};
- try {
- userplaycount = trackxmldom.getElementsByTagName("userplaycount")[0].childNodes[0].nodeValue;
- } catch (e) {};
- try {
- userloved = trackxmldom.getElementsByTagName("userloved")[0].childNodes[0].nodeValue;
- } catch (e) {};
- } else {
- fb.trace(trackxmlhttp.responseText);
- }
- window.NotifyOthers("playingtrack", [lfm_artist, lfm_track, listeners, playcount, userplaycount, userloved]);
- }
- }
- }
- function get_lastfm_chart(method, type, period, charts_folder) {
- if(username.length == 0 || api_key.length != 32) return(fb.trace("Last.fm Charts: Can't contact Last.fm. Check your username / API KEY settings."));
- top_el = method.substring(3).toLowerCase();
- filename = charts_folder + "\\" + username+ "_" + type + "_" + period + ".xml";
- ranks = new Array();
- names = new Array();
- name_widths = new Array();
- tt_texts = new Array();
- playcounts = new Array();
- urls = new Array();
- artists = new Array();
- if(fso.fileExists(filename)) {
- file = fso.Getfile(filename);
- if((refreshlastfmchart || (Date.parse(Date()) - Date.parse(file.DateLastModified) > 86400000)) && !window.GetProperty("offline")) {
- refreshlastfmchart = false;
- lastfm("&user=" + username + "&method=user." + method + "&period=" + period, useragent, function() {save_xml_file(filename); get_lastfm_chart(method, type, period, charts_folder);});
- return;
- }
- chartxml = utils.ReadTextFile(filename);
- if(chartxml.length > 0) {
- var temp_bmp = gdi.CreateImage(1, 1);
- var temp_gr = temp_bmp.GetGraphics();
- var xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
- xmlDoc.async="false";
- xmlDoc.loadXML(chartxml);
- try {
- var tops = xmlDoc.getElementsByTagName(top_el)[0];
- for(i = 0; i < tops.childNodes.length; i++) {
- var top = tops.childNodes[i];
- ranks[i] = top.getAttribute("rank");
- for(j = 0; j < top.childNodes.length; j++) {
- if(top.childNodes[j].tagName == "url") urls[i] = top.childNodes[j].childNodes[0].nodeValue;
- if(top.childNodes[j].tagName == "name") names[i] = top.childNodes[j].childNodes[0].nodeValue;
- if(top.childNodes[j].tagName == "playcount") playcounts[i] = top.childNodes[j].childNodes[0].nodeValue;
- if(i > 0 && playcounts[i] == playcounts[i -1]) ranks[i] = ranks[i -1];
- if(type != 0 && top.childNodes[j].tagName == "artist") {
- artists[i] = top.childNodes[j].childNodes[0].childNodes[0].nodeValue;
- }
- }
- tt_texts[i] = ((artists.length > 0) ? artists[i] + " - " : "") + names[i];
- name_widths[i] = temp_gr.CalcTextWidth(names[i], g_font);
- }
- window.NotifyOthers("lastfmchart", [ranks, names, name_widths, tt_texts, playcounts, urls]);
- } catch (e) {
- window.NotifyOthers("lastfmchart", [[], [], [], [], [], []]);
- }
- temp_bmp.ReleaseGraphics(temp_gr);
- temp_bmp.Dispose();
- temp_gr = null;
- temp_bmp = null;
- }
- } else if (!window.GetProperty("offline")){
- lastfm("&user=" + username + "&method=user." + method + "&period=" + period, useragent, function() {save_xml_file(filename); get_lastfm_chart(method, type, period, charts_folder);});
- } else window.NotifyOthers("lastfmchart", [[], [], [], [], [], []]);
- }
- function get_recent_tracks() {
- if(username.length == 0 || api_key.length != 32) return(fb.trace("Last.fm Charts: Can't contact Last.fm. Check your username / API KEY settings."));
- var ret = "";
- recentxmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
- recentxmlhttp.open("GET", "http://ws.audioscrobbler.com/2.0/?api_key=" + api_key + "&user=" + username + "&method=user.getrecenttracks&limit=20" + "&s=" + Math.random(), true);
- recentxmlhttp.setRequestHeader('User-Agent',useragent);
- recentxmlhttp.send();
- recentxmlhttp.onreadystatechange = function() {
- if (recentxmlhttp.readyState == 4) {
- if (recentxmlhttp.status == 200) {
- recentxml = recentxmlhttp.responseText;
- var recentxmldom = new ActiveXObject("Microsoft.XMLDOM");
- recentxmldom.async="false";
- recentxmldom.loadXML(recentxml);
- try {
- tracks = recentxmldom.getElementsByTagName("name");
- artists = recentxmldom.getElementsByTagName("artist");
- for (i = 0; i < tracks.length; i++) {
- ret += zeroPad((i + 1),2) + ". " + tracks[i].childNodes[0].nodeValue + "\n";
- ret += " By " + artists[i].childNodes[0].nodeValue;
- if (i < tracks.length - 1) ret += "\n";
- }
- } catch(e) {
- ret = "User " + username + " does not have a recent track information on Last.fm.";
- }
- } else ret = "User " + username + " does not have a recent track information on Last.fm.";
- window.NotifyOthers("recenttracks", ret);
- }
- }
- }
- function get_lastfm_token(func) {
- lfmtokenxmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
- lfmtokenxmlhttp.open("GET", "http://ws.audioscrobbler.com/2.0/?api_key=" + api_key + "&method=auth.getToken" + "&s=" + Math.random(), true);
- lfmtokenxmlhttp.setRequestHeader('User-Agent',useragent);
- lfmtokenxmlhttp.send();
- lfmtokenxmlhttp.onreadystatechange = function() {
- if (lfmtokenxmlhttp.readyState == 4) {
- if (lfmtokenxmlhttp.status == 200) {
- lfmtokenxml = lfmtokenxmlhttp.responseText;
- var lfmtokenxmldom = new ActiveXObject("Microsoft.XMLDOM");
- lfmtokenxmldom.async="false";
- lfmtokenxmldom.loadXML(lfmtokenxml);
- try {
- lfm_token = lfmtokenxmldom.getElementsByTagName("token")[0].childNodes[0].nodeValue;
- token_timer && window.KillTimer(token_timer) && token_timer.Dispose();
- token_timer = window.CreateTimerTimeout(3600000);
- get_lastfm_sk(func);
- } catch (e) {
- fb.trace(lfmtokenxml);
- }
- } else {
- fb.trace(lfmtokenxmlhttp.responseText);
- fb.ShowPopupMessage("Unable to get last.fm token. Please check foobar2000 console for furthur information.");
- }
- }
- }
- }
- function get_lastfm_sk(func) {
- if (api_key.length != 32) return(fb.ShowPopupMessage("Can't contact Last.fm. Check your username / API KEY settings."));
- if (lfm_secret == "") return(fb.ShowPopupMessage("Last.fm secret missing, please reenter your last.fm secret in bio panel then try again."));
- if (lfm_token == "") {
- get_lastfm_token(func);
- return;
- }
- WshShell.Run("\"" + lfm_auth_vbs + "\" http://www.last.fm/api/auth/?api_key=" + api_key + "&token=" + lfm_token, 0, true);
- var api_sig = md5("api_key" + api_key + "methodauth.getSessiontoken" + lfm_token + lfm_secret);
- lfmskxmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
- lfmskxmlhttp.open("GET", "http://ws.audioscrobbler.com/2.0/?api_key=" + api_key + "&method=auth.getSession&token=" + lfm_token + "&api_sig=" + api_sig, true);
- lfmskxmlhttp.setRequestHeader('User-Agent',useragent);
- lfmskxmlhttp.send();
- lfmskxmlhttp.onreadystatechange = function() {
- if (lfmskxmlhttp.readyState == 4) {
- if (lfmskxmlhttp.status == 200) {
- lfmskxml = lfmskxmlhttp.responseText;
- var lfmskxmldom = new ActiveXObject("Microsoft.XMLDOM");
- lfmskxmldom.async="false";
- lfmskxmldom.loadXML(lfmskxml);
- try {
- lfm_sk = lfmskxmldom.getElementsByTagName("key")[0].childNodes[0].nodeValue;
- utils.WriteINI(inifile, "default", "session_key", lfm_sk);
- fb.trace("Last.fm authentication complete");
- func();
- } catch (e) {
- fb.trace(lfmskxml);
- }
- } else {
- fb.trace(lfmskxmlhttp.responseText);
- fb.ShowPopupMessage("Unable to get last.fm session key. Please check foobar2000 console for furthur information.");
- }
- }
- }
- }
- function alt_lastfm_loved_state(artist, track, love) {
- if (api_key.length != 32) return(fb.ShowPopupMessage("Can't contact Last.fm. Check your username / API KEY settings."));
- if (lfm_secret == "") return(fb.ShowPopupMessage("Last.fm secret missing, please reenter your last.fm secret in bio panel then try again."));
- if (lfm_sk == "") {
- get_lastfm_sk(function() {alt_lastfm_loved_state(artist, track, love)});
- return;
- }
- var method = love ? "track.love" : "track.unlove";
- var api_sig = md5("api_key" + api_key + "artist" + artist + "method" + method + "sk" + lfm_sk + "track" + track + lfm_secret);
- lfmaltlovehttp = new ActiveXObject("Microsoft.XMLHTTP");
- lfmaltlovehttp.open("POST", "http://ws.audioscrobbler.com/2.0/", true);
- lfmaltlovehttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
- lfmaltlovehttp.setRequestHeader('User-Agent',useragent);
- lfmaltlovehttp.send("api_key=" + api_key + "&method=" + method + "&api_sig=" + api_sig + "&artist=" + encodeURIComponent(artist) + "&track=" + encodeURIComponent(track) + "&sk=" + lfm_sk);
- lfmaltlovehttp.onreadystatechange = function() {
- if (lfmaltlovehttp.readyState == 4) {
- if (lfmaltlovehttp.status == 200) {
- window.NotifyOthers("lastfmlovedstate", love);
- } else {
- fb.trace(lfmaltlovehttp.responseText);
- }
- }
- }
- }
- function sc_cache_save() {
- ts = fso.OpenTextFile(sc_cache_file, 2, true, -1);
- if (playing) {
- if (!pausing) pb_time += pf.Time;
- pb_time = Math.round(pb_time / 1000);
- if (window.GetProperty("scrobble")) {
- entry = sc_cache[sc_cache.length-1];
- if (pb_time <= 5 || entry[0] == -1)
- sc_cache.pop();
- else {
- if (entry.length == 9) entry.push(pb_time);
- }
- } else sc_cache.pop();
- }
- var sc_cache_str = "";
- for (i in sc_cache) {
- entry = sc_cache[i];
- if (entry[0] != -1 && entry.length == 10) {
- sc_cache_str += entry.join(String.fromCharCode(31));
- sc_cache_str += String.fromCharCode(30);
- }
- }
- ts.Write(sc_cache_str);
- ts.Close();
- }
- function sc_cache_restore() {
- var sc_cache_str = utils.ReadTextFile(sc_cache_file, 1200);
- if (sc_cache_str) {
- var entries = sc_cache_str.split(String.fromCharCode(30));
- for (i in entries) {
- if (entries[i]) {
- entry = (entries[i]).split(String.fromCharCode(31));
- sc_cache.push(entry);
- }
- }
- /*fb.trace("SC Total " + sc_cache.length + ":")
- for (i in sc_cache) {
- fb.trace(i + ":")
- fb.trace(sc_cache[i].join("\n"));
- }*/
- if (!lfm_np_updating && !window.GetProperty("offline")) {
- lfm_np_updating = true;
- set_lfm_np(sc_cache.slice());
- }
- //lastfm_scrobble(get_sc_list());
- }
- }
- function sc_cache_add(mdb, timestamp) {
- var ID;
- if (window.GetProperty("onlymlfile")) {
- if (fb.IsMetadbInMediaLibrary(mdb))
- ID = Math.random();
- else
- ID = -1;
- } else
- ID = Math.random();
- var track = fb.TitleFormat(tf_title).EvalWithMetadb(mdb);
- var artist = fb.TitleFormat(tf_artist).EvalWithMetadb(mdb);
- var album = fb.TitleFormat("%album%").EvalWithMetadb(mdb);
- var albumArtist = fb.TitleFormat("%album artist%").EvalWithMetadb(mdb);
- var trackNumber = fb.TitleFormat("$meta(tracknumber)").EvalWithMetadb(mdb);
- var duration = Math.round(fb.PlaybackLength);
- sc_cache.push([ID, false, timestamp, album, albumArtist, artist, duration, track, trackNumber]);
- if (window.GetProperty("scrobble")) {
- sc_np_timer && window.KillTimer(sc_np_timer) && sc_np_timer.Dispose();
- sc_np_timer = window.CreateTimerTimeout(5000);
- }
- }
- function sc_cache_update(ID, album, albumArtist, artist, track) {
- for (i = 0; i < sc_cache.length; i++) {
- entry = sc_cache[i];
- if (ID == entry[0]) {
- entry[1] = true;
- if (album) entry[3] = album;
- if (albumArtist && albumArtist != entry[4]) entry[4] = albumArtist;
- if (artist) entry[5] = artist;
- if (track) entry[7] = track;
- }
- //fb.trace(entry.join("\n"))
- }
- }
- function sc_cache_remove(ID) {
- for (i = 0; i < sc_cache.length; i++) {
- entry = sc_cache[i];
- if (ID == entry[0]) sc_cache.splice(i, 1);
- }
- }
- function set_lfm_np(entries) {
- if (api_key.length != 32) return(fb.ShowPopupMessage("Can't contact Last.fm. Check your username / API KEY settings."));
- if (lfm_secret == "") return(fb.ShowPopupMessage("Last.fm secret missing, please reenter your last.fm secret in bio panel then try again."));
- if (lfm_sk == "") {
- get_lastfm_sk(function() {set_lfm_np(entries)});
- return;
- }
- if (entries.length == 0) {
- lfm_np_updating = false;
- return;
- }
- var entry = entries.shift();
- if (entry[1]) {
- set_lfm_np(entries);
- return;
- }
- //fb.trace("=======================called set_lfm_np========")
- var ID = entry[0];
- var artist = entry[5];
- var track = entry[7];
- if (track == "" || artist == "?" || track == "?" || artist == "") {
- set_lfm_np(entries);
- return(fb.trace("Track tags are incomplete, unable to set last.fm now playing."));
- }
- var album = entry[3];
- var albumArtist = entry[4];
- var duration = entry[6];
- var trackNumber = entry[8];
- var api_sig_raw = "";
- var qs = "";
- if (album != "?" && window.GetProperty("walbum")) {
- api_sig_raw += "album" + album;
- qs += "album=" + encodeURIComponent(album);
- }
- if (albumArtist != "?" && albumArtist != artist && window.GetProperty("walbumartist")) {
- api_sig_raw += "albumArtist" + albumArtist;
- qs += "&albumArtist=" + encodeURIComponent(albumArtist);
- }
- api_sig_raw += "api_key" + api_key;
- qs += "&api_key=" + api_key;
- api_sig_raw += "artist" + artist;
- qs += "&artist=" + encodeURIComponent(artist);
- if (duration != 0 && window.GetProperty("wduration")) {
- api_sig_raw += "duration" + duration;
- qs += "&duration=" + duration;
- }
- api_sig_raw += "methodtrack.updateNowPlaying" + "sk" + lfm_sk;
- qs += "&method=track.updateNowPlaying" + "&sk=" + lfm_sk;
- api_sig_raw += "track" + track;
- qs += "&track=" + encodeURIComponent(track);
- if (trackNumber != "" && window.GetProperty("wtracknumber")) {
- api_sig_raw += "trackNumber" + trackNumber;
- qs += "&trackNumber=" + trackNumber;
- }
- api_sig_raw += lfm_secret
- var api_sig = md5(api_sig_raw);
- qs += "&api_sig=" + api_sig;
- //fb.trace(qs)
- lfmsetnphttp = new ActiveXObject("Microsoft.XMLHTTP");
- lfmsetnphttp.open("POST", "http://ws.audioscrobbler.com/2.0/", true);
- lfmsetnphttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
- lfmsetnphttp.setRequestHeader('User-Agent',useragent);
- lfmsetnphttp.send(qs);
- lfmsetnphttp.onreadystatechange = function() {
- if (lfmsetnphttp.readyState == 4) {
- if (lfmsetnphttp.status == 200) {
- lfmsetnpxml = lfmsetnphttp.responseText;
- var lfmsetnpdom = new ActiveXObject("Microsoft.XMLDOM");
- lfmsetnpdom.async="false";
- lfmsetnpdom.loadXML(lfmsetnpxml);
- var t_artist = t_track = t_album = t_albumArtist = "";
- try {
- t_artist = lfmsetnpdom.getElementsByTagName("artist")[0].childNodes[0].nodeValue;
- } catch (e) {}
- try {
- t_track = lfmsetnpdom.getElementsByTagName("track")[0].childNodes[0].nodeValue;
- } catch (e) {}
- try {
- t_album = lfmsetnpdom.getElementsByTagName("album")[0].childNodes[0].nodeValue;
- } catch (e) {}
- try {
- t_albumArtist = lfmsetnpdom.getElementsByTagName("albumArtist")[0].childNodes[0].nodeValue;
- } catch (e) {}
- sc_cache_update(ID, t_album, t_albumArtist, t_artist, t_track)
- if (entries.length == 0 && fb.IsPlaying) fb.trace("Last.fm submission: Now playing... OK");
- set_lfm_np(entries);
- } else {
- fb.trace(lfmsetnphttp.responseText);
- set_lfm_np(entries);
- }
- }
- }
- }
- function get_sc_list() {
- var sc_list = [];
- var sc_batch = [];
- var discards = [];
- var c = 0;
- for (i = 0; i < sc_cache.length; i++) {
- entry = sc_cache[i];
- if (entry[1] && entry.length == 10) {
- switch (true) {
- case (entry[0] == -1):
- case (entry[6] < 30):
- case (entry[9] < 240 && entry[9] < Math.floor(entry[6] / 2)):
- case (entry[5] == "" || entry[7] == "" || entry[5] == "?" || entry[7] == "?"):
- discards.push(entry[0]);
- break;
- default:
- sc_batch.push(entry);
- c++;
- if (c == 50) {
- sc_list.push(sc_batch.slice());
- sc_batch = [];
- c = 0;
- }
- }
- }
- }
- sc_list.push(sc_batch);
- while (discards.length > 0) {
- sc_cache_remove(discards.shift());
- }
- return sc_list;
- }
- function lastfm_scrobble(sl) {
- if (api_key.length != 32) return(fb.ShowPopupMessage("Can't contact Last.fm. Check your username / API KEY settings."));
- if (lfm_secret == "") return(fb.ShowPopupMessage("Last.fm secret missing, please reenter your last.fm secret in bio panel to scrobble."));
- if (lfm_sk == "") {
- get_lastfm_sk(function() {lastfm_scrobble(sl)});
- return;
- }
- if (sl.length == 0) {
- scrobbling = false;
- return;
- }
- var entries = sl.shift();
- if (entries.length == 0) {
- lastfm_scrobble(sl);
- return;
- }
- var qs_arr = [];
- var scrobbled = [];
- var qs = "";
- var api_sig = "";
- var duration, played_t = 0;
- var album, albumArtist, artist, track, trackNumber = '';
- for (i = 0; i < entries.length; i++) {
- entry = entries[i];
- ID = entry[0];
- timestamp = entry[2];
- album = entry[3];
- albumArtist = entry[4];
- artist = entry[5];
- duration = entry[6];
- track = entry[7];
- trackNumber = entry[8];
- played_t = entry[9];
- scrobbled.push(ID);
- qs_arr.push("timestamp[" + i + "]" + timestamp);
- qs += "×tamp[" + i + "]=" + timestamp;
- if (album != "?" && window.GetProperty("walbum")) {
- qs_arr.push("album[" + i + "]" + album);
- qs += "&album[" + i + "]=" + encodeURIComponent(album);
- }
- if (albumArtist != "?" && albumArtist != artist && window.GetProperty("walbumartist")) {
- qs_arr.push("albumArtist[" + i + "]" + albumArtist);
- qs += "&albumArtist[" + i + "]=" + encodeURIComponent(albumArtist);
- }
- qs_arr.push("artist[" + i + "]" + artist);
- qs += "&artist[" + i + "]=" + encodeURIComponent(artist);
- if (duration != 0 && window.GetProperty("wduration")) {
- qs_arr.push("duration[" + i + "]" + duration);
- qs += "&duration[" + i + "]=" + duration;
- }
- qs_arr.push("track[" + i + "]" + track);
- qs += "&track[" + i + "]=" + encodeURIComponent(track);
- if (trackNumber != "" && window.GetProperty("wtracknumber")) {
- qs_arr.push("trackNumber[" + i + "]" + trackNumber);
- qs += "&trackNumber[" + i + "]=" + trackNumber;
- }
- }
- qs_arr.push("api_key" + api_key);
- qs = "api_key=" + api_key + qs;
- qs_arr.push("methodtrack.scrobble");
- qs += "&method=track.scrobble";
- qs_arr.push("sk" + lfm_sk);
- qs += "&sk=" + lfm_sk;
- qs_arr.sort();
- var api_sig = md5(qs_arr.join("") + lfm_secret);
- qs += "&api_sig=" + api_sig;
- //fb.trace(qs)
- lfmscrobblehttp = new ActiveXObject("Microsoft.XMLHTTP");
- lfmscrobblehttp.open("POST", "http://ws.audioscrobbler.com/2.0/", true);
- lfmscrobblehttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
- lfmscrobblehttp.setRequestHeader('User-Agent',useragent);
- lfmscrobblehttp.send(qs);
- lfmscrobblehttp.onreadystatechange = function() {
- if (lfmscrobblehttp.readyState == 4) {
- if (lfmscrobblehttp.status == 200) {
- fb.trace("Last.fm submission: Scrobbled " + entries.length + " track(s)... OK");
- while (scrobbled.length > 0)
- sc_cache_remove(scrobbled.shift());
- lastfm_scrobble(sl);
- } else {
- fb.trace(lfmscrobblehttp.responseText);
- lastfm_scrobble(sl);
- }
- }
- }
- }
- function get_playing_artistart(path, artist) {
- arr = [];
- arr = read_images(path);
- if (arr.length > 0) {
- arr.push(path);
- notify_artistart(arr);
- return;
- }
- if (!window.GetProperty("auto") || window.GetProperty("offline")) {
- notify_artistart([path]);
- return;
- }
- if (username.length == 0 || api_key.length != 32) return(fb.trace("Can't contact Last.fm. Check your username / API KEY settings."));
- wget = "\"" + script_path + "wget.exe\"";
- if (artist != "") {
- str = utils.ReadTextFile(path + "\\blacklist.txt");
- if (!str) blacklist = "";
- blacklist = str.split("|");
- for (i in blacklist)
- blacklist[i] = blacklist[i].split("\\").pop();
- artistxmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
- qs = "&method=artist.getimages&autocorrect=1&limit=" + limit + "&artist=" + encodeURIComponent(artist);
- artistxmlhttp.open("GET", "http://ws.audioscrobbler.com/2.0/?api_key=" + api_key + qs + "&s=" + Math.random(), true);
- artistxmlhttp.setRequestHeader('User-Agent',useragent);
- artistxmlhttp.send();
- artistxmlhttp.onreadystatechange = function() {
- if (artistxmlhttp.readyState == 4) {
- working++;
- window.NotifyOthers("gettingartistart", true);
- if (artistxmlhttp.status == 200) {
- artistxml = artistxmlhttp.responseText;
- artistxmldom = new ActiveXObject("Microsoft.XMLDOM");
- artistxmldom.async="false";
- artistxmldom.loadXML(artistxml);
- try {
- nodeList = artistxmldom.getElementsByTagName("size");
- ts = fso.OpenTextFile(path + "\\dllist.txt", 2, true, 0);
- getfiles = [];
- geturls = [];
- tails = [];
- for (i = 0; i < nodeList.length; i++) {
- if (nodeList[i].attributes != null && nodeList[i].attributes.getNamedItem("name") != null && nodeList[i].attributes.getNamedItem("name").nodeValue == artistartsize) {
- geturl = nodeList[i].childNodes[0].nodeValue;
- orifilename = geturl.split("/").pop();
- getfiles.push(orifilename);
- geturls.push(geturl.replace(orifilename, encodeURIComponent(orifilename)));
- }
- }
- for (i in blacklist) {
- tails = blacklist[i].match(/\.(\d+)\.(jpg|png|gif)$/);
- count = 0;
- for (j in getfiles) {
- if (tails) {
- delfile = blacklist[i].replace(tails[0], "." + tails[2]);
- if (delfile == getfiles[j]) {
- if (count == tails[1]) {
- geturls[j] = "";
- break;
- }
- count++;
- }
- } else {
- if (blacklist[i] == getfiles[j]) {
- geturls[j] = "";
- break;
- }
- }
- }
- }
- ts.Write(geturls.join("\n"));
- ts.close();
- var pathobj = fso.GetFolder(path);
- WshShell.Run(wget + " -q " + "-P \"" + pathobj.ShortPath + "\" -i \"" + pathobj.ShortPath + "\\dllist.txt\"", 0, true);
- fix_wget_clobber(path);
- fso.DeleteFile(path + "\\dllist.txt");
- arr = read_images(path);
- arr.push(path);
- } catch (e) { arr = [path]; }
- } else {
- arr = [path];
- }
- working--;
- if (working == 0) {
- window.NotifyOthers("gettingartistart", false);
- notify_artistart(arr);
- }
- }
- }
- } else notify_artistart([path]);
- }
- function fix_wget_clobber(path) {
- if (fso.FolderExists(path)) {
- var files = new Enumerator((fso.GetFolder(path)).Files);
- for (; !files.atEnd(); files.moveNext()) {
- fnchunks = ((files.item()).Name).match(/^(.*)\.(jpg|png|gif)\.(\d+)$/);
- if (fnchunks) {
- newname = fnchunks[1] + "." + fnchunks[3] + "." + fnchunks[2];
- fso.MoveFile((files.item()).Path, path + "\\" + newname);
- }
- }
- }
- }
- function notify_artistart(arr) {
- if (!fb.IsPlaying) return;
- artist_folder = data_folder + "\\" + fb.TitleFormat("$crc32(%artist%)").EvalWithMetadb(g_metadb);
- if (arr[arr.length - 1] != artist_folder) {
- arr = [];
- arr = read_images(artist_folder);
- arr.push(artist_folder);
- }
- window.NotifyOthers("artistart", arr);
- }
- function load() {
- if(!g_metadb) return(window.Repaint());
- startplay = false;
- if (data_folder == "/") data_folder = fb.ProfilePath + "wsh_lastfm";
- df_chunks = data_folder.match(/^\?(.*)$/);
- if (df_chunks) {
- data_folder = fb.TitleFormat(df_chunks[1]).EvalWithMetadb(g_metadb) + "\\wsh_lastfm";
- }
- if(!fso.FolderExists(data_folder)) fso.CreateFolder(data_folder);
- lastfm_artist = ret = "";
- simartist_height = 0;
- simartists_height = 0;
- simartists = [];
- simartist_urls_ori = [];
- artist_folder = data_folder + "\\" + fb.TitleFormat("$crc32(%artist%)").EvalWithMetadb(g_metadb);
- if(!fso.FolderExists(artist_folder)) fso.CreateFolder(artist_folder);
- filename = artist_folder + "\\artistinfo.xml";
- if(fso.fileExists(filename)) {
- file = fso.Getfile(filename);
- if (cache_life > 0 && (Date.parse(Date()) - Date.parse(file.DateLastModified) > cache_life)) {
- get(filename, artist);
- if (window.GetProperty("artistartcacherefresh")) {
- var arr = [];
- arr = read_images(artist_folder);
- arr.push(artist_folder);
- window.NotifyOthers("artistart", arr);
- window.NotifyOthers("refreshartistart", 1);
- }
- return;
- }
- ret = utils.ReadTextFile(filename);
- if (ret.match(/^offline/)) {
- if (!window.GetProperty("offline")) {
- get(filename, artist);
- return;
- }
- ret = "offline";
- } else {
- var xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
- xmlDoc.async="false";
- xmlDoc.loadXML(ret);
- ret = ""
- getartistart = false;
- try {
- lastfm_artist = xmlDoc.getElementsByTagName("name")[0].childNodes[0].nodeValue;
- if (lastfm_artist != artist)
- ret = "(redirected from " + artist + ")\n\n";
- } catch (e) { lastfm_artist = ""; }
- try {
- if (xmlDoc.getElementsByTagName("image")[0].childNodes[0].nodeValue != "")
- getartistart = true;
- } catch (e) { getartistart = false; }
- if (getartistart)
- get_playing_artistart(artist_folder, lastfm_artist);
- else
- notify_artistart([artist_folder]);
- if (dlartistart) return;
- try {
- bioraw = xmlDoc.getElementsByTagName("content")[0].childNodes[0].nodeValue;
- ret += decodeXML(bioraw);
- } catch(e) {
- ret += "This artist does not have a biography page on Last.fm.";
- }
- try {
- ret += "\n\nListeners: " + xmlDoc.getElementsByTagName("listeners")[0].childNodes[0].nodeValue;
- } catch (e) {}
- try {
- playcount = xmlDoc.getElementsByTagName("playcount")[0].childNodes[0].nodeValue;
- ret += "\nPlaycount: " + playcount + (playcount > 1 ? " times" : " time");
- } catch (e) {}
- try {
- similars = xmlDoc.getElementsByTagName("similar")[0];
- if (similars.childNodes.length > 1) {
- ret += "\n\nSimilar artists:\n";
- for (i = 0; i < similars.childNodes.length; i++) {
- simartist = (i+1) + ". " + similars.childNodes[i].childNodes[0].childNodes[0].nodeValue;
- ret += simartist;
- if (i < similars.childNodes.length - 1) ret += "\n";
- simartists.push(simartist);
- simartist_urls_ori[i] = similars.childNodes[i].childNodes[1].childNodes[0].nodeValue;
- }
- }
- } catch (e) {}
- try {
- lastfm_artist_url = xmlDoc.getElementsByTagName("url")[0].childNodes[0].nodeValue;
- } catch (e) { lastfm_artist_url = "http://www.last.fm/music/" + ((lastfm_artist != "") ? encodeURIComponent(lastfm_artist.replace(/\s+/g,"+")) : encodeURIComponent(artist)); }
- }
- reset();
- g_tooltip.Text = p_title = (lastfm_artist != "") ? lastfm_artist : artist;
- g_text = ret;
- window.Repaint();
- } else {
- get(filename, artist);
- }
- }
- function get(path, artist) {
- if (username.length == 0 || api_key.length != 32) return(fb.trace("Can't contact Last.fm. Check your username / API KEY settings."));
- if (!window.GetProperty("offline"))
- lastfm("&lang=" + lang + "&method=artist.getinfo&artist=" + encodeURIComponent(artist) + "&autocorrect=1", useragent, function() {save_xml_file(path); load()});
- else {
- xmlDoc = "offline";
- save_xml_file(path);
- load();
- }
- }
- function lastfm(qs, user_agent, func) {
- xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
- xmlhttp.open("GET", "http://ws.audioscrobbler.com/2.0/?api_key=" + api_key + "&user=" + username + qs + "&s=" + Math.random(), true);
- xmlhttp.setRequestHeader('User-Agent',user_agent);
- xmlhttp.send();
- xmlhttp.onreadystatechange = function() {
- if (xmlhttp.readyState == 4) {
- if (xmlhttp.status == 200) {
- xmlDoc = xmlhttp.responseText;
- func();
- } else {
- fb.trace(xmlhttp.responseText);
- func();
- }
- }
- }
- }
- function save_xml_file(path) {
- try {
- ts = fso.OpenTextFile(path, 2, true, -1);
- ts.WriteLine(xmlDoc);
- ts.close();
- } catch(e) {
- }
- }
- function calc_simartists_dim() {
- var temp_bmp = gdi.CreateImage(1, 1);
- var temp_gr = temp_bmp.GetGraphics();
- t_arr = [];
- simartist_widths = [];
- simartist_urls = [];
- for (i in simartists)
- t_arr[i] = temp_gr.CalcTextWidth(simartists[i], g_font);
- for (i = 0; i < t_arr.length; i++) {
- if (t_arr[i] >= ww-16) {
- wrapped_lines = temp_gr.EstimateLineWrap(simartists[i], g_font, ww-16).toArray();
- for (j = 1; j < wrapped_lines.length; j = j + 2) {
- simartist_widths.push(wrapped_lines[j]);
- simartist_urls.push(simartist_urls_ori[i]);
- }
- } else {
- simartist_widths.push(t_arr[i]);
- simartist_urls.push(simartist_urls_ori[i]);
- }
- }
- if (simartist_widths.length != 0) {
- simartist_height = temp_gr.CalcTextHeight(simartist_widths[0], g_font);
- simartists_height = simartist_height * simartist_widths.length;
- }
- need_calc_simartists_dim = false;
- temp_bmp.ReleaseGraphics(temp_gr);
- temp_bmp.Dispose();
- temp_gr = null;
- temp_bmp = null;
- }
- function text_input_box(title, message, section, key, value) {
- WshShell.Run("\"" + inputbox + "\" \"" + title + "\" \"" + message + "\" \"" + value + "\"", 0, true);
- var wshEnv = WshShell.Environment("Volatile");
- var input = wshEnv("WshEnv");
- if (input != "") {
- utils.WriteINI(inifile, section, key, input);
- return input;
- }
- return value;
- }
- function read_images(path) {
- var ret = [];
- if (fso.FolderExists(path)) {
- var files = new Enumerator((fso.GetFolder(path)).Files);
- for (; !files.atEnd(); files.moveNext()) {
- if (((files.item()).Name).match(/^.*\.(jpg|png|gif)$/)) {
- ret.push(path + "\\" + (files.item()).Name);
- }
- }
- }
- return ret;
- }
- function decodeXML(value) {
- value = value.replace(/<\/?[^>]+(>|$)/g, "");
- doc = new ActiveXObject("htmlfile");
- doc.open();
- div = doc.createElement("div");
- div.innerHTML = value.replace(/\n/g, "<br>");
- value = div.innerHTML;
- value = value.replace(/<BR>/g,"\n");
- value = value.replace(/>/g,">");
- value = value.replace(/</g,"<");
- value = value.replace(/ /g," ");
- return value.replace(/&/g,"&");
- }
- function zeroPad(num,count) {
- var numZeropad = num + '';
- while(numZeropad.length < count) {
- numZeropad = "0" + numZeropad;
- }
- return numZeropad;
- }
- function on_mouse_wheel(delta) {
- if (!fb.IsPlaying) return;
- applyDelta(delta * 20, defoffset);
- }
- function on_mouse_lbtn_down(x, y) {
- g_drag = true;
- g_drag_y = y;
- }
- function on_mouse_move(x,y) {
- if (!fb.IsPlaying) {
- g_tooltip.Deactivate();
- window.SetCursor(IDC_ARROW);
- return;
- }
- index = Math.floor((y - start_y - 1)/simartist_height);
- switch (true) {
- case (simartists_height > 0 && x > 6 && x < Math.min(ww-16, 6 + simartist_widths[index]) && y > start_y && y < start_y + simartists_height && y < wh-11):
- window.SetCursor(IDC_HAND);
- if (g_tooltip.Text != simartist_urls[index]) g_tooltip.Text = simartist_urls[index];
- g_tooltip.Activate();
- break;
- case (lastfm_artist_url != "" && x > 6 && x < 6 + p_title_width && y > 6 && y < 30):
- if (p_title_width >= ww - 12) {
- if (g_tooltip.Text != p_title) g_tooltip.Text = p_title;
- g_tooltip.Activate();
- } else g_tooltip.Deactivate();
- window.SetCursor(IDC_HAND);
- break;
- default:
- g_tooltip.Deactivate();
- window.SetCursor(IDC_ARROW);
- }
- if (fb.IsPlaying && g_drag) {
- applyDelta(y - g_drag_y, defoffset);
- g_drag_y = y;
- }
- }
- function on_mouse_lbtn_up(x, y) {
- g_drag = false;
- if (!fb.IsPlaying) return;
- if (lastfm_artist_url != "" && x > 6 && x < 6 + p_title_width && y > 6 && y < 30)
- WshShell.run(lastfm_artist_url);
- index = Math.floor((y - start_y - 1)/simartist_height);
- if (simartists_height > 0 && x > 6 && x < Math.min(ww-16, 6 + simartist_widths[index]) && y > start_y && y < start_y + simartists_height && y < wh-11)
- WshShell.run(simartist_urls[index]);
- }
- function on_mouse_rbtn_up(x, y) {
- var _menu = window.CreatePopupMenu();
- var _languages = window.CreatePopupMenu();
- var _lastfm = window.CreatePopupMenu();
- var _artistart = window.CreatePopupMenu();
- var _artistartsize = window.CreatePopupMenu();
- var _limit = window.CreatePopupMenu();
- var _scrobbler = window.CreatePopupMenu();
- var idx;
- _menu.AppendMenuItem(username.length > 0 && api_key.length == 32 && g_metadb && !window.GetProperty("offline") && fb.IsPlaying ? MF_STRING : MF_GRAYED, 1, "Update");
- _menu.AppendMenuItem(MF_STRING, 2, "Work offline");
- _menu.CheckMenuItem(2, window.GetProperty("offline"));
- _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
- _lastfm.AppendMenuItem(MF_STRING, 3, "Set your username");
- _lastfm.AppendMenuItem(MF_STRING, 4, "Set your API KEY");
- _lastfm.AppendMenuItem(MF_STRING, 5, "Set your secret");
- _lastfm.AppendMenuItem(MF_SEPARATOR, 0, 0);
- _lastfm.AppendMenuItem(MF_STRING, 6, "Set biography text cache life");
- _lastfm.AppendMenuItem(MF_STRING, 7, "Set data folder");
- _lastfm.AppendMenuItem(MF_SEPARATOR, 0, 0);
- _lastfm.AppendMenuItem(MF_STRING, 8, "Enable scrobbler");
- _lastfm.CheckMenuItem(8, window.GetProperty("scrobble"));
- _scrobbler.AppendMenuItem(MF_STRING, 81, "Only file in media library");
- _scrobbler.CheckMenuItem(81, window.GetProperty("onlymlfile"));
- _scrobbler.AppendMenuItem(MF_SEPARATOR, 0, 0);
- _scrobbler.AppendMenuItem(MF_GRAYED, 0, "Modification");
- _scrobbler.AppendMenuItem(MF_STRING, 82, "Artist");
- _scrobbler.AppendMenuItem(MF_STRING, 83, "Title");
- _scrobbler.AppendMenuItem(MF_SEPARATOR, 0, 0);
- _scrobbler.AppendMenuItem(MF_GRAYED, 0, "Query inclusion");
- _scrobbler.AppendMenuItem(MF_STRING, 84, "Album");
- _scrobbler.CheckMenuItem(84, window.GetProperty("walbum"));
- _scrobbler.AppendMenuItem(MF_STRING, 85, "Album Artist");
- _scrobbler.CheckMenuItem(85, window.GetProperty("walbumartist"));
- _scrobbler.AppendMenuItem(MF_STRING, 86, "Track duration");
- _scrobbler.CheckMenuItem(86, window.GetProperty("wduration"));
- _scrobbler.AppendMenuItem(MF_STRING, 87, "Track number");
- _scrobbler.CheckMenuItem(87, window.GetProperty("wtracknumber"));
- _lastfm.AppendMenuItem(window.GetProperty("scrobble") ? MF_STRING | MF_POPUP : MF_GRAYED, _scrobbler.ID, "Scrobble options");
- _menu.AppendMenuItem(MF_STRING | MF_POPUP, _lastfm.ID, "Last.fm options");
- _artistart.AppendMenuItem(MF_STRING, 1000, "Automatically download");
- _artistart.CheckMenuItem(1000, window.GetProperty("auto"));
- _artistart.AppendMenuItem(MF_STRING, 1001, "Refresh artist art with biography text cache");
- _artistart.CheckMenuItem(1001, window.GetProperty("artistartcacherefresh"));
- for (i in artistartsizes) {
- _artistartsize.AppendMenuItem(MF_STRING, 400 + parseInt(i), artistartsizes[i]);
- }
- _artistartsize.CheckMenuRadioItem(400, 405, window.GetProperty("artistartsize", 100));
- _artistart.AppendMenuItem(MF_STRING | MF_POPUP, _artistartsize.ID, "Size");
- _limit.AppendMenuItem(MF_STRING, 301, "1");
- _limit.AppendMenuItem(MF_STRING, 303, "3");
- _limit.AppendMenuItem(MF_STRING, 305, "5");
- _limit.AppendMenuItem(MF_STRING, 310, "10");
- _limit.AppendMenuItem(MF_STRING, 320, "20");
- _limit.CheckMenuRadioItem(301, 320, window.GetProperty("limit"));
- _artistart.AppendMenuItem(MF_STRING | MF_POPUP, _limit.ID, "Limit");
- _artistart.AppendMenuItem(MF_SEPARATOR, 0, 0)
- _artistart.AppendMenuItem(MF_STRING, 1002, "Wget settings")
- _menu.AppendMenuItem(MF_STRING | MF_POPUP, _artistart.ID, "Artist art options");
- for(i in languages) {
- _languages.AppendMenuItem(MF_STRING, 100 + parseInt(i), languages[i]);
- }
- _languages.CheckMenuRadioItem(100, 111, window.GetProperty("language",100));
- _menu.AppendMenuItem(MF_STRING | MF_POPUP, _languages.ID, "Language");
- if(utils.IsKeyPressed(0x10)) {
- _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
- _menu.AppendMenuItem(MF_STRING, 10, "Configure...");
- }
- idx = _menu.TrackPopupMenu(x, y);
- switch(idx) {
- case 100:
- case 101:
- case 102:
- case 103:
- case 104:
- case 105:
- case 106:
- case 107:
- case 108:
- case 109:
- case 110:
- case 111:
- window.SetProperty("language", idx);
- lang = langs[window.GetProperty("language",100) - 100];
- if (!fb.IsPlaying) return;
- get(filename, artist);
- break;
- case 1:
- get(filename, artist);
- break;
- case 2:
- window.SetProperty("offline", !window.GetProperty("offline"));
- if (!window.GetProperty("offline")) {
- fb.IsPlaying && load();
- if (!lfm_np_updating && window.GetProperty("scrobble")) {
- lfm_np_updating = true;
- set_lfm_np(sc_cache.slice());
- }
- }
- break;
- case 3:
- username = text_input_box("Simple Biography", "Please enter your Last.fm username", "default", "username", username);
- if (username != "" && api_key != "") {
- fb.IsPlaying && load();
- window.NotifyOthers("lastfm_account", 1);
- }
- break;
- case 4:
- api_key = text_input_box("Simple Biography", "Please enter your Last.fm API KEY\n\nhttp://www.last.fm/api/account", "default", "api_key", api_key);
- if (username != "" && api_key != "") {
- fb.IsPlaying && load();
- window.NotifyOthers("lastfm_account", 1);
- }
- break;
- case 5:
- lfm_secret = text_input_box("Simple Biography", "Please enter your Last.fm secret\n\nhttp://www.last.fm/api/account", "default", "secret", lfm_secret);
- break;
- case 6:
- cache_life = text_input_box("Simple Biography", "Please enter your Last.fm artist biography text cache life (in days).\n\nUse 0 to disable", "default", "cache_life", cache_life / 86400000) * 86400000;
- break;
- case 7:
- data_folder = text_input_box("Simple Biography", "Please enter your Last.fm cache data folder.\nTo use titleformatting please prefix your string with '?'.\n\nBy default Last.fm cache data is stored in wsh_lastfm folder inside foobar profile directory (enter / to use default).", "default", "data_folder", utils.ReadINI(inifile, "default", "data_folder", "/"));
- if (data_folder == "/") data_folder = fb.ProfilePath + "wsh_lastfm";
- break;
- case 8:
- window.SetProperty("scrobble", !window.GetProperty("scrobble"));
- if (!lfm_np_updating && window.GetProperty("scrobble") && !window.GetProperty("offline")) {
- lfm_np_updating = true;
- set_lfm_np(sc_cache.slice());
- }
- break;
- case 81:
- window.SetProperty("onlymlfile", !window.GetProperty("onlymlfile"))
- break;
- case 82:
- tf_artist = text_input_box("Simple Biography", "Enter titleformatting string to get track title.\n\nDefault is %artist% (enter blank string to use default)", "scrobbler", "tf_artist", tf_artist);
- break;
- case 83:
- tf_title = text_input_box("Simple Biography", "Enter titleformatting string to get artist title.\n\nDefault is $meta(title) (enter blank string to use default)", "scrobbler", "tf_title", tf_title);
- break;
- case 84:
- window.SetProperty("walbum", !window.GetProperty("walbum"));
- break;
- case 85:
- window.SetProperty("walbumartist", !window.GetProperty("walbumartist"));
- break;
- case 86:
- window.SetProperty("wduration", !window.GetProperty("wduration"));
- break;
- case 87:
- window.SetProperty("wtracknumber", !window.GetProperty("wtracknumber"));
- break;
- case 10:
- window.ShowConfigure();
- break;
- case 301:
- case 303:
- case 305:
- case 310:
- case 320:
- window.SetProperty("limit", idx);
- limit = idx - 300;
- fb.IsPlaying && window.NotifyOthers("refreshartistart", 1);
- break;
- case 400:
- case 401:
- case 402:
- case 403:
- case 404:
- case 405:
- window.SetProperty("artistartsize", idx);
- artistartsize = artistartsizetext[window.GetProperty("artistartsize", 400) - 400];
- fb.IsPlaying && window.NotifyOthers("refreshartistart", 1);
- break;
- case 1000:
- window.SetProperty("auto", !window.GetProperty("auto"));
- fb.IsPlaying && window.NotifyOthers("refreshartistart", 1);
- break;
- case 1001:
- window.SetProperty("artistartcacherefresh", !window.GetProperty("artistartcacherefresh"));
- break;
- case 1002:
- WshShell.run("notepad.exe " + proxy_file, 1, true);
- fb.IsPlaying && window.NotifyOthers("refreshartistart", 1);
- break;
- }
- _scrobbler.Dispose();
- _languages.Dispose();
- _limit.Dispose();
- _lastfm.Dispose();
- _artistartsize.Dispose();
- _artistart.Dispose();
- _menu.Dispose();
- return true;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement