jesseward / plex-lastfm-scrobbler

Scrobble played audio items Last.FM from the Plex Media Server application.
MIT License
92 stars 13 forks source link

Add real time now playing support #51

Open ronilaukkarinen opened 7 years ago

ronilaukkarinen commented 7 years ago

Works fine, but scrobbles only afterwards, no progress seen on profile page. I noticed you use pylastfm, it has update_now_playing for this purpose. I have implemented it to my pianobar script here.

I'm not expert in python, but I can try to implement it if/when I got the time. Until then, the stage is yours, if you want this feature.

duramato commented 6 years ago

Yes please! Think is something I really want, and it's something the native plex scrobbler is missing aswell.

ronilaukkarinen commented 6 years ago

Pinging this again, since it's been a while... I have occasionally googled about this again and can't believe nobody has implemented it yet. I guess I have to go and figure it out myself on holiday then. Hopefully someone will get inspired to work on this again.

jesseward commented 6 years ago

hey @ronilaukkarinen and @duramato as far as i can tell this would be a pretty straight forward change. I will take a look at it this week.

ronilaukkarinen commented 6 years ago

Awesome! thanks for so quick answer. It would make my life more complete as I use Plexamp more and more. I don't know much about python so getting into it would be indeed a study-thing. However here's again (if you didn't spot my link earlier) how I did it on Pandora cli client.

ronilaukkarinen commented 6 years ago

Not really experienced in python, but tried to give it a go today. I almost got it, but two things I'm struggling with:

ronilaukkarinen commented 6 years ago

Update: Currently handling this with a simple python script on Tautulli + the official scrobbling for Plex.

ronilaukkarinen commented 6 years ago

Repo is now online, if someone needs it..., check it out.

outpoints commented 1 year ago

Sorry to necro this but do you by any chance still have this file? @ronilaukkarinen

ronilaukkarinen commented 1 year ago
#!/usr/bin/python3.7
import os
import sys
import time
import pylast
import subprocess

artist = sys.argv[1]
album = sys.argv[2]
title = sys.argv[3]
duration = int(sys.argv[4])

# You need to add to to Arguments Playback Start and Playback Resume:
# "{track_artist}" "{album_name}" "{track_name}" {remaining_duration_sec}

print("PLEX: Trying to get metadata for: {0} / {1} / {2} / {3}".format(artist, album, title, duration))

network = pylast.LastFMNetwork(api_key="API_KEY_HERE", api_secret="API_SECRET_HERE",
                               username="USERNAME_HERE", password_hash=pylast.md5("PASSWORD_HERE"))

network.update_now_playing(artist = artist, album = album, title = title, duration = duration)
print("LAST.FM: Updated now playing status successfully for {0} - {2} (from album {1})".format(artist, album, title))
markbchavez commented 1 year ago

Thank you Roni for sharing the Tautulii script. I saved it as a .py file, ensured I had python installed (I used windows store) and selected Triggers of Playback Start and Playback Resume (don't select others as the parameter requirements are different) and added the arguments as noted in the script for Playback Start and Playback Resume. I used the Tautulli logs to see it running. Note that it seems with the duration information, Last.fm automatically handles Pausing and Stopping by removing scrobbles that didn't finish.

This filled a gap in the built-in Plex last.fm integration which would eventually post to last.fm but didn't add the necessary details to cover the nowplaying functionality. I am using this to display my NowPlaying music on my DakBoard digital display leveraging other functionality shared by reddit user Psukez10 at https://www.reddit.com/r/dakboard/comments/11ri22t/made_a_widget_to_display_lastfm_now_scrobbling/ which shows the artist, track, and cover art while something is playing and doesn't show it when nothing is playing (and in my case reveals family photos) . This allows me to used Last.fm for the Now Playing and then just rely on music service integrations to Last.fm (for those that have it) like Plex and Spotify. Speed of updates seems to be based on the source service and last.fm update frequency.

LastFMScrobbling

markbchavez commented 1 year ago

Here is the code in a txt file for my prior comment.... As I mentioned above, I only modified slightly the code created by someone else and commented as such.

LastFMNowPlaying.txt