mirror of
https://github.com/fabianonline/telegram_backup.git
synced 2024-11-22 16:56:16 +00:00
Some improvements in the output.
This commit is contained in:
parent
7bf22f4692
commit
b8d9e2a1b6
@ -1,16 +1,16 @@
|
|||||||
/* Telegram_Backup
|
/* Telegram_Backup
|
||||||
* Copyright (C) 2016 Fabian Schlenz
|
* Copyright (C) 2016 Fabian Schlenz
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU General Public License as published by
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
* (at your option) any later version.
|
* (at your option) any later version.
|
||||||
*
|
*
|
||||||
* This program is distributed in the hope that it will be useful,
|
* This program is distributed in the hope that it will be useful,
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
* GNU General Public License for more details.
|
* GNU General Public License for more details.
|
||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||||
|
|
||||||
@ -22,11 +22,18 @@ import de.fabianonline.telegram_backup.mediafilemanager.AbstractMediaFileManager
|
|||||||
class CommandLineDownloadProgress implements DownloadProgressInterface {
|
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."); }
|
||||||
|
|
||||||
public void onMediaDownloadStart(int count) {
|
public void onMediaDownloadStart(int count) {
|
||||||
i = 0;
|
i = 0;
|
||||||
mediaCount = count;
|
mediaCount = count;
|
||||||
@ -37,22 +44,21 @@ class CommandLineDownloadProgress implements DownloadProgressInterface {
|
|||||||
System.out.println("'.' - Previously downloaded file 'e' - Empty file");
|
System.out.println("'.' - Previously downloaded file 'e' - Empty file");
|
||||||
System.out.println("' ' - Ignored media type (weblinks or contacts, for example)");
|
System.out.println("' ' - Ignored media type (weblinks or contacts, for example)");
|
||||||
System.out.println("'x' - File skipped because of timeout errors");
|
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) {
|
public void onMediaDownloaded(AbstractMediaFileManager fm) {
|
||||||
show(fm.getLetter().toUpperCase());
|
show(fm.getLetter().toUpperCase());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onMediaDownloadedEmpty() { show("e"); }
|
public void onMediaDownloadedEmpty() { show("e"); }
|
||||||
public void onMediaAlreadyPresent(AbstractMediaFileManager fm) {
|
public void onMediaAlreadyPresent(AbstractMediaFileManager fm) {
|
||||||
show(".");
|
show(".");
|
||||||
}
|
}
|
||||||
public void onMediaSkipped() { show("x"); }
|
public void onMediaSkipped() { show("x"); }
|
||||||
|
|
||||||
public void onMediaDownloadFinished() { showNewLine(); System.out.println("Done."); }
|
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 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); }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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.");
|
||||||
}
|
}
|
||||||
|
String channel_name = channel_names.get(channel_id);
|
||||||
|
if (channel_name == null) {
|
||||||
|
channel_name = "?";
|
||||||
|
}
|
||||||
TLInputChannel channel = new TLInputChannel(channel_id, access_hash);
|
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<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();
|
||||||
|
@ -1,16 +1,16 @@
|
|||||||
/* Telegram_Backup
|
/* Telegram_Backup
|
||||||
* Copyright (C) 2016 Fabian Schlenz
|
* Copyright (C) 2016 Fabian Schlenz
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU General Public License as published by
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
* (at your option) any later version.
|
* (at your option) any later version.
|
||||||
*
|
*
|
||||||
* This program is distributed in the hope that it will be useful,
|
* This program is distributed in the hope that it will be useful,
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
* GNU General Public License for more details.
|
* GNU General Public License for more details.
|
||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||||
|
|
||||||
@ -19,10 +19,10 @@ 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();
|
||||||
|
|
||||||
public void onMediaDownloadStart(int count);
|
public void onMediaDownloadStart(int count);
|
||||||
public void onMediaDownloaded(AbstractMediaFileManager a);
|
public void onMediaDownloaded(AbstractMediaFileManager a);
|
||||||
public void onMediaDownloadedEmpty();
|
public void onMediaDownloadedEmpty();
|
||||||
|
Loading…
Reference in New Issue
Block a user