GetCurrentPlayingSong() public method

public GetCurrentPlayingSong ( ) : Song
return Song
Ejemplo n.º 1
0
        public Song get(MusicPlayers player)
        {
            Song song = new Song("No one", "None");
            ProcessInfo p;
            switch (player)
            {

                //
                //Program Titles
                //

                //Foobar
                case MusicPlayers.Foobar2000:
                    p = getProcess(player);
                    if (p.Player != MusicPlayers.None)
                    {
                        Regex r = new Regex(@"(.*) - \[(.*?)\] (.*?)   \[", RegexOptions.IgnoreCase | RegexOptions.Singleline);
                        Match m = r.Match(p.Title);

                        //artist, title, album
                        if (m.Success)
                        {
                            song = new Song(m.Groups[1].ToString().Replace("  ", ""), m.Groups[3].ToString().Replace("  ", ""), m.Groups[2].ToString().Replace("  ", ""));
                        }
                    }
                    break;
                //AIMP3
                case MusicPlayers.AIMP3:
                    p = getProcess(player);
                    if (p.Player != MusicPlayers.None)
                    {
                        Regex r = new Regex(@"(.*) - (.*)$", RegexOptions.IgnoreCase | RegexOptions.Singleline);
                        Match m = r.Match(p.Title);

                        //artist, title, album
                        if (m.Success)
                        {
                            song = new Song(m.Groups[2].ToString().Replace("  ", ""), m.Groups[1].ToString().Replace("  ", ""));
                        }
                    }
                    break;
                //MediaMonkey
                case MusicPlayers.MediaMonkey:
                    p = getProcess(player);
                    if (p.Player != MusicPlayers.None)
                    {
                        Regex r = new Regex(@"(\d)\. (.*?) - (.*?) - MediaMonkey", RegexOptions.IgnoreCase | RegexOptions.Singleline);
                        Match m = r.Match(p.Title);
                        
                        //artist, title, album
                        if (m.Success)
                        {
                            song = new Song(m.Groups[2].ToString().Replace("  ", ""), m.Groups[3].ToString().Replace("  ", ""));
                        }
                    }
                    break;
                //MPC
                case MusicPlayers.MPC:
                    p = getProcess(player);
                    if (p.Player != MusicPlayers.None)
                    {
                        song = new Song(p.Title.Replace(".mp3", "").Replace(".wav", ""));
                    }
                    break;
                //Winamp
                case MusicPlayers.Winamp:
                    p = getProcess(player);
                    if (p.Player != MusicPlayers.None)
                    {
                        Regex r = new Regex(@"(\d)\. (.*?) - (.*?) - Winamp", RegexOptions.IgnoreCase | RegexOptions.Singleline);
                        Match m = r.Match(p.Title);
                        
                        //artist, title, album
                        if (m.Success)
                        {
                            song = new Song(m.Groups[2].ToString().Replace("  ", ""), m.Groups[3].ToString().Replace("  ", ""));
                        }
                    }
                    break;
                //VLC
                case MusicPlayers.VLC:
                    p = getProcess(player);
                    if (p.Player != MusicPlayers.None)
                    {
                        Regex r = new Regex(@"(.*?) - (.*?) - VLC media player", RegexOptions.IgnoreCase | RegexOptions.Singleline);
                        Match m = r.Match(p.Title);
                        
                        //artist, title, album
                        if (m.Success)
                        {
                            song = new Song(m.Groups[1].ToString().Replace("  ", ""), m.Groups[2].ToString().Replace("  ", ""));
                        }
                    }
                    break;
                //Spotify
                case MusicPlayers.Spotify:
                    p = getProcess(player);
                    if (p.Player != MusicPlayers.None)
                    {
                        Regex r = new Regex(@"(?<=Spotify - )(.*?) – (.*)$", RegexOptions.IgnoreCase | RegexOptions.Singleline);
                        Match m = r.Match(p.Title);
                        
                        if (m.Success)
                        {
                            song = new Song(m.Groups[1].ToString().Replace("  ", ""), m.Groups[2].ToString().Replace("  ", ""));
                        }
                    }
                    break;

                //
                //Browsers
                //
                
                case MusicPlayers.Grooveshark:
                    p = getProcess(player);
                    if (p.Player != MusicPlayers.None)
                    {
                        Regex r = new Regex(@"(?<=Grooveshark - )(.*?) by (.*?) - ", RegexOptions.IgnoreCase | RegexOptions.Singleline);
                        Match m = r.Match(p.Title);
                        
                        //artist, title, album
                        if (m.Success)
                        {
                            song = new Song(m.Groups[2].ToString().Replace("  ", ""), m.Groups[1].ToString().Replace("  ", ""));
                        }
                    }
                    break;

                //Youtube
                case MusicPlayers.Youtube:
                    p = getProcess(player);
                    if (p.Player != MusicPlayers.None)
                    {
                        Regex r = new Regex(@"(.*?) - YouTube", RegexOptions.IgnoreCase | RegexOptions.Singleline);
                        Match m = r.Match(p.Title);

                        if (m.Success)
                        {
                            song = new Song(m.Groups[1].ToString().Replace("  ", ""));
                        }
                    }
                    break;
                //Soundcloud
                case MusicPlayers.Soundcloud:
                    p = getProcess(player);
                    if (p.Player != MusicPlayers.None)
                    {
                        Regex r = new Regex(@"(?<=Soundcloud - )(.*?) - (.*?) - ", RegexOptions.IgnoreCase | RegexOptions.Singleline);
                        Match m = r.Match(p.Title);
                        
                        if (m.Success)
                        {
                            song = new Song(m.Groups[1].ToString().Replace("  ", ""), m.Groups[2].ToString().Replace("  ", ""));
                        }
                    }
                    break;
                //Pandora
                case MusicPlayers.Pandora:
                    p = getProcess(player);
                    if (p.Player != MusicPlayers.None)
                    {
                        Regex r = new Regex(@"(?<=Pandora - )(.*?) - (.*?) -", RegexOptions.IgnoreCase | RegexOptions.Singleline);
                        Match m = r.Match(p.Title);
                        
                        if (m.Success)
                        {
                            song = new Song(m.Groups[2].ToString().Replace("  ", ""), m.Groups[1].ToString().Replace("  ", ""));
                        }
                    }
                    break;
                //Plug.dj
                case MusicPlayers.Plug:
                    p = getProcess(player);
                    if (p.Player != MusicPlayers.None)
                    {
                        Regex r = new Regex(@"(?<=Plug.dj - )(.*?) - (.*?) - (.*?) -", RegexOptions.IgnoreCase | RegexOptions.Singleline);
                        Match m = r.Match(p.Title);

                        if (m.Success)
                        {
                            MessageBox.Show(m.Groups[1].ToString());
                            song = new Song(m.Groups[2].ToString().Replace("  ", ""), m.Groups[1].ToString().Replace("  ", ""), m.Groups[3].ToString().Replace("  ", ""));
                        }
                        else
                        {
                            Regex r2 = new Regex(@"(?<=Plug.dj - )(.*?) - (.*?) - ", RegexOptions.IgnoreCase | RegexOptions.Singleline);
                            Match m2 = r2.Match(p.Title);

                            if (m2.Groups[1].ToString() != "")
                            {
                                song = new Song(m2.Groups[2].ToString().Replace("  ", ""), m2.Groups[1].ToString().Replace("  ", ""));
                            }
                        }
                    }
                    break;
                //Zaycev.fm
                case MusicPlayers.Zaycev:
                    p = getProcess(player);
                    if (p.Player != MusicPlayers.None)
                    {
                        Regex r = new Regex(@"(?<=Zaycev - )(.*?)  -  (.*?) -", RegexOptions.IgnoreCase | RegexOptions.Singleline);
                        Match m = r.Match(p.Title);
                        
                        if (m.Success)
                        {
                            song = new Song(m.Groups[1].ToString().Replace("  ", ""), m.Groups[2].ToString().Replace("  ", ""));
                        }
                    }
                    break;
                //8Tracks
                case MusicPlayers.EightTracks:
                    p = getProcess(player);
                    if (p.Player != MusicPlayers.None)
                    {
                        Regex r = new Regex(@"(?<=tracks - )(.*?) - (.*?) -", RegexOptions.IgnoreCase | RegexOptions.Singleline);
                        Match m = r.Match(p.Title);
                        
                        //artist, title, album
                        if (m.Success)
                        {
                            song = new Song(m.Groups[2].ToString().Replace("  ", ""), m.Groups[1].ToString().Replace("  ", ""));
                        }
                    }
                    break;

                //
                //Custom APIs
                //
                case MusicPlayers.iTunes:
                    p = getProcess(player);
                    if (p.Player != MusicPlayers.None)
                    {
                        API.iTunes info = new API.iTunes();
                        song =  info.GetCurrentPlayingSong();
                    }
                    break;
                case MusicPlayers.Nightbot:

                    break;
                case MusicPlayers.Zune:

                    break;
                case MusicPlayers.Jriver:

                    break;
                case MusicPlayers.WindowsMP:
                    p = getProcess(player);
                    if (p.Player != MusicPlayers.None)
                    {
                        API.WMPSongInfo info = new API.WMPSongInfo();
                        song =  info.GetCurrentPlayingSong();
                    }
                break;
            }

            return song;
        }
Ejemplo n.º 2
0
        public Song get(MusicPlayers player)
        {
            Song        song = new Song("No one", "None");
            ProcessInfo p;

            switch (player)
            {
            //
            //Program Titles
            //

            //Foobar
            case MusicPlayers.Foobar2000:
                p = getProcess(player);
                if (p.Player != MusicPlayers.None)
                {
                    Regex r = new Regex(@"(.*) - \[(.*?)\] (.*?)   \[", RegexOptions.IgnoreCase | RegexOptions.Singleline);
                    Match m = r.Match(p.Title);

                    //artist, title, album
                    if (m.Success)
                    {
                        song = new Song(m.Groups[1].ToString().Replace("  ", ""), m.Groups[3].ToString().Replace("  ", ""), m.Groups[2].ToString().Replace("  ", ""));
                    }
                }
                break;

            //AIMP3
            case MusicPlayers.AIMP3:
                p = getProcess(player);
                if (p.Player != MusicPlayers.None)
                {
                    Regex r = new Regex(@"(.*) - (.*)$", RegexOptions.IgnoreCase | RegexOptions.Singleline);
                    Match m = r.Match(p.Title);

                    //artist, title, album
                    if (m.Success)
                    {
                        song = new Song(m.Groups[2].ToString().Replace("  ", ""), m.Groups[1].ToString().Replace("  ", ""));
                    }
                }
                break;

            //MediaMonkey
            case MusicPlayers.MediaMonkey:
                p = getProcess(player);
                if (p.Player != MusicPlayers.None)
                {
                    Regex r = new Regex(@"(\d)\. (.*?) - (.*?) - MediaMonkey", RegexOptions.IgnoreCase | RegexOptions.Singleline);
                    Match m = r.Match(p.Title);

                    //artist, title, album
                    if (m.Success)
                    {
                        song = new Song(m.Groups[2].ToString().Replace("  ", ""), m.Groups[3].ToString().Replace("  ", ""));
                    }
                }
                break;

            //MPC
            case MusicPlayers.MPC:
                p = getProcess(player);
                if (p.Player != MusicPlayers.None)
                {
                    song = new Song(p.Title.Replace(".mp3", "").Replace(".wav", ""));
                }
                break;

            //Winamp
            case MusicPlayers.Winamp:
                p = getProcess(player);
                if (p.Player != MusicPlayers.None)
                {
                    Regex r = new Regex(@"(\d)\. (.*?) - (.*?) - Winamp", RegexOptions.IgnoreCase | RegexOptions.Singleline);
                    Match m = r.Match(p.Title);

                    //artist, title, album
                    if (m.Success)
                    {
                        song = new Song(m.Groups[2].ToString().Replace("  ", ""), m.Groups[3].ToString().Replace("  ", ""));
                    }
                }
                break;

            //VLC
            case MusicPlayers.VLC:
                p = getProcess(player);
                if (p.Player != MusicPlayers.None)
                {
                    Regex r = new Regex(@"(.*?) - (.*?) - VLC media player", RegexOptions.IgnoreCase | RegexOptions.Singleline);
                    Match m = r.Match(p.Title);

                    //artist, title, album
                    if (m.Success)
                    {
                        song = new Song(m.Groups[1].ToString().Replace("  ", ""), m.Groups[2].ToString().Replace("  ", ""));
                    }
                }
                break;

            //Spotify
            case MusicPlayers.Spotify:
                p = getProcess(player);
                if (p.Player != MusicPlayers.None)
                {
                    Regex r = new Regex(@"(?<=Spotify - )(.*?) – (.*)$", RegexOptions.IgnoreCase | RegexOptions.Singleline);
                    Match m = r.Match(p.Title);

                    if (m.Success)
                    {
                        song = new Song(m.Groups[1].ToString().Replace("  ", ""), m.Groups[2].ToString().Replace("  ", ""));
                    }
                }
                break;

            //
            //Browsers
            //

            case MusicPlayers.Grooveshark:
                p = getProcess(player);
                if (p.Player != MusicPlayers.None)
                {
                    Regex r = new Regex(@"(?<=Grooveshark - )(.*?) by (.*?) - ", RegexOptions.IgnoreCase | RegexOptions.Singleline);
                    Match m = r.Match(p.Title);

                    //artist, title, album
                    if (m.Success)
                    {
                        song = new Song(m.Groups[2].ToString().Replace("  ", ""), m.Groups[1].ToString().Replace("  ", ""));
                    }
                }
                break;

            //Youtube
            case MusicPlayers.Youtube:
                p = getProcess(player);
                if (p.Player != MusicPlayers.None)
                {
                    Regex r = new Regex(@"(.*?) - YouTube", RegexOptions.IgnoreCase | RegexOptions.Singleline);
                    Match m = r.Match(p.Title);

                    if (m.Success)
                    {
                        song = new Song(m.Groups[1].ToString().Replace("  ", ""));
                    }
                }
                break;

            //Soundcloud
            case MusicPlayers.Soundcloud:
                p = getProcess(player);
                if (p.Player != MusicPlayers.None)
                {
                    Regex r = new Regex(@"(?<=Soundcloud - )(.*?) - (.*?) - ", RegexOptions.IgnoreCase | RegexOptions.Singleline);
                    Match m = r.Match(p.Title);

                    if (m.Success)
                    {
                        song = new Song(m.Groups[1].ToString().Replace("  ", ""), m.Groups[2].ToString().Replace("  ", ""));
                    }
                }
                break;

            //Pandora
            case MusicPlayers.Pandora:
                p = getProcess(player);
                if (p.Player != MusicPlayers.None)
                {
                    Regex r = new Regex(@"(?<=Pandora - )(.*?) - (.*?) -", RegexOptions.IgnoreCase | RegexOptions.Singleline);
                    Match m = r.Match(p.Title);

                    if (m.Success)
                    {
                        song = new Song(m.Groups[2].ToString().Replace("  ", ""), m.Groups[1].ToString().Replace("  ", ""));
                    }
                }
                break;

            //Plug.dj
            case MusicPlayers.Plug:
                p = getProcess(player);
                if (p.Player != MusicPlayers.None)
                {
                    Regex r = new Regex(@"(?<=Plug.dj - )(.*?) - (.*?) - (.*?) -", RegexOptions.IgnoreCase | RegexOptions.Singleline);
                    Match m = r.Match(p.Title);

                    if (m.Success)
                    {
                        MessageBox.Show(m.Groups[1].ToString());
                        song = new Song(m.Groups[2].ToString().Replace("  ", ""), m.Groups[1].ToString().Replace("  ", ""), m.Groups[3].ToString().Replace("  ", ""));
                    }
                    else
                    {
                        Regex r2 = new Regex(@"(?<=Plug.dj - )(.*?) - (.*?) - ", RegexOptions.IgnoreCase | RegexOptions.Singleline);
                        Match m2 = r2.Match(p.Title);

                        if (m2.Groups[1].ToString() != "")
                        {
                            song = new Song(m2.Groups[2].ToString().Replace("  ", ""), m2.Groups[1].ToString().Replace("  ", ""));
                        }
                    }
                }
                break;

            //Zaycev.fm
            case MusicPlayers.Zaycev:
                p = getProcess(player);
                if (p.Player != MusicPlayers.None)
                {
                    Regex r = new Regex(@"(?<=Zaycev - )(.*?)  -  (.*?) -", RegexOptions.IgnoreCase | RegexOptions.Singleline);
                    Match m = r.Match(p.Title);

                    if (m.Success)
                    {
                        song = new Song(m.Groups[1].ToString().Replace("  ", ""), m.Groups[2].ToString().Replace("  ", ""));
                    }
                }
                break;

            //8Tracks
            case MusicPlayers.EightTracks:
                p = getProcess(player);
                if (p.Player != MusicPlayers.None)
                {
                    Regex r = new Regex(@"(?<=tracks - )(.*?) - (.*?) -", RegexOptions.IgnoreCase | RegexOptions.Singleline);
                    Match m = r.Match(p.Title);

                    //artist, title, album
                    if (m.Success)
                    {
                        song = new Song(m.Groups[2].ToString().Replace("  ", ""), m.Groups[1].ToString().Replace("  ", ""));
                    }
                }
                break;

            //
            //Custom APIs
            //
            case MusicPlayers.iTunes:
                p = getProcess(player);
                if (p.Player != MusicPlayers.None)
                {
                    API.iTunes info = new API.iTunes();
                    song = info.GetCurrentPlayingSong();
                }
                break;

            case MusicPlayers.Nightbot:

                break;

            case MusicPlayers.Zune:

                break;

            case MusicPlayers.Jriver:

                break;

            case MusicPlayers.WindowsMP:
                p = getProcess(player);
                if (p.Player != MusicPlayers.None)
                {
                    API.WMPSongInfo info = new API.WMPSongInfo();
                    song = info.GetCurrentPlayingSong();
                }
                break;
            }

            return(song);
        }