mirror of
https://github.com/FranP-code/classify_saved_videos_yt.git
synced 2025-10-13 00:32:25 +00:00
Compare commits
11 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1c6a19d015 | ||
|
|
d16d80f04b | ||
|
|
35af328224 | ||
|
|
978a48b2ef | ||
|
|
4ca93ba37c | ||
|
|
4167922041 | ||
|
|
e7a0760e5f | ||
|
|
1d9b4ff0dd | ||
|
|
0519e67cb0 | ||
|
|
3395c619bc | ||
|
|
e487260e31 |
185
README.md
Normal file
185
README.md
Normal 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
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
BIN
img/pl_opt.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 902 B |
161
script.py
161
script.py
@@ -1,48 +1,151 @@
|
||||
import pyautogui as pgui
|
||||
import time
|
||||
import keyboard as kb
|
||||
|
||||
# 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)
|
||||
|
||||
pgui.moveTo(browser_loc, duration=0.2)
|
||||
time.sleep(0.2)
|
||||
pgui.click()
|
||||
|
||||
# cambia el tiempo dependiendo de cuanto tarde en abrir tu navegador
|
||||
time.sleep(2)
|
||||
import sys
|
||||
|
||||
|
||||
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)
|
||||
pgui.click()
|
||||
# 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: '))
|
||||
if __name__ == '__main__':
|
||||
counter = 0
|
||||
|
||||
while videos != 0:
|
||||
while True:
|
||||
if kb.is_pressed('q'):
|
||||
print(':(')
|
||||
break
|
||||
|
||||
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()
|
||||
time.sleep(0.2)
|
||||
try:
|
||||
|
||||
del_loc = pgui.locateCenterOnScreen('img/delete.png', confidence=0.8)
|
||||
success = locate_img('options.png', sleep_time=0.2, confidence=0.8, gray_scale=True, region=half_right)
|
||||
|
||||
pgui.moveTo(del_loc, duration=0.2)
|
||||
pgui.click()
|
||||
time.sleep(0.2)
|
||||
if not success:
|
||||
print('changing plans to enable videos...')
|
||||
second_success = change_to_not_available()
|
||||
|
||||
videos -= 1
|
||||
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)
|
||||
|
||||
else: break
|
||||
|
||||
except Exception as e:
|
||||
print(f"Error in delete step: {e}")
|
||||
break
|
||||
|
||||
print("Script finished.")
|
||||
|
||||
Reference in New Issue
Block a user