Exemplo n.º 1
0
    @Override
    protected Boolean doInBackground(String... mess) {

      try {
        Document page = Jsoup.connect("http://messmenu.snu.in/messMenu.php").get();

        Element menu;
        if (mess[0].equals("dh1")) menu = page.getElementsByTag("tbody").get(0);
        else menu = page.getElementsByTag("tbody").get(1);

        Elements breakfast_items = menu.getElementsByTag("td").get(1).children();
        Elements lunch_items = menu.getElementsByTag("td").get(2).children();
        Elements dinner_items = menu.getElementsByTag("td").get(3).children();

        for (Element item : breakfast_items) breakfast.add(item.text());
        for (Element item : lunch_items) lunch.add(item.text());
        for (Element item : dinner_items) dinner.add(item.text());

        return true;

      } catch (IOException | IndexOutOfBoundsException e) {
        e.printStackTrace();
      }

      return false;
    }
Exemplo n.º 2
0
 public static ArrayList<EntryModel> getEpisodeLinks(final String url) {
   final ArrayList<EntryModel> result = new ArrayList<>();
   Thread thread =
       new Thread(
           () -> {
             try {
               Document document = Jsoup.connect(url).get();
               Elements titleElements =
                   document.getElementsByClass("video_option").size() != 0
                       ? document.getElementsByClass("video_option").first().getElementsByTag("a")
                       : document
                           .getElementsByClass("video_option_act")
                           .first()
                           .getElementsByTag("a");
               Elements videoElements = document.getElementsByClass("player_conte");
               for (int i = 0; i < videoElements.size(); i++) {
                 String title = titleElements.get(i).text();
                 String linkUrl = videoElements.get(i).attr("src");
                 if (!linkUrl.startsWith("http")) {
                   Elements flashElements = videoElements.get(i).select("param[name=flashvars]");
                   linkUrl = flashElements.attr("value").split("[&;]")[0].split("=")[1];
                   if (!linkUrl.startsWith("http")) {
                     flashElements = videoElements.get(i).select("[flashvars]");
                     linkUrl = flashElements.attr("flashvars").split("[&;]")[0].split("=")[1];
                   }
                 }
                 result.add(new EntryModel(Constants.TYPE_LINK, title, linkUrl));
               }
             } catch (IOException | IndexOutOfBoundsException e) {
               e.printStackTrace();
             }
           });
   thread.start();
   try {
     thread.join();
     return result;
   } catch (InterruptedException | NullPointerException e) {
     e.printStackTrace();
     return null;
   }
 }