mp3_to_anchor.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import rpyc
  2. import os
  3. import random
  4. import string
  5. import requests
  6. from bs4 import BeautifulSoup
  7. import time
  8. def randomString(stringLength=10):
  9. letters = string.ascii_lowercase
  10. return ''.join(random.choice(letters) for i in range(stringLength))
  11. def mp3_to_anchor(fname):
  12. conn = rpyc.classic.connect("192.168.192.221",18812)
  13. fr=open(fname,'rb')
  14. ropen = conn.builtins.open
  15. randname=randomString(10)
  16. finalname=randomString(10)
  17. fw=ropen('/tmp/'+randname+'.mp3','wb')
  18. fw.write(fr.read())
  19. fw.close()
  20. ros = conn.modules.os
  21. ros.system('/root/to_video/p9.sh '+randname+".mp3 "+finalname+".mp4")
  22. return 'http://192.168.192.221/video/'+finalname+'.mp4'
  23. # conn.execute('import os')
  24. def download_mp4(url):
  25. headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36'}
  26. with open('ai_spokesgirl.mp4','wb') as f:
  27. r = requests.get(url, headers=headers, stream=True)
  28. if r.status_code == 404:
  29. return False
  30. for chunk in r.iter_content(chunk_size=1024):
  31. if chunk:
  32. f.write(chunk)
  33. return True
  34. if __name__ == '__main__':
  35. fname=mp3_to_anchor('/Users/zooeytsai/kw_tools/openshot/input/movie_main/Q8.mp3')
  36. print(fname)
  37. time.sleep(240)
  38. while True:
  39. result = download_mp4(fname)
  40. if result:
  41. break
  42. print('等待...')
  43. time.sleep(60)