Home

Aug. 29th, 2008

Using Perl to process MP3s

I recently got a Squeezebox Duet and have been getting my large MP3 collection into shape. It turns out that SqueezeCenter prefers different tags than Amarok. So getting my music to appear the same in both places has been quite a task. What I figured out is that I had to remove extra junk from the files, convert any tags to ID3v2.4, and then for good measure I strip the ID3v1 tags.
I found three linux programs that do this well, mp3check, eyeD3, and id3convert (part of the id3lib project), but running them manually and remembering which one does what was too hard... So I wrote a Perl script to simplify the process. It takes paths as command line arguments, and will process the MP3s the way I like 'em. It even sets the permissions correctly!

Here it is. )
Tags:

Jul. 22nd, 2008

Pidgin Identica Status Plugin

To go along with this post, I finished the first working version of my pidgin-identica-status plugin today. It pulls an RSS feed from identi.ca, and sets the latest entry as your status in Pidgin.
It feels like a hack to me; the Perl API for Pidgin is poorly documented. I set up a Google Code project for it, and would welcome contributors to clean up the code, ad functionality, etc...
http://code.google.com/p/pidgin-identica-status/

Jul. 19th, 2008

Perl and Pidgin's API

I'm trying to write a plugin for the Pidgin IM client in Perl that would take your latest post to http://identi.ca from an RSS feed and set it as your Pidgin status message. However the Perl API for Pidgin is poorly documented and I'm having trouble. I based a lot of it on the pidgintwitter-plugin.

I'm not sure what's going on exactly though I suspect I'm not passing the URL correctly to the the parsing subroutine.
Any help would be appreciated.

code behind the cut )

May. 29th, 2008

Geek Dad, or using Perl to do math

Yesterday [info]littlemeridian came to me and said she knew the sum of 1+2+3... etc to 100. She had figured out a way to solve the problem without adding all the numbers.
"I can bang out a perl program that can do the math," I said, not convinced she was right (she was right, btw). So we sat at my computer and I wrote this easy program that adds consecutive numbers up to a limit you specify from <STDIN>. It took us a little while to get the math right but we eventually got it.
see the code )

May. 20th, 2008

Ubuntu and Gmail

I was tired of not having mailto: links work correctly on my Ubuntu machine, so I did a bit of google-ing and found a very useful Perl one-liner here.

perl -MURI::Escape -e '$to= shift; if ($to =~ /^([^\?]+)\?(.*)$/){$to=$1;$args="&".$2;$args=~s/\&subject=/&su=/};$to =~ s/^mailto://i; exec("firefox","https://mail.google.com/mail/?view=cm&fs=1&tf=1&cmid=22&to=".URI::Escape::uri_escape($to).$args);' '%s'


Ubuntu (and possibly other Gnome) users, stick this in the Mail Reader custom command field of System -> Preferences -> Preferred Applications -> Internet.
Thanks to dcrooke at gmail dot com. It works like a charm.

Apr. 26th, 2008

Version 1.0

To go along with this post.


 

Apr. 25th, 2008

question for you perl programmers...

I wrote a script that will post to twitter. It takes a command line argument or reads a random line from a text file, and posts the result. I've got it working, but I think code could be a little cleaner.
Basically, I want to know if there is a way to put each element in an array ( like @ARGV) into a string.
For instance, if I run perl post-to-twitter.pl here is a tweet, I'd like to turn "here is a tweet" into a string so I can put it in a scalar like $post.
I think I could use a reference, but I have a hard time wrapping my head around the concept. I really want to turn the last 4 or 5 lines into one.

Thanks...

here's my code )

Oh yeah, if the command line argument has an apostrophe, the script breaks... Why is that?

Mar. 5th, 2008

Perl and regular expressions

I'm doing what my boss calls "professional development," aka learning more Perl and prgramming skills. Today I was doing an exercise that was pretty simple. Calculate an employee's gross pay based on their rate of pay, hours worked and overtime hours worked. The math is easy.

$pay_rate * ( $reg_hours + ( $ot_hours * 1.5 ) )

But then I wanted to validate input, so my program wouldn't break when the user input wasn't non-numeric. I came up with (what I think is) a unique test. I created a regex that matched only digits and an optional decimal point.

/(\d+\.?\d*)/

Problem was it let through input like 7.h. I didn't want that. So I just compared what the regex matched to the string I was putting throught the regex! If they matched, input was valid!

if ( $_[0] =~ m/(\d+\.?\d*)/ and $_[0] eq $1 ) {
$is_valid=1;
}


I'm giving myself a self congratualory high-five.
mangavatar

July 2009

S M T W T F S
   1234
567891011
12131415161718
19202122232425
262728293031 

Advertisement

Syndicate

RSS Atom
Powered by LiveJournal.com