private static void tryResUrls(Picture picture) { String hi_res = ""; String url = picture.media_url.toString(); for (String ending : Main.endings) { try { hi_res = url.replace(url.substring(url.lastIndexOf("_"), url.lastIndexOf(".")), ending); URL hi_url = new URL(hi_res); File hi_name = Helper.extractMediaFileNameFromURL(hi_url); if (hi_name.equals(picture.media_name)) { picture.hi_url = hi_url; picture.hi_name = hi_name; picture.downloaded_hi = true; break; } else { boolean success = Helper.downloadFileFromURLToFileInTemp(hi_url, hi_name); if (success) { picture.hi_url = hi_url; picture.hi_name = hi_name; picture.downloaded_hi = true; Helper.moveTempImageToStore(hi_name, new File(Main.blogdir, picture.md5_id)); break; } } } catch (MalformedURLException ex) { Main.error(String.format("Attempted hi res url %s is a malformed URL.", hi_res)); } } }
protected static void reset() { Helper.removeDirectoryIfItExists(Helper.temp); Helper.removeDirectoryIfItExists(blogdir); Main.post_post_hash.clear(); Main.pic_pic_hash.clear(); Main.pic_post_hash.clear(); Main.dup_post_list.clear(); }
public static void save() { Main.status("Saving databases."); File file = new File(blogdir, "picpic.db"); List<Object> objects = new ArrayList<>(); objects.add(Main.post_post_hash); Helper.saveObjectToFile(file, objects); Main.status("Done saving databases."); }
private static void handlePost(Post post) { Main.post_post_hash.put(post, post); for (Picture picture : post.pictures) { Helper.downloadFileFromURLToFileInTemp(picture.thumb_url, picture.thumb_name); picture.md5_id = Helper.createMD5FromFileInTemp(picture.thumb_name); Helper.moveTempImageToStore(picture.thumb_name, new File(Main.blogdir, picture.md5_id)); if (!Main.pic_pic_hash.containsKey(picture)) { Main.pic_pic_hash.put(picture, picture); Main.pic_post_hash.put(picture, post); Helper.downloadFileFromURLToFileInTemp(picture.media_url, picture.media_name); Helper.moveTempImageToStore(picture.media_name, new File(Main.blogdir, picture.md5_id)); } else { if (!post.equals(Main.pic_post_hash.get(picture))) { dup_post_list.put(post, Main.pic_post_hash.get(picture)); } } } }
public static void load() { Main.status("Loading databases."); File file = new File(blogdir, "picpic.db"); List<Object> objects = Helper.loadObjectFromFile(file); if (objects == null || objects.size() != 1) { Main.error("Unable to load database files so creating new database."); reset(); } else { Main.post_post_hash = (HashMap<Post, Post>) objects.get(0); Main.pic_pic_hash.clear(); Main.pic_post_hash.clear(); Main.dup_post_list.clear(); Main.setupPosts(); } Main.status("Done loading databases."); }