Monday, June 17, 2013

Windows locks folders with thumbs db

Every tried to delete a network folder only to find moronic windows has placed a file there and locked it so preventing you from deleting it? The solution is simple but it always takes me longer to look it up than to do it, so here it is: a. Open "Local group policy editor" by clicking on Run and type ‘gpedit.msc’ in the b. Go to "User configuration" -> "Administrative Templates" -> "Windows Components" -> "Windows Explorer". c. Turns off the caching of thumbnails in hidden thumbs.db files. Sorted.

Tuesday, June 11, 2013

nice way to concat with spaces between lines...

      public String getConcatResult(){
            String res = "";
            for (String line : this.result) { 
                res += (line.trim() + " "); 
            } 

            return res.trim();
        }

Sunday, April 7, 2013

BASH iterating over files with spaces in the name.

Recently I moved my CD collection to my server and converted everything to flac format. It's not a lossy algorithm like mp3 and it's contains meta data tags so my media server (Serviio) understands the files and shows the correct album, artist etc. All is well and good except the bug ridden WDTV Live box won't play a flac file unless it's in a playlist and the hi-fi in the car only accepts mp3. So for the sake of convenience I decided to create a mp3 shadow directory of the flac files. I want this to be self maintaining in so far as any new flac files added are converted. I'm not worried if I delete the flac file and leave the mp3. This turned out to be slightly more troublesome than I originally thought. Mainly because some of the earlier flac conversions have spaces in the filenames and the script didn't handle them too well. So anyway, after a bit of playing about and searching I came to this solution:
  #! /bin/bash  
 LOCKFILE=/tmp/flacscanrunning  
 SECOND=/tmp/secondrequest  
 mungefilename ()  
 {  
  echo "$@" | sed 's|:|-|g' | tr ' ' '_' | sed 's|_\+|_|g' | tr / - | tr -d \'\"\?\[:cntrl:\]  
 }  
 mkdir -p /shares/media/Music/mp3_shadow  
 chmod -R 774 /shares/media/Music/mp3_shadow  
 if [ -f "$LOCKFILE" ]; then  
  echo "Already in progress"  
  if [ -f "$SECOND" ]; then  
   # we are not first or second instance so exit  
   exit 0  
  else  
   touch $SECOND  
   # we've tagged the file. need to wait for the first instance to exit  
   while [ -f "$LOCKFILE" ]; do  
    sleep 60    
   done  
   # we can leave the lockfile as we're gonna run now.  
   rm $SECOND  
  fi  
 else  
  touch $LOCKFILE  
 fi  
 IFS="$(printf '\n\t')"  
 for file in $(find "$1" -name '*.flac'); do   
  if [ -e "$file" ] ; then  
   echo "found: [$file]"  
   PTH=${file%/*}  
   FLE=${file##*/}  
   TGT=`echo $PTH | sed s/flac/mp3_shadow/`  
   CFLE=$(mungefilename $FLE)  
   NFILE="$TGT/${CFLE%.*}.mp3"  
   echo "To new MP3: [$NFILE]"  
   mkdir -p $TGT  
   if [ -f "$NFILE" ]; then  
        echo "Already exists"  
        continue  
   fi  
   ffmpeg -i "$file" -ab 320k -map_metadata 0 "$NFILE";  
  fi  
 done  
 chmod -R 774 /shares/media/Music/mp3_shadow   
 rm $LOCKFILE  

Monday, April 1, 2013

Relaunch...

I'm gonna try again. A relaunch if you like. Less waffle and more substance with a more technical theme. Not that anyone reads this lol