Advertisement
Guest User

Foobar Youtube Radio 2.4.

a guest
Mar 25th, 2015
388
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 50.89 KB | None | 0 0
  1. // ==PREPROCESSOR==
  2. // @name "Youtube Radio"
  3. // @author "Mire777"
  4. // @feature "v1.4"
  5. // @feature "watch-metadb"
  6. // ==/PREPROCESSOR==
  7.  
  8. //Properties
  9. YT_PL = window.GetProperty("YT  Playlist", "0");
  10. YT_AUTO = window.GetProperty("YT  Auto", "0");
  11. YT_TRACK = window.GetProperty("YT Track", "");
  12. STATION = window.GetProperty("YT  Station", "");
  13. SIM_ART = window.GetProperty("YT Similar", "");
  14. YT_URL = window.GetProperty("YT URL", "");
  15. art = window.GetProperty("YT   Artist Variety (1-20)", "20");
  16. sng = window.GetProperty("YT   Song  Hotness (1-20)", "20");
  17. tag = window.GetProperty("YT   Tag  Hotness (1-100)", "27");
  18. pls = window.GetProperty("FB Playlist", "YT Radio");
  19.  
  20. //Folder
  21. fso = new ActiveXObject("Scripting.FileSystemObject");
  22. folder = fb.ProfilePath + "playlists-YT";
  23.  
  24. var MF_GRAYED = 0x00000001;
  25. var MF_STRING = 0x00000000;
  26. var IDC_ARROW = 32512;
  27. var IDC_HAND = 32649;
  28.  
  29. function RGB(r, g, b) {
  30. return (0xff000000 | (r << 16) | (g << 8) | (b));
  31. }
  32.  
  33. function RGBA(r, g, b, a) {
  34. return ((a << 24) | (r << 16) | (g << 8) | (b));
  35. }
  36.  
  37. function on_colors_changed() {
  38. p.colors_changed();
  39. }
  40.  
  41. function on_selection_changed() {
  42. p.item_focus_change();
  43. }
  44.  
  45. function on_playlist_switch() {
  46. set_focus0(); //Check Playlist
  47. }
  48.  
  49. function on_playback_new_track() {
  50. p.item_focus_change();
  51. if (fb.ActivePlaylist == (GetPlaylistID(pls + " [Loved]"))) if (fb.PlaybackLength>=10) {LOVED();} else
  52. p.item_focus_change();
  53. if (fb.PlaybackLength>=10) {LOAD_ART();}
  54. }
  55.  
  56. function on_playback_dynamic_info_track() {
  57. p.item_focus_change();
  58. }
  59.  
  60. function on_playback_stop() {
  61. p.item_focus_change();
  62. }
  63.  
  64. function on_item_focus_change() {
  65. p.item_focus_change();
  66. }
  67.  
  68. function on_mouse_leave() {
  69. }
  70.  
  71. function on_mouse_rbtn_up(x, y) {
  72. p.rbtn_up(x, y);
  73. return true;
  74. }
  75.  
  76. //Remove false string from file names  
  77. this.clean_filename = function(filename) {
  78. return filename.replace(/[\/\\|:]/g, '-').replace(/\*/g, 'x').replace(/"/g, "''").replace(/[?<>]/g, '_');
  79. }
  80.  
  81. //Playlist
  82. function GetPlaylistID(Playlist_Name)
  83. {
  84. for (var i = 0; i < fb.PlaylistCount; i++)
  85. {
  86. if (fb.GetPlaylistName(i) == Playlist_Name)
  87. {
  88. return i;
  89. }
  90. }
  91.  
  92. //Create playlist if it doesn't exist
  93. fb.CreatePlaylist(fb.PlaylistCount, Playlist_Name);
  94. return i;
  95. }
  96.  
  97. //Playlist(Check)
  98. function GetPlaylistID0(Playlist_Name)
  99. {
  100. for (var i = 0; i < fb.PlaylistCount; i++)
  101. if (fb.GetPlaylistName(i) == Playlist_Name)
  102. {
  103. return i;
  104. }
  105. }
  106.  
  107. //Focus on playlist(Check)
  108. function set_focus0()
  109. {  
  110. if (pls>"")
  111. {
  112. var PL_NM = (GetPlaylistID0(pls + " ["+ STATION +"]"));
  113. if (fb.ActivePlaylist == PL_NM) {YT_PL = 1; window.SetProperty("YT  Playlist", "1");}
  114. else
  115. {YT_PL = 0; window.SetProperty("YT  Playlist", "0");}
  116. }
  117. }
  118.  
  119. //Focus on playlist(YT Radio)
  120. function set_focus()
  121. {  
  122. if (pls>"")
  123. fb.ActivePlaylist = (GetPlaylistID(pls + " ["+ STATION +"]"));
  124. }
  125.  
  126. //Focus on playlist(Same Video)
  127. function set_focus2()
  128. {  
  129. if (pls>"")
  130. fb.ActivePlaylist = (GetPlaylistID(pls + " [Same Video]"));
  131. }
  132.  
  133. //Focus on playlist(Search Videos)
  134. function set_focus3()
  135. {  
  136. if (pls>"")
  137. fb.ActivePlaylist = (GetPlaylistID(pls + " [Search Videos]"));
  138. }
  139.  
  140. //Focus on playlist(Popular Tracks)
  141. function set_focus4()
  142. {  
  143. if (pls>"")
  144. fb.ActivePlaylist = (GetPlaylistID(pls + " [Tracks: "+ p.artist +"]"));
  145. }
  146.  
  147. //Focus on playlist(Similar Tracks)
  148. function set_focus5()
  149. {
  150. if (pls>"")
  151. fb.ActivePlaylist = (GetPlaylistID(pls + " [Similar to: "+ p.artist + " - " + p.title +"]"));
  152. }
  153.  
  154. //Focus on playlist(Loved)
  155. function set_focus6()
  156. {
  157. if (pls>"")
  158. fb.ActivePlaylist = (GetPlaylistID(pls + " [Loved]"));
  159. }
  160.  
  161. //Panel
  162.     function panel(name, features) {
  163.     this.item_focus_change = function() {
  164.     if (!this.metadb_func) return;
  165.     switch(this.selection_mode) {
  166.     case 0:
  167.     this.metadb = fb.GetSelection();
  168.     break;
  169.     case 1:
  170.     this.metadb = fb.IsPlaying ? fb.GetNowPlaying() : fb.GetFocusItem();
  171.     break;
  172.     case 2:
  173.     this.metadb = fb.GetFocusItem();
  174.     break;
  175.         }
  176.         if (this.metadb) on_metadb_changed();
  177.     }
  178.  
  179. //Metadb
  180. this.metadb = fb.IsPlaying ? fb.GetNowPlaying() : fb.GetFocusItem();
  181.  
  182. //Size 
  183.    this.size = function() {
  184.    this.w = window.Width;
  185.    this.h = window.Height;
  186. }
  187.  
  188. //Move 
  189.    this.move = function(x, y) {
  190.    this.mx = x;
  191.    this.my = y;
  192. }
  193.  
  194. //Menu 
  195.    this.rbtn_up = function(x, y) {
  196.    var _menu = window.CreatePopupMenu();
  197.    var q = window.CreatePopupMenu();
  198.    var MF_POPUP = 0x00000010;
  199.    var idx;
  200.    switch(true) {
  201.            case typeof th == "object":
  202.            case typeof im == "object":
  203.  
  204. on_item_focus_change()            
  205. if (pls>"")
  206. {                  
  207. if(YT_AUTO==1) _menu.AppendMenuItem(MF_STRING, 1902, "Youtube Radio");
  208. if(YT_AUTO==0) _menu.AppendMenuItem(MF_STRING, 1903, "Youtube Radio");
  209. _menu.CheckMenuItem(1902, YT_AUTO?1:0);
  210.  
  211. _menu.AppendMenuSeparator();
  212.  
  213. //POPUP BUTTON
  214. {_menu.AppendMenuItem(MF_STRING | MF_POPUP, q.ID, "Open");}
  215.  
  216. //START *POPUP
  217. p.artist = p.eval("%artist%");
  218. if (p.artist == "" || p.artist == "?") {q.AppendMenuItem(MF_STRING| MF_GRAYED, 2000, "Radio Station by [%artist%]");}
  219. else
  220. {q.AppendMenuItem(MF_STRING, 1915, "Radio Station by [" + p.artist.replace(/&/g,"&&") + "]");}
  221.  
  222. p.genre = p.eval("%genre%");
  223. if (p.genre == "" || p.genre == "?") {q.AppendMenuItem(MF_STRING| MF_GRAYED, 2000, "Radio Station by [%genre%]");}
  224. else
  225. {q.AppendMenuItem(MF_STRING, 1921, "Radio Station by [genre: " + p.genre.replace(/&/g,"&&") + " ]");}
  226.  
  227. p.artist = p.eval("%artist%");
  228. if (p.artist == "" || p.artist == "?") {q.AppendMenuItem(MF_STRING| MF_GRAYED, 2000, "Top Tracks by " + "[%artist%]");}
  229. else
  230. {q.AppendMenuItem(MF_STRING, 1916, "Top Tracks by [" + p.artist.replace(/&/g,"&&") + "]");}
  231.  
  232. p.artist = p.eval("%artist%");
  233. p.title = p.eval("%title%");
  234. if (p.artist == "" || p.artist == "?") {q.AppendMenuItem(MF_STRING| MF_GRAYED, 2000, "Similar Tracks as [%artist% - %title%]");}
  235. else
  236. {q.AppendMenuItem(MF_STRING, 1920, "Similar Tracks as [" + p.artist.replace(/&/g,"&&") + " - " + p.title.replace(/&/g,"&&") + "]");}
  237. //END *POPUP
  238.  
  239. _menu.AppendMenuSeparator();
  240.  
  241. {
  242. if(YT_PL==1 && YT_AUTO==1 && STATION>"") {_menu.AppendMenuItem(MF_STRING, 22, "Get Next Video");}
  243. else
  244. {_menu.AppendMenuItem(MF_STRING| MF_GRAYED, 2000, "Get Next Video");}
  245.  
  246. _menu.AppendMenuSeparator();
  247.  
  248. _menu.AppendMenuItem(MF_STRING, 1914, "Start Radio Station");
  249.  
  250. _menu.AppendMenuSeparator();
  251.  
  252. //START *LOVED
  253. //Eval
  254. p.path = p.eval("%path%");
  255. p.artist = p.eval("%artist%");
  256. p.title = p.eval("%title%");
  257.  
  258. //Filename
  259. filename = folder + "\\"+ clean_filename(p.artist + " - " + p.title) + ".m3u";
  260.  
  261. //Check files
  262. var arr = utils.Glob(folder + "\\*.*").toArray();
  263. var a = [];
  264. for (i = 0; i < arr.length; i++) {
  265. if (arr[i]) a.push(arr[i]);  
  266. }
  267.  
  268. if (p.path.indexOf("youtube.com")>0 && (fb.ActivePlaylist == (GetPlaylistID(pls + " [Loved]"))))
  269. {
  270. if (fso.FileExists(filename)) {_menu.AppendMenuItem(MF_STRING, 500, "♥ Un-Love");} else {_menu.AppendMenuItem(MF_STRING, 501, "♥ Love Video");}
  271. if (arr=="" || arr=="?") {_menu.AppendMenuItem(MF_STRING| MF_GRAYED, 2000, "♪ Play Loved..");}
  272. else
  273. if (arr>"" || arr>"?") {_menu.AppendMenuItem(MF_STRING, 502, "♪ Next Loved..");}
  274. }
  275.  
  276. else
  277.  
  278. if (p.path.indexOf("youtube.com")>0)
  279. {
  280. if (fso.FileExists(filename)) {_menu.AppendMenuItem(MF_STRING, 500, "♥ Un-Love");} else {_menu.AppendMenuItem(MF_STRING, 501, "♥ Love Video");}
  281. if (arr=="" || arr=="?") {_menu.AppendMenuItem(MF_STRING| MF_GRAYED, 2000, "♪ Play Loved..");}
  282. if (arr>"" || arr>"?") {_menu.AppendMenuItem(MF_STRING, 502, "♪ Play Loved..");}
  283. }
  284.  
  285. else
  286.  
  287. {
  288. {_menu.AppendMenuItem(MF_STRING| MF_GRAYED, 2000, "♥ Love Video");}
  289. if (arr=="" || arr=="?") {_menu.AppendMenuItem(MF_STRING| MF_GRAYED, 2000, "♪ Play Loved..");}
  290. if (arr>"" || arr>"?") {_menu.AppendMenuItem(MF_STRING, 502, "♪ Play Loved..");}
  291. }
  292. //END *LOVED
  293.  
  294. _menu.AppendMenuSeparator();
  295.  
  296. p.artist = p.eval("%artist%");
  297. if (p.artist == "" || p.artist == "?") {_menu.AppendMenuItem(MF_STRING| MF_GRAYED, 2000, "Open Same Video..");}
  298. else
  299. {_menu.AppendMenuItem(MF_STRING, 403, "Open Same Video..");}
  300.  
  301. /* //Find in Browser
  302. _menu.AppendMenuSeparator();
  303. p.artist = p.eval("%artist%");
  304. if (p.artist == "" || p.artist == "?") {_menu.AppendMenuItem(MF_STRING| MF_GRAYED, 2000, "Find in Browser");}
  305. else
  306. {_menu.AppendMenuItem(MF_STRING, 404, "Find in Browser");}
  307. _menu.AppendMenuSeparator();*/
  308.  
  309. _menu.AppendMenuItem(MF_STRING, 401, "Search For Videos...");
  310.  
  311. _menu.AppendMenuSeparator();
  312.  
  313. _menu.AppendMenuItem(MF_STRING, 9, "Properties...");
  314. }              
  315. }
  316. }
  317. if (pls=="") {_menu.AppendMenuItem(MF_STRING, 9, "Please Set: (FB Playlist)");}
  318. if (utils.IsKeyPressed(0x10)) _menu.AppendMenuItem(MF_STRING, 10, "Configure...");
  319.        
  320.        idx = _menu.TrackPopupMenu(x, y);
  321.        switch(idx) {
  322.          
  323.           case 9:
  324.                 window.ShowProperties();
  325.                 break;
  326.                
  327.           case 10:
  328.                 window.ShowConfigure();
  329.                 break;
  330.                
  331.           case 22:
  332.                set_focus(); //Focus on playlist
  333.                 LOAD_ART();
  334.                 break;
  335.                
  336.           case 401:
  337.                set_focus3(); //Focus on playlist
  338.                 fb.RunMainMenuCommand("View/Youtube Source");
  339.                 break;
  340.                
  341.           case 403:
  342.                this.metadb = fb.IsPlaying ? fb.GetNowPlaying() : fb.GetFocusItem();
  343.                set_focus2(); //Focus on playlist
  344.                LOAD_SAME();
  345.                 break;
  346.            
  347.           case 404:
  348.                p.artist = p.eval("%artist% %title%");
  349.                p.browser("https://www.youtube.com/results?search_query=" + encodeURIComponent(p.artist));
  350.                 break;
  351.            
  352.            case 500:
  353.                 filename = folder + "\\"+ clean_filename(p.artist + " - " + p.title) + ".m3u";
  354.                 //Delete file
  355.                 if (fso.FileExists(filename)) fso.DeleteFile(filename);
  356.                 break;
  357.                
  358.            case 501:
  359.                 this.metadb = fb.IsPlaying ? fb.GetNowPlaying() : fb.GetFocusItem();
  360.                 p.path = p.eval("%path%");
  361.                 p.artist = p.eval("%artist%");
  362.                 p.title = p.eval("%title%");
  363.                
  364.                 //Create file & folder
  365.                 filename = folder + "\\"+ clean_filename(p.artist + " - " + p.title) + ".m3u";
  366.                 if(!fso.FolderExists(folder)) fso.CreateFolder(folder);
  367.                
  368.                 //Save file
  369.                 function save_file(x) {
  370.                 try {
  371.                 g_text = p.path;
  372.                 ts = fso.OpenTextFile(filename, 2, true, -2);
  373.                 ts.Write(g_text);
  374.                 ts.close();
  375.                 } catch(e) {
  376.                 fb.trace("Error saving text: " + e);
  377.                 }}
  378.                 save_file(filename);
  379.                 break;
  380.  
  381.            case 502:
  382.                 LOVED();
  383.                 break;
  384.                
  385.            case 1902:
  386.                 YT_AUTO = 0;
  387.                 window.SetProperty("YT  Auto", "0");
  388.                 break;
  389.        
  390.            case 1903:
  391.                 YT_AUTO = 1;
  392.                 window.SetProperty("YT  Auto", "1");
  393.                 break;
  394.            
  395.            case 1914:
  396.                 var Start;
  397.                 Start = this.InputBox("Type Artist to Start Station\n\n( *genre - will play genre station)", "Youtube Radio", "");
  398.                 if (Start=="")
  399.                 {
  400.                 }
  401.                 else
  402.                 {
  403.                 YT_PL = 1;
  404.                 window.SetProperty("YT  Playlist", "1");
  405.                 YT_AUTO = "1"
  406.                 window.SetProperty("YT  Auto", "1");
  407.                 STATION = Start;
  408.                 window.SetProperty("YT  Station", Start);
  409.                 set_focus(); //Focus on playlist
  410.                 LOAD_ART();
  411.                 }
  412.                 break;
  413.            
  414.            case 1915:
  415.                 this.metadb = fb.IsPlaying ? fb.GetNowPlaying() : fb.GetFocusItem();
  416.                 p.artist = p.eval("%artist%");
  417.                 if (p.artist == "" || p.artist == "?") return;
  418.                 STATION = p.artist;
  419.                 window.SetProperty("YT  Station", p.artist);
  420.                 YT_PL = 1;
  421.                 window.SetProperty("YT  Playlist", "1");
  422.                 YT_AUTO = "1"
  423.                 window.SetProperty("YT  Auto", "1");
  424.                 set_focus(); //Focus on playlist
  425.                 LOAD_ART();
  426.                 break;
  427.        
  428.            case 1916:
  429.                 set_focus4(); //focus on playlist
  430.                 POP_TRACKS();
  431.                 break;
  432.            
  433.            case 1920:
  434.                 //set_focus5(); //focus on playlist
  435.                 SIMILAR_TRACKS();
  436.                 break;
  437.            
  438.            case 1921:
  439.                 this.metadb = fb.IsPlaying ? fb.GetNowPlaying() : fb.GetFocusItem();
  440.                 p.genre = p.eval("%genre%");
  441.                 if (p.genre == "" || p.genre == "?") return;
  442.                 STATION = "*" + p.genre;
  443.                 window.SetProperty("YT  Station", "*" + p.genre);
  444.                 YT_PL = 1;
  445.                 window.SetProperty("YT  Playlist", "1");
  446.                 YT_AUTO = "1"
  447.                 window.SetProperty("YT  Auto", "1");
  448.                 set_focus(); //Focus on playlist
  449.                 LOAD_GENRE();
  450.                 break;
  451.                }
  452.                 _menu.Dispose();
  453.              }
  454.  
  455. //Features init
  456.     this.features_init = function() {
  457.     for (i = 0; i < this.features.length; i++) {
  458.     switch(this.features[i]) {
  459.     case "metadb":
  460.     this.selection_mode = 1;
  461.     break;
  462.     case "remap":
  463.     this.artist_tf = ("%artist%");
  464.     break;
  465.             }
  466.         }
  467.     }
  468.    
  469.     this.check_feature = function(f) {
  470.     for (i = 0; i < this.features.length; i++) {
  471.     if (this.features[i] == f) return true;
  472.     }
  473.     return false;
  474.     }
  475.  
  476. //Eval
  477.     this.eval = function(tf) {
  478.     if (!this.metadb || tf == "") return "";
  479.     if (fb.IsPlaying && this.metadb.RawPath.indexOf("file://") != 0) {
  480.     return fb.TitleFormat(tf).Eval();
  481.     } else {
  482.     return fb.TitleFormat(tf).EvalWithMetadb(this.metadb);
  483.     }
  484.     }
  485.    
  486. //Console Msg
  487.     this.console = function(message) {
  488.     this.name = "Youtube Radio"
  489.     fb.trace(this.name + ": " + message);
  490.     }
  491.    
  492. //Trim
  493.     String.prototype.trim = function() {
  494.     return this.replace(/^\s+|\s+$/g, "");
  495.     }    
  496.  
  497. //Input Box    
  498.     this.InputBox = function(prompt, title, value) {
  499.     prompt = prompt.replace(/"/g, '" + Chr(34) + "').replace(/\n/g, '" + Chr(13) + "');
  500.    title = title.replace(/"/g, '" + Chr(34) + "');
  501.     value = value.replace(/"/g, '" + Chr(34) + "');
  502.    var temp_value = this.vb.eval('InputBox' + '("' + prompt + '", "' + title + '", "' + value + '")');
  503.    if (typeof temp_value == "undefined") return value;
  504.    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, "Youtube Radio");
  505.    return temp_value.trim();
  506.     }
  507.  
  508. //Msg Box  
  509.     this.MsgBox = function(prompt, buttons, title) {
  510.    prompt = prompt.replace(/"/g, '" + Chr(34) + "').replace(/\n/g, '" + Chr(13) + "');
  511.     title = title.replace(/"/g, '" + Chr(34) + "');
  512.    return this.vb.eval('MsgBox' + '("' + prompt + '", "' + buttons + '", "' + title + '")');
  513.     }
  514.  
  515. //Browser  
  516.     this.browser = function(command) {
  517.    if (!this.run(command)) this.MsgBox("Unable to launch your default browser.", 0, "Youtube Radio");
  518.     }
  519.  
  520. //Run Command  
  521.     this.run = function(command) {
  522.    try {
  523.    this.WshShell.Run(command);
  524.    return true;
  525.    } catch(e) {
  526.    return false;
  527.    }
  528.     }
  529.    
  530. //futures  
  531.    this.metadb_func = typeof on_metadb_changed == "function";
  532.     this.features = features;
  533.     this.dui = window.InstanceType;
  534.     this.metadb = fb.GetFocusItem();
  535.     this.WshShell = new ActiveXObject("WScript.Shell");
  536.     this.fso = new ActiveXObject("Scripting.FileSystemObject");
  537.     this.vb = new ActiveXObject("ScriptControl");
  538.     this.vb.Language = "VBScript";
  539.     this.artist_tf = "%artist%";
  540.     this.features_init();
  541.    this.metadb = fb.IsPlaying ? fb.GetNowPlaying() : fb.GetFocusItem();
  542.    if (fb.GetFocusItem())
  543.    {this.artist = fb.TitleFormat(this.artist_tf).EvalWithMetadb(this.metadb);}
  544.  
  545. }
  546.  
  547. //YT NAMES-------------------------------------------------
  548.  
  549. //Clean Art Name
  550. CLEAN_ART_NAME = function (t)
  551. {   try
  552.    {
  553.    return t.replace(/about:\//,"").replace("music/","").replace("/_/"," - ").replace("+"," ").replace("+"," ").replace("+"," ").replace("+"," ").replace("+"," ").replace("+"," ").replace("+"," ").replace("+"," ").replace("+"," ").replace("+"," ").replace("+"," ").replace("+"," ").replace("+"," ").replace("+"," ").replace("+"," ").replace("+"," ").replace("+"," ").replace("+"," ").replace("+"," ").replace("+"," ").replace("free-music-downloads","").replace("/+similar?page=2","").replace("/+events","").replace("/+wiki","").replace("-+","").replace("/+albums","").replace("/+tags","").replace("/+images","").replace("/journal","").replace("/charts","").replace("/images","").replace("/listeners","").replace("/similar?page=17","").replace("/news","").replace("/groups","").replace("/albums","").replace("/videos","").replace("/tracks","").replace("/similar","").replace("/tags","").replace("noredirect/","").replace("listeners/+tracks","").replace("videos/+tracks","").replace("/+videos/","").replace("?page=1","").replace("?page=8","").replace("?page=5","").replace("?page=7","").replace("?page=9","").replace("?page=8","").replace(" wiki/edit","").replace("/ similar","").replace("?page=","'").replace("/ charts","'").replace("-","").replace("%2F%E3%82%A4%E3%83%95%E3%83%BB%E3%83%8E%E3%83%83%E3%83%88%E3%83%BB%E3%83%95%E3%82%A9%E3%83%BE3%83%BB%E3%83%A6%E3%83%BC","").replace("Ajoutez ce titre sur Deezer exclusivement sur www.hotmixradio.fr","").replace("www.Hituri.net","").replace("%E3%81%97%E3%82%83%E3%81%AB%E3%82%80%E3%81%AB%E3%82%B7%E3%82%A7%E3%82%A4%E3%82%AF%EF","").replace("%B81%E3%82%B7%E3%82%A7%E3%82%A4%E3%82%AF%EF%B81","").replace("%E4%BD%95%E3%82%88%E3%82%8A%E3%82%82%E5%83%95%E3%82%89%E3%81%97%E3%81%8F%E3%80%81%E4%BD%95%E3%82%88%E3%82%8A","").replace("%E3%82%82%E5%90%9B%E3%82%89%E3%81%97%E3%81%8F","").replace("%D0%91%D1%8D0%B5%D1%82 %D0%BF%D0%BE %D0%B3%D0%BB%D0%B0%D0%B7%D0%B0%D0%BC","").replace("%E3%83%9E%E3%82%A4%E3%83%BB%E3%83%9E3%83%87%E3%82%A3","").replace("%D0%9B%D0%B5%D1%82%D0%B5%D1%82%D1%8C","").replace("%2F%2F %D0%A1%D0%9B%D0%A3%D0%A8%D0%90%D0%AE%D0%A2","").replace("%D0%9F%D0%BE%D0%BF-%D0%A5%D0%B8%D1%82","").replace("/","").replace("%27","'").replace("%27","'").replace("%27","'").replace("%27","'").replace("%27","'").replace("%27","'").replace("%27","'").replace("%27","'").replace("%27","'").replace("%27","'").replace("%27","'").replace("%27","'").replace("%27","'").replace("%27","'").replace("%27","'");
  554.    } catch (e) {}
  555. }
  556.  
  557. //Clean Track Name
  558. CLEAN_TRACK_NAME = function (t)
  559. {   try
  560.    {
  561.    return t.replace(/about:\//,"").trim().split(" (")[0].replace(" (","").split(" [")[0].replace(" [","").split(" {")[0].replace(" {","").split(", ")[0].replace(", ","").replace("%27","'").replace("%27","'").replace("%27","'").replace("%27","'").replace("%27","'").replace("%27","'").replace("%27","'").replace("%27","'").replace("%27","'").replace("%27","'").replace("%27","'").replace("%27","'").replace("%27","'").replace("%27","'").replace("%27","'").replace(" 01-","").replace(" 02-","").replace(" 03-","").replace(" 04-","").replace(" 05-","").replace(" 06-","").replace(" 07-","").replace(" 08-","").replace(" 09-","").replace("09  ","").replace("08  ","").replace("07  ","").replace("06  ","").replace("05  ","").replace("04  ","").replace("03  ","").replace("02  ","").replace("01  ","").replace("00  ","").replace("01 ","").replace("02 ","").replace("03 ","").replace("04 ","").replace("05 ","").replace("06 ","").replace("07 ","").replace("08 ","").replace("09 ","").replace("00 ","").replace(".mp","").replace(" - Remastered ","").replace(" - Remastered","").replace("- "," ").replace(decodeURIComponent(SIM_ART) + " -"," ").replace(decodeURIComponent(SIM_ART) + " - "," ").replace(" - Live ","").replace(" - Live","").replace(" Pt.1","").replace(" - Demo;2 Digital Remaster 66  ","").replace(" - Demo;2 Digital Remaster","").replace(" - Demo;","").replace(" - Demo","").replace("Digital Remaster","").replace("Original-  ","").replace("Original- ","").replace("Original-","").replace(" - Vocal Version","").replace(" Mega-Mix","").replace("Mega-Mix","").replace(" - Original Mix","").replace(" Pop Radio Edit","").replace(" Radio Edit","").replace(" - Single Version","").replace(" - Edited Version","").replace("- ","").replace("- ","").replace("- ","").replace("- ","").replace("- ","").replace("- ","").replace("- ","").replace("- ","").replace("- ","").replace("- ","").replace(" - Extended Version","").replace(" -Remaster","").replace("`","'").replace(". "," ").replace(" Version","").replace(" edit","").replace(" - Edit","").replace("  Simple Mix","").replace("  Almighty Mix","").replace(" - Vocal","").replace(" Vocal","").replace("  Remix","").replace("  Extended Version","").replace(" - Explicit Version","").replace("- Explicit Version","").replace(" Explicit Version","").replace("Explicit Version","").replace(" Anthology", "").replace("The " + decodeURIComponent(SIM_ART), " ").replace(" - Survival Remix","").replace(" Radio Mix","").replace(" Survival Remix","").replace("Survival Remix","").replace(decodeURIComponent(SIM_ART) + "-"," ").replace(decodeURIComponent(SIM_ART)," ").replace(" Club Mix","").replace("_"," ").replace("_"," ").replace("_"," ").replace("_"," ").replace("_"," ").replace("_"," ").replace("_"," ").replace("_"," ").replace("_"," ").replace("_"," ").replace("  wwwi.info","").replace(" Edit","").replace("live","").replace("Single","").replace("vk.com/xclusives zone ","").replace("  Acoustic","").replace("Remix","").replace("Part&","").replace("  +","").replace(" % ","").replace(" % ","").replace(" % ","").replace(" % ","").replace(" % ","").replace(" % ","").replace(" % ","").replace(" % ","").replace(" % ","").replace(" % ","").replace(" % ","").replace(" % ","").replace(" % ","").replace(" Live;0 2","").replace("  Live;0 2","").replace("Live;0 2","").replace(' /"/"',"").replace(" -0","").replace("%","").replace("%","").replace("%","").replace("%","").replace("%","").replace("%","").replace("%","").replace("%","").replace("%","").replace("%","").replace("%","").replace("%","").replace("%","").replace("%","").replace("%","").replace("%","").replace("%","").replace("%","").replace("%","").replace("%","").replace("  Alternate Mix","").replace("Live","").replace(" Alternate Mix","").replace("Alternate Mix","").replace("-0","").replace("  remastered","").replace(" // СЛУШАЮТ:","").replace("www.KLAUSOM.lt","").replace("-;-Bit Digital Remaster","").replace(" :","").replace("-1  Remaster","").replace("  Genuine Album","").replace("  www.rsmp.com","").replace(" www.rsmp.com","").replace("www.rsmp.com","").replace("Instrumental","").replace(" Instrumental","").replace("www.SongsLover.pk","").replace(" Genuine Album","").replace("Album","").replace("Remaster","").replace("Lyrics","").replace("w/lyrics","").replace(" -","").replace("  Radio","").replace("0%","").replace("remaster","").replace(" Lyrics","").split(" | '' |")[0].replace(" | '' |","").split(" |")[0].replace(" |","").split("|")[0].replace("|","").split("| On:")[0].replace("| On:","").split(" feat")[0].replace(" feat","").split(" ft.")[0].replace(" ft.","").split(" Feat.")[0].replace(" Feat","").split("Greatest Hits Megamix")[0].replace("Greatest Hits Megamix","").split("Lyrics")[0].replace("Lyrics","").split("Lyric")[0].replace("Lyric","").split("www.")[0].replace("www.","").split(";Feat")[0].replace(";Feat","").trim();
  562.    } catch (e) {}
  563. }
  564.  
  565. //Clean Genre Name
  566. CLEAN_GENRE_NAME = function (t)
  567. {   try
  568.    {
  569.    return t.replace(/about:\//,"").replace("music/","").replace("+"," ").replace("+"," ").replace("+"," ").replace("+"," ").replace("+"," ").replace("+"," ").replace("+"," ").replace("+"," ").replace("+"," ").replace("+"," ").replace("+"," ").replace("+"," ").replace("+"," ").replace("+"," ").replace("+"," ").replace("+"," ").replace("+"," ").replace("+"," ").replace("+"," ").replace("+"," ").replace("free-music-downloads","").replace("/+similar?page=2","").replace("/+events","").replace("/+wiki","").replace("-+","").replace("/+albums","").replace("/+tags","").replace("/+images","").replace("/journal","").replace("/charts","").replace("/images","").replace("/listeners","").replace("/similar?page=17","").replace("/news","").replace("/groups","").replace("/albums","").replace("/videos","").replace("/tracks","").replace("/similar","").replace("/tags","").replace("noredirect/","").replace("listeners/+tracks","").replace("videos/+tracks","").replace("/+videos/","").replace("?page=1","").replace("?page=8","").replace("?page=5","").replace("?page=7","").replace("?page=9","").replace("?page=8","").replace(" wiki/edit","").replace("/ similar","").replace("?page=","'").replace("/ charts","'").replace("-","").replace("%2F%E3%82%A4%E3%83%95%E3%83%BB%E3%83%8E%E3%83%83%E3%83%88%E3%83%BB%E3%83%95%E3%82%A9%E3%83%BE3%83%BB%E3%83%A6%E3%83%BC","").replace("Ajoutez ce titre sur Deezer exclusivement sur www.hotmixradio.fr","").replace("www.Hituri.net","").replace("%E3%81%97%E3%82%83%E3%81%AB%E3%82%80%E3%81%AB%E3%82%B7%E3%82%A7%E3%82%A4%E3%82%AF%EF","").replace("%B81%E3%82%B7%E3%82%A7%E3%82%A4%E3%82%AF%EF%B81","").replace("%E4%BD%95%E3%82%88%E3%82%8A%E3%82%82%E5%83%95%E3%82%89%E3%81%97%E3%81%8F%E3%80%81%E4%BD%95%E3%82%88%E3%82%8A","").replace("%E3%82%82%E5%90%9B%E3%82%89%E3%81%97%E3%81%8F","").replace("%D0%91%D1%8D0%B5%D1%82 %D0%BF%D0%BE %D0%B3%D0%BB%D0%B0%D0%B7%D0%B0%D0%BC","").replace("%E3%83%9E%E3%82%A4%E3%83%BB%E3%83%9E3%83%87%E3%82%A3","").replace("%D0%9B%D0%B5%D1%82%D0%B5%D1%82%D1%8C","").replace("%2F%2F %D0%A1%D0%9B%D0%A3%D0%A8%D0%90%D0%AE%D0%A2","").replace("%D0%9F%D0%BE%D0%BF-%D0%A5%D0%B8%D1%82","").replace("/","").split("tag")[0].split("hype")[0].split("events")[0];
  570.    } catch (e) {}
  571. }
  572.  
  573. //*********************YT RADIO START**********************
  574.  
  575. //SIMILAR ARTIST--------------------------------------------
  576. this.LOAD_ART = function()
  577. {     if (YT_AUTO=="1")
  578.      if (YT_PL=="1")
  579.    
  580.    { var randomnumber=Math.floor(Math.random()*art)
  581.      var a=randomnumber;
  582.        if (STATION == "" || STATION == "?") return;
  583.         if (!this.xmlhttp) this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  584.         this.xmlhttp.open("GET", "http://www.last.fm/music/" + encodeURIComponent(STATION) + "/+similar"+ "?page=" + a, true);
  585.         this.xmlhttp.send();
  586.         this.xmlhttp.onreadystatechange = function() {
  587.        if (this.xmlhttp.readyState == 4) {
  588.        if (this.xmlhttp.status == 200) {
  589.        var text = this.xmlhttp.responsetext;
  590.        if (!this.doc) this.doc = new ActiveXObject("htmlfile");
  591.        this.doc.open();
  592.        var div = this.doc.createElement("div");
  593.        div.innerHTML = text;
  594.        var data = div.getElementsByTagName("a");
  595.        var urls = [];
  596.  
  597. for (i = 0; i < data.length; i++) {
  598. if (data[i].href.indexOf("about:/music/") == 0) urls.push(CLEAN_ART_NAME(data[i].href));  
  599. }
  600.  
  601. //select random URL
  602. var randomnumber = Math.floor(Math.random()*(20-50)+50);
  603. do{
  604. randomnumber = Math.floor(Math.random()*(20-50)+50);
  605. } while(randomnumber%2!=1);
  606. i=randomnumber;
  607.  
  608. {
  609. //Start with urls[i]
  610. if (urls[i] > "")
  611. {
  612. //p.console("" + urls[i]);
  613. SIM_ART = window.SetProperty("YT Similar", urls[i]);
  614. SIM_ART = urls[i];
  615. window.SetProperty("YT Similar", urls[i]);
  616. }
  617. else
  618. {
  619. SIM_ART = window.SetProperty("YT Similar", "");
  620. SIM_ART = "";
  621. window.SetProperty("YT Similar", "");
  622. }                  
  623. }
  624.            
  625.        this.doc.close();
  626.        if (STATION.indexOf("*")== 0) {LOAD_GENRE();}
  627.        else
  628.        if (SIM_ART == "" || SIM_ART == "?") {LOAD_ART();}
  629.        else
  630.        LOAD_TRACK();
  631.        } else {
  632.        if (STATION.indexOf("*")== 0) {LOAD_GENRE();}
  633.        else
  634.        if (this.xmlhttp.status == 404) {p.console("HTTP error: " + this.xmlhttp.status); LOAD_ART();}
  635.                }
  636.             }
  637.         }
  638.     }                            
  639. }
  640.  
  641. //LOAD TRACK----------------------------------------------------
  642. this.LOAD_TRACK = function()
  643. {
  644.    
  645.    {var randomnumber=Math.floor(Math.random()*sng)
  646.     var a=randomnumber;
  647.        if (SIM_ART == "" || SIM_ART == "?") return;
  648.         if (!this.xmlhttp) this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  649.         this.xmlhttp.open("GET", "http://www.last.fm/music/" + encodeURIComponent(SIM_ART) + "/+tracks" + "?page=" + a, true);
  650.         this.xmlhttp.send();
  651.         this.xmlhttp.onreadystatechange = function() {
  652.        if (this.xmlhttp.readyState == 4) {
  653.        if (this.xmlhttp.status == 200) {
  654.        var text = this.xmlhttp.responsetext;
  655.        if (!this.doc) this.doc = new ActiveXObject("htmlfile");
  656.        this.doc.open();
  657.        var div = this.doc.createElement("tr");
  658.        div.innerHTML = text;
  659.        var data = div.getElementsByTagName("td");
  660.        var urls = [];
  661.  
  662. for (i = 0; i < data.length; i++) {
  663. if (data[i].title) urls.push(CLEAN_TRACK_NAME(data[i].title));
  664. }
  665.  
  666. //select random URL
  667. var randomnumber = Math.floor(Math.random()*Math.max(urls.length));
  668. i=randomnumber;
  669.  
  670. {
  671.  
  672. //Start with urls[i]
  673. if (urls[i] > "")
  674. {
  675. p.console("" + SIM_ART + " - " + urls[i]);
  676.  
  677. YT_TRACK = window.SetProperty("YT Track", urls[i]);
  678. YT_TRACK = urls[i];
  679. window.SetProperty("YT Track", urls[i]);
  680. }
  681. else
  682. {
  683. YT_TRACK = window.SetProperty("YT Track", "");
  684. YT_TRACK = "";
  685. window.SetProperty("YT Track", "");
  686. }
  687. }
  688.  
  689.        this.doc.close();
  690.        if (YT_TRACK == "" || YT_TRACK == "?") {LOAD_ART();}
  691.        else
  692.        set_focus(); //focus on playlist
  693.        do_youtube_search1(decodeURIComponent(SIM_ART), decodeURIComponent(YT_TRACK));
  694.        } else {
  695.        p.console("HTTP error: " + this.xmlhttp.status);
  696.        if (STATION.indexOf("*")== 0) {LOAD_GENRE();}
  697.        else
  698.        if (this.xmlhttp.status == 404) {LOAD_ART();}
  699.                }
  700.             }
  701.         }
  702.     }
  703. }
  704.  
  705. //POPULAR TRACKS----------------------------------------------------
  706. this.POP_TRACKS = function()
  707. {       p.artist = p.eval("%artist%");
  708.  
  709.    {   if (p.artist == "" || p.artist == "?") return;
  710.         if (!this.xmlhttp) this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  711.         this.xmlhttp.open("GET", "http://www.last.fm/music/" + encodeURIComponent(p.artist) + "/+tracks" + "?page=1", true);
  712.         this.xmlhttp.send();
  713.         this.xmlhttp.onreadystatechange = function() {
  714.        if (this.xmlhttp.readyState == 4) {
  715.        if (this.xmlhttp.status == 200) {
  716.        var text = this.xmlhttp.responsetext;
  717.        if (!this.doc) this.doc = new ActiveXObject("htmlfile");
  718.        this.doc.open();
  719.        var div = this.doc.createElement("tr");
  720.        div.innerHTML = text;
  721.        var data = div.getElementsByTagName("td");
  722.        var urls = [];
  723.    
  724. for (i = 0; i < data.length; i++) {
  725. if (data[i].title) urls.push(CLEAN_TRACK_NAME(data[i].title));
  726. }
  727.  
  728. //Select urls[i]
  729. for (i = 0; i < urls.length; i++)
  730.  
  731. {
  732. //Start with urls[i]
  733. if (urls[i] > "")
  734. do_youtube_search1(decodeURIComponent(p.artist), urls[i]);
  735. }
  736.        this.doc.close();
  737.        } else {
  738.        p.console("HTTP error: " + this.xmlhttp.status);
  739.                }
  740.             }
  741.         }
  742.     }
  743. }
  744.  
  745. //SIMILAR TRACKS----------------------------------------------------
  746. this.SIMILAR_TRACKS = function()
  747. { p.artist = p.eval("%artist%");
  748. p.title = p.eval("%title%");
  749.  
  750. { if (p.artist == "" || p.artist == "?") return;
  751. if (p.title == "" || p.title == "?") return;
  752. if (!this.xmlhttp) this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  753. this.xmlhttp.open("GET", "http://www.last.fm/music/" + encodeURIComponent(p.artist) + "/_/" + encodeURIComponent(p.title) + "/+similar", true);
  754. this.xmlhttp.send();
  755. this.xmlhttp.onreadystatechange = function() {
  756. if (this.xmlhttp.readyState == 4) {
  757. if (this.xmlhttp.status == 200) {
  758. var text = this.xmlhttp.responsetext;
  759. if (!this.doc) this.doc = new ActiveXObject("htmlfile");
  760. this.doc.open();
  761. var div = this.doc.createElement("td");
  762. div.innerHTML = text;
  763. var data = div.getElementsByTagName("a");
  764. var urls = [];
  765.  
  766. for (i = 0; i < data.length; i++) {
  767.  
  768. if (data[i].href.indexOf("/_/")>0)
  769.  
  770. urls.push((data[i].href));
  771. }
  772.  
  773. //Select urls[i]
  774. for (i = 0; i < 100; i++)
  775.  
  776. {
  777. //Start with urls[i]
  778. if (urls[i].indexOf("http:")==0) return;
  779. if (urls[i].indexOf("/_/") >0)
  780. title_split = urls[i].split("/_/")[1].replace("+"," ").replace("+"," ").replace("+"," ").replace("+"," ").replace("+"," ").replace("+"," ").replace("+"," ").replace("+"," ").replace("+"," ").replace("+"," ").replace("+"," ").replace("+"," ").replace("+"," ").replace("+"," ").replace("+"," ");
  781. artist_split = urls[i].split("/_/")[0].replace("+"," ").replace("+"," ").replace("+"," ").replace("+"," ").replace("+"," ").replace("+"," ").replace("+"," ").replace("+"," ").replace("+"," ").replace("+"," ").replace("+"," ").replace("+"," ").replace("+"," ").replace("+"," ").replace("+"," ").replace("about:/music/","").replace("noredirect/","");
  782. set_focus5();//set focus on playlist
  783. do_youtube_search1(decodeURIComponent(artist_split),decodeURIComponent(title_split));
  784.  
  785. }
  786. this.doc.close();
  787. } else {
  788. p.console("HTTP error: " + this.xmlhttp.status);
  789. }
  790. }
  791. }
  792. }
  793. }
  794.  
  795. //GENRE----------------------------------------------------
  796. this.LOAD_GENRE = function()
  797. {     if (STATION.indexOf("*")== 0)
  798.  
  799.    { var randomnumber=Math.floor(Math.random()*tag)
  800.      var a=randomnumber;
  801.        if (STATION == "" || STATION == "?") return;
  802.         if (!this.xmlhttp) this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  803.         this.xmlhttp.open("GET", "http://www.last.fm/music/+tag/" + encodeURIComponent(STATION).replace("*","") + "?page=" + a, true);
  804.         this.xmlhttp.send();
  805.         this.xmlhttp.onreadystatechange = function() {
  806.        if (this.xmlhttp.readyState == 4) {
  807.        if (this.xmlhttp.status == 200) {
  808.        var text = this.xmlhttp.responsetext;
  809.        if (!this.doc) this.doc = new ActiveXObject("htmlfile");
  810.        this.doc.open();
  811.        var div = this.doc.createElement("li");
  812.        div.innerHTML = text;
  813.        var data = div.getElementsByTagName("a");
  814.        var urls = [];
  815.    
  816. for (i = 0; i < data.length; i++) {
  817.    if (data[i].className.indexOf("name") == 0)
  818.    if (data[i].href.indexOf("about:/music/") == 0) urls.push(CLEAN_GENRE_NAME(data[i].href));
  819. }
  820.  
  821. //select random URL
  822. var randomnumber = Math.floor(Math.random()*(0-9)+9);
  823. do{
  824. randomnumber = Math.floor(Math.random()*(0-9)+9);
  825. } while(randomnumber%2!=0);
  826.  
  827. i=randomnumber;
  828.  
  829. {
  830.  
  831. //Start with urls[i]
  832. if (urls[i] > "")
  833. {
  834. //p.console("" + urls[i]);
  835. SIM_ART = window.SetProperty("YT Similar", urls[i]);
  836. SIM_ART = urls[i];
  837. window.SetProperty("YT Similar", urls[i]);
  838. }
  839. else
  840. {
  841. SIM_ART = window.SetProperty("YT Similar", "");
  842. SIM_ART = "";
  843. window.SetProperty("YT Similar", "");
  844. }
  845. }
  846.        this.doc.close();
  847.        if (SIM_ART == "" || SIM_ART == "?") {LOAD_GENRE();}
  848.        else
  849.        LOAD_TRACK();
  850.        } else {
  851.        p.console("HTTP error: " + this.xmlhttp.status);
  852.        if (this.xmlhttp.status == 404) {LOAD_GENRE();}
  853.                }
  854.             }
  855.         }
  856.     }
  857. }
  858. //LOVED----------------------------------------------------
  859. this.LOVED = function()
  860. {
  861.                //list files
  862.                var arr = utils.Glob(folder + "\\*.*").toArray();
  863.                var a = [];
  864.  
  865.                for (i = 0; i < arr.length; i++) {
  866.                if (arr[i]) a.push(arr[i]);  
  867.                    }
  868.                //select random file
  869.                var randomnumber = Math.floor(Math.random()*Math.max(arr.length));
  870.                i=randomnumber;
  871.                
  872.                file_path = arr[i];
  873.                var tmppath = p.fso.GetFolder(fb.FoobarPath).ShortPath;
  874.                var str = tmppath + "\\foobar2000.exe /add ";
  875.                var go = str + '"' + file_path + '"';
  876.                
  877.                //load file
  878.                set_focus6(); //Focus on playlist
  879.                var tm = window.SetTimeout(function() {
  880.                p.run(go);
  881.                p.console(file_path);
  882.                window.ClearTimeout(tm); tm = false;
  883.                }, 50);    
  884. }
  885.  
  886. //SAME VIDEO-----------------------------------------------
  887. this.LOAD_SAME = function()
  888.    {
  889.      var artist0 = p.eval("%artist%");
  890.      var title0 = p.eval("%title%");
  891.      if(artist0 > "?" && title0 > "?") {set_focus2(); do_youtube_search1(decodeURIComponent(artist0), decodeURIComponent(title0));}
  892. }
  893.  
  894. //LOAD YOUTUBE VIDEO---------------------------------------
  895. strip_title = function (t1, t2)
  896. {
  897.    try
  898.    {
  899.        if (t1 == t2)
  900.        return t1;
  901.        if (t1.match(RegExp(t2 + "( and | & )", "i")))
  902.        return t1;
  903.        var a = "(by the |by: |by |of |the |feat. |ft. |)";
  904.        var b = "( feat.| ft.|)";
  905.        var t3 = "";
  906.        if (!t2.match(/^the /i))
  907.        {
  908.        t3 = t1.replace(RegExp("[^a-z\\d_)\\]\"]*(" + a + t2 + b + ")[^a-z\\d_(\\[\"]*","gi")," - ").replace(/^[^a-z()\[\]\d\"]*|[^a-z()\[\]\d\"]*$/gi, "");
  909.        }
  910.        else
  911.        {
  912.        var t4 = t2.replace(/^the /i, "")
  913.        t3 = t1.replace(RegExp("[^a-z\\d_)\\]\"]*(" + a + t4 + b + ")[^a-z\\d_(\\[\"]*","gi")," - ").replace(/^[^a-z()\[\]\d\"]*|[^a-z()\[\]\d\"]*$/gi, "");
  914.        }
  915.        return t3.match(/\S/) ? t3 : t1;
  916.    }
  917.    catch (e)
  918.    {
  919.    return t1;
  920.    }
  921. }
  922.  
  923. convert = function(min)
  924. {
  925.    var parts = min.split(':'),
  926.    minutes = +parts[0],
  927.    seconds = +parts[1];
  928.    return minutes * 60 + seconds;
  929. }
  930.  
  931. strip = function (t)
  932. {
  933.    try
  934.    {
  935.    t = t.replace(/[\.,\!\?\:;'"\-_]/g,"").toLowerCase();
  936.    return t;
  937.    } catch (e)
  938.    {}
  939. }
  940.  
  941. clean = function (t)
  942. {
  943.    try
  944.    {
  945.    return t.replace(/'/g, "").toLowerCase();
  946.    } catch (e) {}
  947. }
  948.  
  949. youtube_search = function (state_change_callback, p_on_search_finished_callback)
  950. {
  951.        this.xmlhttp = null;
  952.        this.http_callback_funct = null;
  953.        this.ready_state_change_callback = state_change_callback;
  954.        this.search_done = false;
  955.        this.on_search_finished_callback = p_on_search_finished_callback;
  956.        this.yt_link;
  957.        this.search_artist;
  958.        this.search_title;
  959.        this.metadata;
  960.  
  961.    this.on_state_change = function ()
  962.    {
  963.    if (this.xmlhttp != null && this.xmlhttp.readyState == 4 && this.xmlhttp.status == 200 && this.http_callback_funct != null)
  964.    this.http_callback_funct();
  965.    }
  966.  
  967.    this.StartSearch = function (p_artist, p_title, p_extra_metadata)
  968.    {
  969.        this.search_artist = p_artist;
  970.        this.search_title = p_title;
  971.        this.metadata = p_extra_metadata;
  972.        this.http_callback_funct = null;
  973.        this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  974.  
  975.        var URL = "https://www.youtube.com/results?search_query=" + encodeURIComponent(p_artist + " " + p_title);
  976.  
  977.         this.http_callback_funct = this.AnalyseSearch;
  978.         this.xmlhttp.open("GET", URL);
  979.         this.xmlhttp.onreadystatechange = this.ready_state_change_callback;
  980.         this.xmlhttp.send();
  981.     }
  982.  
  983.     this.AnalyseSearch = function ()
  984.     {
  985.         var text = this.xmlhttp.responsetext;
  986.         var doc = new ActiveXObject("htmlfile");
  987.         doc.open();
  988.         var div = doc.createElement("div");
  989.         div.innerHTML = text;
  990.         var data = div.getElementsByTagName("a");
  991.         var url = "";
  992.         var first_match;
  993.  
  994.         re_test:
  995.  
  996.         for (var i = 0; i < data.length; i++)
  997.         {
  998.         if (data[i].href.indexOf("about:/watch?v=") == 0)
  999.            {
  1000.                 i++; //link
  1001.  
  1002.             //Find Title[OLD]
  1003.             /*{
  1004.             var st = text.indexOf( data[i].href.replace("about:/watch?", "") );
  1005.             var str = "a class=\"yt-uix-tile-link yt-ui-ellipsis yt-ui-ellipsis-2 yt-uix-sessionlink spf-link\">";
  1006.             st = text.indexOf(str, st) + str.length;
  1007.             var et = text.indexOf("</a>", st);
  1008.             var youtube_title = text.substr(st, et - st);
  1009.             var Y_Title = youtube_title.replace("&#39;", "'").replace("&quot;", "''").replace("&amp;", "&").replace("&#39;", "'").replace("&quot;", "''").replace("&amp;", "&").replace("&#39;", "'").replace("&quot;", "''").replace("&amp;", "&").replace("&#39;", "'").replace("&quot;", "''").replace("&amp;", "&").replace("&#39;", "'").replace("&quot;", "''").replace("&amp;", "&").replace("&#39;", "'").replace("&quot;", "''").replace("&amp;", "&").replace("&#39;", "'").replace("&quot;", "''").replace("&amp;", "&").replace("&#39;", "'").replace("&quot;", "''").replace("&amp;", "&").replace("&#39;", "'").replace("&quot;", "''").replace("&amp;", "&").replace("&#39;", "'").replace("&quot;", "''").replace("&amp;", "&").replace("&#39;", "'").replace("&quot;", "''").replace("&amp;", "&").replace("&#39;", "'").replace("&quot;", "''").replace("&amp;", "&").replace("&#39;", "'").replace("&quot;", "''").replace("&amp;", "&").replace("&#39;", "'").replace("&quot;", "''").replace("&amp;", "&").replace("&#39;", "'").replace("&quot;", "''").replace("&amp;", "&").replace("&#39;", "'").replace("&quot;", "''").replace("&amp;", "&").replace("&#39;", "'").replace("&quot;", "''").replace("&amp;", "&").replace("&#39;", "'").replace("&quot;", "''").replace("&amp;", "&").replace("&#39;", "'").replace("&quot;", "''").replace("&amp;", "&").replace("&#39;", "'").replace("&quot;", "''").replace("&amp;", "&").replace("&#39;", "'").replace("&quot;", "''").replace("&amp;", "&").replace("&#39;", "'").replace("&quot;", "''").replace("&amp;", "&").replace("&#39;", "'").replace("&quot;", "''").replace("&amp;", "&").replace("&#39;", "'").replace("&quot;", "''").replace("&amp;", "&").replace("&#39;", "'").replace("&quot;", "''").replace("&amp;", "&").replace("&#39;", "'").replace("&quot;", "''").replace("&amp;", "&").replace("&#39;", "'").replace("&quot;", "''").replace("&amp;", "&").replace("&#39;", "'").replace("&quot;", "''").replace("&amp;", "&").replace("&#39;", "'").replace("&quot;", "''").replace("&amp;", "&").replace("&#39;", "'").replace("&quot;", "''").replace("&amp;", "&").replace("&#39;", "'").replace("&quot;", "''").replace("&amp;", "&").replace("&#39;", "'").replace("&quot;", "''").replace("&amp;", "&").replace("&#39;", "'").replace("&quot;", "''").replace("&amp;", "&").replace("&#39;", "'").replace("&quot;", "''").replace("&amp;", "&").replace("&#39;", "'").replace("&quot;", "''").replace("&amp;", "&").replace("&#39;", "'").replace("&quot;", "''").replace("&amp;", "&").replace("&#39;", "'").replace("&quot;", "''").replace("&amp;", "&").replace("&#39;", "'").replace("&quot;", "''").replace("&amp;", "&").replace("&#39;", "'").replace("&quot;", "''").replace("&amp;", "&").replace("&#39;", "'").replace("&quot;", "''").replace("&amp;", "&").replace("&#39;", "'").replace("&quot;", "''").replace("&amp;", "&").replace("&#39;", "'").replace("&quot;", "''").replace("&amp;", "&").replace("&#39;", "'").replace("&quot;", "''").replace("&amp;", "&").replace("&#39;", "'").replace("&quot;", "''").replace("&amp;", "&").replace("&#39;", "'").replace("&quot;", "''").replace("&amp;", "&").replace("&#39;", "'").replace("&quot;", "''").replace("&amp;", "&").replace("&#39;", "'").replace("&quot;", "''").replace("&amp;", "&").replace("&#39;", "'").replace("&quot;", "''").replace("&amp;", "&").replace("&#39;", "'").replace("&quot;", "''").replace("&amp;", "&").replace("&#39;", "'").replace("&quot;", "''").replace("&amp;", "&").replace("&#39;", "'").replace("&quot;", "''").replace("&amp;", "&");
  1010.             //p.console("Title: " + Y_Title);
  1011.             }*/
  1012.            
  1013.             //Find Title[NEW]
  1014.             Y_Title = data[i].title;
  1015.             Remove_duration = Y_Title.substring(Y_Title.lastIndexOf(" - ")+1);
  1016.             Y_Title = data[i].title.replace(Remove_duration, "").trim();
  1017.             //p.console("Title: " + Y_Title);
  1018.                
  1019.             //Find minutes
  1020.             var s = text.indexOf( data[i].href.replace("about:/watch?", "") );
  1021.             var str = "<span class=\"video-time\" aria-hidden=\"true\">";
  1022.             s = text.indexOf(str, s) + str.length;
  1023.             var e = text.indexOf("</span>", s);
  1024.             var length = text.substr(s, e - s);
  1025.             length = convert(length);
  1026.             length = length ? length : "";
  1027.             if (!first_match)
  1028.  
  1029.             {                  
  1030.             //Artist title stripped if same as search_artist
  1031.             var stripped_title = strip_title(Y_Title, this.search_artist);
  1032.             first_match = "3dydfy://www.youtube.com/watch?" + (this.metadata ? this.metadata + "&" : "") + "fb2k_title=" + encodeURIComponent(stripped_title) + "&3dydfy_alt_length=" + encodeURIComponent(length) + "&fb2k_artist=" + encodeURIComponent(this.search_artist) + "&" + data[i].href.replace("about:/watch?", "");
  1033.             }
  1034.             //3dydfy
  1035.             if (!this.IsGoodMatch(Y_Title))
  1036.             continue;
  1037.  
  1038.             url = "3dydfy://www.youtube.com/watch?" + (this.metadata ? this.metadata + "&" : "") + "fb2k_title=" + encodeURIComponent(this.search_title) + "&3dydfy_alt_length=" + encodeURIComponent(length) + "&fb2k_artist=" + encodeURIComponent(this.search_artist) + "&" + data[i].href.replace("about:/watch?", "");
  1039.             break;
  1040.             }
  1041.         }
  1042.  
  1043.         if (!url.length)
  1044.         url = first_match;
  1045.  
  1046.         this.yt_link = url;
  1047.  
  1048.         doc.close();
  1049.  
  1050.         this.on_search_finished_callback(url, this.search_artist, this.search_title);
  1051.         }
  1052.  
  1053.         this.IsGoodMatch = function (video_name)
  1054.         {
  1055.         var clean_vid_name = clean(strip(video_name));
  1056.         var clean_artist = clean(strip(this.search_artist));
  1057.         var clean_title = clean(strip(this.search_title));
  1058.  
  1059.         if (clean_vid_name.indexOf(clean_artist) != -1 && clean_vid_name.indexOf(clean_title) != -1 && clean_vid_name.indexOf("full album") == -1)
  1060.         {
  1061.             //p.console("GOOD MATCH");
  1062.             return true;
  1063.         }
  1064.         else
  1065.         {
  1066.             //p.console("BAD MATCH");
  1067.             return false;
  1068.         }
  1069.     }
  1070.  
  1071. }
  1072.  
  1073. //Call Search
  1074. do_youtube_search1 = function (p_artist, p_title)
  1075.     {
  1076.     var yt_search1 = new youtube_search(function ()
  1077.     {
  1078.     yt_search1.on_state_change();
  1079.     }, on_youtube_search1_done);
  1080.     yt_search1.StartSearch(p_artist, p_title);
  1081.     }
  1082.  
  1083. on_youtube_search1_done = function (link, p_artist, p_title)
  1084. {
  1085. var url2="";
  1086. url2 = link;
  1087. if (!url2)
  1088. {p.console("Track Or Artist - Not Exist!"); LOAD_ART();}
  1089.  
  1090. if (link && link.length)
  1091. {
  1092.            
  1093. //p.console("" + "\"" + link + "\"");
  1094. YT_URL = window.SetProperty("YT URL", link);
  1095. var tmppath = p.fso.GetFolder(fb.FoobarPath).ShortPath;
  1096. var str = tmppath + "\\foobar2000.exe /add ";
  1097. var go = str + link;
  1098. var tm = window.SetTimeout(function() {
  1099. p.run(go);
  1100. window.ClearTimeout(tm); tm = false;
  1101. }, 50);
  1102. }
  1103.     }
  1104. //**************************(END)**************************
  1105. this.artist = "";
  1106.  
  1107. //Set Panels
  1108. function pan1() { }
  1109. function pan2(x, y, w, h) {}
  1110. //---------------------------------------------------------
  1111.  
  1112. //Begin--->
  1113. var p = new panel("Youtube Radio", ["remap", "metadb"]);
  1114. var im = new pan2(0, 0, 0, 0);
  1115. var th = new pan1();
  1116.  
  1117. on_item_focus_change();
  1118. {
  1119. }
  1120.  
  1121. function on_metadb_changed() {
  1122. }
  1123.  
  1124. //Buttons---------------------------------------------------
  1125.  
  1126. var Buttons;
  1127. var g_tooltip = window.CreateTooltip();
  1128. var g_down = false;
  1129. var btn_down = null;
  1130. var cur_btn = null;
  1131.  
  1132. ButtonStates = {
  1133.     normal: 0,
  1134.     hover: 1,
  1135.     down: 2
  1136. }
  1137.  
  1138. function Button(x, y, w, h, img_src, func, tiptext)  {
  1139.     this.left = x;
  1140.     this.top = y;
  1141.     this.w = w;
  1142.     this.h = h;
  1143.     this.right = x + w;
  1144.     this.bottom = y + h;
  1145.     this.func = func;
  1146.     this.tiptext = tiptext;
  1147.     this.state = ButtonStates.normal;
  1148.     this.img_normal = img_src && img_src.normal ? gdi.Image(img_src.normal) : null;
  1149.     this.img_hover = img_src && img_src.hover ? gdi.Image(img_src.hover) : this.img_normal;
  1150.     this.img_down = img_src && img_src.down ? gdi.Image(img_src.down) : this.img_hover;
  1151.     this.img = this.img_normal;
  1152.    
  1153.     this.alterImage = function(img_src) {
  1154.     this.img_normal = img_src && img_src.normal ? gdi.Image(img_src.normal) : null;
  1155.     this.img_hover = img_src && img_src.hover ? gdi.Image(img_src.hover) : this.img_normal;
  1156.     this.img_down = img_src && img_src.down ? gdi.Image(img_src.down) : this.img_hover;
  1157.        
  1158.     this.changeState(this.state);
  1159.     }
  1160.    
  1161.     this.traceMouse = function (x, y) {
  1162.     var b = (this.left < x) && (x < this.right) && (this.top < y) && (y < this.bottom);
  1163.     if (b)
  1164.     g_down ? this.changeState(ButtonStates.down) : this.changeState(ButtonStates.hover);
  1165.     else
  1166.     this.changeState(ButtonStates.normal);
  1167.     return b;
  1168.     }
  1169.    
  1170.     this.changeState = function (newstate) {
  1171.     if (newstate != this.state)
  1172.     window.RepaintRect(this.left, this.top, this.w, this.h);
  1173.     this.state = newstate;
  1174.     switch (this.state)
  1175.     {
  1176.     case ButtonStates.normal:
  1177.     this.img = this.img_normal;
  1178.     break;
  1179.            
  1180.     case ButtonStates.hover:
  1181.     this.img = this.img_hover;
  1182.     break;
  1183.            
  1184.     case ButtonStates.down:
  1185.     this.img = this.img_down;
  1186.     break;
  1187.            
  1188.     default:
  1189.     this.img = null;
  1190.         }
  1191.     }
  1192.    
  1193.     this.draw = function (gr) {
  1194.     this.img && gr.DrawImage(this.img, this.left, this.top, this.w, this.h, 0, 0, this.w, this.h);
  1195.     }
  1196.    
  1197.     this.onClick = function () {
  1198.     this.func && this.func(x,y);
  1199.     }
  1200.    
  1201.     this.onMouseIn = function() {
  1202.     g_tooltip.Text = this.tiptext;
  1203.     g_tooltip.Activate();
  1204.     }
  1205.    
  1206.     this.onMouseOut = function() {
  1207.     g_tooltip.Deactivate();
  1208.     }
  1209. }
  1210.  
  1211. function buttonsDraw(gr) {
  1212.     for (i in Buttons) {
  1213.     Buttons[i].draw(gr);
  1214.     }
  1215. }
  1216.  
  1217. function buttonsTraceMouse(x, y) {
  1218.     var btn = null;
  1219.     for (i in Buttons) {
  1220.     if (Buttons[i].traceMouse(x, y) && !btn)
  1221.     btn = Buttons[i];
  1222.     }
  1223.  
  1224.     return btn;
  1225. }
  1226.  
  1227. function on_mouse_move(x, y) {
  1228.     var btn = buttonsTraceMouse(x, y);
  1229.    
  1230.     if (btn != cur_btn) {
  1231.     cur_btn && cur_btn.onMouseOut();
  1232.     btn && btn.onMouseIn();
  1233.     }
  1234.    
  1235.     cur_btn = btn;
  1236. }
  1237.  
  1238. function on_mouse_lbtn_down(x, y) {
  1239.     g_down = true;
  1240.     btn_down = cur_btn;
  1241.  
  1242.     if (cur_btn) {
  1243.     cur_btn.changeState(ButtonStates.down);
  1244.     }
  1245. }
  1246.  
  1247. function on_mouse_lbtn_up(x, y) {
  1248.     if (cur_btn) {
  1249.     cur_btn.changeState(ButtonStates.hover);
  1250.     if( btn_down == cur_btn )
  1251.     cur_btn.onClick(x, y);
  1252.     }
  1253.     g_down = false;
  1254. }
  1255.  
  1256. function on_mouse_leave() {
  1257.     if (cur_btn) {
  1258.     cur_btn.changeState(ButtonStates.normal);
  1259.     }
  1260. }
  1261.  
  1262. function on_size() {
  1263.     ww = window.Width;
  1264.     wh = window.Height;
  1265.     window.Repaint();
  1266. }
  1267.  
  1268. //Background
  1269. this.dui = window.InstanceType;
  1270. function on_paint(gr) {
  1271.    
  1272.     if (this.dui) {
  1273.     col = window.GetColorDUI(1);
  1274.     gr.FillSolidRect(0, 0, ww, wh, col);
  1275.     }
  1276.     else
  1277.     {
  1278.     col = window.GetColorCUI(3);    
  1279.     }
  1280.  
  1281.     buttonsDraw(gr);
  1282.    
  1283. }
  1284.  
  1285. function RGB(r,g,b) {
  1286. return (0xff000000|(r<<16)|(g<<8)|(b));
  1287. }
  1288.  
  1289. function on_colors_changed() {
  1290. window.Repaint();
  1291. }
  1292.  
  1293. //Init Buttons--------------------------------------------
  1294.  
  1295. //Custom colour
  1296. var custom = RGB(255,255,255);
  1297.  
  1298. //Button width
  1299. var bw = 24;
  1300.  
  1301. //Button height
  1302. var bh = 20;
  1303.  
  1304. //Button position
  1305. var top_margin = 0;
  1306. var left_margin = 0;
  1307.  
  1308. var image_path0 = window.GetProperty("Button Path", fb.ProfilePath + "image");
  1309. var image_path = (image_path0 + "\\");
  1310.  
  1311. //These 2 lines of code lock the panel size.
  1312. //window.MinWidth = window.MaxWidth = 24;
  1313. //window.MinHeight = window.MaxHeight = 20;
  1314.  
  1315. Buttons = {
  1316.     but1: new Button(left_margin,top_margin,bw,bh, {normal: image_path + "youtube0.png", hover: image_path + "youtube1.png"}, function(){
  1317.     p.rbtn_up(24, 17);
  1318.     }, "Youtube")
  1319.    
  1320. }
  1321.  
  1322. function on_mouse_rbtn_up(x, y) {
  1323. return true;
  1324. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement