Skip to content

Commit

Permalink
Update musicyt.py
Browse files Browse the repository at this point in the history
  • Loading branch information
CheapNightbot committed Dec 9, 2024
1 parent f13c294 commit 650e521
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions yutify/musicyt.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,22 +97,33 @@ def _get_song(self, result: dict) -> None:
song_url = f"https://music.youtube.com/watch?v={video_id}"
lyrics_id = self.ytmusic.get_watch_playlist(video_id)

song_data = self.ytmusic.get_song(video_id)
release_date = song_data.get("microformat").get("microformatDataRenderer").get("uploadDate")
# Get the index of "T" and slice the string after that or only get string before "T".
# For example, "2016-10-18T11:00:03-07:00" will become "2016-10-18"
release_date: str = release_date[:release_date.index("T")]
try:
song_data = self.ytmusic.get_song(video_id)
release_date = (
song_data.get("microformat")
.get("microformatDataRenderer")
.get("uploadDate")
)
# Get the index of "T" and slice the string after that or only get string before "T".
# For example, "2016-10-18T11:00:03-07:00" will become "2016-10-18"
release_date: str = release_date[: release_date.index("T")]
except exceptions.YTMusicServerError:
song_data = {}

try:
lyrics = self.ytmusic.get_lyrics(lyrics_id.get("lyrics"))
except exceptions.YTMusicUserError:
lyrics = {}

try:
album_art = result["thumbnails"][-1]["url"]
except KeyError:
album_art = song_data["videoDetails"]["thumbnail"]["thumbnails"][-1][
"url"
]
album_art = (
song_data.get("videoDetails")
.get("thumbnail")
.get("thumbnails")[-1]
.get("url")
)
self.music_info.append(
{
"album_art": album_art,
Expand Down

0 comments on commit 650e521

Please sign in to comment.