slidegen.py 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. import colorama
  14. from wand.image import Image
  15. from slides import (
  16. ClassicSongTemplate,
  17. ClassicStartSlide,
  18. ClassicSongSlide,
  19. SlideStyle,
  20. generate_slides,
  21. generate_song_template,
  22. count_number_of_slides_to_be_generated,
  23. )
  24. from input import (
  25. parse_prompt_input,
  26. parse_metadata,
  27. parse_songtext,
  28. parse_slidegen_argv_as_tuple,
  29. )
  30. class Slidegen:
  31. def __init__(
  32. self,
  33. slide_style: SlideStyle,
  34. song_file_path: str,
  35. output_dir: str,
  36. chosen_structure: str | list[str],
  37. ) -> None:
  38. self.metadata: dict = {"": ""}
  39. self.songtext: dict = {"": ""}
  40. self.song_file_path: str = song_file_path
  41. self.song_file_content: list = []
  42. self.output_dir: str = output_dir
  43. self.chosen_structure = chosen_structure
  44. self.slide_style: SlideStyle = slide_style
  45. def execute(self, disable_async=False) -> None:
  46. self.parse_file()
  47. self.calculate_desired_structures()
  48. self.generate_slides(disable_async)
  49. def parse_file(self):
  50. parse_metadata(self)
  51. parse_songtext(self)
  52. def calculate_desired_structures(self) -> None:
  53. self.chosen_structure = parse_prompt_input(self)
  54. def generate_slides(self, disable_async: bool) -> None:
  55. template_img: Image = generate_song_template(self)
  56. slide_count: int = count_number_of_slides_to_be_generated(self)
  57. zfill_length: int = len(str(slide_count))
  58. generate_slides(
  59. self, slide_count, template_img, zfill_length, disable_async
  60. )
  61. if __name__ == "__main__":
  62. colorama.init()
  63. classic_slide_style = SlideStyle(
  64. ClassicSongTemplate, # pyright: ignore [reportGeneralTypeIssues]
  65. ClassicStartSlide, # pyright: ignore [reportGeneralTypeIssues]
  66. ClassicSongSlide, # pyright: ignore [reportGeneralTypeIssues]
  67. )
  68. slidegen = Slidegen(classic_slide_style, *parse_slidegen_argv_as_tuple())
  69. slidegen.execute()