diff --git a/chronograph/ui/BoxDialog.py b/chronograph/ui/BoxDialog.py index 7e4bb5a..c68300b 100644 --- a/chronograph/ui/BoxDialog.py +++ b/chronograph/ui/BoxDialog.py @@ -13,13 +13,6 @@ class BoxDialog(Adw.Dialog): Label of the dialog lines_content : tuple titles and subtitles of `Adw.ActionRow(s)`. Like `(("1st Title", "1st subtitle"), ("2nd title", "2nd subtitle"), ...)` - - GTK Objects - ---------- - :: - - diaglog_title_label : Gtk.Label -> Label of the dialog - props_list : Gtk.ListBox -> ListBox with `Adw.ActionRow(s)` with provided data """ __gtype_name__ = "BoxDialog" diff --git a/chronograph/ui/SongCard.py b/chronograph/ui/SongCard.py index 77a2a09..b2bc234 100644 --- a/chronograph/ui/SongCard.py +++ b/chronograph/ui/SongCard.py @@ -22,19 +22,6 @@ class SongCard(Gtk.Box): # ---------- file : Union[FileID3, FileVorbis] File of `.ogg`, `.flac`, `.mp3` and `.wav` formats - - GTK Objects - ---------- - :: - - buttons_revealer: Gtk.Revealer -> Revealer for Play and Edit buttons - play_button: Gtk.Button -> Play button - metadata_editor_button: Gtk.Button -> Metadata editor button - info_button: Gtk.Button -> File info button - cover_button: Gtk.Button -> Clickable cover of song - cover: Gtk.Image -> Cover image of song - title_label: Gtk.Label -> Title of song - artist_label: Gtk.Label -> Artist of song """ __gtype_name__ = "SongCard" diff --git a/chronograph/utils/file.pyi b/chronograph/utils/file.pyi index 8a14acb..dc44cfa 100644 --- a/chronograph/utils/file.pyi +++ b/chronograph/utils/file.pyi @@ -25,6 +25,7 @@ class BaseFile: _album: str _cover: Union[bytes, str] _mutagen_file: dict + _duration: float _path: str diff --git a/chronograph/utils/publish.py b/chronograph/utils/publish.py index ab72d7a..5d2c659 100644 --- a/chronograph/utils/publish.py +++ b/chronograph/utils/publish.py @@ -9,7 +9,14 @@ from chronograph.utils.parsers import sync_lines_parser -def verify_nonce(result, target): +def verify_nonce(result, target) -> bool: + """Checks if current nonce is valid + + Returns + ------- + bool + validity + """ if len(result) != len(target): return False @@ -21,7 +28,15 @@ def verify_nonce(result, target): return True -def solve_challenge(prefix, target_hex): + +def solve_challenge(prefix, target_hex) -> str: + """Generates nonce for publishing + + Returns + ------- + str + generated noce + """ target = unhexlify(target_hex.upper()) nonce = 0 @@ -38,6 +53,13 @@ def solve_challenge(prefix, target_hex): def make_plain_lyrics() -> str: + """Generates plain lyrics form `chronograph.ChronographWindow.sync_lines` + + Returns + ------- + str + plain lyrics + """ pattern = r"\[.*?\] " plain_lyrics = [] for child in shared.win.sync_lines: @@ -46,6 +68,19 @@ def make_plain_lyrics() -> str: def do_publish() -> None: + """Publishes lyrics to LRClib + + Raises + ------ + AttributeError + raised if any needed property is \"Unknown\" + + needed properties: :: + + title: str + artist: str + album: str + """ if ( shared.win.loaded_card.title or shared.win.loaded_card.artist @@ -57,9 +92,7 @@ def do_publish() -> None: shared.win.export_lyrics_button.set_icon_name("export-to-symbolic") raise AttributeError('Some of Title, Artist and/or Album fields are "Unknown"') - challenge_data = requests.post( - url="https://lrclib.net/api/request-challenge" - ) + challenge_data = requests.post(url="https://lrclib.net/api/request-challenge") challenge_data = challenge_data.json() nonce = solve_challenge( prefix=challenge_data["prefix"], target_hex=challenge_data["target"] @@ -81,8 +114,7 @@ def do_publish() -> None: "syncedLyrics": sync_lines_parser(), }, ) - - print(response.status_code) + if response.status_code == 201: shared.win.toast_overlay.add_toast( Adw.Toast(title=_("Published successfully: ") + str(response.status_code)) diff --git a/chronograph/utils/publish.pyi b/chronograph/utils/publish.pyi new file mode 100644 index 0000000..e6931ca --- /dev/null +++ b/chronograph/utils/publish.pyi @@ -0,0 +1,4 @@ +def verify_nonce(result, target) -> bool: ... +def solve_challenge(prefix, target_hex) -> str: ... +def make_plain_lyrics() -> str: ... +def do_publish() -> None: ... diff --git a/chronograph/window.py b/chronograph/window.py index 661bd8b..1868d82 100644 --- a/chronograph/window.py +++ b/chronograph/window.py @@ -432,6 +432,7 @@ def on_export_to_clipboard_action(self, *_args) -> None: export_clipboard(sync_lines_parser()) def on_export_to_lrclib_action(self, *_args) -> None: + """Publishes synced lyrics to LRClib""" thread = threading.Thread(target=do_publish) thread.daemon = True thread.start() diff --git a/chronograph/window.pyi b/chronograph/window.pyi index 1851137..1731bc5 100644 --- a/chronograph/window.pyi +++ b/chronograph/window.pyi @@ -7,12 +7,17 @@ class ChronographWindow(Adw.ApplicationWindow): # Status pages no_source_opened: Adw.StatusPage + search_lrclib_status_page: Adw.StatusPage + search_lrclib_collapsed_status_page: Adw.StatusPage + lrclib_window_nothing_found_status: Adw.StatusPage + lrclib_window_collapsed_nothing_found_status: Adw.StatusPage # Library view widgets toast_overlay: Adw.ToastOverlay navigation_view: Adw.NavigationView library_nav_page: Adw.NavigationPage overlay_split_view: Adw.OverlaySplitView + open_source_button: Gtk.MenuButton right_buttons_revealer: Gtk.Revealer left_buttons_revealer: Gtk.Revealer search_bar: Gtk.SearchBar @@ -82,3 +87,4 @@ class ChronographWindow(Adw.ApplicationWindow): def on_import_lyrics_lrclib_plain_action(self, *_args) -> None: ... def on_export_to_file_action(self, *_args) -> None: ... def on_export_to_clipboard_action(self, *_args) -> None: ... + def on_export_to_lrclib_action(self, *_args) -> None: ...