Skip to content

Automatically presses the 'skip' button on yt videos to skip ads.

Notifications You must be signed in to change notification settings

backrat13/skip-ad.py

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

skip-ad.py

Automatically presses the 'skip' button on yt videos to skip ads.

This is a very clean and robust script for automating a common web interaction task. It's essentially a dedicated YouTube Ad Skipper built using Selenium.

Here is a proper README.md for your script:


🚫 YouTube Ad Skipper (Selenium-Powered)

This Python script provides a robust, background utility to automatically detect and click the "Skip Ad" button on YouTube using the Selenium web automation framework. It's designed to run continuously in the background, minimizing interruptions during your viewing experience.


✨ Features

  • Continuous Ad Detection: Runs a non-blocking loop to constantly look for the skip button element.
  • Multi-Strategy Skipping: Utilizes a list of known and likely locators (Class Name, CSS Selector) for maximum compatibility with various YouTube ad formats.
  • Robust Click Logic: Implements JavaScript clicks as the primary method for reliable interaction, even when the element is visually obscured or prone to interception errors.
  • Error Handling: Catches common Selenium exceptions (TimeoutException, StaleElementReferenceException, etc.) to maintain stability.
  • Binary Auto-Detection: Automatically attempts to locate the Chromium/Chrome binary on common Linux/Unix paths.
  • Graceful Shutdown: Cleans up the WebDriver instance upon a user-initiated KeyboardInterrupt.

🛠️ Prerequisites

  • Python: Version 3.6+
  • Chromium/Chrome: The script requires a working installation of Google Chrome or Chromium. It attempts to find the binary at common locations (see CHROMIUM_CANDIDATES in the script).
  • ChromeDriver: The corresponding ChromeDriver executable must be available in your system's PATH, or you must have the selenium-manager dependency (which is bundled in recent Selenium versions) configured to handle it automatically.

🚀 Setup and Installation

1. Install Python Dependencies

Use pip to install the required library, Selenium:

pip install selenium

2. Configure Chrome Binary (Optional, if auto-detection fails)

If the script throws a RuntimeError regarding the binary not being found, you may need to update the CHROMIUM_CANDIDATES list in the script with the exact path to your browser executable.

3. Execution

Save the provided script as youtube_skipper.py and run it from your terminal:

python youtube_skipper.py

The script will:

  1. Launch a maximized Chrome browser instance and navigate to https://www.youtube.com.
  2. Start the main loop, periodically checking for the "Skip Ad" button.
  3. Automatically skip ads as they appear, logging the action.

4. Stopping the Script

To stop the background process, return to the terminal window where the script is running and press:

$$\text{Ctrl} + \text{C}$$

The browser window will close automatically.


⚙️ Configuration

The following variables can be easily modified in the script:

Variable Description Default Value
CHROMIUM_CANDIDATES List of paths where the script looks for the Chrome/Chromium executable. /usr/bin/chromium-browser, /usr/bin/chromium, /usr/bin/google-chrome
WAIT_TIMEOUT The maximum time (in seconds) to wait for the ad skip button to appear. 2
options.add_argument("--headless=new") Currently commented out. Uncomment this line to run the browser in the background without a visible window. N/A (Commented)

📝 Logging

The script utilizes Python's logging module. All actions, including the initial YouTube opening, successful skips, and user interruptions, are logged to the console with timestamps for easy monitoring.

Example Log Output:

10:30:05 INFO: Opened YouTube
10:30:15 INFO: Ad skipped via By.CLASS_NAME: ytp-ad-skip-button-modern
10:32:01 INFO: Ad skipped after interception
10:35:45 INFO: Stopped by user

About

Automatically presses the 'skip' button on yt videos to skip ads.

Resources

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

Packages

No packages published

Contributors 2

  •  
  •  

Languages