Update docs (closes #7)

This commit is contained in:
sigma67 2020-05-22 16:19:22 +02:00
commit fadba30274
No known key found for this signature in database
GPG key ID: 1545A01D4474BAF0
8 changed files with 129 additions and 104 deletions

1
.gitignore vendored
View file

@ -2,7 +2,6 @@
.vscode .vscode
headers_auth.json headers_auth.json
docs/build docs/build
**.bat
**.cfg **.cfg
**.mp3 **.mp3
.coverage .coverage

35
docs/make.bat Normal file
View file

@ -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

View file

@ -13,12 +13,11 @@
import os import os
import sys import sys
sys.path.insert(0, os.path.abspath('.')) 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' on_rtd = os.environ.get('READTHEDOCS', None) == 'True'
from ytmusicapi import __version__
# -- Project information ----------------------------------------------------- # -- Project information -----------------------------------------------------
project = 'ytmusicapi' project = 'ytmusicapi'
@ -51,7 +50,6 @@ templates_path = ['_templates']
# This pattern also affects html_static_path and html_extra_path. # This pattern also affects html_static_path and html_extra_path.
exclude_patterns = [] exclude_patterns = []
# -- Options for HTML output ------------------------------------------------- # -- Options for HTML output -------------------------------------------------
# The theme to use for HTML and HTML Help pages. See the documentation for # The theme to use for HTML and HTML Help pages. See the documentation for

View file

@ -6,7 +6,8 @@
ytmusicapi: Unofficial API for YouTube Music ytmusicapi: Unofficial API for YouTube Music
================================================== ==================================================
The purpose of this library is to automate interactions with `YouTube Music <https://music.youtube.com/>`_, The purpose of this library is to automate interactions with `YouTube Music <https://music.youtube.com/>`_,
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** **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 :start-after: features
:end-before: end-features :end-before: end-features
For a complete documentation of available functions, refer to the :doc:`Reference <reference>` To **get started**, read the :doc:`setup instructions <setup>`.
For a **complete documentation** of available functions, see the :doc:`Reference <reference>`.
Contents Contents
-------- --------

View file

@ -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. - 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) - 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 Now call :py:func:`YTMusic.setup` with the parameter ``filepath=headers_auth.json`` and paste the request headers to the terminal input.
in the correct format in the current directory. 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 <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 Manual file creation
-------------------- --------------------

View file

@ -7,9 +7,9 @@ version_line = open(VERSIONFILE).read()
version_re = r"^__version__ = ['\"]([^'\"]*)['\"]" version_re = r"^__version__ = ['\"]([^'\"]*)['\"]"
match = re.search(version_re, version_line, re.M) match = re.search(version_re, version_line, re.M)
if match: if match:
version = match.group(1) version = match.group(1)
else: else:
raise RuntimeError("Could not find version in '%s'" % VERSIONFILE) raise RuntimeError("Could not find version in '%s'" % VERSIONFILE)
setup(name='ytmusicapi', setup(name='ytmusicapi',
version=version, version=version,
@ -20,18 +20,10 @@ setup(name='ytmusicapi',
author_email='', author_email='',
license='MIT', license='MIT',
packages=find_packages(), packages=find_packages(),
install_requires=[ install_requires=['requests >= 2.22'],
'requests >= 2.22'
],
extras_require={ extras_require={
'dev': [ 'dev': ['pre-commit', 'flake8', 'yapf', 'coverage', 'sphinx', 'sphinx-rtd-theme']
'pre-commit',
'flake8',
'yapf',
'coverage'
]
}, },
python_requires=">=3.5", python_requires=">=3.5",
include_package_data=True, include_package_data=True,
zip_safe=False zip_safe=False)
)

View file

@ -2,7 +2,7 @@ import unittest
import configparser import configparser
import sys import sys
sys.path.insert(0, '..') sys.path.insert(0, '..')
from ytmusicapi.ytmusic import YTMusic from ytmusicapi.ytmusic import YTMusic # noqa: E402
config = configparser.RawConfigParser() config = configparser.RawConfigParser()
config.read('./test.cfg', 'utf-8') config.read('./test.cfg', 'utf-8')

View file

@ -32,7 +32,6 @@ class YTMusic:
Otherwise the default account is used. You can retrieve the user ID Otherwise the default account is used. You can retrieve the user ID
by going to https://myaccount.google.com and selecting your brand account. 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/ The user ID will be in the URL: https://myaccount.google.com/b/user_id/
""" """
self.auth = auth self.auth = auth
@ -85,7 +84,7 @@ class YTMusic:
:param filepath: Optional filepath to store headers to. :param filepath: Optional filepath to store headers to.
:param headers_raw: Optional request headers copied from browser. :param headers_raw: Optional request headers copied from browser.
Otherwise requested from terminal Otherwise requested from terminal
:return: configuration headers string :return: configuration headers string
""" """
return setup(filepath, headers_raw) return setup(filepath, headers_raw)
@ -128,8 +127,6 @@ class YTMusic:
"resultType": "song" "resultType": "song"
} }
] ]
""" """
body = {'query': query} body = {'query': query}
endpoint = 'search' endpoint = 'search'
@ -202,58 +199,57 @@ class YTMusic:
:param channelId: channel id of the artist :param channelId: channel id of the artist
:return: Dictionary with requested information. :return: Dictionary with requested information.
Example:: Example::
{ {
"name": "Oasis", "name": "Oasis",
"description": "Oasis were ...", "description": "Oasis were ...",
"views": "1,838,795,605", "views": "1,838,795,605",
"songs": { "songs": {
"browseId": "VLPLMpM3Z0118S42R1npOhcjoakLIv1aqnS1", "browseId": "VLPLMpM3Z0118S42R1npOhcjoakLIv1aqnS1",
"results": [ "results": [
{ {
"videoId": "ZrOKjDZOtkA", "videoId": "ZrOKjDZOtkA",
"title": "Wonderwall (Remastered)", "title": "Wonderwall (Remastered)",
"artist": "Oasis", "artist": "Oasis",
"album": "(What's The Story) Morning Glory? (Remastered)" "album": "(What's The Story) Morning Glory? (Remastered)"
} }
] ]
}, },
"albums": { "albums": {
"results": [ "results": [
{ {
"title": "Familiar To Millions", "title": "Familiar To Millions",
"year": "2018", "year": "2018",
"browseId": "MPREb_AYetWMZunqA" "browseId": "MPREb_AYetWMZunqA"
} }
], ],
"browseId": "UCmMUZbaYdNH0bEd1PAlAqsA", "browseId": "UCmMUZbaYdNH0bEd1PAlAqsA",
"params": "6gPTAUNwc0JDbndLYlFBQV..." "params": "6gPTAUNwc0JDbndLYlFBQV..."
}, },
"singles": { "singles": {
"results": [ "results": [
{ {
"title": "Stand By Me (Mustique Demo)", "title": "Stand By Me (Mustique Demo)",
"year": "2016", "year": "2016",
"browseId": "MPREb_7MPKLhibN5G" "browseId": "MPREb_7MPKLhibN5G"
} }
], ],
"browseId": "UCmMUZbaYdNH0bEd1PAlAqsA", "browseId": "UCmMUZbaYdNH0bEd1PAlAqsA",
"params": "6gPTAUNwc0JDbndLYlFBQV..." "params": "6gPTAUNwc0JDbndLYlFBQV..."
}, },
"videos": { "videos": {
"results": [ "results": [
{ {
"title": "Wonderwall", "title": "Wonderwall",
"views": "358M", "views": "358M",
"videoId": "bx1Bh8ZvH84", "videoId": "bx1Bh8ZvH84",
"playlistId": "PLMpM3Z0118S5xuNckw1HUcj1D021AnMEB" "playlistId": "PLMpM3Z0118S5xuNckw1HUcj1D021AnMEB"
} }
], ],
"browseId": "VLPLMpM3Z0118S5xuNckw1HUcj1D021AnMEB" "browseId": "VLPLMpM3Z0118S5xuNckw1HUcj1D021AnMEB"
}
} }
}
""" """
body = prepare_browse_endpoint("ARTIST", channelId) body = prepare_browse_endpoint("ARTIST", channelId)
endpoint = 'browse' endpoint = 'browse'
@ -314,16 +310,15 @@ class YTMusic:
:param params: params obtained by :py:func:`get_artist` :param params: params obtained by :py:func:`get_artist`
:return: List of albums or singles :return: List of albums or singles
Example:: Example::
{
"browseId": "MPREb_0rtvKhqeCY0",
"artist": "Armin van Buuren",
"title": "This I Vow (feat. Mila Josef)",
"type": "EP",
"year": "2020"
}
{
"browseId": "MPREb_0rtvKhqeCY0",
"artist": "Armin van Buuren",
"title": "This I Vow (feat. Mila Josef)",
"type": "EP",
"year": "2020"
}
""" """
body = {"browseId": channelId, "params": params} body = {"browseId": channelId, "params": params}
endpoint = 'browse' endpoint = 'browse'
@ -357,7 +352,7 @@ class YTMusic:
returned by :py:func:`search` returned by :py:func:`search`
:return: Dictionary with title, description, artist and tracks. :return: Dictionary with title, description, artist and tracks.
Each track is in the following format:: Each track is in the following format::
{ {
"title": "Seven", "title": "Seven",
@ -385,7 +380,7 @@ class YTMusic:
"lengthMs": "203406" "lengthMs": "203406"
} }
] ]
}
""" """
body = prepare_browse_endpoint("ALBUM", browseId) body = prepare_browse_endpoint("ALBUM", browseId)
endpoint = 'browse' endpoint = 'browse'
@ -440,7 +435,6 @@ class YTMusic:
'title': 'Playlist title', 'title': 'Playlist title',
'count': 5 'count': 5
} }
""" """
self.__check_auth() self.__check_auth()
body = {'browseId': 'FEmusic_liked_playlists'} body = {'browseId': 'FEmusic_liked_playlists'}
@ -534,7 +528,6 @@ class YTMusic:
"artist": "WildVibes", "artist": "WildVibes",
"subscribers": "2.91K" "subscribers": "2.91K"
} }
""" """
self.__check_auth() self.__check_auth()
body = {'browseId': 'FEmusic_library_corpus_track_artists'} body = {'browseId': 'FEmusic_library_corpus_track_artists'}
@ -720,7 +713,6 @@ class YTMusic:
The setVideoId is the unique id of this playlist item and The setVideoId is the unique id of this playlist item and
needed for moving/removing playlist items needed for moving/removing playlist items
""" """
browseId = "VL" + playlistId if not playlistId.startswith("VL") else playlistId browseId = "VL" + playlistId if not playlistId.startswith("VL") else playlistId
body = prepare_browse_endpoint("PLAYLIST", browseId) body = prepare_browse_endpoint("PLAYLIST", browseId)
@ -931,7 +923,6 @@ class YTMusic:
"title": "A Sky Full Of Stars", "title": "A Sky Full Of Stars",
"album": "Ghost Stories" "album": "Ghost Stories"
} }
""" """
self.__check_auth() self.__check_auth()
endpoint = 'browse' endpoint = 'browse'
@ -957,8 +948,8 @@ class YTMusic:
""" """
Gets the albums of uploaded songs in the user's library. Gets the albums of uploaded songs in the user's library.
:param limit: Number of albums to return :param limit: Number of albums to return. Default: 25
:returns List of albums as returned by :py:func:`get_library_albums` :return: List of albums as returned by :py:func:`get_library_albums`
""" """
self.__check_auth() self.__check_auth()
body = {'browseId': 'FEmusic_library_privately_owned_releases'} body = {'browseId': 'FEmusic_library_privately_owned_releases'}
@ -987,8 +978,8 @@ class YTMusic:
""" """
Gets the artists of uploaded songs in the user's library. Gets the artists of uploaded songs in the user's library.
:param limit: :param limit: Number of artists to return. Default: 25
:returns List of artists as returned by :py:func:`get_library_artists` :return: List of artists as returned by :py:func:`get_library_artists`
""" """
self.__check_auth() self.__check_auth()
body = {'browseId': 'FEmusic_library_privately_owned_artists'} body = {'browseId': 'FEmusic_library_privately_owned_artists'}
@ -1013,10 +1004,11 @@ class YTMusic:
""" """
Returns a list of uploaded tracks for the artist. Returns a list of uploaded tracks for the artist.
:param browseId: :param browseId: Browse id of the upload artist, i.e. from :py:func:`get_library_upload_songs`
:return: List of uploaded songs :return: List of uploaded songs.
Example List::
Example List:
[ [
{ {
"entityId": "t_po_CICr2crg7OWpchDKwoakAQ", "entityId": "t_po_CICr2crg7OWpchDKwoakAQ",
@ -1031,7 +1023,6 @@ class YTMusic:
"album": null "album": null
} }
] ]
""" """
self.__check_auth() self.__check_auth()
body = prepare_browse_endpoint("ARTIST", browseId) body = prepare_browse_endpoint("ARTIST", browseId)
@ -1047,8 +1038,10 @@ class YTMusic:
""" """
Get information and tracks of an album associated with uploaded tracks Get information and tracks of an album associated with uploaded tracks
:param browseId: :param browseId: Browse id of the upload album, i.e. from i.e. from :py:func:`get_library_upload_songs`
:returns Dictionary with title, description, artist and tracks. :return: Dictionary with title, description, artist and tracks.
Example album::
{ {
"title": "Hard To Stop - Single", "title": "Hard To Stop - Single",
@ -1134,7 +1127,7 @@ class YTMusic:
""" """
Deletes a previously uploaded song or album 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` e.g. retrieved from :py:func:`get_library_upload_songs`
:return: Status String or error :return: Status String or error
""" """