summaryrefslogtreecommitdiff
path: root/contrib/eventcmd-examples
diff options
context:
space:
mode:
authorYuval Hager <yhager@yhager.com>2011-08-30 16:18:13 -0700
committerLars-Dominik Braun <lars@6xq.net>2011-08-31 21:34:41 +0200
commit4212b0eac58fb9b926a9dafe4fd76fa886af81b4 (patch)
tree2a19de602181249e9d067b5e96cb32b1475b78eb /contrib/eventcmd-examples
parent6dddf8a25df2798619d9d08f645ebea51bdfe0bb (diff)
downloadpianobar-4212b0eac58fb9b926a9dafe4fd76fa886af81b4.tar.gz
pianobar-4212b0eac58fb9b926a9dafe4fd76fa886af81b4.tar.bz2
pianobar-4212b0eac58fb9b926a9dafe4fd76fa886af81b4.zip
adapt to last.fm scrobble definitons, and support love and ban
Closes #153
Diffstat (limited to 'contrib/eventcmd-examples')
-rwxr-xr-xcontrib/eventcmd-examples/scrobble.py19
1 files changed, 16 insertions, 3 deletions
diff --git a/contrib/eventcmd-examples/scrobble.py b/contrib/eventcmd-examples/scrobble.py
index 51e19c2..99f328c 100755
--- a/contrib/eventcmd-examples/scrobble.py
+++ b/contrib/eventcmd-examples/scrobble.py
@@ -43,7 +43,12 @@ API_KEY = "################################"
API_SECRET = "################################"
USERNAME = "########"
PASSWORD = "########"
+
+# When is a scrobble a scrobble?
+# See http://www.last.fm/api/scrobbling#when-is-a-scrobble-a-scrobble
THRESHOLD = 50 # the percentage of the song that must have been played to scrobble
+PLAYED_ENOUGH = 240 # or if it has played for this many seconds
+MIN_DURATION = 30 # minimum duration for a song to be "scrobblable"
def main():
@@ -51,18 +56,26 @@ def main():
lines = sys.stdin.readlines()
fields = dict([line.strip().split("=", 1) for line in lines])
- # fields: title, artist, album, songDuration, songPlayed, rating, stationName, pRet, pRetStr, wRet, wRetStr
+ # fields: title, artist, album, songDuration, songPlayed, rating, stationName, pRet, pRetStr, wRet, wRetStr, rating
artist = fields["artist"]
title = fields["title"]
song_duration = int(fields["songDuration"])
song_played = int(fields["songPlayed"])
+ rating = int(fields["rating"])
# events: songstart, songfinish, ???
- if event == "songfinish" and 100.0 * song_played / song_duration > THRESHOLD:
+ import pylast
+ if event == "songfinish" and song_duration > 1000*MIN_DURATION and (100.0 * song_played / song_duration > THRESHOLD or song_played > 1000*PLAYED_ENOUGH):
song_started = int(time.time() - song_played / 1000.0)
- import pylast
network = pylast.LastFMNetwork(api_key = API_KEY, api_secret = API_SECRET, username = USERNAME, password_hash = pylast.md5(PASSWORD))
network.scrobble(artist = artist, title = title, timestamp = song_started)
+ if event == "songfinish" and rating > 0:
+ network = pylast.LastFMNetwork(api_key = API_KEY, api_secret = API_SECRET, username = USERNAME, password_hash = pylast.md5(PASSWORD))
+ track = network.get_track(artist, title)
+ if rating == 1:
+ track.love()
+ elif rating == 2:
+ track.ban()
if __name__ == "__main__":
main()