View all essays

Koken export original images

Koken organizes photos in Albums (and Sets), The original uploaded photos are stored in an obscure folder structure like:

/YourPathToKoken/koken/storage/originals/g2/5n/originalfilename.jpg

Every uploaded photo has two unique subfolders in the koken storage. Impossible to see what goes where from Finder or FileExplorer. The PHP script below reads the Koken database and copies the original files to a new location with a separate folder for each album.

It's one of my first scripts in PHP and very, very brute force :)
It runs on OSX and should run on Linux with minor adjustments (osx command cp -n is unsupported on other unix systems). Windows users must edit the mkdir and cp parts.

I think something like this should be part of the Koken GUI. A set of folders and files in the structure of Koken is needed for offline viewing on digital image frames and photoviewers on tablets, smartphones, TV's etc. etc. In my case Plex. Or just as a backup.

I need to update the code below. visibility instead of listed should be used in the SQL statements. See my other blog post.


/**
Koken organizes photos in albums
The original uploaded photos are stored in an obscure folder structure like
/YourPathToKoken/koken/storage/originals/g2/5n/originalfilename.jpg
This php script reads the koken database and copies the original files to a new
location where every album is a new folder.
run from console:
php thisscript.php
**/
query($sql); 
foreach($results as $row) 
{ 
   $makedir = sprintf('mkdir -p \'/YourPath/%s\'',$row['title']);
   system($makedir$retval);  
} 
//end create folders

//copy photos in public

$sql = "SELECT * FROM koken_albums WHERE visibility = 0"$resultsalbum = $pdo->query($sql); 
foreach($resultsalbum as $row) 
{ 
     $albumtitle = $row['title'];
     $albumid = $row['id'];  
     $sqlcontent = sprintf('SELECT * FROM koken_join_albums_content WHERE album_id = %s'$albumid); 
     $resultscontent = $pdo->query($sqlcontent); 
     foreach($resultscontent as $rowcontent)
     {
          $photoid = $rowcontent['content_id'];
          $sqlphoto = sprintf('SELECT * FROM koken_content WHERE id = %s'$photoid); 
          $resultsphoto = $pdo->query($sqlphoto); 
          foreach($resultsphoto as $rowphoto) 
                 { 
                 $photovisibility = $rowphoto['visibility'];
                  //If you set visibility to unlisten in a public album it won't show in the site and it won't copy
                  if($photovisibility == "0") 
                    {
                    //EDIT YourPathToKoken and YourPath
                    $photo_in_storage = sprintf('/YourPathToKoken/koken/storage/originals/%s/%s/%s',
                        substr($rowphoto['internal_id'],0,2),substr($rowphoto['internal_id'],2,2),$rowphoto['filename']);
                   $photo_in_plex = sprintf('/YourPath/%s/%s',$albumtitle,$rowphoto['filename']);
                   $copyphoto = sprintf('cp -n \'%s\' \'%s\'',$photo_in_storage,$photo_in_plex);
                   echo $copyphoto;
                   echo "\n";
                  system($copyphoto$retval);
                  } 
                 
               }
     }
} 
//copy favorite photos in public
//copy all photos marked as favorite in koken
         
$sqlphoto = sprintf('SELECT * FROM koken_content WHERE favorite = 1'); 
$resultsphoto = $pdo->query($sqlphoto); 
foreach($resultsphoto as $rowphoto) 
      { 
      //EDIT YourPathToKoken and YourPath
    $photo_in_storage = sprintf('/YourPathToKoken/koken/storage/originals/%s/%s/%s',
        substr($rowphoto['internal_id'],0,2),substr($rowphoto['internal_id'],2,2),$rowphoto['filename']);
    $photo_in_plex = sprintf('/YourPath/%s',$rowphoto['filename']);
    $copyphoto = sprintf('cp -n \'%s\' \'%s\'',$photo_in_storage,$photo_in_plex);
    echo $copyphoto;
    echo "\n";
    system($copyphoto$retval);
    }
?>
  • Koken database repair

    Albums disappearing, albums don't sort properly, albums jumping from one Set to another: Your koken database is confused. Easy to fix if you have a MySQL editor like phpMyAdmin or Navicat. Open the table koken_albums and sort the table on the following…

    Control Max2Play with Logitech Smart Control

    Max2Play (www. max2play. com) on Raspberry Pi 3 is a great alternative for Logitech Squeezeboxes. I needed a Jivelite setup for my HD screen to control my Logitech Touch as a couch potato without using binoculars. I had set my mind on controlling…