Skip to content

Instantly share code, notes, and snippets.

@justfoolingaround
Last active June 22, 2021 17:04
Show Gist options
  • Save justfoolingaround/2e5aa154b441e6f582b50ff2adf8d6f4 to your computer and use it in GitHub Desktop.
Save justfoolingaround/2e5aa154b441e6f582b50ff2adf8d6f4 to your computer and use it in GitHub Desktop.
Piece of code to automagically remove ads from your local Spotify instance

Auto BlockTheSpot

All the credit goes here!

This only supports the Desktop version of Spotify and not the Windows Store version.


Disable annoyances (One-Time Run)

The additional remove-bar.py will remove the annoying bar (the empty bar for ads since there will be no ads) above the playback controller.

The "Upgrade" button for upgrading to Spotify Premium can be disabled by using remove-upgrade-button.py.

import io
import os
import pathlib
import zipfile
import requests
DLL_URL = "https://github.com/mrpond/BlockTheSpot/releases/download/2021.4.20.35/chrome_elf.zip"
DLL_FILENAME = "chrome_elf.dll"
zip_file = zipfile.ZipFile(io.BytesIO(requests.get(DLL_URL).content))
SpotifyDLLPath = pathlib.Path(os.getenv('APPDATA')) / 'Spotify' / DLL_FILENAME
SpotifyDLLPath.chmod(0x1ff)
with zip_file.open(zip_file.getinfo('chrome_elf.dll'), 'r') as dll_file_stream, open(SpotifyDLLPath, 'wb') as dll_file_write_stream:
dll_file_write_stream.write(dll_file_stream.read())
import io
import os
import pathlib
import re
import zipfile
ui_styling_zip_fn = 'xpui.spa'
ui_styling_zip = pathlib.Path(os.getenv('APPDATA')) / 'Spotify' / 'Apps' / ui_styling_zip_fn
ui_styling_zip_backup = pathlib.Path(os.getenv('APPDATA')) / 'Spotify' / 'Apps' / (ui_styling_zip_fn + ".bak")
ui_styling_css = 'xpui.css'
bar_css_regexp = re.compile(rb"(?<=\.b2731cdeb97c1f6a4cf5caa44e943acb-scss{.{147})((?:(?!;).)+)", re.S | re.M)
with open(ui_styling_zip, 'rb') as ui_styler_stream:
b_stream = ui_styler_stream.read()
with open(ui_styling_zip_backup, 'wb') as ui_styler_backup:
ui_styler_backup.write(b_stream)
zip_file = zipfile.ZipFile(io.BytesIO(b_stream))
zip_file_write = zipfile.ZipFile(ui_styling_zip, 'w', zipfile.ZIP_DEFLATED)
zip_file_write.writestr(ui_styling_css, bar_css_regexp.sub(b'none', zip_file.read(ui_styling_css)))
for _f in zip_file.infolist():
if _f.filename != 'xpui.css':
zip_file_write.writestr(_f.filename, zip_file.read(_f.filename))
import io
import os
import pathlib
import re
import zipfile
ui_styling_zip_fn = 'xpui.spa'
ui_styling_zip = pathlib.Path(os.getenv('APPDATA')) / 'Spotify' / 'Apps' / ui_styling_zip_fn
ui_styling_zip_backup = pathlib.Path(os.getenv('APPDATA')) / 'Spotify' / 'Apps' / (ui_styling_zip_fn + ".bak")
ui_styling_css = 'xpui.css'
upgrade_button_css_regexp = re.compile(rb"(?<=\._3f37264be67c8f40fa9f76449afdb4bd-scss{.{83})(?:(?!;).)+", re.S | re.M)
with open(ui_styling_zip, 'rb') as ui_styler_stream:
b_stream = ui_styler_stream.read()
with open(ui_styling_zip_backup, 'wb') as ui_styler_backup:
ui_styler_backup.write(b_stream)
zip_file = zipfile.ZipFile(io.BytesIO(b_stream))
zip_file_write = zipfile.ZipFile(ui_styling_zip, 'w', zipfile.ZIP_DEFLATED)
zip_file_write.writestr(ui_styling_css, upgrade_button_css_regexp.sub(b'none', zip_file.read(ui_styling_css)))
for _f in zip_file.infolist():
if _f.filename != 'xpui.css':
zip_file_write.writestr(_f.filename, zip_file.read(_f.filename))
@crazyaccess
Copy link

I will ntr amazon prime music and youtube for this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment