From e1ca551342aa52a10517459338c16e55e01daf8e Mon Sep 17 00:00:00 2001 From: sigma67 <16363825+sigma67@users.noreply.github.com> Date: Fri, 27 Dec 2024 20:02:16 +0100 Subject: [PATCH] fix #703 (#704) --- docs/source/_static/style.css | 3 + docs/source/_templates/layout.html | 4 ++ docs/source/conf.py | 7 ++- docs/source/faq.rst | 2 +- docs/source/index.rst | 4 +- docs/source/reference.rst | 97 ----------------------------- docs/source/reference/browsing.rst | 17 +++++ docs/source/reference/explore.rst | 7 +++ docs/source/reference/index.rst | 18 ++++++ docs/source/reference/library.rst | 22 +++++++ docs/source/reference/playlists.rst | 10 +++ docs/source/reference/podcasts.rst | 9 +++ docs/source/reference/search.rst | 7 +++ docs/source/reference/setup.rst | 8 +++ docs/source/reference/uploads.rst | 11 ++++ docs/source/reference/watch.rst | 5 ++ docs/source/reference/ytmusic.rst | 6 ++ ytmusicapi/mixins/library.py | 12 +++- 18 files changed, 147 insertions(+), 102 deletions(-) create mode 100644 docs/source/_static/style.css create mode 100644 docs/source/_templates/layout.html delete mode 100644 docs/source/reference.rst create mode 100644 docs/source/reference/browsing.rst create mode 100644 docs/source/reference/explore.rst create mode 100644 docs/source/reference/index.rst create mode 100644 docs/source/reference/library.rst create mode 100644 docs/source/reference/playlists.rst create mode 100644 docs/source/reference/podcasts.rst create mode 100644 docs/source/reference/search.rst create mode 100644 docs/source/reference/setup.rst create mode 100644 docs/source/reference/uploads.rst create mode 100644 docs/source/reference/watch.rst create mode 100644 docs/source/reference/ytmusic.rst diff --git a/docs/source/_static/style.css b/docs/source/_static/style.css new file mode 100644 index 00000000..18dd3fa4 --- /dev/null +++ b/docs/source/_static/style.css @@ -0,0 +1,3 @@ +.wy-nav-content { + max-width: 1080px !important; +} diff --git a/docs/source/_templates/layout.html b/docs/source/_templates/layout.html new file mode 100644 index 00000000..4392ca73 --- /dev/null +++ b/docs/source/_templates/layout.html @@ -0,0 +1,4 @@ +{% extends "!layout.html" %} +{% block extrahead %} + +{% endblock %} diff --git a/docs/source/conf.py b/docs/source/conf.py index 5dfad5f5..3ae20fb4 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -23,7 +23,7 @@ # -- Project information ----------------------------------------------------- project = "ytmusicapi" -copyright = "2022, sigma67" +copyright = "2024, sigma67" author = "sigma67" # The full version, including alpha/beta/rc tags @@ -47,6 +47,11 @@ # Add any paths that contain templates here, relative to this directory. templates_path = ["_templates"] +# Add any paths that contain custom static files (such as style sheets) here, +# relative to this directory. They are copied after the builtin static files, +# so a file named "default.css" will overwrite the builtin "default.css". +html_static_path = ["_static"] + # List of patterns, relative to source directory, that match files and # directories to ignore when looking for source files. # This pattern also affects html_static_path and html_extra_path. diff --git a/docs/source/faq.rst b/docs/source/faq.rst index 239f7c8e..f0e533f5 100644 --- a/docs/source/faq.rst +++ b/docs/source/faq.rst @@ -12,7 +12,7 @@ My library results are empty even though I set up my cookie correctly. Please make sure that you don't have multiple Google accounts. ``ytmusicapi`` might be returning results from a different account which is currently empty. You can set your account using ``X-Goog-AuthUser`` in your headers file (numeric index) or by providing the id of a brand account with ``ytmusic = YTMusic(headers, "1234..")``. -For more details see the :doc:`reference`. +For more details see the :doc:`reference/index`. Usage ----------------------- diff --git a/docs/source/index.rst b/docs/source/index.rst index f30b893d..fa1a5b14 100644 --- a/docs/source/index.rst +++ b/docs/source/index.rst @@ -12,7 +12,7 @@ To achieve this, it emulates web requests that would occur if you performed the To **get started**, read the :doc:`setup instructions `. -For a **complete documentation** of available functions, see the :doc:`Reference `. +For a **complete documentation** of available functions, see the :doc:`Reference `. Contents -------- @@ -26,5 +26,5 @@ Contents setup/index usage - reference + reference/index faq diff --git a/docs/source/reference.rst b/docs/source/reference.rst deleted file mode 100644 index d77018b9..00000000 --- a/docs/source/reference.rst +++ /dev/null @@ -1,97 +0,0 @@ -Reference -================== - -Reference for the YTMusic class. - -.. currentmodule:: ytmusicapi -.. autoclass:: YTMusic -.. automethod:: YTMusic.__init__ - - -Setup ------ -See also the :doc:`Setup ` page - -.. autofunction:: setup -.. autofunction:: setup_oauth - -Search ------- -.. automethod:: YTMusic.search -.. automethod:: YTMusic.get_search_suggestions -.. automethod:: YTMusic.remove_search_suggestions - - -Browsing --------- -.. automethod:: YTMusic.get_home -.. automethod:: YTMusic.get_artist -.. automethod:: YTMusic.get_artist_albums -.. automethod:: YTMusic.get_album -.. automethod:: YTMusic.get_album_browse_id -.. automethod:: YTMusic.get_user -.. automethod:: YTMusic.get_user_playlists -.. automethod:: YTMusic.get_user_videos -.. automethod:: YTMusic.get_song -.. automethod:: YTMusic.get_song_related -.. automethod:: YTMusic.get_lyrics -.. automethod:: YTMusic.get_tasteprofile -.. automethod:: YTMusic.set_tasteprofile - -Explore --------- -.. automethod:: YTMusic.get_mood_categories -.. automethod:: YTMusic.get_mood_playlists -.. automethod:: YTMusic.get_charts - -Watch --------- -.. automethod:: YTMusic.get_watch_playlist - -Library -------- -.. automethod:: YTMusic.get_library_playlists -.. automethod:: YTMusic.get_library_songs -.. automethod:: YTMusic.get_library_albums -.. automethod:: YTMusic.get_library_artists -.. automethod:: YTMusic.get_library_subscriptions -.. automethod:: YTMusic.get_library_podcasts -.. automethod:: YTMusic.get_library_channels -.. automethod:: YTMusic.get_liked_songs -.. automethod:: YTMusic.get_saved_episodes -.. automethod:: YTMusic.get_history -.. automethod:: YTMusic.add_history_item -.. automethod:: YTMusic.remove_history_items -.. automethod:: YTMusic.rate_song -.. automethod:: YTMusic.edit_song_library_status -.. automethod:: YTMusic.rate_playlist -.. automethod:: YTMusic.subscribe_artists -.. automethod:: YTMusic.unsubscribe_artists -.. automethod:: YTMusic.get_account_info - -Playlists ---------- -.. automethod:: YTMusic.get_playlist -.. automethod:: YTMusic.create_playlist -.. automethod:: YTMusic.edit_playlist -.. automethod:: YTMusic.delete_playlist -.. automethod:: YTMusic.add_playlist_items -.. automethod:: YTMusic.remove_playlist_items - -Podcasts --------- -.. automethod:: YTMusic.get_channel -.. automethod:: YTMusic.get_channel_episodes -.. automethod:: YTMusic.get_podcast -.. automethod:: YTMusic.get_episode -.. automethod:: YTMusic.get_episodes_playlist - -Uploads -------- -.. automethod:: YTMusic.get_library_upload_songs -.. automethod:: YTMusic.get_library_upload_artists -.. automethod:: YTMusic.get_library_upload_albums -.. automethod:: YTMusic.get_library_upload_artist -.. automethod:: YTMusic.get_library_upload_album -.. automethod:: YTMusic.upload_song -.. automethod:: YTMusic.delete_upload_entity diff --git a/docs/source/reference/browsing.rst b/docs/source/reference/browsing.rst new file mode 100644 index 00000000..b69813eb --- /dev/null +++ b/docs/source/reference/browsing.rst @@ -0,0 +1,17 @@ +Browsing +-------- + +.. currentmodule:: ytmusicapi +.. automethod:: YTMusic.get_home +.. automethod:: YTMusic.get_artist +.. automethod:: YTMusic.get_artist_albums +.. automethod:: YTMusic.get_album +.. automethod:: YTMusic.get_album_browse_id +.. automethod:: YTMusic.get_user +.. automethod:: YTMusic.get_user_playlists +.. automethod:: YTMusic.get_user_videos +.. automethod:: YTMusic.get_song +.. automethod:: YTMusic.get_song_related +.. automethod:: YTMusic.get_lyrics +.. automethod:: YTMusic.get_tasteprofile +.. automethod:: YTMusic.set_tasteprofile diff --git a/docs/source/reference/explore.rst b/docs/source/reference/explore.rst new file mode 100644 index 00000000..36df3726 --- /dev/null +++ b/docs/source/reference/explore.rst @@ -0,0 +1,7 @@ +Explore +-------- + +.. currentmodule:: ytmusicapi +.. automethod:: YTMusic.get_mood_categories +.. automethod:: YTMusic.get_mood_playlists +.. automethod:: YTMusic.get_charts diff --git a/docs/source/reference/index.rst b/docs/source/reference/index.rst new file mode 100644 index 00000000..9192d607 --- /dev/null +++ b/docs/source/reference/index.rst @@ -0,0 +1,18 @@ +Reference +========= + +Reference for the YTMusic class. + + +.. toctree:: + + ytmusic + setup + search + browsing + explore + watch + library + playlists + podcasts + uploads diff --git a/docs/source/reference/library.rst b/docs/source/reference/library.rst new file mode 100644 index 00000000..16a92dfa --- /dev/null +++ b/docs/source/reference/library.rst @@ -0,0 +1,22 @@ +Library +------- + +.. currentmodule:: ytmusicapi +.. automethod:: YTMusic.get_library_playlists +.. automethod:: YTMusic.get_library_songs +.. automethod:: YTMusic.get_library_albums +.. automethod:: YTMusic.get_library_artists +.. automethod:: YTMusic.get_library_subscriptions +.. automethod:: YTMusic.get_library_podcasts +.. automethod:: YTMusic.get_library_channels +.. automethod:: YTMusic.get_liked_songs +.. automethod:: YTMusic.get_saved_episodes +.. automethod:: YTMusic.get_history +.. automethod:: YTMusic.add_history_item +.. automethod:: YTMusic.remove_history_items +.. automethod:: YTMusic.rate_song +.. automethod:: YTMusic.edit_song_library_status +.. automethod:: YTMusic.rate_playlist +.. automethod:: YTMusic.subscribe_artists +.. automethod:: YTMusic.unsubscribe_artists +.. automethod:: YTMusic.get_account_info diff --git a/docs/source/reference/playlists.rst b/docs/source/reference/playlists.rst new file mode 100644 index 00000000..3e36ff31 --- /dev/null +++ b/docs/source/reference/playlists.rst @@ -0,0 +1,10 @@ +Playlists +--------- + +.. currentmodule:: ytmusicapi +.. automethod:: YTMusic.get_playlist +.. automethod:: YTMusic.create_playlist +.. automethod:: YTMusic.edit_playlist +.. automethod:: YTMusic.delete_playlist +.. automethod:: YTMusic.add_playlist_items +.. automethod:: YTMusic.remove_playlist_items diff --git a/docs/source/reference/podcasts.rst b/docs/source/reference/podcasts.rst new file mode 100644 index 00000000..716af840 --- /dev/null +++ b/docs/source/reference/podcasts.rst @@ -0,0 +1,9 @@ +Podcasts +-------- + +.. currentmodule:: ytmusicapi +.. automethod:: YTMusic.get_channel +.. automethod:: YTMusic.get_channel_episodes +.. automethod:: YTMusic.get_podcast +.. automethod:: YTMusic.get_episode +.. automethod:: YTMusic.get_episodes_playlist diff --git a/docs/source/reference/search.rst b/docs/source/reference/search.rst new file mode 100644 index 00000000..46537eb2 --- /dev/null +++ b/docs/source/reference/search.rst @@ -0,0 +1,7 @@ +Search +------ + +.. currentmodule:: ytmusicapi +.. automethod:: YTMusic.search +.. automethod:: YTMusic.get_search_suggestions +.. automethod:: YTMusic.remove_search_suggestions diff --git a/docs/source/reference/setup.rst b/docs/source/reference/setup.rst new file mode 100644 index 00000000..7d36f14a --- /dev/null +++ b/docs/source/reference/setup.rst @@ -0,0 +1,8 @@ +Setup +----- + +See also the :doc:`Setup <../setup/index>` page + +.. currentmodule:: ytmusicapi +.. autofunction:: setup +.. autofunction:: setup_oauth diff --git a/docs/source/reference/uploads.rst b/docs/source/reference/uploads.rst new file mode 100644 index 00000000..be9b6977 --- /dev/null +++ b/docs/source/reference/uploads.rst @@ -0,0 +1,11 @@ +Uploads +------- + +.. currentmodule:: ytmusicapi +.. automethod:: YTMusic.get_library_upload_songs +.. automethod:: YTMusic.get_library_upload_artists +.. automethod:: YTMusic.get_library_upload_albums +.. automethod:: YTMusic.get_library_upload_artist +.. automethod:: YTMusic.get_library_upload_album +.. automethod:: YTMusic.upload_song +.. automethod:: YTMusic.delete_upload_entity diff --git a/docs/source/reference/watch.rst b/docs/source/reference/watch.rst new file mode 100644 index 00000000..e5ac6003 --- /dev/null +++ b/docs/source/reference/watch.rst @@ -0,0 +1,5 @@ +Watch +-------- + +.. currentmodule:: ytmusicapi +.. automethod:: YTMusic.get_watch_playlist diff --git a/docs/source/reference/ytmusic.rst b/docs/source/reference/ytmusic.rst new file mode 100644 index 00000000..f593f0d6 --- /dev/null +++ b/docs/source/reference/ytmusic.rst @@ -0,0 +1,6 @@ +YTMusic +------- + +.. currentmodule:: ytmusicapi +.. autoclass:: YTMusic +.. automethod:: YTMusic.__init__ diff --git a/ytmusicapi/mixins/library.py b/ytmusicapi/mixins/library.py index 0517c96d..dc67eca0 100644 --- a/ytmusicapi/mixins/library.py +++ b/ytmusicapi/mixins/library.py @@ -312,11 +312,21 @@ def get_history(self) -> list[dict]: def add_history_item(self, song): """ Add an item to the account's history using the playbackTracking URI - obtained from :py:func:`get_song`. + obtained from :py:func:`get_song`. A ``204`` return code indicates success. + + Usage:: + + song = yt_auth.get_song(videoId) + response = yt_auth.add_history_item(song) + + .. note:: + + You need to use the same YTMusic instance as you used for :py:func:`get_song`. :param song: Dictionary as returned by :py:func:`get_song` :return: Full response. response.status_code is 204 if successful """ + self._check_auth() url = song["playbackTracking"]["videostatsPlaybackUrl"]["baseUrl"] CPNA = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_" cpn = "".join(CPNA[randint(0, 256) & 63] for _ in range(0, 16))