public static List getLatestFeed() throws Exception { YouTubeService service = new YouTubeService("MangaWire"); YouTubeQuery query = new YouTubeQuery(new URL("http://gdata.youtube.com/feeds/api/videos")); query.setAuthor("Ulquiorra43"); query.setOrderBy(OrderBy.PUBLISHED); query.setSafeSearch(SafeSearch.STRICT); VideoFeed feed = service.query(query, VideoFeed.class); System.out.println("Number of entries: " + feed.getEntries().size()); LinkedList<VideoEntry> videoList = new LinkedList<VideoEntry>(); if (feed.getEntries().size() < MAX_RESULTS) { for (int i = 0; i < feed.getEntries().size(); i++) { if (feed.getEntries().get(i).getMediaGroup().getYouTubeContents().isEmpty()) { // DO NOTHING } else { videoList.add(feed.getEntries().get(i)); } } } else { for (int i = 0; i < MAX_RESULTS; i++) { if (feed.getEntries().get(i).getMediaGroup().getYouTubeContents().isEmpty()) { // DO NOTHING } else { videoList.add(feed.getEntries().get(i)); } } } return videoList; }
public String SearchVideos(String keyword) { YouTubeService myService = new YouTubeService("gdataSample-YouTube-1"); // check if the keyword is in the local cache and print appropriate message if (nodeCache.containsKey(keyword)) { System.err.print("Query for " + keyword + " resulted in a cache hit"); // return the RESULT message containing the cached data return nodeCache.get(keyword); } else { System.err.print("Query for " + keyword + " resulted in a cache miss"); try { YouTubeQuery query = new YouTubeQuery(new URL("http://gdata.youtube.com/feeds/api/videos")); // order the results by the number of views query.setOrderBy(YouTubeQuery.OrderBy.VIEW_COUNT); // include restricted content in the search results query.setSafeSearch(YouTubeQuery.SafeSearch.NONE); // search for puppies and include restricted content in the search results query.setFullTextQuery(keyword); VideoFeed videoFeed = myService.query(query, VideoFeed.class); String Xml = FeedToXml(videoFeed); // Enter this into the local cache nodeCache.put(keyword, Xml); // System.out.println(Xml); // printVideoFeed(videoFeed); return Xml; } catch (Exception e) { } } return null; }
public void run() { try { videoFeed = service.query(query, VideoFeed.class); videoEntries = (LinkedList) videoFeed.getEntries(); setChanged(); notifyObservers(); } catch (IOException e) { e.printStackTrace(); return; } catch (ServiceException e) { e.printStackTrace(); return; } }
public static void main(String[] args) { YouTubeService myService = new YouTubeService("gdataSample-YouTube-1"); try { YouTubeQuery query = new YouTubeQuery(new URL("http://gdata.youtube.com/feeds/api/videos")); // order the results by the number of views query.setOrderBy(YouTubeQuery.OrderBy.VIEW_COUNT); // include restricted content in the search results query.setSafeSearch(YouTubeQuery.SafeSearch.NONE); // a category filter holds a collection of categories to limit the search Query.CategoryFilter categoryFilter = new Query.CategoryFilter(); // search for puppies and include restricted content in the search results query.setFullTextQuery("coldplay"); VideoFeed videoFeed = myService.query(query, VideoFeed.class); String Xml = FeedToXml(videoFeed); System.out.println(Xml); // printVideoFeed(videoFeed); } catch (Exception e) { } }