DSL Ideas and Suggestions :: XMMS Improvements



Hi, I think I have a solution fo you.

First about RPMs.

To extract RPMs or DEBs to tar.gz I use script I found a while ago and modified a bit to work with DSL ( I'm using gnu-utils.dsl, so if it doesn't work try that extension, for deb's you'll need 'ar' or use dsl-dpkg.dsl and do dpkg -x file.deb if I'm right)

Code Sample

#!/bin/bash
#set -x
###########################################################################
#
#       Shell program to Convert rpm and debian files to tar.gz format.
#
#       Copyright 2001, USM Bish <bish@nde.vsnl.net.in>.
#
#       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 F ree 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.
#
#
#       Usage:
#
#       2tgz.sh [ -h | --help ] [-d filename.deb] [-r filename.rpm]
#
#       Options:
#
#       -h, --help            Display this help message and exit.
#       -d  filename.deb      Convert .deb file to tar.gz
#       -r  filename.rpm      Convert .rpm file to tar.gz
#
#
#       Revisions:
#
#       Aug/02/2001     File created   .......... Ver 0.1
#       Aug/02/2001     deb converter created ... Ver 0.2
#       Aug/03/2001     rpm converter added  .... Ver 0.3  
#
#       Dependencies on other utils:
#
#       o less      In case not installed, change value of
#                   MY_PAGER to your pager (viz view/ more etc.)
#       o ar        Needed for debian file conversion
#       o rpm2cpio  Needed for rpm conversion
#       o cpio      - do -
#
###########################################################################


###########################################################################
#       Constants
###########################################################################

PROGNAME=$(basename $0)
VERSION="0.3"
TEMP_FILE=/tmp/${PROGNAME}.$$
VIEW_CONT=a  # view content after conversion : y=yes n=no a=ask

MY_PAGER=/usr/bin/less

###########################################################################
#       Functions
###########################################################################

function get_prefix
{
   echo $PACKAGE > $PROGNAME.1
   rev $PROGNAME.1 > $PROGNAME.2
   cat $PROGNAME.2 | cut -b 5- > $PROGNAME.1
   rev $PROGNAME.1 > $PROGNAME.2
   PREFIX=`cat $PROGNAME.2`
}

function view_tgz
{
  tar -tvvz < $PREFIX.tar.gz > $HOME/$PROGNAME.1
  cat $HOME/$PROGNAME.1 | awk '{print $1"\t"$3"\t"$6}' > $HOME/$PROGNAME.2
  echo -en "\nConstituents of tarball : $PREFIX.tar.gz\n\n" > $HOME/$PROGNAME.1
  echo -en "Permissions     Size    Contents\n\n" >> $HOME/$PROGNAME.1
  cat $HOME/$PROGNAME.2 >> $HOME/$PROGNAME.1
  cat $HOME/$PROGNAME.1 | $MY_PAGER
  clean_up
}

function done_message
{
  echo ""
  echo "Done .... Please unpack in a temporary directory"
  echo "Check that there are no filename conflicts ....."
  echo "You may like to do an *ldd* of binaries to check"
  echo "dependencies before installing."
  echo ""
  ls $PREFIX.*
  if [ "$VIEW_CONT" = "a" ]; then
   echo -en "\nView contents of "$PREFIX.tar.gz" [y/ n] .. "
   read YN
   if [ "$YN" = "y" ]; then
      view_tgz
   fi
  elif [ "$VIEW_CONT" = "y" ];then
    view_tgz
  fi
  echo "Bye ... "  
}
   
function clean_up
{
       rm -f ${TEMP_FILE}
       rm -f $PROGNAME.1
       rm -f $PROGNAME.2
}


function graceful_exit
{
       clean_up
       exit
}


function error_exit
{
       echo "${PROGNAME}: ${1:-"Unknown Error"}" >&2
       clean_up
       exit 1
}

function term_exit
{
       echo "${PROGNAME}: Terminated"
       clean_up
       exit
}


function int_exit
{
       echo "${PROGNAME}: Aborted by user"
       clean_up
       exit
}


function usage
{
       echo "Usage: ${PROGNAME} [-h | --help] [-d filename.deb] [-r filename.rpm]"
}

function helptext
{
       #####
       #       Function to display help message for program
       #       No arguments
       #####
       
       local tab=$(echo -en "\t\t")
               
       cat <<- -EOF-

       ${PROGNAME} ver. ${VERSION}    

       This is a program to Convert rpm and debian files to tar.gz format.
       
       $(usage)
       
       Options:
       
       -h, --help            Display this help message and exit.
       -d  filename.deb      Convert .deb file to tar.gz
       -r  filename.rpm      Convert .rpm file to tar.gz

       Example: ${PROGNAME} -d package.deb  (to convert a .deb file)
                       
       -EOF-
}      


###########################################################################
#       Program starts here
###########################################################################

# Trap TERM, HUP, and INT signals and properly exit

trap term_exit TERM HUP
trap int_exit INT

# Process command line arguments

if [ "$1" = "--help" ]; then
   helptext
   graceful_exit
fi

if [ "$1" = "" ]; then
  if [ "$2" = "" ]; then
     helptext
     graceful_exit
  fi
fi

# Process arguments - edit to taste

while getopts ":hd:r:" opt; do

   case $opt in
   
   d ) echo $PROGNAME"  Debian .deb conversion"

       PACKAGE="$2"
       get_prefix

       if [ -e $PACKAGE ]; then
           ar -x $PACKAGE
           rm -f control.tar.gz
           rm -f debian-binary
           mv data.tar.gz $PREFIX.tar.gz
           done_message
       else              # parm entered but incorrect
           echo "Debian package [$PACKAGE] not found"
           echo "Quitting ... "
           clean_up
           exit 1  
       fi
       ;;
   
   r ) echo $PROGNAME"  RedHat .rpm conversion"

       PACKAGE="$2"
       get_prefix

       if [ -e $PACKAGE ]; then
           PD=`pwd`
           mkdir /tmp/2tgz
           rpm2cpio $PACKAGE > /tmp/2tgz/$PREFIX.cpio
           cd /tmp/2tgz
           cpio -imd < $PREFIX.cpio 1> /dev/null 2> /dev/null
           TARGET=`ls -d */`
           tar -cvvzf $PREFIX.tar.gz $TARGET 1> /dev/null 2> /dev/null
           cp $PREFIX.tar.gz $PD
           cd /tmp
           rm -rf 2tgz/
           cd $PD
           done_message
       else              # parm entered but incorrect
           echo "RedHat package [$PACKAGE] not found"
           echo "RedHat package [$PACKAGE] not found"
           echo "Quitting ... "
           clean_up
           exit 1  
       fi
       ;;

   h ) helptext
       graceful_exit;;
       
   * ) usage
       exit 1

   esac

done

graceful_exit

#############################################################



Name it, ex . 2tgz.sh and  make it executable with chmod +x 2tgz.sh

It will ask you to view contents, if you wish default action to not to view contents change VIEW_CONT=a to VIEW_CONT=n

Ok, so now you would be able to get xmmsctrl to work.
After converting to tar.gz you can view the contents with emelfm and remove documentation or any other files, as I recall you need only xmmstrl, you can also check some examples provided in that rpm.
Then move back when emelfm asks you to repack and choose yes.
Now you have tar.gz that you can install with mydsl-load or by clicking myDSL in emelfm. ( you can also install freshly converted rpm, but it'll be larger )

If you wish you can copy xmmsctrl to another directory, create directory structure in unpacked tar.gz in emelfm and paste it to the location in this structure, ex. /opt/bin/xmmsctrl or /opt/xmms/xmmsctrl or /home/bin/xmmstrl

With xmmsctrl you can do many neat actions with xmms from comandline and from bash scripts. For a list of options just run it without ant parameters.

You can check if xmms is playing, and then execute any command :

xmmsctrl playing && echo "Playing" || echo "Not Playing"

I just have a thought, you can do something like:

Code Sample

#!/bin/sh

# change output plugin command goes here

FILEDIR="path/to/wma/dir/or/single/wma"

xmmsctrl dir $FILEDIR

# multiple dirs : xmmsctrl dir BEGIN dir1 dir2 END
## maybe without BEGIN and END it'll also work

xmmsctrl play

while `xmmsctrl playing`
do
P=0
for i in `xmmsctrl print "%*S%n"`  # checks the length of playlist in seconds
do P=$(( P + $i ))
done
sleep $P
done

xmmsctrl quit

# restore config file command goes here

# You can also consider putting this somewhere in the beginning :

sed -i 's/shuffle=TRUE/shuffle=FALSE/;s/repeat=TRUE/repeat=FALSE/' ~/.xmms/config



Ok, but where is lame you ask.
Just check this url

There you can find :

xmms-encode-lame_0.2.1-1_i386.deb

and

xmms-encode-vorbis_0.3-1_i386.deb

Those are xmms output plugins for converting to mp3's and ogg's ( the second one )

You'll also need libmp3lame, it can be found on that site either.
I used liblame-3.97-0_3.96.99+3.97beta2-0rarewares1_i386.deb
Copy libmp3lame* to /usr/lib or add it to your tar.gz extension to usr/lib/ directory

Maybe there are some libs needed for ogg, but again you'll find them clicking the url above.

Remember to modify your script to change libOSS to libout_lame if you want to use that plugin.


Hope this helps someone :)

PS. Lame output plugin was tested with my first wma ever played, googled & downloadned from here :)

By the way, jot, thanks for teaching me the ${VAR/this/that} substitution.   I didn't know about that one, and it's a lot easier to remember than the "cut" syntax.  I can see where it might be troublesome in some situations, though. Say your file has a filename "somethingwav.wav".  The substitution apparently only works on the first instance of "wav", and i don't know how to get it to use either a regexp (wav$), or a global substitution (${i/wav/mp3/g})
I know that it's a bit limited but although it's quite useful. As for your example, I've understood that you want to replace 'somethingwav.wav' with 'somethingmp3.mp3' , if so you can achieve this with ${i//wav/mp3} <- note the double slash, it means to substitute all occurences in the line.

I've learned this trick from here

groovy, thanks =o)
Many thanks to jot and mikshaw for their latest help.

I think I understand what jot is suggesting I try, but being realistic about my own abilities, I know I'd be better off trying first to see if there's any chance at all of stopping xmms within my script with facilities presently available to me.

As to mikshaw's post, editing jot's line referring to lame as he suggested did delete the transitional .wav file, so that problem's out of the way.

That leaves me then only with the question of stopping xmms within my script, rather than manually.

I think I know now why neither killall xmms nor my alternative works.

Leaving my script aside altogether, if I open a terminal, type xmms and press Enter, that opens a window representing the xmms player.

If, instead, I type xmms & and press Enter, I get the output [1] plus a process number. Immediately after that, however, I get the prompt again and the window representing the player opens automatically, just as if I'd typed xmms at the second prompt.

It's the fact that xmms opens in its own window that stops killall from having any effect on xmms, or so I suspect.

On the assumption I'm right, is there some way from a script to close a program you've started in the script, which program has opened its own window?

(Sorry to express my question in such a childish way, but I don't know the proper terminology.)

Next Page...
original here.