plex-lastfm-scrobble - Scrobble Plex audio tracks to Last.fm

plex-lastfm-scrobbler

https://github.com/jesseward/plex-lastfm-scrobbler

plex-lastfm-scrobbler provides a set of scripts that allow you to scrobble played audio items to Last.FM from the Plex Media Server application. plex-lastfm-scrobbler was built to run across platforms, while it has not yet been tested on Windows, it should work.

A few points

  • Uses python standard library. Python is the only requirement to run this application
  • Must be run on the Plex Media Server
  • Parses Plex Media Server logs for the 'got played' string in the log file.
  • Does not differentiate between clients. Meaning all media played, will be scrobbled while the script is running.
  • Your plex-media-server logs must be set at DEBUG level (not VERBOSE)

Installation

Version 0.0.1

It is recommended (but not required) that you install this into a virtualenvironment.

virtualenv ~/.virtualenvs/plex-lastfm-scrobber
source ~/.virtualenvs/plex-lastfm-scrobber/bin/activate

Fetch and install the source from the github repo.

git clone git@github.com:jesseward/plex-lastfm-scrobbler.git
cd plex-lastfm-scrobbler
python setup.py install

You're done.

 

Configuration

The plex-lastfm-scrobbler configuration file (plex_scrobble.conf) is installed to ~/.config/plex-lastfm-scrobbler/ . The following configuration values are available.

If you're running Plex Media Server on a Linux based operating system, things should work out of the box.

# REQUIRED: mediaserver_url is the location of the http service exposed by Plex Media Server
# the default values should be 'ok', assuming you're running the plex scrobble
# script from the same server as your plex media server
mediaserver_url = 'http://localhost:32400'

REQUIRED: mediaserver_log_location references the log file location of the plex media server

the default under /var/lib/… is the default install of plex media server on

a Linux system. You may wish to change this value to reference your OS install.

mediaserver_log_location = ‘/var/lib/plexmediaserver/Library/Application Support/Plex Media Server/Logs/Plex Media Server.log’

REQUIRED: Where do you wish to write the plex-scrobble log file.

log_file = /tmp/plex_scrobble.log

Running

If you installed plex-lastfm-scrobble to a virtual environment, enable the virtual env.

source ~/.virtualenvs/plex-lastfm-scrobber/bin/activate

run the application

$ plex-scrobble.py

On first run you will be prompted to authenticate and grant access to your Last.fm account. Visit the URL generated by plex-scrobble and follow the prompts to grant access to the application.

Example.

$ plex-scrobble.py

== Requesting last.fm auth ==
Please accept authorization at http://www.last.fm/api/auth/?api_key=blunted_dummies-house-for-all-1991

Have you authorized me [y/N] : y
Please relaunch plex-scrobble service.

Once this is complete, please re-start the service, listen to audio via Plex and watch as your music is scrobbled. You may wish to leave the service running in the background. On a POSIX system, wrap the script in the no-hangup utility.

$ nohup plex-scrobble.py &

Troubleshooting

  • If you're experiencing authentication issues (appearing in plex_scrobble.log), remove the ~/.config/plex-lastfm-scrobbler/session file. This stores your Last.FM authentication token. There is no harm in removing/recreating this as many times as needed.
  • Log an issue https://github.com/jesseward/plex-lastfm-scrobbler/issues/new

 

Contributing

Any feedback on the performance on a MS Windows installation would be appreciated. I do not have ability to test plex-lastfm-scrobbler on this platform. Please log an issue or a pull request with any fixes.

Thanks for working on this. Been dying for last.fm scrobbling for a long time!

Sadly I have no clue how I might try to install this on my Windows7 Plex server.

I downloaded and installed Python for Windows from python.org, then I downloaded your zip from github. I tried extracting it to my hard drive and running those commands in the DOS prompt, but it doesn't recognize the commands. Obviously I'm not doing it right. Any tips?

Thanks.

Hey there,
 
Thanks for testing. I found a free, time-limited windows VM to test with, courtesy of Microsoft (https://www.modern.ie/en-us/virtualization-tools for others who may be interested). Which allowed me to at least attempt to start up the script and provide some install instructions for windows users.
 
1.  Download and install Python 2.7.x from https://www.python.org/download/
    a) Ensure you enable the option to install Python to the system/site path.
 
2.  Download the zip of plex-lastfm-scrobbler from https://github.com/jesseward/plex-lastfm-scrobbler/archive/master.zip . Note a made a couple changes to support windows, so you will need to grab a new version.
    a) unzip to a temporary location. for this example we will use c: emp\plex-lastfm-scrobbler\
 
3.  Open a command prompt and change to the emp folder
cd c:	emp\plex-lastfm-scrobbler\
 
4.  in the c: emp\plex-lastfm-scrobbler\ directory, run the installer from the dos prompt
python setup.py install
The above command installs the python scripts to various locations. Directories of interest are
* c:\Python27\scripts\
* .config  - this directory is created in your Users home directory. You will need to modify the configuration file from within this directory and point log locations at the appropriate locations for Plex on windows. You can set the "log_file" property to c: emp or some other location which you wish to write logs to.
 
To run the application, do the following from a DOS prompt
cd c:\Python27\scripts
python plex-scrobble.py

great job! 

but to keep it updated, can you please ask the author of the Unsupported Appstore to implement this Plugin? Thank you! And keep on :)

Hey there,
 
Thanks for testing. I found a free, time-limited windows VM to test with, courtesy of Microsoft (https://www.modern.ie/en-us/virtualization-tools for others who may be interested). Which allowed me to at least attempt to start up the script and provide some install instructions for windows users.
 
1.  Download and install Python 2.7.x from https://www.python.org/download/
    a) Ensure you enable the option to install Python to the system/site path.
 
2.  Download the zip of plex-lastfm-scrobbler from https://github.com/jesseward/plex-lastfm-scrobbler/archive/master.zip . Note a made a couple changes to support windows, so you will need to grab a new version.
    a) unzip to a temporary location. for this example we will use c: emp\plex-lastfm-scrobbler\
 
3.  Open a command prompt and change to the emp folder
cd c:	emp\plex-lastfm-scrobbler\
 
4.  in the c: emp\plex-lastfm-scrobbler\ directory, run the installer from the dos prompt
python setup.py install
The above command installs the python scripts to various locations. Directories of interest are
* c:\Python27\scripts\
* .config  - this directory is created in your Users home directory. You will need to modify the configuration file from within this directory and point log locations at the appropriate locations for Plex on windows. You can set the "log_file" property to c: emp or some other location which you wish to write logs to.
 
To run the application, do the following from a DOS prompt
cd c:\Python27\scripts
python plex-scrobble.py

When I do the 'python setup.py install' I get the message "python is not recognised as an internal or external command operable program or batch file."

Thanks for your help.

EDIT: sorry I needed to restart for that to work.

Hello again,

I ran python plex-scrobble.py from the dos prompt but nothing happened, I didnt get the expected prompt to authenticate my last.fm account.

EDIT: Sorry, I have created an 'issue' using your github link.

It seems that (at least for me) I had to type:

git clone git://github.com:jesseward/plex-lastfm-scrobbler.git 

Instead of

git clone git@github.com:jesseward/plex-lastfm-scrobbler.git

For it to work. I was getting a 'Permission denied (Publickey)' error. Got it working now with the first command.

It seems that (at least for me) I had to type:

git clone git://github.com:jesseward/plex-lastfm-scrobbler.git 

hey thanks for this. Not sure how that crept in there. The README.md on github appears correct.

I have fixed a few bugs and added some features since this initial post. Latest version can be found @ https://github.com/jesseward/plex-lastfm-scrobbler

It will probably work MUCH better for most people if you clone using HTTPS instead of SSH/GIT:

Replace this:

git clone git://github.com:jesseward/plex-lastfm-scrobbler.git 

With this:

git clone https://github.com/jesseward/plex-lastfm-scrobbler.git

Not everyone is a developer and has github SSH-keys :)

Not everyone is a developer and has github SSH-keys :)

thanks. I have updated the docs and also fixed a bug with regards to unicode artist/song names.

 

Is there a user-friendly way to install this yet without any coding or developer knowledge?

So I followed the instruction on your site (https://github.com/jesseward/plex-lastfm-scrobbler) for installing it on my Windows box. Everything has worked up until the point of running the application. Here is a screenshot of the DOS prompt. 
 
error.PNG
 
I assume something is wrong with my config file. Here is what is in my config file.
 
[plex-scrobble]

REQUIRED: mediaserver_url is the location of the http service exposed by Plex Media Server

the default values should be ‘ok’, assuming you’re running the plex scrobble

script from the same server as your plex media server

mediaserver_url = http://localhost:32400

REQUIRED: Where do you wish to write the plex-scrobble log file.

log_file = C: emp\plex_scrobble.log

REQUIRED: a python data struture that stores failed scrobbles. plex-scrobble

will retry on a 60 minute interval, maximum of 10 attempts if last.fm is

experiencing issues.

cache_location = C: emp\plex_scrobble.cache

OPTIONAL: mediaserver_log_location references the log file location of the plex media server

the default under /var/lib/… is the default install of plex media server on

a Linux system. You may wish to change this value to reference your OS install.

https://support.plex.tv/hc/en-us/articles/200250417-Plex-Media-Server-Log-Files

mediaserver_log_location = C:\Users\Paradigit\AppData\Local\Plex Media Server\Logs\Plex Media Server.log

Can you help me fix it?

thanks

@ seanfilidis: Yeah, in comparison to to the original config file it seems that you messed up the syntax of your entries...for example backslash instead of slash or using '' if necessary. That's probably why the script couldn't successfully parse your config. Sorry that I can't give you more specifics since I'm not used to Python or the used code itself.

@ s-jw: Thanks for your work! I was always looking for a server based solution to scrobble my music with Plex.

But I'm on a Synology NAS and have some trouble with the config file too. It doesn't matter what I enter for the location of the PMS log file (should be /volume1/Plex/Library/Application Support/Plex Media Server/Logs/Plex Media Server.log). The script always falls back to the Linux default path (/var/lib/plexmediaserver/...). I tried to alter your code a little bit but it still falls back to the default value. I am not really familiar with Linux or Python so maybe I am doing something more or less obvioulsy wrong. Any help would be appreciated.

The plex-lastfm-scrobble log always says:

2014-10-07 11:58:50,844 [22899] [main ] [DEBUG] config : mediaserver_log_location -> /var/lib/plexmediaserver/Library/Application Support/Plex Media Server/Logs/Plex Media Server.log
2014-10-07 11:58:50,845 [22899] [main ] [DEBUG] config : session -> /root/.config/plex-lastfm-scrobbler/session_key
2014-10-07 11:58:50,845 [22899] [main ] [DEBUG] config : mediaserver_url -> http://localhost:32400
2014-10-07 11:58:50,845 [22899] [main ] [DEBUG] config : log_file -> /tmp/plex_scrobble.log
2014-10-07 11:58:50,846 [22899] [main ] [DEBUG] config : cache_location -> /tmp/plex_scrobble.cache
2014-10-07 11:58:50,846 [22899] [main main] [INFO] starting log monitor thread.
2014-10-07 11:58:50,847 [22899] [main cache_retry] [INFO] starting cache_retry thread.
2014-10-07 11:58:50,847 [22899] [plex_scrobble.plex_monitor monitor_log] [ERROR] Unable to read log-file /var/lib/plexmediaserver/Library/Application Support/Plex Media Server/Logs/Plex Media Server.log. Shutting down.

Would there be any way to modify this script to support scrobbling to multiple last.fm users, based on source IP or username?

@ seanfilidis - will continue discussion within the github ticket -> https://github.com/jesseward/plex-lastfm-scrobbler/issues/16.

@b4th - i added some additional debug information, could you download and install a new build at https://github.com/jesseward/plex-lastfm-scrobbler/archive/master.zip and reinstall.  Start it up and pass along the log output as you have done here. Please also dump your config in http://pastebin.com/

thanks for the bug reports ;-)

Would there be any way to modify this script to support scrobbling to multiple last.fm users, based on source IP or username?

Thanks for the suggestion. I will determine if this is possible and track progress in https://github.com/jesseward/plex-lastfm-scrobbler/issues/18

@b4th - i added some additional debug information, could you download and install a new build at https://github.com/jesseward/plex-lastfm-scrobbler/archive/master.zip and reinstall.  Start it up and pass along the log output as you have done here. Please also dump your config in http://pastebin.com/

Hey, thanks for the immediate reply! I just got time to try it out, sorry.

The config for the version you put on was working right off the box.

But after starting the script, nothing else seems to happen. I played some songs and checked if the "got played" entry was created correctly in the PMS log (it did).

Here are the entries for the last two sessions, since the first run mentioned a "Possible log file rotation":

2014-10-11 20:46:47,194 [15164] [main ] [DEBUG] config : mediaserver_log_location -> /volume1/Plex/Library/Applicatio
2014-10-11 20:46:47,195 [15164] [main ] [DEBUG] config : session -> /root/.config/plex-lastfm-scrobbler/session_key
2014-10-11 20:46:47,195 [15164] [main ] [DEBUG] config : mediaserver_url -> http://localhost:32400
2014-10-11 20:46:47,195 [15164] [main ] [DEBUG] config : config file location -> /root/.config/plex-lastfm-scrobbler/
2014-10-11 20:46:47,196 [15164] [main ] [DEBUG] config : log_file -> /tmp/plex_scrobble.log
2014-10-11 20:46:47,196 [15164] [main ] [DEBUG] config : cache_location -> /tmp/plex_scrobble.cache
2014-10-11 20:46:47,196 [15164] [main main] [INFO] starting log monitor thread.
2014-10-11 20:46:48,003 [15164] [plex_scrobble.plex_monitor monitor_log] [DEBUG] Possible log file rotation, resetting file h
2014-10-11 21:12:04,635 [21432] [main ] [DEBUG] config : mediaserver_log_location -> /volume1/Plex/Library/Applicatio
2014-10-11 21:12:04,636 [21432] [main ] [DEBUG] config : session -> /root/.config/plex-lastfm-scrobbler/session_key
2014-10-11 21:12:04,636 [21432] [main ] [DEBUG] config : mediaserver_url -> http://localhost:32400
2014-10-11 21:12:04,636 [21432] [main ] [DEBUG] config : config file location -> /root/.config/plex-lastfm-scrobbler/
2014-10-11 21:12:04,637 [21432] [main ] [DEBUG] config : log_file -> /tmp/plex_scrobble.log
2014-10-11 21:12:04,637 [21432] [main ] [DEBUG] config : cache_location -> /tmp/plex_scrobble.cache
2014-10-11 21:12:04,637 [21432] [main main] [INFO] starting log monitor thread.

config:

http://pastebin.com/rU3SCs0X (I only changed the log file path)


config:

http://pastebin.com/rU3SCs0X (I only changed the log file path)

config looks good. I have posted an updated version that captures some unicode issues as well as enables additional logging data. Install from https://github.com/jesseward/plex-lastfm-scrobbler/archive/master.zip .

Please let it run , then your log output again. thanks! 

config looks good. I have posted an updated version that captures some unicode issues as well as enables additional logging data.

Hey,

ok, I installed the new version and gave it a try.

But the log looks pretty identical to the previous one. And the scrobbling didn't seem to work either :-/

Should it also write all scrobbled songs in the log? I mean if it would be working here.

2014-10-17 00:09:51,942 [23115] [main ] [DEBUG] config : mediaserver_log_location -> /volume1/Plex/Library/Application Support/Plex Media Server/Logs/Plex Media Server.log
2014-10-17 00:09:51,943 [23115] [main ] [DEBUG] config : session -> /root/.config/plex-lastfm-scrobbler/session_key
2014-10-17 00:09:51,943 [23115] [main ] [DEBUG] config : mediaserver_url -> http://localhost:32400
2014-10-17 00:09:51,943 [23115] [main ] [DEBUG] config : config file location -> /root/.config/plex-lastfm-scrobbler/plex_scrobble.conf
2014-10-17 00:09:51,943 [23115] [main ] [DEBUG] config : log_file -> /tmp/plex_scrobble.log
2014-10-17 00:09:51,944 [23115] [main ] [DEBUG] config : cache_location -> /tmp/plex_scrobble.cache
2014-10-17 00:09:51,944 [23115] [main ] [DEBUG] using last.fm session key=/root/.config/plex-lastfm-scrobbler/session_key , st_mtime=Fri Oct 17 00:09:48 2014
2014-10-17 00:09:51,944 [23115] [main main] [INFO] starting log monitor thread.
2014-10-17 00:09:51,977 [23115] [plex_scrobble.plex_monitor monitor_log] [DEBUG] Possible log file rotation, resetting file handle (st_mtime=Thu Oct 16 21:51:55 2014)
2014-10-17 00:23:03,817 [26720] [main ] [DEBUG] config : mediaserver_log_location -> /volume1/Plex/Library/Application Support/Plex Media Server/Logs/Plex Media Server.log
2014-10-17 00:23:03,818 [26720] [main ] [DEBUG] config : session -> /root/.config/plex-lastfm-scrobbler/session_key
2014-10-17 00:23:03,818 [26720] [main ] [DEBUG] config : mediaserver_url -> http://localhost:32400
2014-10-17 00:23:03,818 [26720] [main ] [DEBUG] config : config file location -> /root/.config/plex-lastfm-scrobbler/plex_scrobble.conf
2014-10-17 00:23:03,819 [26720] [main ] [DEBUG] config : log_file -> /tmp/plex_scrobble.log
2014-10-17 00:23:03,819 [26720] [main ] [DEBUG] config : cache_location -> /tmp/plex_scrobble.cache
2014-10-17 00:23:03,819 [26720] [main ] [DEBUG] using last.fm session key=/root/.config/plex-lastfm-scrobbler/session_key , st_mtime=Fri Oct 17 00:09:48 2014
2014-10-17 00:23:03,820 [26720] [main main] [INFO] starting log monitor thread.
2014-10-17 00:23:03,852 [26720] [plex_scrobble.plex_monitor monitor_log] [DEBUG] Possible log file rotation, resetting file handle (st_mtime=Thu Oct 16 21:51:55 2014)

I just checked some other things, that I could think of.

  • process running:
26720 root     21164 S    /usr/bin/python /usr/local/bin/plex-scrobble.py
  • everyone has read access to the PMS log:
-rw-r--r--    1 plex     users          110 Oct 16 21:51 Plex Media Server.log
  • deleted the session_key and let it create another one

Sorry, that it didn't bring up anything new :mellow:

Maybe this helps:

https://github.com/jesseward/plex-lastfm-scrobbler/issues/24

Hey,

ok, I installed the new version and gave it a try.

But the log looks pretty identical to the previous one. And the scrobbling didn't seem to work either :-/

Should it also write all scrobbled songs in the log? I mean if it would be working here.

2014-10-17 00:09:51,942 [23115] [main ] [DEBUG] config : mediaserver_log_location -> /volume1/Plex/Library/Application Support/Plex Media Server/Logs/Plex Media Server.log
2014-10-17 00:09:51,943 [23115] [main ] [DEBUG] config : session -> /root/.config/plex-lastfm-scrobbler/session_key
2014-10-17 00:09:51,943 [23115] [main ] [DEBUG] config : mediaserver_url -> http://localhost:32400
2014-10-17 00:09:51,943 [23115] [main ] [DEBUG] config : config file location -> /root/.config/plex-lastfm-scrobbler/plex_scrobble.conf
2014-10-17 00:09:51,943 [23115] [main ] [DEBUG] config : log_file -> /tmp/plex_scrobble.log
2014-10-17 00:09:51,944 [23115] [main ] [DEBUG] config : cache_location -> /tmp/plex_scrobble.cache
2014-10-17 00:09:51,944 [23115] [main ] [DEBUG] using last.fm session key=/root/.config/plex-lastfm-scrobbler/session_key , st_mtime=Fri Oct 17 00:09:48 2014
2014-10-17 00:09:51,944 [23115] [main main] [INFO] starting log monitor thread.
2014-10-17 00:09:51,977 [23115] [plex_scrobble.plex_monitor monitor_log] [DEBUG] Possible log file rotation, resetting file handle (st_mtime=Thu Oct 16 21:51:55 2014)
2014-10-17 00:23:03,817 [26720] [main ] [DEBUG] config : mediaserver_log_location -> /volume1/Plex/Library/Application Support/Plex Media Server/Logs/Plex Media Server.log
2014-10-17 00:23:03,818 [26720] [main ] [DEBUG] config : session -> /root/.config/plex-lastfm-scrobbler/session_key
2014-10-17 00:23:03,818 [26720] [main ] [DEBUG] config : mediaserver_url -> http://localhost:32400
2014-10-17 00:23:03,818 [26720] [main ] [DEBUG] config : config file location -> /root/.config/plex-lastfm-scrobbler/plex_scrobble.conf
2014-10-17 00:23:03,819 [26720] [main ] [DEBUG] config : log_file -> /tmp/plex_scrobble.log
2014-10-17 00:23:03,819 [26720] [main ] [DEBUG] config : cache_location -> /tmp/plex_scrobble.cache
2014-10-17 00:23:03,819 [26720] [main ] [DEBUG] using last.fm session key=/root/.config/plex-lastfm-scrobbler/session_key , st_mtime=Fri Oct 17 00:09:48 2014
2014-10-17 00:23:03,820 [26720] [main main] [INFO] starting log monitor thread.
2014-10-17 00:23:03,852 [26720] [plex_scrobble.plex_monitor monitor_log] [DEBUG] Possible log file rotation, resetting file handle (st_mtime=Thu Oct 16 21:51:55 2014)

I just checked some other things, that I could think of.

  • process running:
26720 root     21164 S    /usr/bin/python /usr/local/bin/plex-scrobble.py
  • everyone has read access to the PMS log:
-rw-r--r--    1 plex     users          110 Oct 16 21:51 Plex Media Server.log
  • deleted the session_key and let it create another one

Sorry, that it didn't bring up anything new :mellow: