1
0
mirror of https://github.com/fabianonline/telegram_backup.git synced 2024-11-23 01:06:17 +00:00

Some improvements in the output.

This commit is contained in:
Fabian Schlenz 2017-12-01 14:13:58 +01:00
parent 7bf22f4692
commit b8d9e2a1b6
3 changed files with 37 additions and 28 deletions

View File

@ -23,7 +23,14 @@ class CommandLineDownloadProgress implements DownloadProgressInterface {
private int mediaCount = 0; private int mediaCount = 0;
private int i = 0; private int i = 0;
public void onMessageDownloadStart(int count) { i=0; System.out.println("Downloading " + count + " messages."); } public void onMessageDownloadStart(int count, String source) {
i=0;
if (source==null) {
System.out.println("Downloading " + count + " messages.");
} else {
System.out.println("Downloading " + count + " messages from " + Utils.anonymize(source));
}
}
public void onMessageDownloaded(int number) { i+=number; System.out.print("..." + i); } public void onMessageDownloaded(int number) { i+=number; System.out.print("..." + i); }
public void onMessageDownloadFinished() { System.out.println(" done."); } public void onMessageDownloadFinished() { System.out.println(" done."); }
@ -55,4 +62,3 @@ class CommandLineDownloadProgress implements DownloadProgressInterface {
private void show(String letter) { System.out.print(letter); i++; if (i % 100 == 0) showNewLine();} private void show(String letter) { System.out.print(letter); i++; if (i % 100 == 0) showNewLine();}
private void showNewLine() { System.out.println(" - " + i + "/" + mediaCount); } private void showNewLine() { System.out.println(" - " + i + "/" + mediaCount); }
} }

View File

@ -35,6 +35,7 @@ import com.github.badoualy.telegram.tl.exception.RpcErrorException;
import com.github.badoualy.telegram.tl.api.request.TLRequestUploadGetFile; import com.github.badoualy.telegram.tl.api.request.TLRequestUploadGetFile;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.slf4j.Logger; import org.slf4j.Logger;
import com.google.gson.Gson;
import java.io.IOException; import java.io.IOException;
import java.io.File; import java.io.File;
@ -60,7 +61,7 @@ public class DownloadManager {
static TelegramClient download_client; static TelegramClient download_client;
static boolean last_download_succeeded = true; static boolean last_download_succeeded = true;
static final Logger logger = LoggerFactory.getLogger(DownloadManager.class); static final Logger logger = LoggerFactory.getLogger(DownloadManager.class);
static public enum DownloadType { NORMAL, CHANNELS_AND_SUPERGROUPS } boolean has_seen_flood_wait_message = false;
public DownloadManager(TelegramClient c, DownloadProgressInterface p) { public DownloadManager(TelegramClient c, DownloadProgressInterface p) {
this.user = UserManager.getInstance(); this.user = UserManager.getInstance();
@ -136,7 +137,7 @@ public class DownloadManager {
int end_id = max_message_id; int end_id = max_message_id;
List<Integer> ids = makeIdList(start_id, end_id); List<Integer> ids = makeIdList(start_id, end_id);
downloadMessages(ids, null); downloadMessages(ids, null, null);
} }
logger.info("Searching for missing messages in the db"); logger.info("Searching for missing messages in the db");
@ -169,18 +170,19 @@ public class DownloadManager {
*/ */
if (CommandLineOptions.cmd_channels_and_supergroups) { if (CommandLineOptions.cmd_channels_and_supergroups) {
logger.info("Processing channels and supergroups..."); System.out.println("Processing channels and supergroups...");
HashMap<Integer, Long> channel_access_hashes = new HashMap<Integer, Long>(); HashMap<Integer, Long> channel_access_hashes = new HashMap<Integer, Long>();
HashMap<Integer, String> channel_names = new HashMap<Integer, String>();
// TODO Add chat title (and other stuff?) to the database // TODO Add chat title (and other stuff?) to the database
for (TLAbsChat c : dialogs.getChats()) { for (TLAbsChat c : dialogs.getChats()) {
if (c instanceof TLChannel) { if (c instanceof TLChannel) {
TLChannel ch = (TLChannel)c; TLChannel ch = (TLChannel)c;
channel_access_hashes.put(c.getId(), ch.getAccessHash()); channel_access_hashes.put(c.getId(), ch.getAccessHash());
channel_names.put(c.getId(), ch.getTitle());
// Channel: TLChannel // Channel: TLChannel
// Supergroup: getMegagroup()==true // Supergroup: getMegagroup()==true
System.out.println("" + c.getId() + " - " + (ch.getMegagroup() ? "Supergroup" : "Channel") +": " + ch.getTitle());
} }
} }
@ -192,23 +194,24 @@ public class DownloadManager {
int max_known_id = db.getTopMessageIDForChannel(channel_id); int max_known_id = db.getTopMessageIDForChannel(channel_id);
if (d.getTopMessage() > max_known_id) { if (d.getTopMessage() > max_known_id) {
List<Integer> ids = makeIdList(max_known_id+1, d.getTopMessage()); List<Integer> ids = makeIdList(max_known_id+1, d.getTopMessage());
//messagesPerChannel.put(id, makeIdList(max_known_id+1, d.getTopMessage()));
Long access_hash = channel_access_hashes.get(channel_id); Long access_hash = channel_access_hashes.get(channel_id);
if (access_hash==null) { if (access_hash==null) {
throw new RuntimeException("AccessHash for Channel missing."); throw new RuntimeException("AccessHash for Channel missing.");
} }
TLInputChannel channel = new TLInputChannel(channel_id, access_hash); String channel_name = channel_names.get(channel_id);
downloadMessages(ids, channel); if (channel_name == null) {
channel_name = "?";
}
TLInputChannel channel = new TLInputChannel(channel_id, access_hash);
downloadMessages(ids, channel, "channel " + channel_name);
} }
System.out.println("" + channel_id + " - Known: " + max_known_id + " Availalble: " + d.getTopMessage());
} }
} }
} }
} }
private void downloadMessages(List<Integer> ids, TLInputChannel channel) throws RpcErrorException, IOException { private void downloadMessages(List<Integer> ids, TLInputChannel channel, String source_string) throws RpcErrorException, IOException {
prog.onMessageDownloadStart(ids.size()); prog.onMessageDownloadStart(ids.size(), source_string);
boolean has_seen_flood_wait_message = false;
logger.debug("Entering download loop"); logger.debug("Entering download loop");
while (ids.size()>0) { while (ids.size()>0) {
@ -299,7 +302,7 @@ public class DownloadManager {
if (ids.size()>0) { if (ids.size()>0) {
System.out.println("You have " + ids.size() + " messages in your db that need an update. Doing that now."); System.out.println("You have " + ids.size() + " messages in your db that need an update. Doing that now.");
logger.debug("Found {} messages", ids.size()); logger.debug("Found {} messages", ids.size());
downloadMessages(ids, null); downloadMessages(ids, null, null);
} }
LinkedList<TLMessage> messages = this.db.getMessagesWithMedia(); LinkedList<TLMessage> messages = this.db.getMessagesWithMedia();

View File

@ -19,7 +19,7 @@ package de.fabianonline.telegram_backup;
import de.fabianonline.telegram_backup.mediafilemanager.AbstractMediaFileManager; import de.fabianonline.telegram_backup.mediafilemanager.AbstractMediaFileManager;
public interface DownloadProgressInterface { public interface DownloadProgressInterface {
public void onMessageDownloadStart(int count); public void onMessageDownloadStart(int count, String source);
public void onMessageDownloaded(int number); public void onMessageDownloaded(int number);
public void onMessageDownloadFinished(); public void onMessageDownloadFinished();