Skip to content

Commit b2542cf

Browse files
devoxinAlexFlipnotesh0tx420tailoricapex2504
authored
Update dev to Lavalink.py 4.0 (#121)
* Rename some errors, support Union[int, str] for user_id * Expose AuthenticationError * Ambiguous no more * Update get_tracks returns * Fix dispatching to empty hook lists * Bump aiohttp * Fix slight mistake in example cog. * Readme QoL change. * Use a link reference instead * Start on filter stuff * Update license stuff * Fix CI badge * Fix broken doc ref * Finishing up filter stuff maybe * Specify decode_errors when decoding author too * Exceptions -> Errors, more reliably pull WS close code, handle ConnectionResetError * Didn't mean to push this loool * Add utfm decoding capabilities * Fix equalizer failing to serialize * forgot an await, oops * Reorder player_manager funcs * Fix docs & expand parameter names * Update Lavalink URL * Fix Python 3.5 support not displayed in badge (#109) lol * Update example to use voice client (#116) * Update example to use voice client discord.py 2.0 removed the `on_socket_response` event. This resulted in Lavalink.py not being able to forward the events. At least in the current implementation of the example. We now use the preferred way of using the VoiceProtocol to forward the voice events to Lavalink. * Set player.channel_id to None manually * support new lavalink exception format (#105) * Bump min aiohttp version * Update copyright * who did this * Update license 2 * Making a note of this issue * Bump aiohttp upper version * Slight adjustments to strings * Expose previously unused variables 'position' and 'encoder_version' * Clarify some units in Stats.py * Logging message consistency * Remove superfluous log call in _node_disconnect * Logging consistency * Init node with empty stats object * scheisse * Redundant logic check as this will be zero anyway * int() guild_id in create, add doc link to DefaultPlayer * Doc consistency in playermanager.py * Document player.channel_id attr * More documentation updates * Finalise guild_id -> int change * Lavalink.py v4.0.0 * 0.0 is the default gain * Add timestamp_to_millis helper function. * Linting * Register auto docs for new things * Minor docs changes again * How much other stuff is missing??? * cmon * Fixing docs build error * Add filter limits, allow passing str to Player.X_filter, add filter TODOs * Fix docs formatting * Add missing list call * Avoid handling TrackStartEvent to prevent None being fired * Rotation filter * Low Pass filter * Add channelmix + lint * Add missing __ to init * Add filter command to example cog. * Lavalink appears to have exception handling for this... * Mark set_gain(s) & reset_equalizer as deprecated, add docs for remove_filter. * Enlarge deprecation warning * Move deprecation warning last to ensure func summary still works as intended * Distortion filter * Lint * New year new me xx * doc stuff * forgot to cd out of docs/ * update readme badge * Support volume filter * Enforce 0 < volume < 5 * Support connected in PlayerUpdateEvent * Linting * Small cleanups * new codacy badge * Implement DeferredAudioTrack * Linting * Imports & docs * Custom source support * Implement hash for source * Implement handling for info attribute access in AudioTrack * More docstrings, a little more consistency * Clarify docs. * Adjust player.add parameters, docs * Fix an issue with track needing to be declared, improve compatibility * Oversight * Implement two more docstrings in Client. * Custom Source provider example * If check to avoid returning bogus track on every query. * Enum documentation * missing , * self._raw in AudioTrack * slotssssssss * lets gloss over this ok * Copy-paste RIP * Fix typo in custom_source.py * Add player.destroy shortcut * Reluctantly support passing AudioTrack to AudioTrack * Don't overwrite requester * Remove AudioTrack construction from example cog * Access attributes directly in example cog * Filter descriptions. * an -> a * Support position + sourceName fields * Correctly reflect that track is Optional * Close any existing websockets before connecting * support volume + pause in play op * Fix volume not having an immediate effect * Add @lavalink.listener decorator support * Clarify listener decorator * forgot to cd out of docs again lol * Add player.update_filter, improve docs * Ensure provided filter is a class not instance * Instances passed to issubclass will throw, catch that. * subclass check in other x_filter commands * Add custom source to README * Updating readme * Reducing duplicated code in client * Fixing a slight oversight * Sorting out comment lines a little lol * Remove unused import from example/music.py * Experimental command-line tools * Support SSL on nodes * Use pythonic naming * Add clear_filters() * Only apply endTime if > 0 * On second thoughts, move endTime check AFTER sanity check Co-authored-by: AlexFlipnote <[email protected]> Co-authored-by: sh0tx420 <[email protected]> Co-authored-by: Eric Schneider <[email protected]> Co-authored-by: Rob Wainwright <[email protected]>
1 parent 9b5e659 commit b2542cf

26 files changed

+2006
-437
lines changed

README.md

+16-8
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,25 @@
1+
[Lavalink]: https://github.com/freyacodes/Lavalink
2+
[Documentation]: https://lavalink.readthedocs.io/en/master/
3+
[Latest Docs]: https://lavalink.readthedocs.io/en/latest/
4+
15
<img align="right" src="https://serux.pro/9e83af1581.png" height="150" width="150">
26

37
# Lavalink.py
4-
[![Python](https://img.shields.io/badge/Python-3.6%20%7C%203.7%20%7C%203.8-blue.svg)](https://www.python.org) [![Build Status](https://travis-ci.com/devoxin/Lavalink.py.svg?branch=master)](https://travis-ci.com/Devoxin/Lavalink.py) [![Codacy Badge](https://api.codacy.com/project/badge/Grade/5f4c2517818042c593c57f911ff61062)](https://www.codacy.com/manual/Devoxin/Lavalink.py?utm_source=github.com&amp;utm_medium=referral&amp;utm_content=Devoxin/Lavalink.py&amp;utm_campaign=Badge_Grade) [![License](https://img.shields.io/github/license/Devoxin/Lavalink.py.svg)](LICENSE) [![Documentation Status](https://readthedocs.org/projects/lavalink/badge/?version=latest)](https://lavalink.readthedocs.io/en/latest/?badge=latest)
8+
[![Python](https://img.shields.io/badge/Python-3.5%20%7C%203.6%20%7C%203.7%20%7C%203.8%20%7C%203.9%20%7C%203.10-blue.svg)](https://www.python.org) [![Build Status](https://travis-ci.com/devoxin/Lavalink.py.svg?branch=master)](https://travis-ci.com/Devoxin/Lavalink.py) [![Codacy Badge](https://app.codacy.com/project/badge/Grade/428eebed5a2e467fb038eacfa1d92e62)](https://www.codacy.com/gh/Devoxin/Lavalink.py/dashboard?utm_source=github.com&amp;utm_medium=referral&amp;utm_content=Devoxin/Lavalink.py&amp;utm_campaign=Badge_Grade) [![License](https://img.shields.io/github/license/Devoxin/Lavalink.py.svg)](LICENSE) [![Documentation Status](https://readthedocs.org/projects/lavalink/badge/?version=latest)](https://lavalink.readthedocs.io/en/latest/?badge=latest)
9+
10+
Lavalink.py is a wrapper for [Lavalink] which abstracts away most of the code necessary to use Lavalink, allowing for easier integration into your projects, while still promising full API coverage and powerful tools to get the most out of it.
511

6-
Lavalink.py is a wrapper for [Lavalink](https://github.com/Frederikam/Lavalink) which abstracts away most of the code necessary to use Lavalink, allowing for easier integration into your projects, while still promising full API coverage and powerful tools to get the most out of it.
12+
# What is Lavalink?
13+
Lavalink is standalone audio sending software capable of transmitting audio to Discord, utilising Lavaplayer for audio transcoding. It can be configured to work independently, or as part of a cluster depending on needs, which allows it to be highly scalable and performant. Head over to the [Lavalink] repository to find out more.
714

815
# Getting Started
916
First you need to run a command to install the library,
1017
```shell
1118
pip install lavalink
1219
```
1320

14-
Then you need to setup the Lavalink server, you will need to install Java, and then download the latest [Lavalink.jar](https://github.com/Frederikam/Lavalink/releases/).
15-
Then place an ``application.yml`` file in the same directory. The file should look like [this](https://github.com/Frederikam/Lavalink/blob/master/LavalinkServer/application.yml.example/). Finally run `java -jar Lavalink.jar` in the directory of the jar.
21+
Then you need to setup the Lavalink server, you will need to install Java, and then download the latest [Lavalink.jar](https://github.com/freyacodes/Lavalink/releases/).
22+
Then place an ``application.yml`` file in the same directory. The file should look like [this](https://github.com/freyacodes/Lavalink/blob/master/LavalinkServer/application.yml.example/). Finally run `java -jar Lavalink.jar` in the directory of the jar.
1623

1724
Additionally, there is an [example cog](examples). It should be noted that the example cog is oriented towards usage with Discord.py rewrite and Lavalink v3.1+, although backwards
1825
compatibility may be possible, it's not encouraged nor is support guaranteed.
@@ -21,7 +28,8 @@ compatibility may be possible, it's not encouraged nor is support guaranteed.
2128
- Regions
2229
- Multi-Node Support
2330
- Load Balancing (this includes region-based load balancing)
24-
- Equalizer
31+
- Audio Filters
32+
- [Custom Sources](examples/custom_source.py)
2533

2634
## Optional Dependencies
2735
*These are used by aiohttp.*
@@ -39,7 +47,7 @@ It is highly recommended that you invest in a dedicated server or a [VPS](https:
3947
The exception to the "unsupported platforms" rule are ARM-based machines, for example; a Raspberry Pi. While official Lavalink builds do not support the ARM architecture, there are [custom builds by Cog-Creators](https://github.com/Cog-Creators/Lavalink-Jars/releases) that offer ARM support. These are the official builds, with additional native libraries for running on otherwise unsupported platforms.
4048

4149

42-
## Need Further Help?
43-
[Discord Server](https://discord.gg/SbJXU9s)
50+
## Need Further Help?
51+
[Discord Server](https://discord.gg/SbJXU9s)
4452

45-
[Documentation](https://lavalink.readthedocs.io/en/latest/)
53+
[Documentation] or [Latest Docs] (for Lavalink.py 4.0)

docs/_static/style.css

+20-2
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,23 @@
1515
}
1616

1717
code {
18-
padding: 0px; !important
19-
}
18+
padding: 0px !important;
19+
}
20+
21+
div.deprecated {
22+
margin: 20px 0;
23+
padding: 20px;
24+
background-color: #fff;
25+
border-radius: 3px;
26+
color: #333;
27+
overflow: auto;
28+
border-width: 0 0 0 2px;
29+
border-color: #ff5858;
30+
border-style: solid;
31+
padding-right: 0;
32+
}
33+
34+
span.deprecated {
35+
display: block;
36+
font-size: large;
37+
}

docs/conf.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
# -- Project information -----------------------------------------------------
2020

2121
project = 'Lavalink.py'
22-
copyright = '2020, Devoxin'
22+
copyright = '2022, Devoxin'
2323
author = 'Devoxin'
2424
master_doc = 'index'
2525

@@ -41,6 +41,7 @@
4141
'sphinx.ext.autodoc',
4242
'sphinx.ext.napoleon',
4343
'guzzle_sphinx_theme',
44+
'enum_tools.autoenum'
4445
]
4546

4647
rst_prolog = """
@@ -88,6 +89,7 @@
8889
# relative to this directory. They are copied after the builtin static files,
8990
# so a file named "default.css" will overwrite the builtin "default.css".
9091
html_static_path = ['_static']
92+
html_css_files = ['style.css']
9193

9294
# html_context = {
9395
# 'css_files': ['_static/style.css']

docs/index.rst

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@ Welcome to Lavalink.py's documentation!
1717

1818
\
1919
Lavalink.py is a wrapper for which `Lavalink
20-
<https://github.com/Frederikam/Lavalink/>`_ abstracts away most of the code necessary to use Lavalink to allow for easier integration into your bots, while still promising full API coverage and powerful tools to get the most out of it.
20+
<https://github.com/freyacodes/Lavalink/>`_ abstracts away most of the code necessary to use Lavalink to allow for easier integration into your bots, while still promising full API coverage and powerful tools to get the most out of it.
2121

2222
**Features:**
2323

2424
- Regions
2525
- Multi-Node Support
2626
- Load Balancing (this includes region-based load balancing)
27-
- Equalizer
27+
- Audio Filters
2828

2929
**Support:**
3030

@@ -33,4 +33,4 @@ Welcome to Lavalink.py's documentation!
3333

3434
:ref:`genindex`
3535

36-
:ref:`search`
36+
:ref:`search`

docs/lavalink.rst

+70-6
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,23 @@ Documentation
55

66
.. autofunction:: enable_debug_logging
77

8+
.. autofunction:: listener
9+
810
.. autofunction:: add_event_hook
911

1012
Client
1113
------
1214
.. autoclass:: Client
1315
:members:
1416

17+
Errors
18+
------
19+
.. autoclass:: NodeError
20+
21+
.. autoclass:: AuthenticationError
22+
23+
.. autoclass:: InvalidTrack
24+
1525
Events
1626
------
1727
All Events are derived from :class:`Event`
@@ -22,37 +32,89 @@ All Events are derived from :class:`Event`
2232
.. autoclass:: TrackStartEvent
2333
:members:
2434

25-
.. autoclass:: TrackEndEvent
26-
:members:
27-
2835
.. autoclass:: TrackStuckEvent
2936
:members:
3037

3138
.. autoclass:: TrackExceptionEvent
3239
:members:
3340

41+
.. autoclass:: TrackEndEvent
42+
:members:
43+
3444
.. autoclass:: QueueEndEvent
3545
:members:
3646

37-
.. autoclass:: NodeConnectedEvent
47+
.. autoclass:: PlayerUpdateEvent
3848
:members:
3949

40-
.. autoclass:: NodeChangedEvent
50+
.. autoclass:: NodeConnectedEvent
4151
:members:
4252

4353
.. autoclass:: NodeDisconnectedEvent
4454
:members:
4555

56+
.. autoclass:: NodeChangedEvent
57+
:members:
58+
4659
.. autoclass:: WebSocketClosedEvent
4760
:members:
4861

62+
Filters
63+
-------
64+
**All** custom filters must derive from :class:`Filter`
65+
66+
.. autoclass:: Filter
67+
:members:
68+
69+
.. autoclass:: Equalizer
70+
:members:
71+
72+
.. autoclass:: Karaoke
73+
:members:
74+
75+
.. autoclass:: Timescale
76+
:members:
77+
78+
.. autoclass:: Tremolo
79+
:members:
80+
81+
.. autoclass:: Vibrato
82+
:members:
83+
84+
.. autoclass:: Rotation
85+
:members:
86+
87+
.. autoclass:: LowPass
88+
:members:
89+
90+
.. autoclass:: ChannelMix
91+
:members:
92+
93+
.. autoclass:: Volume
94+
:members:
95+
4996
Models
5097
------
5198
**All** custom players must derive from :class:`BasePlayer`
5299

53100
.. autoclass:: AudioTrack
54101
:members:
55102

103+
.. autoclass:: DeferredAudioTrack
104+
:members:
105+
106+
.. autoenum:: LoadType
107+
:members:
108+
109+
.. autoclass:: PlaylistInfo
110+
:members:
111+
112+
.. autoclass:: LoadResult
113+
:members:
114+
115+
.. autoclass:: Source
116+
:members:
117+
56118
.. autoclass:: BasePlayer
57119
:members:
58120

@@ -84,8 +146,10 @@ Stats
84146

85147
Utilities
86148
---------
149+
.. autofunction:: timestamp_to_millis
150+
87151
.. autofunction:: format_time
88152

89153
.. autofunction:: parse_time
90154

91-
.. autofunction:: decode_track
155+
.. autofunction:: decode_track

docs/license.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Licensed using the `MIT license <http://opensource.org/licenses/MIT>`_.
44

55
MIT License
66

7-
Copyright (c) 2019 Luke & William
7+
Copyright (c) 2022 Devoxin
88

99
Permission is hereby granted, free of charge, to any person obtaining a copy
1010
of this software and associated documentation files (the "Software"), to deal

docs/quickstart.rst

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@ Quickstart
33

44
Setting up Lavalink server
55
--------------------------
6-
Download the latest `Lavalink.jar <https://github.com/Frederikam/Lavalink/releases/>`_
7-
Place an ``application.yml`` file in the same directory. The file should look like `this <https://github.com/Frederikam/Lavalink/blob/master/LavalinkServer/application.yml.example/>`_.
6+
Download the latest `Lavalink.jar <https://github.com/freyacodes/Lavalink/releases/>`_
7+
Place an ``application.yml`` file in the same directory. The file should look like `this <https://github.com/freyacodes/Lavalink/blob/master/LavalinkServer/application.yml.example/>`_.
88

99
Run ``java -jar Lavalink.jar`` in the directory of the jar.
1010

1111
Using Lavalink.py
1212
-----------------
13-
This only applies if you are using the library `Discord.py <https://github.com/Rapptz/discord.py/>`_ and with `Lavalink v3.1+ <https://github.com/Frederikam/Lavalink/releases/>`_
13+
This only applies if you are using the library `Discord.py <https://github.com/Rapptz/discord.py/>`_ and with `Lavalink v3.1+ <https://github.com/freyacodes/Lavalink/releases/>`_
1414
Although backwards compatibility may be possible, it's not encouraged nor is support guaranteed.
1515

1616
Place the `example cog <https://github.com/Devoxin/Lavalink.py/blob/master/examples/music.py>`_ in your cogs folder or anywhere in your bot's file directory.

examples/custom_source.py

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
from lavalink.models import (DeferredAudioTrack, LoadResult, LoadType,
2+
PlaylistInfo, Source)
3+
4+
5+
class LoadError(Exception): # We'll raise this if we have trouble loading our track.
6+
pass
7+
8+
9+
class CustomAudioTrack(DeferredAudioTrack):
10+
# A DeferredAudioTrack allows us to load metadata now, and a playback URL later.
11+
# This makes the DeferredAudioTrack highly efficient, particularly in cases
12+
# where large playlists are loaded.
13+
14+
async def load(self, client): # Load our 'actual' playback track using the metadata from this one.
15+
result: LoadResult = await client.get_tracks('ytsearch:{0.title} {0.author}'.format(self)) # Search for our track on YouTube.
16+
17+
if result.load_type != LoadType.SEARCH or not result.tracks: # We're expecting a 'SEARCH' due to our 'ytsearch' prefix above.
18+
raise LoadError
19+
20+
first_track = result.tracks[0] # Grab the first track from the results.
21+
base64 = first_track.track # Extract the base64 string from the track.
22+
self.track = base64 # We'll store this for later, as it allows us to save making network requests
23+
# if this track is re-used (e.g. repeat).
24+
25+
return base64
26+
27+
28+
class CustomSource(Source):
29+
def __init__(self):
30+
super().__init__(name='custom') # Initialising our custom source with the name 'custom'.
31+
32+
async def load_item(self, client, query: str):
33+
if 'keyword' in query:
34+
# track_metadata = http.get("https://our.provider/api/{}".format(query))
35+
36+
track = CustomAudioTrack({ # Create an instance of our CustomAudioTrack.
37+
'identifier': '27cgqh0VRhVeM61ugTnorD', # Fill it with metadata that we've obtained from our source's provider.
38+
'isSeekable': True,
39+
'author': 'DJ Seinfeld',
40+
'length': 296000,
41+
'isStream': False,
42+
'title': 'These Things Will Come To Be',
43+
'uri': 'https://open.spotify.com/track/27cgqh0VRhVeM61ugTnorD'
44+
}, requester=0) # Init requester with a default value.
45+
return LoadResult(LoadType.TRACK, [track], playlist_info=PlaylistInfo.none())

0 commit comments

Comments
 (0)