diff --git a/src/main/java/de/fabianonline/telegram_backup/CommandLineDownloadProgress.java b/src/main/java/de/fabianonline/telegram_backup/CommandLineDownloadProgress.java
index d56a4c8..1e1c138 100644
--- a/src/main/java/de/fabianonline/telegram_backup/CommandLineDownloadProgress.java
+++ b/src/main/java/de/fabianonline/telegram_backup/CommandLineDownloadProgress.java
@@ -1,16 +1,16 @@
/* Telegram_Backup
* Copyright (C) 2016 Fabian Schlenz
- *
+ *
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
- *
+ *
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with this program. If not, see . */
@@ -22,11 +22,18 @@ import de.fabianonline.telegram_backup.mediafilemanager.AbstractMediaFileManager
class CommandLineDownloadProgress implements DownloadProgressInterface {
private int mediaCount = 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 onMessageDownloadFinished() { System.out.println(" done."); }
-
+
public void onMediaDownloadStart(int count) {
i = 0;
mediaCount = count;
@@ -37,22 +44,21 @@ class CommandLineDownloadProgress implements DownloadProgressInterface {
System.out.println("'.' - Previously downloaded file 'e' - Empty file");
System.out.println("' ' - Ignored media type (weblinks or contacts, for example)");
System.out.println("'x' - File skipped because of timeout errors");
- System.out.println("" + count + " Files to check / download");
+ System.out.println("" + count + " Files to check / download");
}
-
+
public void onMediaDownloaded(AbstractMediaFileManager fm) {
show(fm.getLetter().toUpperCase());
}
-
+
public void onMediaDownloadedEmpty() { show("e"); }
public void onMediaAlreadyPresent(AbstractMediaFileManager fm) {
show(".");
}
public void onMediaSkipped() { show("x"); }
-
+
public void onMediaDownloadFinished() { showNewLine(); System.out.println("Done."); }
-
+
private void show(String letter) { System.out.print(letter); i++; if (i % 100 == 0) showNewLine();}
private void showNewLine() { System.out.println(" - " + i + "/" + mediaCount); }
}
-
diff --git a/src/main/java/de/fabianonline/telegram_backup/DownloadManager.java b/src/main/java/de/fabianonline/telegram_backup/DownloadManager.java
index 948f904..c433418 100644
--- a/src/main/java/de/fabianonline/telegram_backup/DownloadManager.java
+++ b/src/main/java/de/fabianonline/telegram_backup/DownloadManager.java
@@ -35,6 +35,7 @@ import com.github.badoualy.telegram.tl.exception.RpcErrorException;
import com.github.badoualy.telegram.tl.api.request.TLRequestUploadGetFile;
import org.slf4j.LoggerFactory;
import org.slf4j.Logger;
+import com.google.gson.Gson;
import java.io.IOException;
import java.io.File;
@@ -60,7 +61,7 @@ public class DownloadManager {
static TelegramClient download_client;
static boolean last_download_succeeded = true;
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) {
this.user = UserManager.getInstance();
@@ -136,7 +137,7 @@ public class DownloadManager {
int end_id = max_message_id;
List ids = makeIdList(start_id, end_id);
- downloadMessages(ids, null);
+ downloadMessages(ids, null, null);
}
logger.info("Searching for missing messages in the db");
@@ -169,18 +170,19 @@ public class DownloadManager {
*/
if (CommandLineOptions.cmd_channels_and_supergroups) {
- logger.info("Processing channels and supergroups...");
+ System.out.println("Processing channels and supergroups...");
HashMap channel_access_hashes = new HashMap();
+ HashMap channel_names = new HashMap();
// TODO Add chat title (and other stuff?) to the database
for (TLAbsChat c : dialogs.getChats()) {
if (c instanceof TLChannel) {
TLChannel ch = (TLChannel)c;
channel_access_hashes.put(c.getId(), ch.getAccessHash());
+ channel_names.put(c.getId(), ch.getTitle());
// Channel: TLChannel
// 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);
if (d.getTopMessage() > max_known_id) {
List 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);
if (access_hash==null) {
throw new RuntimeException("AccessHash for Channel missing.");
}
+ String channel_name = channel_names.get(channel_id);
+ if (channel_name == null) {
+ channel_name = "?";
+ }
TLInputChannel channel = new TLInputChannel(channel_id, access_hash);
- downloadMessages(ids, channel);
+ downloadMessages(ids, channel, "channel " + channel_name);
}
- System.out.println("" + channel_id + " - Known: " + max_known_id + " Availalble: " + d.getTopMessage());
}
}
}
}
- private void downloadMessages(List ids, TLInputChannel channel) throws RpcErrorException, IOException {
- prog.onMessageDownloadStart(ids.size());
- boolean has_seen_flood_wait_message = false;
+ private void downloadMessages(List ids, TLInputChannel channel, String source_string) throws RpcErrorException, IOException {
+ prog.onMessageDownloadStart(ids.size(), source_string);
logger.debug("Entering download loop");
while (ids.size()>0) {
@@ -299,7 +302,7 @@ public class DownloadManager {
if (ids.size()>0) {
System.out.println("You have " + ids.size() + " messages in your db that need an update. Doing that now.");
logger.debug("Found {} messages", ids.size());
- downloadMessages(ids, null);
+ downloadMessages(ids, null, null);
}
LinkedList messages = this.db.getMessagesWithMedia();
diff --git a/src/main/java/de/fabianonline/telegram_backup/DownloadProgressInterface.java b/src/main/java/de/fabianonline/telegram_backup/DownloadProgressInterface.java
index 6924e59..e760205 100644
--- a/src/main/java/de/fabianonline/telegram_backup/DownloadProgressInterface.java
+++ b/src/main/java/de/fabianonline/telegram_backup/DownloadProgressInterface.java
@@ -1,16 +1,16 @@
/* Telegram_Backup
* Copyright (C) 2016 Fabian Schlenz
- *
+ *
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
- *
+ *
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with this program. If not, see . */
@@ -19,10 +19,10 @@ package de.fabianonline.telegram_backup;
import de.fabianonline.telegram_backup.mediafilemanager.AbstractMediaFileManager;
public interface DownloadProgressInterface {
- public void onMessageDownloadStart(int count);
+ public void onMessageDownloadStart(int count, String source);
public void onMessageDownloaded(int number);
public void onMessageDownloadFinished();
-
+
public void onMediaDownloadStart(int count);
public void onMediaDownloaded(AbstractMediaFileManager a);
public void onMediaDownloadedEmpty();