Download picasa web albums photos automatically. This application requires mpod mother board. See also http://mbed.org/users/geodenx/notebook/mpod/
Dependencies: BlinkLed HTTPClient EthernetInterface FatFileSystemCpp MSCFileSystem mbed-rtos mbed
Download picasa web albums photos automatically.
This application requires mpod mother board.
Picasaウェブアルバムから、自動的に写真をダウンロードして、ディジタルフォトフレームに表示します。
動作させるには mpod マザーボード が必要です。
プログラムの中で、ご自分のアルバムのRSSファイルへのURLを指定してからご利用下さい。
Revision 2:531722036c0a, committed 2012-08-24
- Comitter:
- togayan
- Date:
- Fri Aug 24 13:07:06 2012 +0000
- Parent:
- 1:91f662b9d56f
- Child:
- 3:ffbb2b22099a
- Commit message:
- Only when the album is updated, photos are downloaded.
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Thu Aug 23 14:10:58 2012 +0000
+++ b/main.cpp Fri Aug 24 13:07:06 2012 +0000
@@ -11,6 +11,8 @@
int GetFile(const char *path, const char *url);
int addNewLine(const char* dstPath, const char* srcPath);
int summarizeRss(const char* dstPath, const char* srcPath);
+int removePhotos();
+const char* getExtensionFromUrl(const char* url);
EthernetInterface eth;
HTTPClient http;
@@ -24,7 +26,6 @@
/***** Please specify "albumRssUrl" *****/
const char* albumRssUrl = "http://picasaweb.google.com/data/feed/base/user/*****/albumid/*****?alt=rss&kind=photo&authkey=*****&hl=ja";
-
const char* albumRssPath = "/usb/album.xml";
const char* tempPath = "/usb/temp.xml";
const char* summaryPath = "/usb/summary.xml";
@@ -93,27 +94,41 @@
strcpy(lastBuildDateCurrent, lastBuildDateCurrentElement->GetText());
printf("\nlastBuildDate (current) : %s\n", lastBuildDateCurrent);
-
- char photoUrl[256] = {0};
- char photoPath[32] = {0};
- int photoNo = 1;
- XMLElement* itemElement = docCurrent.FirstChildElement("rss")->FirstChildElement("channel")->FirstChildElement("item");
- if(NULL == itemElement)
+ if( strcmp(lastBuildDateOriginal, lastBuildDateCurrent) != 0 )
{
- fsusb30s = 1; // HSD2
- error("No \"enclosure\" element in current RSS.\n");
- }
- strcpy(photoUrl, itemElement->FirstChildElement("enclosure")->Attribute("url"));
- sprintf(photoPath, "/usb/DCIM/%08d.jpg", photoNo);
- GetFile(photoPath, photoUrl);
- ++photoNo;
-
- while( (itemElement = itemElement->NextSiblingElement( "item" ) ) != NULL )
- {
+ printf("lastBuildDate (original) != lastBuildDate (current)\n");
+ if(removePhotos() < 0)
+ {
+ fsusb30s = 1; // HSD2
+ error("No \"DCIM\" folder in MSD.\n");
+ }
+
+ char photoUrl[256] = {0};
+ char photoPath[32] = {0};
+ int photoNo = 1;
+ XMLElement* itemElement = docCurrent.FirstChildElement("rss")->FirstChildElement("channel")->FirstChildElement("item");
+ if(NULL == itemElement)
+ {
+ fsusb30s = 1; // HSD2
+ error("No \"enclosure\" element in current RSS.\n");
+ }
strcpy(photoUrl, itemElement->FirstChildElement("enclosure")->Attribute("url"));
- sprintf(photoPath, "/usb/DCIM/%08d.jpg", photoNo);
+ const char* extension = getExtensionFromUrl(photoUrl);
+ sprintf(photoPath, "/usb/DCIM/%08d.%s", photoNo, extension);
GetFile(photoPath, photoUrl);
++photoNo;
+
+ while( (itemElement = itemElement->NextSiblingElement( "item" ) ) != NULL )
+ {
+ strcpy(photoUrl, itemElement->FirstChildElement("enclosure")->Attribute("url"));
+ sprintf(photoPath, "/usb/DCIM/%08d.jpg", photoNo);
+ GetFile(photoPath, photoUrl);
+ ++photoNo;
+ }
+ }
+ else
+ {
+ printf("lastBuildDate (original) == lastBuildDate (current)\n");
}
// Wait for the completion of writing to USB Mass Storage Device.
@@ -235,3 +250,46 @@
return 0;
}
+
+int removePhotos()
+{
+ if(DirHandle* dir = opendir("/usb/DCIM"))
+ {
+ int ret = 0;
+ while(struct dirent* ent = dir->readdir())
+ {
+ char filename[32] = {0};
+ sprintf(filename, "/usb/DCIM/%s", ent->d_name);
+ printf("remove %s\n", filename);
+ remove(filename);
+ ++ret;
+ }
+ return ret;
+ }
+ else
+ {
+ return -1;
+ }
+}
+
+const char* getExtensionFromUrl(const char* url)
+{
+ const char* tail = url;
+ while('\0' != *tail)
+ {
+ ++tail;
+ }
+
+ for(const char* p = tail; p >= url; --p)
+ {
+ if ('/' == *p)
+ {
+ return tail;
+ }
+ if ( '.' == *p )
+ {
+ return p+1;
+ }
+ }
+ return tail;
+}
Satoshi Togawa