Skip to content

Instantly share code, notes, and snippets.

@themanyone
Last active September 28, 2024 00:32
Show Gist options
  • Save themanyone/41b5a54684a016fd4e8bd13f8136648a to your computer and use it in GitHub Desktop.
Save themanyone/41b5a54684a016fd4e8bd13f8136648a to your computer and use it in GitHub Desktop.
Skip YouTube Ads, for Firefox
#!/usr/bin/python
# -*- coding: utf-8 -*-
LICENSE = """
Skip YouTube Ads - does what it says
Uses Python to launch a remote-controlled FireFox process.
Copyright (C) 2024 Henry Kroll III, www.thenerdshow.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
import sys
import time
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
if len(sys.argv) < 2:
print("usage: autoskip PwcldsQwalc #v=")
exit(0)
# Initialize the Firefox driver
driver = webdriver.Firefox()
# Navigate to the YouTube page
driver.get(f"https://www.youtube.com/watch?v={sys.argv[1]}")
while 1:
try:
# Wait for the class of skip button to appear
skip_button = WebDriverWait(driver,
10000).until(EC.presence_of_element_located((By.CLASS_NAME, "ytp-skip-ad-button")))
# Give button time to become clickable
time.sleep(1)
# Click the button
skip_button.click()
except:
# Skip errors.
pass
driver.quit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment