1.0.76 - Taptastic ripper improvements

New (improved) filename scheme.
Shortened code length/complexity.
Can now rip all episodes in series from a single /episode/ page.
Code formatting the way I like it.

From pull request #86.
This commit is contained in:
4pr0n 2014-07-01 22:48:02 -07:00
parent a95bfa7928
commit 6c84b192b7
3 changed files with 46 additions and 51 deletions

View File

@ -4,7 +4,7 @@
<groupId>com.rarchives.ripme</groupId> <groupId>com.rarchives.ripme</groupId>
<artifactId>ripme</artifactId> <artifactId>ripme</artifactId>
<packaging>jar</packaging> <packaging>jar</packaging>
<version>1.0.75</version> <version>1.0.76</version>
<name>ripme</name> <name>ripme</name>
<url>http://rip.rarchives.com</url> <url>http://rip.rarchives.com</url>
<properties> <properties>

View File

@ -11,31 +11,20 @@ import java.util.regex.Pattern;
import org.json.JSONArray; import org.json.JSONArray;
import org.json.JSONObject; import org.json.JSONObject;
import org.jsoup.nodes.Document; import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements; import org.jsoup.select.Elements;
import com.rarchives.ripme.ripper.AbstractHTMLRipper; import com.rarchives.ripme.ripper.AbstractHTMLRipper;
import com.rarchives.ripme.utils.Http; import com.rarchives.ripme.utils.Http;
import com.rarchives.ripme.utils.Utils;
class TapasticEpisode { class TapasticEpisode {
int index; protected int index, id;
int id; protected String title, filename;
String title;
String filename;
public TapasticEpisode(int index, int id, String title) { public TapasticEpisode(int index, int id, String title) {
this.index = index; this.index = index;
this.id = id; this.id = id;
this.title = title; this.title = title;
this.filename=title // Windows filenames may not contain any of these... this.filename = Utils.filesystemSafe(title);
.replace("\\", "")
.replace("/", "")
.replace(":", "")
.replace("*", "")
.replace("?", "")
.replace("\"", "")
.replace("<", "")
.replace(">", "")
.replace("|", "");
} }
} }
@ -65,26 +54,19 @@ public class TapasticRipper extends AbstractHTMLRipper {
@Override @Override
public List<String> getURLsFromPage(Document page) { public List<String> getURLsFromPage(Document page) {
List<String> urls = new ArrayList<String>(); List<String> urls = new ArrayList<String>();
Elements scripts=page.select("script"); String html = page.data();
for(Element script: scripts) { if (!html.contains("episodeList : ")) {
String text=script.data(); logger.error("No 'episodeList' found at " + this.url);
if(text.contains("var _data")) { return urls;
String[] lines=text.split("\n"); }
for(String line:lines) { String jsonString = Utils.between(html, "episodeList : ", ",\n").get(0);
String trimmed=line.trim(); JSONArray json = new JSONArray(jsonString);
if(trimmed.startsWith("episodeList : ")) { for (int i = 0; i < json.length(); i++) {
JSONArray json_episodes=new JSONArray(trimmed.substring("episodeList : ".length())); JSONObject obj = json.getJSONObject(i);
for(int i=0;i<json_episodes.length();i++) {
JSONObject obj=json_episodes.getJSONObject(i);
TapasticEpisode episode = new TapasticEpisode(i, obj.getInt("id"), obj.getString("title")); TapasticEpisode episode = new TapasticEpisode(i, obj.getInt("id"), obj.getString("title"));
episodes.add(episode); episodes.add(episode);
urls.add("http://tapastic.com/episode/" + episode.id); urls.add("http://tapastic.com/episode/" + episode.id);
} }
}
}
break;
}
}
return urls; return urls;
} }
@ -93,26 +75,39 @@ public class TapasticRipper extends AbstractHTMLRipper {
try { try {
Document doc = Http.url(url).get(); Document doc = Http.url(url).get();
Elements images = doc.select("article.ep-contents img"); Elements images = doc.select("article.ep-contents img");
// Find maximum # of images for optimal filename indexing
int epiLog = (int) (Math.floor(Math.log10(episodes.size())) + 1),
imgLog = (int) (Math.floor(Math.log10(images.size() )) + 1);
for (int i = 0; i < images.size(); i++) { for (int i = 0; i < images.size(); i++) {
String link = images.get(i).attr("src"); String link = images.get(i).attr("src");
String postfix=String.format(" %d-%d ", i+1,images.size());
TapasticEpisode episode = episodes.get(index - 1); TapasticEpisode episode = episodes.get(index - 1);
addURLToDownload(new URL(link), getPrefix(index)+episode.filename+postfix); // Build elaborate filename prefix
StringBuilder prefix = new StringBuilder();
prefix.append(String.format("ep%0" + epiLog + "d", index));
prefix.append(String.format("-%0" + imgLog + "dof%0" + imgLog + "d-", i + 1, images.size()));
prefix.append(episode.filename.replace(" ", "-"));
prefix.append("-");
addURLToDownload(new URL(link), prefix.toString());
} }
} catch (IOException e) { } catch (IOException e) {
logger.error("[!] Exception while loading/parsing " + this.url,e); logger.error("[!] Exception while downloading " + url, e);
} }
} }
@Override @Override
public String getGID(URL url) throws MalformedURLException { public String getGID(URL url) throws MalformedURLException {
Pattern p = Pattern.compile("^http://tapastic.com/series/(.*)$"); Pattern p = Pattern.compile("^http://tapastic.com/series/([^/?]+).*$");
Matcher m = p.matcher(url.toExternalForm()); Matcher m = p.matcher(url.toExternalForm());
if (m.matches()) { if (m.matches()) {
return m.group(1); return "series_ " + m.group(1);
}
p = Pattern.compile("^http://tapastic.com/episode/([^/?]+).*$");
m = p.matcher(url.toExternalForm());
if (m.matches()) {
return "ep_" + m.group(1);
} }
throw new MalformedURLException("Expected tapastic.com URL format: " throw new MalformedURLException("Expected tapastic.com URL format: "
+ "tapastic.com/series/name - got " + url + " instead"); + "tapastic.com/[series|episode]/name - got " + url + " instead");
} }
} }

View File

@ -21,7 +21,7 @@ import com.rarchives.ripme.utils.Utils;
public class UpdateUtils { public class UpdateUtils {
private static final Logger logger = Logger.getLogger(UpdateUtils.class); private static final Logger logger = Logger.getLogger(UpdateUtils.class);
private static final String DEFAULT_VERSION = "1.0.75"; private static final String DEFAULT_VERSION = "1.0.76";
private static final String updateJsonURL = "http://rarchives.com/ripme.json"; private static final String updateJsonURL = "http://rarchives.com/ripme.json";
private static final String updateJarURL = "http://rarchives.com/ripme.jar"; private static final String updateJarURL = "http://rarchives.com/ripme.jar";
private static final String mainFileName = "ripme.jar"; private static final String mainFileName = "ripme.jar";