karaoke-lyrics-processor 0.3.0__py3-none-any.whl → 0.3.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -5,6 +5,7 @@ import unicodedata
5
5
  import docx2txt
6
6
  from striprtf.striprtf import rtf_to_text
7
7
  import os
8
+ import codecs
8
9
 
9
10
 
10
11
  class KaraokeLyricsProcessor:
@@ -46,6 +47,8 @@ class KaraokeLyricsProcessor:
46
47
  def read_input_file(self):
47
48
  file_extension = os.path.splitext(self.input_filename)[1].lower()
48
49
 
50
+ self.logger.debug(f"Reading input file: {self.input_filename}")
51
+
49
52
  if file_extension == ".txt":
50
53
  return self.read_txt_file()
51
54
  elif file_extension in [".docx", ".doc"]:
@@ -56,8 +59,14 @@ class KaraokeLyricsProcessor:
56
59
  raise ValueError(f"Unsupported file format: {file_extension}")
57
60
 
58
61
  def read_txt_file(self):
59
- with open(self.input_filename, "r", encoding="utf-8") as infile:
60
- return self.clean_text(infile.read()).splitlines()
62
+ with codecs.open(self.input_filename, "r", encoding="utf-8") as infile:
63
+ content = infile.read()
64
+ self.logger.debug(f"Raw content read from file: {repr(content)}")
65
+ lines = content.splitlines()
66
+ self.logger.debug(f"Number of lines read: {len(lines)}")
67
+ for i, line in enumerate(lines):
68
+ self.logger.debug(f"Line {i}: {repr(line)}")
69
+ return self.clean_text(content).splitlines()
61
70
 
62
71
  def read_doc_file(self):
63
72
  text = docx2txt.process(self.input_filename)
@@ -70,13 +79,17 @@ class KaraokeLyricsProcessor:
70
79
  return self.clean_text(plain_text).splitlines()
71
80
 
72
81
  def clean_text(self, text):
73
- # Remove any non-printable characters except newlines
74
- text = "".join(char for char in text if char.isprintable() or char == "\n")
82
+ self.logger.debug(f"Cleaning text: {repr(text)}")
83
+ # Remove any non-printable characters except newlines and U+2005 (four-per-em space)
84
+ cleaned = "".join(char for char in text if char.isprintable() or char in ["\n", "\u2005"])
85
+ self.logger.debug(f"Text after removing non-printable characters: {repr(cleaned)}")
75
86
  # Replace multiple newlines with a single newline
76
- text = re.sub(r"\n{2,}", "\n", text)
87
+ cleaned = re.sub(r"\n{2,}", "\n", cleaned)
88
+ self.logger.debug(f"Text after replacing multiple newlines: {repr(cleaned)}")
77
89
  # Remove leading/trailing whitespace from each line
78
- text = "\n".join(line.strip() for line in text.splitlines())
79
- return text
90
+ cleaned = "\n".join(line.strip() for line in cleaned.splitlines())
91
+ self.logger.debug(f"Final cleaned text: {repr(cleaned)}")
92
+ return cleaned
80
93
 
81
94
  def find_best_split_point(self, line):
82
95
  """
@@ -135,15 +148,28 @@ class KaraokeLyricsProcessor:
135
148
  Replace non-printable space-like characters, tabs, and other whitespace with regular spaces,
136
149
  excluding newline characters.
137
150
  """
138
- self.logger.debug(f"Replacing non-printable spaces in: {text}")
151
+ self.logger.debug(f"Replacing non-printable spaces in: {repr(text)}")
152
+
153
+ # Log each character and its Unicode code point
154
+ # for i, char in enumerate(text):
155
+ # self.logger.debug(f"Character at position {i}: {repr(char)} (Unicode: U+{ord(char):04X})")
156
+
139
157
  # Define a pattern for space-like characters, including tabs and other whitespace, but excluding newlines
140
158
  space_pattern = r"[^\S\n\r]|\u00A0|\u1680|\u2000-\u200A|\u202F|\u205F|\u3000"
159
+
141
160
  # Replace matched characters with a regular space
142
161
  cleaned_text = re.sub(space_pattern, " ", text)
162
+
163
+ # Log the result of the replacement
164
+ self.logger.debug(f"Text after replacing non-printable spaces: {repr(cleaned_text)}")
165
+
143
166
  # Remove leading/trailing spaces and collapse multiple spaces into one, preserving newlines
144
- cleaned_text = re.sub(r" +", " ", cleaned_text).strip()
145
- self.logger.debug(f"Text after replacing non-printable spaces: {cleaned_text}")
146
- return cleaned_text
167
+ final_text = re.sub(r" +", " ", cleaned_text).strip()
168
+
169
+ # Log the final result
170
+ self.logger.debug(f"Final text after cleaning: {repr(final_text)}")
171
+
172
+ return final_text
147
173
 
148
174
  def clean_punctuation_spacing(self, text):
149
175
  """
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: karaoke-lyrics-processor
3
- Version: 0.3.0
3
+ Version: 0.3.1
4
4
  Summary: Process song lyrics to prepare them for karaoke video production, e.g. by splitting long lines
5
5
  Home-page: https://github.com/karaokenerds/karaoke-lyrics-processor
6
6
  License: MIT
@@ -0,0 +1,8 @@
1
+ karaoke_lyrics_processor/__init__.py,sha256=rLRkJQi61qkRiNXdlTleE3ahJ1oBKcghYVkz64x7IIg,62
2
+ karaoke_lyrics_processor/cli.py,sha256=bdtseRI2jcChb1bMr92pc5mpSWpHXh4TSzA2tknbyjU,2522
3
+ karaoke_lyrics_processor/karaoke_lyrics_processor.py,sha256=qMITsW0SbYCaacvEi9WzuZNeBMJhl2wlMck4WktzTEY,11513
4
+ karaoke_lyrics_processor-0.3.1.dist-info/LICENSE,sha256=BiPihPDxhxIPEx6yAxVfAljD5Bhm_XG2teCbPEj_m0Y,1069
5
+ karaoke_lyrics_processor-0.3.1.dist-info/METADATA,sha256=rCLkfq2I2QkdQlEGI0kiecLb_v5HdcBzuKT0VaNdjJw,4264
6
+ karaoke_lyrics_processor-0.3.1.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
7
+ karaoke_lyrics_processor-0.3.1.dist-info/entry_points.txt,sha256=hjFp6CUxl1p-1WJYfB6TbNcI_DHEnVzX3BXAs4y_0O8,78
8
+ karaoke_lyrics_processor-0.3.1.dist-info/RECORD,,
@@ -1,8 +0,0 @@
1
- karaoke_lyrics_processor/__init__.py,sha256=rLRkJQi61qkRiNXdlTleE3ahJ1oBKcghYVkz64x7IIg,62
2
- karaoke_lyrics_processor/cli.py,sha256=bdtseRI2jcChb1bMr92pc5mpSWpHXh4TSzA2tknbyjU,2522
3
- karaoke_lyrics_processor/karaoke_lyrics_processor.py,sha256=LmsciDtBS1-apCbvya2RBmYCSH4S-svrIDpOb8Ut0Gw,10387
4
- karaoke_lyrics_processor-0.3.0.dist-info/LICENSE,sha256=BiPihPDxhxIPEx6yAxVfAljD5Bhm_XG2teCbPEj_m0Y,1069
5
- karaoke_lyrics_processor-0.3.0.dist-info/METADATA,sha256=JuGcHlIyUvoesSQbFxN1iu-JP-B4mmGQIIrgIVv72pE,4264
6
- karaoke_lyrics_processor-0.3.0.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
7
- karaoke_lyrics_processor-0.3.0.dist-info/entry_points.txt,sha256=hjFp6CUxl1p-1WJYfB6TbNcI_DHEnVzX3BXAs4y_0O8,78
8
- karaoke_lyrics_processor-0.3.0.dist-info/RECORD,,