diff --git a/chronograph/main.py b/chronograph/main.py index f834125..b0a4bc5 100644 --- a/chronograph/main.py +++ b/chronograph/main.py @@ -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) } ) diff --git a/chronograph/ui/LrclibTrack.pyi b/chronograph/ui/LrclibTrack.pyi index 45ec1c1..6def22d 100644 --- a/chronograph/ui/LrclibTrack.pyi +++ b/chronograph/ui/LrclibTrack.pyi @@ -27,3 +27,4 @@ class LrclibTrack(Gtk.Box): plain: str def generate_tooltip(self, tuple: tuple) -> str: ... + def set_lyrics(self, *_args) -> None: ... diff --git a/chronograph/utils/parsers.py b/chronograph/utils/parsers.py index ea29092..138003c 100644 --- a/chronograph/utils/parsers.py +++ b/chronograph/utils/parsers.py @@ -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 @@ -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]) diff --git a/chronograph/utils/parsers.pyi b/chronograph/utils/parsers.pyi index 83e5a69..28724f9 100644 --- a/chronograph/utils/parsers.pyi +++ b/chronograph/utils/parsers.pyi @@ -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: ... diff --git a/chronograph/window.py b/chronograph/window.py index 6858aee..b4bc013 100644 --- a/chronograph/window.py +++ b/chronograph/window.py @@ -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 @@ -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() diff --git a/chronograph/window.pyi b/chronograph/window.pyi index 9dc0196..2fdbea3 100644 --- a/chronograph/window.pyi +++ b/chronograph/window.pyi @@ -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: ... diff --git a/data/gtk/window.blp b/data/gtk/window.blp index 85d3969..75bd210 100644 --- a/data/gtk/window.blp +++ b/data/gtk/window.blp @@ -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'; @@ -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';