Merge branch 'master' into moreMagicNumbers

This commit is contained in:
cyian-1756 2018-08-04 12:52:25 -04:00 committed by GitHub
commit 292e977a22
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 121 additions and 101 deletions

View File

@ -224,7 +224,6 @@ public abstract class AbstractHTMLRipper extends AlbumRipper {
if (!subdirectory.equals("")) { // Not sure about this part
subdirectory = File.separator + subdirectory;
}
// TODO Get prefix working again, probably requires reworking a lot of stuff! (Might be fixed now)
saveFileAs = new File(
workingDir.getCanonicalPath()
+ subdirectory

View File

@ -0,0 +1,43 @@
package com.rarchives.ripme.ripper;
import com.rarchives.ripme.utils.Utils;
import java.io.IOException;
import java.net.URL;
/**
* This is just an extension of AbstractHTMLRipper that auto overrides a few things
* to help cut down on copy pasted code
*/
public abstract class AbstractSingleFileRipper extends AbstractHTMLRipper {
private int bytesTotal = 1;
private int bytesCompleted = 1;
protected AbstractSingleFileRipper(URL url) throws IOException {
super(url);
}
@Override
public String getStatusText() {
return Utils.getByteStatusText(getCompletionPercentage(), bytesCompleted, bytesTotal);
}
@Override
public int getCompletionPercentage() {
return (int) (100 * (bytesCompleted / (float) bytesTotal));
}
@Override
public void setBytesTotal(int bytes) {
this.bytesTotal = bytes;
}
@Override
public void setBytesCompleted(int bytes) {
this.bytesCompleted = bytes;
}
@Override
public boolean useByteProgessBar() {return true;}
}

View File

@ -8,6 +8,7 @@ import java.io.InputStream;
import java.io.OutputStream;
import java.lang.reflect.Array;
import java.net.HttpURLConnection;
import java.net.SocketTimeoutException;
import java.net.URL;
import java.net.URLConnection;
import java.util.Arrays;
@ -109,7 +110,10 @@ class DownloadFileThread extends Thread {
huc = (HttpURLConnection) urlToDownload.openConnection();
}
huc.setInstanceFollowRedirects(true);
// It is important to set both ConnectTimeout and ReadTimeout. If you don't then ripme will wait forever
// for the server to send data after connecting.
huc.setConnectTimeout(TIMEOUT);
huc.setReadTimeout(TIMEOUT);
huc.setRequestProperty("accept", "*/*");
if (!referrer.equals("")) {
huc.setRequestProperty("Referer", referrer); // Sic
@ -222,6 +226,11 @@ class DownloadFileThread extends Thread {
bis.close();
fos.close();
break; // Download successful: break out of infinite loop
} catch (SocketTimeoutException timeoutEx) {
// Handle the timeout
logger.error("[!] " + url.toExternalForm() + " timedout!");
// Download failed, break out of loop
break;
} catch (HttpStatusException hse) {
logger.debug("HTTP status exception", hse);
logger.error("[!] HTTP status " + hse.getStatusCode() + " while downloading from " + urlToDownload);

View File

@ -28,7 +28,7 @@ public class CheveretoRipper extends AbstractHTMLRipper {
super(url);
}
private static List<String> explicit_domains_1 = Arrays.asList("tag-fox.com");
private static List<String> explicit_domains = Arrays.asList("tag-fox.com", "kenzato.uk");
@Override
public String getHost() {
@ -43,12 +43,8 @@ public class CheveretoRipper extends AbstractHTMLRipper {
@Override
public boolean canRip(URL url) {
String url_name = url.toExternalForm();
if (explicit_domains_1.contains(url_name.split("/")[2])) {
Pattern pa = Pattern.compile("(?:https?://)?(?:www\\.)?[a-z1-9-]*\\.[a-z1-9]*/album/([a-zA-Z1-9]*)/?$");
Matcher ma = pa.matcher(url.toExternalForm());
if (ma.matches()) {
if (explicit_domains.contains(url_name.split("/")[2])) {
return true;
}
}
return false;
}
@ -70,7 +66,7 @@ public class CheveretoRipper extends AbstractHTMLRipper {
@Override
public String getGID(URL url) throws MalformedURLException {
Pattern p = Pattern.compile("(?:https?://)?(?:www\\.)?[a-z1-9-]*\\.[a-z1-9]*/album/([a-zA-Z1-9]*)/?$");
Pattern p = Pattern.compile("(?:https?://)?(?:www\\.)?[a-z1-9-]*\\.[a-z1-9]*(?:[a-zA-Z1-9]*)/album/([a-zA-Z1-9]*)/?$");
Matcher m = p.matcher(url.toExternalForm());
if (m.matches()) {
return m.group(1);

View File

@ -9,18 +9,14 @@ import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import com.rarchives.ripme.ripper.AbstractHTMLRipper;
import com.rarchives.ripme.utils.Utils;
import com.rarchives.ripme.ripper.AbstractSingleFileRipper;
import org.jsoup.nodes.Document;
import org.jsoup.select.Elements;
import com.rarchives.ripme.utils.Http;
public class GfycatRipper extends AbstractHTMLRipper {
private int bytesTotal = 1;
private int bytesCompleted = 1;
public class GfycatRipper extends AbstractSingleFileRipper {
private static final String HOST = "gfycat.com";
@ -109,27 +105,4 @@ public class GfycatRipper extends AbstractHTMLRipper {
}
return vidUrl;
}
@Override
public String getStatusText() {
return Utils.getByteStatusText(getCompletionPercentage(), bytesCompleted, bytesTotal);
}
@Override
public int getCompletionPercentage() {
return (int) (100 * (bytesCompleted / (float) bytesTotal));
}
@Override
public void setBytesTotal(int bytes) {
this.bytesTotal = bytes;
}
@Override
public void setBytesCompleted(int bytes) {
this.bytesCompleted = bytes;
}
@Override
public boolean useByteProgessBar() {return true;}
}

View File

@ -8,17 +8,12 @@ import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import com.rarchives.ripme.utils.Utils;
import com.rarchives.ripme.ripper.AbstractSingleFileRipper;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import com.rarchives.ripme.ripper.AbstractHTMLRipper;
import com.rarchives.ripme.utils.Http;
public class GfycatporntubeRipper extends AbstractHTMLRipper {
private int bytesTotal = 1;
private int bytesCompleted = 1;
public class GfycatporntubeRipper extends AbstractSingleFileRipper {
public GfycatporntubeRipper(URL url) throws IOException {
super(url);
@ -62,27 +57,4 @@ public class GfycatporntubeRipper extends AbstractHTMLRipper {
public void downloadURL(URL url, int index) {
addURLToDownload(url, getPrefix(index));
}
@Override
public String getStatusText() {
return Utils.getByteStatusText(getCompletionPercentage(), bytesCompleted, bytesTotal);
}
@Override
public int getCompletionPercentage() {
return (int) (100 * (bytesCompleted / (float) bytesTotal));
}
@Override
public void setBytesTotal(int bytes) {
this.bytesTotal = bytes;
}
@Override
public void setBytesCompleted(int bytes) {
this.bytesCompleted = bytes;
}
@Override
public boolean useByteProgessBar() {return true;}
}

View File

@ -8,21 +8,18 @@ import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import com.rarchives.ripme.ripper.AbstractHTMLRipper;
import com.rarchives.ripme.utils.Utils;
import com.rarchives.ripme.ripper.AbstractSingleFileRipper;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import com.rarchives.ripme.utils.Http;
public class XvideosRipper extends AbstractHTMLRipper {
public class XvideosRipper extends AbstractSingleFileRipper {
private static final String HOST = "xvideos";
private int bytesTotal = 1;
private int bytesCompleted = 1;
public XvideosRipper(URL url) throws IOException {
super(url);
}
@ -86,27 +83,4 @@ public class XvideosRipper extends AbstractHTMLRipper {
public void downloadURL(URL url, int index) {
addURLToDownload(url, getPrefix(index));
}
@Override
public String getStatusText() {
return Utils.getByteStatusText(getCompletionPercentage(), bytesCompleted, bytesTotal);
}
@Override
public int getCompletionPercentage() {
return (int) (100 * (bytesCompleted / (float) bytesTotal));
}
@Override
public void setBytesTotal(int bytes) {
this.bytesTotal = bytes;
}
@Override
public void setBytesCompleted(int bytes) {
this.bytesCompleted = bytes;
}
@Override
public boolean useByteProgessBar() {return true;}
}

View File

@ -10,6 +10,7 @@ import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.Array;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URL;
@ -142,6 +143,10 @@ public final class MainWindow implements Runnable, RipStatusHandler {
private ResourceBundle rb = Utils.getResourceBundle(null);
// All the langs ripme has been translated into
private static String[] supportedLanges = new String[] {"en_US", "de_DE", "es_ES", "fr_CH", "kr_KR", "pt_PT",
"fi_FI", "in_ID", "nl_NL", "porrisavvo_FI", "ru_RU"};
private void updateQueueLabel() {
if (queueListModel.size() > 0) {
optionQueue.setText(rb.getString("Queue") + " (" + queueListModel.size() + ")");
@ -496,7 +501,7 @@ public final class MainWindow implements Runnable, RipStatusHandler {
configURLHistoryCheckbox = addNewCheckbox(rb.getString("remember.url.history"), "remember.url_history", true);
configLogLevelCombobox = new JComboBox<>(new String[] {"Log level: Error", "Log level: Warn", "Log level: Info", "Log level: Debug"});
configSelectLangComboBox = new JComboBox<>(new String[] {"en_US", "de_DE", "es_ES", "fr_CH", "kr_KR", "pt_PT", "fi_FI", "in_ID", "nl_NL", "porrisavvo_FI"});
configSelectLangComboBox = new JComboBox<>(supportedLanges);
configLogLevelCombobox.setSelectedItem(Utils.getConfigString("log.level", "Log level: Debug"));
setLogLevel(configLogLevelCombobox.getSelectedItem().toString());
configSaveDirLabel = new JLabel();

View File

@ -0,0 +1,37 @@
Log = Лог
History = История
created = создано
modified = изменено
Queue = Очередь
Configuration = Настройки
# Keys for the Configuration menu
current.version = Текущая версия
check.for.updates = Проверить обновления
auto.update = Автообновление?
max.download.threads = Максимальное число потоков:
timeout.mill = Задержка (в миллисекундах):
retry.download.count = Число повторов
overwrite.existing.files = Перезаписать существующие файлы?
sound.when.rip.completes = Звук при завершении
preserve.order = Сохранять порядок
save.logs = Сохранять логи
notification.when.rip.starts = Уведомление при запуске
save.urls.only = Сохранять только ссылки
save.album.titles = Сохранять названия альбомов
autorip.from.clipboard = Автоскачивание из буфера
save.descriptions = Сохранять описания
prefer.mp4.over.gif = Предпочесть MP4 вместо GIF
restore.window.position = Восстановить положение окна
remember.url.history = Запоминать историю запросов
loading.history.from = Загрузить историю из
# Misc UI keys
loading.history.from.configuration = Загрузить историю из настроек
interrupted.while.waiting.to.rip.next.album = Прервано во время ожидания скачивания следующего альбома
inactive = Неактивно
re-rip.checked = Перекачать выбранное
remove = Удалить
clear = Очистить

View File

@ -4,6 +4,8 @@ import junit.framework.TestCase;
import com.rarchives.ripme.utils.Utils;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.Arrays;
public class UtilsTest extends TestCase {
@ -34,4 +36,12 @@ public class UtilsTest extends TestCase {
assert(!Utils.getListOfAlbumRippers().isEmpty());
}
public void testGetByteStatusText() {
assertEquals("5% - 500.00iB / 97.66KiB", Utils.getByteStatusText(5, 500, 100000));
}
public void testBetween() {
assertEquals(Arrays.asList(" is a "), Utils.between("This is a test", "This", "test"));
}
}

View File

@ -10,4 +10,9 @@ public class CheveretoRipperTest extends RippersTest {
CheveretoRipper ripper = new CheveretoRipper(new URL("http://tag-fox.com/album/Thjb"));
testRipper(ripper);
}
public void testSubdirAlbum() throws IOException {
CheveretoRipper ripper = new CheveretoRipper(new URL("https://kenzato.uk/booru/album/TnEc"));
testRipper(ripper);
}
}

View File

@ -6,8 +6,5 @@ import java.io.IOException;
import java.net.URL;
public class LoveromRipperTest extends RippersTest{
public void testRip() throws IOException {
LoveromRipper ripper = new LoveromRipper(new URL("https://www.loveroms.com/download/nintendo/adventures-of-tom-sawyer-u/107165"));
testRipper(ripper);
}
}