Playlist¶
New in version 2.0.0.
This cog adds the possibility to have as many playlists per user as you want. It is compatible with the Music cog; see below for commands.
Hint
To enable this cog, set the ENABLE_PLAYLISTS variable.
Requirements¶
Packages¶
The
asyncpgpackage:
python3 -m install -U asyncpg
py -m pip install -U asyncpg
The
yt-dlppackage:
python3 -m install -U yt-dlp
py -m pip install -U yt-dlp
env variables¶
The DB_MUSIC variables.
These are used by the MusicDatabaseConnection class to connect to the database containing the playlists.
Creating the database¶
This cog uses PostgreSQL, a “powerful, open source object-relational database system”. Its documentation is quite detailed, don’t hesitate to check it out when in doubt.
A quick guide on setting up PostgreSQL can be found at https://pimylifeup.com/raspberry-pi-postgresql/.
For this cog, the steps to follow are:
Install PostgreSQL: check its downloads page. If you haven’t installed PostgreSQL before, I recommend using version 13 since it’s the one I used to develop this cog.
Switch to user
postgreswith:sudo su postgres
Create a new role. You can use any username you want. Use the command:
createuser <username> -P -D -R -S
This creates a role named username. It requires creating a password (
-P). The role cannot create databases (-D), roles (-R) and won’t be a superuser (-S).Launch the CLI with the
psqlcommand (while still connected as userpostgres).Create the database. You can use any name (except
songs,playlistsorsongs_in_playliststo avoid any confusion). You can name itmusicfor example. Use the command:CREATE DATABASE <name> OWNER <username>;
Where
usernameis the name of the user created in step 3.You can now exit the CLI with
\qand return to your usual user withexit.Set the
.envvariables starting withDB_MUSIC:HOSTshould belocalhost.USERis the name of the user you created in step 3.PASSWORDis that user’s password.DATABASEis the name of the database (musicin the example).PORTis the port used to connect to the database. By default, its 5432.
Once the variables are set, use the
db_setup.pyscript to create the tables needed by the cog:
python3 db_setup.py
py db_setup.py
That should be it. :)
Important
If you turn off or reset the computer in which the bot is running, you may need to restart the database server.
Use the command sudo service postgresql start to do so.
Music cog¶
As the Favourites cog, this cog has two commands that use the Music cog:
nowadds the currently playing song to the default ‘favourites’ list or one specified by the user.playqueues a playlist or a specific song from a playlist.
It also uses the YTDLSource class that comes in the Music cog to generate the Song to save with add.
This does not require enabling the Music cog in order to work.
yt-dlp¶
This package is used to verify the URL passed to this cog is a valid Youtube URL.