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!

No comments:

Post a Comment