summaryrefslogtreecommitdiff
path: root/scripts/python/last.fm.py
blob: 87256f7ce2c109251eb630110ecd11db520631b1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
"""
  :Author: Tim Schumacher <tim AT we-are-teh-b DOT org>

  :What it does: 
    This script informs the active window of your last
    submitted song at last.fm

  :Usage:
    /np - Displays your last submitted song.

  :Configuration Variables:
    ============= ==========================================
    Variable name Meaning
    ============= ==========================================
    lastfmuser    Your username at last.fm
  
  Released under GPL licence.
"""
#!/usr/bin/python

todo = """
 - Realy check if a song was recent.
 - Define 'recent' through a userdefinedvar
 - Add more help

"""

import urllib
import weechat as wc

wc.register("lastfmnp", "0.2.1", "", "now playing for last.fm")

def getLastSong(server, args):
    """ 
    Provides your last submitted song in last.fm to the actual context
    """
    user = wc.get_plugin_config("lastfmuser")
    url = "http://ws.audioscrobbler.com/1.0/user/" + user + "/recenttracks.txt"
    url_handle = urllib.urlopen(url)
    lines = url_handle.readlines()
    song = lines[0].split(",")[1].replace("\n","");
    if song == '':
        song = 'nothing :-)';
    wc.command("np: " + song)
    return 0


wc.add_command_handler("np", "getLastSong")

default = {
  "lastfmuser": "timds235"
}

for k, v in default.items():
  if not wc.get_plugin_config(k):
    wc.set_plugin_config(k, v)