Render_video.py 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. #This file contains render video logic using pywin auto library.
  2. from conf import Config
  3. from pywinauto.application import Application ,ProcessNotFoundError
  4. from pywinauto.findwindows import WindowAmbiguousError, WindowNotFoundError
  5. from pywinauto.findbestmatch import MatchError
  6. from logger import log
  7. from helper import Automate
  8. import time
  9. import os
  10. import datetime
  11. import time
  12. import sys
  13. class render_video:
  14. def convert_files(self,file):
  15. _config = Config()
  16. backslash = "\\"
  17. app_path = _config.Original_Path+backslash+file
  18. #print(app_path)
  19. Auto=Automate()
  20. renderTime=Auto.renderTime(app_path,_config.Rendering_wait_time)
  21. IsFileCopied=Auto.IsCopyFinished(app_path)
  22. if IsFileCopied ==0:
  23. return
  24. if os.path.exists(app_path):
  25. os.startfile(app_path)
  26. else:
  27. log.logger.info("Trec file does not exists")
  28. return
  29. time.sleep(_config.App_time)
  30. # print("Sleep End!!!")
  31. try:
  32. if os.path.exists(_config.Camtasia_Path):
  33. app = Application().connect(path=_config.Camtasia_Path)
  34. else:
  35. log.logger.info("Camtasia executable not found!")
  36. return
  37. # To bring the Camtasia window to the focus.
  38. app_dialog = app.top_window_()
  39. app_dialog.Minimize()
  40. app_dialog.Restore()
  41. except(ProcessNotFoundError):
  42. log.logger.info("Not Camtasia process found... Exiting App")
  43. return
  44. except(WindowNotFoundError):
  45. log.logger.info("Not found Camtasia... Exiting App")
  46. app.kill()
  47. return
  48. except(WindowAmbiguousError):
  49. log.logger.info("There are too many Camtasia windows found... Exiting App")
  50. app.kill()
  51. return
  52. if os.path.exists(app_path):
  53. os.startfile(app_path)
  54. else:
  55. log.logger.info("Trec file does not exists... Exiting App")
  56. app.kill()
  57. return
  58. #for TRIAL
  59. if _config.Trial == 'YES':
  60. try:
  61. app.Window_(best_match='Dialog', top_level_only=True).ChildWindow(best_match='Finish').Click()
  62. except(MatchError):
  63. # print ' Not found Finish Dialog'
  64. log.logger.info("Not found Finish Dialog... Exiting App")
  65. app.kill()
  66. return
  67. time.sleep(_config.Dialog_wait_time)
  68. #end for TRIAL
  69. child_elements = app[_config.App_Name]
  70. #for clicking the share button
  71. child_elements.ClickInput(coords=(_config.Share_Btn_X, _config.Share_Btn_Y))
  72. child_elements.TypeKeys("{DOWN}")
  73. child_elements.TypeKeys("{ENTER}")
  74. time.sleep(_config.Dialog_wait_time)
  75. #for TRIAL
  76. if _config.Trial == 'YES':
  77. #for clicking the water mark button
  78. child_elements.Wait('visible',timeout=20)
  79. child_elements.ClickInput(coords=(_config.Water_Mark_Btn_X, _config.Water_Mark_Btn_Y))
  80. time.sleep(_config.Dialog_wait_time)
  81. #end for TRIAL
  82. for i in range(_config.Dialogs):
  83. time.sleep(2)
  84. child_elements.Wait('visible',timeout=20)
  85. try:
  86. app.Window_(best_match='Dialog', top_level_only=True).ChildWindow(best_match='Next').Click()
  87. except(MatchError):
  88. # print ' Not found Dialog to click the first Next. Check if coordinates are mentioned correctly in configuration.xml'
  89. log.logger.info("Not found Dialog to click the first Next. Check if coordinates are mentioned correctly in configuration.xml. Exiting App")
  90. app.kill()
  91. return
  92. stripped_file_name = os.path.splitext(os.path.basename(file))[0]
  93. dup_dir = Auto.check_duplicate(stripped_file_name,_config.Saved_Path);
  94. if dup_dir == 1:
  95. log.logger.info("Duplicate exists.The rendering will overwrite the existing directory")
  96. try:
  97. app.Window_(best_match='Dialog', top_level_only=True).ChildWindow(title="Untitled Project",class_name="Edit").SetText(stripped_file_name)
  98. except(MatchError):
  99. # print ' Not found Dialog to rename the project'
  100. log.logger.info("Not found Dialog to rename the project... Exiting App")
  101. app.kill()
  102. return
  103. try:
  104. app.Window_(best_match='Dialog', top_level_only=True).ChildWindow(best_match='Finish').Click()
  105. except(MatchError):
  106. # print ' Not found Dialog to click Finish'
  107. log.logger.info("Not found Dialog to click Finish... Exiting App")
  108. app.kill()
  109. return
  110. time.sleep(renderTime)
  111. app.kill_()
  112. time.sleep(_config.Dialog_wait_time)
  113. #print("Rendering Succcessful")
  114. return stripped_file_name
  115. #Finish rendering