Skip to content

Commit

Permalink
picasa_import.js: import zdjęć z Picasy
Browse files Browse the repository at this point in the history
Resolves #10
  • Loading branch information
macbre committed Apr 4, 2015
1 parent 909f872 commit 0cad232
Showing 1 changed file with 61 additions and 0 deletions.
61 changes: 61 additions & 0 deletions picasa_import.js
@@ -0,0 +1,61 @@
#!/usr/bin/env node
/**
* Skrypt importujący wybrane zdjęcie z Google Picasa
*/
var bot = require('nodemw'),
client = new bot('config.js'),
URL = process.argv[2],
DEST = process.argv[3];

if (!URL || !DEST) {
console.log('Podaj link obrazka do importu i nazwę docelową');
console.log(process.argv[1] + ' <URL> <nazwa docelowa>');
process.exit(1);
}

URL = URL.replace('?feat=directlink', '');

client.log('Import: ' + URL);
client.log('Plik: ' + DEST);

client.fetchUrl(URL, function(err, resp) {
if (err) {
console.error(err);
return;
}

// pobierz opis i link do oryginału zdjęcia
matches = resp.match(/{'preload': (.*)},\n/);

if (!matches) {
console.error('JSON info not found!');
return;
}

// parsuj JSON z feed'em
var preload = JSON.parse(matches[1]),
feed = preload.feed;

//client.logData(feed);

var desc = feed.htmlCaption.trim(),
imageUrl = feed.media.thumbnail[0].url;

client.log('Zdjęcie: ' + imageUrl);
client.log('Opis: ' + desc);

// upload
client.logIn(function() {
var params = {
comment: 'Import z Google Picasa',
text: ('{{Picasa|' + URL +'}}\n\n' + desc).trim()
};

client.log('Wrzucam plik <' + imageUrl + '> jako <' + DEST + '>...');

// dodaj zdjęcie
client.uploadByUrl(DEST, imageUrl, params, function(res) {
console.log('Import zakończony');
});
});
});

0 comments on commit 0cad232

Please sign in to comment.