Fix on Android downloader and code indent
This commit is contained in:
@@ -4,9 +4,11 @@ import org.jsoup.Jsoup;
|
||||
import org.jsoup.nodes.Document;
|
||||
import org.jsoup.nodes.Element;
|
||||
import org.jsoup.select.Elements;
|
||||
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipFile;
|
||||
import java.util.Enumeration;
|
||||
|
||||
import net.lingala.zip4j.model.ZipParameters;
|
||||
import net.lingala.zip4j.model.enums.CompressionMethod;
|
||||
|
||||
@@ -25,30 +27,31 @@ public class ImgDownloader {
|
||||
|
||||
private static String convertStreamToString(java.io.InputStream inputStream) {
|
||||
final int bufferSize = 1024;
|
||||
final char[] buffer = new char[bufferSize];
|
||||
final StringBuilder out = new StringBuilder();
|
||||
try {
|
||||
Reader in = new InputStreamReader(inputStream, StandardCharsets.ISO_8859_1);
|
||||
for (; ; ) {
|
||||
int rsz = in.read(buffer, 0, buffer.length);
|
||||
final char[] buffer = new char[bufferSize];
|
||||
final StringBuilder out = new StringBuilder();
|
||||
try {
|
||||
Reader in = new InputStreamReader(inputStream, StandardCharsets.ISO_8859_1);
|
||||
for (; ; ) {
|
||||
int rsz = in.read(buffer, 0, buffer.length);
|
||||
if (rsz < 0)
|
||||
break;
|
||||
out.append(buffer, 0, rsz);
|
||||
}
|
||||
} catch (Exception e) {}
|
||||
} catch (Exception e) {
|
||||
}
|
||||
return out.toString();
|
||||
}
|
||||
|
||||
private static String readLineByLineJava8(String filePath) {
|
||||
StringBuilder contentBuilder = new StringBuilder();
|
||||
|
||||
try {
|
||||
File file = new File(filePath);
|
||||
BufferedReader br = new BufferedReader(new FileReader(file));
|
||||
|
||||
String st;
|
||||
while ((st = br.readLine()) != null)
|
||||
contentBuilder.append(st).append("\n");
|
||||
try {
|
||||
File file = new File(filePath);
|
||||
BufferedReader br = new BufferedReader(new FileReader(file));
|
||||
|
||||
String st;
|
||||
while ((st = br.readLine()) != null)
|
||||
contentBuilder.append(st).append("\n");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -56,32 +59,32 @@ public class ImgDownloader {
|
||||
return contentBuilder.toString();
|
||||
}
|
||||
|
||||
public static String getSetInfo(String setName, boolean zipped, String path){
|
||||
public static String getSetInfo(String setName, boolean zipped, String path) {
|
||||
String cardsfilepath = "";
|
||||
boolean todelete = false;
|
||||
if(zipped){
|
||||
if (zipped) {
|
||||
File resFolder = new File(path + File.separator);
|
||||
File [] listOfFile = resFolder.listFiles();
|
||||
File[] listOfFile = resFolder.listFiles();
|
||||
ZipFile zipFile = null;
|
||||
InputStream stream = null;
|
||||
java.nio.file.Path filePath = null;
|
||||
try {
|
||||
for (int i = 0; i < listOfFile.length; i++){
|
||||
if (listOfFile[i].getName().contains(".zip")){
|
||||
zipFile = new ZipFile(path + File.separator + listOfFile[i].getName());
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(zipFile == null)
|
||||
return "";
|
||||
for (int i = 0; i < listOfFile.length; i++) {
|
||||
if (listOfFile[i].getName().contains(".zip")) {
|
||||
zipFile = new ZipFile(path + File.separator + listOfFile[i].getName());
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (zipFile == null)
|
||||
return "";
|
||||
Enumeration<? extends ZipEntry> e = zipFile.entries();
|
||||
while (e.hasMoreElements()) {
|
||||
ZipEntry entry = e.nextElement();
|
||||
String entryName = entry.getName();
|
||||
if(entryName.contains("sets/")){
|
||||
if(entryName.contains("_cards.dat")){
|
||||
if (entryName.contains("sets/")) {
|
||||
if (entryName.contains("_cards.dat")) {
|
||||
String[] names = entryName.split("/");
|
||||
if(setName.equalsIgnoreCase(names[1])){
|
||||
if (setName.equalsIgnoreCase(names[1])) {
|
||||
stream = zipFile.getInputStream(entry);
|
||||
byte[] buffer = new byte[1];
|
||||
java.nio.file.Path outDir = Paths.get(path + File.separator);
|
||||
@@ -97,26 +100,28 @@ public class ImgDownloader {
|
||||
bos.close();
|
||||
cardsfilepath = filePath.toString();
|
||||
todelete = true;
|
||||
} catch (Exception ex) {}
|
||||
} catch (Exception ex) {
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (IOException ioe){ }
|
||||
finally {
|
||||
}
|
||||
} catch (IOException ioe) {
|
||||
} finally {
|
||||
try {
|
||||
if (zipFile!=null) {
|
||||
if (zipFile != null) {
|
||||
zipFile.close();
|
||||
}
|
||||
} catch (IOException ioe) {}
|
||||
} catch (IOException ioe) {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
File setFolder = new File(path + File.separator + "sets" + File.separator + setName + File.separator);
|
||||
cardsfilepath = setFolder.getAbsolutePath() + File.separator + "_cards.dat";
|
||||
}
|
||||
String lines = readLineByLineJava8(cardsfilepath);
|
||||
if(todelete) {
|
||||
if (todelete) {
|
||||
File del = new File(cardsfilepath);
|
||||
del.delete();
|
||||
}
|
||||
@@ -131,48 +136,52 @@ public class ImgDownloader {
|
||||
return name + " (" + totalcards + " cards)";
|
||||
}
|
||||
|
||||
public static Document findTokenPage(String imageurl, String name, String set, String [] availableSets, String tokenstats) throws Exception {
|
||||
public static Document findTokenPage(String imageurl, String name, String set, String[] availableSets, String tokenstats) throws Exception {
|
||||
Document doc = null;
|
||||
Elements outlinks = null;
|
||||
try {
|
||||
doc = Jsoup.connect(imageurl + "t" + set.toLowerCase()).get();
|
||||
outlinks = doc.select("body a");
|
||||
for (int k = 0; k < outlinks.size(); k++){
|
||||
for (int k = 0; k < outlinks.size(); k++) {
|
||||
String linktoken = outlinks.get(k).attributes().get("href");
|
||||
try {
|
||||
Document tokendoc = Jsoup.connect(linktoken).get();
|
||||
Elements stats = tokendoc.select("head meta");
|
||||
for (int j = 0; j < stats.size(); j++){
|
||||
for (int j = 0; j < stats.size(); j++) {
|
||||
String a = stats.get(j).attributes().get("content");
|
||||
if(stats.get(j).attributes().get("content").contains(tokenstats) && stats.get(j).attributes().get("content").toLowerCase().contains(name.toLowerCase())){
|
||||
if (stats.get(j).attributes().get("content").contains(tokenstats) && stats.get(j).attributes().get("content").toLowerCase().contains(name.toLowerCase())) {
|
||||
return tokendoc;
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {}
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
} catch (Exception e){}
|
||||
} catch (Exception e) {
|
||||
}
|
||||
System.out.println("Warning: Token " + name + " has not been found between " + set + " tokens, i will search for it between any other set...");
|
||||
for (int i = 1; i < availableSets.length; i++){
|
||||
for (int i = 1; i < availableSets.length; i++) {
|
||||
String currentSet = availableSets[i].toLowerCase().split(" - ")[0];
|
||||
if(!currentSet.equalsIgnoreCase(set)){
|
||||
if (!currentSet.equalsIgnoreCase(set)) {
|
||||
try {
|
||||
doc = Jsoup.connect(imageurl + "t" + currentSet).get();
|
||||
outlinks = doc.select("body a");
|
||||
for (int k = 0; k < outlinks.size(); k++){
|
||||
for (int k = 0; k < outlinks.size(); k++) {
|
||||
String linktoken = outlinks.get(k).attributes().get("href");
|
||||
try {
|
||||
Document tokendoc = Jsoup.connect(linktoken).get();
|
||||
Elements stats = tokendoc.select("head meta");
|
||||
for (int j = 0; j < stats.size(); j++){
|
||||
for (int j = 0; j < stats.size(); j++) {
|
||||
String a = stats.get(j).attributes().get("content");
|
||||
if(stats.get(j).attributes().get("content").contains(tokenstats) && stats.get(j).attributes().get("content").toLowerCase().contains(name.toLowerCase())){
|
||||
if (stats.get(j).attributes().get("content").contains(tokenstats) && stats.get(j).attributes().get("content").toLowerCase().contains(name.toLowerCase())) {
|
||||
System.out.println("Token " + name + " has been found between " + currentSet.toUpperCase() + " tokens, i will use this one");
|
||||
return tokendoc;
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {}
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {}
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
System.err.println("Error: Token " + name + " has not been found between any set of " + imageurl);
|
||||
@@ -181,8 +190,8 @@ public class ImgDownloader {
|
||||
|
||||
public static String DownloadCardImages(String set, String[] availableSets, String targetres, String basePath, String destinationPath) throws IOException {
|
||||
String res = "";
|
||||
|
||||
String baseurl = "https://gatherer.wizards.com/Pages/Card/Details.aspx?multiverseid=";
|
||||
|
||||
String baseurl = "https://gatherer.wizards.com/Pages/Card/Details.aspx?multiverseid=";
|
||||
String imageurl = "https://scryfall.com/sets/";
|
||||
|
||||
Integer ImgX = 0;
|
||||
@@ -201,57 +210,57 @@ public class ImgDownloader {
|
||||
ThumbX = 45;
|
||||
ThumbY = 64;
|
||||
}
|
||||
|
||||
|
||||
File baseFolder = new File(basePath);
|
||||
File[] listOfFiles = baseFolder.listFiles();
|
||||
String currentSet = "";
|
||||
String currentSet = "";
|
||||
for (int f = 1; f < availableSets.length; f++) {
|
||||
if(set.equalsIgnoreCase("*.*"))
|
||||
currentSet = availableSets[f];
|
||||
else
|
||||
currentSet = set;
|
||||
Map<String, String> mappa = new HashMap<String, String>();
|
||||
ZipFile zipFile = null;
|
||||
InputStream stream = null;
|
||||
java.nio.file.Path filePath = null;
|
||||
try {
|
||||
if (set.equalsIgnoreCase("*.*"))
|
||||
currentSet = availableSets[f];
|
||||
else
|
||||
currentSet = set;
|
||||
Map<String, String> mappa = new HashMap<String, String>();
|
||||
ZipFile zipFile = null;
|
||||
InputStream stream = null;
|
||||
java.nio.file.Path filePath = null;
|
||||
try {
|
||||
zipFile = new ZipFile(basePath + "/" + listOfFiles[0].getName());
|
||||
Enumeration<? extends ZipEntry> e = zipFile.entries();
|
||||
while (e.hasMoreElements()) {
|
||||
ZipEntry entry = e.nextElement();
|
||||
String entryName = entry.getName();
|
||||
if(entryName.contains("sets/")){
|
||||
if(entryName.contains("_cards.dat")){
|
||||
String[] names = entryName.split("/");
|
||||
if(currentSet.equalsIgnoreCase(names[1])){
|
||||
stream = zipFile.getInputStream(entry);
|
||||
byte[] buffer = new byte[1];
|
||||
java.nio.file.Path outDir = Paths.get(basePath);
|
||||
filePath = outDir.resolve("_cards.dat");
|
||||
if (entryName.contains("sets/")) {
|
||||
if (entryName.contains("_cards.dat")) {
|
||||
String[] names = entryName.split("/");
|
||||
if (currentSet.equalsIgnoreCase(names[1])) {
|
||||
stream = zipFile.getInputStream(entry);
|
||||
byte[] buffer = new byte[1];
|
||||
java.nio.file.Path outDir = Paths.get(basePath);
|
||||
filePath = outDir.resolve("_cards.dat");
|
||||
try {
|
||||
FileOutputStream fos = new FileOutputStream(filePath.toFile());
|
||||
BufferedOutputStream bos = new BufferedOutputStream(fos, buffer.length);
|
||||
int len;
|
||||
while ((len = stream.read(buffer)) != -1) {
|
||||
bos.write(buffer, 0, len);
|
||||
}
|
||||
fos.close();
|
||||
bos.close();
|
||||
} catch (Exception ex) {
|
||||
System.out.println("Error extracting zip file" + ex);
|
||||
}
|
||||
if(!set.equalsIgnoreCase("*.*"))
|
||||
f = availableSets.length;
|
||||
break;
|
||||
}
|
||||
FileOutputStream fos = new FileOutputStream(filePath.toFile());
|
||||
BufferedOutputStream bos = new BufferedOutputStream(fos, buffer.length);
|
||||
int len;
|
||||
while ((len = stream.read(buffer)) != -1) {
|
||||
bos.write(buffer, 0, len);
|
||||
}
|
||||
fos.close();
|
||||
bos.close();
|
||||
} catch (Exception ex) {
|
||||
System.out.println("Error extracting zip file" + ex);
|
||||
}
|
||||
if (!set.equalsIgnoreCase("*.*"))
|
||||
f = availableSets.length;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (IOException ioe){
|
||||
}
|
||||
}
|
||||
} catch (IOException ioe) {
|
||||
System.out.println("Error opening zip file" + ioe);
|
||||
} finally {
|
||||
try {
|
||||
if (zipFile!=null) {
|
||||
if (zipFile != null) {
|
||||
zipFile.close();
|
||||
}
|
||||
} catch (IOException ioe) {
|
||||
@@ -260,27 +269,27 @@ public class ImgDownloader {
|
||||
}
|
||||
|
||||
String lines = readLineByLineJava8(filePath.toString());
|
||||
File del = new File(filePath.toString());
|
||||
del.delete();
|
||||
int totalcards = 0;
|
||||
File del = new File(filePath.toString());
|
||||
del.delete();
|
||||
int totalcards = 0;
|
||||
String findStr = "total=";
|
||||
int lastIndex = lines.indexOf(findStr);
|
||||
String totals = lines.substring(lastIndex, lines.indexOf("\n", lastIndex));
|
||||
totalcards = Integer.parseInt(totals.split("=")[1]);
|
||||
for (int i = 0; i < totalcards; i++) {
|
||||
totalcards = Integer.parseInt(totals.split("=")[1]);
|
||||
while (lines.contains("[card]")) {
|
||||
findStr = "[card]";
|
||||
lastIndex = lines.indexOf(findStr);
|
||||
String id = null;
|
||||
String primitive = null;
|
||||
int a = lines.indexOf("primitive=",lastIndex);
|
||||
if(a > 0)
|
||||
primitive = lines.substring(a, lines.indexOf("\n",a)).replace("//", "-").split("=")[1];
|
||||
int b = lines.indexOf("id=",lastIndex);
|
||||
if(b > 0)
|
||||
id = lines.substring(b, lines.indexOf("\n",b)).replace("-", "").split("=")[1];
|
||||
int c = lines.indexOf("[/card]",lastIndex);
|
||||
if(c > 0)
|
||||
lines = lines.substring(c + 8);
|
||||
lastIndex = lines.indexOf(findStr);
|
||||
String id = null;
|
||||
String primitive = null;
|
||||
int a = lines.indexOf("primitive=", lastIndex);
|
||||
if (a > 0)
|
||||
primitive = lines.substring(a, lines.indexOf("\n", a)).replace("//", "-").split("=")[1];
|
||||
int b = lines.indexOf("id=", lastIndex);
|
||||
if (b > 0)
|
||||
id = lines.substring(b, lines.indexOf("\n", b)).replace("-", "").split("=")[1];
|
||||
int c = lines.indexOf("[/card]", lastIndex);
|
||||
if (c > 0)
|
||||
lines = lines.substring(c + 8);
|
||||
if (primitive != null && id != null && !id.equalsIgnoreCase("null"))
|
||||
mappa.put(id, primitive);
|
||||
}
|
||||
@@ -321,57 +330,57 @@ public class ImgDownloader {
|
||||
String id = mappa.keySet().toArray()[y].toString();
|
||||
Document doc = Jsoup.connect(baseurl + id).get();
|
||||
Elements divs = doc.select("body div");
|
||||
String scryset = currentSet;
|
||||
if(scryset.equalsIgnoreCase("MRQ"))
|
||||
String scryset = currentSet;
|
||||
if (scryset.equalsIgnoreCase("MRQ"))
|
||||
scryset = "MMQ";
|
||||
else if(scryset.equalsIgnoreCase("AVN"))
|
||||
else if (scryset.equalsIgnoreCase("AVN"))
|
||||
scryset = "DDH";
|
||||
else if(scryset.equalsIgnoreCase("BVC"))
|
||||
else if (scryset.equalsIgnoreCase("BVC"))
|
||||
scryset = "DDQ";
|
||||
else if(scryset.equalsIgnoreCase("CFX"))
|
||||
else if (scryset.equalsIgnoreCase("CFX"))
|
||||
scryset = "CON";
|
||||
else if(scryset.equalsIgnoreCase("DM"))
|
||||
else if (scryset.equalsIgnoreCase("DM"))
|
||||
scryset = "DKM";
|
||||
else if(scryset.equalsIgnoreCase("EVK"))
|
||||
else if (scryset.equalsIgnoreCase("EVK"))
|
||||
scryset = "DDO";
|
||||
else if(scryset.equalsIgnoreCase("EVT"))
|
||||
else if (scryset.equalsIgnoreCase("EVT"))
|
||||
scryset = "DDF";
|
||||
else if(scryset.equalsIgnoreCase("FVD"))
|
||||
else if (scryset.equalsIgnoreCase("FVD"))
|
||||
scryset = "DRB";
|
||||
else if(scryset.equalsIgnoreCase("FVE"))
|
||||
else if (scryset.equalsIgnoreCase("FVE"))
|
||||
scryset = "V09";
|
||||
else if(scryset.equalsIgnoreCase("FVL"))
|
||||
else if (scryset.equalsIgnoreCase("FVL"))
|
||||
scryset = "V11";
|
||||
else if(scryset.equalsIgnoreCase("FVR"))
|
||||
else if (scryset.equalsIgnoreCase("FVR"))
|
||||
scryset = "V10";
|
||||
else if(scryset.equalsIgnoreCase("HVM"))
|
||||
else if (scryset.equalsIgnoreCase("HVM"))
|
||||
scryset = "DDL";
|
||||
else if(scryset.equalsIgnoreCase("IVG"))
|
||||
else if (scryset.equalsIgnoreCase("IVG"))
|
||||
scryset = "DDJ";
|
||||
else if(scryset.equalsIgnoreCase("JVV"))
|
||||
else if (scryset.equalsIgnoreCase("JVV"))
|
||||
scryset = "DDM";
|
||||
else if(scryset.equalsIgnoreCase("KVD"))
|
||||
else if (scryset.equalsIgnoreCase("KVD"))
|
||||
scryset = "DDG";
|
||||
else if(scryset.equalsIgnoreCase("PDS"))
|
||||
else if (scryset.equalsIgnoreCase("PDS"))
|
||||
scryset = "H09";
|
||||
else if(scryset.equalsIgnoreCase("PVC"))
|
||||
else if (scryset.equalsIgnoreCase("PVC"))
|
||||
scryset = "DDE";
|
||||
else if(scryset.equalsIgnoreCase("RV"))
|
||||
else if (scryset.equalsIgnoreCase("RV"))
|
||||
scryset = "3ED";
|
||||
else if(scryset.equalsIgnoreCase("SVT"))
|
||||
else if (scryset.equalsIgnoreCase("SVT"))
|
||||
scryset = "DDK";
|
||||
else if(scryset.equalsIgnoreCase("VVK"))
|
||||
else if (scryset.equalsIgnoreCase("VVK"))
|
||||
scryset = "DDI";
|
||||
else if(scryset.equalsIgnoreCase("ZVE"))
|
||||
else if (scryset.equalsIgnoreCase("ZVE"))
|
||||
scryset = "DDP";
|
||||
try {
|
||||
try {
|
||||
doc = Jsoup.connect(imageurl + scryset.toLowerCase()).get();
|
||||
} catch (Exception e) {
|
||||
System.err.println("Problem downloading card: " + mappa.get(id) + " (" + id + ") from " + scryset + " on ScryFall");
|
||||
res = mappa.get(id) + "-" + currentSet + "/" + id + ".jpg\n" + res;
|
||||
res = mappa.get(id) + "-" + currentSet + "/" + id + ".jpg\n" + res;
|
||||
continue;
|
||||
}
|
||||
try {
|
||||
try {
|
||||
doc = Jsoup.connect(imageurl + scryset.toLowerCase()).get();
|
||||
} catch (Exception e) {
|
||||
System.err.println("Error: Problem downloading card: " + mappa.get(id) + "-" + id + " from " + scryset + " on ScryFall, i will retry 2 times more...");
|
||||
@@ -383,7 +392,7 @@ public class ImgDownloader {
|
||||
doc = Jsoup.connect(imageurl + scryset.toLowerCase()).get();
|
||||
} catch (Exception e3) {
|
||||
System.err.println("Error: Problem downloading card: " + mappa.get(id) + "-" + id + " from " + scryset + " on ScryFall, i will not retry anymore...");
|
||||
res = mappa.get(id) + " - " + currentSet + "/" + id + ".jpg\n" + res;
|
||||
res = mappa.get(id) + " - " + currentSet + "/" + id + ".jpg\n" + res;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
@@ -420,17 +429,17 @@ public class ImgDownloader {
|
||||
fos.write(response);
|
||||
fos.close();
|
||||
|
||||
Bitmap yourBitmap = BitmapFactory.decodeFile(cardimage);
|
||||
Bitmap resized = Bitmap.createScaledBitmap(yourBitmap, ImgX, ImgY, true);
|
||||
Bitmap yourBitmap = BitmapFactory.decodeFile(cardimage);
|
||||
Bitmap resized = Bitmap.createScaledBitmap(yourBitmap, ImgX, ImgY, true);
|
||||
try {
|
||||
FileOutputStream fout = new FileOutputStream(cardimage);
|
||||
resized.compress(Bitmap.CompressFormat.JPEG, 100, fout);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
Bitmap resizedThumb = Bitmap.createScaledBitmap(yourBitmap, ThumbX, ThumbY, true);
|
||||
FileOutputStream fout = new FileOutputStream(cardimage);
|
||||
resized.compress(Bitmap.CompressFormat.JPEG, 100, fout);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
Bitmap resizedThumb = Bitmap.createScaledBitmap(yourBitmap, ThumbX, ThumbY, true);
|
||||
try {
|
||||
FileOutputStream fout = new FileOutputStream(thumbcardimage);
|
||||
FileOutputStream fout = new FileOutputStream(thumbcardimage);
|
||||
resizedThumb.compress(Bitmap.CompressFormat.JPEG, 100, fout);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
@@ -494,28 +503,28 @@ public class ImgDownloader {
|
||||
String nametoken = "";
|
||||
String nametocheck = "";
|
||||
String tokenstats = "";
|
||||
for (int l = 1; l < arrays.length - 1; l++) {
|
||||
if (arrays[l].equalsIgnoreCase("creature") && arrays[l + 1].toLowerCase().contains("token")) {
|
||||
nametoken = arrays[l - 1];
|
||||
if(l - 3 > 0)
|
||||
tokenstats = arrays[l - 3];
|
||||
if(nametoken.equalsIgnoreCase("artifact")){
|
||||
if(l - 2 > 0)
|
||||
nametoken = arrays[l - 2];
|
||||
if(l - 4 > 0)
|
||||
tokenstats = arrays[l - 4];
|
||||
}
|
||||
break;
|
||||
} else if (arrays[l].equalsIgnoreCase("put") && arrays[l + 3].toLowerCase().contains("token")) {
|
||||
nametoken = arrays[l + 2];
|
||||
for (int j = 1; j < arrays.length - 1; j++) {
|
||||
if (arrays[j].contains("/"))
|
||||
tokenstats = arrays[j];
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (nametoken.isEmpty() || tokenstats.isEmpty()) {
|
||||
for (int l = 1; l < arrays.length - 1; l++) {
|
||||
if (arrays[l].equalsIgnoreCase("creature") && arrays[l + 1].toLowerCase().contains("token")) {
|
||||
nametoken = arrays[l - 1];
|
||||
if (l - 3 > 0)
|
||||
tokenstats = arrays[l - 3];
|
||||
if (nametoken.equalsIgnoreCase("artifact")) {
|
||||
if (l - 2 > 0)
|
||||
nametoken = arrays[l - 2];
|
||||
if (l - 4 > 0)
|
||||
tokenstats = arrays[l - 4];
|
||||
}
|
||||
break;
|
||||
} else if (arrays[l].equalsIgnoreCase("put") && arrays[l + 3].toLowerCase().contains("token")) {
|
||||
nametoken = arrays[l + 2];
|
||||
for (int j = 1; j < arrays.length - 1; j++) {
|
||||
if (arrays[j].contains("/"))
|
||||
tokenstats = arrays[j];
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (nametoken.isEmpty() || tokenstats.isEmpty()) {
|
||||
tokenfound = false;
|
||||
nametoken = "Unknown";
|
||||
nametocheck = mappa.get(id);
|
||||
@@ -525,7 +534,7 @@ public class ImgDownloader {
|
||||
doc = findTokenPage(imageurl, nametoken, scryset, availableSets, tokenstats);
|
||||
tokenfound = true;
|
||||
nametocheck = nametoken;
|
||||
} catch(Exception e) {
|
||||
} catch (Exception e) {
|
||||
tokenfound = false;
|
||||
nametocheck = mappa.get(id);
|
||||
doc = Jsoup.connect(imageurl + scryset.toLowerCase()).get();
|
||||
@@ -557,28 +566,28 @@ public class ImgDownloader {
|
||||
} else {
|
||||
tokenimage = imgPath + "/" + id + "t.jpg";
|
||||
tokenthumbimage = thumbPath + "/" + id + "t.jpg";
|
||||
System.err.println("Error: Problem downloading token: " + nametoken + " (" + id + "t) i will use the same image of its source card");
|
||||
res = nametoken + " - " + currentSet + "/" + id + "t.jpg\n" + res;
|
||||
System.err.println("Error: Problem downloading token: " + nametoken + " (" + id + "t) i will use the same image of its source card");
|
||||
res = nametoken + " - " + currentSet + "/" + id + "t.jpg\n" + res;
|
||||
}
|
||||
FileOutputStream fos2 = new FileOutputStream(tokenimage);
|
||||
fos2.write(responsetoken);
|
||||
fos2.close();
|
||||
|
||||
Bitmap yourBitmapToken = BitmapFactory.decodeFile(tokenimage);
|
||||
|
||||
Bitmap yourBitmapToken = BitmapFactory.decodeFile(tokenimage);
|
||||
Bitmap resizedToken = Bitmap.createScaledBitmap(yourBitmapToken, ImgX, ImgY, true);
|
||||
try {
|
||||
FileOutputStream fout = new FileOutputStream(tokenimage);
|
||||
try {
|
||||
FileOutputStream fout = new FileOutputStream(tokenimage);
|
||||
resizedToken.compress(Bitmap.CompressFormat.JPEG, 100, fout);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
Bitmap resizedThumbToken = Bitmap.createScaledBitmap(yourBitmapToken, ThumbX, ThumbY, true);
|
||||
try {
|
||||
FileOutputStream fout = new FileOutputStream(tokenthumbimage);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
Bitmap resizedThumbToken = Bitmap.createScaledBitmap(yourBitmapToken, ThumbX, ThumbY, true);
|
||||
try {
|
||||
FileOutputStream fout = new FileOutputStream(tokenthumbimage);
|
||||
resizedThumbToken.compress(Bitmap.CompressFormat.JPEG, 100, fout);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
@@ -589,39 +598,40 @@ public class ImgDownloader {
|
||||
}
|
||||
}
|
||||
}
|
||||
try {
|
||||
try {
|
||||
File oldzip = new File(destinationPath + "/" + set + "/" + set + ".zip");
|
||||
oldzip.delete();
|
||||
} catch (Exception e) {}
|
||||
ZipParameters zipParameters = new ZipParameters();
|
||||
zipParameters.setCompressionMethod(CompressionMethod.STORE);
|
||||
File folder = new File(destinationPath + set + "/");
|
||||
File[] listOfFile = folder.listFiles();
|
||||
net.lingala.zip4j.ZipFile zipped = new net.lingala.zip4j.ZipFile(destinationPath + "/" + set + "/" + set + ".zip");
|
||||
for (int i = 0 ; i < listOfFile.length; i++){
|
||||
if(listOfFile[i].isDirectory()){
|
||||
zipped.addFolder(listOfFile[i],zipParameters);
|
||||
} else {
|
||||
zipped.addFile(listOfFile[i], zipParameters);
|
||||
}
|
||||
}
|
||||
File destFolder = new File(destinationPath + set + "/");
|
||||
try {
|
||||
try {
|
||||
File oldzip = new File(destinationPath + "/" + set + "/" + set + ".zip");
|
||||
oldzip.delete();
|
||||
} catch (Exception e) {
|
||||
}
|
||||
ZipParameters zipParameters = new ZipParameters();
|
||||
zipParameters.setCompressionMethod(CompressionMethod.STORE);
|
||||
File folder = new File(destinationPath + set + "/");
|
||||
File[] listOfFile = folder.listFiles();
|
||||
net.lingala.zip4j.ZipFile zipped = new net.lingala.zip4j.ZipFile(destinationPath + "/" + set + "/" + set + ".zip");
|
||||
for (int i = 0; i < listOfFile.length; i++) {
|
||||
if (listOfFile[i].isDirectory()) {
|
||||
zipped.addFolder(listOfFile[i], zipParameters);
|
||||
} else {
|
||||
zipped.addFile(listOfFile[i], zipParameters);
|
||||
}
|
||||
}
|
||||
File destFolder = new File(destinationPath + set + "/");
|
||||
listOfFiles = destFolder.listFiles();
|
||||
for(int u = 0; u < listOfFiles.length; u++){
|
||||
if (!listOfFiles[u].getName().contains(".zip")){
|
||||
if(listOfFiles[u].isDirectory()){
|
||||
for (int u = 0; u < listOfFiles.length; u++) {
|
||||
if (!listOfFiles[u].getName().contains(".zip")) {
|
||||
if (listOfFiles[u].isDirectory()) {
|
||||
File[] listOfSubFiles = listOfFiles[u].listFiles();
|
||||
for(int j = 0; j < listOfSubFiles.length; j++)
|
||||
for (int j = 0; j < listOfSubFiles.length; j++)
|
||||
listOfSubFiles[j].delete();
|
||||
}
|
||||
listOfFiles[u].delete();
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return res;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user