Skip to content

Commit

Permalink
feat: added importing lyrics from LRClib to editor
Browse files Browse the repository at this point in the history
  • Loading branch information
Dzheremi2 committed Dec 28, 2024
1 parent e77e9f8 commit fce9e4f
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 3 deletions.
4 changes: 3 additions & 1 deletion chronograph/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ def do_activate(self) -> None: # pylint: disable=arguments-differ
("import_from_clipboard", (), shared.win),
("import_from_file", (), shared.win),
("import_from_lrclib", (), shared.win),
("search_lrclib", (), shared.win)
("search_lrclib", (), shared.win),
("import_lyrics_lrclib_synced", (), shared.win),
("import_lyrics_lrclib_plain", (), shared.win)
}
)

Expand Down
1 change: 1 addition & 0 deletions chronograph/ui/LrclibTrack.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,4 @@ class LrclibTrack(Gtk.Box):
plain: str

def generate_tooltip(self, tuple: tuple) -> str: ...
def set_lyrics(self, *_args) -> None: ...
17 changes: 16 additions & 1 deletion chronograph/utils/parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from pathlib import Path
from typing import Union

from gi.repository import Gdk, Gio, GLib, Adw # type: ignore
from gi.repository import Adw, Gdk, Gio, GLib # type: ignore

from chronograph import shared
from chronograph.ui.SongCard import SongCard
Expand Down Expand Up @@ -141,3 +141,18 @@ def file_parser(file: str) -> None:
for i in range(len(list)):
shared.win.sync_lines.append(SyncLine())
shared.win.sync_lines.get_row_at_index(i).set_text(list[i])


def string_parser(string: str) -> None:
"""Sets `chronograph.ChronographWindow.sync_lines` with lyrics from provided string
Parameters
----------
string : str
string to parse lyrics from
"""
list = string.splitlines()
shared.win.sync_lines.remove_all()
for i in range(len(list)):
shared.win.sync_lines.append(SyncLine())
shared.win.sync_lines.get_row_at_index(i).set_text(list[i])
1 change: 1 addition & 0 deletions chronograph/utils/parsers.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ def timing_parser(string: str) -> int: ...
def clipboard_parser(*_args) -> None: ...
def on_clipboard_parsed(_clipboard, result: Gio.Task, clipboard: Gdk.Clipboard) -> None: ...
def file_parser(file: str) -> None: ...
def string_parser(string: str) -> None: ...
24 changes: 23 additions & 1 deletion chronograph/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
title_str,
)
from chronograph.ui.SyncLine import SyncLine
from chronograph.utils.parsers import clipboard_parser, timing_parser
from chronograph.utils.parsers import clipboard_parser, string_parser, timing_parser
from chronograph.utils.select_data import select_dir, select_lyrics_file


Expand Down Expand Up @@ -389,3 +389,25 @@ def set_lyrics(self, _listbox: Gtk.ListBox, row: Gtk.ListBoxRow) -> None:
`Gtk.ListBoxRow` to claim `LrclibTrack` from
"""
row.get_child().set_lyrics()

def on_import_lyrics_lrclib_synced_action(self, *_args) -> None:
"""Import synced lyrics from LRCLib to `self.sync_lines`"""
string_parser(
self.lrclib_window_synced_lyrics_text_view.get_buffer().get_text(
start=self.lrclib_window_synced_lyrics_text_view.get_buffer().get_start_iter(),
end=self.lrclib_window_synced_lyrics_text_view.get_buffer().get_end_iter(),
include_hidden_chars=False,
)
)
self.lrclib_window.close()

def on_import_lyrics_lrclib_plain_action(self, *_args) -> None:
"""Import plain lyrics from LRCLib to `self.sync_lines`"""
string_parser(
self.lrclib_window_plain_lyrics_text_view.get_buffer().get_text(
start=self.lrclib_window_plain_lyrics_text_view.get_buffer().get_start_iter(),
end=self.lrclib_window_plain_lyrics_text_view.get_buffer().get_end_iter(),
include_hidden_chars=False,
)
)
self.lrclib_window.close()
4 changes: 4 additions & 0 deletions chronograph/window.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,7 @@ class ChronographWindow(Adw.ApplicationWindow):
def on_import_from_clipboard_action(self, *_args) -> None: ...
def on_import_from_file_action(self, *_args) -> None: ...
def on_import_from_lrclib_action(self, *_args) -> None: ...
def on_search_lrclib_action(self, *_args) -> None: ...
def set_lyrics(self, _listbox: Gtk.ListBox, row: Gtk.ListBoxRow) -> None: ...
def on_import_lyrics_lrclib_synced_action(self, *_args) -> None: ...
def on_import_lyrics_lrclib_plain_action(self, *_args) -> None: ...
2 changes: 2 additions & 0 deletions data/gtk/window.blp
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ Adw.Dialog lrclib_window {
Adw.SplitButton {
tooltip-text: _("Synced lyrics are used by default, to use plain, select 'Use plain' from submenu");
menu-model: use_lyrics_menu;
action-name: "win.import_lyrics_lrclib_synced";

Adw.ButtonContent {
icon-name: 'import-from-symbolic';
Expand Down Expand Up @@ -358,6 +359,7 @@ Adw.NavigationView lrclib_window_collapsed_navigation_view {
Adw.SplitButton {
tooltip-text: _("Synced lyrics are used by default, to use plain, select 'Use plain' from submenu");
menu-model: use_lyrics_menu;
action-name: "win.import_lyrics_lrclib_synced";

Adw.ButtonContent {
icon-name: 'import-from-symbolic';
Expand Down

0 comments on commit fce9e4f

Please sign in to comment.