本文整理汇总了Java中com.flickr4java.flickr.photos.PhotoList.getPages方法的典型用法代码示例。如果您正苦于以下问题:Java PhotoList.getPages方法的具体用法?Java PhotoList.getPages怎么用?Java PhotoList.getPages使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.flickr4java.flickr.photos.PhotoList
的用法示例。
在下文中一共展示了PhotoList.getPages方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: run
import com.flickr4java.flickr.photos.PhotoList; //导入方法依赖的package包/类
@Override
public void run() {
this.statusLabel.setText("Initializing download process...");
progressBar.setValue(0);
File directory = this.getBackupDirectory();
if (!directory.mkdirs()) {
}
PeopleInterface peopleInt = flickr.getPeopleInterface();
PhotosInterface photoInt = flickr.getPhotosInterface();
int pages = 1;
int page = 1;
int total = 0;
int current = 0;
int error = 0;
Set<String> options = new HashSet<>();
options.add("original_format");
Integer size = Size.ORIGINAL;
try {
do {
RequestContext.getRequestContext().setAuth(this.getAuth());
PhotoList<Photo> list = peopleInt.getPhotos("me", null, null, null, null, null, null, null, options, 500, page);
if (page == 1) {
pages = list.getPages();
total = list.getTotal();
progressBar.setMinimum(0);
progressBar.setMaximum(total);
progressBar.setValue(0);
}
Iterator<Photo> it = list.iterator();
while (it.hasNext() && isRunning) {
current++;
Photo p = it.next();
this.statusLabel.setText("Photo " + current + " of " + total + ": Downloading");
try {
File newFile = new File(directory, this.generateFilename(p, size));
if (!newFile.exists()) {
BufferedInputStream bis = new BufferedInputStream(photoInt.getImageAsStream(p, size));
FileOutputStream fos = new FileOutputStream(newFile);
int read;
byte[] buffer = new byte[100 * 1024];
while ((read = bis.read(buffer)) != -1) {
fos.write(buffer, 0, read);
}
fos.flush();
fos.close();
bis.close();
}
} catch (Exception e) {
error++;
}
progressBar.setValue(current);
}
page++;
} while (page <= pages && isRunning);
statusLabel.setText(isRunning ? "Download of " + total + " photos finished. " + (error == 0 ? "No" : error) + " errors occured!" : "Stopped downloading process. You can resume it at any time.");
} catch (FlickrException ex) {
statusLabel.setText(ex.getMessage());
}
isRunning = false;
updateComponents();
}
示例2: retrieveAccountFeed
import com.flickr4java.flickr.photos.PhotoList; //导入方法依赖的package包/类
@Override
public Response retrieveAccountFeed(AccountFeed feed, Integer maxRequests) {
Response response = new Response();
List<Post> items = new ArrayList<Post>();
Date dateToRetrieve = feed.getSinceDate();
String label = feed.getLabel();
int page=1, pages=1; //pagination
int numberOfRequests = 0;
//Here we search the user by the userId given (NSID) -
// however we can get NSID via flickrAPI given user's username
String userID = feed.getId();
if(userID == null) {
logger.info("#Flickr : No source feed");
return response;
}
PhotosInterface photosInteface = flickr.getPhotosInterface();
SearchParameters params = new SearchParameters();
params.setUserId(userID);
params.setMinUploadDate(dateToRetrieve);
Set<String> extras = new HashSet<String>(Extras.ALL_EXTRAS);
extras.remove(Extras.MACHINE_TAGS);
params.setExtras(extras);
while(page<=pages && numberOfRequests<=maxRequests) {
PhotoList<Photo> photos;
try {
numberOfRequests++;
photos = photosInteface.search(params , PER_PAGE, page++);
} catch (Exception e) {
break;
}
pages = photos.getPages();
if(photos.isEmpty()) {
break;
}
for(Photo photo : photos) {
String userid = photo.getOwner().getId();
UserAccount streamUser = userMap.get(userid);
if(streamUser == null) {
streamUser = getStreamUser(userid);
userMap.put(userid, streamUser);
}
FlickrPost flickrItem = new FlickrPost(photo);
flickrItem.setLabel(label);
items.add(flickrItem);
}
}
response.setPosts(items);
response.setRequests(numberOfRequests);
return response;
}
示例3: retrieveUserFeeds
import com.flickr4java.flickr.photos.PhotoList; //导入方法依赖的package包/类
@Override
public List<Item> retrieveUserFeeds(SourceFeed feed) {
List<Item> items = new ArrayList<Item>();
long currRunningTime = System.currentTimeMillis();
Date dateToRetrieve = feed.getDateToRetrieve();
String label = feed.getLabel();
int page=1, pages=1; //pagination
int numberOfRequests = 0;
int numberOfResults = 0;
//Here we search the user by the userId given (NSID) -
// however we can get NSID via flickrAPI given user's username
Source source = feed.getSource();
String userID = source.getId();
if(userID == null) {
logger.info("#Flickr : No source feed");
return items;
}
PhotosInterface photosInteface = flickr.getPhotosInterface();
SearchParameters params = new SearchParameters();
params.setUserId(userID);
params.setMinUploadDate(dateToRetrieve);
Set<String> extras = new HashSet<String>(Extras.ALL_EXTRAS);
extras.remove(Extras.MACHINE_TAGS);
params.setExtras(extras);
while(page<=pages && numberOfRequests<=maxRequests && numberOfResults<=maxResults &&
(System.currentTimeMillis()-currRunningTime)<maxRunningTime) {
PhotoList<Photo> photos;
try {
numberOfRequests++;
photos = photosInteface.search(params , PER_PAGE, page++);
} catch (Exception e) {
break;
}
pages = photos.getPages();
numberOfResults += photos.size();
if(photos.isEmpty()) {
break;
}
for(Photo photo : photos) {
String userid = photo.getOwner().getId();
StreamUser streamUser = userMap.get(userid);
if(streamUser == null) {
streamUser = getStreamUser(userid);
userMap.put(userid, streamUser);
}
FlickrItem flickrItem = new FlickrItem(photo, streamUser);
flickrItem.setList(label);
items.add(flickrItem);
}
}
//logger.info("#Flickr : Done retrieving for this session");
// logger.info("#Flickr : Handler fetched " + items.size() + " photos from " + userID +
// " [ " + lastItemDate + " - " + new Date(System.currentTimeMillis()) + " ]");
// The next request will retrieve only items of the last day
dateToRetrieve = new Date(System.currentTimeMillis() - (24*3600*1000));
feed.setDateToRetrieve(dateToRetrieve);
return items;
}
示例4: retrieveLocationFeeds
import com.flickr4java.flickr.photos.PhotoList; //导入方法依赖的package包/类
@Override
public List<Item> retrieveLocationFeeds(LocationFeed feed){
List<Item> items = new ArrayList<Item>();
long currRunningTime = System.currentTimeMillis();
Date dateToRetrieve = feed.getDateToRetrieve();
String label = feed.getLabel();
Double[][] bbox = feed.getLocation().getbbox();
if(bbox == null || bbox.length==0)
return items;
int page=1, pages=1;
int numberOfRequests = 0;
int numberOfResults = 0;
PhotosInterface photosInteface = flickr.getPhotosInterface();
SearchParameters params = new SearchParameters();
params.setBBox(bbox[0][0].toString(), bbox[0][1].toString(), bbox[1][0].toString(), bbox[1][1].toString());
params.setMinUploadDate(dateToRetrieve);
Set<String> extras = new HashSet<String>(Extras.ALL_EXTRAS);
extras.remove(Extras.MACHINE_TAGS);
params.setExtras(extras);
while(page<=pages && numberOfRequests<=maxRequests && numberOfResults<=maxResults &&
(System.currentTimeMillis()-currRunningTime)<maxRunningTime) {
PhotoList<Photo> photos;
try {
photos = photosInteface.search(params , PER_PAGE, page++);
} catch (FlickrException e) {
break;
}
pages = photos.getPages();
numberOfResults += photos.size();
if(photos.isEmpty()) {
break;
}
for(Photo photo : photos) {
String userid = photo.getOwner().getId();
StreamUser streamUser = userMap.get(userid);
if(streamUser == null) {
streamUser = getStreamUser(userid);
userMap.put(userid, streamUser);
}
FlickrItem flickrItem = new FlickrItem(photo, streamUser);
flickrItem.setList(label);
items.add(flickrItem);
}
}
logger.info("#Flickr : Handler fetched " + items.size() + " photos "+
" [ " + dateToRetrieve + " - " + new Date(System.currentTimeMillis()) + " ]");
return items;
}