Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- ========================================
- + foo_silk-lastfm 1.2 (2010-11-05)
- + http://code.google.com/p/foobar-silk/
- + (C) 2010 by Matthijs Brobbel
- ========================================
- */
- // ==PREPROCESSOR==
- // @name "foo_silk-lastfm"
- // @version "1.2"
- // @author "Matthijs Brobbel"
- // @import "%fb2k_profile_path%\foo_silk\scripts\foo_silk.js"
- // @import "%fb2k_profile_path%\foo_silk\scripts\foo_silk-lastfm.js"
- // ==/PREPROCESSOR==
- // +Options
- // =====================================
- // Number of periods to be shown for top artist data [Options: 0-5] [Default: 3]
- var ta_periods = 2;
- // Number of top artists to be shown [Options: 1-50] [Default: 20]
- var ta_limit = 20;
- // Periods to show [Options: overall, 12month, 6month, 3month, 7day]
- var ta_period = ["7day", "1month", "overall", "12month", "6month"];
- // +End of Options
- // =====================================
- var name = "lastfm";
- var version = "1.2";
- var wait = 1;
- var lastfm_status =0;
- var username_file = settings_path + "username";
- var api_key_file = settings_path + "api_key";
- var username = read(username_file);
- var api_key = read(api_key_file);
- var img_lastfm_logo_red = gdi.Image(images_path + "lastfm_logo_grey.png");
- var img_lastfm_flip = gdi.Image(images_path + "scrobbleflip.png");
- var lastfm_data = new Array();
- var lastfm_xmlhttp = new Array();
- var lastfm_xmlDoc = new Array();
- var ta_offset = [0,0,0,0,0];
- var m_tac = 0;
- var scroll = window.GetProperty("scroll",1);
- var mini = window.GetProperty("mini", 0);
- var np = [fb.TitleFormat("%artist%").Eval(force=true), fb.TitleFormat("%album%").Eval(force=true), fb.TitleFormat("%title%").Eval(force=true)]
- if(window.GetProperty("avatar",0) == 0){
- var img_avatar = gdi.Image(images_path + "default_avatar.png");
- } else {
- var img_avatar = gdi.Image(images_path + "avatar.png");
- }
- reset_lastfm_data();
- if(fb.IsPlaying && window.GetProperty("mini") == 0){on_playback_new_track();}
- function on_size(){
- window.MaxHeight = window.GetProperty("mini") == 0 ? 350 : 20;
- ww = window.Width;
- wh = window.Height;
- }
- function on_notify_data(name, data) {
- if(name == "username_api" && data == 1) {
- username = read(username_file);
- api_key = read(api_key_file);
- on_playback_new_track();
- }
- }
- function on_playback_new_track() {
- if(window.GetProperty("mini") == 0) {
- np = [fb.TitleFormat("%artist%").Eval(force=true), fb.TitleFormat("%album%").Eval(force=true), fb.TitleFormat("%title%").Eval(force=true)]
- lastfm_status = 0;
- wait = 1;
- get_lastfm_data();
- } else {
- window.Repaint();
- }
- }
- function on_paint(fs){
- if(window.GetProperty("mini") == 0) {
- if(username.length == 0 || api_key.length != 32) {
- fs.GdiDrawText("foo_silk-lastfm 1.2", fnt_foo, clr_txt, 0, 0, ww, wh, DT_CENTER | DT_VCENTER | DT_CALCRECT | DT_NOPREFIX);
- return;
- }
- if(wait==0){
- fs.FillSolidRect(0, 0, ww, wh, clr_bckgrnd);
- fs.DrawImage(img_lastfm_logo_red, 5, 5, 100, 30, 0, 0, 900, 269);
- fs.DrawImage(img_avatar, 5, 60, 126, 126, 0, 0, 126, 126);
- fs.DrawRect(5, 60, 126, 126, 2.0, clr_txt_hl);
- fs.GdiDrawText(username, fnt_big, clr_txt_hl, 5, 35, ww, wh);
- fs.GdiDrawText("Now Playing", fnt_big, clr_txt_hl, s_tar, s_tat + (ta_limit * (fnt_df.height-3)) + 10, ww, wh);
- fs.GdiDrawText("Listeners on Last.fm", fnt_plays, clr_txt_hl, s_tar + 270, s_tat + (ta_limit * (fnt_df.height-3)) + 15, ww, wh);
- fs.GdiDrawText("Plays on Last.fm by " + username, fnt_plays, clr_txt_hl, s_tar + 410, s_tat + (ta_limit * (fnt_df.height-3)) + 15, ww, wh);
- fs.GdiDrawText("Artist:", fnt_np, clr_txt_hl, s_tar, s_tat + (ta_limit * (fnt_df.height-3)) + 10 + fnt_big.height, ww, wh);
- fs.GdiDrawText("Album:", fnt_np, clr_txt_hl, s_tar, s_tat + (ta_limit * (fnt_df.height-3)) + 10 + fnt_big.height + fnt_np.height, ww, wh);
- fs.GdiDrawText("Track:", fnt_np, clr_txt_hl, s_tar, s_tat + (ta_limit * (fnt_df.height-3)) + 10 + fnt_big.height + 2*fnt_np.height, ww, wh);
- for(i=0; i < 3; i++){
- fs.GdiDrawText(np[i], fnt_df, clr_txt, s_tar + 50, s_tat + (ta_limit * (fnt_df.height-3)) + fnt_big.height + 11 + (i*(fnt_np.height)), 200, wh, DT_NOPREFIX | DT_END_ELLIPSIS);
- }
- for(id=1; id <= 3; id++){
- for(y=0; y< lastfm_data[id][2].length; y++){
- fs.DrawImage(img_lastfm_flip, (y*10.7) + s_tar + 270, s_tat + (ta_limit * (fnt_df.height-3)) + 10 + fnt_big.height + ((id-1)*15), img_lastfm_flip.width, img_lastfm_flip.height, 0, 0, img_lastfm_flip.width, img_lastfm_flip.height);
- fs.GdiDrawText(lastfm_data[id][2].substring((y),y+1), fnt_df, clr_dark, (6.1*y) + s_tar + 271.7, s_tat + (ta_limit * (fnt_df.height-3)) + 9 + fnt_big.height + ((id-1)*15), ww, wh);
- }
- }
- for(id=1; id <= 3; id++){
- for(n=0; n <= 1; n++){
- for(y=0; y< lastfm_data[id][n].length; y++){
- fs.DrawImage(img_lastfm_flip, (y*10.7) + s_tar + 410 + (n*140), s_tat + (ta_limit * (fnt_df.height-3)) + 10 + fnt_big.height + ((id-1)*15), img_lastfm_flip.width, img_lastfm_flip.height, 0, 0, img_lastfm_flip.width, img_lastfm_flip.height);
- fs.GdiDrawText(lastfm_data[id][n].substring((y),y+1), fnt_df, clr_dark, (6.1*y) + s_tar + 411.7 + (n*140) , s_tat + (ta_limit * (fnt_df.height-3)) + 9 + fnt_big.height + ((id-1)*15), ww, wh);
- }
- }
- }
- if(ta_periods != 0){
- for(i=0; i < ta_periods; i++){
- txt_ta = ta_period[i];
- switch(txt_ta) {
- case "overall": txt_ta = "Overall"; break;
- case "12month": txt_ta = "12 Months"; break;
- case "6month": txt_ta = "6 Months"; break;
- case "3month": txt_ta = "3 Months"; break;
- case "1month": txt_ta = "Monthly"; break;
- case "7day": txt_ta = " 7 Days"; break;
- }
- fs.GdiDrawText(txt_ta + " Top Artists", fnt_plays, clr_txt_hl, s_tar + i*s_tap, s_tat-fnt_plays.height, ww, wh);
- }
- for(id=4; id <= 4 + ta_periods; id++){
- var max = lastfm_data[id][0][0];
- for(y=ta_offset[id-4]; y < ta_limit + ta_offset[id-4]; y++){
- x = y - ta_offset[id-4];
- if(lastfm_data[id][0][y] != 0){
- fs.GdiDrawText(y+1, fnt_df, clr_txt, s_tar + (id-4) * s_tap, s_tat + x * (fnt_df.height-3), fnt_df.height-2, wh, DT_RIGHT);
- fs.GdiDrawText(lastfm_data[id][1][y], fnt_df, clr_txt, s_tan + (id-4) * s_tap, s_tat + x * (fnt_df.height-3), s_tab - s_tan, fnt_df.height, DT_NOPREFIX | DT_END_ELLIPSIS);
- fs.FillGradRect(s_tab + (id-4)*s_tap, s_tat + 1 + x * (fnt_df.height-3), (lastfm_data[id][0][y]/max) * ((s_tar+s_tap) - s_tab - 15) + 10, fnt_df.height-3 - 0.1, s_tap, RGB(217,217,217), RGB(227,222,222));
- fs.GdiDrawText(addCommas(lastfm_data[id][0][y]), fnt_plays, clr_white, 1 + s_tab + (id-4) * s_tap, s_tat + x * (fnt_df.height-3), ww, wh);
- }
- }
- }
- }
- } else {
- if(fb.IsPlaying){
- fs.GdiDrawText("Grabbing last.fm stats. Hold on!", fnt_foo, clr_txt, 0, 0, ww, wh, DT_CENTER | DT_VCENTER | DT_CALCRECT | DT_NOPREFIX);}
- else {
- fs.GdiDrawText("foo_silk-lastfm 1.2", fnt_foo, clr_txt, 0, 0, ww, wh, DT_CENTER | DT_VCENTER | DT_CALCRECT | DT_NOPREFIX);
- }
- return;
- }
- }
- }
- function on_mouse_move(x, y) {
- if(x > s_tar && x < (s_tar + s_tap)) m_tac = 0;
- else if(x > (s_tar + s_tap) && x < (s_tar + (2*s_tap))) m_tac = 1;
- else if(x > (s_tar + (2*s_tap)) && x < (s_tar + (3*s_tap))) m_tac = 2;
- else if(x > (s_tar + (3*s_tap)) && x < (s_tar + (4*s_tap))) m_tac = 3;
- else if(x > (s_tar + (4*s_tap)) && x < (s_tar + (5*s_tap))) m_tac = 4;
- else if(x > (s_tar + (5*s_tap)) && x < (s_tar + (6*s_tap))) m_tac = 5;
- else m_tac = null;
- }
- function on_mouse_wheel(delta){
- if(window.GetProperty("scroll") == 1){
- if(m_tac != null){
- if(delta > 0){
- calc_ta_offset("up", m_tac);
- } else {
- calc_ta_offset("down", m_tac);
- }
- window.Repaint();
- }
- }
- }
- function calc_ta_offset(du, i) {
- if(du == "down"){
- if(ta_offset[i] < (50-ta_limit)) {
- ta_offset[i]++;
- }
- }
- if(du == "up"){
- if(ta_offset[i] > 0) {
- ta_offset[i]--;
- }
- }
- window.Repaint();
- }
- function on_mouse_rbtn_up(x, y) {
- var _menu = window.CreatePopupMenu();
- var _avatar = window.CreatePopupMenu();
- var idx;
- if(window.GetProperty("mini") == 0) {
- _menu.AppendMenuItem(username.length > 0 && api_key.length == 32 ? MF_STRING : MF_GRAYED, 1, "Update Last.fm Data");
- _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
- _menu.AppendMenuItem(window.GetProperty("scroll")==1 ? MF_CHECKED : MF_UNCHECKED, 5, "Scrolling trough Charts");
- _menu.AppendMenuItem(username.length > 0 && api_key.length == 32 ? MF_STRING | MF_POPUP : MF_GRAYED | MF_POPUP, _avatar.ID, "Avatar");
- _avatar.AppendMenuItem(MF_STRING, 20, "Download Avatar");
- _avatar.AppendMenuItem(MF_STRING, 21, "Restore Default Avatar");
- _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
- _menu.AppendMenuItem(MF_STRING, 11, "Check for Updates...");
- _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
- //_menu.AppendMenuItem(MF_STRING, 9, "Properties");
- _menu.AppendMenuItem(MF_STRING, 12, "Minimize");
- _menu.AppendMenuItem(MF_STRING, 10, "Configure...");
- } else {
- _menu.AppendMenuItem(MF_STRING, 12, "Maximize");
- }
- idx = _menu.TrackPopupMenu(x, y);
- switch(idx) {
- case 1:
- lastfm_status = 0;
- wait = 1;
- window.Repaint();
- on_playback_new_track();
- break;
- case 5:
- window.GetProperty("scroll")==1 ? window.SetProperty("scroll",0) : window.SetProperty("scroll",1);
- break;
- case 20:
- img_avatar.Dispose();
- img_avatar = gdi.Image(images_path + "default_avatar.png")
- window.Repaint();
- window.SetProperty("avatar",1);
- WshShell.Run("\"" + script_path + "url2disk.exe\"" + " -i "+ lastfm_data[0][5] + " -o " + "\"" + images_path + "\avatar.png\"", 0, true);
- img_avatar = gdi.Image(images_path + "avatar.png");
- window.Repaint();
- break;
- case 21:
- window.SetProperty("avatar",0);
- img_avatar.Dispose();
- img_avatar = gdi.Image(images_path + "default_avatar.png");
- window.Repaint();
- break;
- case 9:
- window.ShowProperties();
- break;
- case 10:
- window.ShowConfigure();
- break;
- case 11:
- check_for_updates(name, version);
- break;
- case 12:
- window.GetProperty("mini") == 0 ? window.SetProperty("mini", 1) : window.SetProperty("mini", 0);
- var mini = window.GetProperty("mini");
- on_size();
- on_playback_new_track();
- break;
- }
- _menu.Dispose();
- _avatar.Dispose();
- return true;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement