Thursday, 24 December 2009

flv_to_zen.sh - script to convert any video into format playable by Creative Zen XiFi

#!/bin/bash
# place in /usr/local/bin/flv_to_zen.sh
# ... and copy it across

for FILE in $*; do
  /usr/bin/ffmpeg -i $FILE -s 320x240 -acodec libmp3lame -vcodec mpeg4 -vtag XVID -b 500k -ab 320k ${FILE%.*}.avi
  cp ${FILE%%.flv}.avi /mnt/Zen-Xfi/Video/
done

Script to mount up or dismount a Creative Xen XiFi

UPDATE: Get udev permissions right and then can use Gnomad2 or other GUI without root/sudo without mounting scripts.

As in this post but files edited location different for ubuntu jaunty (in /lib/udev instead of /etc/udev): 
http://ubuntuforums.org/showthread.php?p=5734480

Add the entries (with group audio) in /???/udev/rules.d/45-{mtp8|njb5}.rules files. For me, ubuntu jaunty, there were no  /etc/udev/rules.d/45-whatever files. Adding them in /lib/udev instead of /etc/udev works. Properly done probably files in /etc only should be edited, after an update the edits in /lib might be lost ... so backup.

Group audio audio instead of plugdev for the entries  as normal users are in group audio for me. (possibly something I added so general audio stuff operated better)


$ grep -A1 X-fi /lib/udev/rules.d/45-lib*
/lib/udev/rules.d/45-libmtp8.rules:# Creative Zen X-fi
/lib/udev/rules.d/45-libmtp8.rules-ATTR{idVendor}=="041e", ATTR{idProduct}=="4162", SYMLINK+="libmtp-%k", MODE="770", GROUP="audio"
--
/lib/udev/rules.d/45-libnjb5.rules:# Creative Zen X-fi
/lib/udev/rules.d/45-libnjb5.rules-SYSFS{idVendor}=="041e", SYSFS{idProduct}=="4162", GROUP="plugdev", MODE="0770"




$ sudo /etc/init.d/udev restart

user@machine:~$ groupsuser adm dialout fax cdrom floppy tape audio dip video plugdev scanner fuse
The device numbers match what is in that post and what I see in lsusb or mtp-detect for the Creative Zen XiFi.

$ lsusb
Bus 001 Device 003: ID 041e:4162 Creative Technology, Ltd

$ sudo mtp-detect
libmtp version: 0.3.0
Device 0 (VID=041e and PID=4162) is UNKNOWN.
   Found 1 device(s):
   041e:4162 @ bus 0, dev 3
*** and loads more stuff ***

END UPDATE



script in /usr/local/bin/zen

Santa Claus is creating this script.

#!/bin/bash

if [[ "$1" == "stop" ]] ; then
 # to unmount:
 fusermount -u /mnt/Zen-Xfi
else
 mtpfs /mnt/Zen-Xfi -o allow_other
 nautilus /mnt/Zen-Xfi/ &
fi

# $ sudo mtp-detect >> notes-creative-zen

# I have not quite  yet figured out mounting without root
# setup one-time only:
#sudo mkdir /mnt/Zen-Xfi
#sudo chmod 777 /mnt/Zen-Xfi
#sudo vi /etc/fuse.conf
#   and comment-in user_allow_other  (and restart fuse presumably or linux easier for me to say in blog mode)

add_mp3info.sh - Retrospectively add mp3 info into mp3 files.

cat /home/jamesc/bin/add_mp3info.sh
#!/bin/bash

# Retrospectively add mp3 info into mp3 files.
# Based on directory name and file name.


# usage:
#~/mp3$ add_mp3info.sh */*/*.mp3
#~/mp3$ add_mp3info.sh -f therapy/*/*.mp3
# WARNING: doesn't work for other directory levels
# TODO: oops, doesn't work if leading ./ or anything leading.
# BUT: is safe enough, it won't overwrite existing mp3info (unless -f FORCE flag is passed)

# e.g.
# artist_name/album_name/01-track_title.mp3 does not have an ID3 1.x tag.
#find . -name *.mp3 -exec mp3info {} \; |less


FORCE=$1
if [[ "$FORCE" == "-f" ]] ; then echo foo; shift; fi
#for f in tom_waits/*/*; do
for f in $*; do
 info=$(mp3info "$f")
 if [[ "$FORCE" == "-f" || "$info" == "" ]] ; then
  echo "Adding info to file:$f"
  artist=;album=;title=;track=;
  artist=${f%%\/*.mp3}
  rest=${f#*\/}
  album=${rest%%\/*.mp3}
  rest=${rest#*\/}
  title=${rest%%.mp3}
  title=${title##*-}
  track=${rest%%-*}
  title=$(echo $title|sed "s/_\([a-z]\)/ \U\1/g" |sed "s/^\([a-z]\)/\U\1/")
  artist=$(echo $artist|sed "s/_\([a-z]\)/ \U\1/g" |sed "s/^\([a-z]\)/\U\1/")
  album=$(echo $album|sed "s/_\([a-z]\)/ \U\1/g" |sed "s/^\([a-z]\)/\U\1/")
  params=""
  #[[ "$title" != "" ]] && params="$params -t \"\$title\""
  mp3info -t "$title" -l "$album" -a "$artist" -n "$track" -c "badgers are lovely" "$f"
 fi
done


# TODO: oops, doesn't work if leading ./ or anything leading.
#/home/jamesc/bin/add_mp3info.sh: 24: [[: not found
# so this won't work:  find . -name "*.mp3" -exec add_mp3info.sh {} \;

# to get meta info from music/video files generally (if it is there): exiftool

Sunday, 6 December 2009

Retrospective rename music tracks

If you copy one of your CDs to digital form while not connected to the internet then how can you name the files correctly and embed the information also in the music files?

Is there an easier way to do this?
Has someone already written a script?
This example for .ogg files.

Get freedb/cddb info from http://www.freedb.org/ text search
Use emacs and macros to generate the  file name + rename list and the meta info programming command list.

cd ~/ogg
mv noartist/unknown_disc various_artists/oh_brother_where_art_thou_motion_picture_soundtrackmv noartist-unknown_disc.m3u various_artists-oh_brother_where_art_thou_motion_picture_soundtrack.m3u


mv track_01.ogg James_Carter__The_Prisoners__Po_Lazuras.ogg
mv track_02.ogg Harry_McClintock__Big_Rock_Candy_Mountain.ogg
mv track_03.ogg Norman_Blake__You_Are_My_Sunshine.ogg
mv track_04.ogg Alison_Krauss__Down_To_The_River_To_Pray.ogg
mv track_05.ogg Soggy_Bottom_Boys_Feat_Dan_Tyminski__I_Am_A_Man_Of_Constant_Sorrow_radio_station_version.ogg
mv track_06.ogg Chris_Thomas_King__Hard_Time_Killing_Floor_Blues.ogg
mv track_07.ogg Norman_Blake__I_Am_A_Man_Of_Constant_Sorrow_instrumental.ogg
mv track_08.ogg The_Whites__Keep_On_The_Sunny_Side.ogg
mv track_09.ogg Gillian_Welch__Alison_Krauss__Ill_Fly_Away.ogg
mv track_10.ogg G_Welch,_A_Krauss,_Emmylou_Harris__Didnt_Leave_Nobody_But_The_Baby.ogg
mv track_11.ogg Sarah,_Hannah__Leah_Peasall__In_The_Highways.ogg
mv track_12.ogg The_Cox_Family__I_Am_Weary_Let_Me_Rest.ogg
mv track_13.ogg John_Hartford__I_Am_A_Man_Of_Constant_Sorrow_instrumental.ogg
mv track_14.ogg Ralph_Stanley__O_Death.ogg
mv track_15.ogg Soggy_Bottom_Boys_Feat_Tim_Blake_Nelson__In_The_Jailhouse_Now.ogg
mv track_16.ogg Soggy_Bottom_Boys_Feat_Dan_Tyminski__I_Am_A_Man_Of_Constant_Sorrow_band_version.ogg
mv track_17.ogg John_Hartford__Indian_War_Whoop.ogg
mv track_18.ogg Fairfield_Four__Lonesome_Valley.ogg
mv track_19.ogg The_Stanley_Brothers__Angel_Band.ogg

#oops
mv G_Welch,_A_Krauss,_Emmylou_Harris__Didnt_Leave_Nobody_But_The_Baby.ogg G_Welch_A_Krauss_Emmylou_Harris__Didnt_Leave_Nobody_But_The_Baby.ogg
mv Sarah,_Hannah__Leah_Peasall__In_The_Highways.ogg Sarah_Hannah__Leah_Peasall__In_The_Highways.ogg

#### vorbiscomment -w overwrites old info, so e.g. tracknumber was gone.
D=ogg/various_artists/oh_brother_where_art_thou_motion_picture_soundtrack
ALBUM="Oh Brother Where Art Thou Soundtrack"
VBC=vorbiscomment
TN=01;F=James_Carter__The_Prisoners__Po_Lazuras.ogg;ARTIST="James Carter & The Prisoners";TRACK="Po Lazuras";$VBC -w -t tracknumber=$TN  $F -t "ARTIST=$ARTIST" -t "TITLE=$TRACK" -t "ALBUM=$ALBUM"
TN=02;F=Harry_McClintock__Big_Rock_Candy_Mountain.ogg;ARTIST="Harry McClintock";TRACK="Big Rock Candy Mountain";$VBC -w -t tracknumber=$TN  $F -t "ARTIST=$ARTIST" -t "TITLE=$TRACK" -t "ALBUM=$ALBUM"
TN=03;F=Norman_Blake__You_Are_My_Sunshine.ogg;ARTIST="Norman Blake";TRACK="You Are My Sunshine";$VBC -w -t tracknumber=$TN  $F -t "ARTIST=$ARTIST" -t "TITLE=$TRACK" -t "ALBUM=$ALBUM"
TN=04;F=Alison_Krauss__Down_To_The_River_To_Pray.ogg;ARTIST="Alison Krauss";TRACK="Down To The River To Pray";$VBC -w -t tracknumber=$TN  $F -t "ARTIST=$ARTIST" -t "TITLE=$TRACK" -t "ALBUM=$ALBUM"
TN=05;F=Soggy_Bottom_Boys_Feat_Dan_Tyminski__I_Am_A_Man_Of_Constant_Sorrow_radio_station_version.ogg;ARTIST="Soggy Bottom Boys Feat. Dan Tyminski";TRACK="I Am A Man Of Constant Sorrow (radio station version";$VBC -w -t tracknumber=$TN  $F -t "ARTIST=$ARTIST" -t "TITLE=$TRACK" -t "ALBUM=$ALBUM"
TN=06;F=Chris_Thomas_King__Hard_Time_Killing_Floor_Blues.ogg;ARTIST="Chris Thomas King";TRACK="Hard Time Killing Floor Blues";$VBC -w -t tracknumber=$TN  $F -t "ARTIST=$ARTIST" -t "TITLE=$TRACK" -t "ALBUM=$ALBUM"
TN=07;F=Norman_Blake__I_Am_A_Man_Of_Constant_Sorrow_instrumental.ogg;ARTIST="Norman Blake";TRACK="I Am A Man Of Constant Sorrow (instrumental";$VBC -w -t tracknumber=$TN  $F -t "ARTIST=$ARTIST" -t "TITLE=$TRACK" -t "ALBUM=$ALBUM"
TN=08;F=The_Whites__Keep_On_The_Sunny_Side.ogg;ARTIST="The Whites";TRACK="Keep On The Sunny Side";$VBC -w -t tracknumber=$TN  $F -t "ARTIST=$ARTIST" -t "TITLE=$TRACK" -t "ALBUM=$ALBUM"
TN=09;F=Gillian_Welch__Alison_Krauss__Ill_Fly_Away.ogg;ARTIST="Gillian Welch & Alison Krauss";TRACK="I'll Fly Away";$VBC -w -t tracknumber=$TN  $F -t "ARTIST=$ARTIST" -t "TITLE=$TRACK" -t "ALBUM=$ALBUM"
TN=10;F=G_Welch_A_Krauss_Emmylou_Harris__Didnt_Leave_Nobody_But_The_Baby.ogg;ARTIST="G Welch, A Krauss, Emmylou Harris";TRACK="Didn't Leave Nobody But The Baby";$VBC -w -t tracknumber=$TN  $F -t "ARTIST=$ARTIST" -t "TITLE=$TRACK" -t "ALBUM=$ALBUM"
TN=11;F=Sarah_Hannah__Leah_Peasall__In_The_Highways.ogg;ARTIST="Sarah, Hannah & Leah Peasall";TRACK="In The Highways";$VBC -w -t tracknumber=$TN  $F -t "ARTIST=$ARTIST" -t "TITLE=$TRACK" -t "ALBUM=$ALBUM"
TN=12;F=The_Cox_Family__I_Am_Weary_Let_Me_Rest.ogg;ARTIST="The Cox Family";TRACK="I Am Weary (Let Me Rest";$VBC -w -t tracknumber=$TN  $F -t "ARTIST=$ARTIST" -t "TITLE=$TRACK" -t "ALBUM=$ALBUM"
TN=13;F=John_Hartford__I_Am_A_Man_Of_Constant_Sorrow_instrumental.ogg;ARTIST="John Hartford";TRACK="I Am A Man Of Constant Sorrow (instrumental";$VBC -w -t tracknumber=$TN  $F -t "ARTIST=$ARTIST" -t "TITLE=$TRACK" -t "ALBUM=$ALBUM"
TN=14;F=Ralph_Stanley__O_Death.ogg;ARTIST="Ralph Stanley";TRACK="O Death";$VBC -w -t tracknumber=$TN  $F -t "ARTIST=$ARTIST" -t "TITLE=$TRACK" -t "ALBUM=$ALBUM"
TN=15;F=Soggy_Bottom_Boys_Feat_Tim_Blake_Nelson__In_The_Jailhouse_Now.ogg;ARTIST="Soggy Bottom Boys Feat. Tim Blake Nelson";TRACK="In The Jailhouse Now";$VBC -w -t tracknumber=$TN  $F -t "ARTIST=$ARTIST" -t "TITLE=$TRACK" -t "ALBUM=$ALBUM"
TN=16;F=Soggy_Bottom_Boys_Feat_Dan_Tyminski__I_Am_A_Man_Of_Constant_Sorrow_band_version.ogg;ARTIST="Soggy Bottom Boys Feat. Dan Tyminski";TRACK="I Am A Man Of Constant Sorrow (band version";$VBC -w -t tracknumber=$TN  $F -t "ARTIST=$ARTIST" -t "TITLE=$TRACK" -t "ALBUM=$ALBUM"
TN=17;F=John_Hartford__Indian_War_Whoop.ogg;ARTIST="John Hartford";TRACK="Indian War Whoop";$VBC -w -t tracknumber=$TN  $F -t "ARTIST=$ARTIST" -t "TITLE=$TRACK" -t "ALBUM=$ALBUM"
TN=18;F=Fairfield_Four__Lonesome_Valley.ogg;ARTIST="Fairfield Four";TRACK="Lonesome Valley";$VBC -w -t tracknumber=$TN  $F -t "ARTIST=$ARTIST" -t "TITLE=$TRACK" -t "ALBUM=$ALBUM"
TN=19;F=The_Stanley_Brothers__Angel_Band.ogg;ARTIST="The Stanley Brothers";TRACK="Angel Band";$VBC -w -t tracknumber=$TN  $F -t "ARTIST=$ARTIST" -t "TITLE=$TRACK" -t "ALBUM=$ALBUM"

Wednesday, 18 November 2009

Making a recording of a little drumming bear toy for a Play

I have now a recording of the little drumming bear toy which is pretty good.
It's a rather specific sound, "squeak squeak squeak squeak squeak *drum*  *drum* *drum*" and it's good the sound we've recorded matches the toy (who will be on stage an performing also! :)
I haven't done sounds before for something like this.


This is my recording setup now:

Karaoke microphones -> DVD -> TV -> laptop (TV has audio out).
Works pretty well. The microphones are from Lidl or Aldi.
I first used mobile phone to record stuff. Then Bluetooth sounds -> laptop. (and ffmpeg enabled for amr converting) That's not great. Flat
 

I'm using linux so mostly Audacity for sound editing, Ardour for playing, VLC/ffmpeg for converting.
We shall see this weekend how they sound in the theatre! Ulp! :)


This is what it is for: http://www.milltheatre.com/shows/seasons-greetings
Season's Greetings by playwright Alan Ayckbourn.   (in Dundrum on 24-28 Nov)
Glencullen Musical and Dramatic Society.
Season's Greetings is a black, though often farcical comedy about a dysfunctional family Christmas, set over Christmas Eve, Christmas Day and St Stephen's Day in an average suburban house.

happy-shiny jolly Christmas song

We're still selecting happy-jolly tunes but we've some from hi5 and Johnny Mathis and others which are good: kids songs with singing .... I was up till 5am on Monday grepping youtube.
I'm looking for a very happy-shiny jolly Christmas song.
Alvin and the Chipmunks are not jolly enough.
 Looney Tunes are not jolly enough!

TODO: links
http://www.youtube.com/my_playlists?pi=7&ps=20&sf=&sa=0&sq=&dm=0&p=41D83C5287331CCB
http://www.youtube.com/my_playlists?pi=7&ps=20&sf=&sa=0&sq=&dm=0&p=D531FB80CBB0916E
Some possibilities: Boney M, Hi5, Johnny Mathis, The Supremes, Michael Jackson, Slade, The Wiggles, Claymation

This is what it is for: http://www.milltheatre.com/shows/seasons-greetings
Season's Greetings by playwright Alan Ayckbourn.   (in Dundrum on 24-28 Nov)
Glencullen Musical and Dramatic Society.
Season's Greetings is a black, though often farcical comedy about a dysfunctional family Christmas, set over Christmas Eve, Christmas Day and St Stephen's Day in an average suburban house.
And incidentally on the odd musical note, my brother is releasing a single:
 http://www.youtube.com/watch?v=HQPh7SBUoec
 http://music.bcoleman.com/

Eclipse regexp Find/Replace error "Incompatible line delimiter near index"

Eclipse Find/Replace error:  "Incompatible line delimiter near index"
Searching for: " - %i,*" replace with "0\\\n"

Because you have dos line ending in file, eclipse will be happier with this:
Searching for: " - %i,*" replace with "0\\\r\n"

Or better make sure everything is dos2unix converted if touched by something which converts it the other way. In eclipse you can select File -> Convert line delimiters to ...

WARNING: Don't mess with file encoding unless you know what you'er doing!
In eclipse these other settings are relevant:
 Right-click on Project -> Properties
    Resource -> Text File Encoding
      Might be best to leave this (Inherited from container Cp1252 for windows)

    Resource -> New Text File Line Delimiter
      Change to "unix"
 Windows -> Preferences
    General -> Editors -> Text Editors
      Select "Insert spaces for tabs"
    General -> Content types -> Text -> Tcl Content Type
Set default enccoding (leave it alone is probably best policy!)

Saturday, 14 November 2009

bt-sync-mobile.sh script handle files with spaces in names.

bt-sync-mobile.sh updated with a bit of grief to allow sync files with spaces in file names. Could not do it "properly" and get quoting/slashifying correct. Hacked s/ /_SPACE_/g when getting file list then iterate lists and s/_SPACE_/ / when needed.

Used to sync mobile sounds.

And photos, here's one photo synced:
http://www.facebook.com/home.php?ref=home#/photo.php?pid=30466015&id=1118555017

And here's one that got a bit washed out:



Here's the script:
Presumably cut&pasting it from here might not work ... depending ... oh well ...
See below below for script, embed from github:


#!/bin/bash

#INVOCATION:
#$ bt-sync-mobile.sh [device [dir]]
#$ bt-sync-mobile.sh Pooky 'C:\Data\Images\' 2>&1 |tee .btsync/bt_sync_images.log
#Stuff is synched to ~/.btsync/`echo $dir |sed 's/[\/ \\"]/_/g'`
#wami*.gpx and *.jpg files are cleared off device if synced successfully and mp4 or png
#
#REQUIREMENTS:
#linux with bluetooth hardware
#various bluetooth linux utils, these ubuntu packages:
#bluez bluez-utils(?) obexftp openobex-apps
#
# some of these come by default, and some are not needed, but this is on the system the script was tested on
#$ dpkg -l |egrep "bluez|hci|obex" |sed 's/  */ /g'
#ii bluez 4.32-0ubuntu4.1 Bluetooth tools and daemons
#ii bluez-alsa 4.32-0ubuntu4.1 Bluetooth audio support
#ii bluez-cups 4.32-0ubuntu4.1 Bluetooth printer driver for CUPS
#ii bluez-gnome 1.8-0ubuntu5 Bluetooth utilities for GNOME
#ii bluez-gstreamer 4.32-0ubuntu4.1 Bluetooth gstreamer support
#ii bluez-utils 4.32-0ubuntu4.1 Transitional package
#ii gnome-vfs-obexftp 0.4-1build1 GNOME VFS module for OBEX FTP
#ii libopenobex1 1.5-1 OBEX protocol library
#ii libopenobex1-dev 1.5-1 OBEX protocol library - development files
#ii obex-data-server 0.4.4-0ubuntu1 D-Bus service for OBEX client and server sid
#ii obexftp 0.19-7ubuntu2 file transfer utility for devices that use t
#ii openobex-apps 1.5-1 Applications for OpenOBEX
#ii python-bluez 0.16-1ubuntu1 Python wrappers around BlueZ for rapid bluet
#
#NOTES:
#The bluetooth connect seems to fail sometimes.
#Files with funny chars in name could cause a problem. maybe. () are okay
#Files to clear out are hardcoded.
#It's simple - just syncs files up if they don't exist on host.
#There are various other TODOs
#
### TODO: hey look at Images\_PAlbTN\ dir ! every thumbnail since year DOT! sneaky !
# nokia E65 phone
#
#I've thrown together an ugly script to automate sync (a dumb enough sync) of files from my phone.
#And made an ugly blog post about the ugly script also:
#http://gaoithe.livejournal.com/33541.html
#
#It would be nice to sync properly like rsync (i.e. check files size and date/times on host and device).
#It would be nice to use rsync itself! :)
#Possibly obexftp could be improved, commands like "get-if-changed, put-if-not-up-to-date", recursive ability.
#Hmm. Hmm.
#mount could mount some ugly thing + obexftp interface?   then rsync away
# Hmmm.
#
# 14/11/2009 Fix allow spaces in file names.
#     probably also allow spaces in dirs and device name
#     for F in *.amr ; do echo F=$F; done
#     for F in *.amr ; do echo F=$F; N=${F%%.amr}; if [[ ! -e $N.ogg ]] ; then ffmpeg -i $F $N.ogg; fi; done
# export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib
# for F in *.amr ; do echo F=$F; N=${F%%.amr}; if [[ ! -e $N.ogg ]] ; then ffmpeg-amr -i "$F" "$N.ogg"; fi; done
#
# f=Sound\ clip\(10\).ogg; n=${f%%.amr}; mv "$f" "${n}_DragonSoup.ogg"
# for f in DataSoundsDigital/Sound\ clip\({1,2}*\).ogg; do vlc "$f"; done
# for f in DataSoundsDigital/Sound\ clip\({1*,20,21,22,23}\).ogg; do n=${f%%.ogg}; mv "$f" "${n}_DragonSoup.ogg"; done
#
# for f in DataSoundsDigital/Sound\ clip\(*\).ogg; do vlc "$f"; done
# for f in *.flv; do n=${f%%.flv}; if [[ ! -e "$n.wav" ]] ; then ffmpeg -i "$f" "$n.wav"; fi; done




DEVICENAME="$1"
#echo all is $*
BTSYNCHOME=~/.btsync

# DEVICENAME can be blank (scans all devices)
HCISCAN=`hcitool scan |grep "$DEVICENAME" |grep -v ^Scanning `
#Scanning ...
#    00:1F:5D:BF:29:39    Nokia 3120 fionnuala
#    00:17:E5:EE:29:18    Pooky
#check for duplicates
DEVCOUNT=`echo "$HCISCAN" |wc -l`
HCISCAN_S=`echo "$HCISCAN" |sed 's/[\t ][\t ]*/ /g;s/^ *//;'`
BTADDR=`echo "$HCISCAN_S" |cut -d' ' -f1`
DEVNAME=`echo "$HCISCAN_S" |cut -d' ' -f2-`

#echo "DEVCOUNT=$DEVCOUNT HCISCAN=$HCISCAN
#BTADDR=$BTADDR DEVNAME=$DEVNAME"

if [[ $DEVCOUNT -ne 1 ]] ; then
    echo "usage: $0  
  e.g. $0 42:54:41:44:44:52 \"C:/Data/\"
Which device?
$HCISCAN
"
    exit;
fi

echo "BTADDR=$BTADDR DEVNAME=$DEVNAME"
#sudo hcitool info $BTADDR

DIRTOSYNC="$2"
# TODO pass in dir/file to sync on cmd line in $2
if [[ -z $DIRTOSYNC ]] ; then
    echo "usage: $0  
  e.g. $0 42:54:41:44:44:52 \"C:/Data/\"
  e.g. $0 \$BTADDR \"C:/Data/Images/\"
  e.g. $0 $BTADDR \"C:/Data/Videos/\"
  e.g. $0 42:54:41:44:44:52 \"C:/Data/Sounds/\"
"
    DIRTOSYNC="C:/Data/"
    #exit;
fi

mkdir -p $BTSYNCHOME

DIRTOSYNC_HASH=`echo "$DIRTOSYNC" |sed 's/[\/ \\"]/_/g'`
# cd to where we are getting files
mkdir -p $BTSYNCHOME/$DIRTOSYNC_HASH
cd /tmp
cd  $BTSYNCHOME/$DIRTOSYNC_HASH
pwd

#obexftp -b $BTADDR -v -l ""
#obexftp -b $BTADDR -v -l "C:/"
echo DIRTOSYNC=$DIRTOSYNC DIRTOSYNC_HASH=$DIRTOSYNC_HASH
obexftp -b $BTADDR -v -l "$DIRTOSYNC" |tee $BTSYNCHOME/$DIRTOSYNC_HASH.list




echo get list of all files
echo TODO: parse xml safely/properly
#

#FILES=$(grep "
FILES=$(grep "

date >> $BTSYNCHOME/$DIRTOSYNC_HASH.log
echo FILES=$FILES |tee -a $BTSYNCHOME/$DIRTOSYNC_HASH.log


## forget about first retrieve or not, just check files on each system
#if [[ -f $BTSYNCHOME/$DIRTOSYNC_HASH.success ]] ; then
#echo for second/.. retrieve just get differences

echo TODO: recurse into directories

echo TODO get updated files, now we get new files only


function wipe_existing_files_from_list () {
    echo for now we check if file exists already and wipe from list
    ##file list to retrieve by eliminating ones already retrieved
    FILESTOGET=
    for F in $FILES ; do
        #F=$(echo $F|sed 's/_SPACE_/ /g')
        if [[ ! -f $F ]] ; then
            FILESTOGET="$FILESTOGET $F"
        fi
    done  
    FILES="$FILESTOGET"
#diff $BTSYNCHOME/$DIRTOSYNC_HASH $BTSYNCHOME/$DIRTOSYNC_HASH.success
#mv $BTSYNCHOME/$DIRTOSYNC_HASH $BTSYNCHOME/$DIRTOSYNC_HASH.success
}

function get_the_files () {
    if [[ ! -z $FILES ]] ; then
        echo get the files
        date >> $BTSYNCHOME/$DIRTOSYNC_HASH.get
        SP_Q=$(echo $FILES|grep _SPACE_)
        if [[ "$SP_Q" != "" ]] ; then
            # spaces in file names so must do them induhvidually
            for F in $FILES; do
                F=$(echo $F|sed 's/_SPACE_/ /g')
                echo "obexftp get $F"
                echo obexftp -b $BTADDR -v -c \"$DIRTOSYNC\" -g \"$F\"
                obexftp -b $BTADDR -v -c "$DIRTOSYNC" -g "$F" |tee -a $BTSYNCHOME/$DIRTOSYNC_HASH.get
            done
        else
            echo "obexftp get $FILES"
            echo obexftp -b $BTADDR -v -c \"$DIRTOSYNC\" -g $FILES
            obexftp -b $BTADDR -v -c "$DIRTOSYNC" -g $FILES |tee -a $BTSYNCHOME/$DIRTOSYNC_HASH.get
        fi
 
        # can obexftp do a dir? would be handy.
        #obexftp -b $BTADDR -v -g "$DIRTOSYNC" |tee $BTSYNCHOME/$DIRTOSYNC_HASH.getdir
        # also -G (get and delete) could be used for some files
    fi
}



# TODO/half DONE track and check each file seperately
# TODO maybe if we got the file, store the associated line then in .success file
# use size/date in xml and  on file system.
# ideally we want commands: GET[and remove] if newer/different

function track_the_files () {
#CHECKFILES=`echo $FILES |sed 's/ / && -f /g'`
#if [[ $CHECKFILES ]] ; then
#   mv $BTSYNCHOME/$DIRTOSYNC_HASH $BTSYNCHOME/$DIRTOSYNC_HASH.success
    date >> $BTSYNCHOME/$DIRTOSYNC_HASH.success
    for F in $FILES ; do
        F=$(echo $F|sed 's/_SPACE_/ /g')
        if [[ -f $F ]] ; then
            # a file name which is part of others will cause problems
            FILEINFO=`grep "> $BTSYNCHOME/$DIRTOSYNC_HASH.success
        fi
    done
}


## TODO cleanup all files  on mobile retrieved this time or previous
##   allows syncing as soon as possible but cleaning after longer (keep recent photos, traces, ...)

# cleanup files matching certain patterns on mobile if they were successfully retrieved
# we could use -G earlier (get and delete)
function clean_the_files () {
    for F in $FILES ; do
        F=$(echo $F|sed 's/_SPACE_/ /g')
###if [[ -f bin/eirkey.pl && ( -n ${FG#wami-2} || -n ${F%gpx} ) ]] ; then echo yep; fi
       
        if [[ -f $F && ( -n ${F#wami-2*.gpx} || -n ${F#*.jpg} || -n ${F#*.mp4} || -n ${F#*.png} ) ]] ; then
            obexftp -b $BTADDR -v -c "$DIRTOSYNC" -k $F |tee -a $BTSYNCHOME/$DIRTOSYNC_HASH.clean
        fi
    done
}




wipe_existing_files_from_list
echo "files to get FILES=$FILES"

get_the_files

track_the_files

clean_the_files


collecting sounds for theatre, ffmpeg converting, howto ffmpeg + amr


I'm collecting sounds for the theatre people. Need a cassette tape screech sound, doorbell, jolly Christmas song. It's jolly difficult to find jolly christmas songs jollily sung! :) We don't have

This is for the play Season's Greetings.
 http://www.milltheatre.com/shows/seasons-greetings
 http://www.facebook.com/group.php?gid=6065036825

 http://en.wikipedia.org/wiki/Season%27s_Greetings_(play)
 http://seasonsgreetings.alanayckbourn.net/


I'm recording sounds with my mobile phone (Nokia E65). Converting sounds and vids with ffmpeg.

Ubuntu jaunty default ffmpeg kindof did amr to wav or ogg. But didn't mostly. I first tried ffmpeg source + older amr codecs with licencing problems. Found ffmpeg now uses libopencore. AND actually also I have the older amr codecs installed already as ubuntu packages  anyway. Anyway fresh built ffmpeg converts all amr ro wav or ogg.

So 15/Nov/2009 how to get ffmpeg working a bit better with amr format:

http://opencore-amr.sourceforge.net/
  tar -zxvf opencore-amr-0.1.2.tar.gz
  cd opencore-amr-0.1.2/
  less README
  ./configure --prefix=/usr/local
  make
  sudo make install

  cd ../
  svn checkout svn://svn.mplayerhq.hu/ffmpeg/trunk ffmpeg-svn
  cd ffmpeg-svn
  ./configure --prefix=/usr/local --enable-gpl --enable-pthreads --enable-version3  --enable-libopencore-amrnb --enable-libopencore-amrwb
  make
  sudo make install


  # if you install in /usr/local you'll need to set the LIBRARY path:
  export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib

  # This converts all .amr files in dir to .ogg (and doesn't do it if already done)
  for F in *.amr ; do
    echo F=$F;
    N=${F%%.amr};
    if [[ ! -e $N.ogg ]] ; then
      ffmpeg-amr -i "$F" "$N.ogg";
    fi;
  done

Songs of the 80s.
http://www.afn.org/~afn30091/


Also. VLC crashes if try to do things  with playlist?
Individual VLCs are fine open and playing together which is  what is wanted.

Wednesday, 11 November 2009

SalomeToXQual.pl


#!/usr/bin/perl -w


=head1 NAME


Read in Salomé_TMF exported .xml file.
Choose a Test Plan and set of tests to import.
Write out .xml or .csv that XQual can read.


=head1 SYNOPSIS


Salomé project INX8000-OLC
-> Data exchange format -> Export xml xml_export_olc_all.xml (file saved to Desktop)


Read in that file (as XML).
Read in Famille Nom, offer user choice of Famille Nom and/or SuiteTest Nom to choose.
Read in all wanted particular items matching Famille and SuiteTest.
Save to ; delimited .csv (awkward with excel) and " " indented for "with testplan" option.
Write fields out (some values merged, others generated/hardcoded).


=head1 SPEC


I tried doing this Salome_TMF export -> excel -> .csv -> XStudio.
But excel .csv output is annoyingly limited.
Possibly could get closer with openoffice but feh.


=head2 INPUT Salome_TMF .xml format




.


OLC
.

SU_A2 OLC
Area for tests which are parts of this phase of testing


SU_A2


=head2 Mapping Salomé .xml/.xls fields to XStudio format


A+BI+BJ (projet+id_famille+Nom) category; (set to 4) priority; (set to "") canonicalPath;(set to test script name) path
BM (id_test) index; (set to 1) implemented; BP (Nom) name;
CK+CL+CM step;param1,param2,...; CN check1,check2,...


=head2 XQual XStudio .csv and .xml import format


Format .xml or .csv or .csv with test plan
The .xml format (detailed below) for import I have not tested.
The IDs are in the .xml, how would we decide on those when importing?
So I'm using use .csv to import.


Tests and Testcases (without testplan)
category;implemented;priority;canonicalPath;path;indexTestcase1,indexTestcase2,...


OR Tests and Testcases (with testplan>, indentation spaces matter)
category;priority;canonicalPath;path(script name)
index;implemented;name
step;param1,param2,...;check1,check2,...


=head2 OUTPUT XStudio .csv in format


# the indentation whitespace matters
# test path must begin with /
# numeric fields must be numeric
# ColdRestartsOfTCS.tcl is the script for this example (one script for all test cases in category)


SU_A2;4;TestCanPathIsScriptNameMaybe;/TestPath/ColdRestartsOfTCS


1159;0;Cold Restarts of TCS with no input power


Action_1075 A0 Check bringup wait time for WSS;;"20 minutes, or longer. [HLD.OPTA.BLK_E.0010]"
Action_1076,A1,There is no optical output during this startup phase [Bringup slides] & R[HLD.OPTA.BLK_E.0011];;Using a power meter confirm
Action_1077,A2,"After warm-up phase complete if BI available, manufacture and calibration phase available then the following three tasks commence \n1) CC TX - CC laser and APR ON \n2) CC RX - Coarse RX Loop starts \n3) Data plane 1st powers and warms up \n";;Confirm these tasks commence.
Action_1090,A3,###############################################################################################################################################################################################################################################################;;Due to the fact that only part of the functionally is available cannot see without that stubbing that the bring can complete. This step attempts to highlight this issue.


=head2 running


I'm using cygwin's perl for now. By default XML/LibXML.pm is available.


#!/cygdrive/c/Perl/bin/perl -w
$ perl c:/Perl/scripts/SalomeToXQual.pl
Can't locate XML/LibXML.pm in @INC (@INC contains: c:/Perl/site/lib c:/Perl/lib .) at c:/Perl/scripts/SalomeToXQual.pl line 283.


=head2 DESIGN


http://perl-xml.sourceforge.net/faq/#quick_choice


=cut


use strict;


use XML::LibXML;


# defaults
my $filename = shift;
my $ofilename;
my $match = shift;
$filename="c:/Documents and Settings/james.coleman/Desktop/xml_export_olc_all.xml" if (!defined $filename);
#$match = "SU_A2 OLC" if (undef $match);
$match = "" if (!defined($match));
my $matchhash = $match;
$matchhash =~ s/[^\w\d]/_/g;
if (!defined $ofilename) {
$ofilename=$filename;
$ofilename =~ s/.xml$//;
$ofilename .= "_${matchhash}.csv";
}
print "$0 filename=$filename ofilename=$ofilename match=$match\n";


my $parser = XML::LibXML->new();
my $doc = $parser->parse_file($filename);


# TODO user passes in filename [optional outfile] [optional regexp/list of famille to take]
#my $c = $#ARGV + 1;
#print FILE "ARGC=$c\n";
#foreach my $i (0 .. $#ARGV) {
# print FILE "arg ARGV[$i]=$ARGV[$i]\n";
#}


open(FILE, '>', $ofilename) or die $!;


# ct = current test
my %ct;
my ($category,$priority,$canonicalPath,$path);
my ($index,$impl,$name);
my ($step,$param1,$param2,$check1,$check2);


$ct{'category'} = "0xdeadbeef";
$ct{'path'} = "0xdeadbeef";
$ct{'index'} = "0xdeadbeef";
$ct{'name'} = "0xdeadbeef";
$ct{'step'} = "0xdeadbeef";
$ct{'param1'} = "";
$ct{'param2'} = "";
$ct{'check1'} = "";
$ct{'check2'} = "";


$ct{'priority'} = 4;
$ct{'canonicalPath'} = "";
$ct{'impl'} = 0;


$ct{'project'} = $doc->findnodes('//Nom')->to_literal;


foreach my $f ($doc->findnodes('//Familles/Famille')) {
my($n) = $f->findnodes('./Nom');
print $n->to_literal, "\n";


next if ($match eq "");


$_ = $n->to_literal;
if (m/$match/) {
print "MATCH ", $n->to_literal, "\n";
$ct{'category'} = $n->to_literal;
$ct{'cathash'} = $ct{'category'};
$ct{'cathash'} =~ s/ /_/g;
### PATH MUST BEGIN WITH /
$ct{'path'} = "/IntuneTest/".$ct{'cathash'}."TestScript";


#my $s = $f->findnodes('./SuiteTests');
#print "Suite: ", $s->to_literal, "\n";
my($tests) = $f->findnodes('.//Tests');
#print "Tests: ", $tests->to_literal, "\n";


#category;priority;canonicalPath;path(script name)
# index;implemented;name
# step;param1,param2,...;check1,check2,...
print FILE "\n$ct{'category'};$ct{'priority'};$ct{'canonicalPath'};$ct{'path'}\n";


foreach my $t ($tests->findnodes('.//Test')) {


my @a0 = $t->attributes();
#$ct{'index'} = $t->getAttribute('test_id');
$ct{'index'} = $a0[0]->getValue();
$ct{'index'} =~ s/[^0-9]//g;


my $tn = $t->findnodes('./Nom');
$ct{'name'} = $tn->to_literal;


# no test name in .csv :( NO, actually yuou can do it (and must I think) - had a different problem
# AND two \n's are VITAL!
print FILE "\n $ct{'index'};$ct{'impl'};$ct{'name'}\n\n";
#print FILE "\n $ct{'index'};$ct{'impl'}\n\n";
# place test name in 1st test step
#print FILE " $ct{'name'};;\n";

### TODO Test Description not included
# my $desc = $tests->findnodes('./Description')) {
foreach my $step ($t->findnodes('./TestManuel/ActionTest')) {
my @stepa0 = $step->attributes();
$ct{'step'} = $stepa0[0]->getValue();
$ct{'step'} .= "," . $step->findnodes('./Nom')->to_literal;
$ct{'step'} .= "," . $step->findnodes('./Description')->to_literal;
$ct{'check1'} = $step->findnodes('./ResultAttendu')->to_literal;
#print FILE " $ct{'step'};$ct{'param1'},$ct{'param2'},;$ct{'check1'},$ct{'check2'},\n";
$ct{'step'} =~ s/[;,]/_/g;
$ct{'param1'} =~ s/[;,]/_/g;
$ct{'check1'} =~ s/[;,]/_/g;
print FILE " $ct{'step'};$ct{'param1'};$ct{'check1'}\n";
}
}
}
}


my $ts = time();


close FILE;


Sunday, 8 November 2009

Curtlestown Woods walk: buggyable*with lift

Walk in Curtlestown Woods, Kilmalin, past Pet Cemetary near Enniskerry, Wicklow. With Brian and Trinh and their and our kids. ... and very very few other people. Lovely sunny day in Nov.

We're trying out some of the walks in the "Ten Walks in the district of Enniskerry" book by Albert Smith and Kevin Warner and others. (the revised and updated edition replacing the walks with disputed section with others and notes on the legal proceedings - added interest for Irish walking books!).

Walk 6 in book. Kilmolin loop walk. This was a lovely walk and lovely day for it too. The bus turning circle looks like a great place to park until you see a double-decker bus trying to turn in it and having to reverse blind out into the road, wheels going down into potholes and underneath of front of bus scraping on road. There is lots of parking a little further on as noted in the book.



Books could have a buggyable rating for walks :) A 4k est 50 mins walk took us 2 hrs I think. Kids were very good. All of them walked the whole way except Maeve who got a shoulder for a short bit and Mark who is 2 was main user of buggy and inside it most of the time. Buggy lifted in 2 places: over coilte gate 5ft (easiest with two lifting buggy high and walking through gate step-through - make sure kids if they're still in buggy are well strapped in!!!) and over coilte bar 3 feet.

The map in the book doesn't have contour lines on it. :) Steepish uphill for whole 1st half of walk.

Daire went ahead of us in the woods. And somehow got a bit lost. At a fork we called him but not sure if he heard. We went past and he somehow missed us and started back even though we could still see the turn-off fork? He's gone ahead and gone straight on and had to be chased on walks before. Good man but hello! Fionn shouted for him and went back with Brian to collect him.

We had little oranges and banana at the view of Killiney, the Lead mines, Bray. Saw the ferry going out of Dun Laoghaire.

After the walk we were hUnGrY. Eat ouyt? Go home? We stopped in Enniskerry. Fionn and Trinh went to buy tasty food in delicatessen there. Home and ham and cheese rolls, homemade Fionn scones and other yummy stuff. Kids play. Maeve takes 93 photos with my phone and it's battery dies. :)

The same view in OpenStreetMaps and GoogleMaps:
  http://www.openstreetmap.org/?lat=53.1936&lon=-6.2043&zoom=14&layers=B000FTF
  http://maps.google.com/maps?f=q&source=s_q&hl=en&geocode=&q=Enniskerry,+Co.&sll=53.19287,-6.208649&sspn=0.026534,0.090895&ie=UTF8&radius=1.88&rq=1&ev=zo&hq=Enniskerry,+Co.&hnear=&ll=53.191842,-6.194401&spn=0.025249,0.090895&z=14
Impressed with OpenStreetMap's details. GoogleMaps have satellite overlay which is good for details though.

More pics here:
http://picasaweb.google.com/gaoithe/SchoolActivityPlaygroundBuildAndWalkUpCountryLanes#

Tuesday, 3 November 2009

VM setup. Problem copying VM with cygwin. dir/file group ownership


Had a problem copying a VM with cygwin, it won't import “Add VM to inventory”. The directory copy did not work. “Add to VM Inventory” could see dir but not browse inside. Symptom: you see group names like “????????” and “mkgroup-l-d” in cygwin (ls).
Copy dir with windows works, then rename. But wished to script the VM creation and using xcopy and copy (cmd built in) wasn't easy enough. Script does copy of the whole VM directory and contents then edit the .vmx file inside, just change the “displayName”. This does the copy and rename:
FROM=Node2_XXX
TO=Node3_XXX
cp -R -p -a $FROM $TO
perl -i.bak -pe 's/(displayName *= *").*(")/$1'$TO'$2/' $TO/*.vmx
# we're matching this one: displayName = "Node2_XXX"
# and ignoring this and all others: extendedConfigFile = "QNX_641_xxx.vmxf"
After thisscript is run in VM interface do “Add VM to Inventory", browse to dir. Select the vmx file. Select “I copied it” (this assigns a new mac address). Then power on machine. Edit network settings etc..


We can copy it with cygwin, if we fix up groups. It was a wrong group problem.  Solution do this: cp /etc/group /etc/group.bak; mkgroup -l -d >/etc/group
See below for more detail.

I'm sure this groups thing has caused me trouble before. e.g. the mysterious differences running sshd as windows service vs running on command-line. (Note: running on command-line can change permissions/ownership on files used and make it not work when running as server).

More details (cygwin mkgroup -l -d and {set,get}facl )

Copying one file example:
# BEFORE:
$ cp -a -p VM1_lab/*.vmx test.vmx
$ ls -al VM1_lab/*.vmx test*.vmx
-rwx------+ 1 me ????????    0 Nov 2 18:51 VM1_lab/QNX_641_xxx.vmx
-rwx------  1 me mkgroup-l-d 0 Nov 3 11:35 test.vmx

# AFTER:
$ cp /etc/group /etc/group.bak; mkgroup -l -d >/etc/group
$ cp -a -p VM1_lab/*.vmx test2.vmx
$ ls -al VM1_lab/*.vmx test*.vmx
-rwx------+ 1 me Domain Users 2189 Nov 2 18:51 VM1_lab/QNX_641_xxx.vmx
-rwx------  1 me Users 2196        Nov 3 11:35 test.vmx
-rwx------  1 me Domain Users 2189 Nov 2 18:51 test2.vmx

See below the result of cygwin cp VM1_lab Node2_XXX make the group owner of dir mkgroup-l-d. Highlighted in orange. That dir shows up in VM Add machine to inventory but the .vmx files inside are not visible.
me@mine /cygdrive/c/Virtual Machines
$ ls -al
total 1967096
drwxrwx---+ 14 Administrators SYSTEM 0 Nov 2  18:15 .
drwxrwxr-x+ 25 Administrators SYSTEM 0 Oct 30 14:48 ..
drwx------+ 2 me mkgroup-l-d 0         Nov 2  18:25 Node2_XXX
-rwx------+ 1 me ???????? 643830909    Aug 4  18:15 QNX641_XXX_template.tar.gz
drwx------+ 3 me ???????? 0            Nov 2  17:55 VM1_lab
drwx------+ 4 me ???????? 0            Oct 30 13:33 VM2_lab
-rwx------+ 1 me ???????? 732909568    Aug 31 14:14 ubuntu-9.04-desktop-i386.iso
drwx------+ 2 me ???????? 0            Oct 27 09:35 zenoss-2.4.5-380-x86

Re: CYGWIN=ntsec, "cp -a", and NT acls

It's worth fixing/using cygwin because md/mkdir/copy is cmd builtin, xcopy is prompty-fussy (prompts Y/N file copy can be overcome but prompts File/Dir cannot?)

$ getfacl $FROM>moo.facl; setfacl -f moo.gfacl $TO
setfacl: illegal acl entries
More direct: getfacl $FROM | setfacl -f - $TO


me@mine /cygdrive/c/Virtual Machines
$ cat moo.facl
# file: VM1_lab
# owner: me
# group: ????????
user::rwx
group::---
group:root:rwx
group:SYSTEM:rwx
group:mkgroup-l-d:rwx
mask:rwx
other:---
default:user::rwx
default:group:root:rwx
default:group:SYSTEM:rwx
default:group:mkgroup-l-d:rwx
default:mask:rwx

For reference, a VM template dir contents might be somthing like this:
$ tar -zxvf QNX641_xxx_template.tar.gz
drwxr-xr-x root/root 0 2009-08-04 17:06 QNX641_xxx/
-rw------- root/root 8684 2009-08-04 17:05 QNX641_xxx/QNX_641_xxx.nvram
-rw-r--r-- root/root 44488 2009-08-04 17:05 QNX641_xxx/vmware-0.log
-rw-r--r-- root/root 43871 2009-08-04 17:05 QNX641_xxx/vmware-2.log
-rw-r--r-- root/root 45331 2009-08-04 17:05 QNX641_xxx/vmware-1.log
-rw------- root/root 0 2009-08-04 17:05 QNX641_xxx/QNX_641_xxx.vmsd
-rwxr-xr-x root/root 2037 2009-08-04 17:05 QNX641_xxx/QNX_641_xxx.vmx
-rw-r--r-- root/root 240400 2009-08-04 17:05 QNX641_xxx/vmware.log
-rw------- root/root 2147483648 2009-08-04 17:06 QNX641_xxx/QNX_641_xxx-flat.vmdk