slide_selection_iterator.py 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. """
  2. Copyright © 2022 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. """
  14. import os
  15. from utils import log, create_min_obs_subdirs
  16. from slides import ClassicSongTemplate, ClassicStartSlide, ClassicSongSlide
  17. import config as const
  18. import slidegen
  19. def slide_selection_iterator():
  20. iterator_prompt = "Exit now? [y/N]: "
  21. structure_prompt = (
  22. "Choose song structure (leave blank for full song)"
  23. + " eg. [1,R,2,R] / [1-4]: "
  24. )
  25. file_list_str = ""
  26. for file in os.listdir(const.RCLONE_LOCAL_DIR):
  27. file_list_str += file + "\n"
  28. file_list_str = file_list_str[:-1]
  29. tempfile_str = ".chosen-tempfile"
  30. index = 0
  31. while True:
  32. index += 1
  33. input_song_prompt = "[{} {}] ".format(const.OBS_TARGET_SUBDIR, index)
  34. prompt_answer = str(input(input_song_prompt + iterator_prompt))
  35. if prompt_answer.lower() == "y":
  36. create_min_obs_subdirs(index)
  37. break
  38. file_list_str = file_list_str.replace("\n", "\\n")
  39. os.system('printf "{}" | fzf > {}'.format(file_list_str, tempfile_str))
  40. with open(
  41. tempfile_str, encoding="utf-8", mode="r"
  42. ) as tempfile_file_opener:
  43. chosen_song_file = tempfile_file_opener.read()[:-1].strip()
  44. if len(chosen_song_file) == 0:
  45. log("no slides chosen, skipping...")
  46. else:
  47. structure_prompt_answer = input(
  48. input_song_prompt + structure_prompt
  49. )
  50. log(
  51. "generating slides '{}' to '{} {}'...".format(
  52. chosen_song_file, const.OBS_TARGET_SUBDIR, index
  53. )
  54. )
  55. src_dir = os.path.join(const.RCLONE_LOCAL_DIR, chosen_song_file)
  56. dest_dir = os.path.join(
  57. const.OBS_SLIDES_DIR,
  58. const.OBS_TARGET_SUBDIR + " " + str(index),
  59. )
  60. os.mkdir(dest_dir)
  61. slidegen_instance = slidegen.Slidegen(
  62. ClassicSongTemplate,
  63. ClassicStartSlide,
  64. ClassicSongSlide,
  65. src_dir,
  66. dest_dir,
  67. structure_prompt_answer,
  68. )
  69. slidegen_instance.execute()
  70. if os.path.isfile(tempfile_str):
  71. os.remove(tempfile_str)