Monthly Archives: December 2013

Audiobooks on the iPod

Librivox is amazing. You can find some excellent books that you can listen to, when you just don’t have the energy to read. Now, like a podcast, when you’re listening to an audiobook, you may want to stop in the middle and resume your listening at a later time. If you’ve got an iPod and are ok with using iTunes, that’s pretty straightforward. You can download either the m4b or the mp3s and join them to make an audiobook. If you’re on linux you run into several issues.

First, what’s an m4b? It’s just like an m4a which has been renamed (one solution) or you can look at the wikipedia article here to find out more. The cool thing about it is that you can have chapters, just like those in your books, for audio, and all of those can be in one file. Additionally, when you listen to an audiobook on the ipod it saves your last position, so even if you ran out of juice or decided to take a break, you can always get back to where you were. So, a very useful format indeed.

Now, on linux, I know of no one who has a working version of iTunes on WINE. The only option is to install it in a virtual windows machine. Sucks. And I do want to get away from iTunes. So, the problems faced are:

  1. Convert your mp3s to a m4b audiobook
  2. Load those onto the iPod.

I researched the first for a long long while (2 weeks on and off) and then kicked myself when I stumbled across m4baker in the debian stable repository!! What could be easier? You can download it here if you’re on linux – in case it’s not in your repository. If you’re not on linux, well you can easily use iTunes, can’t you? 🙂

Loading it onto the iPod – I’ve got a gen5 classic (video iPod – see? All the stuff you learn when you use Linux. I wouldn’t have to think about this otherwise). Tried using Rhythmbox, and gtkpod (crashed repeatedly) to copy the file over. It copied fine. BUT – and that’s the killer – it did not have the bookmark function. At first I scratched my head and wondered if it was a format issue. That kept me busy for a few days, but then I figured I’d move it over with iTunes. I did and the file worked just fine… so after much fiddling, I figured it was Apple. They’re just messing around. I tried looking for software on linux that’d help. Nothing. So, I was stuck with two options – a) Change the genre to a podcast (which I know would work) or b) use iTunes to transfer the file over – which sucks!

I’m trying out option 3. Install Rockbox onto your iPod and get rid of Apple’s software. 🙂 And the best part about Rockbox? Actually there are 2 good things:

  1. Installation is a breeze – I mean it. I couldn’t believe it was installed when it was!
  2. You can dualboot it. So you can have Rockbox and you can have the iOS, coexisting on your iPod. And switching betweem then couldn’t be easier.

And I realized something. The Apple iPod’s been hacked like mad and I think that works in Apple’s favor. The Zune was built way too securely, and look where it is now… anyone heard of it? Lessons to learn…

Converting numbers to text

After trying with Learn Python The Hard Way, I’m continuing with CodeAcademy. It’s fun to do some programming again. After mulling over something significantly challenging for my rusty gears, I decided to solve the problem of converting numbers to text.

The hardest bit was taking the time to think through the issue. I committed the error of coding without thinking. Perhaps the only intelligent thing I did in phase I was working out the mydict dictionary, which did not need to be changed throughout, except that I added trillion to it.

So here’s the code without much ado. When prompted to enter a number, enter just numbers.

E.g.:

Enter a number:832743242
Eight Hundred Thirty Two Million Seven Hundred Forty Three Thousand Two Hundred Forty Two

mydict = {0:"",
          1:"one", 
          2:"two", 
          3:"three",
          4:"four",
          5:"five",
          6:"six",
          7:"seven",
          8:"eight",
          9:"nine",
          10:"ten",
          11:"eleven",
          12:"twelve",
          13:"thirteen",
          14:"fourteen",
          15:"fifteen",
          16:"sixteen",
          17:"seventeen",
          18:"eighteen",
          19:"nineteen",
          20:"twenty",
          30:"thirty",
          40:"forty",
          50:"fifty",
          60:"sixty",
          70:"seventy",
          80:"eighty",
          90:"ninety",
          100:"hundred",
          1000:"thousand",
          1000000:"million",
          1000000000:"billion",
          1000000000000:"trillion"
          }

def to_text2(num,units=1):
    #have to split the number into thousands
    low = num % 1000
    high = int(num /1000)
    #evaluate the lower part
    low_str = ""
    if low!=0:
        hundred = int(low / 100)
        #print h
        if hundred!=0:
            low_str = mydict.get(hundred) +" "+ mydict.get(100) 
        tens = (low %100)
        if tens<=20:
            if tens!=0:
                low_str = low_str + " " + mydict.get(tens)
        else:
            low_str = low_str+ " " + mydict.get(int(tens/10)*10) + " " + mydict.get(tens%10)
        
        if units!=1:
            if low_str!="":
                low_str =low_str + " " + mydict.get(units)
    if high!=0:
        return to_text2(high,units*1000) + " " + low_str.strip()
    else:   
        return low_str.strip()

input_number = eval(raw_input("Enter a number:"))
print to_text2(input_number).title()