Youtube maintenance (#1022)
authorMarvin Schenkel <marvinschenkel@gmail.com>
Tue, 23 Jan 2024 10:56:52 +0000 (11:56 +0100)
committerGitHub <noreply@github.com>
Tue, 23 Jan 2024 10:56:52 +0000 (11:56 +0100)
music_assistant/server/providers/ytmusic/helpers.py
music_assistant/server/providers/ytmusic/manifest.json
requirements_all.txt

index f4203427f37cb8ce88fa6c61c31970a87fd8f44e..8a0d73189630fdc532831db0d668b2d62f871254 100644 (file)
@@ -7,7 +7,6 @@ This also nicely separates the parsing logic from the Youtube Music provider log
 """
 
 import asyncio
-import json
 from time import time
 
 import ytmusicapi
@@ -28,7 +27,7 @@ async def get_artist(prov_artist_id: str, headers: dict[str, str]) -> dict[str,
     """Async wrapper around the ytmusicapi get_artist function."""
 
     def _get_artist():
-        ytm = ytmusicapi.YTMusic(auth=json.dumps(headers))
+        ytm = ytmusicapi.YTMusic(auth=headers)
         try:
             artist = ytm.get_artist(channelId=prov_artist_id)
             # ChannelId can sometimes be different and original ID is not part of the response
@@ -55,7 +54,7 @@ async def get_playlist(prov_playlist_id: str, headers: dict[str, str]) -> dict[s
     """Async wrapper around the ytmusicapi get_playlist function."""
 
     def _get_playlist():
-        ytm = ytmusicapi.YTMusic(auth=json.dumps(headers))
+        ytm = ytmusicapi.YTMusic(auth=headers)
         playlist = ytm.get_playlist(playlistId=prov_playlist_id, limit=None)
         playlist["checksum"] = get_playlist_checksum(playlist)
         return playlist
@@ -69,7 +68,7 @@ async def get_track(
     """Async wrapper around the ytmusicapi get_playlist function."""
 
     def _get_song():
-        ytm = ytmusicapi.YTMusic(auth=json.dumps(headers))
+        ytm = ytmusicapi.YTMusic(auth=headers)
         track_obj = ytm.get_song(videoId=prov_track_id, signatureTimestamp=signature_timestamp)
         track = {}
         if "videoDetails" not in track_obj:
@@ -98,7 +97,7 @@ async def get_library_artists(headers: dict[str, str]) -> dict[str, str]:
     """Async wrapper around the ytmusicapi get_library_artists function."""
 
     def _get_library_artists():
-        ytm = ytmusicapi.YTMusic(auth=json.dumps(headers))
+        ytm = ytmusicapi.YTMusic(auth=headers)
         artists = ytm.get_library_subscriptions(limit=9999)
         # Sync properties with uniformal artist object
         for artist in artists:
@@ -115,7 +114,7 @@ async def get_library_albums(headers: dict[str, str]) -> dict[str, str]:
     """Async wrapper around the ytmusicapi get_library_albums function."""
 
     def _get_library_albums():
-        ytm = ytmusicapi.YTMusic(auth=json.dumps(headers))
+        ytm = ytmusicapi.YTMusic(auth=headers)
         return ytm.get_library_albums(limit=9999)
 
     return await asyncio.to_thread(_get_library_albums)
@@ -125,7 +124,7 @@ async def get_library_playlists(headers: dict[str, str]) -> dict[str, str]:
     """Async wrapper around the ytmusicapi get_library_playlists function."""
 
     def _get_library_playlists():
-        ytm = ytmusicapi.YTMusic(auth=json.dumps(headers))
+        ytm = ytmusicapi.YTMusic(auth=headers)
         playlists = ytm.get_library_playlists(limit=9999)
         # Sync properties with uniformal playlist object
         for playlist in playlists:
@@ -141,7 +140,7 @@ async def get_library_tracks(headers: dict[str, str]) -> dict[str, str]:
     """Async wrapper around the ytmusicapi get_library_tracks function."""
 
     def _get_library_tracks():
-        ytm = ytmusicapi.YTMusic(auth=json.dumps(headers))
+        ytm = ytmusicapi.YTMusic(auth=headers)
         tracks = ytm.get_library_songs(limit=9999)
         return tracks
 
@@ -154,7 +153,7 @@ async def library_add_remove_artist(
     """Add or remove an artist to the user's library."""
 
     def _library_add_remove_artist():
-        ytm = ytmusicapi.YTMusic(auth=json.dumps(headers))
+        ytm = ytmusicapi.YTMusic(auth=headers)
         if add:
             return "actions" in ytm.subscribe_artists(channelIds=[prov_artist_id])
         if not add:
@@ -171,7 +170,7 @@ async def library_add_remove_album(
     album = await get_album(prov_album_id=prov_item_id)
 
     def _library_add_remove_album():
-        ytm = ytmusicapi.YTMusic(auth=json.dumps(headers))
+        ytm = ytmusicapi.YTMusic(auth=headers)
         playlist_id = album["audioPlaylistId"]
         if add:
             return ytm.rate_playlist(playlist_id, "LIKE")
@@ -188,7 +187,7 @@ async def library_add_remove_playlist(
     """Add or remove an album or playlist to the user's library."""
 
     def _library_add_remove_playlist():
-        ytm = ytmusicapi.YTMusic(auth=json.dumps(headers))
+        ytm = ytmusicapi.YTMusic(auth=headers)
         if add:
             return "actions" in ytm.rate_playlist(prov_item_id, "LIKE")
         if not add:
@@ -204,7 +203,7 @@ async def add_remove_playlist_tracks(
     """Async wrapper around adding/removing tracks to a playlist."""
 
     def _add_playlist_tracks():
-        ytm = ytmusicapi.YTMusic(auth=json.dumps(headers))
+        ytm = ytmusicapi.YTMusic(auth=headers)
         if add:
             return ytm.add_playlist_items(playlistId=prov_playlist_id, videoIds=prov_track_ids)
         if not add:
@@ -220,7 +219,7 @@ async def get_song_radio_tracks(
     """Async wrapper around the ytmusicapi radio function."""
 
     def _get_song_radio_tracks():
-        ytm = ytmusicapi.YTMusic(auth=json.dumps(headers))
+        ytm = ytmusicapi.YTMusic(auth=headers)
         playlist_id = f"RDAMVM{prov_item_id}"
         result = ytm.get_watch_playlist(
             videoId=prov_item_id, playlistId=playlist_id, limit=limit, radio=True
@@ -262,7 +261,7 @@ async def search(query: str, ytm_filter: str = None, limit: int = 20) -> list[di
                 elif "browseId" in result:
                     result["id"] = result["browseId"]
                     del result["browseId"]
-        return results
+        return results[:limit]
 
     return await asyncio.to_thread(_search)
 
index 60721eac1375e669108c9d5b5f6bd72e01b0e024..9aa74e42412df8d0072ef5f0edc70db92444e808 100644 (file)
@@ -4,7 +4,7 @@
   "name": "YouTube Music",
   "description": "Support for the YouTube Music streaming provider in Music Assistant.",
   "codeowners": ["@MarvinSchenkel"],
-  "requirements": ["ytmusicapi==1.3.2", "git+https://github.com/MarvinSchenkel/pytube.git"],
+  "requirements": ["ytmusicapi==1.5.0", "git+https://github.com/MarvinSchenkel/pytube.git"],
   "documentation": "https://github.com/music-assistant/hass-music-assistant/discussions/606",
   "multi_instance": true
 }
index 643f44fa826512f1565c84cdab7e5685e35aa60e..95bf9a2f663c37b1b9f6f8481d98f39458586517 100644 (file)
@@ -34,5 +34,5 @@ tidalapi==0.7.3
 unidecode==1.3.8
 uvloop==0.19.0
 xmltodict==0.13.0
-ytmusicapi==1.3.2
+ytmusicapi==1.5.0
 zeroconf==0.131.0