|
@@ -17,21 +17,10 @@ You should have received a copy of the GNU General Public License
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
"""
|
|
"""
|
|
|
|
|
|
-import re
|
|
|
|
-import sys
|
|
|
|
-
|
|
|
|
import colorama
|
|
import colorama
|
|
|
|
|
|
from wand.image import Image
|
|
from wand.image import Image
|
|
|
|
|
|
-from utils import (
|
|
|
|
- log,
|
|
|
|
- error_msg,
|
|
|
|
- get_songtext_by_structure,
|
|
|
|
- structure_as_list,
|
|
|
|
- get_unique_structure_elements,
|
|
|
|
-)
|
|
|
|
-
|
|
|
|
from slides import (
|
|
from slides import (
|
|
ClassicSongTemplate,
|
|
ClassicSongTemplate,
|
|
ClassicStartSlide,
|
|
ClassicStartSlide,
|
|
@@ -39,11 +28,10 @@ from slides import (
|
|
generate_start_slide,
|
|
generate_start_slide,
|
|
generate_song_slides,
|
|
generate_song_slides,
|
|
generate_song_template,
|
|
generate_song_template,
|
|
|
|
+ count_number_of_slides_to_be_generated,
|
|
)
|
|
)
|
|
|
|
|
|
-import config as const
|
|
|
|
-
|
|
|
|
-from prompt import parse_input
|
|
|
|
|
|
+from input import parse_prompt_input, parse_metadata, parse_songtext, parse_argv
|
|
|
|
|
|
|
|
|
|
class Slidegen:
|
|
class Slidegen:
|
|
@@ -60,118 +48,29 @@ class Slidegen:
|
|
self.song_template_form = song_template_form
|
|
self.song_template_form = song_template_form
|
|
self.start_slide_form = start_slide_form
|
|
self.start_slide_form = start_slide_form
|
|
self.song_slide_form = song_slide_form
|
|
self.song_slide_form = song_slide_form
|
|
- self.parse_argv()
|
|
|
|
|
|
+ parse_argv(self)
|
|
|
|
|
|
def execute(self) -> None:
|
|
def execute(self) -> None:
|
|
self.parse_file()
|
|
self.parse_file()
|
|
self.calculate_desired_structures()
|
|
self.calculate_desired_structures()
|
|
self.generate_slides()
|
|
self.generate_slides()
|
|
|
|
|
|
- def count_number_of_slides_to_be_generated(self) -> int:
|
|
|
|
- slide_count: int = 0
|
|
|
|
- for structure in self.chosen_structure:
|
|
|
|
- line_count: int = len(self.songtext[structure].splitlines())
|
|
|
|
- if line_count > const.STRUCTURE_ELEMENT_MAX_LINES:
|
|
|
|
- slide_count += (
|
|
|
|
- line_count // const.STRUCTURE_ELEMENT_MAX_LINES + 1
|
|
|
|
- )
|
|
|
|
- else:
|
|
|
|
- slide_count += 1
|
|
|
|
|
|
+ def parse_file(self):
|
|
|
|
+ parse_metadata(self)
|
|
|
|
+ parse_songtext(self)
|
|
|
|
|
|
- return slide_count
|
|
|
|
|
|
+ def calculate_desired_structures(self) -> None:
|
|
|
|
+ self.chosen_structure = parse_prompt_input(self)
|
|
|
|
|
|
def generate_slides(self) -> None:
|
|
def generate_slides(self) -> None:
|
|
template_img: Image = generate_song_template(self)
|
|
template_img: Image = generate_song_template(self)
|
|
|
|
|
|
- slide_count: int = self.count_number_of_slides_to_be_generated()
|
|
|
|
|
|
+ slide_count: int = count_number_of_slides_to_be_generated(self)
|
|
zfill_length: int = len(str(slide_count))
|
|
zfill_length: int = len(str(slide_count))
|
|
|
|
|
|
generate_start_slide(self, template_img, zfill_length)
|
|
generate_start_slide(self, template_img, zfill_length)
|
|
generate_song_slides(self, slide_count, template_img, zfill_length)
|
|
generate_song_slides(self, slide_count, template_img, zfill_length)
|
|
|
|
|
|
- def parse_file(self) -> None:
|
|
|
|
- self.parse_metadata()
|
|
|
|
- self.parse_songtext()
|
|
|
|
-
|
|
|
|
- def parse_metadata(self) -> None:
|
|
|
|
- metadata_dict = dict.fromkeys(const.METADATA_STRINGS)
|
|
|
|
- try:
|
|
|
|
- with open(self.song_file_path, mode="r", encoding="utf8") as opener:
|
|
|
|
- content = opener.readlines()
|
|
|
|
- except IOError:
|
|
|
|
- error_msg(
|
|
|
|
- "could not read the the song input file: '{}'".format(
|
|
|
|
- self.song_file_path
|
|
|
|
- )
|
|
|
|
- )
|
|
|
|
- valid_metadata_strings = list(const.METADATA_STRINGS)
|
|
|
|
-
|
|
|
|
- for line_nr, line in enumerate(content):
|
|
|
|
- if len(valid_metadata_strings) == 0:
|
|
|
|
- content = content[line_nr:]
|
|
|
|
- break
|
|
|
|
- if not re.match(
|
|
|
|
- r"^(?!structure)\S+: .+|^structure: ([0-9]+|R)(,([0-9]+|R))*$",
|
|
|
|
- line,
|
|
|
|
- ):
|
|
|
|
- if line[-1] == "\n":
|
|
|
|
- line = line[:-1]
|
|
|
|
- missing_metadata_strs = ""
|
|
|
|
- for metadata_str in valid_metadata_strings:
|
|
|
|
- missing_metadata_strs += ", " + metadata_str
|
|
|
|
- missing_metadata_strs = missing_metadata_strs[2:]
|
|
|
|
- error_msg(
|
|
|
|
- "invalid metadata syntax on line {}:\n{}\nThe ".format(
|
|
|
|
- line_nr + 1, line
|
|
|
|
- )
|
|
|
|
- + "following metadata strings are still missing: {}".format(
|
|
|
|
- missing_metadata_strs
|
|
|
|
- )
|
|
|
|
- )
|
|
|
|
- metadata_str = line[: line.index(":")]
|
|
|
|
- if metadata_str in valid_metadata_strings:
|
|
|
|
- metadata_dict[metadata_str] = line[line.index(": ") + 2 : -1]
|
|
|
|
- valid_metadata_strings.remove(metadata_str)
|
|
|
|
- continue
|
|
|
|
-
|
|
|
|
- error_msg("invalid metadata string '{}'".format(metadata_str))
|
|
|
|
-
|
|
|
|
- self.metadata = metadata_dict
|
|
|
|
- self.song_file_content = content
|
|
|
|
-
|
|
|
|
- def parse_songtext(self) -> None:
|
|
|
|
- unique_structures = get_unique_structure_elements(
|
|
|
|
- structure_as_list(self.metadata["structure"])
|
|
|
|
- )
|
|
|
|
- output_dict = dict.fromkeys(unique_structures)
|
|
|
|
-
|
|
|
|
- for structure in unique_structures:
|
|
|
|
- output_dict[structure] = get_songtext_by_structure(
|
|
|
|
- self.song_file_content, structure
|
|
|
|
- )
|
|
|
|
-
|
|
|
|
- self.songtext = output_dict
|
|
|
|
-
|
|
|
|
- def calculate_desired_structures(self) -> None:
|
|
|
|
- self.chosen_structure: list | str = parse_input(
|
|
|
|
- str(self.metadata["structure"]), self.chosen_structure
|
|
|
|
- )
|
|
|
|
-
|
|
|
|
- def parse_argv(self) -> None:
|
|
|
|
- try:
|
|
|
|
- self.song_file_path = sys.argv[1]
|
|
|
|
- self.output_dir = sys.argv[2]
|
|
|
|
- except IndexError:
|
|
|
|
- error_msg("incorrect amount of arguments provided, exiting...")
|
|
|
|
- try:
|
|
|
|
- self.chosen_structure = sys.argv[3]
|
|
|
|
- if self.chosen_structure.strip() == "":
|
|
|
|
- self.chosen_structure = ""
|
|
|
|
- except IndexError:
|
|
|
|
- self.chosen_structure = ""
|
|
|
|
-
|
|
|
|
- log("parsing {}...".format(self.song_file_path))
|
|
|
|
-
|
|
|
|
|
|
|
|
def main() -> None:
|
|
def main() -> None:
|
|
colorama.init()
|
|
colorama.init()
|