diff --git a/.gitignore b/.gitignore
index df50230..55e2cff 100644
--- a/.gitignore
+++ b/.gitignore
@@ -2,7 +2,6 @@
.vscode
headers_auth.json
docs/build
-**.bat
**.cfg
**.mp3
.coverage
\ No newline at end of file
diff --git a/docs/make.bat b/docs/make.bat
new file mode 100644
index 0000000..9534b01
--- /dev/null
+++ b/docs/make.bat
@@ -0,0 +1,35 @@
+@ECHO OFF
+
+pushd %~dp0
+
+REM Command file for Sphinx documentation
+
+if "%SPHINXBUILD%" == "" (
+ set SPHINXBUILD=sphinx-build
+)
+set SOURCEDIR=source
+set BUILDDIR=build
+
+if "%1" == "" goto help
+
+%SPHINXBUILD% >NUL 2>NUL
+if errorlevel 9009 (
+ echo.
+ echo.The 'sphinx-build' command was not found. Make sure you have Sphinx
+ echo.installed, then set the SPHINXBUILD environment variable to point
+ echo.to the full path of the 'sphinx-build' executable. Alternatively you
+ echo.may add the Sphinx directory to PATH.
+ echo.
+ echo.If you don't have Sphinx installed, grab it from
+ echo.http://sphinx-doc.org/
+ exit /b 1
+)
+
+%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
+goto end
+
+:help
+%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
+
+:end
+popd
diff --git a/docs/source/conf.py b/docs/source/conf.py
index 38be5df..baa9632 100644
--- a/docs/source/conf.py
+++ b/docs/source/conf.py
@@ -13,12 +13,11 @@
import os
import sys
sys.path.insert(0, os.path.abspath('.'))
+sys.path.insert(0, '../..')
+from ytmusicapi import __version__ # noqa: E402
on_rtd = os.environ.get('READTHEDOCS', None) == 'True'
-from ytmusicapi import __version__
-
-
# -- Project information -----------------------------------------------------
project = 'ytmusicapi'
@@ -51,7 +50,6 @@ templates_path = ['_templates']
# This pattern also affects html_static_path and html_extra_path.
exclude_patterns = []
-
# -- Options for HTML output -------------------------------------------------
# The theme to use for HTML and HTML Help pages. See the documentation for
@@ -73,4 +71,4 @@ else:
# 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']
\ No newline at end of file
+html_static_path = ['_static']
diff --git a/docs/source/index.rst b/docs/source/index.rst
index b24b69c..c5c35df 100644
--- a/docs/source/index.rst
+++ b/docs/source/index.rst
@@ -6,7 +6,8 @@
ytmusicapi: Unofficial API for YouTube Music
==================================================
The purpose of this library is to automate interactions with `YouTube Music `_,
-such as retrieving your library content or creating large playlists.
+such as retrieving your library content, managing playlists and uploading songs.
+To achieve this, it emulates web requests that would occur if you performed the same actions in your web browser.
**This project is not supported nor endorsed by Google**
@@ -14,7 +15,9 @@ such as retrieving your library content or creating large playlists.
:start-after: features
:end-before: end-features
-For a complete documentation of available functions, refer to the :doc:`Reference `
+To **get started**, read the :doc:`setup instructions `.
+
+For a **complete documentation** of available functions, see the :doc:`Reference `.
Contents
--------
diff --git a/docs/source/setup.rst b/docs/source/setup.rst
index e874c43..eb87ae4 100644
--- a/docs/source/setup.rst
+++ b/docs/source/setup.rst
@@ -17,8 +17,13 @@ To do so, follow these steps:
- Go to the developer tools (Ctrl-Shift-I) and find an authenticated POST request. You can filter for /browse to easily find a suitable request.
- Copy the request headers (right click > copy > copy request headers)
-Now call :py:func:`YTMusic.setup()` and paste the request headers and it will create configuration file
-in the correct format in the current directory.
+Now call :py:func:`YTMusic.setup` with the parameter ``filepath=headers_auth.json`` and paste the request headers to the terminal input.
+If you don't want terminal interaction you can pass the request headers with the ``headers_raw`` parameter.
+
+The function returns a JSON string with the credentials needed for :doc:`Usage `. Alternatively, if you passed the filepath parameter as described above,
+a file called ``headers_auth.json`` will be created in the current directory, which you can pass to ``YTMusic()`` for authentication.
+
+These credentials remain valid as long as your YTMusic browser session is valid (about 2 years unless you log out).
Manual file creation
--------------------
diff --git a/setup.py b/setup.py
index 49291ef..8dcb68f 100644
--- a/setup.py
+++ b/setup.py
@@ -7,9 +7,9 @@ version_line = open(VERSIONFILE).read()
version_re = r"^__version__ = ['\"]([^'\"]*)['\"]"
match = re.search(version_re, version_line, re.M)
if match:
- version = match.group(1)
+ version = match.group(1)
else:
- raise RuntimeError("Could not find version in '%s'" % VERSIONFILE)
+ raise RuntimeError("Could not find version in '%s'" % VERSIONFILE)
setup(name='ytmusicapi',
version=version,
@@ -20,18 +20,10 @@ setup(name='ytmusicapi',
author_email='',
license='MIT',
packages=find_packages(),
- install_requires=[
- 'requests >= 2.22'
- ],
+ install_requires=['requests >= 2.22'],
extras_require={
- 'dev': [
- 'pre-commit',
- 'flake8',
- 'yapf',
- 'coverage'
- ]
+ 'dev': ['pre-commit', 'flake8', 'yapf', 'coverage', 'sphinx', 'sphinx-rtd-theme']
},
python_requires=">=3.5",
include_package_data=True,
- zip_safe=False
-)
+ zip_safe=False)
diff --git a/tests/test.py b/tests/test.py
index bb19d34..54dd9c3 100644
--- a/tests/test.py
+++ b/tests/test.py
@@ -2,7 +2,7 @@ import unittest
import configparser
import sys
sys.path.insert(0, '..')
-from ytmusicapi.ytmusic import YTMusic
+from ytmusicapi.ytmusic import YTMusic # noqa: E402
config = configparser.RawConfigParser()
config.read('./test.cfg', 'utf-8')
diff --git a/ytmusicapi/ytmusic.py b/ytmusicapi/ytmusic.py
index b77cf98..e095a24 100644
--- a/ytmusicapi/ytmusic.py
+++ b/ytmusicapi/ytmusic.py
@@ -32,7 +32,6 @@ class YTMusic:
Otherwise the default account is used. You can retrieve the user ID
by going to https://myaccount.google.com and selecting your brand account.
The user ID will be in the URL: https://myaccount.google.com/b/user_id/
-
"""
self.auth = auth
@@ -85,7 +84,7 @@ class YTMusic:
:param filepath: Optional filepath to store headers to.
:param headers_raw: Optional request headers copied from browser.
- Otherwise requested from terminal
+ Otherwise requested from terminal
:return: configuration headers string
"""
return setup(filepath, headers_raw)
@@ -128,8 +127,6 @@ class YTMusic:
"resultType": "song"
}
]
-
-
"""
body = {'query': query}
endpoint = 'search'
@@ -202,58 +199,57 @@ class YTMusic:
:param channelId: channel id of the artist
:return: Dictionary with requested information.
- Example::
+ Example::
- {
- "name": "Oasis",
- "description": "Oasis were ...",
- "views": "1,838,795,605",
- "songs": {
- "browseId": "VLPLMpM3Z0118S42R1npOhcjoakLIv1aqnS1",
- "results": [
- {
- "videoId": "ZrOKjDZOtkA",
- "title": "Wonderwall (Remastered)",
- "artist": "Oasis",
- "album": "(What's The Story) Morning Glory? (Remastered)"
- }
- ]
- },
- "albums": {
- "results": [
- {
- "title": "Familiar To Millions",
- "year": "2018",
- "browseId": "MPREb_AYetWMZunqA"
- }
- ],
- "browseId": "UCmMUZbaYdNH0bEd1PAlAqsA",
- "params": "6gPTAUNwc0JDbndLYlFBQV..."
- },
- "singles": {
- "results": [
- {
- "title": "Stand By Me (Mustique Demo)",
- "year": "2016",
- "browseId": "MPREb_7MPKLhibN5G"
- }
- ],
- "browseId": "UCmMUZbaYdNH0bEd1PAlAqsA",
- "params": "6gPTAUNwc0JDbndLYlFBQV..."
- },
- "videos": {
- "results": [
- {
- "title": "Wonderwall",
- "views": "358M",
- "videoId": "bx1Bh8ZvH84",
- "playlistId": "PLMpM3Z0118S5xuNckw1HUcj1D021AnMEB"
- }
- ],
- "browseId": "VLPLMpM3Z0118S5xuNckw1HUcj1D021AnMEB"
- }
+ {
+ "name": "Oasis",
+ "description": "Oasis were ...",
+ "views": "1,838,795,605",
+ "songs": {
+ "browseId": "VLPLMpM3Z0118S42R1npOhcjoakLIv1aqnS1",
+ "results": [
+ {
+ "videoId": "ZrOKjDZOtkA",
+ "title": "Wonderwall (Remastered)",
+ "artist": "Oasis",
+ "album": "(What's The Story) Morning Glory? (Remastered)"
+ }
+ ]
+ },
+ "albums": {
+ "results": [
+ {
+ "title": "Familiar To Millions",
+ "year": "2018",
+ "browseId": "MPREb_AYetWMZunqA"
+ }
+ ],
+ "browseId": "UCmMUZbaYdNH0bEd1PAlAqsA",
+ "params": "6gPTAUNwc0JDbndLYlFBQV..."
+ },
+ "singles": {
+ "results": [
+ {
+ "title": "Stand By Me (Mustique Demo)",
+ "year": "2016",
+ "browseId": "MPREb_7MPKLhibN5G"
+ }
+ ],
+ "browseId": "UCmMUZbaYdNH0bEd1PAlAqsA",
+ "params": "6gPTAUNwc0JDbndLYlFBQV..."
+ },
+ "videos": {
+ "results": [
+ {
+ "title": "Wonderwall",
+ "views": "358M",
+ "videoId": "bx1Bh8ZvH84",
+ "playlistId": "PLMpM3Z0118S5xuNckw1HUcj1D021AnMEB"
+ }
+ ],
+ "browseId": "VLPLMpM3Z0118S5xuNckw1HUcj1D021AnMEB"
}
-
+ }
"""
body = prepare_browse_endpoint("ARTIST", channelId)
endpoint = 'browse'
@@ -314,16 +310,15 @@ class YTMusic:
:param params: params obtained by :py:func:`get_artist`
:return: List of albums or singles
- Example::
-
- {
- "browseId": "MPREb_0rtvKhqeCY0",
- "artist": "Armin van Buuren",
- "title": "This I Vow (feat. Mila Josef)",
- "type": "EP",
- "year": "2020"
- }
+ Example::
+ {
+ "browseId": "MPREb_0rtvKhqeCY0",
+ "artist": "Armin van Buuren",
+ "title": "This I Vow (feat. Mila Josef)",
+ "type": "EP",
+ "year": "2020"
+ }
"""
body = {"browseId": channelId, "params": params}
endpoint = 'browse'
@@ -357,7 +352,7 @@ class YTMusic:
returned by :py:func:`search`
:return: Dictionary with title, description, artist and tracks.
- Each track is in the following format::
+ Each track is in the following format::
{
"title": "Seven",
@@ -385,7 +380,7 @@ class YTMusic:
"lengthMs": "203406"
}
]
-
+ }
"""
body = prepare_browse_endpoint("ALBUM", browseId)
endpoint = 'browse'
@@ -440,7 +435,6 @@ class YTMusic:
'title': 'Playlist title',
'count': 5
}
-
"""
self.__check_auth()
body = {'browseId': 'FEmusic_liked_playlists'}
@@ -534,7 +528,6 @@ class YTMusic:
"artist": "WildVibes",
"subscribers": "2.91K"
}
-
"""
self.__check_auth()
body = {'browseId': 'FEmusic_library_corpus_track_artists'}
@@ -720,7 +713,6 @@ class YTMusic:
The setVideoId is the unique id of this playlist item and
needed for moving/removing playlist items
-
"""
browseId = "VL" + playlistId if not playlistId.startswith("VL") else playlistId
body = prepare_browse_endpoint("PLAYLIST", browseId)
@@ -931,7 +923,6 @@ class YTMusic:
"title": "A Sky Full Of Stars",
"album": "Ghost Stories"
}
-
"""
self.__check_auth()
endpoint = 'browse'
@@ -957,8 +948,8 @@ class YTMusic:
"""
Gets the albums of uploaded songs in the user's library.
- :param limit: Number of albums to return
- :returns List of albums as returned by :py:func:`get_library_albums`
+ :param limit: Number of albums to return. Default: 25
+ :return: List of albums as returned by :py:func:`get_library_albums`
"""
self.__check_auth()
body = {'browseId': 'FEmusic_library_privately_owned_releases'}
@@ -987,8 +978,8 @@ class YTMusic:
"""
Gets the artists of uploaded songs in the user's library.
- :param limit:
- :returns List of artists as returned by :py:func:`get_library_artists`
+ :param limit: Number of artists to return. Default: 25
+ :return: List of artists as returned by :py:func:`get_library_artists`
"""
self.__check_auth()
body = {'browseId': 'FEmusic_library_privately_owned_artists'}
@@ -1013,10 +1004,11 @@ class YTMusic:
"""
Returns a list of uploaded tracks for the artist.
- :param browseId:
- :return: List of uploaded songs
+ :param browseId: Browse id of the upload artist, i.e. from :py:func:`get_library_upload_songs`
+ :return: List of uploaded songs.
+
+ Example List::
- Example List:
[
{
"entityId": "t_po_CICr2crg7OWpchDKwoakAQ",
@@ -1031,7 +1023,6 @@ class YTMusic:
"album": null
}
]
-
"""
self.__check_auth()
body = prepare_browse_endpoint("ARTIST", browseId)
@@ -1047,8 +1038,10 @@ class YTMusic:
"""
Get information and tracks of an album associated with uploaded tracks
- :param browseId:
- :returns Dictionary with title, description, artist and tracks.
+ :param browseId: Browse id of the upload album, i.e. from i.e. from :py:func:`get_library_upload_songs`
+ :return: Dictionary with title, description, artist and tracks.
+
+ Example album::
{
"title": "Hard To Stop - Single",
@@ -1134,7 +1127,7 @@ class YTMusic:
"""
Deletes a previously uploaded song or album
- :param entityId: The entity id of the uploaded song to delete,
+ :param entityId: The entity id of the uploaded song or album,
e.g. retrieved from :py:func:`get_library_upload_songs`
:return: Status String or error
"""