Perl Script to upload Gallery2 albums to SmugMug

madeingermanymadeingermany Registered Users Posts: 22 Big grins
Hi,

Based on on Jeremy Mooney's FileUpload for SmugMug I created a Perl script that takes a Gallery album, looks up the tilte from Gallery's mysql database and uploads the images into a new album on SmugMug.

You can find the script and documentation at
http://marcofrom.com/smug-uploadalbum/

Let me know, what you think and pardon my code :dunno

Thank you!
Marco


PS: Alternative Hacks dealing with Gallery are Gallery Album to SmugMug and Migratr but both didn't cut it for me ;)

Comments

  • battsbatts Registered Users Posts: 94 Big grins
    edited March 6, 2008
    script help
    Hi Marco,
    I'm in the same struggles you had, looking for other options to migrate from gallery2 and well the other options so far have given me no luck in compeletly working.

    I'm running gallery2, and older 2.1X and I feel that is giving me problems with some of the other migration programs. I don't have the option to update, because as many gallery2 users might know that always opens up another can of worms, or so has been my luck.

    cutting to the quesiton here

    I'm running g2 usingpostgres, I'm probably dangerous enough to get in trouble with things, and feel your script might provide the best options . I'm having a problem running the script. The output follows

    $ ./uploadalbum --directory /home/test/gallery/g2data/albums/test --database DBI:Pg:test_gallery:localhost --dbuser test --dbpass test --email test@t.net --pass test

    ....logged in successfully.
    DBI connect('test_gallery:localhost','test',...) failed: missing "=" after "test_gallery:localhost" in connection info string
    at ./uploadalbum line 104
    DB error: missing "=" after "test_gallery:localhost" in connection info string


    Any help would be great

    thank you..

    Hi,

    Based on on Jeremy Mooney's FileUpload for SmugMug I created a Perl script that takes a Gallery album, looks up the tilte from Gallery's mysql database and uploads the images into a new album on SmugMug.

    You can find the script and documentation at
    http://marcofrom.com/smug-uploadalbum/

    Let me know, what you think and pardon my code ne_nau.gif

    Thank you!
    Marco


    PS: Alternative Hacks dealing with Gallery are Gallery Album to SmugMug and Migratr but both didn't cut it for me ;)
  • ubahmapkubahmapk Registered Users Posts: 2 Beginner grinner
    edited August 7, 2008
    So close...I think
    I'm trying to import my galleries from g2 using this script (thank you, BTW) and it looks like it's *really* close to working :-)
    find /path/to/g2data/albums -type d -exec ./uploadalbum --directory {} \;
    
    produces
    Using path /path/to/g2data/albums
    Using path /path/to/g2data/albums/AlbumName1
    found AlbumName1
    Session a12b3c4d5e6f7a8b9c0d52336c2b5
    smugmug-user-id logged in successfully.
    
    For all of my G2 albums...but none of the albums were actually uploaded...

    ???

    I'm afraid I'm not real sure where to look. Any ideas?

    thanks.
  • madeingermanymadeingermany Registered Users Posts: 22 Big grins
    edited August 8, 2008
    Hi ubahmapk,

    sorry that it is not working for you. It has been a while that I looked at this... because you only need it once ;)

    If you run it for just one album
    ./uploadalbum --directory /path/to/g2data/albums/AlbumName1
    
    Is the Session ID the last thing you see?
    You should get "Using Album $albumname (Gallery2 ID $parent)" after that, otherwise I'm thinking it has to do with the mysql connection.

    Can you double check your mysql settings in the config file?
    On the other hand the script should throw an error, if anything goes wrong.

    Marco
  • ubahmapkubahmapk Registered Users Posts: 2 Beginner grinner
    edited August 8, 2008
    sadness
    I tried running it against one folder and the SessionID was still the last thing I saw.

    So I looked through the script and found where it prints the Session ID and then I started adding print statements after that to see if I could figure out what was going on.

    It looks like the g2_FileSystemIdentity table is empty (I think that was the one - I don't have it in front of me this morning). Which, as far as I can tell, means that my SQL export didn't work correctly :(

    The real bugger is that the original DB is no longer in existence and the only thing I *had* was the SQL export.....
  • Andrew MaimanAndrew Maiman Registered Users Posts: 50 Big grins
    edited September 5, 2008
    Thanks for writing this great script. I'm new to SmugMug and DGrin and am in the process of migrating my photos from my old Gallery2 site to my new SmugMug site. (And I'll eventually upload the thousands of newer pictures that I didn't have on the old site since I didn't want to pay for the disk space for my web server. Unlimited storage on SmugMug sounds like a good deal to me :D). Most of the stuff on my old gallery is from several years ago, I haven't posted any of the (much better) stuff from any of my recent travel since my new camera generates gigabytes of pictures for each trip.

    Anyway, it looks like this script hasn't been updated in a while, and I ran into a few problems with it. Mainly, it doesn't handle the new album keys that were added a while ago, so it doesn't properly parse the album and image IDs. This was causing it to be unable to upload images to an album that had just been created by the script. The URL displayed at the end of the script also cannot be used to view the album, since the key is not appended to the end of the URL.

    I went ahead and fixed the problems, the updated script can be downloaded from here:
    http://www2.maiman.net/smug-uploadalbum/uploadalbum

    While I was at it, I added two new features (to suit my import needs). I added two command line switches, --nofilenamecaptions and --captionsfromdescriptions. The first switch prevents the filename from being used as the caption if there is no caption present in Gallery2. The second switch causes the "description" field on the Gallery2 item to be used instead of the "title" field. (All of my captions were in that field, not in the title).

    I attached a diff to this message showing the code changes.

    I tested out the changes, and they appear to be working correctly, but it's always good if some other people try it out.

    I hope you don't mind that I modified your code, hopefully you'll be able to incorporate these changes into your next version.

    This was a good first exposure to the SmugMug API for me. I think I'll take a crack at writing a Blackberry Uploader to SmugMug next (being able to post geotagged photos from my phone like I can do with Flickr would be a cool feature and it doesn't look like anyone else has tried to write one yet). Plus, I saw that SmugMug has an offer that authors of apps that use the API can be eligible for a free account, so I can kill two birds with one stones (save money and finally learn the Blackberry JDE which I've been meaning to do for a while).
  • rdk8rdk8 Registered Users Posts: 1 Beginner grinner
    edited May 22, 2009
    For postgresql users--can't use "
    Just a quick note for postgresql users--you can't use double quotes " in WHERE clauses, so this script will only work if you change the double quotes to single quotes ' in all of the SELECT queries
  • korethkoreth Registered Users Posts: 3 Beginner grinner
    edited May 28, 2009
    I made another tweak to the script. Now if --captionsfromdescription is specified, it will try to use the description, then the summary, then the title, then the filename (unless --nofilenamecaptions is specified) until it finds something. Also, if --nofilenamecaptions is specified, it now checks for filename titles that got saved to the Gallery2 database and strips them off (previously that option would only avoid creating *new* filename captions but would use existing ones.)

    Updated script:

    http://www.midwinter.com/~koreth/uploadalbum
  • LaephisLaephis Registered Users Posts: 3 Beginner grinner
    edited January 9, 2010
    This script almost works perfectly for me with one major problem: all of my Gallery 2.3 albums are being named with their filename instead of their Title. So for example, /home/user/g2data/albums/album01 is being imported into Smugmug and called "album01" instead of being named "Family Photos" which is its title in Gallery 2.3. Is there anyway to fix this? I've spent some time looking at the script, but I'm no Perl guru. :(
  • madeingermanymadeingermany Registered Users Posts: 22 Big grins
    edited January 11, 2010
    Laephis wrote:
    all of my Gallery 2.3 albums are being named with their filename instead of their Title.

    Hi Erick,

    I haven't looked at this for 2 years ... but looking at the code now, it seems to not support the feature of getting Album name from the Database.
    I don't know why (thinking there must have been a good reason). I'll try to look at it next weekend.

    Thanks,
    Marco
  • TransportImagesTransportImages Registered Users Posts: 1 Beginner grinner
    edited December 31, 2010
    I've just given this script a go, but am running into a slightly different error.
    ./uploadalbum --directory /home/replacedusername/g2data/albums/railways/ukcurrent/nxec
    Using path /home/replacedusername/g2data/albums/railways/ukcurrent/nxec
    found railways/ukcurrent/nxec
    Session f7c3aba848cfacd2bcce7213def59c1f
    transportimages logged in successfully.
    album id = 6935
    album id = 40360
    album id = 48421
    Using Album nxec (Gallery2 ID 48421).
    ERROR creating Album!
    <?xml version="1.0" encoding="utf-8"?>
    <rsp stat="fail">
      <err code="3" msg="invalid session"/>
    </rsp>
    
    Creating Album nxec CategoryID 0
    

    Any ideas? Thanks.

    Also, for anyone looking for a tool to move menalto gallery images to smugmug, Smuganizer at http://code.google.com/p/smuganizer/ does seem to work, albeit (unfortunately) without moving across data from custom fields.

    Keith
  • ZonylZonyl Registered Users Posts: 1 Beginner grinner
    edited May 8, 2011
    I've just given this script a go, but am running into a slightly different error.
    ./uploadalbum --directory /home/replacedusername/g2data/albums/railways/ukcurrent/nxec
    Using path /home/replacedusername/g2data/albums/railways/ukcurrent/nxec
    found railways/ukcurrent/nxec
    Session f7c3aba848cfacd2bcce7213def59c1f
    transportimages logged in successfully.
    album id = 6935
    album id = 40360
    album id = 48421
    Using Album nxec (Gallery2 ID 48421).
    ERROR creating Album!
    <?xml version="1.0" encoding="utf-8"?>
    <rsp stat="fail">
      <err code="3" msg="invalid session"/>
    </rsp>
    
    Creating Album nxec CategoryID 0
    
    Any ideas? Thanks.

    The issue is you dont have a cookie jar and they are shoving some stuff in there upon login:
    Find this section:
    my $ua = LWP::UserAgent->new;
    $ua->agent('MarcosGallery2PerlUploader/0.1');

    add this line beneath:
    $ua->cookie_jar( {} );
  • libovelibove Registered Users Posts: 1 Beginner grinner
    edited August 11, 2015
    Gallery3 support?
    Community efforts like this are great - thanks to all who have worked on this.
    Has anyone updated it to be able to transfer a Gallery3 album (set of albums, website)?
    With Menalto Gallery3 now obsoleted, we all need to transfer, and there don't seem to be any scripts or services to do it :(
    thanks,
Sign In or Register to comment.