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
+ }
0 commit comments