Пример #1
0
 public Main()
 {
     InitializeComponent();
     socket.Open();
     socket.On("pause", (data) =>
     {
         WebHelperResult whr = WebHelperHook.GetStatus();
         if (whr.isPlaying)
         {
             whr.isPlaying = false;
             BeginInvoke(new Action(this.Resume));
         }
     });
     socket.On("play", (data) =>
     {
         WebHelperResult whr = WebHelperHook.GetStatus();
         if (!whr.isPlaying)
         {
             whr.isPlaying = true;
             BeginInvoke(new Action(this.Resume));
         }
     });
 }
Пример #2
0
        /**
         * Contains the logic for when to mute Spotify
         **/
        private void MainTimer_Tick(object sender, EventArgs e)
        {
            try {
                if (Process.GetProcessesByName("spotify").Length < 1)
                {
                    File.AppendAllText(logPath, "Spotify process not found\r\n");
                    Notify("Exiting EZBlocker.");
                    Application.Exit();
                }

                WebHelperResult whr = WebHelperHook.GetStatus();

                if (whr.isAd) // Track is ad
                {
                    if (whr.isPlaying)
                    {
                        Debug.WriteLine("Ad is playing");
                        if (lastArtistName != whr.artistName)
                        {
                            if (!muted)
                            {
                                Mute(1);
                            }
                            StatusLabel.Text = "Muting ad";
                            lastArtistName   = whr.artistName;
                            LogAction("/mute/" + whr.artistName);
                            Debug.WriteLine("Blocked " + whr.artistName);
                        }
                    }
                    else // Ad is paused
                    {
                        Debug.WriteLine("Ad is paused");
                        Resume();
                    }
                }
                else if (whr.isPrivateSession)
                {
                    if (lastArtistName != whr.artistName)
                    {
                        StatusLabel.Text = "Playing: *Private Session*";
                        lastArtistName   = whr.artistName;
                        MessageBox.Show("Please disable 'Private Session' on Spotify for EZBlocker to function properly.", "EZBlocker", MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1, (MessageBoxOptions)0x40000);
                    }
                }
                else if (!whr.isRunning)
                {
                    StatusLabel.Text = "Spotify is not running";
                    //Notify("Error connecting to Spotify. Retrying...");
                    File.AppendAllText(logPath, "Not running.\r\n");
                    MainTimer.Interval = 5000;

                    /*
                     * MainTimer.Enabled = false;
                     * MessageBox.Show("Spotify is not running. Please restart EZBlocker after starting Spotify.", "EZBlocker", MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1, (MessageBoxOptions)0x40000);
                     * StatusLabel.Text = "Spotify is not running";
                     * Application.Exit();
                     */
                }
                else if (!whr.isPlaying)
                {
                    StatusLabel.Text = "Spotify is paused";
                    lastArtistName   = "";
                }
                else // Song is playing
                {
                    if (muted)
                    {
                        Mute(0);
                    }
                    if (MainTimer.Interval > 1000)
                    {
                        MainTimer.Interval = 1000;
                    }
                    if (lastArtistName != whr.artistName)
                    {
                        StatusLabel.Text = "Playing: " + ShortenName(whr.artistName);
                        lastArtistName   = whr.artistName;
                    }
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
                File.AppendAllText(logPath, ex.Message);
            }
        }
Пример #3
0
        /**
         * Contains the logic for when to mute Spotify
         **/
        private void TimerMain_Tick(object sender, EventArgs e)
        {
            try
            {
                if (Process.GetProcessesByName("spotify").Length < 1)
                {
                    NotifyBalloon("Exiting EZBlocker...", 10000);
                    noErrors = false;
                    Application.Exit();
                }

                WebHelperResult whr = WebHelperHook.GetStatus();

                if (whr.isAd)
                {
                    if (whr.isPlaying)
                    {
                        if (lastSongName != whr.songName)
                        {
                            if (!muted)
                            {
                                Mute(1);
                            }
                            lastSongName = "";
                            LabelMessage("Playing: Muted ad!", "");
                        }
                    }
                    else
                    {
                        lastSongName = "";
                        LabelMessage("Ad is paused!? Why?", "Resume it now please");
                    }
                }
                else if (whr.isPrivateSession)
                {
                    if (lastSongName != whr.songName)
                    {
                        lastSongName = whr.songName;
                        LabelMessage("Playing: *Private Session*", "Please disable 'Private Session' on Spotify for EZBlocker to function properly.");
                    }
                }
                else if (!whr.isRunning)
                {
                    lastSongName = "";
                    LabelMessage("Spotify is not playing", "");
                }
                else if (!whr.isPlaying)
                {
                    lastSongName = "";
                    LabelMessage("Spotify is paused", "");
                }
                else // Song is playing
                {
                    if (muted)
                    {
                        Mute(0);
                    }
                    if (lastSongName != whr.songName)
                    {
                        lastSongName = whr.songName;
                        LabelMessage("Playing: " + ShortenName(whr.songName), "Artist: " + ShortenName(whr.artistName));
                    }
                }
            }
            catch
            {
                LabelMessage("Is Internet availble?", "");
            }
        }
Пример #4
0
        /**
         * Contains the logic for when to mute Spotify
         **/
        private void MainTimer_Tick(object sender, EventArgs e)
        {
            try
            {
                WebHelperResult whr = WebHelperHook.GetStatus();
                //Console.WriteLine(whr.isAd);

                if (whr.isAd) // Track is ad
                {
                    if (whr.isPlaying)
                    {
                        if (lastArtistName != whr.artistName)
                        {
                            if (!muted)
                            {
                                Mute(1);
                            }
                            StatusLabel.Text = "Muting ad: " + ShortenName(whr.artistName);
                            lastArtistName   = whr.artistName;
                            LogAction("/mute/" + whr.artistName);
                            Console.WriteLine("Blocked " + whr.artistName);
                        }
                    }
                    else // Ad is paused
                    {
                        Resume();
                        StatusLabel.Text = "Muting: " + ShortenName(whr.artistName);
                    }
                }

                /*else if (whr.length - whr.position < 1.5) // Song is within last 1.5 seconds
                 * {
                 *  if (skipAds)
                 *      NextTrack();
                 * }*/
                else if (!whr.isRunning)
                {
                    StatusLabel.Text = "Spotify is not running";
                    lastArtistName   = "N/A";
                }
                else if (!whr.isPlaying)
                {
                    StatusLabel.Text = "Spotify is paused";
                    lastArtistName   = "N/A";
                }
                else // Song is playing
                {
                    if (muted)
                    {
                        Mute(0);
                    }
                    if (lastArtistName != whr.artistName)
                    {
                        StatusLabel.Text = "Playing: " + ShortenName(whr.artistName);
                        lastArtistName   = whr.artistName;
                    }
                }
            }
            catch (Exception except)
            {
                StatusLabel.Text = "Connection Error";
                WebHelperHook.CheckWebHelper();
                Console.WriteLine(except);
                File.WriteAllText(logPath, except.ToString());
            }
        }