slidegen.py 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. #!/usr/bin/env python3
  2. # Copyright © 2024 Noah Vogt <noah@noahvogt.com>
  3. # This program is free software: you can redistribute it and/or modify
  4. # it under the terms of the GNU General Public License as published by
  5. # the Free Software Foundation, either version 3 of the License, or
  6. # (at your option) any later version.
  7. # This program is distributed in the hope that it will be useful,
  8. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. # GNU General Public License for more details.
  11. # You should have received a copy of the GNU General Public License
  12. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. from threading import Thread
  14. import colorama
  15. from wand.image import Image
  16. from slides import (
  17. ClassicSongTemplate,
  18. ClassicStartSlide,
  19. ClassicSongSlide,
  20. SlideStyle,
  21. generate_slides,
  22. generate_song_template,
  23. count_number_of_slides_to_be_generated,
  24. )
  25. from input import (
  26. parse_prompt_input,
  27. parse_metadata,
  28. parse_songtext,
  29. parse_slidegen_argv_as_tuple,
  30. )
  31. class Slidegen:
  32. def __init__(
  33. self,
  34. slide_style: SlideStyle,
  35. song_file_path: str,
  36. output_dir: str,
  37. chosen_structure: str | list[str],
  38. ) -> None:
  39. self.metadata: dict = {"": ""}
  40. self.songtext: dict = {"": ""}
  41. self.song_file_path: str = song_file_path
  42. self.song_file_content: list = []
  43. self.output_dir: str = output_dir
  44. self.chosen_structure = chosen_structure
  45. self.slide_style: SlideStyle = slide_style
  46. def execute(self, disable_async=False) -> list[Thread]:
  47. self.parse_file()
  48. self.calculate_desired_structures()
  49. return self.generate_slides(disable_async)
  50. def parse_file(self):
  51. parse_metadata(self)
  52. parse_songtext(self)
  53. def calculate_desired_structures(self) -> None:
  54. self.chosen_structure = parse_prompt_input(self)
  55. def generate_slides(self, disable_async: bool) -> list[Thread]:
  56. template_img: Image = generate_song_template(self)
  57. slide_count: int = count_number_of_slides_to_be_generated(self)
  58. zfill_length: int = len(str(slide_count))
  59. return generate_slides(
  60. self, slide_count, template_img, zfill_length, disable_async
  61. )
  62. if __name__ == "__main__":
  63. colorama.init()
  64. classic_slide_style = SlideStyle(
  65. ClassicSongTemplate, # pyright: ignore [reportGeneralTypeIssues]
  66. ClassicStartSlide, # pyright: ignore [reportGeneralTypeIssues]
  67. ClassicSongSlide, # pyright: ignore [reportGeneralTypeIssues]
  68. )
  69. slidegen = Slidegen(classic_slide_style, *parse_slidegen_argv_as_tuple())
  70. slidegen.execute()