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"