Package com.tubeonfire.entity

Examples of com.tubeonfire.entity.TubesFeed


    } else {
      response.sendRedirect("/home");
    }
    try {
      System.out.println("Keyword to search : " + key);
      TubesFeed result = TubeService.searchByKey(key, currentPage, 1);
      request.setAttribute("url", request.getRequestURL());
      request.setAttribute("listCategory", JavaCacheHandle.getCategory());
      request.setAttribute("listChannel", JavaCacheHandle.getChannels());
      request.setAttribute("result", result);
      request.setAttribute("key", key);
View Full Code Here


        System.out.println("Error path.");
        response.sendRedirect("/home");
      }
      typeChart = URLDecoder.decode(typeChart, "UTF8");
      System.out.println("Chart type : " + typeChart);
      TubesFeed result = null;
      if (typeChart.equalsIgnoreCase("most-viewed")) {
        result = TubeService.getMostView("today", itemPerPage, page);
      } else if (typeChart.equalsIgnoreCase("most-shared")) {
        result = TubeService.getMostShared(itemPerPage, page);
      } else if (typeChart.equalsIgnoreCase("top-rated")) {
        result = TubeService.getTopRate("today", itemPerPage, page);
      } else if (typeChart.equalsIgnoreCase("most-discussed")) {
        result = TubeService.getMostDiscussed("today", itemPerPage, page);
      } else if (typeChart.equalsIgnoreCase("top-favorites")) {
        result = TubeService.getTopFavorites("today", itemPerPage, page);
      }
      if (result != null && result.getListTube().size() > 0) {
        request.setAttribute("url", request.getRequestURL());
        request.setAttribute("listCategory",
            JavaCacheHandle.getCategory());
        request.setAttribute("listChannel",
            JavaCacheHandle.getChannels());
        request.setAttribute("result", result.getListTube());
        request.setAttribute("typeChart", typeChart);
        request.setAttribute("totalResult", result.getTotalResult());
        System.out.println(result.getTotalResult());
        request.setAttribute("currentPage", result.getCurrentPage());
        request.getRequestDispatcher("/tube_charts.jsp").forward(request,
            response);
      } else {
        System.out.println("Null pointer.");
        response.sendRedirect("/home");
View Full Code Here

                                        // change
                                        // service
                                        // name.

  public static TubesFeed searchByKey(String key, int page, int type) {
    TubesFeed result = new TubesFeed();
    List<Tube> listTube = new ArrayList<Tube>();
    System.out.println("Searching...");
    try {
      YouTubeQuery query = new YouTubeQuery(new URL(
          "https://gdata.youtube.com/feeds/api/videos"));
      query.setFullTextQuery(key);
      query.setMaxResults(itemPerPage);
      query.setStartIndex(itemPerPage * page);
      query.setSafeSearch(YouTubeQuery.SafeSearch.NONE);
      VideoFeed videoFeed = service.query(query, VideoFeed.class);
      result.setTotalResult(videoFeed.getTotalResults());
      result.setCurrentPage(page);
      List<Tube> listSave2DB = new ArrayList<Tube>();
      for (VideoEntry videoEntry : videoFeed.getEntries()) {
        Tube tub = new Tube();
        tub.transformHalfVideoEntry(videoEntry);
        tub.setStatus(2);
        tub.setUpdated(Calendar.getInstance().getTime());
        listTube.add(tub);
        if (TubeModel.getByTubeId(tub.getTubeId()) == null) {
          listSave2DB.add(tub);
          System.out.println(tub.getTitle().getValue()
              + " ready to save !");
        }
      }
      if (listSave2DB.size() > 0) {
        TubeModel.addAll(listSave2DB);
        System.out.println("Saved " + listSave2DB.size()
            + " video success !");
      }
      TubeModel.closePM();
    } catch (MalformedURLException e) {
      System.out.println("Error when searching with key : + " + key);
      e.printStackTrace();
    } catch (IOException e) {
      System.out.println("Error when searching with key : + " + key);
      e.printStackTrace();
    } catch (ServiceException e) {
      System.out.println("Error when searching with key : + " + key);
      e.printStackTrace();
    }
    result.setListTube(listTube);
    return result;
  }
View Full Code Here

    }
    return tub;
  }

  public static TubesFeed getMostView(String time, int itemPerPage, int page) {
    TubesFeed result = new TubesFeed();
    List<Tube> listTube = new ArrayList<Tube>();
    List<Tube> listSave2DB = new ArrayList<Tube>();
    int startIndex = 1;
    if (page != 1) {
      startIndex = itemPerPage * page;
    }
    try {
      YouTubeQuery query = new YouTubeQuery(new URL(
          "https://gdata.youtube.com/feeds/api/standardfeeds/most_viewed?time="
              + time + "&start-index=" + startIndex
              + "&max-results=" + itemPerPage
              + "&orderby=viewCount&v=2"));
      VideoFeed videoFeed = service.query(query, VideoFeed.class);
      result.setTotalResult(videoFeed.getTotalResults());
      result.setCurrentPage(page);
      List<VideoEntry> videos = videoFeed.getEntries();
      for (VideoEntry videoEntry : videos) {
        Tube tub = new Tube();
        tub.transformHalfVideoEntry(videoEntry);
        tub.setStatus(2);
        tub.setUpdated(Calendar.getInstance().getTime());
        listTube.add(tub);
        System.out.println(tub.getTubeId());
        if (TubeModel.getByTubeId(tub.getTubeId()) == null) {
          listSave2DB.add(tub);
          System.out.println(tub.getTitle() + " ready to save !");
        }
      }
      if (listSave2DB.size() > 0) {
        TubeModel.addAll(listSave2DB);
        System.out.println("Saved " + listSave2DB.size()
            + " video success !");
      }
      result.setListTube(listTube);
    } catch (MalformedURLException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (IOException e) {
      // TODO Auto-generated catch block
View Full Code Here

    }
    return result;
  }

  public static TubesFeed getMostShared(int itemPerPage, int page) {
    TubesFeed result = new TubesFeed();
    List<Tube> listTube = new ArrayList<Tube>();
    List<Tube> listSave2DB = new ArrayList<Tube>();
    int startIndex = 1;
    try {
      YouTubeQuery query = new YouTubeQuery(new URL(
          "https://gdata.youtube.com/feeds/api/standardfeeds/most_shared?start-index="
              + startIndex + "&max-results=" + itemPerPage
              + "&orderby=viewCount"));
      VideoFeed videoFeed = service.query(query, VideoFeed.class);
      result.setTotalResult(videoFeed.getTotalResults());
      result.setCurrentPage(page);
      List<VideoEntry> videos = videoFeed.getEntries();
      for (VideoEntry videoEntry : videos) {
        Tube tub = new Tube();
        tub.transformHalfVideoEntry(videoEntry);
        tub.setStatus(2);
        tub.setUpdated(Calendar.getInstance().getTime());
        listTube.add(tub);
        System.out.println(tub.getTubeId());
        if (TubeModel.getByTubeId(tub.getTubeId()) == null) {
          listSave2DB.add(tub);
          System.out.println(tub.getTitle() + " ready to save !");
        }
      }
      if (listSave2DB.size() > 0) {
        TubeModel.addAll(listSave2DB);
        System.out.println("Saved " + listSave2DB.size()
            + " video success !");
      }
      result.setListTube(listTube);
    } catch (MalformedURLException e) {
      System.out.println("Malformed exception.");
      e.printStackTrace();
    } catch (IOException e) {
      System.out.println("IO exception.");
View Full Code Here

    }
    return result;
  }

  public static TubesFeed getMostDiscussed(String time, int itemPerPage, int page) {
    TubesFeed result = new TubesFeed();
    List<Tube> listTube = new ArrayList<Tube>();
    List<Tube> listSave2DB = new ArrayList<Tube>();
    int startIndex = 1;
    if (page != 1) {
      startIndex = itemPerPage * page;
    }
    try {
      YouTubeQuery query = new YouTubeQuery(new URL(
          "https://gdata.youtube.com/feeds/api/standardfeeds/most_discussed?time="
              + time + "&start-index=" + startIndex
              + "&max-results=" + itemPerPage
              + "&orderby=viewCount&v=2"));
      VideoFeed videoFeed = service.query(query, VideoFeed.class);
      result.setTotalResult(videoFeed.getTotalResults());
      result.setCurrentPage(page);
      List<VideoEntry> videos = videoFeed.getEntries();
      for (VideoEntry videoEntry : videos) {
        Tube tub = new Tube();
        tub.transformHalfVideoEntry(videoEntry);
        tub.setStatus(2);
        tub.setUpdated(Calendar.getInstance().getTime());
        listTube.add(tub);       
        if (TubeModel.getByTubeId(tub.getTubeId()) == null) {
          listSave2DB.add(tub);
          System.out.println(tub.getTitle() + " ready to save !");
        }
      }
      if (listSave2DB.size() > 0) {
        TubeModel.addAll(listSave2DB);
        System.out.println("Saved " + listSave2DB.size()
            + " video success !");
      }
      result.setListTube(listTube);
    } catch (MalformedURLException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (IOException e) {
      // TODO Auto-generated catch block
View Full Code Here

    }
    return result;
  }

  public static TubesFeed getTopRate(String time, int itemPerPage, int page) {
    TubesFeed result = new TubesFeed();
    List<Tube> listTube = new ArrayList<Tube>();
    List<Tube> listSave2DB = new ArrayList<Tube>();
    int startIndex = 1;
    if (page != 1) {
      startIndex = itemPerPage * page;
    }
    try {
      YouTubeQuery query = new YouTubeQuery(new URL(
          "https://gdata.youtube.com/feeds/api/standardfeeds/top_rated?time="
              + time + "&start-index=" + startIndex
              + "&max-results=" + itemPerPage
              + "&orderby=viewCount&v=2"));
      VideoFeed videoFeed = service.query(query, VideoFeed.class);
      result.setTotalResult(videoFeed.getTotalResults());
      result.setCurrentPage(page);
      List<VideoEntry> videos = videoFeed.getEntries();
      for (VideoEntry videoEntry : videos) {
        Tube tub = new Tube();
        tub.transformHalfVideoEntry(videoEntry);
        tub.setStatus(2);
        tub.setUpdated(Calendar.getInstance().getTime());
        listTube.add(tub);
        System.out.println(tub.getTubeId());
        if (TubeModel.getByTubeId(tub.getTubeId()) == null) {
          listSave2DB.add(tub);
          System.out.println(tub.getTitle() + " ready to save !");
        }
      }
      if (listSave2DB.size() > 0) {
        TubeModel.addAll(listSave2DB);
        System.out.println("Saved " + listSave2DB.size()
            + " video success !");
      }
      result.setListTube(listTube);
    } catch (MalformedURLException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (IOException e) {
      // TODO Auto-generated catch block
View Full Code Here

    }
    return result;
  }

  public static TubesFeed getTopFavorites(String time, int itemPerPage, int page) {
    TubesFeed result = new TubesFeed();
    List<Tube> listTube = new ArrayList<Tube>();
    List<Tube> listSave2DB = new ArrayList<Tube>();
    int startIndex = 1;
    if (page != 1) {
      startIndex = itemPerPage * page;
    }
    try {
      YouTubeQuery query = new YouTubeQuery(new URL(
          "https://gdata.youtube.com/feeds/api/standardfeeds/top_favorites?time="
              + time + "&start-index=" + startIndex
              + "&max-results=" + itemPerPage
              + "&orderby=viewCount&v=2"));
      VideoFeed videoFeed = service.query(query, VideoFeed.class);
      result.setTotalResult(videoFeed.getTotalResults());
      result.setCurrentPage(page);
      List<VideoEntry> videos = videoFeed.getEntries();
      for (VideoEntry videoEntry : videos) {
        Tube tub = new Tube();
        tub.transformHalfVideoEntry(videoEntry);
        tub.setStatus(2);
        tub.setUpdated(Calendar.getInstance().getTime());
        listTube.add(tub);       
        if (TubeModel.getByTubeId(tub.getTubeId()) == null) {
          listSave2DB.add(tub);
          System.out.println(tub.getTitle() + " ready to save !");
        }
      }
      if (listSave2DB.size() > 0) {
        TubeModel.addAll(listSave2DB);
        System.out.println("Saved " + listSave2DB.size()
            + " video success !");
      }
      result.setListTube(listTube);
    } catch (MalformedURLException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (IOException e) {
      // TODO Auto-generated catch block
View Full Code Here

TOP

Related Classes of com.tubeonfire.entity.TubesFeed

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.