-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added tests for lyrics screens, further refactoring, deleting dupe code
- Loading branch information
Showing
17 changed files
with
1,313 additions
and
690 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
from lyrics_transcriber.output.ass.lyrics_screen import LyricsScreen | ||
from lyrics_transcriber.output.ass.lyrics_line import LyricsLine | ||
from lyrics_transcriber.output.ass.section_screen import SectionScreen | ||
from lyrics_transcriber.output.ass.style import Style | ||
from lyrics_transcriber.output.ass.event import Event | ||
from lyrics_transcriber.output.ass.config import ( | ||
ScreenConfig, | ||
LineTimingInfo, | ||
LineState, | ||
) | ||
|
||
__all__ = [ | ||
'LyricsScreen', | ||
'LyricsLine', | ||
'SectionScreen', | ||
'Style', | ||
'Event', | ||
'ScreenConfig', | ||
'LineTimingInfo', | ||
'LineState', | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
from dataclasses import dataclass | ||
|
||
|
||
@dataclass | ||
class ScreenConfig: | ||
"""Configuration for screen timing and layout.""" | ||
|
||
# Screen layout | ||
max_visible_lines: int = 4 | ||
line_height: int = 50 | ||
top_padding: int = 50 # One line height of padding | ||
video_height: int = 720 # 720p default | ||
|
||
# Timing configuration | ||
screen_gap_threshold: float = 5.0 | ||
post_roll_time: float = 1.0 | ||
fade_in_ms: int = 100 | ||
fade_out_ms: int = 400 | ||
cascade_delay_ms: int = 200 | ||
target_preshow_time: float = 5.0 | ||
position_clear_buffer_ms: int = 300 | ||
|
||
|
||
@dataclass | ||
class LineTimingInfo: | ||
"""Timing information for a single line.""" | ||
|
||
fade_in_time: float | ||
end_time: float | ||
fade_out_time: float | ||
clear_time: float | ||
|
||
|
||
@dataclass | ||
class LineState: | ||
"""Complete state for a single line.""" | ||
|
||
text: str | ||
timing: LineTimingInfo | ||
y_position: int |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
from dataclasses import dataclass | ||
from typing import Optional | ||
import logging | ||
from datetime import timedelta | ||
|
||
from lyrics_transcriber.types import LyricsSegment | ||
|
||
|
||
@dataclass | ||
class LyricsLine: | ||
"""Represents a single line of lyrics with timing and karaoke information.""" | ||
|
||
segment: LyricsSegment | ||
logger: Optional[logging.Logger] = None | ||
|
||
def __post_init__(self): | ||
"""Ensure logger is initialized""" | ||
if self.logger is None: | ||
self.logger = logging.getLogger(__name__) | ||
|
||
def _create_ass_text(self, start_ts: timedelta) -> str: | ||
"""Create the ASS text with karaoke timing tags.""" | ||
# Initial delay before first word | ||
first_word_time = self.segment.start_time | ||
start_time = max(0, (first_word_time - start_ts.total_seconds()) * 100) | ||
text = r"{\k" + str(int(round(start_time))) + r"}" | ||
|
||
prev_end_time = first_word_time | ||
|
||
for word in self.segment.words: | ||
# Add gap between words if needed | ||
gap = word.start_time - prev_end_time | ||
if gap > 0.1: # Only add gap if significant | ||
text += r"{\k" + str(int(round(gap * 100))) + r"}" | ||
|
||
# Add the word with its duration | ||
duration = int(round((word.end_time - word.start_time) * 100)) | ||
text += r"{\kf" + str(duration) + r"}" + word.text + " " | ||
|
||
prev_end_time = word.end_time # Track the actual end time of the word | ||
|
||
return text.rstrip() | ||
|
||
def __str__(self): | ||
return f"{{{self.segment.text}}}" |
This file was deleted.
Oops, something went wrong.
94 changes: 0 additions & 94 deletions
94
lyrics_transcriber/output/ass/lyrics_models/lyrics_line.py
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.