rulururu

post MP3 to ogg, preserving tags

April 20th, 2008

Filed under: mac — zedr0n @ 2:51 pm

I personally don’t like all those insane 320kbit bitrates, I’m perfectly fine with listening to 80kbit ogg(which sounds like 128kbit mp3 occupying less space at the same time). As it’s impossible to convert from inside iTunes(oh, Foobar, where art thou?) I had to resort to command line tools. The tools we’ll need are

  • LAME - mp3 encoder
  • eggenc - ogg encoder(you’ll need to build libogg, libvorbis, vorbis-tools but it builds out-of-box)
  • id3tool - mp3 tag viewer(and editor) - also builds successfully
  • Grep and sed - text manipulators, powerful standard tools

Now the bash script which will convert all the supplied mp3 files to ogg(mp32ogg):

#!/bin/sh

for file in "$@"
do
    if test ! -f "$(basename "$file" .mp3).ogg"
    then
        lame --decode "$file"
        ARTIST=`id3tool "$file" | grep Artist | sed s/Artist:// | sed 's/[^A-Za-z0-9]*//'`
        ALBUM=`id3tool "$file" | grep Album | sed s/Album:// | sed 's/[^A-Za-z0-9]*//'`
        TRACK=`id3tool "$file" | grep Track | sed s/Track:// | sed 's/[^A-Za-z0-9]*//'`
        YEAR=`id3tool "$file" | grep Year | sed s/Year:// | sed 's/[^A-Za-z0-9]*//'`
        GENRE=`id3tool "$file" | grep Genre | sed s/Genre:// | sed -e 's/[^A-Za-z0-9]*//' -e 's/(.*)$//'`
        oggenc -a "$ARTIST" -G "$GENRE" -d "$YEAR" -N "$TRACK" -l "$ALBUM" -b 80 "$file.wav" -o "$(basename "$file" .mp3).ogg"
        rm "$file.wav"
    fi
done

In case you wonder why it uses such strange long lines, the process of getting the artist for example can be described as follows:

  • id3tool “$file” - get tags
  • grep Artist - get line containing word Artist
  • sed s/Artist:// - remove the preceding string “Artist:” from the line
  • sed ’s/[^A-Za-z0-9]*// - remove the unnecessary spaces/tabs/etc… before the artist name itself(the actual meaning is remove all characters before encountering alphanumerical - A-Z or a-z or 0-9)

Btw, basename “$file” .mp3 is just a neat way to strip mp3 extension preserving the filename itself.

The syntax is straightforward - you could use built-in wildcards - e.g. mp32ogg T*.mp3 will convert all mp3 files starting with T.

post RPM’s on OsX

March 19th, 2008

Filed under: mac — zedr0n @ 12:18 pm

Recently one of the ways to distribute packages(binary and source) is by using RPM. That’s all very good and everything but what to do if the rpms aren’t supported - as on osX? It gets a bit trickier but still manageable.

First grab the perl script - rpm2cpio.pl. Its usage is pretty straightforward

rpm2cpio, perl version by orabidoo <odar@pobox.com> +sw
dumps the contents to stdout as a cpio archive

use: rpm2cpio [file.rpm] > file.cpio

Here's how to use cpio:
    list of contents:   cpio -t -i < /file/name
       extract files:   cpio -d -i < /file/name

Thankfully, cpio is natively available on osx, so that’s pretty much it all amounts to.

post Par2 on OsX

March 19th, 2008

Filed under: C++, Coding, mac — zedr0n @ 12:08 pm

There’s a handy tool for correcting data errors - Par2

The command line utility for linux is included in most packages, but alas not so on macos. There are still two ways to go - there is a port over at MacPorts but I already have Fink installed and I didn’t really want to get another clutter in the system. So I just found the ALT Linux Source, extracted the rpm and built it.

You can grab the source here Par2.tar.gz
Now just extract it and build it

tar -xvf par2.tar.gz
cd par2cmdline-0.4
chmod +x configure
./configure
make

Now you can just move par2 utility to your path directory of choice.
Just in case you don’t want to bother building it - grab the binary here - par2.bz2

post Vim & LaTeX on a mac

February 26th, 2008

Filed under: mac — zedr0n @ 9:38 pm

Since I’ve moved to mac not so long ago, I was happy that most of the apps I normally use are ported to os x.
As I’ve been writing a lot of mathematical stuff in LaTeX it soon got quite annoying constantly recompiling, closing previous Preview.app instance and opening it again so that the pdf file gets properly reloaded(on Windows dvi viewer reloaded automatically). Seems like this wasn’t only my problem as there turned out to be a pdf/dvi viewer out there with automatic reloading - Skim.

I’ve also learned about pdfsync which is quite neatly handled in Skim - just Shift-Command-Click and it opens Vim at the corresponding line in tex file, nice…

While at it, I’ve switched to MacVim because of better integration with pdfsync, along with nicer aqua interface, tab support etc…

post Cave story - multiple saves

February 21st, 2008

Filed under: mac — zedr0n @ 12:44 am

There is a very old-skool platformer style game called Doukutsu Monogatari or Cave story. You can read more about it here. It has multiple endings but the main drawback is that it has very limited save support - there is only one save slot available - which is quite similar to another old-skool game ADOM.
But it doesn’t take a super-guru to right things for this one. Here is a quick-coded bash script which adds the capability for multiple saves. It’s based on the fact that the save progress is stored in file ~/Library/Preferences/com.nakiwo.Doukutsu.plist
What is done precisely is just saving the current file to a Save directory with a description supplied by the user.

Installation:
- Download doukutsu script here
- chmod +x doukutsu in case it’s not executable
- create a directory named Saves in the directory where you put doukutsu script
- you are done

The usage is straightforward, just follow the instructions when running the script.

P.S. It will locate the Cave Story .app file on its own if it has been put in /Applications folder

post Custom refresh of NetNewsWire with AppleScript

January 16th, 2008

Filed under: Coding, mac — zedr0n @ 5:00 pm

I’ve switched to mac just recently and haven’t yet found the alternatives for all the windows tools. I’ve been trying Newsfire for some time and I’ve been somewhat satisfied with its performance. But since I’ve discovered Wilmott Forums RSS feeds I was having problems with Newsfire - it doesn’t change status, nor in any other way acknowledge small item updates. And as Wilmott goes with the one-item-per-thread model, so that the item just contains the date of the last post, it was more or less useless for with Newsfire.

Then NetNewsWire went freeware, so I decided to give it a try. It has a useful feature - “mark updated items as unread” while also sorting the items by the last update time, which is more or less what I need. Although, I need to say that it doesn’t mark items as unread after tiny updates - as on Wilmott, so it’s not ideal. One other problem with NetNewsWire is that the minimum refresh time is set to 30 minutes. While it might be acceptable to most feeds so as to not get distracted all the time, I want to get faster wilmott updates. Well, when there’s a will, there’s a way. And this way is called AppleScript.

Skip down for new beta of custom refresh app

The first, and by far simpler, way is to use a script. It’s pretty straightforward - just open up Script Editor and insert

repeat
  tell application "NetNewsWire" to refreshAll
  delay 300
end repeat

I’ve settled on 300 seconds for delay time, but whatever one wants. Now, running the script manually, looks like a chore and it still shows up as a window. So, to improve it, we can do File->Save As->application bundle. Still not much improvement so far, we can’t even quit the app. But we don’t really need it if we hide it. And it can be easily achieved by adding to /NameOfApp.app/Contents/Info.plist

<key>LSUIElement</key>
<string>1</string>

This key tells the app to work in background/dockless mode, which is precisely what we need. The cpu usage is quite modest indeed, so we can just add it as a Login item and all’s done. The NetNewsWire now refreshes as fast as we want it too.

The second way is for those who just need to be able to stop refreshing without resorting to Force Quit. It’s a bit harder, and involves using XCode.
The standard way to automate actions in Os X so far seems to use Automator, and NetNewsWire is no exception. Unfortunately, the number of actions available is rather limited, and no refresh/refreshAll action available. But we can create a new action on our own. To do this, simply do
XCode->New Projects->New AppleScript Application. Now the files we need are main.applescript, Info.plist, InfoPlist.strings. The script is just

on run {input, parameters}
    tell application "NetNewsWire" to refreshAll
    return input
end run

Now, if we switch to Release mode and build the app, the only thing left to install the action is to copy from project directory to either /Library/Automator or ~/Library/Automator. It will show up in Automator but as a separate action unrelated to NetNewsWire, it will work, but it does annoy a bit. That’s why we’ll need Info.plist - we change AMApplication key to

<key>AMApplication</key>
<string>NetNewsWire</string>

And that’s all we need to do for the app to show under NetNewsWire. To clean up things a bit, we can also edit InfoPlist.strings

AMName = "RefreshFeeds";
/*  AMDescription localized strings  */
AMDSummary = "Refresh all feeds";

Everything else there is irrelevant for our purpose.

The only thing left is just to create an Automator workflow of the format:

  • NetNewsWire-> _our new action to refreshAll in NetNewsWire_
  • Automator->Pause
  • Automator->RunWorkflow

Now we can save the workflow as application and apply the same trick with LSUielement. The only difference is on the menu bar
Menu Bar refresh

We can stop it at any time by pressing the red button. The disadvantages with this approach is 5-10 times bigger cpu usage(well, under 1% still) and clutter on the menu bar - but whatever one prefers…
You can download both apps here - script RefreshRSS and Automator RefreshFeeds

Thanks to a request from Theodora I’ve tried to improve the script a bit to allow for custom subscription refresh. It’s beta for now, so any comments are highly welcome, though it should work ;) So, what’s in the Refresher.app? It’s still just a script as RefreshRSS but with a few tweaks. Upon launch you’ll get a dialog in NetNewsWire asking

netnewswire001.jpg

If you click yes, then you’ll get a list of all your subscriptions where you need to choose the one you wish to set/change the refresh rate, it looks smth like this
netnewswire002.png

If you select the subscription you haven’t previously set the refresh rate for you’ll just get a dialog box
netnewswire003.png

The default value is 5 minutes; pressing ok will bring you again to the dialog box asking if you want to add another refresh rate.

If for whatever reason you want to change the refresh rate for subscription you just select it from the list and get a dialog box like
netnewswire005.png

That’s pretty much it. For technically oriented, this is pure AppleScript, all the details of your subscriptions are stored in ~/Library/Preferences/Refresher.info in format “Subscription:refresh time” on every line.

You can get it here : Refresher.zip

p.s. If you are getting error message “file Macintosh HD: … is already open” then this means that app crashed earlier and you’ll have to reboot to close it properly. Anybody knows how to close file opened with open for access under applescript for that matter?

ruldrurd
© quant0r.com , Designed by Stealth Settings
Entries (RSS) and Comments (RSS)