Example usage for twitter4j MediaEntity getMediaURLHttps

List of usage examples for twitter4j MediaEntity getMediaURLHttps

Introduction

In this page you can find the example usage for twitter4j MediaEntity getMediaURLHttps.

Prototype

String getMediaURLHttps();

Source Link

Document

Returns the media secure URL.

Usage

From source file:com.alainesp.fan.sanderson.SummaryFragment.java

License:Open Source License

private String getTweetText(twitter4j.Status tweet) {
    SpannableStringBuilder text = new SpannableStringBuilder(tweet.getText());

    URLEntity[] urls = tweet.getURLEntities();
    MediaEntity[] medias = tweet.getMediaEntities();

    for (MediaEntity media : medias)
        if ("photo".equals(media.getType())) {
            InternetHelper.getRemoteFile(media.getMediaURLHttps());
            text.setSpan(new ImageSpan(null, media.getMediaURLHttps()), media.getStart(), media.getEnd(),
                    Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        }/*  ww w  .j  ava  2s. c om*/

    for (URLEntity url : urls) {
        text.setSpan(new URLSpan(url.getURL()), url.getStart(), url.getEnd(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
        text.replace(url.getStart(), url.getEnd(), url.getExpandedURL());
    }

    return Html.toHtml(text);
}

From source file:com.fsatir.twitter.TwitterManagedBean.java

public List<Media> trendImageList(Twitter twitter, String trendName) {

    Query query = new Query(trendName + " AND filter:images");
    query.setCount(1);/*from   w  w w.j  a  v a  2s. c  o  m*/
    QueryResult result;
    try {
        do {
            result = twitter.search(query);

            List<twitter4j.Status> tweets = result.getTweets();
            int counter = 0;
            for (twitter4j.Status status : tweets) {

                Media myMedia = new Media();
                int control = 0;
                for (MediaEntity me : status.getMediaEntities()) {
                    //Tek grsel almay kesinletirmek iin kontrol.
                    //leride modeldeki trendImgURL diziye dntrlerek kontrol kaldrlabilir.
                    if (control < 1)
                        myMedia.setTrendImgURL(me.getMediaURLHttps());
                    control++;
                }
                // URL null deilse, grsel ve bigileri list'e eklenir.
                if (myMedia.getTrendImgURL() != null) {
                    myMedia.setTweetID(status.getId());
                    myMedia.setFavorite_count(status.getFavoriteCount());
                    myMedia.setRetweet_count(status.getRetweetCount());
                    //myMedia.setTrendImgURL(status.getMediaEntities()[0].getMediaURLHttps());
                    myMedia.setTrendName(trendName);
                    myMedia.setName(Long.toString(status.getId()));
                    myMedia.setType(status.getMediaEntities()[0].getType());

                    myMediaList.add(counter++, myMedia);
                }
            }
        } while ((query = result.nextQuery()) != null && result.getRateLimitStatus().getRemaining() > 0);

    } catch (TwitterException e) {
        e.printStackTrace();
    }

    myMediaListFiltered = filterList(myMediaList);

    return myMediaListFiltered;

}

From source file:com.github.jcustenborder.kafka.connect.twitter.StatusConverter.java

License:Apache License

static Struct convertMediaEntity(MediaEntity mediaEntity) {
    return new Struct(SCHEMA_MEDIA_ENTITY).put("Id", mediaEntity.getId()).put("Type", mediaEntity.getType())
            .put("MediaURL", mediaEntity.getMediaURL()).put("Sizes", convertSizes(mediaEntity.getSizes()))
            .put("MediaURLHttps", mediaEntity.getMediaURLHttps())
            .put("VideoAspectRatioWidth", mediaEntity.getVideoAspectRatioWidth())
            .put("VideoAspectRatioHeight", mediaEntity.getVideoAspectRatioHeight())
            .put("VideoDurationMillis", mediaEntity.getVideoDurationMillis())
            .put("VideoVariants", convert(mediaEntity.getVideoVariants()))
            .put("ExtAltText", mediaEntity.getExtAltText()).put("URL", mediaEntity.getURL())
            .put("Text", mediaEntity.getText()).put("ExpandedURL", mediaEntity.getExpandedURL())
            .put("Start", mediaEntity.getStart()).put("End", mediaEntity.getEnd())
            .put("DisplayURL", mediaEntity.getDisplayURL());
}

From source file:com.ofbizian.camelympics.MainApp.java

License:Open Source License

public static void main(String[] args) throws Exception {
    System.out.println("___________________Camelympics___________________");
    System.out.println("Open your web browser on http://localhost:8080");
    System.out.println("Press ctrl+c to stop this application");
    System.out.println("__________________________________________________");
    Main main = new Main();
    main.enableHangupSupport();/*from   w  w  w.ja va 2 s .c o m*/
    main.addRouteBuilder(new RouteBuilder() {

        @Override
        public void configure() throws Exception {

            PropertiesComponent properties = new PropertiesComponent();
            properties.setLocation("classpath:app.properties");
            properties.setSystemPropertiesMode(PropertiesComponent.SYSTEM_PROPERTIES_MODE_OVERRIDE);
            getContext().addComponent("properties", properties);

            ThreadPoolProfile throttlerPool = new ThreadPoolProfile("throttlerPool");
            throttlerPool.setRejectedPolicy(ThreadPoolRejectedPolicy.Discard);
            throttlerPool.setMaxQueueSize(10);
            throttlerPool.setMaxPoolSize(2);
            throttlerPool.setPoolSize(2);
            getContext().getExecutorServiceManager().registerThreadPoolProfile(throttlerPool);
            getContext().getShutdownStrategy().setTimeout(1);

            from("twitter://streaming/filter?type=event&keywords={{searchTerm}}&accessToken={{accessToken}}&accessTokenSecret={{accessTokenSecret}}&consumerKey={{consumerKey}}&consumerSecret={{consumerSecret}}")

                    .to("log:tweetStream?level=INFO&groupInterval=10000&groupDelay=50000&groupActiveOnly=false")

                    .process(new Processor() {

                        @Override
                        public void process(Exchange exchange) throws Exception {
                            tweetCount++;
                            Status status = exchange.getIn().getBody(Status.class);
                            MediaEntity[] mediaEntities = status.getMediaEntities();
                            if (mediaEntities != null && !status.isPossiblySensitive()) { //nsfw
                                for (MediaEntity mediaEntity : mediaEntities) {
                                    imageCount++;
                                    exchange.getIn()
                                            .setBody(new Tweet().withName(status.getUser().getScreenName())
                                                    .withText(status.getText()).withCount(tweetCount)
                                                    .withImageCount(imageCount)
                                                    .withTweetUrl(mediaEntity.getDisplayURL().toString())
                                                    .withImageUrl(mediaEntity.getMediaURLHttps().toString()));

                                    exchange.getIn().setHeader("UNIQUE_IMAGE_URL",
                                            mediaEntity.getMediaURL().toString());
                                    break; //grab only the first image
                                }
                            }
                        }
                    })

                    .filter(body().isInstanceOf(Tweet.class))

                    .idempotentConsumer(header("UNIQUE_IMAGE_URL"),
                            MemoryIdempotentRepository.memoryIdempotentRepository(10000))

                    .throttle(1).timePeriodMillis(500).asyncDelayed().executorServiceRef("throttlerPool")

                    .marshal().json(JsonLibrary.Jackson).convertBodyTo(String.class)

                    .to("websocket://0.0.0.0:8080/camelympics?sendToAll=true&staticResources=classpath:web/.");
        }
    });

    main.run();
}

From source file:de.vanita5.twittnuker.util.MediaPreviewUtils.java

License:Open Source License

public static String getSupportedFirstLink(final Status status) {
    if (status == null)
        return null;
    final MediaEntity[] mediaEntities = status.getMediaEntities();
    if (mediaEntities != null) {
        for (final MediaEntity mediaEntity : mediaEntities) {
            final String expanded = ParseUtils.parseString(mediaEntity.getMediaURLHttps());
            if (getSupportedLink(expanded) != null)
                return expanded;
        }/*from w  w  w  . j a v  a  2s. co  m*/
    }
    final URLEntity[] urlEntities = status.getURLEntities();
    if (urlEntities != null) {
        for (final URLEntity urlEntity : urlEntities) {
            final String expanded = ParseUtils.parseString(urlEntity.getExpandedURL());
            if (getSupportedLink(expanded) != null)
                return expanded;
        }
    }
    return null;
}

From source file:org.getlantern.firetweet.util.MediaPreviewUtils.java

License:Open Source License

public static String getSupportedFirstLink(final Status status) {
    if (status == null)
        return null;
    final MediaEntity[] mediaEntities = status.getMediaEntities();
    if (mediaEntities != null) {
        for (final MediaEntity mediaEntity : mediaEntities) {
            final String expanded = mediaEntity.getMediaURLHttps();
            if (getSupportedLink(expanded) != null)
                return expanded;
        }//w  ww .  j  a  va  2 s .  c  o m
    }
    final URLEntity[] urlEntities = status.getURLEntities();
    if (urlEntities != null) {
        for (final URLEntity urlEntity : urlEntities) {
            final String expanded = urlEntity.getExpandedURL();
            if (getSupportedLink(expanded) != null)
                return expanded;
        }
    }
    return null;
}

From source file:org.mariotaku.twidere.extension.streaming.util.MediaPreviewUtils.java

License:Open Source License

public static String getSupportedFirstLink(final Status status) {
    if (status == null)
        return null;
    final MediaEntity[] medias = status.getMediaEntities();
    if (medias != null) {
        for (final MediaEntity entity : medias) {
            final String expanded = ParseUtils.parseString(entity.getMediaURLHttps());
            if (getSupportedLink(expanded) != null)
                return expanded;
        }//from www .j  a  v a  2 s  . c o m
    }
    final URLEntity[] urls = status.getURLEntities();
    if (urls != null) {
        for (final URLEntity entity : urls) {
            final String expanded = ParseUtils.parseString(entity.getExpandedURL());
            if (getSupportedLink(expanded) != null)
                return expanded;
        }
    }
    return null;
}

From source file:org.xmlsh.twitter.util.TwitterWriter.java

License:BSD License

private void write(String localName, MediaEntity m) throws XMLStreamException {
    startElement(localName);/*ww w.  j  a va 2 s.  c  om*/
    attribute("display-url", m.getDisplayURL());
    attribute("end", m.getEnd());
    attribute("expanded-url", m.getExpandedURL().toString());
    attribute("id", m.getId());
    attribute("media-url", m.getMediaURL().toString());
    attribute("media-url-https", m.getMediaURLHttps().toString());

    attribute("start", m.getStart());
    attribute("url", m.getURL().toString());
    Set<Entry<Integer, Size>> sizes = m.getSizes().entrySet();
    for (Entry<Integer, Size> s : sizes) {
        startElement("size");
        attribute("height", s.getValue().getHeight());
        attribute("width", s.getValue().getWidth());
        attribute("resize", s.getValue().getResize());
        endElement();

    }
}