11 Commits
linux ... v1.0L

Author SHA1 Message Date
Emi
1c6a19d015 new variable for playlist url 2025-07-07 17:46:03 -03:00
Emi
d16d80f04b update readme 2025-07-07 17:45:28 -03:00
Emi
35af328224 update readme 2025-07-07 17:24:08 -03:00
Emi
978a48b2ef update script 2025-07-07 17:16:13 -03:00
Emi
4ca93ba37c new images 2025-07-07 17:16:01 -03:00
Emi
4167922041 changes on readme 2025-07-06 20:39:39 -03:00
Emi
e7a0760e5f changes on readme 2025-07-05 23:37:06 -03:00
Emi
1d9b4ff0dd changed readme 2025-07-05 23:35:38 -03:00
Emi
0519e67cb0 refactor script.py 2025-07-05 23:10:41 -03:00
Emi
3395c619bc new comment 2025-07-05 23:04:44 -03:00
Emi
e487260e31 refactor on script 2025-07-05 23:02:57 -03:00
4 changed files with 317 additions and 29 deletions

185
README.md Normal file
View File

@@ -0,0 +1,185 @@
# AutoDelete YouTube Videos 🗑️🎬
This script automates the process of deleting videos from your YouTube "Watch Later" playlist using PyAutoGUI.
---
## Requirements 📦
- Python **3.11.10** 🐍
---
## Setup & Usage (English) 🇬🇧
### ⚙️ Requirements
- Python **3.11.10** 🐍
### 1⃣ Create a Virtual Environment
**With `venv`:**
```bash
python3.11 -m venv venv
```
**With `virtualenv`:**
```bash
python3.11 -m pip install virtualenv
python3.11 -m virtualenv venv
```
### 2⃣ Activate the Virtual Environment
**On Linux/macOS:**
```bash
source venv/bin/activate
```
**On Windows:**
```bash
venv\Scripts\activate
```
### 3⃣ Install Dependencies
```bash
pip install -r requirements.txt
```
### 4⃣ Run the Script 🚀
```bash
python script.py
```
---
## Features & Customization 🛠️
### Features
- 🖼️ **Image Recognition:**
Uses screenshots in the `img` folder to locate and interact with UI elements (browser icon, YouTube buttons, etc).
- 🔍 **Region-based Search:**
The script splits the screen into left and right halves to speed up image searches.
- 🗂️ **Automatic Tab Handling:**
Automatically opens/closes tabs and navigates to your "Watch Later" playlist.
- ⏱️ **Timing Controls:**
You can adjust `sleep` and `duration` values in the code to match your PC's speed.
- 🛑 **Hotkey Listener:**
Press `q` at any time to safely stop the script.
- 🖱️ **Easy Customization:**
Change the images in the `img` folder or tweak the logic in functions like `locate_img` and `change_to_not_available` to adapt to UI changes or other platforms.
### Customization
- 🖼️ **Browser Image:**
Replace the browser icon image in the `img` folder with a screenshot of your browser's icon. Make sure the filename matches the value of the `browser_img` variable in `script.py` (e.g., `brave.png` for Brave browser).
- 🔗 **Playlist URL:**
You can change the playlist URL by editing the value of the `playlist_url` variable at the top of the `script.py` file.
- ⏱️ **Adjust Timing:**
The script uses `sleep` and `duration` values to wait for your PC to respond. You may need to increase or decrease these values depending on your computer's speed and internet connection.
- 📌 **Pin Your Browser:**
For the script to work, your browser must be pinned to your taskbar.
---
# AutoDelete YouTube Videos 🗑️🎬
Este script automatiza el proceso de eliminar videos de tu lista de "Ver más tarde" en YouTube usando PyAutoGUI.
---
## Requisitos 📦
- Python **3.11.10** 🐍
---
## Configuración y Uso (Español) 🇪🇸
### ⚙️ Requisitos
- Python **3.11.10** 🐍
### 1⃣ Crear un Entorno Virtual
**Con `venv`:**
```bash
python3.11 -m venv venv
```
**Con `virtualenv`:**
```bash
python3.11 -m pip install virtualenv
python3.11 -m virtualenv venv
```
### 2⃣ Activar el Entorno Virtual
**En Linux/macOS:**
```bash
source venv/bin/activate
```
**En Windows:**
```bash
venv\Scripts\activate
```
### 3⃣ Instalar las Dependencias
```bash
pip install -r requirements.txt
```
### 4⃣ Ejecutar el Script 🚀
```bash
python script.py
```
---
## Funcionalidades y Personalización 🛠️
### Funcionalidades
- 🖼️ **Reconocimiento de Imágenes:**
Usa capturas en la carpeta `img` para localizar e interactuar con elementos de la interfaz (icono del navegador, botones de YouTube, etc).
- 🔍 **Búsqueda por Regiones:**
El script divide la pantalla en mitades izquierda y derecha para acelerar la búsqueda de imágenes.
- 🗂️ **Manejo Automático de Pestañas:**
Abre/cierra pestañas y navega automáticamente a tu lista de "Ver más tarde".
- ⏱️ **Control de Tiempos:**
Puedes ajustar los valores de `sleep` y `duration` en el código según la velocidad de tu PC.
- 🛑 **Escucha de Teclas:**
Presiona `q` en cualquier momento para detener el script de forma segura.
- 🖱️ **Fácil Personalización:**
Cambia las imágenes en la carpeta `img` o ajusta la lógica en funciones como `locate_img` y `change_to_not_available` para adaptarlo a cambios en la interfaz o a otras plataformas.
### Personalización
- 🖼️ **Imagen del Navegador:**
Reemplaza la imagen del icono de tu navegador en la carpeta `img` con una captura de pantalla del icono de tu navegador. Asegúrate de que el nombre del archivo coincida con el valor de la variable `browser_img` en `script.py` (por ejemplo, `brave.png` para el navegador Brave).
- 🔗 **URL de la Playlist:**
Puedes cambiar la URL de la playlist que se usa modificando el valor de la variable `playlist_url` al inicio del archivo `script.py`.
- ⏱️ **Ajusta los Tiempos:**
El script utiliza valores de `sleep` y `duration` para esperar la respuesta de tu PC. Puede que necesites aumentar o disminuir estos valores dependiendo de la velocidad de tu computadora y conexión a internet.
- 📌 **Ancla tu Navegador:**
Para que el script funcione, es indispensable que tengas tu navegador anclado a tu barra de tareas.

BIN
img/not-available.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.5 KiB

BIN
img/pl_opt.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 902 B

145
script.py
View File

@@ -1,48 +1,151 @@
import pyautogui as pgui
import time
import keyboard as kb
import sys
# colocar el nombre de tu navegador, basado en el nombre de la imagen de su respectivo icono
browser = 'brave'
browser_loc = pgui.locateCenterOnScreen(f'img/{browser}.png', confidence=0.8)
playlist_url = 'https://www.youtube.com/playlist?list=WL'
half_left = (
0,
0,
pgui.size().width // 2,
pgui.size().height
)
half_right = (
pgui.size().width // 2,
0,
pgui.size().width,
pgui.size().height
)
def locate_img(
image: str,
sleep_time:float=None,
search_time:float=0,
confidence:float=1.0,
gray_scale:bool=False,
region:tuple[int,int,int,int]=None
):
"""Locate and click on an image. Returns True if successful, False otherwise."""
try:
opt_loc = pgui.locateCenterOnScreen(
f'img/{image}',
confidence=confidence,
minSearchTime=search_time,
grayscale=gray_scale,
region=region
)
if opt_loc:
pgui.click(opt_loc)
if sleep_time:
time.sleep(sleep_time)
return True
except Exception as e:
print(f"Error locating '{image}': {e}")
return False
def change_to_not_available():
try:
success = locate_img('pl_opt.png', sleep_time=0.2, search_time=0.5, confidence=0.8, gray_scale=True, region=half_left)
if not success: return False
success = locate_img('not-available.png', search_time=0.5, confidence=0.8)
if not success: return False
window = pgui.size()
x_pos = 3 * (window.width / 4)
y_pos = window.height / 2
pgui.moveTo(x_pos, y_pos)
time.sleep(5)
success = locate_img('options.png', sleep_time=0.2, confidence=0.8, gray_scale=True, region=half_right)
if not success: return False
return True
except:
print(f"Critical error in change_to_not_available")
return False
# Enter the name of your browser, based on the name of its icon image.
browser_img = 'brave.png'
browser_loc = pgui.locateCenterOnScreen(f'img/{browser_img}', confidence=0.8)
if browser_loc:
pgui.moveTo(browser_loc, duration=0.2)
time.sleep(0.2)
pgui.click()
# cambia el tiempo dependiendo de cuanto tarde en abrir tu navegador
# Change the time depending on how long it takes to open your browser
time.sleep(2)
else:
print("Browser icon not found.")
sys.exit('closing script')
pgui.hotkey('ctrl', 't')
pgui.write('https://www.youtube.com/playlist?list=WL')
pgui.write(playlist_url)
time.sleep(0.05)
pgui.press("enter")
# cambiar dependiendo de cuanto tarde en cargarte yt
# change depending on how long it takes to load yt
time.sleep(5)
videos = int(input('number of videos: '))
while videos != 0:
if __name__ == '__main__':
counter = 0
while True:
if kb.is_pressed('q'):
print(':(')
break
opt_loc = pgui.locateCenterOnScreen('img/options.png', confidence=0.8)
if counter > 0 and (counter % 90) == 0:
pgui.hotkey('ctrl', 'w')
pgui.hotkey('ctrl', 't')
pgui.write(playlist_url)
pgui.press("enter")
time.sleep(8)
pgui.moveTo(opt_loc, duration=0.2)
pgui.click()
try:
success = locate_img('options.png', sleep_time=0.2, confidence=0.8, gray_scale=True, region=half_right)
if not success:
print('changing plans to enable videos...')
second_success = change_to_not_available()
if not second_success:
break
except:
print('Error finding options image')
break
try:
success = locate_img('delete.png', confidence=0.8)
if success:
counter += 1
print(f"Deleted {counter} videos.")
time.sleep(0.2)
del_loc = pgui.locateCenterOnScreen('img/delete.png', confidence=0.8)
else: break
pgui.moveTo(del_loc, duration=0.2)
pgui.click()
time.sleep(0.2)
except Exception as e:
print(f"Error in delete step: {e}")
break
videos -= 1
print("Script finished.")