private void StopRecording() { string filePath = string.Empty; string song = string.Empty; Mp3Tag songTag = Mp3Tag.EmptyTag(); int duration = 0; if (soundCardRecorder != null) { addToLog("Recording stopped"); soundCardRecorder.Stop(); filePath = soundCardRecorder.FilePath; song = soundCardRecorder.SongTag.ToString(); songTag = soundCardRecorder.SongTag; duration = soundCardRecorder.Duration; addToLog("Duration: " + duration + " (Limit: " + thresholdTextBox.Value + ")"); soundCardRecorder.Dispose(); soundCardRecorder = null; if (duration < (int)thresholdTextBox.Value && thresholdCheckBox.Checked) { File.Delete(filePath); addToLog("Recording too short; deleting file..."); } else { if (!string.IsNullOrEmpty(filePath)) { addToLog("Recorded file: " + filePath); encodingLabel.Text = song; PostProcessing(filePath, songTag); } } } }
void stateCheckTimer_Tick(object sender, EventArgs e) { DeezerState oldState = currentDeezerState; Mp3Tag oldTrack = new Mp3Tag(currentTrack.Title, currentTrack.Artist); // figure out what Deezer is doing now // therefore, we need to execute a small javascript code // which returns all HTML elements with a specific tag // the first element of these gives us the song title // the next elements give us the artists // Get this array string script = "[dzPlayer.getSongTitle(), dzPlayer.getArtistName()]"; try { mainBrowser.EvaluateScriptAsync(script).ContinueWith(x => { var response = x.Result; if (response.Success && response.Result != null) { var list = (List <object>)response.Result; string artist = list[1].ToString(); string title = list[0].ToString(); //currentTrack = new Mp3Tag(title, artist); this.Invoke((Action)(() => { //currentTrack = new Mp3Tag(title, artist); Mp3Tag newTag = new Mp3Tag(title, artist); if (!(newTag.Equals(currentTrack))) { StateChanged(this, new StateChangedEventArgs() { Song = newTag, PreviousSong = currentTrack, State = currentDeezerState, PreviousState = currentDeezerState }); } })); } }); } catch (Exception ex) { addToLog("Error: " + ex.Message); } // Find out if Deezer is paused or playing string scriptIsPlaying = "dzPlayer.isPlaying()"; try { mainBrowser.EvaluateScriptAsync(scriptIsPlaying).ContinueWith(y => { var responseIsPlaying = y.Result; if (responseIsPlaying.Success && responseIsPlaying.Result != null) { bool isPlaying = (bool)responseIsPlaying.Result; if (isPlaying) { this.Invoke((Action)(() => { if (currentDeezerState != DeezerState.Playing) { StateChanged(this, new StateChangedEventArgs() { PreviousState = currentDeezerState, State = DeezerState.Playing, Song = currentTrack, PreviousSong = currentTrack }); } })); } else { this.Invoke((Action)(() => { if (currentDeezerState != DeezerState.Paused) { StateChanged(this, new StateChangedEventArgs() { PreviousState = currentDeezerState, State = DeezerState.Paused, Song = currentTrack, PreviousSong = currentTrack }); } })); } } }); } catch (Exception ex) { addToLog("Error: " + ex.Message); } }
private void OnLoad(object sender, EventArgs eventArgs) { // Load the main browser mainBrowser = new ChromiumWebBrowser("https://www.deezer.com/") { BrowserSettings = new BrowserSettings() { Plugins = CefState.Enabled } }; this.splitContainer1.Panel2.Controls.Add(mainBrowser); // Load the timer only when loading is finished mainBrowser.LoadingStateChanged += OnLoadingStateChanged; //load the available devices LoadWasapiDevicesCombo(); //load the different bitrates LoadBitrateCombo(); //Load user settings LoadUserSettings(); //set the change event if filePath is songLabel.Text = string.Empty; encodingLabel.Text = string.Empty; folderDialog = new FolderBrowserDialog { SelectedPath = outputFolderTextBox.Text }; versionLabel.Text = string.Format("Version {0}", Application.ProductVersion); ChangeApplicationState(_currentApplicationState); // instantiate the sound recorder once in an attempt to reduce lag the first time used try { soundCardRecorder = new SoundCardRecorder((MMDevice)deviceListBox.SelectedItem, CreateOutputFile("deleteme", "wav"), Mp3Tag.EmptyTag()); soundCardRecorder.Dispose(); soundCardRecorder = null; if (File.Exists(CreateOutputFile("deleteme", "wav"))) { File.Delete(CreateOutputFile("deleteme", "wav")); } } catch (Exception ex) { addToLog("Error: " + ex.Message); } }
void stateCheckTimer_Tick(object sender, EventArgs e) { // figure out what spotify is doing right now var iframes = browser.Document.GetElementsByTagName("iframe"); foreach (Gecko.DOM.GeckoIFrameElement frame in iframes) { GeckoHtmlElement doc = null; string queryArtist = "", queryTrack = "", queryTrackUri = "", queryIsPlaying = "", queryAddButton = "", attrTrackUri = ""; // Old Player if (frame.Id == "app-player") { doc = frame.ContentDocument.DocumentElement as GeckoHtmlElement; queryIsPlaying = "#play-pause.playing"; queryArtist = "#track-artist a"; queryTrack = "#track-name a"; queryTrackUri = "#track-name a"; attrTrackUri = "href"; queryAddButton = "#track-add"; } // New Player if (frame.Id == "main") { doc = frame.ContentDocument.DocumentElement as GeckoHtmlElement; queryIsPlaying = "#play.playing"; queryArtist = "p.artist a"; queryTrack = "p.track a"; queryTrackUri = "p.track a"; attrTrackUri = "data-uri"; queryAddButton = ".caption button.button-add"; } if (doc != null) { SpotifyState oldState = currentSpotifyState; string oldTrack = currentTrack.TrackUri; // get current track var isPlaying = doc.QuerySelector(queryIsPlaying); if (isPlaying != null) { currentSpotifyState = SpotifyState.Playing; var artist = doc.QuerySelector(queryArtist).TextContent; var title = doc.QuerySelector(queryTrack).TextContent; var trackUri = doc.QuerySelector(queryTrackUri).GetAttribute(attrTrackUri); currentTrack = new Mp3Tag(title, artist, trackUri); } else { currentSpotifyState = SpotifyState.Paused; } // ad detection (new player only) var addToMyMusicButton = doc.QuerySelector(queryAddButton); if (addToMyMusicButton != null) { var style = addToMyMusicButton.Attributes["style"]; if (style != null) { if (style.NodeValue.Contains("display: none")) { currentSpotifyState = SpotifyState.Ad; } } } // extra ad detection, works for old player too if (currentTrack.Artist == "Spotify") { currentSpotifyState = SpotifyState.Ad; } // mute sound on ads if (currentSpotifyState == SpotifyState.Ad) { if (MuteOnAdsCheckBox.Checked && !MutedSound) { addToLog("Ads detected - Attempting to Mute!"); Util.ToggleMuteVolume(this.Handle); MutedSound = true; } } else { if (MutedSound) { addToLog("Un-Muting"); Util.ToggleMuteVolume(this.Handle); MutedSound = false; } } // set state if changed if (oldState != currentSpotifyState || oldTrack != currentTrack.TrackUri) { if (currentSpotifyState == SpotifyState.Playing) { var song = currentTrack.Artist + " - " + currentTrack.Title; songLabel.Text = song; addToLog("Now playing: " + song + " (" + currentTrack.TrackUri + ")"); if (_currentApplicationState != RecorderState.NotRecording && oldTrack != currentTrack.TrackUri) { ChangeApplicationState(RecorderState.Recording); } else if (_currentApplicationState == RecorderState.Recording) { ChangeApplicationState(RecorderState.WaitingForRecording); } } else if (currentSpotifyState == SpotifyState.Paused) { addToLog("Music stopped"); if (_currentApplicationState == RecorderState.Recording) { ChangeApplicationState(RecorderState.WaitingForRecording); } } else if (currentSpotifyState == SpotifyState.Ad) { addToLog("Ads..."); if (_currentApplicationState == RecorderState.Recording) { ChangeApplicationState(RecorderState.WaitingForRecording); } } } break; } } songLabel.Visible = _currentApplicationState == RecorderState.Recording; }