public override void Update() { if (!this.Found) { this.Handle = UnsafeNativeMethods.FindWindow("SpotifyMainWindow", null); this.Found = true; this.NotRunning = false; } else { // Make sure the process is still valid. if (this.Handle != IntPtr.Zero && this.Handle != null) { int windowTextLength = UnsafeNativeMethods.GetWindowText(this.Handle, this.Title, this.Title.Capacity); string spotifyTitle = this.Title.ToString(); this.Title.Clear(); // If the window title length is 0 then the process handle is not valid. if (windowTextLength > 0) { // Only update if the title has actually changed. // This prevents unnecessary calls and downloads. if (spotifyTitle != this.LastTitle) { if (spotifyTitle == "Spotify") { if (Globals.SaveAlbumArtwork) { this.SaveBlankImage(); } TextHandler.UpdateTextAndEmptyFilesMaybe(Globals.ResourceManager.GetString("NoTrackPlaying")); } else { this.DownloadJson(spotifyTitle); dynamic jsonSummary = SimpleJson.DeserializeObject(this.json); if (jsonSummary != null) { var numberOfResults = jsonSummary.tracks.total; if (numberOfResults > 0) { jsonSummary = SimpleJson.DeserializeObject(jsonSummary.tracks["items"].ToString()); TextHandler.UpdateText( jsonSummary[0].name.ToString(), jsonSummary[0].artists[0].name.ToString(), jsonSummary[0].album.name.ToString()); if (Globals.SaveAlbumArtwork) { this.HandleSpotifyAlbumArtwork(jsonSummary[0].name.ToString()); } } else { // In the event of an advertisement (or any song that returns 0 results) // then we'll just write the whole title as a single string instead. TextHandler.UpdateText(spotifyTitle); } } } this.LastTitle = spotifyTitle; } } else { if (!this.NotRunning) { this.ResetSinceSpotifyIsNotRunning(); } } } else { if (!this.NotRunning) { this.ResetSinceSpotifyIsNotRunning(); } } } }
public override void Update() { if (!this.Found) { this.Handle = UnsafeNativeMethods.FindWindow("Winamp v1.x", null); this.Found = true; this.NotRunning = false; } else { // Make sure the process is still valid. if (this.Handle != IntPtr.Zero && this.Handle != null) { int windowTextLength = UnsafeNativeMethods.GetWindowText(this.Handle, this.Title, this.Title.Capacity); string winampTitle = this.Title.ToString(); this.Title.Clear(); // If the window title length is 0 then the process handle is not valid. if (windowTextLength > 0) { // Only update the system tray text and text file text if the title changes. if (winampTitle != this.LastTitle || Globals.RewriteUpdatedOutputFormat) { Globals.RewriteUpdatedOutputFormat = false; if (winampTitle.Contains("- Winamp [Stopped]") || winampTitle.Contains("- Winamp [Paused]")) { TextHandler.UpdateTextAndEmptyFilesMaybe(Globals.ResourceManager.GetString("NoTrackPlaying")); } else { // Winamp window titles look like "#. Artist - Track - Winamp". // Require that the user use ATF and replace the format with something like: // %artist% – %title% string windowTitleFull = winampTitle.Replace("- Winamp", string.Empty); string[] windowTitle = windowTitleFull.Split('–'); // Album artwork not supported by Winamp if (Globals.SaveAlbumArtwork) { this.SaveBlankImage(); } if (windowTitle.Length > 1) { string artist = windowTitle[0].Trim(); string songTitle = windowTitle[1].Trim(); TextHandler.UpdateText(songTitle, artist); } else { TextHandler.UpdateText(windowTitle[0].Trim()); } } this.LastTitle = winampTitle; } } else { if (!this.NotRunning) { if (Globals.SaveAlbumArtwork) { this.SaveBlankImage(); } TextHandler.UpdateTextAndEmptyFilesMaybe( string.Format( CultureInfo.InvariantCulture, Globals.ResourceManager.GetString("PlayerIsNotRunning"), Globals.ResourceManager.GetString("Winamp"))); this.Found = false; this.NotRunning = true; } } } else { if (!this.NotRunning) { if (Globals.SaveAlbumArtwork) { this.SaveBlankImage(); } TextHandler.UpdateTextAndEmptyFilesMaybe( string.Format( CultureInfo.InvariantCulture, Globals.ResourceManager.GetString("PlayerIsNotRunning"), Globals.ResourceManager.GetString("Winamp"))); this.Found = false; this.NotRunning = true; } } } }
public override void Update() { if (!this.Found) { this.Handle = UnsafeNativeMethods.FindWindow("SpotifyMainWindow", null); this.Found = true; this.NotRunning = false; } else { // Make sure the process is still valid. if (this.Handle != IntPtr.Zero && this.Handle != null) { int windowTextLength = UnsafeNativeMethods.GetWindowText(this.Handle, this.Title, this.Title.Capacity); string spotifyTitle = this.Title.ToString(); this.Title.Clear(); // If the window title length is 0 then the process handle is not valid. if (windowTextLength > 0) { // Only update the system tray text and text file text if the title changes. if (spotifyTitle != this.LastTitle) { if (spotifyTitle == "Spotify") { if (Globals.SaveAlbumArtwork) { this.SaveBlankImage(); } if (Globals.EmptyFileIfNoTrackPlaying) { TextHandler.UpdateTextAndEmptyFile(Globals.ResourceManager.GetString("NoTrackPlaying")); } else { TextHandler.UpdateText(Globals.ResourceManager.GetString("NoTrackPlaying")); } } else { // Spotify window titles look like "Spotify - Artist – Song Title". string windowTitleFull = spotifyTitle.Replace("Spotify - ", string.Empty); string[] windowTitle = windowTitleFull.Split('–'); string artist = windowTitle[0].Trim(); string songTitle = windowTitle[1].Trim(); songTitle = songTitle.Replace(" - Explicit Album Version", string.Empty); if (Globals.SaveAlbumArtwork || Globals.SaveSeparateFiles) { this.DownloadJson(artist, songTitle); } if (Globals.SaveAlbumArtwork) { this.HandleSpotifyAlbumArtwork(songTitle); } if (Globals.SaveSeparateFiles) { string album = this.HandleSpotifyAlbumName(); TextHandler.UpdateText(songTitle, artist, album); } else { TextHandler.UpdateText(songTitle, artist); } } this.LastTitle = spotifyTitle; } } else { if (!this.NotRunning) { if (Globals.SaveAlbumArtwork) { this.SaveBlankImage(); } if (Globals.EmptyFileIfNoTrackPlaying) { TextHandler.UpdateTextAndEmptyFile(Globals.ResourceManager.GetString("SpotifyIsNotRunning")); } else { TextHandler.UpdateText(Globals.ResourceManager.GetString("SpotifyIsNotRunning")); } this.Found = false; this.NotRunning = true; } } } else { if (!this.NotRunning) { if (Globals.SaveAlbumArtwork) { this.SaveBlankImage(); } if (Globals.EmptyFileIfNoTrackPlaying) { TextHandler.UpdateTextAndEmptyFile(Globals.ResourceManager.GetString("SpotifyIsNotRunning")); } else { TextHandler.UpdateText(Globals.ResourceManager.GetString("SpotifyIsNotRunning")); } this.Found = false; this.NotRunning = true; } } } }
public override void Update() { if (!this.Found) { this.Handle = UnsafeNativeMethods.FindWindow("QWidget", "VLC media player"); this.Found = true; this.NotRunning = false; } else { // Make sure the process is still valid. if (this.Handle != IntPtr.Zero && this.Handle != null) { int windowTextLength = UnsafeNativeMethods.GetWindowText(this.Handle, this.Title, this.Title.Capacity); string vlcTitle = this.Title.ToString(); this.Title.Clear(); // If the window title length is 0 then the process handle is not valid. if (windowTextLength > 0) { // Only update the system tray text and text file text if the title changes. if (vlcTitle != this.LastTitle) { if (vlcTitle.Equals("VLC media player")) { if (Globals.EmptyFileIfNoTrackPlaying) { TextHandler.UpdateTextAndEmptyFile(Globals.ResourceManager.GetString("NoTrackPlaying")); } else { TextHandler.UpdateText(Globals.ResourceManager.GetString("NoTrackPlaying")); } } else { string windowTitleFull = vlcTitle.Replace(" - VLC media player", string.Empty); if (Globals.SaveAlbumArtwork) { this.SaveBlankImage(); } TextHandler.UpdateText(windowTitleFull.Trim()); } this.LastTitle = vlcTitle; } } else { if (!this.NotRunning) { if (Globals.SaveAlbumArtwork) { this.SaveBlankImage(); } if (Globals.EmptyFileIfNoTrackPlaying) { TextHandler.UpdateTextAndEmptyFile(Globals.ResourceManager.GetString("VLCIsNotRunning")); } else { TextHandler.UpdateText(Globals.ResourceManager.GetString("VLCIsNotRunning")); } this.Found = false; this.NotRunning = true; } } } else { if (!this.NotRunning) { if (Globals.SaveAlbumArtwork) { this.SaveBlankImage(); } if (Globals.EmptyFileIfNoTrackPlaying) { TextHandler.UpdateTextAndEmptyFile(Globals.ResourceManager.GetString("VLCIsNotRunning")); } else { TextHandler.UpdateText(Globals.ResourceManager.GetString("VLCIsNotRunning")); } this.Found = false; this.NotRunning = true; } } } }
public override void Update() { // There's no sense in doing anything anymore without a valid token. if (!string.IsNullOrEmpty(this.token)) { if (!this.Found) { this.Handle = UnsafeNativeMethods.FindWindow("SpotifyMainWindow", null); this.Found = true; this.NotRunning = false; } else { // Make sure the process is still valid. if (this.Handle != IntPtr.Zero && this.Handle != null) { int windowTextLength = UnsafeNativeMethods.GetWindowText(this.Handle, this.Title, this.Title.Capacity); string spotifyTitle = this.Title.ToString(); this.Title.Clear(); // If the window title length is 0 then the process handle is not valid. if (windowTextLength > 0) { // Only update if the title has actually changed. // This prevents unnecessary calls and downloads. if (spotifyTitle != this.LastTitle || Globals.RewriteUpdatedOutputFormat) { Globals.RewriteUpdatedOutputFormat = false; if (spotifyTitle == "Spotify") { if (Globals.SaveAlbumArtwork) { this.SaveBlankImage(); } TextHandler.UpdateTextAndEmptyFilesMaybe(Globals.ResourceManager.GetString("NoTrackPlaying")); } else { this.DownloadJson(spotifyTitle); if (!string.IsNullOrEmpty(this.json)) { dynamic jsonSummary = SimpleJson.DeserializeObject(this.json); if (jsonSummary != null) { var numberOfResults = jsonSummary.tracks.total; if (numberOfResults > 0) { jsonSummary = SimpleJson.DeserializeObject(jsonSummary.tracks["items"].ToString()); int mostPopular = SelectTrackByPopularity(jsonSummary, spotifyTitle); TextHandler.UpdateText( jsonSummary[mostPopular].name.ToString(), jsonSummary[mostPopular].artists[0].name.ToString(), jsonSummary[mostPopular].album.name.ToString(), jsonSummary[mostPopular].id.ToString()); if (Globals.SaveAlbumArtwork) { this.DownloadSpotifyAlbumArtwork(jsonSummary[mostPopular].album); } } else { // In the event of an advertisement (or any song that returns 0 results) // then we'll just write the whole title as a single string instead. TextHandler.UpdateText(spotifyTitle); } } } else { // For whatever reason the JSON file couldn't download // In the event this happens we'll just display Spotify's window title as the track TextHandler.UpdateText(spotifyTitle); } } this.LastTitle = spotifyTitle; } } else { if (!this.NotRunning) { this.ResetSinceSpotifyIsNotRunning(); } } } else { if (!this.NotRunning) { this.ResetSinceSpotifyIsNotRunning(); } } } } }