distube 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- distube-0.1.0/.gitignore +34 -0
- distube-0.1.0/LICENSE +25 -0
- distube-0.1.0/PKG-INFO +357 -0
- distube-0.1.0/README.md +288 -0
- distube-0.1.0/examples/README.md +62 -0
- distube-0.1.0/examples/basic_bot.py +235 -0
- distube-0.1.0/pyproject.toml +74 -0
- distube-0.1.0/src/distube/__init__.py +64 -0
- distube-0.1.0/src/distube/compat/__init__.py +3 -0
- distube-0.1.0/src/distube/compat/dave.py +304 -0
- distube-0.1.0/src/distube/core/__init__.py +4 -0
- distube-0.1.0/src/distube/core/handler.py +144 -0
- distube-0.1.0/src/distube/core/task_queue.py +53 -0
- distube-0.1.0/src/distube/distube.py +198 -0
- distube-0.1.0/src/distube/enums.py +19 -0
- distube-0.1.0/src/distube/errors.py +90 -0
- distube-0.1.0/src/distube/events.py +19 -0
- distube-0.1.0/src/distube/managers/__init__.py +15 -0
- distube-0.1.0/src/distube/managers/base.py +44 -0
- distube-0.1.0/src/distube/managers/filter.py +91 -0
- distube-0.1.0/src/distube/managers/queue.py +141 -0
- distube-0.1.0/src/distube/managers/voice.py +31 -0
- distube-0.1.0/src/distube/models/__init__.py +5 -0
- distube-0.1.0/src/distube/models/playlist.py +77 -0
- distube-0.1.0/src/distube/models/queue.py +301 -0
- distube-0.1.0/src/distube/models/song.py +96 -0
- distube-0.1.0/src/distube/options.py +146 -0
- distube-0.1.0/src/distube/plugins/__init__.py +10 -0
- distube-0.1.0/src/distube/plugins/base.py +88 -0
- distube-0.1.0/src/distube/plugins/yt_dlp.py +175 -0
- distube-0.1.0/src/distube/py.typed +0 -0
- distube-0.1.0/src/distube/utils.py +75 -0
- distube-0.1.0/src/distube/voice/__init__.py +4 -0
- distube-0.1.0/src/distube/voice/adapter.py +299 -0
- distube-0.1.0/src/distube/voice/protocols.py +39 -0
- distube-0.1.0/tests/test_core.py +303 -0
- distube-0.1.0/tests/test_dave_compat.py +81 -0
- distube-0.1.0/tests/test_models.py +64 -0
- distube-0.1.0/tests/test_options.py +31 -0
- distube-0.1.0/tests/test_plugins.py +34 -0
- distube-0.1.0/tests/test_utils.py +34 -0
- distube-0.1.0/tests/test_yt_dlp_plugin.py +195 -0
distube-0.1.0/.gitignore
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# Python
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
*.pyd
|
|
5
|
+
*.so
|
|
6
|
+
.pytest_cache/
|
|
7
|
+
.ruff_cache/
|
|
8
|
+
.mypy_cache/
|
|
9
|
+
.coverage
|
|
10
|
+
htmlcov/
|
|
11
|
+
|
|
12
|
+
# Virtual environments
|
|
13
|
+
.venv/
|
|
14
|
+
venv/
|
|
15
|
+
env/
|
|
16
|
+
|
|
17
|
+
# Packaging
|
|
18
|
+
build/
|
|
19
|
+
dist/
|
|
20
|
+
*.egg-info/
|
|
21
|
+
|
|
22
|
+
# Secrets and local configuration
|
|
23
|
+
.env
|
|
24
|
+
.env.*
|
|
25
|
+
!.env.example
|
|
26
|
+
|
|
27
|
+
# Logs
|
|
28
|
+
*.log
|
|
29
|
+
|
|
30
|
+
# IDE / OS
|
|
31
|
+
.vscode/
|
|
32
|
+
.idea/
|
|
33
|
+
.DS_Store
|
|
34
|
+
Thumbs.db
|
distube-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2020 Skick and the DisTube contributors
|
|
4
|
+
Copyright (c) 2026 DisTube-Python contributors
|
|
5
|
+
|
|
6
|
+
This project is a Python port derived from the original DisTube project:
|
|
7
|
+
https://github.com/skick1234/DisTube
|
|
8
|
+
|
|
9
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
10
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
11
|
+
in the Software without restriction, including without limitation the rights
|
|
12
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
13
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
14
|
+
furnished to do so, subject to the following conditions:
|
|
15
|
+
|
|
16
|
+
The above copyright notice and this permission notice shall be included in all
|
|
17
|
+
copies or substantial portions of the Software.
|
|
18
|
+
|
|
19
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
20
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
21
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
22
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
23
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
24
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
25
|
+
SOFTWARE.
|
distube-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,357 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: distube
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Asynchronous Discord music framework with queues, events, filters, and yt-dlp support
|
|
5
|
+
Project-URL: Homepage, https://github.com/ChillatoOfficial/distube.py
|
|
6
|
+
Project-URL: Documentation, https://github.com/ChillatoOfficial/distube.py#readme
|
|
7
|
+
Project-URL: Repository, https://github.com/ChillatoOfficial/distube.py
|
|
8
|
+
Project-URL: Issues, https://github.com/ChillatoOfficial/distube.py/issues
|
|
9
|
+
Author: ChillatoOfficial
|
|
10
|
+
License: MIT License
|
|
11
|
+
|
|
12
|
+
Copyright (c) 2020 Skick and the DisTube contributors
|
|
13
|
+
Copyright (c) 2026 DisTube-Python contributors
|
|
14
|
+
|
|
15
|
+
This project is a Python port derived from the original DisTube project:
|
|
16
|
+
https://github.com/skick1234/DisTube
|
|
17
|
+
|
|
18
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
19
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
20
|
+
in the Software without restriction, including without limitation the rights
|
|
21
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
22
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
23
|
+
furnished to do so, subject to the following conditions:
|
|
24
|
+
|
|
25
|
+
The above copyright notice and this permission notice shall be included in all
|
|
26
|
+
copies or substantial portions of the Software.
|
|
27
|
+
|
|
28
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
29
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
30
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
31
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
32
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
33
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
34
|
+
SOFTWARE.
|
|
35
|
+
License-File: LICENSE
|
|
36
|
+
Keywords: asyncio,bot,discord,distube,ffmpeg,music,yt-dlp
|
|
37
|
+
Classifier: Development Status :: 3 - Alpha
|
|
38
|
+
Classifier: Framework :: AsyncIO
|
|
39
|
+
Classifier: Intended Audience :: Developers
|
|
40
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
41
|
+
Classifier: Operating System :: OS Independent
|
|
42
|
+
Classifier: Programming Language :: Python :: 3
|
|
43
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
44
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
45
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
46
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
47
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
48
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
49
|
+
Classifier: Programming Language :: Python :: 3.15
|
|
50
|
+
Classifier: Topic :: Multimedia :: Sound/Audio :: Players
|
|
51
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
52
|
+
Classifier: Typing :: Typed
|
|
53
|
+
Requires-Python: >=3.10
|
|
54
|
+
Provides-Extra: discord-py
|
|
55
|
+
Requires-Dist: davey>=0.2.0; extra == 'discord-py'
|
|
56
|
+
Requires-Dist: discord-py[voice]<2.8,>=2.7.1; extra == 'discord-py'
|
|
57
|
+
Provides-Extra: disnake
|
|
58
|
+
Requires-Dist: disnake[voice]>=2.9; extra == 'disnake'
|
|
59
|
+
Provides-Extra: nextcord
|
|
60
|
+
Requires-Dist: nextcord[voice]>=2.6; extra == 'nextcord'
|
|
61
|
+
Provides-Extra: py-cord
|
|
62
|
+
Requires-Dist: py-cord[voice]>=2.4; extra == 'py-cord'
|
|
63
|
+
Provides-Extra: test
|
|
64
|
+
Requires-Dist: pytest-asyncio>=0.23; extra == 'test'
|
|
65
|
+
Requires-Dist: pytest>=8.0; extra == 'test'
|
|
66
|
+
Provides-Extra: yt-dlp
|
|
67
|
+
Requires-Dist: yt-dlp>=2024.1.1; extra == 'yt-dlp'
|
|
68
|
+
Description-Content-Type: text/markdown
|
|
69
|
+
|
|
70
|
+
# DisTube.py
|
|
71
|
+
|
|
72
|
+
[](https://pypi.org/project/distube/)
|
|
73
|
+
[](https://pypi.org/project/distube/)
|
|
74
|
+
[](LICENSE)
|
|
75
|
+
|
|
76
|
+
Framework asincrono per creare bot musicali Discord in Python, ispirato a [DisTube](https://github.com/skick1234/DisTube), con queue, eventi, filtri FFmpeg e supporto `yt-dlp`.
|
|
77
|
+
|
|
78
|
+
> **Stato:** release iniziale alpha. Prima di usarla in produzione, verifica il comportamento con il fork Discord scelto.
|
|
79
|
+
|
|
80
|
+
## Installazione
|
|
81
|
+
|
|
82
|
+
Scegli **un solo** fork Discord:
|
|
83
|
+
|
|
84
|
+
```bash
|
|
85
|
+
# discord.py (consigliato)
|
|
86
|
+
python -m pip install "distube[discord-py,yt-dlp]"
|
|
87
|
+
|
|
88
|
+
# oppure Pycord
|
|
89
|
+
python -m pip install "distube[py-cord,yt-dlp]"
|
|
90
|
+
|
|
91
|
+
# oppure Nextcord
|
|
92
|
+
python -m pip install "distube[nextcord,yt-dlp]"
|
|
93
|
+
|
|
94
|
+
# oppure Disnake
|
|
95
|
+
python -m pip install "distube[disnake,yt-dlp]"
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
Serve inoltre [FFmpeg](https://ffmpeg.org/) disponibile nel `PATH`.
|
|
99
|
+
|
|
100
|
+
## Funzionalità
|
|
101
|
+
|
|
102
|
+
- Riproduzione da URL e ricerca testuale tramite `yt-dlp`
|
|
103
|
+
- Video, playlist e numerosi siti supportati da yt-dlp
|
|
104
|
+
- Queue per server
|
|
105
|
+
- Play, pausa, resume, skip, previous, jump, seek e shuffle
|
|
106
|
+
- Repeat song/queue e autoplay
|
|
107
|
+
- Filtri FFmpeg integrati
|
|
108
|
+
- Eventi asincroni
|
|
109
|
+
- Metadata e requester del brano
|
|
110
|
+
- Supporto tramite adapter per discord.py, Pycord, Nextcord e Disnake
|
|
111
|
+
- Patch runtime DAVE per `discord.py 2.7.1` con `davey 0.2.x`
|
|
112
|
+
|
|
113
|
+
## Requisiti
|
|
114
|
+
|
|
115
|
+
- Python 3.10 o superiore (incluso Python 3.15)
|
|
116
|
+
- [FFmpeg](https://ffmpeg.org/) disponibile nel `PATH`
|
|
117
|
+
- Un solo fork Discord installato nell'ambiente
|
|
118
|
+
|
|
119
|
+
Non installare contemporaneamente discord.py, Pycord, Nextcord e Disnake: alcuni condividono il namespace `discord` e possono entrare in conflitto.
|
|
120
|
+
|
|
121
|
+
Per installare la versione di sviluppo direttamente dal repository:
|
|
122
|
+
|
|
123
|
+
```bash
|
|
124
|
+
python -m pip install "distube[discord-py,yt-dlp] @ git+https://github.com/ChillatoOfficial/distube.py.git"
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
## Esempio rapido
|
|
128
|
+
|
|
129
|
+
```python
|
|
130
|
+
import os
|
|
131
|
+
|
|
132
|
+
import discord
|
|
133
|
+
from discord.ext import commands
|
|
134
|
+
|
|
135
|
+
from distube import DisTube, Events, YtDlpPlugin
|
|
136
|
+
|
|
137
|
+
intents = discord.Intents.default()
|
|
138
|
+
intents.message_content = True
|
|
139
|
+
intents.voice_states = True
|
|
140
|
+
|
|
141
|
+
bot = commands.Bot(command_prefix="!", intents=intents)
|
|
142
|
+
player = DisTube(bot, plugins=[YtDlpPlugin()])
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
@bot.command()
|
|
146
|
+
async def play(ctx, *, query: str):
|
|
147
|
+
voice = getattr(ctx.author, "voice", None)
|
|
148
|
+
if voice is None or voice.channel is None:
|
|
149
|
+
await ctx.send("Entra prima in un canale vocale.")
|
|
150
|
+
return
|
|
151
|
+
|
|
152
|
+
await player.play(
|
|
153
|
+
voice.channel,
|
|
154
|
+
query,
|
|
155
|
+
text_channel=ctx.channel,
|
|
156
|
+
member=ctx.author,
|
|
157
|
+
)
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
def require_queue(ctx):
|
|
161
|
+
queue = player.get_queue(ctx.guild)
|
|
162
|
+
if queue is None:
|
|
163
|
+
raise commands.CommandError("Non c'è una coda attiva.")
|
|
164
|
+
return queue
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
@bot.command()
|
|
168
|
+
async def pause(ctx):
|
|
169
|
+
await require_queue(ctx).pause()
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
@bot.command()
|
|
173
|
+
async def resume(ctx):
|
|
174
|
+
await require_queue(ctx).resume()
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
@bot.command()
|
|
178
|
+
async def skip(ctx):
|
|
179
|
+
await require_queue(ctx).skip()
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
@bot.command()
|
|
183
|
+
async def stop(ctx):
|
|
184
|
+
await require_queue(ctx).stop()
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
async def announce_song(queue, song):
|
|
188
|
+
if queue.text_channel is not None:
|
|
189
|
+
await queue.text_channel.send(
|
|
190
|
+
f"▶️ **{song.name}** — `{song.formatted_duration}`\n{song.url}"
|
|
191
|
+
)
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
async def announce_error(error, queue=None, song=None):
|
|
195
|
+
channel = getattr(queue, "text_channel", None)
|
|
196
|
+
if channel is not None:
|
|
197
|
+
await channel.send(f"❌ `{error}`")
|
|
198
|
+
else:
|
|
199
|
+
print(error)
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
player.on(Events.PLAY_SONG, announce_song)
|
|
203
|
+
player.on(Events.ERROR, announce_error)
|
|
204
|
+
|
|
205
|
+
bot.run(os.environ["DISCORD_TOKEN"])
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
Nel Discord Developer Portal abilita il **Message Content Intent** e assegna al bot i permessi **Connetti** e **Parla**.
|
|
209
|
+
|
|
210
|
+
## Oggetto `Song`
|
|
211
|
+
|
|
212
|
+
Il parametro `song` degli eventi come `Events.PLAY_SONG` espone:
|
|
213
|
+
|
|
214
|
+
```python
|
|
215
|
+
song.id
|
|
216
|
+
song.name
|
|
217
|
+
song.url
|
|
218
|
+
song.source
|
|
219
|
+
song.duration
|
|
220
|
+
song.formatted_duration
|
|
221
|
+
song.thumbnail
|
|
222
|
+
song.views
|
|
223
|
+
song.likes
|
|
224
|
+
song.uploader
|
|
225
|
+
song.is_live
|
|
226
|
+
song.age_restricted
|
|
227
|
+
song.member
|
|
228
|
+
song.user
|
|
229
|
+
song.metadata
|
|
230
|
+
song.playlist
|
|
231
|
+
song.plugin
|
|
232
|
+
song.stream
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
Sono disponibili anche gli alias:
|
|
236
|
+
|
|
237
|
+
```python
|
|
238
|
+
song.isLive
|
|
239
|
+
song.formattedDuration
|
|
240
|
+
song.ageRestricted
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
## Queue
|
|
244
|
+
|
|
245
|
+
```python
|
|
246
|
+
queue = player.get_queue(ctx.guild)
|
|
247
|
+
|
|
248
|
+
await queue.pause()
|
|
249
|
+
await queue.resume()
|
|
250
|
+
await queue.skip()
|
|
251
|
+
await queue.previous()
|
|
252
|
+
await queue.seek(60)
|
|
253
|
+
await queue.shuffle()
|
|
254
|
+
await queue.stop()
|
|
255
|
+
|
|
256
|
+
queue.set_volume(75)
|
|
257
|
+
queue.set_repeat_mode()
|
|
258
|
+
queue.toggle_autoplay()
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
La canzone corrente è `queue.songs[0]`.
|
|
262
|
+
|
|
263
|
+
## Filtri
|
|
264
|
+
|
|
265
|
+
```python
|
|
266
|
+
queue.filters.add("bassboost")
|
|
267
|
+
queue.filters.set(["nightcore"])
|
|
268
|
+
queue.filters.remove("nightcore")
|
|
269
|
+
queue.filters.clear()
|
|
270
|
+
```
|
|
271
|
+
|
|
272
|
+
Filtri inclusi:
|
|
273
|
+
|
|
274
|
+
```text
|
|
275
|
+
3d, bassboost, echo, flanger, gate, haas, karaoke, nightcore,
|
|
276
|
+
reverse, vaporwave, mcompand, phaser, tremolo, surround, earwax
|
|
277
|
+
```
|
|
278
|
+
|
|
279
|
+
## Eventi
|
|
280
|
+
|
|
281
|
+
```python
|
|
282
|
+
player.on(Events.ADD_SONG, callback)
|
|
283
|
+
player.on(Events.ADD_LIST, callback)
|
|
284
|
+
player.on(Events.PLAY_SONG, callback)
|
|
285
|
+
player.on(Events.FINISH_SONG, callback)
|
|
286
|
+
player.on(Events.FINISH, callback)
|
|
287
|
+
player.on(Events.ERROR, callback)
|
|
288
|
+
player.on(Events.NO_RELATED, callback)
|
|
289
|
+
player.on(Events.DISCONNECT, callback)
|
|
290
|
+
player.on(Events.DELETE_QUEUE, callback)
|
|
291
|
+
player.on(Events.DEBUG, callback)
|
|
292
|
+
player.on(Events.FFMPEG_DEBUG, callback)
|
|
293
|
+
```
|
|
294
|
+
|
|
295
|
+
Sono disponibili anche `once()` e `off()`.
|
|
296
|
+
|
|
297
|
+
## Plugin yt-dlp
|
|
298
|
+
|
|
299
|
+
```python
|
|
300
|
+
plugin = YtDlpPlugin(
|
|
301
|
+
{
|
|
302
|
+
"cookiefile": "cookies.txt",
|
|
303
|
+
}
|
|
304
|
+
)
|
|
305
|
+
|
|
306
|
+
player = DisTube(bot, plugins=[plugin])
|
|
307
|
+
```
|
|
308
|
+
|
|
309
|
+
Il supporto ai siti dipende da yt-dlp e può cambiare nel tempo. Alcuni servizi richiedono cookie o autenticazione.
|
|
310
|
+
|
|
311
|
+
## DAVE su Discord
|
|
312
|
+
|
|
313
|
+
`discord.py 2.7.1` non gestisce nativamente tutte le nuove API di `davey 0.2.x`. La libreria applica automaticamente una patch runtime basata sulla correzione upstream:
|
|
314
|
+
|
|
315
|
+
https://github.com/Rapptz/discord.py/pull/10548
|
|
316
|
+
|
|
317
|
+
La patch è idempotente, non modifica `site-packages` e viene applicata soltanto alla combinazione interessata.
|
|
318
|
+
|
|
319
|
+
## Esempio completo
|
|
320
|
+
|
|
321
|
+
Vedi [`examples/basic_bot.py`](examples/basic_bot.py).
|
|
322
|
+
|
|
323
|
+
## Sviluppo
|
|
324
|
+
|
|
325
|
+
```bash
|
|
326
|
+
git clone https://github.com/ChillatoOfficial/distube.py.git
|
|
327
|
+
cd distube.py
|
|
328
|
+
python -m pip install -e ".[test,discord-py,yt-dlp]"
|
|
329
|
+
python -m pytest
|
|
330
|
+
```
|
|
331
|
+
|
|
332
|
+
## Pubblicazione
|
|
333
|
+
|
|
334
|
+
Il nome della distribuzione e il package importabile sono entrambi `distube`. Prima di ogni release aggiorna `__version__` in `src/distube/__init__.py`; Hatch usa quel valore anche per il pacchetto PyPI. Poi crea e valida gli artefatti:
|
|
335
|
+
|
|
336
|
+
```bash
|
|
337
|
+
python -m pip install --upgrade build twine
|
|
338
|
+
python -m build
|
|
339
|
+
python -m twine check dist/*
|
|
340
|
+
```
|
|
341
|
+
|
|
342
|
+
Prova prima su TestPyPI; quindi pubblica su PyPI usando un token o Trusted Publishing. Le versioni già caricate non possono essere sostituite.
|
|
343
|
+
|
|
344
|
+
## Sicurezza
|
|
345
|
+
|
|
346
|
+
Non inserire mai il token Discord nel sorgente. Usa una variabile d'ambiente:
|
|
347
|
+
|
|
348
|
+
```cmd
|
|
349
|
+
set DISCORD_TOKEN=IL_TOKEN_DEL_BOT
|
|
350
|
+
python examples\basic_bot.py
|
|
351
|
+
```
|
|
352
|
+
|
|
353
|
+
Se un token viene pubblicato, rigeneralo immediatamente nel Discord Developer Portal.
|
|
354
|
+
|
|
355
|
+
## Licenza
|
|
356
|
+
|
|
357
|
+
MIT. Questo progetto mantiene l'attribuzione al progetto DisTube originale. Consulta [LICENSE](LICENSE).
|
distube-0.1.0/README.md
ADDED
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
# DisTube.py
|
|
2
|
+
|
|
3
|
+
[](https://pypi.org/project/distube/)
|
|
4
|
+
[](https://pypi.org/project/distube/)
|
|
5
|
+
[](LICENSE)
|
|
6
|
+
|
|
7
|
+
Framework asincrono per creare bot musicali Discord in Python, ispirato a [DisTube](https://github.com/skick1234/DisTube), con queue, eventi, filtri FFmpeg e supporto `yt-dlp`.
|
|
8
|
+
|
|
9
|
+
> **Stato:** release iniziale alpha. Prima di usarla in produzione, verifica il comportamento con il fork Discord scelto.
|
|
10
|
+
|
|
11
|
+
## Installazione
|
|
12
|
+
|
|
13
|
+
Scegli **un solo** fork Discord:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
# discord.py (consigliato)
|
|
17
|
+
python -m pip install "distube[discord-py,yt-dlp]"
|
|
18
|
+
|
|
19
|
+
# oppure Pycord
|
|
20
|
+
python -m pip install "distube[py-cord,yt-dlp]"
|
|
21
|
+
|
|
22
|
+
# oppure Nextcord
|
|
23
|
+
python -m pip install "distube[nextcord,yt-dlp]"
|
|
24
|
+
|
|
25
|
+
# oppure Disnake
|
|
26
|
+
python -m pip install "distube[disnake,yt-dlp]"
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Serve inoltre [FFmpeg](https://ffmpeg.org/) disponibile nel `PATH`.
|
|
30
|
+
|
|
31
|
+
## Funzionalità
|
|
32
|
+
|
|
33
|
+
- Riproduzione da URL e ricerca testuale tramite `yt-dlp`
|
|
34
|
+
- Video, playlist e numerosi siti supportati da yt-dlp
|
|
35
|
+
- Queue per server
|
|
36
|
+
- Play, pausa, resume, skip, previous, jump, seek e shuffle
|
|
37
|
+
- Repeat song/queue e autoplay
|
|
38
|
+
- Filtri FFmpeg integrati
|
|
39
|
+
- Eventi asincroni
|
|
40
|
+
- Metadata e requester del brano
|
|
41
|
+
- Supporto tramite adapter per discord.py, Pycord, Nextcord e Disnake
|
|
42
|
+
- Patch runtime DAVE per `discord.py 2.7.1` con `davey 0.2.x`
|
|
43
|
+
|
|
44
|
+
## Requisiti
|
|
45
|
+
|
|
46
|
+
- Python 3.10 o superiore (incluso Python 3.15)
|
|
47
|
+
- [FFmpeg](https://ffmpeg.org/) disponibile nel `PATH`
|
|
48
|
+
- Un solo fork Discord installato nell'ambiente
|
|
49
|
+
|
|
50
|
+
Non installare contemporaneamente discord.py, Pycord, Nextcord e Disnake: alcuni condividono il namespace `discord` e possono entrare in conflitto.
|
|
51
|
+
|
|
52
|
+
Per installare la versione di sviluppo direttamente dal repository:
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
python -m pip install "distube[discord-py,yt-dlp] @ git+https://github.com/ChillatoOfficial/distube.py.git"
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## Esempio rapido
|
|
59
|
+
|
|
60
|
+
```python
|
|
61
|
+
import os
|
|
62
|
+
|
|
63
|
+
import discord
|
|
64
|
+
from discord.ext import commands
|
|
65
|
+
|
|
66
|
+
from distube import DisTube, Events, YtDlpPlugin
|
|
67
|
+
|
|
68
|
+
intents = discord.Intents.default()
|
|
69
|
+
intents.message_content = True
|
|
70
|
+
intents.voice_states = True
|
|
71
|
+
|
|
72
|
+
bot = commands.Bot(command_prefix="!", intents=intents)
|
|
73
|
+
player = DisTube(bot, plugins=[YtDlpPlugin()])
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
@bot.command()
|
|
77
|
+
async def play(ctx, *, query: str):
|
|
78
|
+
voice = getattr(ctx.author, "voice", None)
|
|
79
|
+
if voice is None or voice.channel is None:
|
|
80
|
+
await ctx.send("Entra prima in un canale vocale.")
|
|
81
|
+
return
|
|
82
|
+
|
|
83
|
+
await player.play(
|
|
84
|
+
voice.channel,
|
|
85
|
+
query,
|
|
86
|
+
text_channel=ctx.channel,
|
|
87
|
+
member=ctx.author,
|
|
88
|
+
)
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
def require_queue(ctx):
|
|
92
|
+
queue = player.get_queue(ctx.guild)
|
|
93
|
+
if queue is None:
|
|
94
|
+
raise commands.CommandError("Non c'è una coda attiva.")
|
|
95
|
+
return queue
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
@bot.command()
|
|
99
|
+
async def pause(ctx):
|
|
100
|
+
await require_queue(ctx).pause()
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
@bot.command()
|
|
104
|
+
async def resume(ctx):
|
|
105
|
+
await require_queue(ctx).resume()
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
@bot.command()
|
|
109
|
+
async def skip(ctx):
|
|
110
|
+
await require_queue(ctx).skip()
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
@bot.command()
|
|
114
|
+
async def stop(ctx):
|
|
115
|
+
await require_queue(ctx).stop()
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
async def announce_song(queue, song):
|
|
119
|
+
if queue.text_channel is not None:
|
|
120
|
+
await queue.text_channel.send(
|
|
121
|
+
f"▶️ **{song.name}** — `{song.formatted_duration}`\n{song.url}"
|
|
122
|
+
)
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
async def announce_error(error, queue=None, song=None):
|
|
126
|
+
channel = getattr(queue, "text_channel", None)
|
|
127
|
+
if channel is not None:
|
|
128
|
+
await channel.send(f"❌ `{error}`")
|
|
129
|
+
else:
|
|
130
|
+
print(error)
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
player.on(Events.PLAY_SONG, announce_song)
|
|
134
|
+
player.on(Events.ERROR, announce_error)
|
|
135
|
+
|
|
136
|
+
bot.run(os.environ["DISCORD_TOKEN"])
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
Nel Discord Developer Portal abilita il **Message Content Intent** e assegna al bot i permessi **Connetti** e **Parla**.
|
|
140
|
+
|
|
141
|
+
## Oggetto `Song`
|
|
142
|
+
|
|
143
|
+
Il parametro `song` degli eventi come `Events.PLAY_SONG` espone:
|
|
144
|
+
|
|
145
|
+
```python
|
|
146
|
+
song.id
|
|
147
|
+
song.name
|
|
148
|
+
song.url
|
|
149
|
+
song.source
|
|
150
|
+
song.duration
|
|
151
|
+
song.formatted_duration
|
|
152
|
+
song.thumbnail
|
|
153
|
+
song.views
|
|
154
|
+
song.likes
|
|
155
|
+
song.uploader
|
|
156
|
+
song.is_live
|
|
157
|
+
song.age_restricted
|
|
158
|
+
song.member
|
|
159
|
+
song.user
|
|
160
|
+
song.metadata
|
|
161
|
+
song.playlist
|
|
162
|
+
song.plugin
|
|
163
|
+
song.stream
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
Sono disponibili anche gli alias:
|
|
167
|
+
|
|
168
|
+
```python
|
|
169
|
+
song.isLive
|
|
170
|
+
song.formattedDuration
|
|
171
|
+
song.ageRestricted
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
## Queue
|
|
175
|
+
|
|
176
|
+
```python
|
|
177
|
+
queue = player.get_queue(ctx.guild)
|
|
178
|
+
|
|
179
|
+
await queue.pause()
|
|
180
|
+
await queue.resume()
|
|
181
|
+
await queue.skip()
|
|
182
|
+
await queue.previous()
|
|
183
|
+
await queue.seek(60)
|
|
184
|
+
await queue.shuffle()
|
|
185
|
+
await queue.stop()
|
|
186
|
+
|
|
187
|
+
queue.set_volume(75)
|
|
188
|
+
queue.set_repeat_mode()
|
|
189
|
+
queue.toggle_autoplay()
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
La canzone corrente è `queue.songs[0]`.
|
|
193
|
+
|
|
194
|
+
## Filtri
|
|
195
|
+
|
|
196
|
+
```python
|
|
197
|
+
queue.filters.add("bassboost")
|
|
198
|
+
queue.filters.set(["nightcore"])
|
|
199
|
+
queue.filters.remove("nightcore")
|
|
200
|
+
queue.filters.clear()
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
Filtri inclusi:
|
|
204
|
+
|
|
205
|
+
```text
|
|
206
|
+
3d, bassboost, echo, flanger, gate, haas, karaoke, nightcore,
|
|
207
|
+
reverse, vaporwave, mcompand, phaser, tremolo, surround, earwax
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
## Eventi
|
|
211
|
+
|
|
212
|
+
```python
|
|
213
|
+
player.on(Events.ADD_SONG, callback)
|
|
214
|
+
player.on(Events.ADD_LIST, callback)
|
|
215
|
+
player.on(Events.PLAY_SONG, callback)
|
|
216
|
+
player.on(Events.FINISH_SONG, callback)
|
|
217
|
+
player.on(Events.FINISH, callback)
|
|
218
|
+
player.on(Events.ERROR, callback)
|
|
219
|
+
player.on(Events.NO_RELATED, callback)
|
|
220
|
+
player.on(Events.DISCONNECT, callback)
|
|
221
|
+
player.on(Events.DELETE_QUEUE, callback)
|
|
222
|
+
player.on(Events.DEBUG, callback)
|
|
223
|
+
player.on(Events.FFMPEG_DEBUG, callback)
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
Sono disponibili anche `once()` e `off()`.
|
|
227
|
+
|
|
228
|
+
## Plugin yt-dlp
|
|
229
|
+
|
|
230
|
+
```python
|
|
231
|
+
plugin = YtDlpPlugin(
|
|
232
|
+
{
|
|
233
|
+
"cookiefile": "cookies.txt",
|
|
234
|
+
}
|
|
235
|
+
)
|
|
236
|
+
|
|
237
|
+
player = DisTube(bot, plugins=[plugin])
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
Il supporto ai siti dipende da yt-dlp e può cambiare nel tempo. Alcuni servizi richiedono cookie o autenticazione.
|
|
241
|
+
|
|
242
|
+
## DAVE su Discord
|
|
243
|
+
|
|
244
|
+
`discord.py 2.7.1` non gestisce nativamente tutte le nuove API di `davey 0.2.x`. La libreria applica automaticamente una patch runtime basata sulla correzione upstream:
|
|
245
|
+
|
|
246
|
+
https://github.com/Rapptz/discord.py/pull/10548
|
|
247
|
+
|
|
248
|
+
La patch è idempotente, non modifica `site-packages` e viene applicata soltanto alla combinazione interessata.
|
|
249
|
+
|
|
250
|
+
## Esempio completo
|
|
251
|
+
|
|
252
|
+
Vedi [`examples/basic_bot.py`](examples/basic_bot.py).
|
|
253
|
+
|
|
254
|
+
## Sviluppo
|
|
255
|
+
|
|
256
|
+
```bash
|
|
257
|
+
git clone https://github.com/ChillatoOfficial/distube.py.git
|
|
258
|
+
cd distube.py
|
|
259
|
+
python -m pip install -e ".[test,discord-py,yt-dlp]"
|
|
260
|
+
python -m pytest
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
## Pubblicazione
|
|
264
|
+
|
|
265
|
+
Il nome della distribuzione e il package importabile sono entrambi `distube`. Prima di ogni release aggiorna `__version__` in `src/distube/__init__.py`; Hatch usa quel valore anche per il pacchetto PyPI. Poi crea e valida gli artefatti:
|
|
266
|
+
|
|
267
|
+
```bash
|
|
268
|
+
python -m pip install --upgrade build twine
|
|
269
|
+
python -m build
|
|
270
|
+
python -m twine check dist/*
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
Prova prima su TestPyPI; quindi pubblica su PyPI usando un token o Trusted Publishing. Le versioni già caricate non possono essere sostituite.
|
|
274
|
+
|
|
275
|
+
## Sicurezza
|
|
276
|
+
|
|
277
|
+
Non inserire mai il token Discord nel sorgente. Usa una variabile d'ambiente:
|
|
278
|
+
|
|
279
|
+
```cmd
|
|
280
|
+
set DISCORD_TOKEN=IL_TOKEN_DEL_BOT
|
|
281
|
+
python examples\basic_bot.py
|
|
282
|
+
```
|
|
283
|
+
|
|
284
|
+
Se un token viene pubblicato, rigeneralo immediatamente nel Discord Developer Portal.
|
|
285
|
+
|
|
286
|
+
## Licenza
|
|
287
|
+
|
|
288
|
+
MIT. Questo progetto mantiene l'attribuzione al progetto DisTube originale. Consulta [LICENSE](LICENSE).
|