fork(4) download
  1. import pyautogui
  2. import time
  3. import pyperclip
  4. import subprocess
  5. import functools
  6. import math
  7. import os
  8. import os.path
  9. import shutil
  10. import sys
  11. import re
  12.  
  13. # x = 255
  14. # y = 250
  15.  
  16. # x, y = pyautogui.position()
  17.  
  18.  
  19. def askMeToCLick(width, height):
  20. pyautogui.click(width, height, duration=0.50)
  21.  
  22.  
  23. def askMeToMaximiseMinimise():
  24. print("\n ------Maximise&askMeToMaximise Invoked ---------\n")
  25. askMeToCLick(1903, 1061)
  26.  
  27.  
  28. def startKazam():
  29. print("\n ------startKazam Invoked ---------\n")
  30. pyautogui.hotkey('ctrlleft', 'winleft', 'r')
  31.  
  32.  
  33. def stopKazam():
  34. print("\n ------stopKazam Invoked ---------\n")
  35. pyautogui.hotkey('ctrlleft', 'winleft', 'f')
  36.  
  37.  
  38. def openKazam():
  39. print("\n ------openKazam Invoked ---------\n")
  40. askMeToCLick(22, 1904)
  41.  
  42.  
  43. def saveFile():
  44. print("\n ------saveFile Invoked ---------\n")
  45. askMeToCLick(1880, 1058)
  46.  
  47.  
  48. def copyFilename():
  49. pyautogui.moveTo(377, 127)
  50. pyautogui.click()
  51. pyautogui.dragTo(1190, 135, duration=0.25)
  52. pyautogui.hotkey('ctrl', 'c')
  53.  
  54.  
  55. def copyFoldername():
  56. # global x, y
  57. # # pyautogui.click(x, y)
  58. pyautogui.click(x, y)
  59. pyautogui.dragRel(300, 10, duration=0.25)
  60. pyautogui.hotkey('ctrl', 'c')
  61. pyautogui.click(x, y)
  62.  
  63.  
  64. def checkYoutubeButton():
  65. pyautogui.moveTo(800, 410, duration=0.250)
  66. im = pyautogui.screenshot()
  67. print(im.getpixel((1179, 631)))
  68. print(pyautogui.pixelMatchesColor(1179, 631, (255, 255, 255)))
  69. # sys.exit()
  70. return pyautogui.pixelMatchesColor(1179, 631, (255, 255, 255))
  71.  
  72.  
  73. def clickYoutubeButton():
  74. if(checkYoutubeButton):
  75. pyautogui.rightClick(1179, 631, duration=0.250)
  76. askMeToCLick(1199, 654)
  77. downloadVideoInTerminal()
  78.  
  79.  
  80. def downloadVideoInTerminal():
  81. global folderName
  82. print("Downloading Youtube Video")
  83. url = pyperclip.paste()
  84. print("Url = {a}".format(a=url))
  85. # dest = '{val}'.format(val=folderName)
  86. subprocess.run(["you-get", "-o", folderName, url])
  87.  
  88. # subprocess.run(["you-get","-o",'\"Graphs.(SelfStudy)\"',"https://y...content-available-to-author-only...u.be/MTsvJUwZdS4"])
  89.  
  90.  
  91. def checkTitleOrFile(x, y):
  92. print("X = {A} Y= {B}".format(A=x, B=y))
  93. im = pyautogui.screenshot()
  94. yn = pyautogui.pixelMatchesColor(x, y, (42, 42, 42))
  95. if yn:
  96. print("File")
  97. return 1 # File
  98. else:
  99. print("Folder")
  100. return 0 # Folder
  101.  
  102.  
  103. def get_time():
  104. pyautogui.click(1500, 870)
  105. pyautogui.hotkey('ctrlleft', 'shiftleft', 'j')
  106. pyautogui.click(1498, 735, duration=0.25)
  107. sys.exit()
  108. pyautogui.click(1175, 129, duration=0.25)
  109. pyautogui.click(1145, 170, duration=0.25)
  110. pyautogui.typewrite("document.getElementById('video').duration", 0.10)
  111. pyautogui.press('enter')
  112. pyautogui.click(1155, 171, duration=0.25)
  113. pyautogui.dragTo(1291, 173, duration=0.5)
  114. pyautogui.hotkey('ctrl', 'c')
  115. pyautogui.click(1894, 114)
  116. value = pyperclip.paste()
  117. time = float(value)
  118. time = math.ceil(time)
  119. print("Time For the Video Is ={t}".format(t=time))
  120. return time
  121.  
  122.  
  123. def set_duration():
  124. pyautogui.click(1500, 870)
  125. pyautogui.hotkey('ctrlleft', 'shiftleft', 'j')
  126. pyautogui.click(1498, 735, duration=0.25)
  127. pyautogui.click(1175, 129, duration=0.25)
  128. sys.exit()
  129. pyautogui.click(1145, 170, duration=0.25)
  130. pyautogui.typewrite("document.getElementById('video').currentTime=0", 0.10)
  131. pyautogui.press('enter')
  132. pyautogui.click(1894, 114)
  133.  
  134.  
  135. def createFolder(folderName):
  136. try:
  137. if os.path.isdir(os.path.join(os.getcwd(), folderName)) == False:
  138. os.makedirs(folderName)
  139. print("Directory Created")
  140. else:
  141. print("\n Directory Present No Need To Create A Directory")
  142. except:
  143. print("Directory Not Created")
  144.  
  145.  
  146. def moveFiles(folderName):
  147. try:
  148. path = "/home/ashish/Desktop/folder_name/"
  149. moveto = "/home/ashish/Desktop/folder_name/" + folderName + "/"
  150. files = os.listdir(path)
  151. files.sort()
  152. for f in files:
  153. if f.endswith(".mp4"):
  154. src = path + f
  155. dst = moveto + f
  156. shutil.move(src, dst)
  157. elif f.endswith(".srt"):
  158. src = path + f
  159. dst = moveto + f
  160. shutil.move(src, dst)
  161.  
  162. except:
  163. print("---------------File Movement Failed------------")
  164.  
  165.  
  166. def renameFiles(file):
  167. path = "/home/ashish/Desktop/folder_Name/"
  168. moveTo = "/home/ashish/Desktop/folder_Name/"
  169. os.listdir(os.getcwd())
  170. files = os.listdir(path)
  171.  
  172. name = file + ".mp4"
  173. for f in files:
  174. if f.startswith("coding"):
  175. print("\n" + f + "\n")
  176. os.rename(f, name)
  177.  
  178.  
  179. def scrollIndex():
  180. # global x, y
  181. # pyautogui.click(x, y)
  182. # pyautogui.press('down')
  183. # pyautogui.press('down')
  184. pyautogui.scroll(-16)
  185.  
  186.  
  187. def increasey():
  188. global y
  189. y += 40
  190.  
  191.  
  192. def close(a, b):
  193. askMeToCLick(a, b)
  194.  
  195.  
  196. def PauseVideo():
  197. print("\n ------PauseVideo Invoked ---------\n")
  198. pyautogui.click(777, 458)
  199. pyautogui.press('space')
  200. print("\n ------PauseVideo End ---------\n")
  201.  
  202.  
  203. def PlayVideo():
  204. print("\n ------PlayVideo Invoked ---------\n")
  205. pyautogui.click(777, 458)
  206. pyautogui.press('space')
  207. print("\n ------PlayVideo End ---------\n")
  208.  
  209.  
  210. def CheckPlayPause():
  211. data = pyautogui.locateOnScreen('pl.png')
  212. if data is None:
  213. PauseVideo()
  214. pyautogui.press('space')
  215.  
  216.  
  217. def removeNum(in_string):
  218. out_string = filter(lambda c: not c.isdigit(), in_string)
  219. data = list(out_string)
  220. out_string = ""
  221. for i in data:
  222. out_string += i
  223. return out_string
  224.  
  225.  
  226. def createLog(txt):
  227. file = open('log.txt', 'a+')
  228. file.write(txt)
  229. file.close()
  230.  
  231.  
  232. folderName = ""
  233. var = 0
  234. x = 100
  235. y = 210
  236. i = 0
  237. a = 0
  238. b = 0
  239. fileCount = 0
  240.  
  241.  
  242. def whatIsFolderName():
  243. global folderName
  244. folderName = pyperclip.paste().strip().replace(" ", "")
  245. print("\n---Folder Name={f}---\n".format(f=folderName))
  246. folderName = removeNum(folderName)
  247. folderName = re.sub('\ |(|)|\?|\.|\!|\/|\;|\:', '', folderName)
  248.  
  249.  
  250. def whatIsFileName():
  251. fileName = pyperclip.paste().strip().replace(" ", "")
  252. fileName = re.sub('[0-9]| |\| (|)|\?|\.|\!|\/|\;|\:', '', fileName)
  253. print("\n---File Name={f}---\n".format(f=fileName))
  254. return fileName
  255.  
  256.  
  257. def youtubeDownloadProcess():
  258. global fileCount, folderName
  259. clickYoutubeButton()
  260. createLog(str(fileCount) + " . Youtube File Created\n")
  261. # print("Move Files Called")
  262. # moveFiles(folderName)
  263. time.sleep(2)
  264.  
  265.  
  266. def kazamRecordProcess(fileName):
  267. global folderName, fileCount
  268.  
  269. set_duration()
  270. time.sleep(2)
  271. videoTime = get_time() - 3
  272. print(
  273. "\n------Sleeping For ----= {d}\n".format(d=videoTime))
  274.  
  275. askMeToMaximiseMinimise()
  276. time.sleep(1)
  277.  
  278. # openKazam()
  279. startKazam()
  280.  
  281. time.sleep(1)
  282. PlayVideo()
  283.  
  284. time.sleep(videoTime) # videoTime
  285.  
  286. stopKazam()
  287. time.sleep(2)
  288.  
  289. renameFiles(fileName)
  290.  
  291. message = (str(fileCount) + ' . ' +
  292. str(fileName) + ' created\n')
  293. createLog(message)
  294.  
  295. askMeToMaximiseMinimise()
  296.  
  297. moveFiles(folderName)
  298.  
  299.  
  300. def relocateCursor():
  301. global i, a, b, x, y
  302. temp = ""
  303. if i > 0:
  304. close(a, b)
  305. moveFiles(temp)
  306. # time.sleep(1)
  307. i = 0
  308. y = b + 40
  309. if(i == 0):
  310. a = x
  311. b = y
  312. increasey()
  313. i = i + 1
  314.  
  315.  
  316. def checkFilePresent(name):
  317. pathV = "/home/ashish/Desktop/Folder_Name/" + name +".mp4"
  318. return os.path.isfile(pathV)
  319.  
  320.  
  321. def main():
  322. global i
  323. global y, x, folderName, a, b, var, fileCount
  324. while(y <= 1080):
  325. if (checkTitleOrFile(x, y) == 0):
  326. # print("\n----------- Creating Folder-----------\n")
  327. #
  328. # copyFoldername()
  329. # whatIsFolderName()
  330. # createFolder(folderName)
  331. relocateCursor()
  332. continue
  333.  
  334. else:
  335. # FIle Counter
  336. fileCount += 1
  337.  
  338. # print("\n----------- Creating File-----------\n")
  339.  
  340. pyautogui.click(x, y, duration=0.25)
  341. # waiting to load video
  342. time.sleep(4)
  343.  
  344. if checkYoutubeButton():
  345. # print("Youtube File")
  346. # youtubeDownloadProcess()
  347. increasey()
  348. continue
  349.  
  350. else:
  351. CheckPlayPause()
  352.  
  353. # Copy File Name
  354. copyFilename()
  355. fileName = whatIsFileName()
  356.  
  357. if checkFilePresent(fileName) == True:
  358. continue
  359. kazamRecordProcess(fileName)
  360. increasey()
  361.  
  362.  
  363. if __name__ == "__main__":
  364. time.sleep(5)
  365. main()
  366.  
  367. # fileName = removeNum(fileName)
Runtime error #stdin #stdout #stderr 0.01s 27712KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Traceback (most recent call last):
  File "./prog.py", line 1, in <module>
ImportError: No module named 'pyautogui'