Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==PREPROCESSOR==
- // @name "Youtube Radio"
- // @author "Mire777"
- // @feature "v1.4"
- // @feature "watch-metadb"
- // ==/PREPROCESSOR==
- //Properties
- auto_yt = window.GetProperty("YT Playlist", "0");
- AUTO = window.GetProperty("YT Auto", "0");
- ooo2 = window.GetProperty("YT Track", "");
- START_ARTIST = window.GetProperty("YT Station", "");
- last_fm = window.GetProperty("YT Similar", "");
- YT_URL = window.GetProperty("YT URL", "");
- art = window.GetProperty("YT Artist Variety (1-20)", "20");
- sng = window.GetProperty("YT Song Hotness (1-20)", "20");
- gnr = window.GetProperty("YT Tag Hotness (1-100)", "27");
- pls = window.GetProperty("FB Playlist", "YT Radio");
- var MF_GRAYED = 0x00000001;
- var MF_STRING = 0x00000000;
- var IDC_ARROW = 32512;
- var IDC_HAND = 32649;
- function RGB(r, g, b) {
- return (0xff000000 | (r << 16) | (g << 8) | (b));
- }
- function RGBA(r, g, b, a) {
- return ((a << 24) | (r << 16) | (g << 8) | (b));
- }
- function on_colors_changed() {
- p.colors_changed();
- }
- function on_selection_changed() {
- p.item_focus_change();
- }
- function on_playlist_switch() {
- set_focus0(); //Check Playlist
- }
- function on_playback_new_track() {
- p.item_focus_change();
- downloadLFM();
- }
- function on_playback_dynamic_info_track() {
- p.item_focus_change();
- }
- function on_playback_stop() {
- p.item_focus_change();
- }
- function on_item_focus_change() {
- p.item_focus_change();
- }
- function on_mouse_leave() {
- }
- function on_mouse_rbtn_up(x, y) {
- p.rbtn_up(x, y);
- return true;
- }
- //Playlist
- function GetPlaylistID(Playlist_Name)
- {
- for (var i = 0; i < fb.PlaylistCount; i++)
- {
- if (fb.GetPlaylistName(i) == Playlist_Name)
- {
- return i;
- }
- }
- // create playlist if it doesn't exist
- fb.CreatePlaylist(fb.PlaylistCount, Playlist_Name);
- return i;
- }
- //Playlist(Check)
- function GetPlaylistID0(Playlist_Name)
- {
- for (var i = 0; i < fb.PlaylistCount; i++)
- if (fb.GetPlaylistName(i) == Playlist_Name)
- {
- return i;
- }
- }
- //Focus on playlist(Check)
- function set_focus0()
- { if (pls>"")
- {
- var PL_NM = (GetPlaylistID0(pls + " ["+ START_ARTIST +"]"));
- if (fb.ActivePlaylist == PL_NM) {auto_yt = 1; window.SetProperty("YT Playlist", "1");}
- else
- {auto_yt = 0; window.SetProperty("YT Playlist", "0");}
- }
- }
- //Focus on playlist(YT Radio)
- function set_focus()
- { if (pls>"")
- fb.ActivePlaylist = (GetPlaylistID(pls + " ["+ START_ARTIST +"]"));
- }
- //Focus on playlist(Same Video)
- function set_focus2()
- { if (pls>"")
- fb.ActivePlaylist = (GetPlaylistID(pls + " [Same Video]"));
- }
- //Focus on playlist(Search Videos)
- function set_focus3()
- { if (pls>"")
- fb.ActivePlaylist = (GetPlaylistID(pls + " [Search Videos]"));
- }
- //Panel
- function panel(name, features) {
- this.item_focus_change = function() {
- if (!this.metadb_func) return;
- switch(this.selection_mode) {
- case 0:
- this.metadb = fb.GetSelection();
- break;
- case 1:
- this.metadb = fb.IsPlaying ? fb.GetNowPlaying() : fb.GetFocusItem();
- break;
- case 2:
- this.metadb = fb.GetFocusItem();
- break;
- }
- if (this.metadb) on_metadb_changed();
- }
- //Metadb
- this.metadb = fb.IsPlaying ? fb.GetNowPlaying() : fb.GetFocusItem();
- //Size
- this.size = function() {
- this.w = window.Width;
- this.h = window.Height;
- }
- //Move
- this.move = function(x, y) {
- this.mx = x;
- this.my = y;
- }
- //Menu
- this.rbtn_up = function(x, y) {
- var _menu = window.CreatePopupMenu();
- var idx;
- switch(true) {
- case typeof th == "object":
- case typeof im == "object":
- on_item_focus_change()
- if (pls>"")
- {
- if(AUTO==1) _menu.AppendMenuItem(MF_STRING, 1902, "Youtube Radio");
- if(AUTO==0) _menu.AppendMenuItem(MF_STRING, 1903, "Youtube Radio");
- _menu.CheckMenuItem(1902, AUTO?1:0);
- _menu.AppendMenuSeparator();
- {
- if(auto_yt==1 && AUTO==1 && START_ARTIST>"") {_menu.AppendMenuItem(MF_STRING, 22, "Get Next Video");}
- else
- {_menu.AppendMenuItem(MF_STRING| MF_GRAYED, 2000, "Get Next Video");}
- _menu.AppendMenuItem(MF_STRING, 401, "Search Videos");
- _menu.AppendMenuSeparator();
- _menu.AppendMenuItem(MF_STRING, 1914, "Start Radio Station");
- p.artist = p.eval("%artist%");
- if (p.artist == "" || p.artist == "?") {_menu.AppendMenuItem(MF_STRING| MF_GRAYED, 2000, "Same Artist Station");}
- else
- {_menu.AppendMenuItem(MF_STRING, 1915, "Same Artist Station");}
- _menu.AppendMenuSeparator();
- p.artist = p.eval("%artist%");
- if (p.artist == "" || p.artist == "?") {_menu.AppendMenuItem(MF_STRING| MF_GRAYED, 2000, "Open Same Video");}
- else
- {_menu.AppendMenuItem(MF_STRING, 403, "Open Same Video");}
- p.artist = p.eval("%artist%");
- if (p.artist == "" || p.artist == "?") {_menu.AppendMenuItem(MF_STRING| MF_GRAYED, 2000, "Find in Browser");}
- else
- {_menu.AppendMenuItem(MF_STRING, 404, "Find in Browser");}
- _menu.AppendMenuSeparator();
- _menu.AppendMenuItem(MF_STRING, 9, "Properties...");
- }
- }
- }
- if (pls=="") {_menu.AppendMenuItem(MF_STRING, 9, "Please Set: (FB Playlist)");}
- if (utils.IsKeyPressed(0x10)) _menu.AppendMenuItem(MF_STRING, 10, "Configure...");
- idx = _menu.TrackPopupMenu(x, y);
- switch(idx) {
- case 9:
- window.ShowProperties();
- break;
- case 10:
- window.ShowConfigure();
- break;
- case 22:
- set_focus(); //Focus on playlist
- downloadLFM();
- break;
- case 401:
- set_focus3(); //Focus on playlist
- fb.RunMainMenuCommand("View/Youtube Source");
- break;
- case 403:
- this.metadb = fb.IsPlaying ? fb.GetNowPlaying() : fb.GetFocusItem();
- set_focus2(); //Focus on playlist
- downloadART_TITLE();
- break;
- case 404:
- p.artist = p.eval("%artist% %title%");
- p.browser("http://www.youtube.com/results?search_query=" + encodeURIComponent(p.artist));
- break;
- case 1902:
- AUTO = 0;
- window.SetProperty("YT Auto", "0");
- break;
- case 1903:
- AUTO = 1;
- window.SetProperty("YT Auto", "1");
- break;
- case 1914:
- var Start;
- Start = this.InputBox("Type Artist to Start Station\n\n( *genre - will play genre station)", "Youtube Radio", "");
- if (Start=="")
- {
- }
- else
- {
- auto_yt = 1;
- window.SetProperty("YT Playlist", "1");
- AUTO = "1"
- window.SetProperty("YT Auto", "1");
- START_ARTIST = Start;
- window.SetProperty("YT Station", Start);
- set_focus(); //Focus on playlist
- downloadLFM();
- }
- break;
- case 1915:
- this.metadb = fb.IsPlaying ? fb.GetNowPlaying() : fb.GetFocusItem();
- p.artist = p.eval("%artist%");
- if (p.artist == "" || p.artist == "?") return;
- START_ARTIST = p.artist;
- window.SetProperty("YT Station", p.artist);
- auto_yt = 1;
- window.SetProperty("YT Playlist", "1");
- AUTO = "1"
- window.SetProperty("YT Auto", "1");
- set_focus(); //Focus on playlist
- downloadLFM();
- break;
- }
- _menu.Dispose();
- }
- //Features init
- this.features_init = function() {
- for (i = 0; i < this.features.length; i++) {
- switch(this.features[i]) {
- case "metadb":
- this.selection_mode = 1;
- break;
- case "remap":
- this.artist_tf = ("%artist%");
- break;
- }
- }
- }
- this.check_feature = function(f) {
- for (i = 0; i < this.features.length; i++) {
- if (this.features[i] == f) return true;
- }
- return false;
- }
- this.eval = function(tf) {
- if (!this.metadb || tf == "") return "";
- if (fb.IsPlaying && this.metadb.RawPath.indexOf("file://") != 0) {
- return fb.TitleFormat(tf).Eval();
- } else {
- return fb.TitleFormat(tf).EvalWithMetadb(this.metadb);
- }
- }
- //Console Msg
- this.console = function(message) {
- this.name = "Youtube Radio"
- fb.trace(this.name + ": " + message);
- }
- //Trim
- String.prototype.trim = function() {
- return this.replace(/^\s+|\s+$/g, "");
- }
- //Input Box
- this.InputBox = function(prompt, title, value) {
- prompt = prompt.replace(/"/g, '" + Chr(34) + "').replace(/\n/g, '" + Chr(13) + "');
- title = title.replace(/"/g, '" + Chr(34) + "');
- value = value.replace(/"/g, '" + Chr(34) + "');
- var temp_value = this.vb.eval('InputBox' + '("' + prompt + '", "' + title + '", "' + value + '")');
- if (typeof temp_value == "undefined") return value;
- 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");
- return temp_value.trim();
- }
- //Msg Box
- this.MsgBox = function(prompt, buttons, title) {
- prompt = prompt.replace(/"/g, '" + Chr(34) + "').replace(/\n/g, '" + Chr(13) + "');
- title = title.replace(/"/g, '" + Chr(34) + "');
- return this.vb.eval('MsgBox' + '("' + prompt + '", "' + buttons + '", "' + title + '")');
- }
- //Browser
- this.browser = function(command) {
- if (!this.run(command)) this.MsgBox("Unable to launch your default browser.", 0, "Youtube Radio");
- }
- //Run Command
- this.run = function(command) {
- try {
- this.WshShell.Run(command);
- return true;
- } catch(e) {
- return false;
- }
- }
- //futures
- this.metadb_func = typeof on_metadb_changed == "function";
- this.features = features;
- this.dui = window.InstanceType;
- this.metadb = fb.GetFocusItem();
- this.WshShell = new ActiveXObject("WScript.Shell");
- this.fso = new ActiveXObject("Scripting.FileSystemObject");
- this.vb = new ActiveXObject("ScriptControl");
- this.vb.Language = "VBScript";
- this.artist_tf = "%path%";
- this.features_init();
- this.metadb = fb.IsPlaying ? fb.GetNowPlaying() : fb.GetFocusItem();
- if (fb.GetFocusItem())
- {this.artist = fb.TitleFormat(this.artist_tf).EvalWithMetadb(this.metadb);}
- }
- //YT NAMES-------------------------------------------------
- //Clean Art Name
- CLEAN_ART_NAME = function (t)
- {
- try
- {
- 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","'");
- } catch (e) {}
- }
- //Clean Track Name
- CLEAN_TRACK_NAME = function (t)
- {
- try
- {
- 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(last_fm) + " -"," ").replace(decodeURIComponent(last_fm) + " - "," ").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(last_fm), " ").replace(" - Survival Remix","").replace(" Radio Mix","").replace(" Survival Remix","").replace("Survival Remix","").replace(decodeURIComponent(last_fm) + "-"," ").replace(decodeURIComponent(last_fm)," ").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();
- } catch (e) {}
- }
- //Clean Genre Name
- CLEAN_GENRE_NAME = function (t)
- {
- try
- {
- 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];
- } catch (e) {}
- }
- //*********************YT RADIO START**********************
- //SIMILAR--------------------------------------------------
- this.downloadLFM = function()
- { if (AUTO=="1")
- if (auto_yt=="1")
- { var randomnumber=Math.floor(Math.random()*art)
- var a=randomnumber;
- if (START_ARTIST == "" || START_ARTIST == "?") return;
- if (!this.xmlhttp) this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
- this.xmlhttp.open("GET", "http://www.last.fm/music/" + encodeURIComponent(START_ARTIST) + "/+similar"+ "?page=" + a, true);
- this.xmlhttp.send();
- this.xmlhttp.onreadystatechange = function() {
- if (this.xmlhttp.readyState == 4) {
- if (this.xmlhttp.status == 200) {
- var text = this.xmlhttp.responsetext;
- if (!this.doc) this.doc = new ActiveXObject("htmlfile");
- this.doc.open();
- var div = this.doc.createElement("div");
- div.innerHTML = text;
- var data = div.getElementsByTagName("a");
- var urls = [];
- for (i = 0; i < data.length; i++) {
- if (data[i].href.indexOf("about:/music/") == 0) urls.push(CLEAN_ART_NAME(data[i].href));
- }
- //select random URL
- var randomnumber = Math.floor(Math.random()*(20-50)+50);
- do{
- randomnumber = Math.floor(Math.random()*(20-50)+50);
- } while(randomnumber%2!=1);
- i=randomnumber;
- {
- //Start with urls[i]
- if (urls[i] > "")
- {
- //p.console("" + urls[i]);
- last_fm = window.SetProperty("YT Similar", urls[i]);
- last_fm = urls[i];
- window.SetProperty("YT Similar", urls[i]);
- }
- else
- {
- last_fm = window.SetProperty("YT Similar", "");
- last_fm = "";
- window.SetProperty("YT Similar", "");
- }
- }
- this.doc.close();
- if (START_ARTIST.indexOf("*")== 0) {downloadGENRE();}
- else
- if (last_fm == "" || last_fm == "?") {downloadLFM();}
- else
- downloadTRACK();
- } else {
- if (START_ARTIST.indexOf("*")== 0) {downloadGENRE();}
- else
- if (this.xmlhttp.status == 404) {p.console("HTTP error: " + this.xmlhttp.status); downloadLFM();}
- }
- }
- }
- }
- }
- //TRACK----------------------------------------------------
- this.downloadTRACK = function()
- {
- {var randomnumber=Math.floor(Math.random()*sng)
- var a=randomnumber;
- if (last_fm == "" || last_fm == "?") return;
- if (!this.xmlhttp) this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
- this.xmlhttp.open("GET", "http://www.last.fm/music/" + encodeURIComponent(last_fm) + "/+tracks" + "?page=" + a, true);
- this.xmlhttp.send();
- this.xmlhttp.onreadystatechange = function() {
- if (this.xmlhttp.readyState == 4) {
- if (this.xmlhttp.status == 200) {
- var text = this.xmlhttp.responsetext;
- if (!this.doc) this.doc = new ActiveXObject("htmlfile");
- this.doc.open();
- var div = this.doc.createElement("tr");
- div.innerHTML = text;
- var data = div.getElementsByTagName("td");
- var urls = [];
- for (i = 0; i < data.length; i++) {
- if (data[i].title) urls.push(CLEAN_TRACK_NAME(data[i].title));
- }
- //select random URL
- var randomnumber = Math.floor(Math.random()*Math.max(urls.length));
- i=randomnumber;
- {
- //Start with urls[i]
- if (urls[i] > "")
- {
- p.console("" + last_fm + " - " + urls[i]);
- ooo2 = window.SetProperty("YT Track", urls[i]);
- ooo2 = urls[i];
- window.SetProperty("YT Track", urls[i]);
- }
- else
- {
- ooo2 = window.SetProperty("YT Track", "");
- ooo2 = "";
- window.SetProperty("YT Track", "");
- }
- }
- this.doc.close();
- if (ooo2 == "" || ooo2 == "?") {downloadLFM();}
- else
- set_focus(); //focus on playlist
- downloadYT(decodeURIComponent(last_fm), decodeURIComponent(ooo2));
- } else {
- p.console("HTTP error: " + this.xmlhttp.status);
- if (START_ARTIST.indexOf("*")== 0) {downloadGENRE();}
- else
- if (this.xmlhttp.status == 404) {downloadLFM();}
- }
- }
- }
- }
- }
- //SAME VIDEO-----------------------------------------------
- this.downloadART_TITLE = function()
- {
- var artist0 = p.eval("%artist%");
- var title0 = p.eval("%title%");
- if(artist0 > "?" && title0 > "?") {set_focus2(); downloadYT(decodeURIComponent(artist0), decodeURIComponent(title0));}
- }
- //GENRE----------------------------------------------------
- this.downloadGENRE = function()
- {
- if (START_ARTIST.indexOf("*")== 0)
- { var randomnumber=Math.floor(Math.random()*gnr)
- var a=randomnumber;
- if (START_ARTIST == "" || START_ARTIST == "?") return;
- if (!this.xmlhttp) this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
- this.xmlhttp.open("GET", "http://www.last.fm/music/+tag/" + encodeURIComponent(START_ARTIST).replace("*","") + "?page=" + a, true);
- this.xmlhttp.send();
- this.xmlhttp.onreadystatechange = function() {
- if (this.xmlhttp.readyState == 4) {
- if (this.xmlhttp.status == 200) {
- var text = this.xmlhttp.responsetext;
- if (!this.doc) this.doc = new ActiveXObject("htmlfile");
- this.doc.open();
- var div = this.doc.createElement("li");
- div.innerHTML = text;
- var data = div.getElementsByTagName("a");
- var urls = [];
- for (i = 0; i < data.length; i++) {
- if (data[i].className.indexOf("name") == 0)
- if (data[i].href.indexOf("about:/music/") == 0) urls.push(CLEAN_GENRE_NAME(data[i].href));
- }
- //select random URL
- var randomnumber = Math.floor(Math.random()*(0-9)+9);
- do{
- randomnumber = Math.floor(Math.random()*(0-9)+9);
- } while(randomnumber%2!=0);
- i=randomnumber;
- {
- //Start with urls[i]
- if (urls[i] > "")
- {
- //p.console("" + urls[i]);
- last_fm = window.SetProperty("YT Similar", urls[i]);
- last_fm = urls[i];
- window.SetProperty("YT Similar", urls[i]);
- }
- else
- {
- last_fm = window.SetProperty("YT Similar", "");
- last_fm = "";
- window.SetProperty("YT Similar", "");
- }
- }
- this.doc.close();
- if (last_fm == "" || last_fm == "?") {downloadGENRE();}
- else
- downloadTRACK();
- } else {
- p.console("HTTP error: " + this.xmlhttp.status);
- if (this.xmlhttp.status == 404) {downloadGENRE();}
- }
- }
- }
- }
- }
- //LOAD YOUTUBE VIDEO---------------------------------------
- //Convert minutes
- convert = function(min)
- {
- var parts = min.split(':'),
- minutes = +parts[0],
- seconds = +parts[1];
- return minutes * 60 + seconds;
- }
- //Start
- this.downloadYT = function(p_art, p_titl)
- {
- if (!this.xmlhttp) this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
- this.xmlhttp.open("GET", "http://www.youtube.com/results?search_query=" + encodeURIComponent(p_art) + " %2D " + encodeURIComponent(p_titl), true);
- this.xmlhttp.send();
- this.xmlhttp.onreadystatechange = function() {
- if (this.xmlhttp.readyState == 4) {
- if (this.xmlhttp.status == 200) {
- var text = this.xmlhttp.responsetext;
- if (!this.doc) this.doc = new ActiveXObject("htmlfile");
- this.doc.open();
- var div = this.doc.createElement("div");
- div.innerHTML = text;
- var data = div.getElementsByTagName("a");
- var urls = [];
- //Find minutes..
- for (var i = 0; i < 34; i++)
- {
- if (data[i].href.indexOf("about:/watch?v=") == 0)
- {
- i++;
- //p.console("I: " + i);
- var s = text.indexOf( data[i].href.replace("about:/watch?", "") );
- var str = "<span class=\"video-time\">";
- s = text.indexOf(str, s) + str.length;
- var e = text.indexOf("</span>", s);
- var length = text.substr(s, e - s);
- length = convert(length);
- length = length ? length : "";
- }}
- if (length=="")
- {
- for (var i = 0; i < 35; i++)
- {
- if (data[i].href.indexOf("about:/watch?v=") == 0)
- {
- i++;
- //p.console("I: " + i);
- var s = text.indexOf( data[i].href.replace("about:/watch?", "") );
- var str = "<span class=\"video-time\">";
- s = text.indexOf(str, s) + str.length;
- var e = text.indexOf("</span>", s);
- var length = text.substr(s, e - s);
- length = convert(length);
- length = length ? length : "";
- }}
- }
- //Find video
- for (i = 0; i < data.length; i++) {
- if (data[i].href.indexOf("about:/watch?v=") == 0) urls.push("" + data[i].href.replace(/about:\//,"").replace("watch?",""));
- }
- i = 1;
- {
- //Start with urls[i]
- //p.console("" + urls[i]);
- if (urls[i] > "" && ooo2 > "")
- {
- YT_URL = window.SetProperty("YT URL", urls[i]);
- YT_URL = urls[i];
- window.SetProperty("YT URL", urls[i]);
- var tmppath = p.fso.GetFolder(fb.FoobarPath).ShortPath;
- var str = tmppath + "\\foobar2000.exe /add ";
- var go = str + "3dydfy://www.youtube.com/watch?fb2k_artist=" + encodeURIComponent(p_art) + "&fb2k_title=" + encodeURIComponent(p_titl) + "&3dydfy_alt_length=" + encodeURIComponent(length) + "&" + urls[i];
- p.run(go);
- }
- else
- {
- YT_URL = window.SetProperty("YT URL", "");
- YT_URL = "";
- window.SetProperty("YT URL", "");
- }
- }
- this.doc.close();
- if (YT_URL == "" || YT_URL == "?") {downloadLFM();}
- } else {
- p.console("HTTP error: " + this.xmlhttp.status);
- if (START_ARTIST.indexOf("*")== 0) {downloadGENRE();}
- else
- if (this.xmlhttp.status == 404) {downloadLFM();}
- }
- }
- }
- }
- //**************************(END)**************************
- this.artist = "";
- //Set Panels
- function pan1() { }
- function pan2(x, y, w, h) { }
- //---------------------------------------------------------
- //Begin--->
- var p = new panel("Youtube Radio", ["remap", "metadb"]);
- var im = new pan2(0, 0, 0, 0);
- var th = new pan1();
- on_item_focus_change();
- {
- }
- function on_metadb_changed() {
- }
- //Buttons---------------------------------------------------
- var Buttons;
- var g_tooltip = window.CreateTooltip();
- var g_down = false;
- var btn_down = null;
- var cur_btn = null;
- ButtonStates = {
- normal: 0,
- hover: 1,
- down: 2
- }
- function Button(x, y, w, h, img_src, func, tiptext) {
- this.left = x;
- this.top = y;
- this.w = w;
- this.h = h;
- this.right = x + w;
- this.bottom = y + h;
- this.func = func;
- this.tiptext = tiptext;
- this.state = ButtonStates.normal;
- this.img_normal = img_src && img_src.normal ? gdi.Image(img_src.normal) : null;
- this.img_hover = img_src && img_src.hover ? gdi.Image(img_src.hover) : this.img_normal;
- this.img_down = img_src && img_src.down ? gdi.Image(img_src.down) : this.img_hover;
- this.img = this.img_normal;
- this.alterImage = function(img_src) {
- this.img_normal = img_src && img_src.normal ? gdi.Image(img_src.normal) : null;
- this.img_hover = img_src && img_src.hover ? gdi.Image(img_src.hover) : this.img_normal;
- this.img_down = img_src && img_src.down ? gdi.Image(img_src.down) : this.img_hover;
- this.changeState(this.state);
- }
- this.traceMouse = function (x, y) {
- var b = (this.left < x) && (x < this.right) && (this.top < y) && (y < this.bottom);
- if (b)
- g_down ? this.changeState(ButtonStates.down) : this.changeState(ButtonStates.hover);
- else
- this.changeState(ButtonStates.normal);
- return b;
- }
- this.changeState = function (newstate) {
- if (newstate != this.state)
- window.RepaintRect(this.left, this.top, this.w, this.h);
- this.state = newstate;
- switch (this.state)
- {
- case ButtonStates.normal:
- this.img = this.img_normal;
- break;
- case ButtonStates.hover:
- this.img = this.img_hover;
- break;
- case ButtonStates.down:
- this.img = this.img_down;
- break;
- default:
- this.img = null;
- }
- }
- this.draw = function (gr) {
- this.img && gr.DrawImage(this.img, this.left, this.top, this.w, this.h, 0, 0, this.w, this.h);
- }
- this.onClick = function () {
- this.func && this.func(x,y);
- }
- this.onMouseIn = function() {
- g_tooltip.Text = this.tiptext;
- g_tooltip.Activate();
- }
- this.onMouseOut = function() {
- g_tooltip.Deactivate();
- }
- }
- function buttonsDraw(gr) {
- for (i in Buttons) {
- Buttons[i].draw(gr);
- }
- }
- function buttonsTraceMouse(x, y) {
- var btn = null;
- for (i in Buttons) {
- if (Buttons[i].traceMouse(x, y) && !btn)
- btn = Buttons[i];
- }
- return btn;
- }
- function on_mouse_move(x, y) {
- var btn = buttonsTraceMouse(x, y);
- if (btn != cur_btn) {
- cur_btn && cur_btn.onMouseOut();
- btn && btn.onMouseIn();
- }
- cur_btn = btn;
- }
- function on_mouse_lbtn_down(x, y) {
- g_down = true;
- btn_down = cur_btn;
- if (cur_btn) {
- cur_btn.changeState(ButtonStates.down);
- }
- }
- function on_mouse_lbtn_up(x, y) {
- if (cur_btn) {
- cur_btn.changeState(ButtonStates.hover);
- if( btn_down == cur_btn )
- cur_btn.onClick(x, y);
- }
- g_down = false;
- }
- function on_mouse_leave() {
- if (cur_btn) {
- cur_btn.changeState(ButtonStates.normal);
- }
- }
- function on_size() {
- ww = window.Width;
- wh = window.Height;
- window.Repaint();
- }
- //Background
- this.dui = window.InstanceType;
- function on_paint(gr) {
- if (this.dui) {
- col = window.GetColorDUI(1);
- gr.FillSolidRect(0, 0, ww, wh, col);
- }
- else
- {
- col = window.GetColorCUI(3);
- }
- buttonsDraw(gr);
- }
- function RGB(r,g,b) {
- return (0xff000000|(r<<16)|(g<<8)|(b));
- }
- function on_colors_changed() {
- window.Repaint();
- }
- //Init Buttons--------------------------------------------
- //Custom colour
- var custom = RGB(255,255,255);
- //Button width
- var bw = 24;
- //Button height
- var bh = 20;
- //Button position
- var top_margin = -1;
- var left_margin = 0;
- var image_path0 = window.GetProperty("Button Path", fb.ProfilePath + "image");
- var image_path = (image_path0 + "\\");
- //These 2 lines of code lock the panel size.
- //window.MinWidth = window.MaxWidth = 24;
- //window.MinHeight = window.MaxHeight = 20;
- Buttons = {
- but1: new Button(left_margin,top_margin,bw,bh, {normal: image_path + "youtube0.png", hover: image_path + "youtube1.png"}, function(){
- p.rbtn_up(24, 17);
- //downloadONE();
- }, "Youtube")
- }
- function on_mouse_rbtn_up(x, y) {
- return true;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement