File: eControl

package info (click to toggle)
exaile 0.2.14%2Bdebian-2.3
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 6,836 kB
  • ctags: 3,187
  • sloc: python: 23,677; ansic: 224; makefile: 157; perl: 137; sh: 123; sql: 80
file content (185 lines) | stat: -rwxr-xr-x 5,978 bytes parent folder | download | duplicates (2)
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
#!/bin/bash
#
# A script for Controlling Exaile
# Copyright (C) 2007  Nicholas Omann <Nicholas.Omann@member.fsf.org>

# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

#  README:
#
#  1. Installing
#    First, use: chmod +x eControl to make it executable
#          Also: chmod 755 /usr/bin/eControl
#
#    Second, find a place to store eControl (option a is recommended).
#      a) place it in your /usr/bin
#        -This will allow you to click on it at any time in order to use it
#        -Will be used in examples
#
#      b) call it using /path/to/file/eControl
#        -This way you must always call it using the path
#      
#  2. Using eControl
#
#    a)Running from XChat - adding user commands
#      You can run eControl from XChat in many ways. The most simple way
#      is to create a user command for it. To do that click on Settings->
#      Advanced -> User Commands... Click add new command. At which point
#      the following commands are recommended:
#      exec -o eControl playing color
#      exec eControl next
#      exec eControl play
#      You will place these in the 2nd box on the bottom. The name you put
#      in the first box will be able to be used to call teh command then
#      if you type /name (name being whatever name you chose).
#      
#    b)Running from XChat - without user commands
#      You can choose not to create user commands. If you then want to run
#      eControl you will have to type the whole thing every time.


VERSION="1.0"
AUTHOR="Nicholas Omann"

# Color choices:
#  red "\000321"  
#  blue "\000350"
#  green "\000309"

TEXT_COLOR_1="\000350"  
TEXT_COLOR_2="\000321" 

# Configures dbus to make method calls
DBUS="dbus-send --type=method_call --dest=org.exaile.DBusInterface /DBusInterfaceObject"
#Configures dbus to print replies
DBUSR="dbus-send --print-reply --type=method_call --dest=org.exaile.DBusInterface /DBusInterfaceObject"

#Tests to make sure that Exaile is actually running(avoids spamming dbus errors
EXAILE_TEST="$(ps -F -u $(whoami) -U $(whoami) | grep exaile | grep -v grep)"
if [ "$EXAILE_TEST" == "" ] ; then
  echo "Exaile is not on."
  exit 0
fi

# Start of case statment that does all the work
case "$1" in
  help) #displays help
    echo "Type eControl [command]"
    echo "Commands:"
    echo "          next"
    echo "          play (also pauses)"
    echo "          playing [time] [rating] [color]"
    echo "          prev"
    echo "          rate [1..8]"
    echo "          version"
    echo "          volume [up,down] [1..100]"
  ;;
  version) # Displays Verion information
    echo "Version: $VERSION"
    echo "Made by: $AUTHOR"
  ;;
  volume)  # Changes volume (Defaults to increments of 10)
    if [ "$2" = "up" ] ; then
      if [ "$3" = "" ]
        then
          INC=10
        else
          INC=$3
      fi
        NULLCOMMANDOUTPUT="$($DBUS org.exaile.DBusInterface.increase_volume int32:$INC)"
    fi
    
    if [ "$2" = "down" ] ; then
      if [ "$3" = "" ] 
        then
          INC=10
        else
          INC=$3
      fi
        NULLCOMMANDOUTPUT="$($DBUS org.exaile.DBusInterface.decrease_volume int32:$INC)"  
    fi     
  ;;
   play) #plays but if playing pauses
    NULLCOMMANDOUTPUT="$($DBUS org.exaile.DBusInterface.play_pause)"
  ;;
  next) #Plays next song
    NULLCOMMANDOUTPUT="$($DBUS org.exaile.DBusInterface.next_track)"
  ;;
  prev) #Plays previous song
    NULLCOMMANDOUTPUT="$($DBUS org.exaile.DBusInterface.prev_track)"
  ;;
  rate)
    NULLCOMMANDOUTPUT="$($DBUS org.exaile.DBusInterface.set_rating int32:$2)"
  ;;
  playing)  #echo "is listening to $TITLE by $ARTIST from $ALBUM [$INDEX/$TOTAL] [Exaile v$EXAILE_VERSION]"
    TIME="$($DBUSR org.exaile.DBusInterface.current_position)"
    TIME=${TIME##*byte\ }
    MIN=0
    if (( $TIME >= 60 )) ; then
      while (( TIME >= 60)) ; do 
        let "MIN += 1"
        let "TIME -= 60"
      done
    fi
    TIMEF="$MIN:$TIME"
    TOTAL_TIME="$($DBUSR org.exaile.DBusInterface.get_length)"
    TOTAL_TIME=${TOTAL_TIME#*\"}
    TOTAL_TIME=${TOTAL_TIME%\"}
    ALBUM="$($DBUSR org.exaile.DBusInterface.get_album | grep \")"
    ALBUM=${ALBUM#*\"}
    ALBUM=${ALBUM%\"}
    ARTIST="$($DBUSR org.exaile.DBusInterface.get_artist)"
    ARTIST=${ARTIST#*\"}
    ARTIST=${ARTIST%\"}
    TITLE="$($DBUSR org.exaile.DBusInterface.get_title)"
    TITLE=${TITLE#*\"}
    TITLE=${TITLE%\"}
    RATING="$($DBUSR org.exaile.DBusInterface.get_rating)"
    RATING=${RATING##*int32\ }
    TOTAL="8"
    EXAILE_VERSION="$($DBUSR org.exaile.DBusInterface.get_version)"
    EXAILE_VERSION=${EXAILE_VERSION#*\"}
    EXAILE_VERSION=${EXAILE_VERSION%\"}
	  
	  #color options
	  if [ "$2" = "color" -o "$3" = "color" -o "$4" = "color" ] ; then
	    COLOR_1="$TEXT_COLOR_1"
	    COLOR_2="$TEXT_COLOR_2"
	  else
	    COLOR_1=""
	    COLOR_2=""
	  fi

	  OUTPUT="${COLOR_1}is listening"	  
	  if [ -n "$TITLE" ] ; then
	    OUTPUT="$OUTPUT to ${COLOR_2}$TITLE"
	  fi
	  if [ -n "$ARTIST" ] ; then
	    OUTPUT="$OUTPUT ${COLOR_1}by ${COLOR_2}$ARTIST"
	  fi
	  if [ -n "$ALBUM" ] ; then
	    OUTPUT="$OUTPUT ${COLOR_1}from ${COLOR_2}$ALBUM"
	  fi
	  if [ "$2" = "time" -o "$3" = "time" -o "$4" = "time" ] ; then
	    OUTPUT="$OUTPUT [$TIMEF/$TOTAL_TIME]"
	  fi
	  if [ "$2" = "rating" -o "$3" = "rating" -o "$4" = "rating" ] ; then
	    OUTPUT="$OUTPUT [$RATING/$TOTAL]"
	  fi
	  
	  echo -e "$OUTPUT ${COLOR_1}[Exaile v$EXAILE_VERSION]"
  ;;
  *) # Default case for invalid commands
    echo "Error - invalid command supplied to eControl try help"
  ;;
esac
exit 0