KianBrose / Image-Recognition-Botting-Tutorial

Hello! This is the code I use in the https://www.youtube.com/watch?v=YRAIUA-Oc1Y video
222 stars 110 forks source link

file not working right #7

Closed Veudip closed 3 years ago

Veudip commented 3 years ago

so i modified your stickman code to skip youtube ads automatically but when i try to run it from cmd or IDLE (i use vs code to code everything) it raises this error: raise IOError("Failed to read %s because file is missing, " OSError: Failed to read Ohitamainos.png because file is missing, has improper permissions, or is an unsupported or invalid format

i tired if its cause path but it didnt fix it but when i made the pictures again with your regionscreenshotsaver i tworked once and then it didnt work anymore do you know why this happens?

python3

#This script locates the image skipadbutton.png in the region i gave it and then clicks it
from pathlib import Path
from pyautogui import * 
import pyautogui 
import time 
import keyboard 
import random
import win32api, win32con

#path = "C:\\Users\\veeti\\OneDrive\\Työpöytä\koodaus\\bot\\Image-Recognition-Botting-Tutorial-master\\Image-Recognition-Botting-Tutorial-master\\"
while True:
    if pyautogui.locateOnScreen('Ohitamainos.png', region=(0,0,1917,1039), grayscale=True, confidence=0.8) != None:
        x, y = pyautogui.locateCenterOnScreen('Ohitamainos.png', confidence=0.8)
        pyautogui.click(x, y)
        time.sleep(0.5)
    elif pyautogui.locateOnScreen('Ohitamainokset.png', region=(0,0,1917,1039), grayscale=True, confidence=0.8) != None:
        x, y = pyautogui.locateCenterOnScreen('Ohitamainokset.png', confidence=0.8)
        pyautogui.click(x, y)
        time.sleep(0.5)    
    else:
        print("no skips")
        time.sleep(0.2)
Veudip commented 3 years ago

this worked

from pathlib import Path
from pyautogui import * 
import pyautogui 
import time 
import keyboard 
import random
import win32api, win32con

while keyboard.is_pressed('up + down + right + left') == False:
    if pyautogui.locateOnScreen('Ohitamainos.jpg', region=(0,0,1917,1039), grayscale=True, confidence=0.8) != None:  
        x, y = pyautogui.locateCenterOnScreen('Ohitamainos.jpg', grayscale=True, confidence=0.8)  
        pyautogui.click(x, y, clicks=1)
        time.sleep(1)
    elif pyautogui.locateOnScreen('Ohitamainokset.jpg', region=(0,0,1917,1039), grayscale=True, confidence=0.8) != None:  
        x, y = pyautogui.locateCenterOnScreen('Ohitamainokset.jpg', grayscale=True, confidence=0.8) 
        pyautogui.click(x, y, clicks=1)
        time.sleep(1)    
    else:
        #print("no skips")
        time.sleep(0.2)