Advertisement
Guest User

Untitled

a guest
Jan 31st, 2011
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==PREPROCESSOR==
  2. // @import "%fb2k_profile_path%marc2003\common.js"
  3. // @name "Now Playing"
  4. // @author "marc2003"
  5. // ==/PREPROCESSOR==
  6.  
  7. var stopped_text = "foobar2000";
  8. var title_tf =  fb.TitleFormat("%title%");
  9. var album_tf = fb.TitleFormat("[%album%]");
  10. var artist_tf = fb.TitleFormat("%artist%");
  11. var title_font = gdi.Font("Segoe UI", 30, 1);
  12. var album_font = gdi.Font("Segoe UI", 22, 1);
  13. var artist_font = gdi.Font("Segoe UI", 22, 1);
  14. var title_colour = RGB(240, 240, 240);
  15. var album_colour = RGB(210, 210, 210);
  16. var artist_colour = RGB(180, 180, 180);
  17. var blacklist_file = '';
  18. var title = '';
  19. var artist = '';
  20. var album = '';
  21.  
  22. var album_img = null;
  23. var artist_img = null;
  24. var arr = new Array();
  25. var g_valid_tid = 0;
  26.  
  27. window.GetProperty("bl", true);
  28. window.GetProperty("auto", true);
  29. var cycle = window.GetProperty("cycle", 200) - 200;
  30. var limit = window.GetProperty("limit", 305) - 300;
  31. var album_img_size = window.GetProperty("album_img_size", 510) - 400;
  32.  
  33. if(fb.IsPlaying) on_playback_new_track();
  34.  
  35. function on_playback_time(time) {
  36.     if(cycle > 0 && arr.length > 1 && (time % cycle == 0)) on_mouse_wheel(-1);
  37.     window.RepaintRect(0, wh - 130, ww, 110);
  38. }
  39.  
  40. function on_playback_stop(reason) {
  41.     album_img && album_img.Dispose();
  42.     artist_img && artist_img.Dispose();
  43.     g_metadb = album_img = artist_img = arr = null;
  44.     if(reason != 2) window.Repaint();
  45. }
  46.  
  47. function  on_playback_new_track() {
  48.     g_metadb = fb.GetNowPlaying();
  49.     artist = artist_tf.EvalWithMetadb(g_metadb);
  50.     title = title_tf.EvalWithMetadb(g_metadb);
  51.     album = album_tf.EvalWithMetadb(g_metadb);
  52.     album_img && album_img.Dispose();
  53.     album_img = utils.GetAlbumArtEmbedded(g_metadb.rawpath, 0);
  54.     if(!album_img) utils.GetAlbumArtAsync(window.ID, g_metadb, 0);
  55.     folder = data_folder + fb.TitleFormat("$crc32(%artist%)").EvalWithMetadb(g_metadb);
  56.     bl();
  57.     arr = read_images();
  58.     if(arr.length == 0 && window.GetProperty("auto")) {
  59.         download_images();
  60.     } else {
  61.         index = Math.floor(Math.random()*arr.length);
  62.         load_image();
  63.     }
  64. }
  65.  
  66. function on_mouse_wheel(delta) {
  67.     if(!g_metadb || arr.length < 2) return;
  68.     index += -delta;
  69.     if(index < 0) index = arr.length - 1;
  70.     if(index >= arr.length) index = 0;
  71.     load_image();
  72. }
  73.  
  74. function load_image() {
  75.     artist_image_path = arr[index];
  76.     g_valid_tid = gdi.LoadImageAsync(window.ID, artist_image_path);
  77. }
  78.  
  79. function on_load_image_done(tid, image) {
  80.     if (g_valid_tid == tid) {
  81.         artist_img && artist_img.Dispose();
  82.         artist_img = image;
  83.         window.Repaint();
  84.     }
  85. }
  86.  
  87. function on_mouse_lbtn_dblclk() {
  88.     try {WshShell.Run("\"" + artist_image_path + "\""); } catch(e) {}
  89. }
  90.  
  91. function on_get_album_art_done(metadb, art_id, im, ip) {
  92.     album_img = im;
  93.     window.Repaint();
  94. }
  95.  
  96. function on_size() {
  97.     ww = window.width;
  98.     wh = window.height;
  99. }
  100.  
  101. function on_paint(gr) {
  102.     gr.SetInterpolationMode(6);
  103.     if(artist_img) {
  104.         scale(gr, artist_img, 0, 0, ww, wh, "max");
  105.     } else {
  106.         gr.FillGradRect(0, 0, ww, wh, 90,g_backcolor, g_textcolor_hl);
  107.     }
  108.     gr.FillSolidRect(0,wh-130,ww,110,RGBA(0,0,0,156));
  109.     if(album_img) {
  110.         text_x = album_img_size + 10;
  111.         scale(gr, album_img, 0, wh-20-album_img_size, album_img_size, album_img_size, "min");
  112.     } else {
  113.         text_x = 10;
  114.     }
  115.     if(fb.IsPlaying) {
  116.         gr.GdiDrawText(fb.TitleFormat("%title% - %playback_time%[ / %length%]").Eval(), title_font, title_colour, text_x, wh -127, ww-text_x-10, wh,DT_END_ELLIPSIS | DT_CALCRECT | DT_NOPREFIX);
  117.         gr.GdiDrawText(album, album_font, album_colour, text_x, wh - 80, ww-text_x-10, wh,DT_END_ELLIPSIS | DT_CALCRECT | DT_NOPREFIX);
  118.         gr.GdiDrawText(artist, artist_font, artist_colour, text_x, wh - 55, ww-text_x-10, wh,DT_END_ELLIPSIS | DT_CALCRECT | DT_NOPREFIX);
  119.     } else {
  120.         scale(gr, gdi.Image(images_path + "new foo.png"), 0, 0, ww, wh - 130, "min");
  121.         gr.GdiDrawText(stopped_text, title_font, title_colour, 0, wh - 130, ww, 110,DT_CENTER | DT_VCENTER | DT_END_ELLIPSIS | DT_CALCRECT | DT_NOPREFIX);
  122.     }
  123. }
  124.  
  125. function on_mouse_rbtn_up(x, y) {
  126.     var _album = window.CreatePopupMenu();
  127.     var _cycle = window.CreatePopupMenu();
  128.     var _menu = window.CreatePopupMenu();
  129.     var _lastfm_options = window.CreatePopupMenu();
  130.     var _limit = window.CreatePopupMenu();
  131.     var idx;
  132.     _menu.AppendMenuItem(g_metadb ? MF_STRING : MF_GRAYED, 11, "Download artist art from Last.fm");
  133.     _lastfm_options.AppendMenuItem(MF_STRING, 1000, "Automatically download");
  134.     _lastfm_options.CheckMenuItem(1000, window.GetProperty("auto"));
  135.     _limit.AppendMenuItem(MF_STRING, 301, "1");
  136.     _limit.AppendMenuItem(MF_STRING, 303, "3");
  137.     _limit.AppendMenuItem(MF_STRING, 305, "5");
  138.     _limit.AppendMenuItem(MF_STRING, 310, "10");
  139.     _limit.AppendMenuItem(MF_STRING, 320, "20");
  140.     _limit.CheckMenuRadioItem(301, 320, window.GetProperty("limit"));
  141.     _lastfm_options.AppendMenuItem(MF_STRING | MF_POPUP, _limit.ID, "Limit");
  142.     _lastfm_options.AppendMenuItem(MF_SEPARATOR, 0, 0);
  143.     _lastfm_options.AppendMenuItem(MF_STRING, 1001, "Blacklist deleted images");
  144.     _lastfm_options.CheckMenuItem(1001, window.GetProperty("bl"));
  145.     _lastfm_options.AppendMenuItem(fso.FileExists(blacklist_file) ? MF_STRING : MF_GRAYED, 1002, "Clear blacklist for this artist");
  146.     _lastfm_options.AppendMenuItem(MF_SEPARATOR, 0, 0);
  147.     _lastfm_options.AppendMenuItem(MF_STRING, 1003, "Explain blacklisting");
  148.     _menu.AppendMenuItem(MF_STRING | MF_POPUP, _lastfm_options.ID, "Last.fm options");
  149.     _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
  150.     _cycle.AppendMenuItem(MF_STRING, 200, "Off");
  151.     _cycle.AppendMenuItem(MF_STRING, 205, "5 seconds");
  152.     _cycle.AppendMenuItem(MF_STRING, 210, "10 seconds");
  153.     _cycle.AppendMenuItem(MF_STRING, 220, "20 seconds");
  154.     _cycle.CheckMenuRadioItem(200, 220, window.GetProperty("cycle"));
  155.     _menu.AppendMenuItem(MF_STRING | MF_POPUP, _cycle.ID, "Cycle");
  156.     _album.AppendMenuItem(MF_STRING, 510, "Small");
  157.     _album.AppendMenuItem(MF_STRING, 620, "Large");
  158.     _album.CheckMenuRadioItem(510, 620, window.GetProperty("album_img_size"));
  159.     _menu.AppendMenuItem(MF_STRING | MF_POPUP, _album.ID, "Cover image size");
  160.     _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
  161.     _menu.AppendMenuItem(artist_img ? MF_STRING : MF_GRAYED, 12, "Open containing folder");
  162.     if(artist_img) _menu.AppendMenuItem(MF_STRING, 15, "Delete this image");
  163.     _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
  164.     if(utils.IsKeyPressed(0x10)) _menu.AppendMenuItem(MF_STRING, 99, "Properties");
  165.     _menu.AppendMenuItem(MF_STRING, 100, "Configure...");
  166.     idx = _menu.TrackPopupMenu(x, y);
  167.     switch(idx) {
  168.         case 200:
  169.         case 205:
  170.         case 210:
  171.         case 220:
  172.             window.SetProperty("cycle", idx);
  173.             cycle = idx - 200;
  174.             break;
  175.         case 301:
  176.         case 303:
  177.         case 305:
  178.         case 310:
  179.         case 320:
  180.             window.SetProperty("limit", idx);
  181.             limit = idx - 300;
  182.             break;
  183.         case 510:
  184.         case 620:
  185.             window.SetProperty("album_img_size", idx);
  186.             album_img_size = idx - 400;
  187.             window.Repaint();
  188.             break;
  189.         case 11:
  190.             download_images();
  191.             break;
  192.         case 12:
  193.             WshShell.Run("explorer /select," + artist_image_path);
  194.             break;
  195.         case 15:
  196.             try {
  197.                 if(window.GetProperty("bl") == true) {
  198.                     ts = fso.OpenTextFile(blacklist_file, 2, true, -1);
  199.                     ts.WriteLine(blacklist + arr[index] + "|") ;
  200.                     ts.close();
  201.                 }
  202.                 artist_img.Dispose();
  203.                 artist_img = null;
  204.                 fso.DeleteFile(arr[index]);
  205.             } catch(e) {
  206.                 fb.trace("Error: Could not delete " + arr[index]);
  207.             }
  208.             on_playback_new_track();
  209.             break;
  210.         case 99:
  211.             window.ShowProperties();
  212.             break;
  213.         case 100:
  214.             window.ShowConfigure();
  215.             break;
  216.         case 1000:
  217.             window.SetProperty("auto", !window.GetProperty("auto"));
  218.             break;
  219.         case 1001:
  220.             window.SetProperty("bl", !window.GetProperty("bl"));
  221.             break;
  222.         case 1002:
  223.             try { fso.DeleteFile(blacklist_file); } catch(e) {}
  224.             break;
  225.         case 1003:
  226.             fb.ShowPopupMessage("When you delete an image, there is no way for this script to prevent it being downloaded again. As a workaround, you can \"blacklist\" images you don't want and they will be deleted after downloading is complete.", "Now Playing");
  227.             break;
  228.     }
  229.     _lastfm_options.Dispose();
  230.     _menu.Dispose();
  231.     _cycle.Dispose();
  232.     _limit.Dispose();
  233.     _album.Dispose();
  234.     return true;
  235. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement