Beispiel #1
0
 /// <summary>
 /// Initialise the Spotifiy API
 /// </summary>
 public void InitApi()
 {
     try
     {
         _handle = GetHandle();
         WebHelperHook.GetObjects(out _clientInfo, out _songInfo);
     }
     catch (Exception exception)
     {
         MessageBox.Show($"ERROR: {exception.Message}");
     }
 }
Beispiel #2
0
        private void BT_RecordOnPlay_Click(object sender, EventArgs e)
        {
            WebHelperResult whr = WebHelperHook.GetStatus();

            if (!whr.isPlaying)
            {
                recordWaiting = true;
            }
            else
            {
                StartCapture(savePath + "\\" + strToFile(lastArtistName + " - " + lastTrackName + ".wav"));
                File.AppendAllText(mp3ID3Catalog, lastArtistName + " - " + lastTrackName + ".wav" + "¤" + lastTrackName + "¤" + lastArtistName + "¤" + lastAlbumName + "\n");
            }

            BT_Record.Enabled       = false;
            BT_RecordOnPlay.Enabled = false;
            BT_Stop.Enabled         = true;
            recordOnPlay            = true;
        }
Beispiel #3
0
        private void MainTimer_Tick(object sender, EventArgs e)
        {
            // Avoid simultaneous calls
            if (!isTimerDone)
            {
                return;
            }
            isTimerDone = false;

            try
            {
                if (Process.GetProcessesByName("spotify").Length < 1)
                {
                    if (exitTolerance > 10)
                    {
                        File.AppendAllText(logPath, "Spotify process not found\r\n");
                        MessageBox.Show("Spotify hasn't started or was manually closed, the application will exit.", "Closing", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        Application.Exit();
                    }
                    if (LB_Status.InvokeRequired)
                    {
                        LB_Status.Invoke(new MethodInvoker(delegate { LB_Status.Text = "Spotify not started"; }));
                    }

                    exitTolerance += 1;
                    isTimerDone    = true;
                    return;
                }
                else
                {
                    exitTolerance = 0;
                }

                WebHelperResult whr = WebHelperHook.GetStatus();

                if (whr.isAd) // Track is ad
                {
                    if (whr.isPlaying)
                    {
                        Debug.WriteLine("Ad is playing");
                        if (lastArtistName != whr.artistName)
                        {
                            lastArtistName = whr.artistName;
                            //LogAction("/mute/" + whr.artistName);
                            Debug.WriteLine("Blocked " + whr.artistName);
                        }
                    }
                    else // Ad is paused
                    {
                        Debug.WriteLine("Ad is paused");
                    }
                }
                else if (whr.isPrivateSession)
                {
                    if (lastArtistName != whr.artistName)
                    {
                        lastArtistName = whr.artistName;
                        MessageBox.Show("Please disable 'Private Session' on Spotify for EasyBlocker to function properly.", "EasyBlocker", MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1, (MessageBoxOptions)0x40000);
                    }
                }
                else if (!whr.isRunning)
                {
                    if (LB_Status.InvokeRequired)
                    {
                        LB_Status.Invoke(new MethodInvoker(delegate { LB_Status.Text = "SpotifyWebHelper nor started"; }));
                    }
                    File.AppendAllText(logPath, "Not running.\r\n");
                    timer.Interval = 5000;
                }
                else if (!whr.isPlaying)
                {
                    if (recordOnPlay && !recordWaiting)
                    {
                        StopCapture();
                        recordOnPlay  = false;
                        recordWaiting = false;
                    }

                    if (LB_Status.InvokeRequired)
                    {
                        LB_Status.Invoke(new MethodInvoker(delegate { LB_Status.Text = "Spotify paused"; }));
                    }
                    lastArtistName = "";
                    lastTrackName  = "";
                }
                else // Song is playing
                {
                    if ((whr.length - whr.position < 2) || (!whr.isPlaying && recordOnPlay))
                    {
                        timer.Interval = 300;
                    }
                    else if (timer.Interval != 1000)
                    {
                        timer.Interval = 1000;
                    }

                    if (lastArtistName != whr.artistName || lastTrackName != whr.trackName)
                    {
                        if (recordOnPlay)
                        {
                            if (!recordWaiting)
                            {
                                StopCapture();
                            }

                            StartCapture(savePath + "\\" + strToFile(whr.artistName + " - " + whr.trackName + ".wav"));
                            recordWaiting = false;

                            Task.Run(() => convertToMP3(true));
                            File.AppendAllText(mp3ID3Catalog, strToFile(whr.artistName + " - " + whr.trackName + ".wav") + "¤" + whr.trackName + "¤" + whr.artistName + "¤" + whr.albumName + "\n");
                        }

                        // Delegate refresh on track change
                        if (LB_Status.InvokeRequired)
                        {
                            LB_Status.Invoke(new MethodInvoker(delegate { LB_Status.Text = ShortenName("> " + whr.artistName + " - " + whr.trackName); }));
                        }
                        if (PlayingProgress.InvokeRequired)
                        {
                            PlayingProgress.Invoke(new MethodInvoker(delegate { PlayingProgress.Maximum = whr.length; }));
                        }
                        lastArtistName = whr.artistName;
                        lastTrackName  = whr.trackName;
                        lastAlbumName  = whr.albumName;
                    }

                    if (LB_Position.InvokeRequired)
                    {
                        LB_Position.Invoke(new MethodInvoker(delegate { LB_Position.Text = toTimeString(whr.position, whr.length); }));
                    }
                    Int32 minValue = (int)whr.position < whr.length ? (int)whr.position : whr.length;
                    if (PlayingProgress.InvokeRequired)
                    {
                        PlayingProgress.Invoke(new MethodInvoker(delegate { PlayingProgress.Value = minValue; }));
                    }
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
                File.AppendAllText(logPath, ex.Message + '\n');
            }

            isTimerDone = true;
        }