Coder Social home page Coder Social logo

melody's Introduction

Melody Banner

Melody


Description

A YouTube Music Discord Rich-Presence App utilizing PyPresence and BeautifulSoup

Examples

Melody App Example

Prerequisites

  1. Go to Discord Developer Portal

  2. Create a new application

  3. Get your Application ID

  4. Create a new environment variable named "MELODY_RPC_APP_ID" and add the Application ID as the value.

  5. Python version 3.10 or higher is required. For Linux (aarch64), skip to this section

  6. Install the dependencies:

    # Append `pyobjc` for MacOS
    pip install pyinstaller requests-html lxml numpy dearpygui beautifulsoup4 pypresence Pillow

Continue onto Building

Building

Windows/MacOS

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

Linux (aarch64)

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:

  1. Install the wheel package:

    pip3.10 install wheel
  2. Build dearpygui from source:

    1. Get the repository:

      git clone --recursive https://github.com/hoffstadt/DearPyGui && cd DearPyGui
    2. Install the necessary libs:

      sudo apt install -y cmake libglu1-mesa-dev libgl1-mesa-dev \
      libxrandr-dev libxinerama-dev libxcursor-dev libxi-dev
    3. Build the wheel:

      python3.10 -m setup bdist_wheel --dist-dir {OUTPUT_DIST_DIRECTORY}
    4. 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 to pyppteer.launch() in the browser property in BaseSession

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

Setup Melody

  1. Unzip the assets directory into the dist output directory
  2. Open YouTube Music and Rich Presence will showcase what you're listening to!

Important Additional Info

  • 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
  • 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)

Acknowledgements

Background photo by Agata Ciosek on Unsplash

Icons by:

melody's People

Contributors

inohime avatar

Stargazers

 avatar

Watchers

 avatar  avatar

melody's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.