slidegen.py 2.6 KB

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