Twitter ripper enhancements
This commit is contained in:
parent
c2bb65bc60
commit
bfd575906e
@ -168,10 +168,10 @@ public class TwitterRipper extends AlbumRipper {
|
|||||||
return tweets;
|
return tweets;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void parseTweet(JSONObject tweet) throws MalformedURLException {
|
private boolean parseTweet(JSONObject tweet) throws MalformedURLException {
|
||||||
if (!tweet.has("entities")) {
|
if (!tweet.has("entities")) {
|
||||||
logger.error("XXX Tweet doesn't have entitites");
|
logger.error("XXX Tweet doesn't have entitites");
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
JSONObject entities = tweet.getJSONObject("entities");
|
JSONObject entities = tweet.getJSONObject("entities");
|
||||||
@ -185,8 +185,12 @@ public class TwitterRipper extends AlbumRipper {
|
|||||||
url = media.getString("media_url");
|
url = media.getString("media_url");
|
||||||
if (url.contains(".twimg.com/")) {
|
if (url.contains(".twimg.com/")) {
|
||||||
url += ":large";
|
url += ":large";
|
||||||
}
|
|
||||||
addURLToDownload(new URL(url));
|
addURLToDownload(new URL(url));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
logger.debug("Unexpected media_url: " + url);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -204,6 +208,7 @@ public class TwitterRipper extends AlbumRipper {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -220,11 +225,8 @@ public class TwitterRipper extends AlbumRipper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Long lastMaxID = 0L;
|
Long lastMaxID = 0L;
|
||||||
|
int parsedCount = 0;
|
||||||
for (int i = 0; i < MAX_REQUESTS; i++) {
|
for (int i = 0; i < MAX_REQUESTS; i++) {
|
||||||
if (isStopped()) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
List<JSONObject> tweets = getTweets(getApiURL(lastMaxID - 1));
|
List<JSONObject> tweets = getTweets(getApiURL(lastMaxID - 1));
|
||||||
if (tweets.size() == 0) {
|
if (tweets.size() == 0) {
|
||||||
logger.info(" No more tweets found.");
|
logger.info(" No more tweets found.");
|
||||||
@ -234,12 +236,22 @@ public class TwitterRipper extends AlbumRipper {
|
|||||||
if (tweets.size() == 1 &&
|
if (tweets.size() == 1 &&
|
||||||
lastMaxID.equals(tweets.get(0).getString("id_str"))
|
lastMaxID.equals(tweets.get(0).getString("id_str"))
|
||||||
) {
|
) {
|
||||||
|
logger.info(" No more tweet found.");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (JSONObject tweet : tweets) {
|
for (JSONObject tweet : tweets) {
|
||||||
lastMaxID = tweet.getLong("id");
|
lastMaxID = tweet.getLong("id");
|
||||||
parseTweet(tweet);
|
if (parseTweet(tweet)) {
|
||||||
|
parsedCount++;
|
||||||
|
}
|
||||||
|
if (isStopped() || (isThisATest() && parsedCount > 0) ) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isStopped() || (isThisATest() && parsedCount > 0) ) {
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
Loading…
Reference in New Issue
Block a user