You are not logged in.
Pages: 1
Hi folks!
Don't know why nor how this update fucked up my "now playing" scripts for amarok. First script is this:
# amarok_xchat by sven kissner (aka chimaera)
#
# simple script to display the song currently played in amarok
__module_name__ = "amarok_xchat"
__module_version__ = "0.2"
__module_description__ = "python module for xchat to display titles playing in amarok"
import xchat
import commands
def amarok_send(word, word_eol, userdata):
xchat.command('np: ' + commands.getoutput('dcop amarok player artist') + " - " + commands.getoutput('dcop amarok player album') + " - " + commands.getoutput('dcop amarok player title'))
return xchat.EAT_ALL
xchat.hook_command('amarok', amarok_send)
xchat.prnt('amarok_xchat v0.2 loaded..')
The error is:
Traceback (most recent call last):
File "/home/sushi/.xchat2/amarok_xchat_0.2.py", line 10, in <module>
import commands
ImportError: No module named commands
Error loading module /home/sushi/.xchat2/amarok_xchat_0.2.py
Second script:
#! /usr/bin/env python
__module_name__ = "amarok display"
__module_version__ = "1.0"
__module_description__ = "amarok display"
import xchat
from os import popen
from random import randint
import string
from urllib import unquote
def show_song(word, word_eol, userdata):
########################## CONFIGURATION ######################
#
#Written by Moobert and Eno_
#
##You can your own xchat colours in the song display by editing the below:
#
#
info_name = 9
first_bracket = 5
second_bracket = 7
song_info = 8
#
#then type;
#/disork
# to show the song information.
#/disrok help
# to get a list of other commands.
#
#problems/ideas:
# Drop one of us a line on server irc.odinnet.ca, in #oldskool
#
##############################################################
songdata = ''
arun = 0
def zeroadd(info):
if len(str(info)) < 2:
return '0'+str(info)
else:
return ''+str(info)
c = [zeroadd(info_name), zeroadd(first_bracket), zeroadd(second_bracket), zeroadd(song_info)]
def getinfod(info):
return popen("dcop amarok default "+info,"r").read().strip()
for line in popen("dcop 2> /dev/null","r").readlines():
if 'amarok' in line:
arun = 1
if int(getinfod('status')) == 2:
arun = 2
def getVolume():
if (getinfod('getVolume') == "100"):
return "110"
else:
return getinfod('getVolume')
def randn():
return zeroadd(randint(0, 15))
def getRating():
score = int(getinfod('score'))
if (int(getinfod('trackPlayCounter')) == 0):
return "Not Applicable"
if (score <= 20):
return "Abominable"
elif (score > 20 and score <= 40):
return "Bad"
elif (score > 40 and score <= 60):
return "Average"
elif (score > 60 and score <= 80):
return "Good"
elif (score > 80):
return "Excellent"
def getQuality():
sample = str(int(getinfod('sampleRate'))/1000)
bitrate = getinfod('bitrate').strip(string.letters + ' ')
return bitrate + '/' + sample
def getPlayCounter():
if (int(getinfod('trackPlayCounter')) == 0):
return "Never before"
elif (int(getinfod('trackPlayCounter')) == 1):
return "Once before"
else:
return getinfod('trackPlayCounter') + " times before"
if arun > 0:
if len(word) > 1:
if word[1] == 'rand':
c = [randn(), randn(), randn(), randn()]
elif word[1] == 'vol':
getinfod('setVolume '+word[2])
print 'Amarok\'s volume set to ' + word[2] + '%'
arun = -1
elif word[1] == 'stop':
getinfod('stop')
arun = -1
elif word[1] == 'play':
getinfod('play')
arun = -1
elif word[1] == 'prev':
getinfod('prev')
arun = -1
elif word[1] == 'next':
getinfod('next')
arun = -1
elif word[1] == 'send':
file = unquote(getinfod('encodedURL')).replace('file:', '')
songdata = 'dcc send ' + word[2] + ' "' + file + '"'
arun = -1
else:
print """
Valid commands are:
/disrok rand Display amarok's currently playing song using random colors
/disrok stop Stop amarok
/disrok play Resume amarok
/disrok prev Play previous song in amarok playlist
/disrok next Play next song in amarok playlist
/disrok vol <0-100> Set audio volume in amarok
/disrok send <nick> Send current playing song to nick
/disrok Display amarok's currently playing song
"""
arun = -1
if arun > 1:
isplaying = 'me ' + c[0] + 'is playing:' + c[1] + '[' + c[2] + '[' + c[3] + '"' + getinfod('title') + '"' + c[2] +' by ' + c[3] + '"' + getinfod('artist') + '"' + c[2] + ' from the album ' + c[3] + '"' + getinfod('album') + '"' + c[2] + ']' + c[1] + ']'
quality = c[0] + 'Quality:' + c[1] + '[' + c[2] + '[' + c[3] + getQuality() + c[2] + ']' + c[1] + ']'
position = c[0] + 'Position:' + c[1] + '[' + c[2] + '[' + c[3] + getinfod('currentTime')+' of '+getinfod('totalTime') + c[2] + ']' + c[1] + ']'
volume = c[0] + 'Volume:' + c[1] + '[' + c[2] + '[' + c[3] + getVolume() + '%' + c[2] + ']' + c[1] + ']'
played = c[0] + 'Played:' + c[1] + '[' + c[2] + '[' + c[3] + getPlayCounter() + c[2] + ']' + c[1] + ']'
score = c[0] + 'Rating:' + c[1] + '[' + c[2] + '[' + c[3] + getRating() + c[2] + ']' + c[1] + ']'
songdata = isplaying + ' ' + quality + ' ' + position + ' ' + volume + ' ' + played + ' ' + score
else:
if arun == 1:
print "amarok doesn't seem to be playing..."
elif arun == 0:
print 'load amarok, or check that dcop is running.'
xchat.command(songdata)
return xchat.EAT_ALL
xchat.hook_command("disrok", show_song)
print 'Display amarok loaded, type "/disrok help" for a command list'
and the error by loading is this:
Traceback (most recent call last):
File "/home/sushi/.xchat2/disrokxchat.py", line 8, in <module>
from os import popen
ImportError: No module named os
Error loading module /home/sushi/.xchat2/disrokxchat.py
Any idea with that? Both scripts were working well before the update...
Album reviews (in german): http://schallwelle.filzo.de
Offline
Hmm, great! I think this one got compiled against Python 2.5 from testing
You're running 2.4 from current right?
Offline
Offline
Updated xchat to 2.8.0 now, built with python 2.4 this time
Offline
Thanks a lot, but in fact it doesn't help me any further with the problem. The first script loads without complaining but when typing "/amarok" simply nothing happens. No errors, nothing. The second script comes up with following error:
Traceback (most recent call last):
File "/home/sushi/.xchat2/disrokxchat.py", line 140, in show_song
score = c[0] + 'Rating:' + c[1] + '[' + c[2] + '[' + c[3] + getRating() + c[2] + ']' + c[1] + ']'
File "/home/sushi/.xchat2/disrokxchat.py", line 69, in getRating
score = int(getinfod('score'))
ValueError: invalid literal for int(): 91.000000
Last edited by Susu (2007-02-09 20:15:42)
Album reviews (in german): http://schallwelle.filzo.de
Offline
Any ideas how to fix it or what went wrong? I like these scripts alot...
Album reviews (in german): http://schallwelle.filzo.de
Offline
I've got the same problem with disrok on ubuntu. After not finding a solution via google I changed it the folowing way. the decimal numbers for the ratings can't be treared as int therefore I changed the type to float.
Here's the patch.
69,70c69,70
< score = float(getinfod('score'))
< if (float(getinfod('trackPlayCounter')) == 0):
---
> score = int(getinfod('score'))
> if (int(getinfod('trackPlayCounter')) == 0):
Offline
I seem to have a similar problem, but I don't see how the fix Rondom posted would be implemented in my case. I had an mpd script that stopped working, and no other mpd script I could find would work. They all had the same or similar problems. Here is an example of an error I get upon attempting to load the script:
Traceback (most recent call last):
File "/home/eric/.xchat2/mpd.py", line 19, in ?
import commands
ImportError: No module named commands
Error loading module /home/eric/.xchat2/mpd.py
The error is very similar to the error Susu posted, as you can see. Here is the script:
__module_name__ = "X-Chat MPD_Info Script"
__module_version__ = "0.1.0.1"
__module_description__ = "Prints Music Player Demon info"
__module_author__ = "Michael Edwards <eddy@lug-norderstedt.de>"
# This is the MPD_Info Script, written by me ^^ ;)
# Features:
# You can Display the current song or the current radio stream.
# The script detect, if it is a song or an stream, and toggle the output
# of mpd.
# Known commands:
# mpd :displays current song/stream information in to the current channel
# mpd_stats :displays the stats of the mpd server in the current channel
# mpd_play :toggles between play and pause
# mpd_stop :stops mpd from playing
# mpd_next :plays next song, and jump to the beginning of the list if the end is reached
# mpd_local :prints song information for you
import xchat
import commands
def mpd_info_full(word, word_eol, userdata):
# Title full #
volume = commands.getoutput("mpc volume | sed 's/volume://g' | sed 's/ //g' | sed 's/%/ %/'")
notitle = commands.getoutput("mpc | wc -l")
timetot = commands.getoutput("mpc --format '[%time%]' | head -n1")
timeof = commands.getoutput("mpc | grep playing | tr ' ' '\012' | grep :")
url = commands.getoutput("mpc --format '%file%' | head -n1")
stream = commands.getoutput("mpc --format '%file%' | grep http:// | wc -l")
streamtitle = commands.getoutput("mpc --format '[%title% (%name%)]' | head -n 1")
title = commands.getoutput("mpc --format '[%artist% - %title%]' | head -n 1 | sed 's/ - $//;s/^ - //'")
if notitle == "1": xchat.command("me is listening to -=(\002 defintiv nothing\002 )=-")
else:
if stream == "1":xchat. command("me is listening to -=(\002 %s - %s - %s\002 )=-" % (streamtitle, url, volume))
else: title = xchat.command("me is listening to -=(\002 %s - %s of %s - Volume %s\002 )=-" % (title, timeof, timetot, volume))
return xchat.EAT_ALL
xchat.hook_command("mpd", mpd_info_full, help="Prints MPD info")
def mpd_local_info(word, word_eol, userdata):
# Title local #
title = commands.getoutput("mpc | head -n 1")
print("you are listening to %s" % title)
return xchat.EAT_ALL
xchat.hook_command("mpd_local", mpd_local_info, help="Prints MPD info")
def mpd_stats(word, word_eol, userdata):
# Stats #
title = commands.getoutput("mpc stats | sed '/^$/d; s/^/\002 ][ \002/' | tr -d '\n'| sed 's/$/\002 ]/g; s/ ]//'")
xchat.command("me Music Player Demon Status: -={\002 %s }=-" % title)
return xchat.EAT_ALL
xchat.hook_command("mpd_stats", mpd_stats, help="Prints MPD Stats")
def mpd_play(word, word_eol, userdata):
# MPD play/pause toggle; it's a hack, cause I didn't find a way to include "mpc toggle". ;) #
playing = commands.getoutput("mpc | grep playing | wc -l")
title = commands.getoutput("mpc | head -n 1")
play = commands.getoutput("mpc play | head -n 1")
if playing == "0": print("mpd starts playing: %s" % play)
else:
commands.getoutput("mpc pause")
print("mpd is paused")
return xchat.EAT_ALL
xchat.hook_command("mpd_play", mpd_play, help="Prints MPD info")
def mpd_stop(word, word_eol, userdata):
# Stops MPD playing #
commands.getoutput("mpc stop")
print("mpd stops playing")
return xchat.EAT_ALL
xchat.hook_command("mpd_stop", mpd_stop, help="Prints MPD info")
def mpd_next(word, word_eol, userdata):
# Go to the next song #
commands.getoutput("mpc next")
notitle = commands.getoutput("mpc | wc -l")
if notitle == "1": commands.getoutput("mpc play")
print("mpd jumps to next song")
return xchat.EAT_ALL
xchat.hook_command("mpd_next", mpd_next, help="Prints MPD info")
print "X-Chat2 MPD_info Script [0.1.0.1] by Zappi Successfully loaded!"
Sorry if this problem was already solved, but I'm not sure exactly what I'm supposed to do to fix it.
Offline
Do you have python 2.4 installed? Or just the 2.5?
python24 pkg might be your best friend..
At least worth trying
Offline
Pages: 1