Skip to content

Commit ba664f8

Browse files
committed
Add documentation for config, logging in and playlist modification
1 parent 431c204 commit ba664f8

File tree

5 files changed

+170
-8
lines changed

5 files changed

+170
-8
lines changed

docs/config.rst

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
2+
Config
3+
======
4+
5+
Here is an example of how you can modify the quality of tracks and videos, historically this has
6+
been done before initializing the session, since some api keys didn't support all qualities.
7+
8+
.. testcode::
9+
10+
import tidalapi
11+
12+
config = tidalapi.Config(quality=tidalapi.Quality.lossless, video_quality=tidalapi.VideoQuality.low)
13+
session = tidalapi.Session(config)

docs/index.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@ Indices and tables
77
==================
88

99
.. toctree::
10+
config
11+
login
1012
pages
13+
playlist
1114
api
1215
history
1316
genindex

docs/login.rst

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
2+
Login
3+
=====
4+
5+
Here is an example of how you can login in a more advanced way, the login is a bit complicated since
6+
people use tidalapi in lots of different ways.
7+
8+
See :class:`tidalapi.session` for additional information about the available fields and functions
9+
10+
Customizable login
11+
-------------------------
12+
13+
This will use a desktop notification to show the link used for logging in, you can also open the browser directly,
14+
display the code and tell the user to visit link.tidal.com and enter it, write it to a file, or send an email.
15+
16+
See :class:`tidalapi.session.LinkLogin` for the fields you can use to print the link
17+
18+
.. testsetup::
19+
20+
import tests.conftest
21+
import requests
22+
import sys
23+
session = tests.conftest.login(requests.Session())
24+
printer = lambda x: print(x, file=sys.stderr)
25+
26+
.. testcode::
27+
28+
from plyer import notification
29+
30+
login, future = session.login_oauth()
31+
32+
notification.notify("Open the URL to log in", login.verification_uri_complete)
33+
34+
future.result()
35+
print(session.check_login())
36+
37+
.. testoutput::
38+
:hide:
39+
40+
True
41+
42+
Simple login
43+
------------
44+
This will print the link, and then wait for the login future to complete, but it's not very flexible
45+
46+
.. testcode::
47+
48+
# The function is print by default, but you can use anything, here we do it to avoid the print being swallowed
49+
session.login_oauth_simple(function=printer)
50+
print(session.check_login())
51+
52+
.. testoutput::
53+
:hide:
54+
55+
True
56+
57+
Storing login credentials
58+
-------------------------
59+
60+
In order to store the login details, you need to store these variables in a secure place
61+
62+
.. testcode::
63+
64+
token_type = session.token_type
65+
access_token = session.access_token
66+
refresh_token = session.refresh_token # Not needed if you don't care about refreshing
67+
expiry_time = session.expiry_time
68+
69+
70+
Loading login credentials
71+
-------------------------
72+
73+
Using the variables from the above snippet, we can login using stored credentials.
74+
This could for example be used to login on your computer, and then load the credentials in the cloud.
75+
76+
.. testcode::
77+
78+
print(session.load_oauth_session(token_type, access_token, refresh_token, expiry_time))
79+
80+
.. testoutput::
81+
:hide:
82+
83+
True

docs/pages.rst

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,35 +31,37 @@ Goes through these pages and prints all of the categories and items
3131

3232
for category in home.categories:
3333
print(category.title)
34+
items = []
3435
for item in category.items:
3536
if isinstance(item, PageItem):
36-
print("\t" + item.short_header)
37-
print("\t" + item.short_sub_header[0:50])
37+
items.append("\t" + item.short_header)
38+
items.append("\t" + item.short_sub_header[0:50])
3839
# Call item.get() on this one, for example on click
3940
elif isinstance(item, PageLink):
40-
print("\t" + item.title)
41+
items.append("\t" + item.title)
4142
# Call item.get() on this one, for example on click
4243
elif isinstance(item, Mix):
43-
print("\t" + item.title)
44+
items.append("\t" + item.title)
4445
# You can optionally call item.get() to request the items() first, but it does it for you if you don't
4546
else:
46-
print("\t" + item.name)
47+
items.append("\t" + item.name)
4748
# An album could be handled by session.album(item.id) for example,
4849
# to get full details. Usually the relevant info is there already however
4950
print()
51+
[print(x) for x in sorted(items)]
5052

5153
.. testoutput::
5254
:hide:
5355
:options: +ELLIPSIS, +NORMALIZE_WHITESPACE
5456

5557
For You...
5658
Recently Played...
57-
Mixes For You...
58-
Trending Playlists...
59-
Radio Stations for You...
6059
Suggested New Tracks...
6160
Suggested New Albums...
61+
Mixes For You...
62+
Radio Stations for You...
6263
Your History...
64+
Trending Playlists...
6365
Popular Playlists...
6466
TIDAL Rising...
6567
The Charts...

docs/playlist.rst

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
2+
Playlists
3+
=========
4+
5+
This library allows you to create, modify and delete playlists, note that this is mostly about
6+
the :class:`tidalapi.playlist.UserPlaylist` class, you can't modify other's playlists
7+
8+
9+
Creating a playlist
10+
-------------------
11+
12+
.. testsetup::
13+
14+
import tests.conftest
15+
import requests
16+
session = tests.conftest.login(requests.Session())
17+
18+
.. testcode::
19+
20+
playlist = session.user.create_playlist("Example playlist", "An example of a playlist")
21+
print(playlist.name)
22+
23+
.. testoutput::
24+
:hide:
25+
26+
Example playlist
27+
28+
Adding to a playlist
29+
--------------------
30+
31+
.. testcode::
32+
33+
playlist.add([133937137, 71823815])
34+
[print(x.name) for x in playlist.tracks()]
35+
36+
.. testoutput::
37+
:hide:
38+
39+
Worlds Collide
40+
Lost Forever
41+
42+
Removing from a playlist
43+
------------------------
44+
45+
.. testcode::
46+
47+
playlist.remove_by_index(0)
48+
playlist.remove_by_id(71823815)
49+
print(playlist.tracks())
50+
51+
.. testoutput::
52+
:hide:
53+
54+
[]
55+
56+
Deleting a playlist
57+
-------------------
58+
59+
.. testcode::
60+
61+
playlist.delete()

0 commit comments

Comments
 (0)