Exemplo 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;
        }
Exemplo n.º 2
0
        private void write_song(Song song)
        {
            if (song.Title != "None")
            {
                string ifreg = @"(?<=\[if\()(.*?)\)\](.*?)\[\/if\]";
                string ouput = Properties.Settings.Default.OutFormat;

                for (int i = 0; i < 4; i++)
                {
                    Regex r = new Regex(ifreg, RegexOptions.IgnoreCase | RegexOptions.Singleline);
                    Match m = r.Match(ouput);

                    if (m.Success)
                    {
                        if (m.Groups[1].ToString().Contains("[Artist]"))
                        {
                            if (String.IsNullOrEmpty(song.Artist))
                                ouput = ouput.Replace("[if(" + m.Groups[1].ToString() + ")]" + m.Groups[2].ToString() + "[/if]", "");
                            else
                                ouput = ouput.Replace("[if(" + m.Groups[1].ToString() + ")]" + m.Groups[2].ToString() + "[/if]", m.Groups[2].ToString().Replace("[Artist]", song.Artist));
                        }
                        else if (m.Groups[1].ToString().Contains("[Title]"))
                        {
                            if (String.IsNullOrEmpty(song.Title))
                                ouput = ouput.Replace("[if(" + m.Groups[1].ToString() + ")]" + m.Groups[2].ToString() + "[/if]", "");
                            else
                                ouput = ouput.Replace("[if(" + m.Groups[1].ToString() + ")]" + m.Groups[2].ToString() + "[/if]", m.Groups[2].ToString().Replace("[Title]", song.Title));
                        }
                        else if (m.Groups[1].ToString().Contains("[Album]"))
                        {
                            if (String.IsNullOrEmpty(song.Album))
                                ouput = ouput.Replace("[if(" + m.Groups[1].ToString() + ")]" + m.Groups[2].ToString() + "[/if]", "");
                            else
                                ouput = ouput.Replace("[if(" + m.Groups[1].ToString() + ")]" + m.Groups[2].ToString() + "[/if]", m.Groups[2].ToString().Replace("[Album]", song.Album));
                        }
                    }
                }

                ouput = ouput.Replace("[Artist]", song.Artist);
                ouput = ouput.Replace("[Title]", song.Title);
                ouput = ouput.Replace("[Album]", song.Album);
                ouput = ouput.Replace("  ", " ");

                try
                {
                    File.WriteAllText(Properties.Settings.Default.OutputFile, ouput);
                }
                catch (Exception ex) { }
            }
            else
            {
                try
                {
                    File.WriteAllText(Properties.Settings.Default.OutputFile, "");
                }
                catch (Exception ex) { }
            }
        }
Exemplo n.º 3
0
        private void toggle_Click(object sender, EventArgs e)
        {
            if (timer.Enabled)
            {
                currentSong = null;

                toolStripSeparator2.Visible = false;
                currentSonglb.Visible = false;
                currentsongToolStripMenuItem.Visible = false;

                timer.Enabled = false;
                toggle.Text = "Start";
                File.WriteAllText(Properties.Settings.Default.OutputFile, "");
            }
            else
            {
                toolStripSeparator2.Visible = true;
                currentSonglb.Visible = true;
                currentsongToolStripMenuItem.Visible = true;

                timer.Enabled = true;
                toggle.Text = "Stop";
            }
        }
Exemplo n.º 4
0
        private void timer_Tick(object sender, EventArgs e)
        {
            if (currentPlayer != null)
            {
                Song s = f.get(currentPlayer.Type);

                if (currentSong == null || s.Title != currentSong.Title)
                {
                    currentSong = s;

                    if (String.IsNullOrEmpty(s.Album))
                    {
                        currentSonglb.Text = String.Format("Current Song: {0} by {1} ", s.Title, s.Artist);
                        currentsongToolStripMenuItem.Text = String.Format("Current Song: {0} by {1}", s.Title, s.Artist);
                    }
                    else if (String.IsNullOrEmpty(s.Artist))
                    {
                        currentSonglb.Text = String.Format("Current Song: {0}", s.Title);
                        currentsongToolStripMenuItem.Text = String.Format("Current Song: {0}", s.Title);
                    }
                    else
                    {
                        currentSonglb.Text = String.Format("Current Song: {0} by {1} (Album: {2})", s.Title, s.Artist, s.Album);
                        currentsongToolStripMenuItem.Text = String.Format("Current Song: {0} by {1} (Album: {2})", s.Title, s.Artist, s.Album);
                    }

                    write_song(s);
                }
            }
        }