1
0
mirror of https://github.com/RipMeApp/ripme.git synced 2025-08-25 23:06:22 +02:00

Merge pull request #1239 from Tush-r/artstn

Added support for artstn.co
This commit is contained in:
cyian-1756
2019-03-22 06:52:10 -05:00
committed by GitHub
2 changed files with 77 additions and 0 deletions

View File

@@ -0,0 +1,58 @@
package com.rarchives.ripme.ripper.rippers;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import org.jsoup.Connection.Response;
import com.rarchives.ripme.utils.Http;
/*
* Ripper for ArtStation's short URL domain.
* Example URL: https://artstn.co/p/JlE15Z
*/
public class ArtstnRipper extends ArtStationRipper {
public URL artStationUrl = null;
public ArtstnRipper(URL url) throws IOException {
super(url);
}
@Override
public boolean canRip(URL url) {
return url.getHost().endsWith("artstn.co");
}
@Override
public String getGID(URL url) throws MalformedURLException {
if (artStationUrl == null) {
// Run only once.
try {
artStationUrl = getFinalUrl(url);
if (artStationUrl == null) {
throw new IOException("Null url received.");
}
} catch (IOException e) {
LOGGER.error("Couldnt resolve URL.", e);
}
}
return super.getGID(artStationUrl);
}
public URL getFinalUrl(URL url) throws IOException {
if (url.getHost().endsWith("artstation.com")) {
return url;
}
LOGGER.info("Checking url: " + url);
Response response = Http.url(url).connection().followRedirects(false).execute();
if (response.statusCode() / 100 == 3 && response.hasHeader("location")) {
return getFinalUrl(new URL(response.header("location")));
} else {
return null;
}
}
}

View File

@@ -0,0 +1,19 @@
package com.rarchives.ripme.tst.ripper.rippers;
import java.io.IOException;
import java.net.URL;
import com.rarchives.ripme.ripper.rippers.ArtstnRipper;
public class ArtstnRipperTest extends RippersTest {
public void testSingleProject() throws IOException {
URL url = new URL("https://artstn.co/p/JlE15Z");
testRipper(new ArtstnRipper(url));
}
public void testUserPortfolio() throws IOException {
URL url = new URL("https://artstn.co/m/rv37");
testRipper(new ArtstnRipper(url));
}
}