Advertisement
Guest User

formatting fixed

a guest
Dec 9th, 2016
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.25 KB | None | 0 0
  1. /*
  2.  
  3. ========================================
  4. + foo_silk-lastfm 1.2 (2010-11-05)
  5. + http://code.google.com/p/foobar-silk/
  6. + (C) 2010 by Matthijs Brobbel
  7. ========================================
  8.  
  9. */
  10.  
  11. // ==PREPROCESSOR==
  12. // @name "foo_silk-lastfm"
  13. // @version "1.2"
  14. // @author "Matthijs Brobbel"
  15. // @import "%fb2k_profile_path%\foo_silk\scripts\foo_silk.js"
  16. // @import "%fb2k_profile_path%\foo_silk\scripts\foo_silk-lastfm.js"
  17. // ==/PREPROCESSOR==
  18.  
  19. // +Options
  20. // =====================================
  21. // Number of periods to be shown for top artist data [Options: 0-5] [Default: 3]
  22. var ta_periods = 2;
  23. // Number of top artists to be shown [Options: 1-50] [Default: 20]
  24. var ta_limit = 20;
  25. // Periods to show [Options: overall, 12month, 6month, 3month, 7day]
  26. var ta_period = ["7day", "1month", "overall", "12month", "6month"];
  27. // +End of Options
  28. // =====================================
  29.  
  30. var name = "lastfm";
  31. var version = "1.2";
  32.  
  33. var wait = 1;
  34. var lastfm_status =0;
  35. var username_file = settings_path + "username";
  36. var api_key_file = settings_path + "api_key";
  37. var username = read(username_file);
  38. var api_key = read(api_key_file);
  39. var img_lastfm_logo_red = gdi.Image(images_path + "lastfm_logo_grey.png");
  40. var img_lastfm_flip = gdi.Image(images_path + "scrobbleflip.png");
  41. var lastfm_data = new Array();
  42. var lastfm_xmlhttp = new Array();
  43. var lastfm_xmlDoc = new Array();
  44. var ta_offset = [0,0,0,0,0];
  45. var m_tac = 0;
  46. var scroll = window.GetProperty("scroll",1);
  47. var mini = window.GetProperty("mini", 0);
  48. var np = [fb.TitleFormat("%artist%").Eval(force=true), fb.TitleFormat("%album%").Eval(force=true), fb.TitleFormat("%title%").Eval(force=true)]
  49. if(window.GetProperty("avatar",0) == 0){
  50. var img_avatar = gdi.Image(images_path + "default_avatar.png");
  51. } else {
  52. var img_avatar = gdi.Image(images_path + "avatar.png");
  53. }
  54.  
  55. reset_lastfm_data();
  56. if(fb.IsPlaying && window.GetProperty("mini") == 0){on_playback_new_track();}
  57.  
  58. function on_size(){
  59. window.MaxHeight = window.GetProperty("mini") == 0 ? 350 : 20;
  60. ww = window.Width;
  61. wh = window.Height;
  62. }
  63.  
  64. function on_notify_data(name, data) {
  65. if(name == "username_api" && data == 1) {
  66. username = read(username_file);
  67. api_key = read(api_key_file);
  68. on_playback_new_track();
  69. }
  70. }
  71.  
  72. function on_playback_new_track() {
  73. if(window.GetProperty("mini") == 0) {
  74. np = [fb.TitleFormat("%artist%").Eval(force=true), fb.TitleFormat("%album%").Eval(force=true), fb.TitleFormat("%title%").Eval(force=true)]
  75. lastfm_status = 0;
  76. wait = 1;
  77. get_lastfm_data();
  78. } else {
  79. window.Repaint();
  80. }
  81. }
  82.  
  83. function on_paint(fs){
  84. if(window.GetProperty("mini") == 0) {
  85. if(username.length == 0 || api_key.length != 32) {
  86. fs.GdiDrawText("foo_silk-lastfm 1.2", fnt_foo, clr_txt, 0, 0, ww, wh, DT_CENTER | DT_VCENTER | DT_CALCRECT | DT_NOPREFIX);
  87. return;
  88. }
  89. if(wait==0){
  90. fs.FillSolidRect(0, 0, ww, wh, clr_bckgrnd);
  91. fs.DrawImage(img_lastfm_logo_red, 5, 5, 100, 30, 0, 0, 900, 269);
  92. fs.DrawImage(img_avatar, 5, 60, 126, 126, 0, 0, 126, 126);
  93. fs.DrawRect(5, 60, 126, 126, 2.0, clr_txt_hl);
  94. fs.GdiDrawText(username, fnt_big, clr_txt_hl, 5, 35, ww, wh);
  95. fs.GdiDrawText("Now Playing", fnt_big, clr_txt_hl, s_tar, s_tat + (ta_limit * (fnt_df.height-3)) + 10, ww, wh);
  96. 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);
  97. 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);
  98. fs.GdiDrawText("Artist:", fnt_np, clr_txt_hl, s_tar, s_tat + (ta_limit * (fnt_df.height-3)) + 10 + fnt_big.height, ww, wh);
  99. 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);
  100. 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);
  101. for(i=0; i < 3; i++){
  102. 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);
  103. }
  104. for(id=1; id <= 3; id++){
  105. for(y=0; y< lastfm_data[id][2].length; y++){
  106. 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);
  107. 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);
  108. }
  109. }
  110. for(id=1; id <= 3; id++){
  111. for(n=0; n <= 1; n++){
  112. for(y=0; y< lastfm_data[id][n].length; y++){
  113. 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);
  114. 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);
  115. }
  116. }
  117. }
  118.  
  119. if(ta_periods != 0){
  120. for(i=0; i < ta_periods; i++){
  121. txt_ta = ta_period[i];
  122. switch(txt_ta) {
  123. case "overall": txt_ta = "Overall"; break;
  124. case "12month": txt_ta = "12 Months"; break;
  125. case "6month": txt_ta = "6 Months"; break;
  126. case "3month": txt_ta = "3 Months"; break;
  127. case "1month": txt_ta = "Monthly"; break;
  128. case "7day": txt_ta = " 7 Days"; break;
  129. }
  130. fs.GdiDrawText(txt_ta + " Top Artists", fnt_plays, clr_txt_hl, s_tar + i*s_tap, s_tat-fnt_plays.height, ww, wh);
  131. }
  132. for(id=4; id <= 4 + ta_periods; id++){
  133. var max = lastfm_data[id][0][0];
  134. for(y=ta_offset[id-4]; y < ta_limit + ta_offset[id-4]; y++){
  135. x = y - ta_offset[id-4];
  136. if(lastfm_data[id][0][y] != 0){
  137. 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);
  138. 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);
  139. 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));
  140. 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);
  141. }
  142. }
  143. }
  144. }
  145. } else {
  146. if(fb.IsPlaying){
  147. fs.GdiDrawText("Grabbing last.fm stats. Hold on!", fnt_foo, clr_txt, 0, 0, ww, wh, DT_CENTER | DT_VCENTER | DT_CALCRECT | DT_NOPREFIX);}
  148. else {
  149. fs.GdiDrawText("foo_silk-lastfm 1.2", fnt_foo, clr_txt, 0, 0, ww, wh, DT_CENTER | DT_VCENTER | DT_CALCRECT | DT_NOPREFIX);
  150. }
  151. return;
  152. }
  153. }
  154. }
  155.  
  156. function on_mouse_move(x, y) {
  157. if(x > s_tar && x < (s_tar + s_tap)) m_tac = 0;
  158. else if(x > (s_tar + s_tap) && x < (s_tar + (2*s_tap))) m_tac = 1;
  159. else if(x > (s_tar + (2*s_tap)) && x < (s_tar + (3*s_tap))) m_tac = 2;
  160. else if(x > (s_tar + (3*s_tap)) && x < (s_tar + (4*s_tap))) m_tac = 3;
  161. else if(x > (s_tar + (4*s_tap)) && x < (s_tar + (5*s_tap))) m_tac = 4;
  162. else if(x > (s_tar + (5*s_tap)) && x < (s_tar + (6*s_tap))) m_tac = 5;
  163. else m_tac = null;
  164. }
  165.  
  166. function on_mouse_wheel(delta){
  167. if(window.GetProperty("scroll") == 1){
  168. if(m_tac != null){
  169. if(delta > 0){
  170. calc_ta_offset("up", m_tac);
  171. } else {
  172. calc_ta_offset("down", m_tac);
  173. }
  174. window.Repaint();
  175. }
  176. }
  177. }
  178. function calc_ta_offset(du, i) {
  179. if(du == "down"){
  180. if(ta_offset[i] < (50-ta_limit)) {
  181. ta_offset[i]++;
  182. }
  183. }
  184. if(du == "up"){
  185. if(ta_offset[i] > 0) {
  186. ta_offset[i]--;
  187. }
  188. }
  189. window.Repaint();
  190. }
  191.  
  192. function on_mouse_rbtn_up(x, y) {
  193. var _menu = window.CreatePopupMenu();
  194. var _avatar = window.CreatePopupMenu();
  195. var idx;
  196. if(window.GetProperty("mini") == 0) {
  197. _menu.AppendMenuItem(username.length > 0 && api_key.length == 32 ? MF_STRING : MF_GRAYED, 1, "Update Last.fm Data");
  198. _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
  199. _menu.AppendMenuItem(window.GetProperty("scroll")==1 ? MF_CHECKED : MF_UNCHECKED, 5, "Scrolling trough Charts");
  200. _menu.AppendMenuItem(username.length > 0 && api_key.length == 32 ? MF_STRING | MF_POPUP : MF_GRAYED | MF_POPUP, _avatar.ID, "Avatar");
  201. _avatar.AppendMenuItem(MF_STRING, 20, "Download Avatar");
  202. _avatar.AppendMenuItem(MF_STRING, 21, "Restore Default Avatar");
  203. _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
  204. _menu.AppendMenuItem(MF_STRING, 11, "Check for Updates...");
  205. _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
  206. //_menu.AppendMenuItem(MF_STRING, 9, "Properties");
  207. _menu.AppendMenuItem(MF_STRING, 12, "Minimize");
  208. _menu.AppendMenuItem(MF_STRING, 10, "Configure...");
  209. } else {
  210. _menu.AppendMenuItem(MF_STRING, 12, "Maximize");
  211. }
  212. idx = _menu.TrackPopupMenu(x, y);
  213. switch(idx) {
  214. case 1:
  215. lastfm_status = 0;
  216. wait = 1;
  217. window.Repaint();
  218. on_playback_new_track();
  219. break;
  220. case 5:
  221. window.GetProperty("scroll")==1 ? window.SetProperty("scroll",0) : window.SetProperty("scroll",1);
  222. break;
  223. case 20:
  224. img_avatar.Dispose();
  225. img_avatar = gdi.Image(images_path + "default_avatar.png")
  226. window.Repaint();
  227. window.SetProperty("avatar",1);
  228. WshShell.Run("\"" + script_path + "url2disk.exe\"" + " -i "+ lastfm_data[0][5] + " -o " + "\"" + images_path + "\avatar.png\"", 0, true);
  229. img_avatar = gdi.Image(images_path + "avatar.png");
  230. window.Repaint();
  231. break;
  232. case 21:
  233. window.SetProperty("avatar",0);
  234. img_avatar.Dispose();
  235. img_avatar = gdi.Image(images_path + "default_avatar.png");
  236. window.Repaint();
  237. break;
  238. case 9:
  239. window.ShowProperties();
  240. break;
  241. case 10:
  242. window.ShowConfigure();
  243. break;
  244. case 11:
  245. check_for_updates(name, version);
  246. break;
  247. case 12:
  248. window.GetProperty("mini") == 0 ? window.SetProperty("mini", 1) : window.SetProperty("mini", 0);
  249. var mini = window.GetProperty("mini");
  250. on_size();
  251. on_playback_new_track();
  252. break;
  253. }
  254. _menu.Dispose();
  255. _avatar.Dispose();
  256. return true;
  257. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement