Fix on Android downloader and code indent

This commit is contained in:
valfieri
2019-08-23 12:58:10 +02:00
parent 30622010df
commit 9dfd513ad3
2 changed files with 550 additions and 712 deletions

View File

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

File diff suppressed because it is too large Load Diff