Merge pull request #705 from cyian-1756/twitterFix
Twitter ripper now rips retweets
This commit is contained in:
commit
706fe0a988
@ -20,6 +20,8 @@ import com.rarchives.ripme.utils.Utils;
|
|||||||
|
|
||||||
public class TwitterRipper extends AlbumRipper {
|
public class TwitterRipper extends AlbumRipper {
|
||||||
|
|
||||||
|
int downloadUrls = 1;
|
||||||
|
|
||||||
private static final String DOMAIN = "twitter.com",
|
private static final String DOMAIN = "twitter.com",
|
||||||
HOST = "twitter";
|
HOST = "twitter";
|
||||||
|
|
||||||
@ -123,7 +125,7 @@ public class TwitterRipper extends AlbumRipper {
|
|||||||
.append("&include_entities=true")
|
.append("&include_entities=true")
|
||||||
.append("&exclude_replies=true")
|
.append("&exclude_replies=true")
|
||||||
.append("&trim_user=true")
|
.append("&trim_user=true")
|
||||||
.append("&include_rts=false")
|
.append("&include_rts=true")
|
||||||
.append("&count=" + 200);
|
.append("&count=" + 200);
|
||||||
break;
|
break;
|
||||||
case SEARCH:
|
case SEARCH:
|
||||||
@ -187,18 +189,28 @@ public class TwitterRipper extends AlbumRipper {
|
|||||||
url = media.getString("media_url");
|
url = media.getString("media_url");
|
||||||
if (media.getString("type").equals("video")) {
|
if (media.getString("type").equals("video")) {
|
||||||
JSONArray variants = media.getJSONObject("video_info").getJSONArray("variants");
|
JSONArray variants = media.getJSONObject("video_info").getJSONArray("variants");
|
||||||
|
int largestBitrate = 0;
|
||||||
|
String urlToDownload = null;
|
||||||
|
// Loop over all the video options and find the biggest video
|
||||||
for (int j = 0; j < medias.length(); j++) {
|
for (int j = 0; j < medias.length(); j++) {
|
||||||
JSONObject variant = (JSONObject) variants.get(i);
|
JSONObject variant = (JSONObject) variants.get(i);
|
||||||
if (variant.has("bitrate") && variant.getInt("bitrate") == 832000) {
|
if (variant.getInt("bitrate") > largestBitrate) {
|
||||||
addURLToDownload(new URL(variant.getString("url")));
|
largestBitrate = variant.getInt("bitrate");
|
||||||
parsedCount++;
|
urlToDownload = variant.getString("url");
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (urlToDownload != null) {
|
||||||
|
addURLToDownload(new URL(urlToDownload), getPrefix(downloadUrls));
|
||||||
|
downloadUrls++;
|
||||||
|
} else {
|
||||||
|
LOGGER.error("URLToDownload was null");
|
||||||
|
}
|
||||||
|
parsedCount++;
|
||||||
} else if (media.getString("type").equals("photo")) {
|
} else if (media.getString("type").equals("photo")) {
|
||||||
if (url.contains(".twimg.com/")) {
|
if (url.contains(".twimg.com/")) {
|
||||||
url += ":orig";
|
url += ":orig";
|
||||||
addURLToDownload(new URL(url));
|
addURLToDownload(new URL(url), getPrefix(downloadUrls));
|
||||||
|
downloadUrls++;
|
||||||
parsedCount++;
|
parsedCount++;
|
||||||
} else {
|
} else {
|
||||||
LOGGER.debug("Unexpected media_url: " + url);
|
LOGGER.debug("Unexpected media_url: " + url);
|
||||||
@ -211,6 +223,10 @@ public class TwitterRipper extends AlbumRipper {
|
|||||||
return parsedCount;
|
return parsedCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getPrefix(int index) {
|
||||||
|
return String.format("%03d_", index);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void rip() throws IOException {
|
public void rip() throws IOException {
|
||||||
getAccessToken();
|
getAccessToken();
|
||||||
|
Loading…
Reference in New Issue
Block a user