mirror of
https://github.com/RipMeApp/ripme.git
synced 2025-08-26 07:14:38 +02:00
Merge pull request #1239 from Tush-r/artstn
Added support for artstn.co
This commit is contained in:
@@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -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));
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user