pokevolution.py 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. #!/usr/bin/env python
  2. import os
  3. import requests
  4. # Evolution image and a background image. For both it needs to be
  5. # either an HTTPS URL or a file on your computer. Also needs to be a
  6. # PNG file.
  7. # This is an image to represent the pokemon evolving.
  8. evolveimage = "https://spee.ch/@TrueAuraCoralPublishesImages:5/PokeevolutionEvolveSign:8"
  9. # This is an image the pokemon will be overlayed on
  10. backgroundimage = "https://spee.ch/@TrueAuraCoralPublishesImages:5/PokeevolutionBackgroundSign:a"
  11. # Audio file to go over the video to make it less boring. Need to have
  12. # one on your computer
  13. audio = "C:\\SGZ_Pro\\Hobbys\\Media\\music\\pokemon-songs-no-copyright-music.mp3"
  14. # Various pokemon you want to have a evolution video out of. These are
  15. # all the starters in pokemon. This placeholder going to get oudated
  16. # because scarlet and violet
  17. pokemons = ["bulbasaur","charmander","squirtle","chikorita","cyndaquil","totodile","treecko","torchic","mudkip","turtwig","chimchar","piplup","snivy","tepig","oshawott","chespin","fennekin","froakie","rowlet","litten","popplio","grookey","scorbunny","sobble"]
  18. if evolveimage.startswith("https://"):
  19. with open("evolveimage.png","wb") as f:
  20. f.write(requests.get(evolveimage).content)
  21. evolveimage = "evolveimage.png"
  22. if backgroundimage.startswith("https://"):
  23. with open("backgroundimage.png","wb") as f:
  24. f.write(requests.get(backgroundimage).content)
  25. backgroundimage = "backgroundimage.png"
  26. os.system(f"ffmpeg -y -loop 1 -i {evolveimage} -c:v libx264 -t 5 -pix_fmt yuv420p -vf scale=1920:1080 evolveimage.mp4")
  27. def artinator(a):
  28. data2 = requests.get(f"https://pokeapi.co/api/v2/pokemon/{a}").json()
  29. artwork = data2["sprites"]["other"]["official-artwork"]["front_default"]
  30. with open(a+".png","wb") as f:
  31. f.write(requests.get(artwork).content)
  32. def makeevolutionvideo(pokemon):
  33. data = requests.get(f"https://pokeapi.co/api/v2/pokemon-species/{pokemon}").json()
  34. data = requests.get(data["evolution_chain"]["url"]).json()
  35. artinator(pokemon)
  36. if data["chain"]["evolves_to"] == []:
  37. text = f"{pokemon.capitalize()} does not evolve"
  38. second = ""
  39. third = ""
  40. else:
  41. second = data["chain"]["evolves_to"][0]["species"]["name"]
  42. print(second)
  43. artinator(second)
  44. text = f"{pokemon.capitalize()} evolves into {second.capitalize()}"
  45. try:
  46. third = data["chain"]["evolves_to"][0]["evolves_to"][0]["species"]["name"]
  47. artinator(third)
  48. text3 = f"{second.capitalize()} evolves into {third.capitalize()}"
  49. except:
  50. third = ""
  51. os.system(f'ffmpeg -y -i {backgroundimage} -i {pokemon}.png -filter_complex "[1]scale=950:950[b];[0][b] overlay=(main_w-overlay_w)/2:(main_h-overlay_h)/2:shortest=1" edit-{pokemon}.png')
  52. os.system(f"ffmpeg -y -loop 1 -i edit-{pokemon}.png -c:v libx264 -t 5 -pix_fmt yuv420p -vf scale=1920:1080 {pokemon}.mp4")
  53. os.system(f"ffmpeg -y -i evolveimage.mp4 -vf \"drawtext=text='{text}':fontcolor=white:bordercolor=black:borderw=5:fontsize=65:x=(w-text_w)/2:y=(h-text_h)/2:\" evolveimage-{pokemon}.mp4")
  54. with open("concat.txt","w") as f:
  55. f.write(f"""file '{pokemon}.mp4'
  56. file 'evolveimage-{pokemon}.mp4'""")
  57. if second == "":
  58. pass
  59. else:
  60. text2 = f"{second.capitalize()} evolves into {third.capitalize()}"
  61. os.system(f'ffmpeg -y -i {backgroundimage} -i {second}.png -filter_complex "[1]scale=950:950[b];[0][b] overlay=(main_w-overlay_w)/2:(main_h-overlay_h)/2:shortest=1" edit-{second}.png')
  62. os.system(f"ffmpeg -y -loop 1 -i edit-{second}.png -c:v libx264 -t 5 -pix_fmt yuv420p -vf scale=1920:1080 {second}.mp4")
  63. os.system(f"ffmpeg -y -i evolveimage.mp4 -vf \"drawtext=text='{text2}':fontcolor=white:bordercolor=black:borderw=5:fontsize=65:x=(w-text_w)/2:y=(h-text_h)/2:\" evolveimage-{second}.mp4")
  64. with open("concat.txt","a") as f:
  65. f.write(f"""
  66. file '{second}.mp4'
  67. file 'evolveimage-{second}.mp4'""")
  68. if third == "":
  69. pass
  70. else:
  71. os.system(f'ffmpeg -y -i {backgroundimage} -i {third}.png -filter_complex "[1]scale=950:950[b];[0][b] overlay=(main_w-overlay_w)/2:(main_h-overlay_h)/2:shortest=1" edit-{third}.png')
  72. os.system(f"ffmpeg -y -loop 1 -i edit-{third}.png -c:v libx264 -t 5 -pix_fmt yuv420p -vf scale=1920:1080 {third}.mp4")
  73. with open("concat.txt","a") as f:
  74. f.write(f"""
  75. file '{third}.mp4'""")
  76. os.system(f"ffmpeg -y -f concat -i concat.txt -c copy vid-{pokemon}.mp4")
  77. for file in os.listdir():
  78. if file == "backgroundimage.png":
  79. pass
  80. elif file == "evolveimage.png":
  81. pass
  82. elif file.endswith(".png"):
  83. os.remove(file)
  84. os.remove(pokemon+".mp4")
  85. os.remove("evolveimage-"+pokemon+".mp4")
  86. os.remove(second+".mp4")
  87. os.remove("evolveimage-"+second+".mp4")
  88. os.remove(third+".mp4")
  89. for thing in pokemons:
  90. makeevolutionvideo(thing)
  91. print(f"Made video for {thing.capitalize()}.")
  92. with open("concat2.txt","a") as f:
  93. f.write(f"\nfile 'vid-{thing}.mp4'")
  94. os.system(f"ffmpeg -y -f concat -i concat2.txt -c copy input.mp4")
  95. os.remove("backgroundimage.png")
  96. os.remove("evolveimage.png")
  97. os.remove("evolveimage.mp4")
  98. for thing in pokemons:
  99. os.remove("vid-"+thing+".mp4")
  100. os.system(f'ffmpeg -y -i input.mp4 -i "{audio}" -filter_complex \" [1:0] apad \" -shortest output.mp4')
  101. os.remove("input.mp4")
  102. os.remove("concat2.txt")
  103. os.remove("concat.txt")
  104. # Theoretically with this you could create ALL the pokemon evolutions.
  105. # That's just going to take a REALLY REALLY long time to render. As well as
  106. # a lot of possible errors...
  107. #data = requests.get("https://pokeapi.co/api/v2/pokemon?limit=2000").json()
  108. #for pokemon in data["results"]:
  109. # pokemon["name"]: