Friday, March 20, 2015

Spring cleaning

Been a while, hasn't it ....?

Saturday, March 29, 2008

Hacking picasaweb's flash player

As ive mentioned in my last post, im currently transferring all of my photos to picasaweb :)
I love the service, and im really happy with everything (maybe except the weight of the javascript on the site itself).

Well - since ive effectively killed off my own gallery to for this to make sense, i needed to show off my flashy new gallery on this blog :)

I had a couple of ways to do this:
1) get a drupal module that would do this for me
2) use the embed player that picasaweb offers
3) make my own view using the picasaweb's public api

1) proved to be a no-go, the module is there, but doesnt do any of the things i need
2) is cool, but lacks certain functionality i needed
3) yeah, like i have the time to do that ;)

well, that really left me with only one choice - be happy with the standart player...
or did it ? >:)

The picasaweb flash slideshow player is pretty much like any other slideshow player out there.
Its always album specific, and allows you to only enable/disable the captions, and autoplaying.
This is how the source for the embed player looks like:
<embed type="application/x-shockwave-flash" 
src="http://picasaweb.google.com/s/c/bin/slideshow.swf" 
width="288" 
height="192" 
flashvars="host=picasaweb.google.com&RGB=0x000000&
feed=http%3A%2F%2Fpicasaweb.google.com%2Fdata%2Ffeed%2Fapi%2Fuser%2Flandrzejak%2Falbumid%2F5183182292933551745%3Fkind
%3Dphoto%26alt%3Drss" 
pluginspage="http://www.macromedia.com/go/getflashplayer"></embed>



It takes a list of photos and plays them...
You can already see how to change the size of the embed object by hand - so that it makes a better fit to your site.
Wait, back up - a list of photos, right ?
Where does it get this list from i wonder....

Well, a look at the source told me that it uses flashvars to deterimine what and how its going to get a feed.
feed ? :>
Yes, it uses a simple xml feed from picasaweb, just as described on the api docs.
It also uses some other variables, doesnt it ?
What might those do ? =)

RGB - is a pretty simple one - its the players background color.
Usefull - the default is black, so it wont fit this website at all, i made it white right away.
host - is pretty self explaining as well, and i dont think i need to change this one.
feed - is pretty straightforward as well, and it contains the feed supplying the list of photos to be played.

When you try to change the autoplay and cation options, two new items appear on the list of params:

noautoplay when present in the list disables the automatic slideshow, which now has to be stared manually
captions when present this displays the photo's caption

not too many, huh ?
i actually wanted to make the images repeat themselves and maybe randomize, by default the player just plays them as it gets them, and stops playing when it reaches the last image in the album.
maybe there are others ?
lets check ! :)
lets get ourselves a flash action script extractor, preferebly one that works under linux, and let it loose on the player that picasa provides.
Flare creates a nice text file that contains all of the action script present in the player.

How does action script extract the flashvars from an embed object ?
I googled out that those vars are present in _root.varname, so i grepped the action script produced by flare.
The results:

if (_root.host.length > 0) {
this.hostname_ = _root.host.toLowerCase();
this.hostname_ = 'http://' + _root.host;
if (_root.port.length > 0) {
var v14 = _global.parseInt(_root.port);
if (_root.scalemax != undefined) {
if (_root.interval != undefined) {
var v16 = _global.parseInt(_root.interval);
com.google.photos.slideshow.LH_Viewer.viewer = com.google.photos.slideshow.LH_Viewer(_root.attachMovie(com.google.photos.slideshow.LH_Viewer.symbolName, 'viewer', _root.getNextHighestDepth()));
var v2 = _root.feed;
if (_root.font.length > 0) {
v2 = _global.parseInt(_root.font);
if (_root.text.length > 0) {
this.caption_.rgb = _global.parseInt(_root.text, 16);
if (_root.textBackground.length > 0) {
this.caption_.background = _global.parseInt(_root.textBackground, 16);
if (_root.textAlpha.length > 0) {
this.caption_.alpha = _global.parseInt(_root.textAlpha);
if (_root.captions.length > 0 || _root.capti..1 != undefined) {
if (_root.noautoplay != undefined) {
if (_root.RGB.length > 0) {
var v2 = _global.parseInt(_root.RGB, 16);
if (_root.font.length > 0) {
v3 = _global.parseInt(_root.font);


WHOA ! What do we have here ?
It seems that apart from the ones we already know, there are severall other variables !
Ill save you the gueswork and explain the ones i found:
text - define the captions text color in hex
font - no idea, maybe it was supposed to be the font size, but it doesnt work for me
textAlpha - cation text backgrounds alpha
textBackground - caption text backgrounds hex color
scalemax - not sure, it seems to change the resize algorythm possibly producing images of a closer fit to the embed objects size (instead of just panning them out)
interval - how many seconds per image

As you can see - the ones i was looking for (repeat, random) are not there, but its still pretty interesting.
In the least, it lets you get a more personalized slideshow player :)

Now, playing just one of my albums was pointless, since i had no intention to change the the object every time i added new photos to picasa.
I couldhave just changed the feed to:
http://picasaweb.google.com/data/feed/api/user/landrzejak?kind=photo
i couldhave also changed the number of photos from the default 100 by changing the feed to:
http://picasaweb.google.com/data/feed/api/user/landrzejak?kind=photo
&max-results=100&alt=rss

The limit for the list of photos is 500 - and trust me, its too much for firefox and flash - the xml feed weighs about 1meg at that point.

And whats the point of showing the images, if i cant show all of them, or change their order.
Even i get bored when forced to watch all of my images from just one album - check them out, i pretty much make up in numbers what i lack in photographic skills.
Besides, i didnt want to show all of them, just the best ones....
Like the ones i set up to be the albums main image !
I changed my feed to get all of my albums, along with the preview images:

http://picasaweb.google.com/data/feed/api/user/landrzejak/?kind=album&alt=rss

That worked like a charm ! Looks like the player accepts any kind of picasa's feeds :D

So what did i end up with ?
You can see for yourselves on the right side of this page :)
The player now shows my albums covers, at the proper pace of one image every 5 seconds :)

Hope anyone found this usefull in using picasaweb on their website :)

Tuesday, July 31, 2007

RFC ? WTF is that ?

Well, some technicians actually dont know.
Ive learned this the hard way.
A recent task ive been assigned to is to build a csv parser.
We all know the format.
Comma separated values. If you want to include a comma into the value - you quote it.
If you have nothing to add, just insert a comma.
If your done with the data row - carrige return, line feed.
The standard flatfile has been known for decades.
It was one of the very first industry standards that everyone agreed on.
It was simple, and it just worked.

Then came microsoft.
The company that creates new standards, while destroying the ones already established.
Its like that with odf, it was the same with smb, and its the same with cvs.
A file format which full specification i just managed to enclose into 4 sentences.

But nooooo....
Lets change the comma into a semicolon. As to avoid confusion - we will keep the name (CommaSeparatedValues).
Oh, and lets assume the encoding. After all - everyone knows what excel's local standard encoding is, right ?
Sure we all do. Its win-12xx. Whatever the x.
Oh, and when a line finishes with empty values, lets not waste any bytes. We ignore them.
Just think of all those WATT's saved this way.

Heh.
But all this causes problems mostly on excels part and can be walked around from inside php.
But not all of it.
You have to know (i didnt before stumbling upon a bug) that fgetcsv is linked to the locale your system is running.
I have no fucking idea what difference does it make if the semicolon (below the 127 ascii threshold) is under iso-1/2/3/win-x.
But it does make a difference to php.
Any characters that are not in the locale encoding get cut out.
Obviously without any error message/warning/whatever.
I mean why bother.

Funny thing is - its not so hard to handcode a fgetcsv equivalent in php itself.
I managed to do it in less then 50 lines of code.
And now for the scary part.
Parsing a 7meg file, the php interpreted csv parser is 20% faster then the c++ written one invoked with fgetcsv.
I was fairly certain that i had an error somewhere and was ommiting data.
Doesnt look like it.
Its faster and has fewer restrictions.
Too bad i cant post it here - but its a work project and belongs to the company.

Sunday, November 12, 2006

PHPCON 2006

K, so i fucked up.
The conference came along and i forgot about this site (yet again).
So let me make it up:
from 6.11 to 9.11 i was in frankfurt (beautifull city) at the internationall php conference.
It was really great, i met alot of interesting people, we exchanged ideas and such.
There were alot of geeky discussions, and alot of hacking on each others problems.
Should you want to go there and see for yourself, you simply must sign up for a workshop !
It was amazing, having an open discussion like that with about 30 other geeks Cool.
The hotel in which the whole thing was hosted was rather expensive, but it was a 4 * hotel and you really got what you paid for :)
Hopefully ill have another chance to go there next year and itl be even better.

Update (2015):
Came away from this with some new ajax gimmicks which we included in the build within a few weeks (I don't recall if Selenium was available or viable at the time).

Thursday, March 16, 2006

Going SANE

I recently aquired a new toy.
Yes, anotheir one.
This one i have only for the time being - as it will eventually end up at the clients desk.
But for now - ladies and gentlemen - i present to you:
The Plustek OpticSlim 2400 USB scanner.
For a strangely low price - you can get one too !
Lets be honest - this is low end equipment.
Its designed to work with laptops - thus it requires no externall power source, other then the 5v that your usb2 port can provide.
It also looks pretty cool - its slim, a nice gray metallic, not much bigger then the standard A4 sheet.
And the best part of it all:
it works on Linux with almost no problems :)
There are a few catches that i got caught up in, mostly because last time i used SANE was about 2 years ago.
  1. You need to extract the firmware from the windows drivers.
    This isnt too obvoius - but it seems that alot of hardware thats usb connected these days doesnt have any firmware in them what so ever (besides the bare minimum that is needed to upload the real firmware). This is the case with some modems, printers and - yes - scanners.
    So you basicly need to have a M$ system somewhere to get the firmware.
  2. Once its all in there - you need to take a look at your permissions.
    First thing - when playing around - you might as well do it as root.
    You probably dont have the hotplug tools that change perms on the fly when you connect something.
    Im sure they arent in any way sugdested or bundled with SANE in debian, so you might have to get that package.
  3. AFAIK this is driver specific - so it might, or might not concearn you:
    the scanner has a 15 wait to heat up the lamp on every scan you make. Loosing minutes - yes, but nontheless the speed is pretty good, so im not going to bitch about it.
    I read somewhere that its a driver bug, but got no such response in #sane on freenode - so this might not be true. I dont really have a windows machine to test it on and see if its the same there.
All in all - i really like it. It worked almost out of the box - and the problems ive had were only my fault.
I would consider getting one for myself, but i would rather get a digitall cam, or an ipod B)

In (un)related news - the gallery "feature" is now fixed, soon i will post some images scanned with this puppy in there :)