-
Notifications
You must be signed in to change notification settings - Fork 0
/
spotify-noads.py.j2
executable file
·51 lines (41 loc) · 1.7 KB
/
spotify-noads.py.j2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/python3
import os
import time
from selenium import webdriver
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
os.popen("for process in $(ps -ef |grep spotify-no-ads-profile |grep -v 'grep' |awk '{print $2}'); do kill $process; done").read()
options = webdriver.ChromeOptions()
options.add_argument('--ignore-certificate-errors')
options.add_argument("--window-size=2110,1234")
options.add_argument("--user-data-dir={{ ansible_env.HOME}}/.config/google-chrome/spotify-no-ads-profile")
options.add_argument("--enable-extensions")
# Define the webdriver to use.
# Chrome webdriver
driver = webdriver.Chrome(options=options)
# Go to the website
def go_to_main_site():
driver.get('https://open.spotify.com/')
time.sleep(1)
def mute_add():
audio_enabled = True
try:
now_playing = WebDriverWait(driver, 5).until(EC.presence_of_element_located((By.XPATH, '//a[@aria-label="Advertisement"]'))).get_attribute("aria-label")
if "Advertisement" in now_playing and audio_enabled:
print("Mute audio")
os.popen("amixer set Master mute").read()
audio_enabled = False
while not audio_enabled:
try:
WebDriverWait(driver, 1).until(
EC.presence_of_element_located((By.XPATH, '//a[@aria-label="Advertisement"]'))).get_attribute("aria-label")
except:
print("Enable audio")
os.popen("amixer set Master unmute").read()
audio_enabled = True
except:
pass
go_to_main_site()
while True:
mute_add()