Commits

Anonymous committed 254a7aa

Init containing all files

  • Participants

Comments (0)

Files changed (3)

File rcplayer.brc

+#!/usr/bin/env brc
+HELP='Commands:		Play\Pause RM\Remove Stop Shuffle Repeat Next Previous Mute Notify
+Vol - + Num
+Pos <(Pull - less) (Push + more) [+-]seconds>';nl='
+'
+
+Notifiers=(XSetRoot Dzen Galago stdout)
+# Be sure to name them exact
+Players=(Cmus XMMS2 audacious)
+	
+	fn pgrep { builtin pgrep -i $* > /dev/null } # pgrep -f
+		if (!pgrep $Players) { echo 'Not running anything' ; exit 1 }
+# this file should already have a number inside
+  MuteFile=/tmp/PlayerVolume
+  Current=/tmp/PlayerCurrent
+		
+fn audacious { cmd=audtool
+ logo='/usr/local/share/icons/hicolor/48x48/apps/audacious.png'
+ fn Next		{ $cmd playlist-advance }
+ fn Prev		{ $cmd playlist-reverse }
+ fn PP			{ $cmd playback-playpause }
+ fn Repeat		{ $cmd playlist-repeat-toggle } # doesnt work
+ fn Shuffle		{ $cmd playlist-shuffle-toggle }
+ fn Stop		{ $cmd playback-stop }
+ fn Volume		{ $cmd set-volume $* }
+ fn Position 	{ $cmd playback-seek $* }
+ fn Mute		{ Vol=`{ $cmd get-volume } }
+ fn rmCurrent	{ getfile=`{ $cmd current-song-filename } 
+   ~ $getfile *^'?1' && getfile=`{ echo $getfile | cut -d'?' -f 1 } # introducing, a new bug!
+		Current=`{ $cmd current-song }
+		ID=`{ $cmd playlist-position }
+	  echo 'Song:'$ID'='$Current
+	  $cmd playlist-advance
+	  $cmd playlist-delete $ID }
+ fn Info {	*='current-song-'
+	*=(	current-song
+	  $*^'tuple-data '^(title artist album file-name)
+		$*^length
+	  $*^'tuple-data '^(mime-type quality copyright codec)
+		$*^info
+	) ; *=`{ echo $* }
+	$cmd $*
+ }
+}
+ 	
+fn Cmus	{	cmd=cmus-remote
+ logo='/usr/local/share/icons/hicolor/48x48/apps/xfce-terminal.png'
+ fn Next		{ $cmd -n }
+ fn Prev		{ $cmd --prev }
+ fn PP			{ ~ `{ $cmd -C status } 'playing' && {
+	$cmd --pause } || { $cmd --play } }
+ fn Shuffle		{ $cmd --shuffle }
+ fn Repeat		{ $cmd --repeat }
+ fn Stop		{ $cmd --stop }
+ fn Volume		{ $cmd -v $* }
+ fn Position	{ $cmd --seek $* }
+ fn Mute		{ Vol=`{ $cmd -C status } ; Vol=$Vol($#Vol) }
+ fn rmCurrent	{ getfile=`{ $cmd -Q | awk 'NR==2 && sub(/^file /, "")' }
+		$cmd -Q | awk 'match($1, /tag/), sub(/^tag /, "", $0)'
+		$cmd -C win-sel-cur player-next win-remove win-sel-cur }
+ fn Info		{
+	$cmd -Q | grep -v '^set' > $Current
+	awk 'sub(/^tag /, "")' $Current
+	grep -v -e '^tag' -e '^file' $Current
+	*=`{ grep '^file' $Current } ; shift ; du -h $^*
+ }
+ fn StatusContent {
+	fn $0 { shift $1 ; echo -n $* }
+
+	for (* in `` $nl {cmus-remote -Q}){
+	 *=`{ echo -n $* }
+	  if (~ $1 status file duration position){
+		$1 = `{ $0 2 $* }
+	   } else {
+		$2 = `{ $0 3 $* }
+	} }
+ }
+}
+			
+fn XMMS2	{	cmd=nyxmms2
+ logo='/usr/local/share/pixmaps/xmms2-48.png'
+ fn Next	{ $cmd next }
+ fn Prev	{ $cmd prev }
+ fn PP		{ $cmd toggle }
+ fn Stop	{ $cmd stop }
+ fn Volume	{ $cmd volume $* }# set channels? nah its a waste
+ fn Repeat	{ $cmd config 'playlist.repeat_all=1' } # plus others
+ fn Position{ $cmd seek $* }
+ fn Mute	{ Vol=`{ $cmd volume_list } ; Vol=$Vol($#Vol) }	
+ fn rmCurrent	{
+	getfile=`{ $cmd info | tail -n1 | cut -d/ -f3- | tr -s '+' ' ' }
+	ID=`{ $cmd info | awk 'match($2, /id/) { print $4 }' }
+	$cmd next ; $cmd remove $^ID }
+ fn Info	{
+	$cmd info | awk '/title/ {$1="";$2="";$3="";print $0}'
+	$cmd info | awk 'gsub(/./, "", $1)  $2 !~ /lmod|mime|laststarted|added|channels/'
+ }
+}
+
+fn XSetRoot { Info=`{ Info | sed 1q }
+	xsetroot -name $^Info }
+	
+fn Galago	{
+    Info=`{ Info | sed -e 's/&/&amp;/g' -e 's/</&lt;/g' -e 's/>/&gt;/g' }
+	  Title=('Title: ' `{ Info | sed 1q}) ; Artist=`{Info|grep -i artist} #awk match?
+	notify-send $^Title $^Artist -i $logo -t 5000 }
+	
+fn Dzen { POS=`{ xrandr | tr -s x   ' ' |\
+	awk '/\*/ {
+		W = $1 / 2		#(	Hover	)#
+		X = $1 - 450	#(	Width	)#
+		Y = $2 - 18		#(	Height	)#
+	} END { print W" "X" "Y }' }
+
+	FG=yellow ; Show=15 ; Lines=`{ Info | wc -l }
+	Info | dzen2 -fg $FG -p $Show -w $POS(1) -x $POS(2) -y $POS(3) -l $Lines &
+}
+
+fn MuteSet {
+	~ $Vol 0 && { Volume `{ cat $MuteFile }
+		} || {	  echo $Vol > $MuteFile ; Volume 0
+} }
+
+for (x in $Players){ pgrep $x && $x && break }
+
+
+# turn this into a parser that would give the returning command as output
+switch($1){
+ case [Nn][Ee]*			;	Next
+ case [Pp][Rr]*			;	Prev
+ case [Pp][Ll]* [Pp][Aa]*	;	PP
+ case [Rr][Ee]*			;	Repeat
+ case [Ss][Hh]*			;	Shuffle
+ case [Ss][Tt]*			;	Stop
+ case [Vv][Oo]*		#Vol
+  switch ($2){	# <(lower less) (raise more) [+-] volume>
+	case - [Ll]^(ower ess)		; *='-10'
+	case + [Rr]aise [Mm]ore		; *='+5'
+	case [Mm][Uu][Tt][Ee]		; Mute ; MuteSet
+	case *[A-z]*	; echo 'Err: Ints only' ; exit 1
+	case *[+-]		; echo 'Err: Are you bananas!?' ; exit 1
+	case [-+]*					; *=$2
+	case [0-9] [0-9]^[0-9] 100	; *=$2
+	case *			 	; echo 'Err: ermm what?' ; exit 1
+   } # &&
+  Volume $*
+ case [Pp]os*	[Jj]ump		# Position
+  switch ($2){	# <(Pull less) (Push more) [+-]seconds >
+	case (-) [Ff]orward [Pp]ull [Ll]ess		;	*='-50'
+	case (+) [Bb]ackward [Pp]ush [Mm]ore	;	*='+50'
+	case *[A-z]*	; echo 'Err: Ints only' ; exit 1
+	case *[+-]		; echo 'Err: Are you bananas!?' ; exit 1
+	case [-+]*		; *=$2
+	case [0-9]^*	; *=$2
+	case *		 	; echo 'Err: ermm what?' ; exit 1
+   }
+  Position $*
+ case [Mm][Uu][Tt][Ee] # Mute
+	 Mute # Saves the current volume for later
+	 MuteSet
+ case [Rr]^[Mm] [Rr]emove
+	ifs='
+'	;	rmCurrent
+	echo -n `{ du -h $getfile | awk '{print $1}' }' '
+	~ $2 [yY] && { rm -vf $^getfile } || { rm -i $^getfile }
+	echo $getfile >> /tmp/deletedmusic
+ case [Nn]otify	[Nn][Oo]*
+  if (~ $#* 2){
+	switch($2){	#( hope dzen isnt your status bar )#
+	 case [Dd]zen
+	 	pgrep dzen2 && { pkill -2 dzen2 ; Dzen } || { Dzen }
+	 case [Gg]alago			; Galago
+	 case [Xx][Ss]et[Rr]oot	; XSetRoot
+	 case stdout	 		; Info }
+	} else { $Notifiers(1)
+  }
+ case *		; 	echo $HELP
+}
+
+###SYNOPSIS
+	rcplayer arguments [[+-]NUM]
+###DESCRIPTION
+ RCPlayer is a Wrapper amongst different music players.
+	Sends command to the running player
+
+###ARGUMENTS
+* Play
+* Pause
+* Remove/rm
+* Stop
+* Shuffle
+* Repeat
+* Next
+* Previous
+* Mute
+* Notify
+	+	Dzen
+	+	Galago
+	+	stdout
+	+	xsetroot
+* Volume [arg]
+	+ [+-]Vol		**	( Raise or lower by ) **
+	+ \-			**	( -10 ) **
+	+ \+			**	( +5 ) **
+	+ int			**	( will be INT ) **
+* Position	Jump [arg]
+	+ [+-]Pos		**	( Raise or lower by ) **
+	+ \-			**	( -50 )	**
+	+ \+			**	( +50 )	**
+	+ [HH:]MM:SS	**	( Depends on player ) **
+
+###SUPPORTS
+* Players:
+	+ Cmus
+	+ XMMS2
+	+ Audacious
+* Notification
+	+ Dzen
+	+ LibGalago (broken)
+	+ stdout
+	+ XSetRoot
+
+###SEE ALSO
+ + [audacious(1)][audacious]
+ + [audtool(1)][audacious]
+ + [cmus][cmus][(1)](	http://gitorious.org/cmus/cmus/blobs/master/Doc/cmus.txt)
+ + [cmus-remote(1)](	http://gitorious.org/cmus/cmus/blobs/master/Doc/cmus-remote.txt)
+ + [cmus-tutorial(7)](	http://gitorious.org/cmus/cmus/blobs/master/Doc/cmus-tutorial.txt)
+ + [xmms2(1)][xmms2]
+ + [nyxmms2(1)][xmms2]
+ + [b][brc][rc][rc][(1)][rcman]
+
+[rc]:			https://bitbucket.org/rsc/plan9port
+[brc]:			http://paganbooks.eu/software/article/rc
+[rcman]:		http://man.cat-v.org/plan_9/1/rc
+[audacious]:	http://audacious-media-player.org
+[cmus]:			http://cmus.sourceforge.net
+[xmms2]:		http://xmms2.org
+
+###SPEC
+1.	Checks to see which player is running
+2.	First one it finds, it runs the command with arguments
+
+###LICENSE
+Copyright (c) 2012, Khwerz@gmail.com
+
+Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.
+
+THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+

File rcplayer.todo

+rcplayer
+  no args:
+	display running players & help
+
+go by percents in a jump
+ volume too?
+
+
+
+
+
+status has now changed to info
+status displays the status of the player
+info displays the current song info
+what displays a 1 liner displaying the song info important part
+
+trouble is
+
+
+
+fn status { cmus-remote -Q | awk ' match ($1,"status") { print $2 }' }
+fn status { audtool playback-status }
+
+
+# given the nature of this and tha many players change this shit
+0 = playing
+everything else means not
+
+command for one liner
+command for all info
+
+info	-- Displays full song and all info
+status	-- displays status
+
+Mute uses alsamixer or mixer
+
+make 2rcplayers one uses the mixer, the other the internal player function
+
+
+Support 
+	Music Player Daemon (mpd)
+
+
+Improve
+	Galago	[[	use url(de en)code ]]
+	XMMS2
+	Notify	-	If a song doesnt have a title, use the filename
+
+Bugs
+
+	Audacious			-	spc's $getfile workaround, check for bugfix on new versions
+	/tmp/PlayerVolume	- 	only holds 1 value... waste ( var daemon? )
+	Cmus -	Cannot remove song from Playlist
+	Cmus -	$logo depends on xfce
+
+
+
+Feature
+	run $cmd to all players running instead of 1  ( As a flag or check too see which player is stopped ? )
+
+
+	BigSwitch
+		translates arg into a function that all players know
+		leaving ( send to all running players easier to implement )
+		$cmd^$arg
+		cmd=(audacious cmus)^(next)
+		$cmd
+			audacious next
+			cmus next
+				cmus and audacious are actually wrappers so this should run
+
+
+	Cmus - 	/tmp/PlayerCurrent	-	unnecessary file ( keep it all on a pipe ? )
+	
+
+
+	- (Feature) if ~ $#playersrunning 1 || check status ; ~ $status stopped || dont run this players function
+	- (Feature) Pass $cmd to all players running instead of 1  ( As a flag or check too see which player is stopped ? )
+	- [Notify Galago] has too much output to handle, so we need to diminish it... probably only display Status{} first line?
+	- [Pos Tilt] Add tilt option to Pos, which would make the Position of current song Random!