Code Monkey home page Code Monkey logo

discord-np's Introduction

Discord Now Playing

GitHub GitHub release (latest by date)

This script will update your Discord "Listening to" status with whatever you are listening to according to Last.FM

Discord Screenshot GitHub release (latest by date)

Setup will take a few minutes and requires two main things:

1. Last.FM API Key

Head over to the Last.FM API Page and sign in with your existing Last.FM username and password. It should bring you to the Create API account page and ask you for a few things.

It doesn't really matter what you put in most of the fields, but it should probably look something like this:

LastFM Create API Account Screenshot

After clicking Submit you should get a confirmation page with two items: API Key and Shared Secret. The API Key is the only one you need for this, but I recommend you save both for future use just in case, as they don't actually provide a way to retrieve these later.

LastFM API Account Created Screenshot

Copy and paste the API Key value into the config file in the api_key = xxx line

2. Discord User Token

For this one you'll need to use the Desktop or Web app - it will not work on mobile.

WARNING: Anyone who knows your Discord token has FULL ACCESS to your account. Do not share it with anyone! You should read this application's source code for yourself and make sure you trust it before inputting your token.

If you still want to proceed, head over to https://discordhelp.net/discord-token and follow the instructions there.

When you're done

Save your config file as "config.ini" and it should look something like this:

Finished Config File

Now just run the executable. It should connect to Discord and immediately start setting your "Playing" status to whatever you're listening to on Last.FM

If it's working, it will look something like this:

Running Executable

Run from Source

If you want to contribute to the code or just prefer to run the raw perl script instead of my packaged executable, you can do that too.

Linux, MacOS

Install and Configure Perl + cpanminus

Install Perl You should already have Perl. If you don't, you need at least v5.10 -- Install it with your package manager. On MacOS I recommend installing perl from Homebrew instead of system perl. It's probably not necessary for this particular project, but I recommend it in general.

Install cpanminus cpanminus is an excellent tool for managing CPAN modules. Simpler and more powerful than the included CPAN shell. You may be able to install this through your package manager or you can install it with the cpan install cpanminus command. If you go the second route you'll have to go through the CPAN setup, which just asks you a number of questions you can (probably) just hit "Enter" and accept the defaults for every single one.

Configure cpanminus Perl can install modules to the system for all users (which requires sudo) or it can install to your home directory (a "local" lib(rary)) for your user alone. This doesn't require elevated permissions and is generally preferred. But you do need to set up a couple things:

  1. Set up your local lib

You should add the following to either ~/.bash_profile or ~/.zprofile (or if you are using a shell other than bash or zsh, in that shell's profile file). Remember to replace "username" with your own username. Use your favorite text editor.

export PERL_MB_OPT='--install_base /home/username/perl5'
export PERL_MM_OPT='INSTALL_BASE=/home/username/perl5'
export PERL5LIB="/home/username/perl5/lib/perl5"
export PATH="/home/username/perl5/bin:$PATH"
export PERL_LOCAL_LIB_ROOT="/home/usename/perl5:$PERL_LOCAL_LIB_ROOT"

Now either restart your terminal or re-source your profile (eg source ~/.zprofile)

  1. Configure cpanminus

You should be able to just run

cpanm --local-lib=~/perl5 local::lib && eval $(perl -I ~/perl5/lib/perl5/ -Mlocal::lib)

If you try to install something with cpanm it will complain and prompt you to do this anyway.

Now anything you install with cpanminus will go to the local lib in ~/perl5 instead of to a system directory.

Install Discord::NP

# Clone the repository
git clone https://github.com/vsTerminus/Discord-NP.git

# Enter the project directory
cd Discord-NP

In the root directory of this project you should see a file called "cpanfile" which contains a list of this project's dependencies. You can point cpanminus at it to install them:

cpanm --installdeps .

This will install everything except for one library:

Install Mojo::Discord

Mojo::Discord is the library required for this application to connect to Discord in the first place. It will go up on CPAN eventually and then you'll be able to install it with cpanm, but it needs more unit tests and documentation first. So for now you'll have to install it manually.

Luckily it's not too difficult:

# Check out the repository
git clone https://github.com/vsTerminus/Mojo-Discord.git

# Enter the project directory
cd Mojo-Discord

# Install Mojo-Discord's dependencies
cpanm --installdeps .

# Manually install Mojo::Discord by creating symlinks inside your local lib
# This way you can update it just by running "git pull" in the future.
ln -s $PWD/Mojo-Discord/lib/Mojo/Discord.pm $PERL5LIB/Mojo/
ln -s $PWD/Mojo-Discord/lib/Mojo/Discord $PERL5LIB/Mojo/

To validate that both modules are installed,

perl -MMojo::Discord -MMojo::WebService::LastFM -e 1

If you don't see any errors then you got it right. Congrats!

Configure the App

Create a copy of the example config file named "config.ini"

cp config.ini.example config.ini

Use your favorite text editor to fill it out as you saw in the first section of this readme.

Run the App

Should be as simple as

perl discordnp.pl

from inside the Discord::NP project folder.

Windows

I recommend installing Strawberry Perl, as it comes with cpanminus already installed.

You need to check out two repositories

Clone each one using git

git clone https://github.com/vsTerminus/Discord-NP.git
git clone https://github.com/vsTerminus/Mojo-Discord.git

Enter each folder and install the dependencies

cd Mojo-Discord
cpanm --installdeps .
cd ../Discord-NP
cpanm --installdeps .

Next grab a copy of the "Mojo" folder (inside /lib) and drop it into C:\Strawberry\perl\lib\ and choose Yes when it asks you if you would like to merge with the existing Net folder.

Finally, make a copy of config.ini.example in the Discord-NP project folder and rename it to "config.ini". Fill it out as normal.

To run it, perl discordnp.pl

That's it! Have fun.

Build From Source

The build process is virtually identical for Mac, Windows, and Linux.

You will need two things: 'make' and 'pp'

'pp' is a utility provided by PAR::Packer, a perl module which you can install using cpanminus like so:

cpanm pp

'make' is something you should install with your package manager. On macOS you can use brew, on Windows I recommend using Chocolatey. (Once installed you run choco install make in an admin terminal and that's it)

Before you build, make sure you have a valid config.ini file in the project root as well as in the 'build' folder, I'll address that in a future update. The build process has to run the script to find dependencies, so having a valid config.ini is important.

Finally, run

make

and you should see it write the discordnp-OSTYPE file into the 'build' directory.

Troubleshooting

Please, if you are having trouble open a ticket on the Issues tab. Let me know what's going on or what isn't clear so I can update it.

You can also reach me on my discord, https://discord.gg/FuKTcHF

I make no promises as to availability or time frames, but I will try to help you if I can.

discord-np's People

Contributors

vsterminus avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

discord-np's Issues

Mojo/UserAgent.pm issues

Hi there, I'm encountering this error when I run discordnp.exe on Windows 10:

Tue Dec 1 20:15:29 2020 - Loaded Config: config.ini
Use of unauthorized value $loop in hash element at Mojo/UserAgent.pm line 192.
Mojo:: Reactor::Poll: I/O watcher failed: Can't call method "remove" on an undefined value at Mojo/UserAgent.pm line 269.

Here are the steps I've taken leading up to this:

  • Created last.fm API account and acquired API key
  • Acquired Discord token
  • Downloaded the latest .exe
  • Extracted file to a folder titled "Discord-NP" in /AppData/Local (same place my Discord folder is)
  • Entered all the necessary information into config.ini.example and saved as config.ini
  • Ran discordnp.exe

I've been able to get another Discord scrobbler to work, so I know the Discord token is correct. I'd just rather use this one if I can because it looks so nice.

Thanks in advance.

MacOS - client is not connected?

I'm pretty new to this and was trying to setup on MacOS Big Sur. My tokens validate ok, but it doesn't seem to be able to connect.

I edited out part of the path here but this is the error I'm getting. Any help would be appreciated.

$VAR1 = 'Cannot send OP - Client is not connected at /var/folders/v2/..../inc/lib/Mojo/Discord/Gateway.pm line 265.

(edit)
I also ran debug as mentioned by you in another ticket and this is what's in the log...

[2020-12-03 11:13:23.66829] [7563] [error] [Gateway.pm] [gateway] Could not retrieve Gateway URL from 'https://discord.com/api/gateway'
[2020-12-03 11:13:23.66862] [7563] [debug] $error = {
'message' => 'IO::Socket::SSL 2.009+ required for TLS support'
};

For those who are struggling to run this on Linux

It took me an insurmountable amount of time with quite a few reinstallations with different magic variables to configure this on Linux (Manjaro). Apparently Perl doesn't "just work" and the author doesn't explain the meaning of $PERL5LIB and doesn't suggest what to set it to. Anyway, based on default paths created by Perl, this works for me (assuming you store this software in .local/soft) and the application can find all libraries:

cd .local/soft
git clone https://github.com/vsTerminus/Discord-NP.git
git clone https://github.com/vsTerminus/Mojo-Discord.git
git clone https://github.com/vsTerminus/Mojo-WebService-LastFM.git
export PERL5LIB="/home/ave/perl5/lib/perl5"
export PERL_LOCAL_LIB_ROOT="/home/ave/perl5"
export PERL_MB_OPT="--install_base "/home/ave/perl5""
export PERL_MM_OPT="INSTALL_BASE=/home/ave/perl5"
mkdir -p $PERL5LIB/Mojo/WebService
ln -s $PWD/Mojo-Discord/lib/Mojo/Discord.pm $PERL5LIB/Mojo/
ln -s $PWD/Mojo-Discord/lib/Mojo/Discord $PERL5LIB/Mojo/
ln -s $PWD/Mojo-WebService-LastFM/lib/Mojo/WebService/LastFM.pm $PERL5LIB/Mojo/WebService/LastFM.pm
cd Mojo-Discord && cpanm --notest --installdeps .
cd ../Mojo-WebService-LastFM && cpanm --notest --installdeps .
cd ../Discord-NP && cpanm --notest --installdeps .
cpanm --local-lib=~/perl5 local::lib && eval $(perl -I ~/perl5/lib/perl5/ -Mlocal::lib)

Afterwards you can run it from clear shell context like that:

PERL5LIB="/home/ave/perl5/lib/perl5" ./.local/soft/Discord-NP/discordnp.pl

Presence doesn't show up

No errors were shown on the executable file, "Scrobbling Now" is active, but the presence itself doesn't show up on Discord status
image
After a while the following error showed up:

Mojo::Reactor::Poll: I/O watcher failed: Can't call method "add_emoji" on an undefined value at Mojo::Reactor::Poll: I/O watcher failed: Can't call method "add_emoji" on an undefined value at C:\Users\Gustavo\AppData\Local\Temp\par-4775737461766f\cache-e8d2f318777f4e704e314243981de786d2fc3f6c\inc\lib/Mojo/Discord/Gateway.pm line 783.
Mojo::Reactor::Poll: I/O watcher failed: Can't call method "add_emoji" on an undefined value at C:\Users\Gustavo\AppData\Local\Temp\par-4775737461766f\cache-e8d2f318777f4e704e314243981de786d2fc3f6c\inc\lib/Mojo/Discord/Gateway.pm line 783.

Mojo::Discord

Getting an error when I run this in Windows 10. I installed Strawberry Perl and used CPAN to install Config::Tiny, the strictures module, and Mojo::WebService::LastFM module without error. When trying to run I get this:

C:\Users\ccslo\Desktop\dnp>discordnp.pl
Can't locate Mojo/Discord.pm in @INC (you may need to install the Mojo::Discord module) (@INC contains: C:/Users/ccslo/Desktop/dnp/lib C:/Strawberry/perl/site/lib C:/Strawberry/perl/vendor/lib C:/Strawberry/perl/lib) at C:/Users/ccslo/Desktop/dnp/lib/Discord/NP.pm line 8.
BEGIN failed--compilation aborted at C:/Users/ccslo/Desktop/dnp/lib/Discord/NP.pm line 8.
Compilation failed in require at C:\Users\ccslo\Desktop\dnp\discordnp.pl line 31.
BEGIN failed--compilation aborted at C:\Users\ccslo\Desktop\dnp\discordnp.pl line 31.

When trying to install, I get this:

cpan> install Mojo::Discord
Warning: Cannot install Mojo::Discord, don't know what it is.
Try the command

    i /Mojo::Discord/

to find objects with matching identifiers.

Any ideas?

Not working

When I try to execute the perl script, I get this:
Can't locate Net/LastFM.pm in @inc (you may need to install the Net::LastFM module) (@inc contains: C:/Perl64/site/lib C:/Perl64/lib .) at discordnp.pl line 7.
BEGIN failed--compilation aborted at discordnp.pl line 7.

Discord status clearing itself unless the song played changes

I'm trying your app and I'm having an "issue" with it.
After something like one minute, Discord's status clears itself even though the song is still being played.
If the song changes, the status reappears, but will again disappear after the same amount of time.

Is there a way around this (aka keeping the song being played until it's actually over)?

Wrong instructions?

# Install Mojo::Discord and Mojo::WebService::LastFM
ln -s $PWD/Mojo-Discord/lib/Mojo/Discord.pm $PERL5LIB/Mojo/
ln -s $PWD/Mojo-Discord/lib/Mojo/Discord $PERL5LIB/Mojo/

This tries to link $PERL5LIB/Mojo/ to two different things. What should be done instead?

Android notifications not working when using the script

As above, whenever the script is running I no longer receive android notifications, stop the script and everything works as it should.

is this a limitation, and expected behaviour, or should push notifications work as intended?

error 1005 on submission, not updating status - also possible memory leak?

hi, I've been using your script for like a month or more, it fills the niche for last fm support in Discord.

however recently I've been getting error output from the terminal? for example:

Mon Aug 28 20:41:38 2017 (on_finish) Websocket Connection Closed with Code 1005 (No Status Received)

is this normal?

also I'm wondering if there might be a memory leak somewhere, since when I run the script for like a day or so, it takes up 99% of CPU resources.

any help would be appreciated, thanks!

Can't use an undefined value as a HASH reference.

I keep getting an error when I try to run the script.

Can't use an undefined value as a HASH reference at /usr/lib/perl5/vendor_perl/Net/Discord/Gateway.pm line 149.

Not sure if I have the token correct. I couldn't get it when I tried ctrl+shift+I so I tried making a bot user instead.

Mojo/Gateway not connecting

Am having issues connecting to Discord. Seems like the token is valid. I guess a connection must've been made to determine that?

Sat Apr 24 14:53:24 2021 - Loaded Config: config.ini
Sat Apr 24 14:53:24 2021 - Discord Token: OK
Sat Apr 24 14:53:24 2021 - LastFM API Key: OK
Sat Apr 24 14:53:24 2021 - LastFM User: flam316
Deep recursion on subroutine "Mojo::Discord::Gateway::gw_connect" at /Users/adamrubinstein/perl5/lib/perl5/Mojo/Discord/Gateway.pm line 470.
Deep recursion on subroutine "Mojo::Discord::Gateway::reconnect" at /Users/adamrubinstein/perl5/lib/perl5/Mojo/Discord/Gateway.pm line 356.

Error every interval: $VAR1 = 'Use of uninitialized value in concatenation (.) or string

~/discordnp
:: ./discordnp.exe
Mon Mar  1 13:02:20 2021 - Loaded Config: config.ini
Mon Mar  1 13:02:20 2021 - Discord Token: OK (Ends with ***)
Mon Mar  1 13:02:20 2021 - LastFM API Key: OK (Ends with ***)
Mon Mar  1 13:02:20 2021 - LastFM User: earnestma
Mon Mar  1 13:02:21 2021 - Connected to Discord
$VAR1 = 'Use of uninitialized value in concatenation (.) or string at C:\\Users\\earne\\AppData\\Local\\Temp\\par-6561726e65\\cache-30fe91174516285d35d929feb7d0f7db51160d81\\inc\\lib/Discord/NP.pm line 53.
';

$VAR1 = 'Use of uninitialized value in concatenation (.) or string at C:\\Users\\earne\\AppData\\Local\\Temp\\par-6561726e65\\cache-30fe91174516285d35d929feb7d0f7db51160d81\\inc\\lib/Discord/NP.pm line 53.
';

$VAR1 = 'Use of uninitialized value in concatenation (.) or string at C:\\Users\\earne\\AppData\\Local\\Temp\\par-6561726e65\\cache-30fe91174516285d35d929feb7d0f7db51160d81\\inc\\lib/Discord/NP.pm line 53.
';

$VAR1 = 'Use of uninitialized value in concatenation (.) or string at C:\\Users\\earne\\AppData\\Local\\Temp\\par-6561726e65\\cache-30fe91174516285d35d929feb7d0f7db51160d81\\inc\\lib/Discord/NP.pm line 53.
';

guild member update
Mojo::Reactor::Poll: I/O watcher failed: Can't call method "add_member" on an undefined value at C:\Users\earne\AppData\Local\Temp\par-6561726e65\cache-30fe91174516285d35d929feb7d0f7db51160d81\inc\lib/Mojo/Discord/Gateway.pm line 798.
guild member update
Mojo::Reactor::Poll: I/O watcher failed: Can't call method "add_member" on an undefined value at C:\Users\earne\AppData\Local\Temp\par-6561726e65\cache-30fe91174516285d35d929feb7d0f7db51160d81\inc\lib/Mojo/Discord/Gateway.pm line 798.
$VAR1 = 'Use of uninitialized value in concatenation (.) or string at C:\\Users\\earne\\AppData\\Local\\Temp\\par-6561726e65\\cache-30fe91174516285d35d929feb7d0f7db51160d81\\inc\\lib/Discord/NP.pm line 53.
';

$VAR1 = 'Use of uninitialized value in concatenation (.) or string at C:\\Users\\earne\\AppData\\Local\\Temp\\par-6561726e65\\cache-30fe91174516285d35d929feb7d0f7db51160d81\\inc\\lib/Discord/NP.pm line 53.
';

I am using the compiled Windows binary from https://github.com/vsTerminus/Discord-NP/releases/tag/1.4 running through Git Bash.

My config.ini:

[lastfm]
# You will need a Last.FM Developer API account for this script to work.
# There is no way around it, since the request requires an API key and I will not share my own.
# Fortunately, this is easy to get! Simply head over to http://www.last.fm/api/account/create
# Once your account is created, the site will display your API Key and API Secret.
# WRITE THESE DOWN! Last.FM apparently has no way to look them up later, so don't lose them.
# This script only requires the api key.
api_key = *****

# You'll also need to provide your Last.FM username for the script to query.
username = earnestma

# Provide an interval (in seconds). This tells the script how often it should
# check what you're listening to.
interval = 15

# These next two determine what shows up in the sidebar under your name where it says "Listening to ..."
# Yes to both: "artist - title" (eg "Devin Townsend - Genesis")
# Yes to artist only: "artist" (eg "Devin Townsend")
# Yes to title only: "title" (eg "Genesis")
# No to both: "Music"
# In any case, clicking on your name will show Artist, Title, and Album info in the popup.
show_artist = yes
show_title = yes

[discord]
# You need your discord user token so the script can log in as you and set your status.
#
# DISCLAIMER:
# YOU SHOULD CONSIDER THIS CAREFULLY. The discord token is like your password. Take care not to share it with anyone!
# You should absolutely look at the source code for yourself before you entrust any application (even this one!) with your token.
#
# If you still wish to proceed, learn how to get your token from here: https://discordhelp.net/discord-token
# It should look something like this (but longer): Mzk1MjY1.DgAknw.IiTvP8eSNRD
token = mfa.******

# Logging - This script will record a log of events to disk.
# log_dir should be set to a folder you have access to. Do not add a trailing slash.
# log_level can be one of: debug, info, warn, error, fatal, none
# Default value logs only warnings and fatal errors, and defaults to the same folder the script is in.
log_dir=.
log_level=fatal

Ubuntu - libcrypt.so.2: cannot open shared object file: No such file or directory

Trying to run version 1.3 on a fresh Ubuntu 20.04 install and the only output I'm getting is
error while loading shared libraries: libcrypt.so.2: cannot open shared object file: No such file or directory

Figured that meant libcrypt.so.2 was just not installed, but the closest thing that seemed related in apt is libcrypt1 and it's already installed.

Appreciate any help!

No status Change even tho appears to be working on the console

Last.fm is getting queried and I see the correct track being dumped out in the terminal - and a message saying connected to Discord so am assuming the token is correct - but I get no status updated to the Last-fm track.

Ubuntu 17.04, Discord 30/03/2017 - Linux

Still working?

Hi! Is this still working with the custom status update changes? I'm trying to get it to work on Linux Mint, but nothing is happening when I run it.

Now Playing: Songs I'm not scrobbling/listening to

Hey, basically your program shows my Now Playing as songs I'm not listening to or scrobbling anywhere:

error

Wires crossed somewhere? This happens both when I am listening to/scrobbling something and when I'm not. Seems a bit insecure not sure where it's pulling the info from or how.

Windows error line 78

$VAR1 = 'use of an uninitialized value in string eq at \AppData\Local\Temp\par- at line 78

I attached a screenshot, application seems to be working fine.
error discord NP line 78

Websocket closed with Code 1009 (Message Too Big)

If you are connected to any massive servers (such as the Discord API Server...) you might get this when you try to connect.

When the client sends IDENT to tell the Gateway who it is, the Gateway responds with a READY packet full of state info for all users and servers that you are connected to. Even with compression, apparently this can be took big for the Websocket to handle.

Unsure how to resolve this yet other than to leave said server.

Presence only shows sometimes

It shows the song playing, but it doesn't show on Discord, but it does work once in a while though.
The first, second, and fourth songs did not show, but the third song did work.
mojo-discord.log

Thanks in advance!

Edit:
After leaving it running for a bit, I got this:
Mojo::Reactor::Poll: I/O watcher failed: Use of uninitialized value $guild_id in hash element at C:\Users\name\AppData\Local\Temp\par-616e64726577\cache-e76337bf4f6843a907b0961fdb8c48f021de5b97\inc\lib/Mojo/Discord/Gateway.pm line 718.

Thank you; and sorry for bug tracker

I want to apologize for commenting through your bug tracker, however I could not find a single way to message you formally.

I just wanted to say thank you for this amazing plugin. I run it with itunes and it allows me to show my friends what i listen to , because we like to go back and fourth with bands.

I'm sure all of us really appreciate your work.

Can't open perl script "cpanminus": No such file or directory

Have been trying for hours to get this working with Strawberry Perl, but it keeps saying that cpanminus doesn't exist. I have never used Perl before, so I'm a real noob here. Would it be possible for you to create an updated executable? The latest release seems to be almost two years old and still has that annoying problem where the status disappears after two minutes. Thanks!

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.