26 lines
840 B
Python
26 lines
840 B
Python
|
import re
|
||
|
import sys
|
||
|
|
||
|
try:
|
||
|
import qutebrowser.api
|
||
|
from qutebrowser.api import interceptor
|
||
|
from qutebrowser.extensions.interceptors import Request
|
||
|
from qutebrowser.qt.core import QUrl
|
||
|
from qutebrowser.utils import debug, log
|
||
|
except ImportError:
|
||
|
sys.stderr.write('qutebrowser not imported\n')
|
||
|
else:
|
||
|
# Block youtube ads
|
||
|
def filter_yt(info: Request) -> None:
|
||
|
"""Block given request if necessary"""
|
||
|
lYT_URLS = ( "www.youtube.com", "youtube.com", "youtu.be" )
|
||
|
url = info.request_url
|
||
|
if url.host() in lYT_URLS \
|
||
|
and url.path() == "/get_video_info" \
|
||
|
and "&adformat=" in url.query():
|
||
|
log.network.info(f"Blocking to {url}")
|
||
|
info.block()
|
||
|
interceptor.register(filter_yt)
|
||
|
log.init.debug(f"loaded filter_yt interceptor")
|
||
|
|