mirror of
https://github.com/FranP-code/classify_saved_videos_yt.git
synced 2025-10-13 00:32:25 +00:00
update script
This commit is contained in:
137
script.py
137
script.py
@@ -1,9 +1,83 @@
|
|||||||
import pyautogui as pgui
|
import pyautogui as pgui
|
||||||
import time
|
import time
|
||||||
import keyboard as kb
|
# import keyboard as kb
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
|
||||||
|
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.
|
# Enter the name of your browser, based on the name of its icon image.
|
||||||
browser_img = 'brave.png'
|
browser_img = 'brave.png'
|
||||||
|
|
||||||
@@ -27,28 +101,49 @@ pgui.press("enter")
|
|||||||
# change depending on how long it takes to load yt
|
# change depending on how long it takes to load yt
|
||||||
time.sleep(5)
|
time.sleep(5)
|
||||||
|
|
||||||
while True:
|
if __name__ == '__main__':
|
||||||
|
counter = 0
|
||||||
|
|
||||||
if kb.is_pressed('q'):
|
while True:
|
||||||
print(':(')
|
# if kb.is_pressed('q'):
|
||||||
break
|
# 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('https://www.youtube.com/playlist?list=WL')
|
||||||
|
pgui.press("enter")
|
||||||
|
time.sleep(8)
|
||||||
|
|
||||||
if opt_loc:
|
|
||||||
pgui.moveTo(opt_loc, duration=0.2)
|
|
||||||
pgui.click()
|
|
||||||
time.sleep(0.2)
|
|
||||||
else:
|
|
||||||
print('options button not founded')
|
|
||||||
break
|
|
||||||
|
|
||||||
del_loc = pgui.locateCenterOnScreen('img/delete.png', confidence=0.8)
|
try:
|
||||||
|
|
||||||
if del_loc:
|
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()
|
if not success:
|
||||||
time.sleep(0.2)
|
print('changing plans to enable videos...')
|
||||||
else:
|
second_success = change_to_not_available()
|
||||||
print('delete button not founded')
|
|
||||||
break
|
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