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

Hey, thanks for pointing to your bug report...I didn't realize that there should have been a new "-p option".

I was alreadey wondering why no new options showed up after the reinstall.

DS1813> plex-scrobble.py -p
Usage: plex-scrobble.py [options]

So it seems that I still downloaded the wrong/old version last time.

After doing the whole procedure again, it's working like a charm now ^_^

DS1813> plex-scrobble.py -p
----------------------------------------------------------------------
| Running a few tests against your installation to ensure that
| required Plex Media Server files are in place.
----------------------------------------------------------------------
| * verify_plex_log_file_exists                          => [PASS]
| * detect_played_audio_in_PMS_log                       => [PASS]
| * was_lastfm_authorization_granted                     => [PASS]
----------------------------------------------------------------------

This works really well for me, thank you!  I am running this on a headless Ubuntu server, so I'm running into difficulty with sessions.  When I ssh into my server and run the script all is well. When I kill that session of course, the script stops and scrobbling ceases.  I've tried setting this as a service through Upstart but haven't had any luck.

Any suggestions on getting this to run on startup and all the time?

edit: Nevermind, I got it working.  Was missing some details but this covered it.

http://askubuntu.com/questions/175751/how-do-i-run-a-python-script-in-the-background-and-restart-it-after-a-crash


edit: Nevermind, I got it working.  Was missing some details but this covered it.

http://askubuntu.com/questions/175751/how-do-i-run-a-python-script-in-the-background-and-restart-it-after-a-crash

But I'm still stuck. Upstart just doesn't seem to run my .conf-file. Any hints?

start on (filesystem and stopped udevtrigger)
stop on runlevel [016]

# tell upstart to respawn the process if abnormal exit
respawn

script
  /home/ubuntu/.virtualenvs/plex-lastfm-scrobber/bin/python /home/ubuntu/plex-lastfm-scrobber/scripts/plex-scrobble.py
end script

But I'm still stuck. Upstart just doesn't seem to run my .conf-file. Any hints?

start on (filesystem and stopped udevtrigger)
stop on runlevel [016]

# tell upstart to respawn the process if abnormal exit
respawn

script
  /home/ubuntu/.virtualenvs/plex-lastfm-scrobber/bin/python /home/ubuntu/plex-lastfm-scrobber/scripts/plex-scrobble.py
end sc
/ript

i don't see an exec command in your script to kick off python.

here is my /etc/init/PlexPythonScrobbler.conf file contents.  you probably want to run the script as your "ubuntu" user using the setuid and setgid commands

start on runlevel [2345]
stop on runlevel [016]

respawn
setuid macdonals
setgid macdonals
exec python /home/macdonals/plex-lastfm-scrobbler/scripts/plex-scrobble.py

i don't see an exec command in your script to kick off python.

here is my /etc/init/PlexPythonScrobbler.conf file contents.  you probably want to run the script as your "ubuntu" user using the setuid and setgid commands

start on runlevel [2345]
stop on runlevel [016]

respawn
setuid macdonals
setgid macdonals
exec python /home/macdonals/plex-lastfm-scrobbler/scripts/plex-scrobble.py

Thanks, the

setuid macdonals
setgid macdonals

did the trick!

Thanks, the

setuid macdonals
setgid macdonals

did the trick!

Unfortunately I was cheering too soon...

The service seems to be running, but it gives an error on a 'possible log file rotation' and refuses to scrobble. However when I start the service manually it works like a charm. Any hints?

Unfortunately I was cheering too soon...

The service seems to be running, but it gives an error on a 'possible log file rotation' and refuses to scrobble. However when I start the service manually it works like a charm. Any hints?

I'm not sure, but maybe it's the way you're executing the script.  I'm not clear on what the execution context is with the mechanism.  I just use 

exec python *python script location goes here*

I've done everything up to the point of "plex-scrobble.py" in ubuntu, but then the terminal just hangs until I have to force stop the action. Any fix for this?

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.

How do we get this to start on boot?

I think i have double instances. im scrobbling twice.

How do I stop it?

Thanks in advance.

Does it have to be complied on your own machine? Would it be possible to publish a compiled version that just has the bundle folder and all the necessary files so it could just be unzipped to the correct folder in Plex? Similar to how the Trakt Scrobbler works: https://github.com/trakt/Plex-Trakt-Scrobbler

Just a quick note to say I installed this on my OSX Plex machine and it's working great. Thank you for putting this together! OS X 10.7.5, PMS 0.9.11.7

Does it have to be complied on your own machine? Would it be possible to publish a compiled version that just has the bundle folder and all the necessary files so it could just be unzipped to the correct folder in Plex? Similar to how the Trakt Scrobbler works: https://github.com/trakt/Plex-Trakt-Scrobbler

Would like this too, if it could be added as a channel.

I am trying to install it on Synology DS213+ (DSM 5.2 beta). I installed to /volume1/@appstore/ 

I followed instructions, I get the token and I authorized the app on last.fm site. 

When I restart the app, it continues to log:

2015-03-15 12:45:34,469 [11592] [main ] [DEBUG] config : mediaserver_log_location -> /volume1/Plex/Library/Application Support/Plex Media Server/Logs/
2015-03-15 12:45:34,470 [11592] [main ] [DEBUG] config : session -> /root/.config/plex-lastfm-scrobbler/session_key
2015-03-15 12:45:34,470 [11592] [main ] [DEBUG] config : mediaserver_url -> http://localhost:32400
2015-03-15 12:45:34,471 [11592] [main ] [DEBUG] config : config file location -> /root/.config/plex-lastfm-scrobbler/plex_scrobble.conf
2015-03-15 12:45:34,471 [11592] [main ] [DEBUG] config : log_file -> /tmp/plex_scrobble.log
2015-03-15 12:45:34,472 [11592] [main ] [DEBUG] config : cache_location -> /tmp/plex_scrobble.cache
2015-03-15 12:45:34,472 [11592] [main ] [INFO] Prompting to authenticate to Last.fm.
2015-03-15 12:45:39,271 [11592] [plex_scrobble.lastfm _do_raw_lastfm_query] [ERROR] Unable to submit query http://ws.audioscrobbler.com/2.0/?api_sig=488f37ab8c6b8a015e30b3dfd31caba7&token=9b5e236f45203470db764a96dd4fa64d&api_key=e692f685cdb9434ade9e72307fe53b05&method=auth.getSession - HTTP Error 403: Forbidden
2015-03-15 12:45:39,272 [11592] [plex_scrobble.lastfm last_fm_auth] [ERROR] Unable to send authorization request HTTP Error 403: Forbidden
2015-03-15 12:45:39,273 [11592] [main ] [WARNING] Exiting application..

Running plex-scrobble.py -p returns

DS213> plex-scrobble.py -p
----------------------------------------------------------------------
| Running a few tests against your installation to ensure that
| required Plex Media Server files are in place.
----------------------------------------------------------------------
| * verify_plex_log_file_exists                          => [FAIL]
|       Check: Log file does not exist, please ensure you have
|       correctly set mediaserver_log location in your Plex Scrobbler
|       configuration.
| * detect_played_audio_in_PMS_log                       => [FAIL]
|       Check: Log file does not exist, please ensure you
|       havecorrectly set mediaserver_log location in your Plex
|       Scrobblerconfiguration.
| * was_lastfm_authorization_granted                     => [FAIL]
|       Check: Your last.fm authtoken does not exist. Please
|       run"python plex-scrobbler.py -a" and follow instructions to
|       grantauthorization to your last.fm account.
PS.

OK, fixed, was a problem of last.fm authorization. 

now

DS213> plex-scrobble.py -p
----------------------------------------------------------------------
| Running a few tests against your installation to ensure that
| required Plex Media Server files are in place.
----------------------------------------------------------------------
| * verify_plex_log_file_exists                          => [PASS]
| * detect_played_audio_in_PMS_log                       => [PASS]
| * was_lastfm_authorization_granted                     => [PASS]
----------------------------------------------------------------------

This has been working great for me until yesterday when I setup users and now each user requires a pin. Is there anyway to work around this ?

http://pastebin.com/2aMPA4jB

EDIT: actually got it working, looked through the url and noticed it has inserted a space into it. 

Also, on my Windows server getting things set up was a little more complex than the instructions would have you believe. ;)

I've just tried setting this up and I'm getting this error with the last.fm setup step:

Invalid API key. If you are a third party developer see our authentication how-to to find out more.

I am not good with code, anyone could suggest an autorun script to be used on Synology, Linux OS.

Thanks

I am not good with code, anyone could suggest an autorun script to be used on Synology, Linux OS.
Thanks

Same here.  :huh:

Well, looking around, a proposed script could be (not tested yet):

#!/bin/sh## Startup script for plex scrobbler## Stop myself if runningPIDFILE=/var/run/S98plexscrobbler.pid #start() {sleep 1nohup /usr/bin/plex-scrobble.py & # write pidfileecho $! > $PIDFILE}#stop() {[ -f ${PIDFILE} ] && kill cat ${PIDFILE}# remove pidfilerm -f $PIDFILE}#case “$1” instart)start;;stop)stop;;restart)stopsleep 1start;;*)echo "Usage: $0 (start|stop|restart)"exit 1;;esac# End

I called it S98plexscrobbler.sh and put it in /usr/local/etc/rc.d.


I modified an existing file to run at start JDownloader2.


Update 21APR2015

Script is working fine.

Tried this out with Premium Music while waiting for last.fm functionality to be added (as per comment thread on blog, it's on the to-do list)...not able to make this work.  Does this only work with "regular" music libraries?