Skip to content

Instantly share code, notes, and snippets.

@Minecraftian14
Created June 29, 2022 16:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Minecraftian14/eabeff70cc4d0ccd1adff167c0ba5f28 to your computer and use it in GitHub Desktop.
Save Minecraftian14/eabeff70cc4d0ccd1adff167c0ba5f28 to your computer and use it in GitHub Desktop.
Download Reels From... IG ig?
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.Optional;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* Just give in two arguments, one for the page link and the other for the output file, as commandline arguments.
* Wait until you see "Success!"
*/
class InstaReelDownloader {
private static final Pattern pat = Pattern.compile("video_url\":\"([^\"]+)\"");
private static Optional<byte[]> readAnd(String url_str) {
try {
URL url = new URL(url_str);
try (InputStream ins = url.openStream()) {
var bts = ins.readAllBytes();
return Optional.of(bts);
}
} catch (Exception e) {
System.out.println(e.getMessage());
}
return Optional.empty();
}
public static void main(String[] args) {
if (args.length >= 1 && args[0].contains("?")) args[0] = args[0].substring(0, args[0].indexOf("?"));
readAnd((args.length >= 1 ? args[0] : "https://www.instagram.com/tv/CeoZCGXAwcj/") + "?__a=1")
.map(String::new)
.map(pat::matcher)
.filter(Matcher::find)
.map(matcher -> matcher.group(1))
.flatMap(Scratch::readAnd)
.ifPresent(bytes -> {
try (var o = new FileOutputStream(args.length >= 2 ? args[1] : "D://out.mp4")) {
o.write(bytes);
System.out.println("Success!");
} catch (IOException e) {
e.printStackTrace();
}
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment