diff --git a/build.gradle b/build.gradle index f7fcd8b..005bb34 100644 --- a/build.gradle +++ b/build.gradle @@ -14,7 +14,7 @@ repositories { } dependencies { - compile 'com.github.badoualy:kotlogram:0.0.6' + compile 'com.github.badoualy:kotlogram:497e5dd62d9bcb341f584164b04b4b537ce9d295' compile 'org.xerial:sqlite-jdbc:3.8.11.2' compile 'com.github.spullara.mustache.java:compiler:0.8.18' } diff --git a/src/main/java/de/fabianonline/telegram_backup/ApiStorage.java b/src/main/java/de/fabianonline/telegram_backup/ApiStorage.java index 8e05701..e0c59ea 100644 --- a/src/main/java/de/fabianonline/telegram_backup/ApiStorage.java +++ b/src/main/java/de/fabianonline/telegram_backup/ApiStorage.java @@ -17,8 +17,9 @@ package de.fabianonline.telegram_backup; import com.github.badoualy.telegram.api.TelegramApiStorage; -import com.github.badoualy.telegram.mtproto.DataCenter; +import com.github.badoualy.telegram.mtproto.model.DataCenter; import com.github.badoualy.telegram.mtproto.auth.AuthKey; +import com.github.badoualy.telegram.mtproto.model.MTSession; import org.apache.commons.io.FileUtils; @@ -132,7 +133,8 @@ class ApiStorage implements TelegramApiStorage { } } - public void saveServerSalt(long salt) {} + public void saveSession(MTSession session) { + } - public Long loadServerSalt() { return null; } + public MTSession loadSession() { return null; } } diff --git a/src/main/java/de/fabianonline/telegram_backup/CommandLineController.java b/src/main/java/de/fabianonline/telegram_backup/CommandLineController.java index 61c48f0..4e46842 100644 --- a/src/main/java/de/fabianonline/telegram_backup/CommandLineController.java +++ b/src/main/java/de/fabianonline/telegram_backup/CommandLineController.java @@ -65,8 +65,12 @@ public class CommandLineController { if (CommandLineOptions.cmd_list_accounts) this.list_accounts(); Log.debug("Initializing TelegramApp"); + if (CommandLineOptions.cmd_debug_telegram) { + System.setProperty(org.slf4j.impl.SimpleLogger.DEFAULT_LOG_LEVEL_KEY, "DEBUG"); + } else { + System.setProperty(org.slf4j.impl.SimpleLogger.DEFAULT_LOG_LEVEL_KEY, "ERROR"); + } app = new TelegramApp(Config.APP_ID, Config.APP_HASH, Config.APP_MODEL, Config.APP_SYSVER, Config.APP_APPVER, Config.APP_LANG); - if (CommandLineOptions.cmd_debug_telegram) Kotlogram.setDebugLogEnabled(true); Log.debug("Checking accounts"); Log.up(); diff --git a/src/main/java/de/fabianonline/telegram_backup/Config.java b/src/main/java/de/fabianonline/telegram_backup/Config.java index ea7da10..0339e02 100644 --- a/src/main/java/de/fabianonline/telegram_backup/Config.java +++ b/src/main/java/de/fabianonline/telegram_backup/Config.java @@ -37,14 +37,8 @@ public class Config { public static final String FILE_FILES_BASE = "files"; public static final String FILE_STICKER_BASE = "stickers"; - public static final int[] FILE_DOWNLOAD_BLOCK_SIZES = new int[]{ - 1*1024*1024, - 512*1024, - 2*1024*1024, - 4*1024*1024}; - - public static int DELAY_AFTER_GET_MESSAGES = 200; - public static int DELAY_AFTER_GET_FILE = 1000; + public static int DELAY_AFTER_GET_MESSAGES = 100; + public static int DELAY_AFTER_GET_FILE = 100; public static final String SECRET_GMAPS = "AIzaSyBEtUDhCQKEH6i2Mn1GAiQ9M_tLN0vxHIs"; diff --git a/src/main/java/de/fabianonline/telegram_backup/Database.java b/src/main/java/de/fabianonline/telegram_backup/Database.java index b07f68e..c568a9a 100644 --- a/src/main/java/de/fabianonline/telegram_backup/Database.java +++ b/src/main/java/de/fabianonline/telegram_backup/Database.java @@ -161,16 +161,16 @@ public class Database { } } - public synchronized void saveMessages(TLVector all) { + public synchronized void saveMessages(TLVector all, Integer api_layer) { try { //"(id, dialog_id, from_id, from_type, text, time, has_media, data, sticker, type) " + //"VALUES " + //"(?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"); String columns = - "(id, message_type, dialog_id, chat_id, sender_id, fwd_from_id, text, time, has_media, media_type, media_file, media_size, data) "+ + "(id, message_type, dialog_id, chat_id, sender_id, fwd_from_id, text, time, has_media, media_type, media_file, media_size, data, api_layer) "+ "VALUES " + - "(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; - //1 2 3 4 5 6 7 8 9 10 11 12 13 + "(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; + //1 2 3 4 5 6 7 8 9 10 11 12 13 14 PreparedStatement ps = conn.prepareStatement("INSERT OR REPLACE INTO messages " + columns); PreparedStatement ps_insert_or_ignore = conn.prepareStatement("INSERT OR IGNORE INTO messages " + columns); @@ -194,11 +194,13 @@ public class Database { throw new RuntimeException("Unexpected Peer type: " + peer.getClass().getName()); } ps.setInt(5, msg.getFromId()); - if (msg.getFwdFromId()!=null && msg.getFwdFromId() instanceof TLPeerUser) { - ps.setInt(6, ((TLPeerUser)msg.getFwdFromId()).getUserId()); + + if (msg.getFwdFrom() != null) { + ps.setInt(6, msg.getFwdFrom().getFromId()); } else { ps.setNull(6, Types.INTEGER); } + String text = msg.getMessage(); if ((text==null || text.equals("")) && msg.getMedia()!=null) { if (msg.getMedia() instanceof TLMessageMediaDocument) { @@ -224,6 +226,7 @@ public class Database { ByteArrayOutputStream stream = new ByteArrayOutputStream(); msg.serializeBody(stream); ps.setBytes(13, stream.toByteArray()); + ps.setInt(14, api_layer); ps.addBatch(); } else if (abs instanceof TLMessageService) { ps_insert_or_ignore.setInt(1, abs.getId()); @@ -239,6 +242,7 @@ public class Database { ps_insert_or_ignore.setNull(11, Types.VARCHAR); ps_insert_or_ignore.setNull(12, Types.INTEGER); ps_insert_or_ignore.setNull(13, Types.BLOB); + ps_insert_or_ignore.setInt(14, api_layer); ps_insert_or_ignore.addBatch(); } else if (abs instanceof TLMessageEmpty) { ps_insert_or_ignore.setInt(1, abs.getId()); @@ -254,6 +258,7 @@ public class Database { ps_insert_or_ignore.setNull(11, Types.VARCHAR); ps_insert_or_ignore.setNull(12, Types.INTEGER); ps_insert_or_ignore.setNull(13, Types.BLOB); + ps_insert_or_ignore.setInt(14, api_layer); ps_insert_or_ignore.addBatch(); } else { throw new RuntimeException("Unexpected Message type: " + abs.getClass().getName()); @@ -397,6 +402,17 @@ public class Database { } } + public LinkedList getIdsFromQuery(String query) { + try { + LinkedList list = new LinkedList(); + ResultSet rs = stmt.executeQuery(query); + while(rs.next()) { list.add(rs.getInt(1)); } + rs.close(); + return list; + } catch (SQLException e) { throw new RuntimeException(e); } + } + + public HashMap getMessageTypesWithCount() { HashMap map = new HashMap(); try { diff --git a/src/main/java/de/fabianonline/telegram_backup/DatabaseUpdates.java b/src/main/java/de/fabianonline/telegram_backup/DatabaseUpdates.java index 030169d..4abb754 100644 --- a/src/main/java/de/fabianonline/telegram_backup/DatabaseUpdates.java +++ b/src/main/java/de/fabianonline/telegram_backup/DatabaseUpdates.java @@ -29,6 +29,7 @@ public class DatabaseUpdates { register(new DB_Update_4(conn, db)); register(new DB_Update_5(conn, db)); register(new DB_Update_6(conn, db)); + register(new DB_Update_7(conn, db)); Log.down(); } @@ -97,7 +98,7 @@ public class DatabaseUpdates { } } - private DatabaseUpdate getUpdateToVersion(int i) { return updates.get(i); } + private DatabaseUpdate getUpdateToVersion(int i) { return updates.get(i-1); } private int getMaxPossibleVersion() { return updates.size(); @@ -205,7 +206,7 @@ class DB_Update_4 extends DatabaseUpdate { class DB_Update_5 extends DatabaseUpdate { public int getVersion() { return 5; } public DB_Update_5(Connection conn, Database db) { super(conn, db); } - + protected void _doUpdate() throws SQLException { stmt.executeUpdate("CREATE TABLE runs (id INTEGER PRIMARY KEY ASC, time INTEGER, start_id INTEGER, end_id INTEGER, count_missing INTEGER)"); } @@ -268,10 +269,10 @@ class DB_Update_6 extends DatabaseUpdate { while (rs.next()) { ps.setInt(5, rs.getInt(1)); TLMessage msg = db.bytesToTLMessage(rs.getBytes(2)); - if (msg==null || msg.getFwdFromId()==null || ! (msg.getFwdFromId() instanceof TLPeerUser)) { + if (msg==null || msg.getFwdFrom()==null) { ps.setNull(1, Types.INTEGER); } else { - ps.setInt(1, ((TLPeerUser)msg.getFwdFromId()).getUserId()); + ps.setInt(1, msg.getFwdFrom().getFromId()); } AbstractMediaFileManager f = FileManagerFactory.getFileManager(msg, db.user_manager, db.client); if (f==null) { @@ -294,3 +295,15 @@ class DB_Update_6 extends DatabaseUpdate { stmt.executeUpdate("ALTER TABLE messages_new RENAME TO messages"); } } + +class DB_Update_7 extends DatabaseUpdate { + public int getVersion() { return 7; } + public boolean needsBackup() { return true; } + public DB_Update_7(Connection conn, Database db) { super(conn, db); } + + protected void _doUpdate() throws SQLException { + stmt.executeUpdate("ALTER TABLE messages ADD COLUMN api_layer INTEGER"); + + stmt.executeUpdate("UPDATE messages SET api_layer=51"); + } +} diff --git a/src/main/java/de/fabianonline/telegram_backup/DownloadManager.java b/src/main/java/de/fabianonline/telegram_backup/DownloadManager.java index 250321f..14923ee 100644 --- a/src/main/java/de/fabianonline/telegram_backup/DownloadManager.java +++ b/src/main/java/de/fabianonline/telegram_backup/DownloadManager.java @@ -24,6 +24,7 @@ import de.fabianonline.telegram_backup.mediafilemanager.FileManagerFactory; import de.fabianonline.telegram_backup.mediafilemanager.AbstractMediaFileManager; import com.github.badoualy.telegram.api.TelegramClient; +import com.github.badoualy.telegram.api.Kotlogram; import com.github.badoualy.telegram.tl.core.TLIntVector; import com.github.badoualy.telegram.tl.core.TLObject; import com.github.badoualy.telegram.tl.api.messages.TLAbsMessages; @@ -38,6 +39,7 @@ import java.io.File; import java.io.FileOutputStream; import java.util.ArrayList; import java.util.LinkedList; +import java.util.List; import java.util.Random; import java.net.URL; import java.util.concurrent.TimeoutException; @@ -96,7 +98,7 @@ public class DownloadManager { dialog_limit); Log.debug("Got %d dialogs", dialogs.getDialogs().size()); Log.up(); - for (TLAbsDialog d : dialogs.getDialogs()) { + for (TLDialog d : dialogs.getDialogs()) { if (d.getTopMessage() > max_message_id) { Log.debug("Updating top message id: %d => %d", max_message_id, d.getTopMessage()); max_message_id = d.getTopMessage(); @@ -119,42 +121,10 @@ public class DownloadManager { throw new RuntimeException("max_database_id is bigger then max_message_id. This shouldn't happen. But the telegram api nonetheless does that sometimes. Just ignore this error, wait a few seconds and then try again."); } else { int start_id = max_database_id + 1; - int current_start_id = start_id; int end_id = max_message_id; - prog.onMessageDownloadStart(end_id - current_start_id + 1); - - Log.debug("Entering download loop"); - Log.up(); - while (current_start_id <= end_id) { - Log.debug("Loop"); - Log.up(); - Log.debug("current_start_id: %d", current_start_id); - Log.debug("end_id: %d", end_id); - int my_end_id = Math.min(current_start_id+99, end_id); - Log.debug("my_end_id: %d", my_end_id); - ArrayList a = makeIdList(current_start_id, my_end_id); - TLIntVector ids = new TLIntVector(); - ids.addAll(a); - my_end_id = ids.get(ids.size()-1); - Log.debug("my_end_id: %d", my_end_id); - current_start_id = my_end_id + 1; - Log.debug("current_start_id: %d", current_start_id); - TLAbsMessages response = client.messagesGetMessages(ids); - prog.onMessageDownloaded(response.getMessages().size()); - db.saveMessages(response.getMessages()); - db.saveChats(response.getChats()); - db.saveUsers(response.getUsers()); - Log.debug("Sleeping"); - try { - Thread.sleep(Config.DELAY_AFTER_GET_MESSAGES); - } catch (InterruptedException e) {} - Log.down(); - } - Log.down(); - Log.debug("Finished."); - - prog.onMessageDownloadFinished(); + List ids = makeIdList(start_id, end_id); + downloadMessages(ids); } Log.debug("Searching for missing messages in the db"); @@ -173,38 +143,49 @@ public class DownloadManager { LinkedList ids = db.getMissingIDs(); count_missing = ids.size(); System.out.println("Downloading " + ids.size() + " messages that are missing in your database."); - prog.onMessageDownloadStart(ids.size()); - Log.debug("Entering download loop"); - Log.up(); - while (ids.size()>0) { - Log.debug("Loop"); - Log.up(); - TLIntVector vector = new TLIntVector(); - for (int i=0; i<100; i++) { - if (ids.size()==0) break; - vector.add(ids.remove()); - } - Log.debug("vector.size(): %d", vector.size()); - Log.debug("ids.size(): %d", ids.size()); - TLAbsMessages response = client.messagesGetMessages(vector); - prog.onMessageDownloaded(response.getMessages().size()); - db.saveMessages(response.getMessages()); - db.saveChats(response.getChats()); - db.saveUsers(response.getUsers()); - Log.debug("sleep"); - try { Thread.sleep(Config.DELAY_AFTER_GET_MESSAGES); } catch (InterruptedException e) {} - Log.down(); - } - Log.down(); - prog.onMessageDownloadFinished(); + + downloadMessages(ids); } } - Log.down(); + Log.debug("Logging this run"); db.logRun(Math.min(max_database_id + 1, max_message_id), max_message_id, count_missing); Log.down(); } + private void downloadMessages(List ids) throws RpcErrorException, IOException { + prog.onMessageDownloadStart(ids.size()); + + Log.debug("Entering download loop"); + Log.up(); + while (ids.size()>0) { + Log.debug("Loop"); + Log.up(); + TLIntVector vector = new TLIntVector(); + for (int i=0; i<100; i++) { + if (ids.size()==0) break; + vector.add(ids.remove(0)); + } + Log.debug("vector.size(): %d", vector.size()); + Log.debug("ids.size(): %d", ids.size()); + + TLAbsMessages response = client.messagesGetMessages(vector); + prog.onMessageDownloaded(response.getMessages().size()); + db.saveMessages(response.getMessages(), Config.API_LAYER); + db.saveChats(response.getChats()); + db.saveUsers(response.getUsers()); + Log.debug("Sleeping"); + try { + Thread.sleep(Config.DELAY_AFTER_GET_MESSAGES); + } catch (InterruptedException e) {} + Log.down(); + } + Log.down(); + Log.debug("Finished."); + + prog.onMessageDownloadFinished(); + } + public void downloadMedia() throws RpcErrorException, IOException { boolean completed = true; do { @@ -232,6 +213,14 @@ public class DownloadManager { private void _downloadMedia() throws RpcErrorException, IOException, TimeoutException { Log.debug("This is _downloadMedia"); + Log.debug("Checking if there are messages in the DB with a too old API layer"); + LinkedList ids = db.getIdsFromQuery("SELECT id FROM messages WHERE has_media=1 AND api_layer<" + Kotlogram.API_LAYER); + if (ids.size()>0) { + System.out.println("You have " + ids.size() + " messages in your db that need an update. Doing that now."); + Log.debug("Found %d messages", ids.size()); + downloadMessages(ids); + } + LinkedList messages = this.db.getMessagesWithMedia(); Log.debug("Database returned %d messages with media", messages.size()); prog.onMediaDownloadStart(messages.size()); @@ -259,10 +248,9 @@ public class DownloadManager { prog.onMediaDownloadFinished(); } - private ArrayList makeIdList(int start, int end) { - if (start > end) throw new RuntimeException("start and end reversed"); - ArrayList a = new ArrayList(end - start + 1); - for (int i=0; i<=end-start; i++) a.add(start+i); + private List makeIdList(int start, int end) { + LinkedList a = new LinkedList(); + for (int i=start; i<=end; i++) a.add(i); return a; } diff --git a/src/main/java/de/fabianonline/telegram_backup/TelegramUpdateHandler.java b/src/main/java/de/fabianonline/telegram_backup/TelegramUpdateHandler.java index df8c581..57c2272 100644 --- a/src/main/java/de/fabianonline/telegram_backup/TelegramUpdateHandler.java +++ b/src/main/java/de/fabianonline/telegram_backup/TelegramUpdateHandler.java @@ -65,15 +65,15 @@ class TelegramUpdateHandler implements UpdateCallback { if (db==null) return; if (debug) System.out.println("onShortChatMessage - " + m.getMessage()); TLMessage msg = new TLMessage( - m.getUnread(), m.getOut(), m.getMentioned(), m.getMediaUnread(), + m.getSilent(), + false, m.getId(), m.getFromId(), new TLPeerChat(m.getChatId()), - m.getFwdFromId(), - m.getFwdDate(), + m.getFwdFrom(), m.getViaBotId(), m.getReplyToMsgId(), m.getDate(), @@ -81,10 +81,11 @@ class TelegramUpdateHandler implements UpdateCallback { null, null, m.getEntities(), + null, null); TLVector vector = new TLVector(TLAbsMessage.class); vector.add(msg); - db.saveMessages(vector); + db.saveMessages(vector, Config.API_LAYER); System.out.print('.'); } @@ -100,15 +101,15 @@ class TelegramUpdateHandler implements UpdateCallback { from_id = m.getUserId(); } TLMessage msg = new TLMessage( - m.getUnread(), m.getOut(), m.getMentioned(), m.getMediaUnread(), + m.getSilent(), + false, m.getId(), from_id, new TLPeerUser(to_id), - m.getFwdFromId(), - m.getFwdDate(), + m.getFwdFrom(), m.getViaBotId(), m.getReplyToMsgId(), m.getDate(), @@ -116,10 +117,11 @@ class TelegramUpdateHandler implements UpdateCallback { null, null, m.getEntities(), + null, null); TLVector vector = new TLVector(TLAbsMessage.class); vector.add(msg); - db.saveMessages(vector); + db.saveMessages(vector, Config.API_LAYER); System.out.print('.'); } @@ -131,7 +133,7 @@ class TelegramUpdateHandler implements UpdateCallback { TLAbsMessage abs_msg = ((TLUpdateNewMessage)update).getMessage(); TLVector vector = new TLVector(TLAbsMessage.class); vector.add(abs_msg); - db.saveMessages(vector); + db.saveMessages(vector, Config.API_LAYER); System.out.print('.'); if (abs_msg instanceof TLMessage) { AbstractMediaFileManager fm = FileManagerFactory.getFileManager((TLMessage)abs_msg, user, client); diff --git a/src/main/java/de/fabianonline/telegram_backup/UserManager.java b/src/main/java/de/fabianonline/telegram_backup/UserManager.java index 16599af..793fa65 100644 --- a/src/main/java/de/fabianonline/telegram_backup/UserManager.java +++ b/src/main/java/de/fabianonline/telegram_backup/UserManager.java @@ -17,7 +17,7 @@ package de.fabianonline.telegram_backup; import com.github.badoualy.telegram.api.TelegramClient; -import com.github.badoualy.telegram.tl.api.auth.TLAbsSentCode; +import com.github.badoualy.telegram.tl.api.auth.TLSentCode; import com.github.badoualy.telegram.tl.api.auth.TLAuthorization; import com.github.badoualy.telegram.tl.api.TLUser; import com.github.badoualy.telegram.tl.api.TLUserFull; @@ -36,7 +36,7 @@ public class UserManager { public String phone = null; private String code = null; private TelegramClient client = null; - private TLAbsSentCode sent_code = null; + private TLSentCode sent_code = null; private TLAuthorization auth = null; private boolean password_needed = false; @@ -54,7 +54,7 @@ public class UserManager { public void sendCodeToPhoneNumber(String number) throws RpcErrorException, IOException { this.phone = number; - this.sent_code = this.client.authSendCode(this.phone, 5); + this.sent_code = this.client.authSendCode(false, this.phone, true); } public void verifyCode(String code) throws RpcErrorException, IOException { @@ -72,7 +72,7 @@ public class UserManager { public void verifyPassword(String pw) throws RpcErrorException, IOException { byte[] password = pw.getBytes("UTF-8"); - byte[] salt = ((TLPassword)client.executeRpcQuery(new TLRequestAccountGetPasswordWithCurrentSalt())).getCurrentSalt().getData(); + byte[] salt = ((TLPassword)client.accountGetPassword()).getCurrentSalt().getData(); MessageDigest md = null; try { md = MessageDigest.getInstance("SHA-256"); diff --git a/src/main/java/de/fabianonline/telegram_backup/mediafilemanager/AudioFileManager.java b/src/main/java/de/fabianonline/telegram_backup/mediafilemanager/AudioFileManager.java deleted file mode 100644 index c8df8c4..0000000 --- a/src/main/java/de/fabianonline/telegram_backup/mediafilemanager/AudioFileManager.java +++ /dev/null @@ -1,73 +0,0 @@ -/* 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 . */ - -package de.fabianonline.telegram_backup.mediafilemanager; - -import de.fabianonline.telegram_backup.UserManager; -import de.fabianonline.telegram_backup.Database; -import de.fabianonline.telegram_backup.StickerConverter; -import de.fabianonline.telegram_backup.DownloadProgressInterface; -import de.fabianonline.telegram_backup.DownloadManager; - -import com.github.badoualy.telegram.api.TelegramClient; -import com.github.badoualy.telegram.tl.core.TLIntVector; -import com.github.badoualy.telegram.tl.core.TLObject; -import com.github.badoualy.telegram.tl.api.messages.TLAbsMessages; -import com.github.badoualy.telegram.tl.api.messages.TLAbsDialogs; -import com.github.badoualy.telegram.tl.api.*; -import com.github.badoualy.telegram.tl.api.upload.TLFile; -import com.github.badoualy.telegram.tl.exception.RpcErrorException; -import com.github.badoualy.telegram.tl.api.request.TLRequestUploadGetFile; - -import java.io.IOException; -import java.io.File; -import java.io.FileOutputStream; -import java.util.ArrayList; -import java.util.LinkedList; -import java.net.URL; -import java.util.concurrent.TimeoutException; - -import org.apache.commons.io.FileUtils; - -public class AudioFileManager extends AbstractMediaFileManager { - protected TLAudio audio; - - public AudioFileManager(TLMessage msg, UserManager user, TelegramClient client) { - super(msg, user, client); - TLAbsAudio a = ((TLMessageMediaAudio)msg.getMedia()).getAudio(); - if (a instanceof TLAudio) { - this.audio = (TLAudio) a; - } else if (a instanceof TLAudioEmpty) { - this.isEmpty = true; - } else { - throwUnexpectedObjectError(a); - } - } - - public int getSize() { return audio.getSize(); } - - public String getExtension() { - return extensionFromMimetype(audio.getMimeType()); - } - - public void download() throws RpcErrorException, IOException { - DownloadManager.downloadFile(client, getTargetPathAndFilename(), getSize(), audio.getDcId(), audio.getId(), audio.getAccessHash()); - } - - public String getLetter() { return "a"; } - public String getName() { return "audio"; } - public String getDescription() { return "Audio"; } -} diff --git a/src/main/java/de/fabianonline/telegram_backup/mediafilemanager/FileManagerFactory.java b/src/main/java/de/fabianonline/telegram_backup/mediafilemanager/FileManagerFactory.java index 62161ef..e636e1b 100644 --- a/src/main/java/de/fabianonline/telegram_backup/mediafilemanager/FileManagerFactory.java +++ b/src/main/java/de/fabianonline/telegram_backup/mediafilemanager/FileManagerFactory.java @@ -55,10 +55,6 @@ public class FileManagerFactory { return new StickerFileManager(m, u, c); } return d; - } else if (media instanceof TLMessageMediaVideo) { - return new VideoFileManager(m, u, c); - } else if (media instanceof TLMessageMediaAudio) { - return new AudioFileManager(m, u, c); } else if (media instanceof TLMessageMediaGeo) { return new GeoFileManager(m, u, c); } else if (media instanceof TLMessageMediaEmpty) { diff --git a/src/main/java/de/fabianonline/telegram_backup/mediafilemanager/VideoFileManager.java b/src/main/java/de/fabianonline/telegram_backup/mediafilemanager/VideoFileManager.java deleted file mode 100644 index 20486b5..0000000 --- a/src/main/java/de/fabianonline/telegram_backup/mediafilemanager/VideoFileManager.java +++ /dev/null @@ -1,73 +0,0 @@ -/* 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 . */ - -package de.fabianonline.telegram_backup.mediafilemanager; - -import de.fabianonline.telegram_backup.UserManager; -import de.fabianonline.telegram_backup.Database; -import de.fabianonline.telegram_backup.StickerConverter; -import de.fabianonline.telegram_backup.DownloadProgressInterface; -import de.fabianonline.telegram_backup.DownloadManager; - -import com.github.badoualy.telegram.api.TelegramClient; -import com.github.badoualy.telegram.tl.core.TLIntVector; -import com.github.badoualy.telegram.tl.core.TLObject; -import com.github.badoualy.telegram.tl.api.messages.TLAbsMessages; -import com.github.badoualy.telegram.tl.api.messages.TLAbsDialogs; -import com.github.badoualy.telegram.tl.api.*; -import com.github.badoualy.telegram.tl.api.upload.TLFile; -import com.github.badoualy.telegram.tl.exception.RpcErrorException; -import com.github.badoualy.telegram.tl.api.request.TLRequestUploadGetFile; - -import java.io.IOException; -import java.io.File; -import java.io.FileOutputStream; -import java.util.ArrayList; -import java.util.LinkedList; -import java.net.URL; -import java.util.concurrent.TimeoutException; - -import org.apache.commons.io.FileUtils; - -public class VideoFileManager extends AbstractMediaFileManager { - protected TLVideo video; - - public VideoFileManager(TLMessage msg, UserManager user, TelegramClient client) { - super(msg, user, client); - TLAbsVideo v = ((TLMessageMediaVideo)msg.getMedia()).getVideo(); - if (v instanceof TLVideo) { - this.video = (TLVideo) v; - } else if (v instanceof TLVideoEmpty) { - this.isEmpty = true; - } else { - throwUnexpectedObjectError(v); - } - } - - public int getSize() { return video.getSize(); } - - public String getExtension() { - return extensionFromMimetype(video.getMimeType()); - } - - public void download() throws RpcErrorException, IOException { - DownloadManager.downloadFile(client, getTargetPathAndFilename(), getSize(), video.getDcId(), video.getId(), video.getAccessHash()); - } - - public String getLetter() { return "v"; } - public String getName() { return "video"; } - public String getDescription() { return "Video"; } -}