February 23, 2011

Grooveshark is in the air ...

Hello to everybody! Some days without posting, but not without making inventions for fun and profit.

I'm enjoying to deploy a geo-social app, but about this i will write another day. Today, I want to speak about Groveeshark. I like Grooveshark, imho is best than Spotify. But, I've got a problem. I'm poor .. so I can't pay 9$/mo. by listen it in my mobile device. Also I want listen it in other devices that haven't got support ;)

So, i've thinking about this problem .. and i've found a workaround: streaming my favourite Groveeshark station through icecast. It's easy and now i can listen it in my phone, in my Wii, in my Xtreamer ...

Step 1: The audio source


Obviously, we need Grooveshark. So, we start a Grooveshark client (desktop or web) in our linux desktop and choose our favorite radio station.


Step 2: The icecast2 server


Yes, we need an icecast2 server. So, go to install it.
apt-get install icecast2
We don't need any special config, only change the default password and start it.

Step 3: The magic command


Now, we've got a Grooveshark client that is playing music in our desktop and a streaming server that is ready to relay audio. So, we need connect our music with our streaming server. How?

It's very easy. We only need three tools: arecord, lame and ezstream and put all together.

arecord -f cd -t wav | lame - - | ezstream -c /etc/default/ezstream_groove.xml

This is the command. With arecord we record the current PCM output, with lame we reencode the WAV stream into a MP3 stream, finally, with ezstream we send the audio to the icecast server.

The ezstream_groove.xml file can be some like this:

<ezstream>
    <url>http://yourhost:8000/groove</url>
    <sourcepassword>YourPassword</sourcepassword>
    <format>MP3</format>
    <filename>stdin</filename>
    <stream_once>1</stream_once>
    <svrinfoname>GrooveIT</svrinfoname>
    <svrinfourl>http://appinventorlife.blogspot.com</svrinfourl>
    <svrinfogenre>All</svrinfogenre>
    <svrinfodescription>GrooveShark Radio</svrinfodescription>
    <svrinfobitrate>128</svrinfobitrate>
    <svrinfoquality>3.0</svrinfoquality>
    <svrinfochannels>2</svrinfochannels>
    <svrinfosamplerate>44100</svrinfosamplerate>
    <svrinfopublic>1</svrinfopublic>
</ezstream>

Step 4: Listen your station



Our icecast server will be played in a lot of devices:

- Android with Online Raadio
- Homebrew Wii with WiiRadio
- Any VLC compatible device
- ...

Step 5: Making it stable


Finally, if we want deploy this idea, we need make it stable. How make it?

First, we making a script that relaunch the stream if fails.
#!/bin/bash
while true
do
 echo "Streaming ..."
 arecord -f cd -t wav | lame - - | ezstream -c /etc/default/ezstream_groove.xml > /dev/null
done
Second, Grooveshark stops the music if detects inactivity. So, we need simulate activity in our desktop. For this, we need a random mouse movement :)
#!/usr/bin/python

import random
import time
from Xlib import X, display

while 1:
 disp = display.Display()
 scr = disp.screen()
 root = scr.root
 root.warp_pointer(random.randint(100,800),random.randint(100,600))
 disp.sync()
 time.sleep(10);
This is all ... enjoy it :)

P.S. You can try your invents with this: streaming OGG and use a HTML5 client and others ...

February 3, 2011

ISBNDownloader: the movie

Yesterday, I wrote that ISBNDownloader might seem SCI-FI. This video shows that it isn't SCI-FI. You get a book, scan its barcode and obtain its direct download in your JDownloader desktop client. Enjoy it!

P.S. This video is dedicated to Sinde-Biden law :)

February 2, 2011

ISBNDownloader: a "hello world" basque style for App Inventor ...

A lot of hackneyed subjects exist in Spain. I think that the most hackneyed subject is that women are dark-haired, tanned skin and they spend all day singing flamenco. Of course, men know playing the guitar and they spend their time fighting bulls. Obviously, this isn't true, but ... who cares? There also exist other less widespread hackneyed subjects. I love specially one, it's about basque people: they are crudes. They don't play soccer or basketball, they cut down trees, raise huge stones and also eat cows for breakfast (this maybe a gossip).

Anyway, this post exists because I want to pay tribute to basque people and their hackneyed subject, therefore, I can't make a typical Hello world for App Inventor, I need to make a Hello world! basque style.

First Step: the idea.


So, if I want to make a Hello world! basque style, I needed an idea and I've found it some days ago:
  1. You get a book.
  2. You capture its ISBN through a barcode scanner.
  3. You search in Google Books for it and you export its bibliographic information in ENW format.
  4. You search if a direct download exists for the book in the most famous spanish bookz portal: QuedeLibros.
  5. If a direct donwload exists, you export the download URL to JDownloader desktop client.
  6. You download the book at your home. Legal advisory: this is only legal for books that you've in your library. Are you a legal?
Maybe you think: this is Sci Fi! But i tell you that it's real: you get a book, you scan its barcode and you download it at your home. Easy, fast and free. Sounds good? We go to make it.

Second Step: the mobile client.


The mobile client has been made with Google's App Inventor. The main components, used in this proyect, are two: barcode scanner and TinyWebDB.

The barcode scanner component lets the application obtain the ISBN code from a book. When the ISBN is readed, it's sended to the intermediate web service through a TinyWebDB request. The web service replies with the name of the book, and if is available, with the direct download URL.

To finish the process, if we want to download the book, the app sends another TinyWebDB request to the web service, notifying to the desktop client that a new download has been requested.

The source code of this proyect is available here. If you wish, you can download it and import in your app inventor account. Sorry, but we don't release the android package, only the source code.

To package and run this source in your Android device, you only need change the ServiceURL of the ISBNWebDB component. By default is set to http://domain/isbndownloader/, so if you try it without change the ServiceURL, it will fail.

Third Step: the intermediate webservice.


At this moment, if you want to make a rich application with "App Inventor", only an approach is available: you make a thin client for the Android device, and move the model and heavy logic to a intermediate server, communicating both extremes through TinyWebDB.

ISBNDownloader uses two PHP scripts to emulate a TinyWebDB service. These PHP receive/send data from/to the Android device. It uses a BASH script for web scraping routines: parsing google books, parsing quedelibros, etc. Also we've a PHP script to send the directs downloads urls to the desktop client. We've been made a compatible TinyWebDB service using mod_rewrite and a .htaccess file.

The source code can be downloaded from here.

Fourth Step: the desktop client.


At this moment, the desktop client is only a cron script for Linux that receive the downloads urls from the intermediate server and insert into JDownloader internal web server.

The source code can be downloaded from here.

Five Step: all together.


Finally, if you want to make your ISBNDownloader service, you need make the next steps:
  1. Install the mobile application in to your Android device. First, import the source code for Android app into App Inventor. Second, change the ServiceURL in the ISBNWebDB to your intermediate web service. Finally, package the proyect and download it in your Android device. Remember to let install unsigned app in your device.
  2. Deploy the intermediate web service in an Apache web server. You need inflate the gziped file, move the www folder to Apache htdocs folder and move the file bin/isb2qdl to /usr/local/bin. If you can't put the isb2qdl file into /usr/local/bin folder, you must edit the getvalue.php script to set your isbn2qdl path properly.
  3. Download the cron script and setup a cron task for this script in your desktop client. I propose you an entry like this: */5 * * * * nobody /usr/local/bin/isbndownloader, looking for downloads every five minutes.
  4. Install the JDownloader web interface in your desktop client and setup the web server to localhost:8030. JDownloader by default listen to *:tcpport, so you need iptables to filter incoming connections from others hosts and only allow locahost communication.

Enjoy it!

Why jquerymobile is not good enough for our current application

Yesterday I wasn't able to explain here what I've found testing jquerymobile and iScroll together, but as I promise I'm here today to tell you what happened.

First of all I want to say a little disclaimer. What I'm writing here is my opinion based on my experiences. If I say "doesn't work", perhaps I should be more polite saying "doesn't work for me"... and perhaps it's my mistake being so fool to make it work properly. But hey! This is The App Inventor's blog, so as far I don't critizice him I believe I can do that ;)

Why did I try to put together jquerymobile and iScroll? If you tried to work with PhoneGap for anything far than a "hello world" and you need to scroll your mainpage, you see a disgusting effect. The page scrolls far than its limits... just like when you're browsing a webpage!!. It's pretty obvious you are just embedding a webview on a container and I believe it's not good for users perception.

So I started to find a way to make my users experience better, and found we can avoid scrolling with a simple event.preventDefault(); attached to touchmove event. Great, no more scrolling out of boundaries... but no more scrolling anytime, at least with common gesture. I tried to set-up a div container with "overflow:scroll", but no luck until i've found iScroll.

iScroll works nice as far as you don't put a lot of elements into the container. Also I've found a "minor" flaw, being unable to override the issue of check the DOM for changes for itself. That made iScroll to calc more than it needs, so it lowers down performance. But it's still a good choice and a sacrifice I can do without so much less of performance.

I wanted to use jquerymobile just for my layout. First screen in the app will ask the user to choose for a location, and it seems the most natural way showing available locations in a list, the user can scroll (using iScroll) and choose to continue to next step in the app. My list was dynamic, building it getting information from a JS and appending li elements on my previously defined and empty ul.

That's how I understood how jquerymobile works from inside. It doesn't have a stand-alone css collection to skin the components, just it relays on its JS to skin them... so after building the list, I need to ask the framework to "skin it" via #mydiv.page(); to render it.

When I do that, seems boundaries of iScroll doesn't update properly, so I have to ask iScroll to get them handly with a call to myScroll.refresh(); and... it works, but it's to heavy for little processors on some "old" mobile devices and navigation is not as fluid as it should be.

I hope jquerymobile developers will evolve their product a lot (let's remember it's alpha 2 at this time), but currently is not an option to work with in the scenario I described before, so for now I'm keeping it on my toolbox for another usages and I'm looking to build (or find) a better way to skin my scrollable lists, preferably using pure CSS if possible.

Have anyone out there found a good solution to this issue? Let me and The App Inventor know!

February 1, 2011

... in a land far,far away ...

It was a matter of time, and I have to admit it... I knew it will happen sooner or later.

The App Inventor told me he pretended to do something with mobile devices and blog about it, and it was obvious for anyone who knew us that I was going to follow his steps. I was doing my little experiments with mobile phones since J2ME times, but I never have found the time and the idea to "be in the business". Perhaps that's why I'm not rich... or perhaps is my lazyness... whatever...

I was talking about not finding time or ideas... Time is still hard to find, but The App Inventor is a guy full of ideas. Unfortunately not all of those ideas are great, nor even good, but sometimes he finds a good one, it's a matter of statistics. On the other side, I have almost no ideas so I can't have good ones.

So we started to create a mobile application... but not a plain "hello world", just something with multiple screens, scrolling, data storage, webscrapping (if you can't find a webservice you have to scrap) and perhaps some usage of phone capabilites like gps. And the aim of the application is not making money (still!) but learning from the inside.

I've found some time today to play and build a little prototype of our first app, testing Matteo Spinelli's iScroll and putting it together with my own CSS, some scrapping code in JS and jquerymobile... but I haven't found the time to write about that, so I promise to try tomorrow.

Stay tuned!

January 31, 2011

Upon once a time ...

Open a blog is a recursive activity in my life. I opened my first blog in 2001. In the bloggers world has rained a lot since these years: from a smalls communities to the vast inmensity of blogspot, from few nerds to everybody, from a simply personal online diary to all themes that you can have in your head.

I got out of this world the last three or four years, i was tired, but now i need return.

¿Why? Is easy, because i found one thing that i need to tell the world: Google's App Inventor and PhoneGap are better than sex. If sex were like App Inventor or like PhoneGap, everybody might be Rocco Siffredi. One block here, another block there and ready! One tag here, another script there and ready!

But sex isn't like RAD toolkits, so i'm not a pornstar, only an inventor and if you like, you can read about my life.

Welcome.

P.S.: We know that sex is better than mobile development. Really, if you think that a phone is better than sex, you need a psychiatrist.