Open Source Photoblog Workflow with phpGraphy

As I am lucky enough to be able to travel a bit in the near future, I thought of blogging a few pictures en route. I wanted to do this from my Androidphone (2.3) without the hassle of logging in some software or website, let alone to use some BS like Instagram. I’ll try to explain in all briefness.

The main idea behind this is to have some sort of sync-mechanism between the phone and the blog which automatically renders directories and pictures as HTML. I choose phpGraphy as my main tool. It supports a flat file database and renders any content in its /pictures/ folder based on date of creation.

Since I had some concerns to put the password for my main webspace into the hands of some random Android-app I created a uberspace for my pictures. If you’re in or near Germany I highly recommend these guys – great support, incredible features, almost anonymous. The next was to get BotSync on my phone which enables uploads via SSH. You just specify directory on your phone to be uploaded and the destination on the server – a very slim & fast app. So, I can take a picture, organize it via some file management app and upload it to my picture-uberspace.

To get it on my main webspace I used rsync with SSH. You can find plenty of tutorials on the net regarding this.

rsync -avze 'ssh -i /home/user/.ssh/id' user@host.de:/home/user/html/and-upload/ /home/user/html/phpgraphy/pictures

Since phpGraphy sometimes messes up the thumbnail creation with the original pics of my phone’s camera, I run mogrify to resize them. Because I want to resize every picture in any directory the ‘find’ will look for any file with a jpeg-extension; the mogrify will set any side of the pic to 1400px which is more than enough.

find /home/user/html/phpgraphy/pictures/ -name "*.jpg" -exec mogrify -resize '1400x1400>' {} \;

Of course, these tasks need to be automated. Cron will take over and run these two commands every morning at six o’clock.

crontab -e
0 6 * * * /home/user/sync.sh

phpGraphy supports furthermore a cool feature concerning the naming convention. You can set it up to use a EXIF field for the image’s name. A few apps like Photo Editor allow to edit the EXIF metadata on Android. So I edit the User Comment EXIF field and tell phpGraphy to use this field as title. Works!

The workflow:

Take picture --> (Edit EXIF data) --> Put into upload directory on phone --> run BotSync --> done.

The good thing is I can change this workflow really easy. I can log on my picture-uberspace from any computer without worrying about giving away important credentials and just put some pics in the upload-folder. Then, my main uberspace will fetch the pictures via rsync and puts them in phpgraphy/pictures.

Of course, one could say: just use some service other than Instagram if you don’t like it. But this way I can control my data w/o worry about some TOS, pricing plans or whatnot. And it’s more fun to use something you set up.

Crunchbang Keyboard Layout

I looked for a simple way to change my keyboard layout on crunchbang linux (Waldorf) and found a post by Bogdan Costea and a thread in the FreeBSD forums. Following their information I did this:

sudo gedit /etc/default/keyboard

Besides XKBLAYOUT you add the desired languages (do ls -la /usr/share/X11/xkb/symbols/ for list of available languages). And XKBOPTIONS sets the keyboard shortcut. The FreeBSD-thread lists these possible shortcuts:

grp:toggle – Right Alt
grp:shift_toggle – Two Shift
grp:ctrl_shift_toggle – Ctrl+Shift
grp:alt_shift_toggle – Alt+Shift
grp:ctrl_alt_toggle – Ctrl+Alt
grp:caps_toggle – CapsLock
grp:lwin_toggle – Left "Win"
grp:rwin_toggle – Right "Win"
grp:menu_toggle – Button "Menu"

So my keyboard file looks currently like this:

XKBMODEL="pc105"
XKBLAYOUT="de,fr,us"
XKBVARIANT=""
XKBOPTIONS="grp:menu_toggle"

Bogdan suggests using the small program fbxkb to visualize the current layout. Just add the following to ~/.config/openbox/autostart:

## Run indicator for keyboard layout
fbxkb &

This will show little language indicating png-graphics in the taskbar which look like text. To replace them with actual flags go to /usr/share/fbxkb/images and overwrite the png-files (need to be superuser). One convenient way are the famfamfam flags which use the same naming convention. Just overwrite everything inside the fbxkb-folder.

Note: this still looks somehow crappy since fam³ flags are in 16×16 px and fbxkb displays in 24×24 px – but good enough for me.

And btw: if you are looking to do a ç (cedille) or other special characters without big hassle check out the German Ubuntu wiki. To enter the french ligatures like ɶ or Æ press and hold Ctrl + Shift + u and enter the hexdecimal unicode – see selfhtml or shapecatcher for info on the codes.

Set GPS update rate on Arduino Uno + Adafruit Ultimate GPS Logger Shield

Just in case someone wants to alter the GPS update rate on a Adafruit Ultimate GPS Logger Shield. This may come in handy if you want to reduce the power consumption of your board. According to a datasheet of the GPS-chip the max update rate is 10000ms/10sec. So how do you set it?

Relatively simple: go to your Adafruit_GPS-library, open Adafruit_GPS.h and look for these lines:

#define PMTK_SET_NMEA_UPDATE_1HZ "$PMTK220,1000*1F"
#define PMTK_SET_NMEA_UPDATE_5HZ "$PMTK220,200*2C"
#define PMTK_SET_NMEA_UPDATE_10HZ "$PMTK220,100*2F"

So this will define the name of the method/function/whatever which will be called in your Arduino-sketch, e.g. PMTK_SET_NMEA_UPDATE_1HZ. PMTK220 is the chip-internal code for update rate. So we say: Hey, I want to alter the update rate. The value after the comma is the update rate in milliseconds. We set it to 10000 (or whatever you like). The value behind the * is the checksum which the chip requires. Thanks to Stevens post about reading GPS data with bash I stumpled upon the MTK NMEA checksum calculator. So you put in PMTK220,10000 and get back $PMTK220,10000*2F. That’s it. Our new line would read:

#define PMTK_SET_NMEA_UPDATE_10SEC "$PMTK220,10000*2F"

Just set PMTK_SET_NMEA_UPDATE_10SEC in your sketch and upload it.

PirateBox – some tipps

PirateBox is, without a doubt, a great project. Nevertheless there are some things to consider and also some things to improve. I’ll just make a short list of what I learnt. You are warmly invited to comment. I used the OpenWrt-version of Piratebox.

1) This might be obvious but I never conceived the notion of it until I worked with PirateBox and the TP-Link MR3020-Router: you’re just dealing with linux. After SSH-ing into the router just be free to explore and play around. cd and ls the hell outta this thing.

2) Simplest mode of operating the box is either via wall socket or a battery. Note there are premade affordable 12V to 5V USB-converters available. Just search for ‘12v 5v usb‘ on ebay or somewhere else. 12V (car) batteries are available in your local electronics store (maybe even the converter). A 7000 mAh battery should give you about a day of operating off-grid. This will vary of course due to wireless usage, router type and battery quality.

3) Tech and ‘open something’ people like the word ‘pirate’ – it’s freedom, it’s controlling your destingy, taking what’s yours, operating outside of incrusted structures. For other people it may be – at best – adventure tales and the pirate party (which has a arguable reputation) or – worse – illegal activity, stealing, hacking and so on. So, I decided to alter the SSID of my PirateBox. I called it Open Library – Share freely (instead of PirateBox – Share freely). To do this SSH into the router and follow these instructions. To mirror this information:

Edit the wireless file on the router by

vi /etc/config/wireless (vi cheatsheet)

Look for the SSID option and alter the string (allowed chars), save it and type

/etc/init.d/network reload

You should now be able to use your new SSID. I’d always choose something welcoming; ‘NSA-surveillance van’ maybe not a good idea. 😉

4) Furthermore, I altered the landing page of PirateBox. For two reasons; first, the PirateBox logo without explanation may be intimidating for some people. Second, not everyone is able to read English on a level which is sufficient to be comfortable in this new context. So I changed to PirateBox logo to a pictogram I found on the PLA blog (Number 42). Less intimidating while preserving the notion of sharing.

To change the logo as well as the text on the landing page you cd to

/opt/piratebox/www/
ls -a (shows all (hidden) contents in the folder)

You’ll find index.html (landing page), piratebox-logo-small.png (the logo on the landing page) and .READ.ME.htm (the about page). Code snippets for German ‘customisation’ are below this post. The big logo on the about page stayed the same, since I wanted to give credit to the project.

But how do you get this stuff on your computer to edit it? scp will help you. The article on scp explains it quite well, but just for the record:

scp source target (the general idea behind scp)

scp /opt/piratebox/www/index.html user@yourhost:/home/user/ (this will copy index.html into your home directory; of course, if you’re already in the directory, just put the filename as source; you’ll need the password for ‘user’ on your local machine)

scp user@yourhost:/home/user/index.html /opt/piratebox/www/ (and copy the file back to the router; overwrites without warning!)

Of course, you can edit all the files on the router with vi but it’s more comfortable this way, I guess. So, edit the files the way you want – all you need is a bit HTML knowledge. I started with a little disclaimer that nobody is trying to hack the users computer or will try to do something illegal. But I think the localisation is the important part; make PirateBox accessible by using your local language. (Though, I’d leave the english version as it is to honour the work of David and to be accessible for international folks.)

Well, that’s it. Have fun with shared information on PirateBox and leave a comment. 🙂

————–

Snippets:
index.html

<div><img src="/lib.jpg"/></div>
<div id="message">
<b>1.</b> Was ist das hier alles? <a href="/.READ.ME.htm" target="_parent"><b>Antworten hier</b></a>.<p>
<b>2.</b> Lade etwas hoch. :) Einfach unten Datei auswaehlen und los geht's.</p>
<b>3.</b> Anschauen und Runterladen des Vorhandenen kannst du <a href="/Shared" target="_parent"><b>hier</b></a>.<br>
</div>

.READ.ME.html

<table border=0 width=50% cellpadding=0 cellspacing=0 align=center>
<tr>
  <td width="75"><br></td>
  <td><p>Erstmal: keine Angst - niemand hat vor dich zu hacken oder illegalem Treiben zu verleiten. :)</p>
  <p>PirateBox entstand aus den Ideen des Piratenradios und 'free culture movements' - Artikel darueber findest du auf Wikipedia. Ziel ist dabei ein Geraet zu erschaffen, welches autonom und mobil eingesetzt werden kann. Dabei setzt PirateBox auf freie Software (FLOSS) um ein lokales, anonymes Netzwerk zum Teilen von Bildern, Videos, Dokumenten, Musik usw. bereit zu stellen.</p>
<p>PirateBox ist dafuer gemacht sicher und einfach zu funktionieren: keine Zugangsdaten, keine Mitschnitte wer wann auf was zugegriffen hat. PirateBox ist nicht mit dem Internet verbunden, sodass niemand (Nein, nicht mal die NSA) mitbekommt was hier geschieht.</p>
<p>PirateBox wurde von David Darts erschaffen und steht unter einer Free Art License (2011). Mehr ueber das Projekt und wie Du dir einfach eine eigene PirateBox bauen kannst, findest du hier: http://wiki.daviddarts.com/piratebox</p>
<p>Mit der Partei hat dies hier uebrigens nichts zu tun. ;)</p>
<hr />
</td>
  <td width="25"><br></td>
</tr>
</table>

Convert youtube to audio

So, you want to archive all that cool music these crazy people put on youtube? Be my guest. :]

First of all: check yourself before you wreck yourself. I will definitely not do this but some people trick you with code snippets. One can easily put some hidden characters via CSS into innocent commands that may look ok in the browser but do terrible stuff in your console. So before hitting the big enter button, read the code you are going to input into your terminal.

But let’s get to the fun. You need to get youtube-dl (readme); so on Ubuntu you may type:

sudo apt-get install youtube-dl

Chances are good that youtube changed its API mechanisms since the last repo update, so run the internal update function. You need root privileges since the update wants to alter some stuff in /usr/bin/youtube-dl:

sudo youtube-dl -U

Youtube-dl should work now just perfect. In my case youtube-dl needs to do some batch stuff. I don’t exactly want this (this gets one video and saves it to your hard drive):

youtube-dl 7yJMLArxPaA

I want this:

youtube-dl -a batch.txt

So put all these nice videos respectively their video ID in a text file and run the command like above. The program will fetch one video after another and do some processing (if indicated). Now, you may want to play around with the options of youtube-dl (see readme). For example the -t option will use the title as filename; very handy. But we are only halfway there because what you have now is either flv or mp4 which contains the audio and video track. youtube-dl has an internal audio converter which relies on ffmpeg, so you can easily go like this:

youtube-dl -a batch.txt -t -x --audio-format "wav"

This will get the IDs in batch.txt, fetch the title and put it as filename and directly convert the videos to wav. For mp3-conversion you will have to install the MP3-support for ffmpeg:

sudo apt-get install ffmpeg libavcodec-extra-53

The following command will give high quality mp3-files (which is by the way kind of unnecessary since you’ll never get perfect quality on youtube; expect some stuff that sounds good on your mobile audioplayer and home system, but terrible on anything close to Hi-Fi; so you may want to save some disk space by setting the quality around 4 or 5-ish):

youtube-dl -a batch.txt -t -x --audio-format "mp3" --audio-quality 0

But mp3 isn’t cool. You know what’s cool? 1 Billi… err, ogg/vorbis, I mean. ;] So just enter something like this and get some patent troll-free musical goodness.

youtube-dl -a batch.txt -t -x --audio-format "vorbis" --audio-quality 8

Be aware, the quality parameter is reversed for ogg/vorbis – 0 is low quality, 9 is high quality. Furthermore, you may want to check out hardware with ogg support to not rely on mp3 patents (I once had a SanDisk player). If you have any questions, feel free to comment.

Edit: To enhance your “productivity” you may install a clipboard manager like parcellite (or any other), copy the URI of the desired videos, find the history file (in case of parcellite it resides here: ~/.local/share/parcellite/history; same goes for glipper), clean that file up a bit and use it as your batch.txt – cool, eh?

Edit 2: Be careful with those playlist parameters (&list=xyz); youtube-dl tries to fetch the whole playlist. Playlists with hundreds or thousands of videos aren’t unusual, so better limit the number of items to be fetched:

youtube-dl yourURI --playlist-end NUMBER 

Also, when messing around with playlists make sure to set the -i parameter. Youtube-dl will ignore errors like “Sorry, not available in your country”.