aMSN Forums
August 21, 2018, 07:30:17 am *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: New forum for aMSN !!
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: [bug report]Music plugin shows incorrect artist information  (Read 11308 times)
arucard
Newbie

Offline Offline

Posts: 4


View Profile
« on: March 16, 2011, 09:39:35 am »

Using amarok2 on linux, the response to retrieving the artist variable in infoamarok2 is the line containing albumartist as well as artist. This is because the word artist is used to grep those lines, which is contained in artist as well as albumartist. This causes aMSN to show both names when using %artist in your nickname, with "album" in front of the albumartist, since that isn't removed. This problem might also occur with other players that retrieve their info in the same way.

This is easily fixed by changing the infoamarok2 file; just change "grep artist" to "grep ^artist" to make it ignore the albumartist. It might be a good idea to do the same for the grep values of the other  variables, in case the metadata that's retrieved changes again. I hope this is helpful to someone having this same problem. I looked around on the forum, but couldn't really find anything about this, so maybe this isn't a problem for many people.
Logged
alexandernst
Developers
Super Power User
*
Offline Offline

Posts: 886



View Profile WWW
« Reply #1 on: March 16, 2011, 06:02:37 pm »

Thanks for the tip arucard, I'm changing that right now Wink
Logged
arucard
Newbie

Offline Offline

Posts: 4


View Profile
« Reply #2 on: March 24, 2011, 02:37:43 am »

I also tried to use the GetStatus metadata to specify the status variable for amarok2, but for some reason this doesn't work. Currently, the script retrieves the position of the song and if it's 0 (stopped), it sets the status to 0. When i use GetStatus, i store this in a variable called "playing" and this gives 0 when the song is playing. So when the playing variable is 0, i set the status to 1 and 0 otherwise. But when i do this, the songs are no longer displayed correctly.
This is the change in the script
default:
Code:
        position=`qdbus org.kde.amarok /Player PositionGet`
        if [ $position == 0 ]
        then
          status=0
        else
          status=1
        fi
Changed one:
Code:
       playing=`qdbus --literal org.kde.amarok /Player GetStatus | sed s/[^0-9]*//g | cut -c 1`
       if [ $playing == 0]
        then
         status=1
        else         
         status=0
        fi
Any ideas on why this doesn't work? The reason for this change is to make it work when a song is only paused, but not playing. Currently, the song is only removed from the nickname when the song is stopped, but if you pause it, it just stays in the nickname continuously. I thought this might work, but i have no idea what went wrong. I checked the outcome of the command and it correctly shows either a 0, 1 or 2, depending on the status of the player. Any help would be appreciated.
Logged
alexandernst
Developers
Super Power User
*
Offline Offline

Posts: 886



View Profile WWW
« Reply #3 on: March 26, 2011, 05:10:48 pm »

Could you post the full script? Maybe I could help you.
Logged
arucard
Newbie

Offline Offline

Posts: 4


View Profile
« Reply #4 on: March 26, 2011, 09:28:27 pm »

Could you post the full script? Maybe I could help you.
Here's the full script, though all the rest is just the default script for amarok2
Code:
#! /bin/bash
# Shell script to get informations about the current song playing in Amarok

#Amarok is launched ?
AMAROK=`ps -e | grep [a]marok`
if [ -n "$AMAROK" ]
then
        #Yes so we get the info
        #artist=`qdbus org.kde.amarok /Player GetMetadata | grep artist`
        title=`qdbus org.kde.amarok /Player GetMetadata | grep title`
        artist=`qdbus org.kde.amarok /Player GetMetadata | grep ^artist`
        path=`qdbus org.kde.amarok /Player GetMetadata | grep location | sed -e s/%20/\ /g`
        artpath=`qdbus org.kde.amarok /Player GetMetadata | grep arturl | sed -e s/%20/\ /g`
        album=`qdbus org.kde.amarok /Player GetMetadata | grep album:`
        playing=`qdbus --literal org.kde.amarok /Player GetStatus | sed s/[^0-9]*//g | cut -c 1`
        if [ $playing == 0]
        then
          status=1
        else
          status=0
        fi

        #regsub -all "%20" "what%20ever" tata blabla
        #set test [string map { "%20" "ta" } $path]
        #bla="allo"
        #regsub -all (jni) $path {!\1!} bla

        echo $status
        echo ${artist/"artist: "/""}
        #echo ${path/"location: "/""}
        echo ${title/"title: "/""}
        echo ${path/"location: file:"/""}
        echo ${artpath/"arturl: file:"/""}
        echo ${album/"album: "/""}
else
        #No so we set to state stopped
        echo 0
fi

exit 0
Just to clarify, the command used to set the "playing" variable works correctly when executed on the command-line so I'm fairly sure that that variable gets set to the correct value. This value can be 0, 1 or 2, representing the state of playing, paused or stopped respectively, which has been tested to work correctly on the command-line with the command for the "playing" variable. So that's why I can't figure out what's wrong with this.
« Last Edit: March 27, 2011, 12:55:33 pm by arucard » Logged
alexandernst
Developers
Super Power User
*
Offline Offline

Posts: 886



View Profile WWW
« Reply #5 on: March 27, 2011, 06:04:22 pm »

Oh, I see. Your logic is wrong. You must meet 2 conditions for detecting "pause".

$position should be > than 0 and playing should be 1. (well, that could detect wrong "pause" if song was paused at 00:00, but that's really difficult, isn't it? :p)

Anyways, here you have:

Code:
#! /bin/bash
# Shell script to get informations about the current song playing in Amarok

#Amarok is launched ?
AMAROK=`ps -e | grep [a]marok`
if [ -n "$AMAROK" ]
then
#Yes so we get the info
#artist=`qdbus org.kde.amarok /Player GetMetadata | grep artist`
title=`qdbus org.kde.amarok /Player GetMetadata | grep title`
artist=`qdbus org.kde.amarok /Player GetMetadata | grep artist`
path=`qdbus org.kde.amarok /Player GetMetadata | grep location | sed -e s/%20/\ /g`
artpath=`qdbus org.kde.amarok /Player GetMetadata | grep arturl | sed -e s/%20/\ /g`
album=`qdbus org.kde.amarok /Player GetMetadata | grep album:`
position=`qdbus org.kde.amarok /Player PositionGet`
playing=`qdbus --literal org.kde.amarok /Player GetStatus | sed s/[^0-9]*//g | cut -c 1`
if [ $position == 0 ]
then
  status=0
else
  if [ $playing == 1 ]
  then
    status=0
  else
    status=1
  fi
fi

#regsub -all "%20" "what%20ever" tata blabla
#set test [string map { "%20" "ta" } $path]
  #bla="allo"
#regsub -all (jni) $path {!\1!} bla

echo $status
echo ${artist/"artist: "/""}
#echo ${path/"location: "/""}
echo ${title/"title: "/""}
echo ${path/"location: file:"/""}
echo ${artpath/"arturl: file:"/""}
echo ${album/"album: "/""}
else
#No so we set to state stopped
echo 0
fi

exit 0


Feel free to change the nested if/else with a signel if with more logic. I always hated bash's [[]] (()) and family. Also, imho nested if's are easier for revieweing/maintaining.

Regards.
Logged
arucard
Newbie

Offline Offline

Posts: 4


View Profile
« Reply #6 on: March 27, 2011, 09:22:59 pm »

Oh, I see. Your logic is wrong. You must meet 2 conditions for detecting "pause".

$position should be > than 0 and playing should be 1. (well, that could detect wrong "pause" if song was paused at 00:00, but that's really difficult, isn't it? :p)
...
I'm sorry, turns out my problem had nothing to do with amsn or this plugin. It seems I was missing a space before the closing square bracket ( ] ) in my if statement. I found out when i realized i could just run the infoamarok2 script from the command-line, which showed this as an error.

As for the conditions to detect pause state of a song, it seems that just the GetStatus method is enough. This would correctly recognize when a song is playing and is able to differentiate it from paused and stopped state, as descrverkeibed in the MPRIS specification, even if paused at 00:00 Cheesy

I noticed that this plugin interfaces with many players through MPRIS, so maybe this could be used in those as well, making them detect paused songs as well. If you change the number on the cut command to 2, 3 or 4 you can get the values for whether the player is playing in shuffle mode, repeat song mode or repeat all mode respectively. I'm not sure if there's any use for knowing those values, but they're available too, if someone can think of something fun to do with them Tongue

I'd like to thank you for taking the time to help me with this, and of course for making the plugin itself.  Grin For completeness sake, I'll post the full working script here.
Code:
#! /bin/bash
# Shell script to get informations about the current song playing in Amarok

#Amarok is launched ?
AMAROK=`ps -e | grep [a]marok`
if [ -n "$AMAROK" ]
then
        #Yes so we get the info
        #artist=`qdbus org.kde.amarok /Player GetMetadata | grep artist`
        title=`qdbus org.kde.amarok /Player GetMetadata | grep title`
        artist=`qdbus org.kde.amarok /Player GetMetadata | grep ^artist`
        path=`qdbus org.kde.amarok /Player GetMetadata | grep location | sed -e s/%20/\ /g`
        artpath=`qdbus org.kde.amarok /Player GetMetadata | grep arturl | sed -e s/%20/\ /g`
        album=`qdbus org.kde.amarok /Player GetMetadata | grep album:`
        playing=`qdbus --literal org.kde.amarok /Player GetStatus | sed s/[^0-9]*//g | cut -c 1`
        if [ $playing == 0 ]
        then
                status=1
        else
                status=0
        fi

        #regsub -all "%20" "what%20ever" tata blabla
        #set test [string map { "%20" "ta" } $path]
        #bla="allo"
        #regsub -all (jni) $path {!\1!} bla

        echo $status
        echo ${artist/"artist: "/""}
        #echo ${path/"location: "/""}
        echo ${title/"title: "/""}
        echo ${path/"location: file:"/""}
        echo ${artpath/"arturl: file:"/""}
        echo ${album/"album: "/""}
else
        #No so we set to state stopped
        echo 0
fi

exit 0
Logged
alexandernst
Developers
Super Power User
*
Offline Offline

Posts: 886



View Profile WWW
« Reply #7 on: March 27, 2011, 11:04:41 pm »

I'm gonna implement that ASAP.
Thanks for the suggestion Wink
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!