I chose Skusta's MV continuous playback function as a subject for self-study of Python, but the completed program can play MV loops, but in reality only one song can be played and it is too poor to say that it is a continuous playback function. It was a thing.
This time, I will implement the operation to send the song list down after the end of playback.
Previous article: Play the MV of Python Skusta for the first time continuously
You can advance songs by clicking inside the red frame in the above image, but as you can see from the song list, it is unique because each song is completely different and the range that can be used as a common part is covered with other songs It seems difficult to choose the part. Here, first get the coordinates of the part that will surely be unique on the screen, and then click the coordinates with the offset amount added.
The part surrounded by the blue frame in the above image was targeted.
coding:utf-8
MAIN_PATH:str=".\\MVPlay\\"
FILE_TYPE:str="*.png "
# Argument constant
FILES:int=0
FILEEVENTS:int=1
WAITTIME:int=2
# Constant for acquiring X and Y coordinates
X:int=0
Y:int=1
# Event definition constant
CLICK:int=0
SWIPE:int=1
RECURE:int=2
EXIT:int=3
# Constant for file event
FILE:int=0
EVENT:int=1
ARG1:int=2
ARG2:int=3
ARG3:int=4
# Define file event
FILEEVENTS_MAIN:list=[
#When the image matches the file name, click the position where the coordinates are offset by the specified value.
[".\\MVPlay\\03scroll.png ",CLICK,[220,630],None,None]
]
coding:utf-8
from pydef import*
# Get file event
def getFileEvent(fn:str,fev):
for tmpl in fev:
if tmpl[FILE]==fn:
return tmpl
return None
# It keeps increasing every time the image recognition is successful, and returns to the beginning when all the files are finished.
def sequentialCount(i:int,maxcount:int):
if i>=maxcount:
return 0
else:
return i+1
coding:utf-8
import pyautogui
import glob
import time
from pydef import*
from pyfunc import*
# Execute processing corresponding to the event
# Since the main function is called recursively, write it in main instead of pyfunc.
def fileEvent(arg:list,loc:list):
#Click when there is nothing
if arg==None:
pyautogui.click(loc[X],loc[Y])
#Click event
elif arg[EVENT]==CLICK:
loc=[x+y for (x,y) in zip(loc,arg[ARG1])]
pyautogui.click(loc[X],loc[Y])
#Swipe event
elif arg[EVENT]==SWIPE:
_n = None # Not implemented
#Recursion event
elif arg[EVENT]==RECURE:
flist=glob.glob(arg[ARG1]+FILE_TYPE)
main([flist,arg[ARG2],arg[ARG3]])
#End event
elif arg[EVENT]==EXIT:
exit()
# Based on the received file list and file event list
# Keep running the event
def main(arg:list):
i:int=0
while True:
#Image recognition check
loc=pyautogui.locateCenterOnScreen(arg[FILES][i])
if not(loc==None):
time.sleep(arg[WAITTIME])
#File event execution
fileEvent(getFileEvent(arg[FILES][i],arg[FILEEVENTS]),loc)
i=sequentialCount(i,len(arg[FILES])-1)
time.sleep(arg[WAITTIME])
flist=glob.glob(MAIN_PATH+FILE_TYPE)
main([flist,FILEEVENTS_MAIN,0.5])
It's been a lot longer than last time, but most of them are constant declarations.
[".\\MVPlay\\03scroll.png ",CLICK,[220,630],None,None]
This definition means that when a file with the same name as ". \ MVPlay \ 03scroll.png " including the path is read, 220 and 620 are added to the X and Y coordinates matched by image recognition and clicked. ..
# Execute processing corresponding to the event
# Since the main function is called recursively, write it in main instead of pyfunc.
def fileEvent(arg:list,loc:list):
#Click when there is nothing
if arg==None:
pyautogui.click(loc[X],loc[Y])
#Click event
elif arg[EVENT]==CLICK:
loc=[x+y for (x,y) in zip(loc,arg[ARG1])]
pyautogui.click(loc[X],loc[Y])
#Swipe event
elif arg[EVENT]==SWIPE:
_n = None # Not implemented
#Recursion event
elif arg[EVENT]==RECURE:
flist=glob.glob(arg[ARG1]+FILE_TYPE)
main([flist,arg[ARG2],arg[ARG3]])
#End event
elif arg[EVENT]==EXIT:
exit()
Events defined in the file are processed by the newly added fileEvent function. Events other than CLICK are not particularly meaningful for now as they may be needed.
Now, the series of operations of pressing the MV button → pressing the play button → moving to the next song when the MV playback is completed and the song list screen is returned has been automated. The only thing I thought about this time was that the list was too convenient.I didn't get it right when I heard the story, but I can feel it by touching it. Calling the callback function when defining the file event. It may be fun to design it.
Since it also has a song list movement function, I feel that I'm getting closer to my ideal continuous playback, but the problem that uncleared songs and MVs stop at unimplemented songs still remains. Next, I would like to solve this problem.
Recommended Posts