reddit-read.py 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #!/usr/bin/env python
  2. import requests
  3. import os
  4. import base64
  5. subreddit="entitledparents"
  6. # Some speech to text tool. Output has to be a .wav
  7. texttospeech = 'mimic -t "TEXT" -o FILE'
  8. headers = {'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20121201 icecat/17.0.1'}
  9. data = requests.get(f"https://www.reddit.com/r/{subreddit}.json?limit=400",headers=headers).json()
  10. num = 0
  11. for i, post in enumerate(data["data"]["children"]):
  12. if i == 0:
  13. pass
  14. elif i == 5:
  15. break
  16. else:
  17. num = num+1
  18. text = post["data"]["selftext_html"].replace(";","")\
  19. .replace("&","")\
  20. .replace("lt","")\
  21. .replace("/div","")\
  22. .replace("!-- SC_ON --","")\
  23. .replace("!-- SC ON --","")\
  24. .replace("!-- SC_OFF --","")\
  25. .replace("!-- SC OFF --","")\
  26. .replace("gt","")\
  27. .replace("div class=\"md\"","")\
  28. .replace("/p","")\
  29. .replace("\n","")\
  30. .replace("amp#39","")
  31. text = text.encode("ascii","ignore").decode()
  32. print(text)
  33. #os.system(texttospeech.replace("TEXT",text).replace("FILE",str(i)+".wav"))
  34. os.system(texttospeech.replace("TEXT",text).replace("FILE","audio.wav"))
  35. text = text.replace(".","").split(" ")
  36. for i, word in enumerate(text):
  37. print(i)
  38. imagedata = requests.get(f"https://search.davidovski.xyz/api.php?q={word}&p=1&type=1").json()[0]["base64"]
  39. os.system(f'ffmpeg -i "data:image/gif;base64,{imagedata}=" {str(i)}.png')
  40. # decodedata = base64.b64decode(imagedata)
  41. # try:
  42. # with open(str(i)+".jpeg","wb") as f:
  43. # f.write(decodedata)
  44. # except:
  45. # print("idk didn't work here")
  46. os.system(f'ffmpeg -y -framerate 1/0.3 -i %d.jpeg -r 25 -vf "scale=1920:1080:force_original_aspect_ratio=decrease,pad=1920:1080:-1:-1:color=black" -pix_fmt yuv422p input.mp4')
  47. os.system(f'ffmpeg -y -i input.mp4 -i audio.wav output.mp4')
  48. for file in os.listdir():
  49. if file.endswith(".jpeg"):
  50. os.remove(file)
  51. os.remove("input.mp4")