├── LICENSE ├── Program.cs ├── README.md ├── SpotifyNowPlaying.sln ├── app ├── SpotifyNowPlaying.deps.json ├── SpotifyNowPlaying.dll ├── SpotifyNowPlaying.exe ├── SpotifyNowPlaying.pdb └── SpotifyNowPlaying.runtimeconfig.json └── img ├── ads-skip.png ├── app-preview1.png └── memory-usage.png /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 github.com/maciekkoks 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Diagnostics; 3 | using System.Linq; 4 | using System.Runtime.InteropServices; 5 | using System.Threading; 6 | 7 | namespace SpotifyNowPlaying 8 | { 9 | class Program 10 | { 11 | [DllImport("user32.dll")] 12 | 13 | public static extern void keybd_event(byte virtualKey, byte scanCode, uint flags, IntPtr extraInfo); 14 | public static int a = 0; 15 | static void Main(string[] args) 16 | { 17 | Console.ForegroundColor = ConsoleColor.Green; 18 | Console.WriteLine("Spotify AdBlocker + Now Playing"); 19 | Console.ForegroundColor = ConsoleColor.Magenta; 20 | Console.WriteLine("Author: github.com/maciekkoks"); 21 | Console.ForegroundColor = ConsoleColor.White; 22 | Console.WriteLine(); 23 | 24 | while (true) 25 | { 26 | Console.ForegroundColor = ConsoleColor.White; 27 | var proc = Process.GetProcessesByName("Spotify").LastOrDefault(p => !string.IsNullOrWhiteSpace(p.MainWindowTitle)); 28 | if (proc == null) 29 | { 30 | Console.ForegroundColor = ConsoleColor.Red; 31 | Console.WriteLine("Spotify is not running"); 32 | System.Diagnostics.Process.Start("Spotify.exe"); 33 | Console.ResetColor(); 34 | Thread.Sleep(1000); 35 | continue; 36 | } 37 | if (proc.MainWindowTitle == "Advertisement" || proc.MainWindowTitle == "Spotify") 38 | { 39 | foreach (var process in Process.GetProcessesByName("Spotify")) 40 | { 41 | process.Kill(); 42 | } 43 | System.Diagnostics.Process.Start("Spotify.exe"); 44 | Thread.Sleep(2000); 45 | keybd_event(0xB3, 0, 1, IntPtr.Zero); 46 | Console.ForegroundColor = ConsoleColor.DarkYellow; 47 | Console.WriteLine("Advertisement skipped"); 48 | a++; 49 | Console.ResetColor(); 50 | while (proc.MainWindowTitle == "Spotify"){Thread.Sleep(1000);} 51 | } 52 | if (proc != null) 53 | { 54 | if (proc.MainWindowTitle != "Spotify Free") 55 | { 56 | Console.Title = " Spotify AdBlocker - " + "Advertisements skipped: " + a + " " + proc.MainWindowTitle; 57 | Console.WriteLine("[" + DateTime.Now.ToString("HH:mm:ss", System.Globalization.DateTimeFormatInfo.InvariantInfo) + "] " + proc.MainWindowTitle); 58 | } 59 | else 60 | { 61 | Console.WriteLine("[" + DateTime.Now.ToString("HH:mm:ss", System.Globalization.DateTimeFormatInfo.InvariantInfo) + "] " + "Spotify (Paused)"); 62 | Console.Title = " Spotify AdBlocker - " + "Advertisements skipped: " + a + " " + "Spotify (Paused)"; 63 | } 64 | Thread.Sleep(1000); 65 | } 66 | } 67 | } 68 | } 69 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # SpotifyAdBlock 2 | Get currently played Spotify song name and block ads by using C# console app / Get processes by name method 3 | ![preview](https://raw.githubusercontent.com/maciekkoks/SpotifyBlockAds/main/img/app-preview1.png) 4 | # Ads skipping 5 | ![ads](https://raw.githubusercontent.com/maciekkoks/SpotifyBlockAds/main/img/ads-skip.png) 6 | # Memory Usage 7 | ![memory](https://raw.githubusercontent.com/maciekkoks/SpotifyBlockAds/main/img/memory-usage.png) 8 | 9 | # Main C# Code 10 | ```cs 11 | using System; 12 | using System.Diagnostics; 13 | using System.Linq; 14 | using System.Runtime.InteropServices; 15 | using System.Threading; 16 | 17 | namespace SpotifyNowPlaying 18 | { 19 | class Program 20 | { 21 | [DllImport("user32.dll")] 22 | 23 | public static extern void keybd_event(byte virtualKey, byte scanCode, uint flags, IntPtr extraInfo); 24 | public static int a = 0; 25 | static void Main(string[] args) 26 | { 27 | Console.ForegroundColor = ConsoleColor.Green; 28 | Console.WriteLine("Spotify AdBlocker + Now Playing"); 29 | Console.ForegroundColor = ConsoleColor.Magenta; 30 | Console.WriteLine("Author: github.com/maciekkoks"); 31 | Console.ForegroundColor = ConsoleColor.White; 32 | Console.WriteLine(); 33 | 34 | while (true) 35 | { 36 | Console.ForegroundColor = ConsoleColor.White; 37 | var proc = Process.GetProcessesByName("Spotify").LastOrDefault(p => !string.IsNullOrWhiteSpace(p.MainWindowTitle)); 38 | if (proc == null) 39 | { 40 | Console.ForegroundColor = ConsoleColor.Red; 41 | Console.WriteLine("Spotify is not running"); 42 | System.Diagnostics.Process.Start("Spotify.exe"); 43 | Console.ResetColor(); 44 | Thread.Sleep(1000); 45 | continue; 46 | } 47 | if (proc.MainWindowTitle == "Advertisement" || proc.MainWindowTitle == "Spotify") 48 | { 49 | foreach (var process in Process.GetProcessesByName("Spotify")) 50 | { 51 | process.Kill(); 52 | } 53 | System.Diagnostics.Process.Start("Spotify.exe"); 54 | Thread.Sleep(2000); 55 | keybd_event(0xB3, 0, 1, IntPtr.Zero); 56 | Console.ForegroundColor = ConsoleColor.DarkYellow; 57 | Console.WriteLine("Advertisement skipped"); 58 | a++; 59 | Console.ResetColor(); 60 | while (proc.MainWindowTitle == "Spotify"){Thread.Sleep(1000);} 61 | } 62 | if (proc != null) 63 | { 64 | if (proc.MainWindowTitle != "Spotify Free") 65 | { 66 | Console.Title = " Spotify AdBlocker - " + "Advertisements skipped: " + a + " " + proc.MainWindowTitle; 67 | Console.WriteLine("[" + DateTime.Now.ToString("HH:mm:ss", System.Globalization.DateTimeFormatInfo.InvariantInfo) + "] " + proc.MainWindowTitle); 68 | } 69 | else 70 | { 71 | Console.WriteLine("[" + DateTime.Now.ToString("HH:mm:ss", System.Globalization.DateTimeFormatInfo.InvariantInfo) + "] " + "Spotify (Paused)"); 72 | Console.Title = " Spotify AdBlocker - " + "Advertisements skipped: " + a + " " + "Spotify (Paused)"; 73 | } 74 | Thread.Sleep(1000); 75 | } 76 | } 77 | } 78 | } 79 | } 80 | ``` 81 | -------------------------------------------------------------------------------- /SpotifyNowPlaying.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.31613.86 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SpotifyNowPlaying", "SpotifyNowPlaying\SpotifyNowPlaying.csproj", "{803871A5-22F4-462B-8DE3-71CE86D96CD0}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {803871A5-22F4-462B-8DE3-71CE86D96CD0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {803871A5-22F4-462B-8DE3-71CE86D96CD0}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {803871A5-22F4-462B-8DE3-71CE86D96CD0}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {803871A5-22F4-462B-8DE3-71CE86D96CD0}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | GlobalSection(ExtensibilityGlobals) = postSolution 23 | SolutionGuid = {6F87FBF5-880E-4129-B5FD-9FF5D7324F11} 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /app/SpotifyNowPlaying.deps.json: -------------------------------------------------------------------------------- 1 | { 2 | "runtimeTarget": { 3 | "name": ".NETCoreApp,Version=v5.0", 4 | "signature": "" 5 | }, 6 | "compilationOptions": {}, 7 | "targets": { 8 | ".NETCoreApp,Version=v5.0": { 9 | "SpotifyNowPlaying/1.0.0": { 10 | "runtime": { 11 | "SpotifyNowPlaying.dll": {} 12 | } 13 | } 14 | } 15 | }, 16 | "libraries": { 17 | "SpotifyNowPlaying/1.0.0": { 18 | "type": "project", 19 | "serviceable": false, 20 | "sha512": "" 21 | } 22 | } 23 | } -------------------------------------------------------------------------------- /app/SpotifyNowPlaying.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maciekt07/SpotifyAdBlock/42c4dd1b6904494578425acca94432fb697c77f0/app/SpotifyNowPlaying.dll -------------------------------------------------------------------------------- /app/SpotifyNowPlaying.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maciekt07/SpotifyAdBlock/42c4dd1b6904494578425acca94432fb697c77f0/app/SpotifyNowPlaying.exe -------------------------------------------------------------------------------- /app/SpotifyNowPlaying.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maciekt07/SpotifyAdBlock/42c4dd1b6904494578425acca94432fb697c77f0/app/SpotifyNowPlaying.pdb -------------------------------------------------------------------------------- /app/SpotifyNowPlaying.runtimeconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "runtimeOptions": { 3 | "tfm": "net5.0", 4 | "framework": { 5 | "name": "Microsoft.NETCore.App", 6 | "version": "5.0.0" 7 | }, 8 | "configProperties": { 9 | "System.Reflection.Metadata.MetadataUpdater.IsSupported": false 10 | } 11 | } 12 | } -------------------------------------------------------------------------------- /img/ads-skip.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maciekt07/SpotifyAdBlock/42c4dd1b6904494578425acca94432fb697c77f0/img/ads-skip.png -------------------------------------------------------------------------------- /img/app-preview1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maciekt07/SpotifyAdBlock/42c4dd1b6904494578425acca94432fb697c77f0/img/app-preview1.png -------------------------------------------------------------------------------- /img/memory-usage.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maciekt07/SpotifyAdBlock/42c4dd1b6904494578425acca94432fb697c77f0/img/memory-usage.png --------------------------------------------------------------------------------