private static GEvent newGEvent(Event event, GCalendar calendar) {
    DateTime start = event.getStart().getDateTime();
    DateTime end = event.getEnd().getDateTime();
    if (start == null) {
      // All-day events don't have start times, so just use
      // the start date.
      start = event.getStart().getDate();
    }
    if (end == null) {
      end = event.getEnd().getDate();
    }
    Calendar startEvent = new GregorianCalendar();
    Calendar endEvent = new GregorianCalendar();
    startEvent.setTime(new Date(start.getValue()));
    endEvent.setTime(new Date(end.getValue()));

    //        SimpleDateFormat format1 = new SimpleDateFormat("yyyy-MM-dd H:m:s");
    //        Log.d("gevent", "start = " + format1.format(startEvent.getTime()) + ", end = " +
    // format1.format(endEvent.getTime()));

    GEvent nEvent = new GEvent(event.getSummary(), startEvent, endEvent);
    nEvent.SetBackgroundColor(calendar.backgroundColor);
    nEvent.SetForegroundColor(calendar.foregroundColor);

    return nEvent;
  }
  public String getTimeDescription() {
    EventDateTime startDT = event.getStart();
    EventDateTime endDT = event.getEnd();
    // this field is populated if event has time
    if (startDT.getDateTime() != null) {
      return String.format(
          "Start: %s End: %s",
          formatDateTime(startDT.getDateTime()), formatDateTime(endDT.getDateTime()));
    }
    DateTime startDate = startDT.getDate();
    DateTime endDate = endDT.getDate();
    // special case for 1 full day event - just show the one date instead of start end
    final long oneDayTime = 1000 * 60 * 60 * 24;
    if (endDate.getValue() - startDate.getValue() == oneDayTime)
      return String.format("Date: %s", startDate);

    return String.format("Start: %s End: %s", startDate, endDate);
  }
 private boolean less(Date date, DateTime dateTime) {
   return date.getTime() < dateTime.getValue();
 }
  @SuppressWarnings("deprecation")
  @Override
  public Boolean crawl(RssEntityBean site) throws CrawlerException {
    log.info("start YouTube crawl channel id = " + site.url);
    Boolean updated = false;
    YouTube youtube =
        new YouTube.Builder(
                HTTP_TRANSPORT,
                JSON_FACTORY,
                new HttpRequestInitializer() {
                  public void initialize(HttpRequest request) throws IOException {}
                })
            .setApplicationName("youtube-cmdline-search-sample")
            .build();

    try {
      YouTube.Search.List search = youtube.search().list("id,snippet");
      String apiKey = Conf.getValue("youtube.appkey");
      search.setKey(apiKey);
      search.setType("video");
      search.setOrder("date");
      search.setMaxResults(maxResult);
      search.setChannelId(site.url);

      SearchListResponse searchResponse = search.execute();
      List<SearchResult> searchResultList = searchResponse.getItems();
      log.info("search response video count = " + searchResultList.size());
      for (SearchResult result : searchResultList) {

        SearchResultSnippet snippet = result.getSnippet();
        DateTime publishDate = snippet.getPublishedAt();
        DateTime lastCrawlDate = null;
        if (site.lastCrawl != null) {
          lastCrawlDate = new DateTime(site.lastCrawl);
        }
        if ((lastCrawlDate == null) || (publishDate.getValue() > lastCrawlDate.getValue())) {
          YouTube.Videos.List videolist = youtube.videos().list("id,snippet");
          videolist.setId(result.getId().getVideoId());
          videolist.setKey(apiKey);
          VideoListResponse videoListResponse = videolist.execute();
          List<Video> videos = videoListResponse.getItems();
          if (videos.size() != 1) {
            log.warn("video not found : " + videolist.getId());
            continue;
          }
          Video video = videos.get(0);

          ArticleEntityBean article = new ArticleEntityBean();
          article.link = video.getId();
          article.title = snippet.getTitle();
          article.description = snippet.getDescription();
          article.imageUrl = snippet.getThumbnails().getDefault().getUrl();
          article.url = site.url;
          article.createdAt = snippet.getPublishedAt();
          String fixHour = Conf.getValue("fix_time");
          Date now = new Date();
          Date fixDate =
              new Date(now.getYear(), now.getMonth(), now.getDate(), Integer.parseInt(fixHour), 0);
          if (now.getTime() > fixDate.getTime()) {
            article.publishedAt = tomorrow;
          } else {
            article.publishedAt = today;
          }
          article.site = site.site;
          article.type = site.type;
          article.tags = site.defaultTag;
          log.info("save article video id = " + article.link + " / video title = " + article.title);
          article.save();
          updated = true;
        }
      }
    } catch (IOException e) {
      log.warn("youtube api error : " + e.getMessage());
      throw new CrawlerException(e);
    }
    log.info("end YouTube crawl");
    return updated;
  }
 private static String formatDateTime(DateTime googleDateTime) {
   return formatDateTime.format(new Date(googleDateTime.getValue()));
 }