From a1dd9bbd2571fab1c4a62f9908e3615b468e45c1 Mon Sep 17 00:00:00 2001 From: 4pr0n Date: Thu, 10 Apr 2014 23:19:21 -0700 Subject: [PATCH] 1.0.16 - Fixed bug for Instagram usernames with - and _ #7 --- pom.xml | 2 +- .../ripme/ripper/rippers/InstagramRipper.java | 6 +++--- .../tst/ripper/rippers/InstagramRipperTest.java | 14 ++++++++++++++ 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/pom.xml b/pom.xml index ab663b8d..4990fdad 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ com.rarchives.ripme ripme jar - 1.0.15 + 1.0.16 ripme http://rip.rarchives.com diff --git a/src/main/java/com/rarchives/ripme/ripper/rippers/InstagramRipper.java b/src/main/java/com/rarchives/ripme/ripper/rippers/InstagramRipper.java index b4fb4487..718c57d7 100644 --- a/src/main/java/com/rarchives/ripme/ripper/rippers/InstagramRipper.java +++ b/src/main/java/com/rarchives/ripme/ripper/rippers/InstagramRipper.java @@ -32,7 +32,7 @@ public class InstagramRipper extends AbstractRipper { @Override public URL sanitizeURL(URL url) throws MalformedURLException { - Pattern p = Pattern.compile("^https?://instagram\\.com/p/([a-zA-Z0-9]{1,}).*$"); + Pattern p = Pattern.compile("^https?://instagram\\.com/p/([a-zA-Z0-9\\-_]{1,}).*$"); Matcher m = p.matcher(url.toExternalForm()); if (m.matches()) { // Link to photo, not the user account @@ -43,7 +43,7 @@ public class InstagramRipper extends AbstractRipper { throw new MalformedURLException("Failed to retrieve user page from " + url); } } - p = Pattern.compile("^.*instagram.com/([a-zA-Z0-9]{3,}).*$"); + p = Pattern.compile("^.*instagram.com/([a-zA-Z0-9\\-_]{3,}).*$"); m = p.matcher(url.toExternalForm()); if (!m.matches()) { throw new MalformedURLException("Expected username in URL (instagram.com/username and not " + url); @@ -132,7 +132,7 @@ public class InstagramRipper extends AbstractRipper { @Override public String getGID(URL url) throws MalformedURLException { - Pattern p = Pattern.compile("^https?://statigr.am/([a-zA-Z0-9]{3,}).*$"); + Pattern p = Pattern.compile("^https?://statigr.am/([a-zA-Z0-9\\-_]{3,}).*$"); Matcher m = p.matcher(url.toExternalForm()); if (m.matches()) { return m.group(1); diff --git a/src/test/java/com/rarchives/ripme/tst/ripper/rippers/InstagramRipperTest.java b/src/test/java/com/rarchives/ripme/tst/ripper/rippers/InstagramRipperTest.java index e1b95436..c45383e2 100644 --- a/src/test/java/com/rarchives/ripme/tst/ripper/rippers/InstagramRipperTest.java +++ b/src/test/java/com/rarchives/ripme/tst/ripper/rippers/InstagramRipperTest.java @@ -3,12 +3,26 @@ package com.rarchives.ripme.tst.ripper.rippers; import java.io.IOException; import java.net.URL; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; import com.rarchives.ripme.ripper.rippers.InstagramRipper; public class InstagramRipperTest extends RippersTest { + public void testInstagramGID() throws IOException { + Map testURLs = new HashMap(); + testURLs.put(new URL("http://instagram.com/Test_User"), "Test_User"); + testURLs.put(new URL("http://instagram.com/_test_user_"), "_test_user_"); + testURLs.put(new URL("http://instagram.com/-test-user-"), "-test-user-"); + for (URL url : testURLs.keySet()) { + InstagramRipper ripper = new InstagramRipper(url); + assertEquals(testURLs.get(url), ripper.getGID(ripper.getURL())); + deleteDir(ripper.getWorkingDir()); + } + } + public void testInstagramAlbums() throws IOException { if (!DOWNLOAD_CONTENT) { return;