Skip to content

Commit

Permalink
chore: added and optimized docstrings and stubs
Browse files Browse the repository at this point in the history
  • Loading branch information
Dzheremi2 committed Dec 28, 2024
1 parent bc7bd58 commit 6173d67
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 27 deletions.
7 changes: 0 additions & 7 deletions chronograph/ui/BoxDialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
13 changes: 0 additions & 13 deletions chronograph/ui/SongCard.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions chronograph/utils/file.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class BaseFile:
_album: str
_cover: Union[bytes, str]
_mutagen_file: dict
_duration: float

_path: str

Expand Down
46 changes: 39 additions & 7 deletions chronograph/utils/publish.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand All @@ -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:
Expand All @@ -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
Expand All @@ -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"]
Expand All @@ -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))
Expand Down
4 changes: 4 additions & 0 deletions chronograph/utils/publish.pyi
Original file line number Diff line number Diff line change
@@ -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: ...
1 change: 1 addition & 0 deletions chronograph/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
6 changes: 6 additions & 0 deletions chronograph/window.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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: ...

0 comments on commit 6173d67

Please sign in to comment.