From tag-bounces@lists.linuxgazette.net Sat Mar 21 12:42:02 2009 From: Ben Okopnik Date: Sat, 21 Mar 2009 15:36:49 -0400 To: The Answer Gang Reply-To: The Answer Gang Sender: tag-bounces@lists.linuxgazette.net Subject: [TAG] tct: 2-cent Tip: Lists of files by extension MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=utf8 Status: O Content-Length: 3333 Lines: 77 Recently, I decided to sort, organize, and generally clean up my rather extensive music collection, and as a part of this, I decided to "flatten" the number of file types that were represented in it. Over the years, just about every type of audio file had made its way into it: FLAC, M4A, WMA, WAV, MID, APE, and so on, and so on. In fact, the first step would be to classify all these various types, get a list of each, and decide how to convert them to MP3s (see my next tip, which describes a generalized script to do just that.) The process of collecting this kind of info wasn't unfamiliar to me; in fact, I'd previously done this, or something like it, with the "find" command when I was trying to establish what kind of files I'd want to index in a search database. This time, however, I took a bit of extra care to deal with names containing spaces, non-English characters, and files with no extensions. I also defined a list of files that I wanted to ignore (see the "User-modified vars" section of the script) and provided the option of specifying the directory to index (current one by default) and the directory in which to create the 'ext' files (/tmp/files) by default; the script notifies you of the name.) This isn't something that comes up often, but it can be very useful in certain situations. ``` #!/bin/bash # Created by Ben Okopnik on Thu Mar 12 11:54:02 EDT 2009 # Creates a list of files named after all found extensions and containing the associated filenames [ "$1" = "-h" -o "$1" = "--help" ] && { echo "${0##*/} [dir_to_read] [output_dir]"; exit 0; } [ -n "$1" -a ! -d "$1" ] && { echo "'$1' is not a valid input directory"; exit 1; } [ -n "$2" -a ! -d "$2" ] && { echo "'$2' is not a valid output directory"; exit 1; } ################ User-modified vars ######################## dir_root="/tmp/files" ignore_exts="m3u bak" ################ User-modified vars ######################## snap=`pwd` [ -n "$1" ] && snap="$1" [ -n "$2" ] && dir_root="$2" out_dir=`mktemp -d "${dir_root}XXX"` echo "The output will be written to the '$out_dir' directory" cd / old=$IFS IFS=' ' [ -n "`/bin/ls $out_dir`" ] && /bin/rm $out_dir/* for n in `/usr/bin/find "$snap" -type f` do ext="`echo ${n/*.}|tr 'A-Z' 'a-z'`" # Ignore all specified extensions [ -n "`echo $ignore_exts|/bin/grep -i \"\\<$ext\\>\"`" ] && continue # No extension means the substitution won't work; no substitution means # we get the entire path and filename. So, no ext gets spun off to 'none'. [ -n "`echo $ext|grep '/'`" ] && ext=none echo $n >> $out_dir/$ext done echo "Done." ''' -- * Ben Okopnik * Editor-in-Chief, Linux Gazette * http://LinuxGazette.NET * +-+--------------------------------------------------------------------+-+ You've asked a question of The Answer Gang, so you've been sent the reply directly as a courtesy. The TAG list has also been copied. Please send all replies to tag@lists.linuxgazette.net, so that we can help our other readers by publishing the exchange in our monthly Web magazine: Linux Gazette (http://linuxgazette.net/) +-+--------------------------------------------------------------------+-+ _______________________________________________ TAG mailing list TAG@lists.linuxgazette.net http://lists.linuxgazette.net/mailman/listinfo/tag From tag-bounces@lists.linuxgazette.net Fri Mar 20 19:25:50 2009 Date: Sat, 21 Mar 2009 07:50:04 +0530 From: Kapil Hari Paranjape To: The Answer Gang Reply-To: The Answer Gang Sender: tag-bounces@lists.linuxgazette.net Subject: [TAG] tct: 2-cent Tip: Screenshots without X MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=utf8 Status: O Content-Length: 2026 Lines: 60 Hello, I had to do this to debug a program so I thought I'd share it. X window dump without X How does one take a screenshot without X? (For example, from the text console) Use Xvfb (the X server that runs on a virtual frame buffer). Steps: ``` 1. Run Xvfb $ Xvfb This will usually start the X server :99 $ DISPLAY=:99 ; export DISPLAY 2. Run your application in the appropriate state. $ firefox http://www.linuxgazette.net & 3. Find out which window id corresponds to your application $ xwininfo -name 'firefox-bin' | grep id Or $ xlsclients Use the hex string that you get as window id in the commands below 4. Dump the screen shot of that window $ xwd -id 'hexid" > firefox.xwd 5. If you want to, then kill these applications along with the X server $ killall Xvfb ''' 'firefox.xwd' is the screenshot you wanted. Use 'convert' or on of the netpbm tools to convert the 'xwd' format to 'png' or whatever. Additional Notes: A. You can use a different screenshot program. B. If you need to manipulate the window from the command line, then programmes like 'xautomation' and/or 'xwit' are your friends. Alternatively, use a WM like "fvwm" or "xmonad": `` DISPLAY=:99 xmonad & '' This will allow you to manipulate windows from the command line if you know some Haskell! Regards, Kapil. -- +-+--------------------------------------------------------------------+-+ You've asked a question of The Answer Gang, so you've been sent the reply directly as a courtesy. The TAG list has also been copied. Please send all replies to tag@lists.linuxgazette.net, so that we can help our other readers by publishing the exchange in our monthly Web magazine: Linux Gazette (http://linuxgazette.net/) +-+--------------------------------------------------------------------+-+ _______________________________________________ TAG mailing list TAG@lists.linuxgazette.net http://lists.linuxgazette.net/mailman/listinfo/tag From tag-bounces@lists.linuxgazette.net Sat Mar 21 04:31:15 2009 Date: Sat, 21 Mar 2009 11:29:19 +0000 From: Thomas Adam To: The Answer Gang Reply-To: The Answer Gang Sender: tag-bounces@lists.linuxgazette.net Subject: Re: [TAG] tct: 2-cent Tip: Screenshots without X MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=utf8 Status: O Content-Length: 1090 Lines: 29 2009/3/21 Kapil Hari Paranjape : > Hello, > > I had to do this to debug a program so I thought I'd share it. > > X window dump without X > ----------------------- > > How does one take a screenshot without X? (For example, from the text > console) > > Use Xvfb (the X server that runs on a virtual frame buffer). Or just use Xephyr. In fact this would be even easier, since there's an additional overhead in using Xvfb. -- Thomas Adam +-+--------------------------------------------------------------------+-+ You've asked a question of The Answer Gang, so you've been sent the reply directly as a courtesy. The TAG list has also been copied. Please send all replies to tag@lists.linuxgazette.net, so that we can help our other readers by publishing the exchange in our monthly Web magazine: Linux Gazette (http://linuxgazette.net/) +-+--------------------------------------------------------------------+-+ _______________________________________________ TAG mailing list TAG@lists.linuxgazette.net http://lists.linuxgazette.net/mailman/listinfo/tag From tag-bounces@lists.linuxgazette.net Sat Mar 21 08:31:49 2009 Date: Sat, 21 Mar 2009 21:00:07 +0530 From: Kapil Hari Paranjape To: tag@lists.linuxgazette.net Reply-To: The Answer Gang Sender: tag-bounces@lists.linuxgazette.net Subject: Re: [TAG] tct: 2-cent Tip: Screenshots without X MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=utf8 Status: O Content-Length: 1122 Lines: 32 Hello, On Sat, 21 Mar 2009, Thomas Adam wrote: > 2009/3/21 Kapil Hari Paranjape : > > Use Xvfb (the X server that runs on a virtual frame buffer). > > Or just use Xephyr. In fact this would be even easier, since there's > an additional overhead in using Xvfb. I thought Xephyr cannot create a virtual display (for example if you are in a text console). I agree that Xephyr would be better if you want to run this inside an existing X session. Regards, Kapil. -- +-+--------------------------------------------------------------------+-+ You've asked a question of The Answer Gang, so you've been sent the reply directly as a courtesy. The TAG list has also been copied. Please send all replies to tag@lists.linuxgazette.net, so that we can help our other readers by publishing the exchange in our monthly Web magazine: Linux Gazette (http://linuxgazette.net/) +-+--------------------------------------------------------------------+-+ _______________________________________________ TAG mailing list TAG@lists.linuxgazette.net http://lists.linuxgazette.net/mailman/listinfo/tag From tag-bounces@lists.linuxgazette.net Wed Mar 25 07:08:58 2009 Return-Path: Received: from linuxmafia.com (linuxmafia.com [198.144.195.186]) by genetikayos.com (8.12.11.20060308/8.12.11) with ESMTP id n2PE8nrE028531 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NO); Wed, 25 Mar 2009 07:08:51 -0700 Received: from localhost ([127.0.0.1]:40028 helo=linuxmafia.com) by linuxmafia.com with esmtp (Exim 4.61 #1 (EximConfig 2.0)) id 1LmTmH-00078w-P7 ; Wed, 25 Mar 2009 07:08:26 -0700 Received: from genetikayos.com ([64.246.26.120]:48479) by linuxmafia.com with esmtps (Cipher TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.61 #1 (EximConfig 2.0)) id 1LmTlW-00078L-Om for ; Wed, 25 Mar 2009 07:08:12 -0700 Received: from localhost.localdomain (genetikayos.com [64.246.26.120]) by genetikayos.com (8.12.11.20060308/8.12.11) with ESMTP id n2PE7OK9028392 for ; Wed, 25 Mar 2009 07:07:25 -0700 Received: from localhost ([127.0.0.1]) by Tyr (bssmtp 0.3) with SMTP id 42802146; Wed, 25 Mar 2009 10:03:24 -0400 From: Ben Okopnik Message-ID: <20090325140321.GA7526@linuxgazette.net> Date: Wed, 25 Mar 2009 10:03:21 -0400 To: The Answer Gang Mail-Followup-To: The Answer Gang MIME-Version: 1.0 Content-Disposition: inline X-gazette-tag: Ben User-Agent: Mutt/1.5.18 (2008-05-17) Received-SPF: none (linuxmafia.com: domain of ben@linuxgazette.net does not designate permitted sender hosts) X-EximConfig: v2.0 on linuxmafia.com (http://www.jcdigita.com/eximconfig) X-BeenThere: tag@lists.linuxgazette.net X-Mailman-Version: 2.1.8rc1 Precedence: list Reply-To: The Answer Gang List-Id: The Answer Gang List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: tag-bounces@lists.linuxgazette.net Errors-To: tag-bounces@lists.linuxgazette.net X-EximConfig: v2.0 on linuxmafia.com (http://www.jcdigita.com/eximconfig) X-SA-Exim-Connect-IP: 127.0.0.1 X-SA-Exim-Mail-From: tag-bounces@lists.linuxgazette.net X-Spam-Checker-Version: SpamAssassin 3.2.4 (2008-01-01) on genetikayos.com X-Spam-Level: X-Spam-Status: No, score=-2.5 required=5.0 tests=AWL,BAYES_00,SPF_HELO_PASS autolearn=ham version=3.2.4 Subject: [TAG] tct: 2-cent Tip: Converting from $FOO to MP3 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-SA-Exim-Version: 4.2.1 (built Mon, 27 Mar 2006 13:42:28 +0200) Status: RO Content-Length: 4481 Lines: 103 Recently, while organizing my (very large) music library, I analyzed the whole thing and found out that I had almost 30 (!) different file types. Much of this was a variety of info files that came with the music (text, PDF, MS-docs, etc.) as well as image files in every conceivable format (which I ended up "flattening" to JPG) - but a large number of these were music formats of every kind, a sort of a living museum of "Music Formats Throughout the Ages." I decided to "flatten" all of that as well by converting all the odd formats to MP3. Fortunately, there's a wonderful Linux app that will take pretty much every kind of audio - "mplayer" (http://www.mplayerhq.hu/DOCS/codecs-status.html#ac). It can also dump that audio to a single, easily-convertible format (WAV). As a result, I created a script that uses "mplayer" and "lame" to process a directory of music files called "2mp3". It was surprisingly difficult to get everything to work together as it should, with some odd challenges along the way; for example, redirecting error output for either of the above programs was rather tricky. The script processes each file, creates an MP3, and appends to a log called '2mp3.LOG' in the current directory. It does not delete the original files - that part is up to you. Enjoy! ``` #!/bin/bash # Created by Ben Okopnik on Mon Jul 2 01:16:32 EDT 2007 # Convert various audio files to MP3 format # # Copyright (C) 2007 Ben Okopnik # 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 Free 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. ########## User-modifiable variables ########################### set="*{ape,flac,m4a,wma,qt,ra,pcm,dv,aac,mlp,ac3,mpc,ogg}" ########## User-modifiable variables ########################### # Need to have Bash expand the construct set=`eval "ls -1 $set" 2>/dev/null` # Set the IFS to a newline (i.e., ignore spaces and tabs in filenames) IFS=' ' # Turn off the 'fake filenames' for failed matches shopt -s nullglob # Figure out if any of these files are present. 'ls' doesn't work (reports # '.' for the match when no matching files are present) and neither does # 'echo [pattern]|wc -w' (fails on filenames with spaces); this strange # method seems to do just fine. for f in "$set"; do ((count++)); done [ -z "$count" ] && { echo "None of '$set' found; exiting."; exit 1; } # Blow away the previous log, if any >"${0##*/}.LOG" # The child process spawned just below allows dealing with the STDERR # redirection; it seems that you can't just do 'exec 2>foo' in the current # shell. This may be a Bash bug. ( for i in $set do fn="${i##*/}" base="${fn%.*}" # Dump STDERR to the log; 'mplayer' can't handle the '2>foo' # redirection semantics exec 2>>"${0##*/}.LOG" echo "######### ${0##*/}: Processing $i #########" >&2 echo -n "*** MPLAYER: ***" >&2 echo -n "'$i': Dumping via Mplayer... " time /usr/bin/mplayer -msglevel all=-1 -vc null -vo null -af resample=44100 -ao pcm:fast "$i" > /dev/null [ "$?" -gt 0 ] && echo "############ ERROR (mplayer): Check ${0##*/}.LOG for details." echo -ne "\n*** LAME: ***" >&2 echo -n "Encoding via Lame... " time /usr/bin/lame -S -m s audiodump.wav -o $base.mp3 [ "$?" -gt 0 ] && echo "############ ERROR (lame): Check ${0##*/}.LOG for details." [ -e "audiodump.wav" ] && /bin/rm audiodump.wav # Wrap the console report line echo done ) ''' -- * Ben Okopnik * Editor-in-Chief, Linux Gazette * http://LinuxGazette.NET * +-+--------------------------------------------------------------------+-+ You've asked a question of The Answer Gang, so you've been sent the reply directly as a courtesy. The TAG list has also been copied. Please send all replies to tag@lists.linuxgazette.net, so that we can help our other readers by publishing the exchange in our monthly Web magazine: Linux Gazette (http://linuxgazette.net/) +-+--------------------------------------------------------------------+-+ _______________________________________________ TAG mailing list TAG@lists.linuxgazette.net http://lists.linuxgazette.net/mailman/listinfo/tag