A YouTube Music Discord Rich-Presence App utilizing PyPresence and BeautifulSoup
-
Go to Discord Developer Portal
-
Create a new application
-
Get your Application ID
-
Create a new environment variable named
"MELODY_RPC_APP_ID"
and add the Application ID as the value. -
Python version
3.10 or higher
is required. ForLinux (aarch64)
, skip to this section -
Install the dependencies:
# Append `pyobjc` for MacOS pip install pyinstaller requests-html lxml numpy dearpygui beautifulsoup4 pypresence Pillow
Continue onto Building
Build & Install the application:
# Use in root directory
pyinstaller -n melody --windowed --icon=assets/dmi.ico -F src/mel.py
If the build fails, it may be due to the packages not being located. To resolve this, supply the directory of your python site-packages to the paths flag:
# Ex.) --paths=C:/Python311/Lib/site-packages
--paths={PATH_TO_YOUR_PYTHON_LIB_SITE-PACKAGES}
Continue to Setup
Both Discord & Google Chrome do not support Linux (aarch64)
, opt for their alternatives:
- ArmCord
- Chromium
Some of the dependencies are not supported in python 3.11
for this platform,
use pyenv
to get a python version between 3.10
& 3.10.11
to install these packages.
Create a new python virtual environment:
python3.10 -m venv ~/{DIRECTORY_NAME}/
Build dearpygui
wheel from source as it lacks a package for this platform:
-
Install the wheel package:
pip3.10 install wheel
-
Build
dearpygui
from source:-
Get the repository:
git clone --recursive https://github.com/hoffstadt/DearPyGui && cd DearPyGui
-
Install the necessary libs:
sudo apt install -y cmake libglu1-mesa-dev libgl1-mesa-dev \ libxrandr-dev libxinerama-dev libxcursor-dev libxi-dev
-
Build the wheel:
python3.10 -m setup bdist_wheel --dist-dir {OUTPUT_DIST_DIRECTORY}
-
Install the package:
pip3.10 install {OUTPUT_DIST_DIRECTORY}/dearpygui-1.9.2-cp310-cp310-linux_aarch64.whl
-
Important
The application requires requests-html
to work.
The chromium that comes with the package doesn't support aarch64.
To fix this, requests_html.py
will need to be modified:
- Add
"executablePath="/snap/bin/chromium"
or the directory of your chromium executable as the first argument topyppteer.launch()
in thebrowser
property inBaseSession
Setup Discord IPC:
mkdir -p ~/.config/user-tmpfiles.d
echo 'L %t/discord-ipc-0 - - - - .flatpak/xyz.armcord.ArmCord/xdg-run/discord-ipc-0' > \
~/.config/user-tmpfiles.d/discord-rpc.conf
systemctl --user enable --now systemd-tmpfiles-setup.service
Build & Install the application:
# Using pyinstaller package from python virtual environment bin
./pyinstaller -n melody --windowed -F ~/Melody/src/mel.py \
--distpath=~/Melody/dist/ --specpath=~/Melody/ --workpath=~/Melody/build/
Continue to Setup
- Unzip the
assets
directory into thedist
output directory - Open YouTube Music and Rich Presence will showcase what you're listening to!
-
Firefox & LibreWolf in MacOS/Linux update the history database infrequently, the current song shown will be inaccurate
- Test cases that make browser update the history database:
- Search then close tab
- Close browser
- Test cases that make browser update the history database:
-
Rich Presence only updates once every 15 seconds (per Discord API limit)
-
Prefer to close the application normally instead of using the quit button (both do the same thing, dearpygui framework limitation)
- If you decide to use the quit button, wait 5 seconds before closing the application
-
If there is no album title found, the song's title will be used as the album title
-
If 11 URLs are visited, the application will assume you have paused the media session, you will need to reload the tab or select another song
-
Currently, the application does not check if discord is closed (should this happen, you will need to close the chromium instances created by the application)
Background photo by Agata Ciosek on Unsplash
Icons by: