Flickrから検索した語のサムネイルを返すクラス。

随分昔に作った、Flickrから検索した語のサムネイルURLを返すクラス。
機能はそれだけ。

/* 
 FlickerReader class
 Reads images URL of your keyword from www.flicker.com
 This class require proHTML library. Visit "http://www.texone.org/prohtml/"
 

 ex. 
 myFlickerReader = new FlickerReader("oneKeyword");
 myFlickerReader.getURL(); // return URL String.
 */


public class FlickerReader {
  import prohtml.HtmlImageFinder; // require prohtml!!!!!!!!

  HtmlImageFinder imgFinder;
  private int page, pageImgNum, index;
  private String keyword;

  FlickerReader(String keyword) {
    this.keyword = keyword;
    serchNext();
  }
  FlickerReader(String word1, String word2) {
    this.keyword = word1 + "+" + word2;
    serchNext();
  }
  FlickerReader(String word1, String word2, String word3) {
    this.keyword = word1 + "+" + word2 + "+" + word3;
    serchNext();
  }

  public String getURL() {
    String url = " ";
    int noMoreImage = 0;
    do{
      if( index < pageImgNum) {
        url =  imgFinder.getImageLink(index);
        index++;  
      }
      else if(noMoreImage > 100) {
        println("No More Image");
        return null;
      }
      else {
        serchNext();
      }
      noMoreImage++;
    } 
    while(!isImage(url));
    return url;
  }

  private void serchNext() {
    index = 0;
    page++;
    String URL;
    if(page <= 1) {
      URL = "http://www.flickr.com/search/?q="+keyword+"&m=tags";
    } 
    else {
      URL = "http://www.flickr.com/search/?q="+keyword+"&m=tags&page="+page;
    }
    imgFinder = new HtmlImageFinder(URL);
    pageImgNum = imgFinder.getNumbOfImages();
  }


  private boolean isImage(String url) {
    String[] jpg = match(url, "_m.jpg");
    if(jpg != null ) {
      return true;
    } 
    else {
      return false;
    }
  }


}


anime - image search engine from Koki IBUKURO on Vimeo.
これはこのクラス使ってる。