Write images based on post name

Rather than writing out the raw image files, with no easy way to look up what
post the image came from, use the post id and title as the image filename.

This makes it much easier to construct a URL for any given cabin.

Also handles already downloaded image files and renames them accordingly.
no functional changes to this block of code, i just moved it up to get out of my way of other changes