-
Notifications
You must be signed in to change notification settings - Fork 215
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added Lyrics w. Timestamps #662
Conversation
Added `get_lyrics_with_timestamps` to get lyrics with timestamps. The Method doesn't try to parse the response as normal lyrics, if no lyrics with timestamps are returned. (could be changed to do so tho, the format is the same)
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #662 +/- ##
==========================================
+ Coverage 94.88% 95.01% +0.12%
==========================================
Files 38 40 +2
Lines 2289 2348 +59
==========================================
+ Hits 2172 2231 +59
Misses 117 117
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @heinrich26 , pretty cool that you were able to make this work!
I take it you're basically emulating the mobile client to fetch the timed data? Since you're modifying the client info.
Could we replace the previous get_lyrics
with this? I wouldn't want to have two methods for the same purpose in the API if one provides a superset of information.
Finally, to get this merged:
- please ensure the linters pass
- please add a test for the function
Yea, calling the API "as a different frontend" gives you different results. I temporarily changed the client because I thought unforeseen side-effects aren't desirable.As per the implementation of a multipurpose `get_lyrics()`, I would add an argument like `timestamps=True/False`, to keep it backwards compatible and allow the user to always get the same (old) format – with my approach, you'll end up with 2 possible formats.Furthermore, would you keep the original format with the nested `CueRange` or would you rather have a flat dict? I think that nesting is kinda useless.
|
…ads, because vscode didn't show them otherwise
Pushed to the wrong branch :(
because idk where it came from...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, looks much better! :)
As a general rule of thumb: Don't change more than necessary in a single PR. It makes it harder for the maintainer to review the changes (more time consuming), and harder to trace back potential future issues to specific PRs. It will also prolong the time it takes for the PR to get merged.
Note for this review: Please don't resolve threads, I will do so myself after verifying the changes
ytmusicapi/mixins/search.py
Outdated
@@ -204,7 +206,7 @@ def search( | |||
if filter and "playlists" in filter: | |||
filter = "playlists" | |||
elif scope == scopes[1]: | |||
filter = scopes[1] | |||
filter = scopes[1] # type:ignore |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please undo all changes to this file
@@ -181,7 +181,7 @@ def __init__( | |||
try: | |||
cookie = self.base_headers.get("cookie") | |||
self.sapisid = sapisid_from_cookie(cookie) | |||
self.origin = self.base_headers.get("origin", self.base_headers.get("x-origin")) | |||
self.origin = cast(str, self.base_headers.get("origin", self.base_headers.get("x-origin"))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please undo changes to this file
ytmusicapi/__init__.py
Outdated
@@ -2,14 +2,16 @@ | |||
|
|||
from ytmusicapi.setup import setup, setup_oauth | |||
from ytmusicapi.ytmusic import YTMusic | |||
from .mixins.browsing import Lyrics, TimedLyrics, LyricLine |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please undo the changes to this file. They are not needed and I don't want to start exporting everything from root
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking similar, but then you'll need to create a submodule for these classes to be accessible
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can already access them: from ytmusicapi.mixins.browsing import TimedLyrics
It's similar for https://github.com/sigma67/ytmusicapi/blob/main/ytmusicapi/parsers/podcasts.py
Although with #621 in mind, it might be wise to move them to a ytmusicapi.models
module (one for podcasts
and one for lyrics
, I guess)
ytmusicapi/mixins/_utils.py
Outdated
|
||
from ytmusicapi.exceptions import YTMusicUserError | ||
|
||
|
||
OrderType = Literal['a_to_z', 'z_to_a', 'recently_added'] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a good change in general, but the name is too broad. Since you introduced an ArtistOrderType
elsewhere, this should have a more specific name as well. Maybe LibraryOrderType
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes
reverted some changes that I moved to an extra PR
…y `yt.as_mobile()`
finally used pre-commit to fix those formatting complaints 🤷♂️ |
Hi @heinrich26 , I am moving this over to #693 as merging is somehow blocked here |
* Added Lyrics w. Timestamps Added `get_lyrics_with_timestamps` to get lyrics with timestamps. The Method doesn't try to parse the response as normal lyrics, if no lyrics with timestamps are returned. (could be changed to do so tho, the format is the same) * Update browsing.py * Combined both get_lyrics methods into one and fixed some typechecking errors * Fixed a missing hasTimestamps and added the doccomments to the overloads, because vscode didn't show them otherwise * Removed the old get_lyrics_with_timestamps method because idk where it came from... * fixed remaining issues * Update uploads.py reverted some changes that I moved to an extra PR * removed variable `context` from the Mixin, as it's use was replaced by `yt.as_mobile()` * fix some formatting complaints by ruff and mypy * please the linter * fix union syntax * improve typing in ytmusic.py * improve typing * replace docsbuild.yml with RTD --------- Co-authored-by: Hendrik Horstmann <65970327+heinrich26@users.noreply.github.com> Co-authored-by: henrich26 <hendrik-horstmann@o2mail.de>
Added
get_lyrics_with_timestamps
to get lyrics with timestamps. The Method doesn't try to parse the response as normal lyrics, if no lyrics with timestamps are returned. (could be changed to do so tho, the format is the same)