diff --git a/build.gradle b/build.gradle index 34616be..21d1949 100644 --- a/build.gradle +++ b/build.gradle @@ -31,7 +31,7 @@ compileKotlin { dependencies { - compile('com.github.badoualy:kotlogram:666a81ef9d6707f117a3fecc2d21c91d51c7d075') { + compile('com.github.badoualy:kotlogram:e3c26c69c2896b6bf3fce539ba0c46debc884e0f') { exclude module: 'slf4j-simple' } compile 'org.xerial:sqlite-jdbc:3.16.1' @@ -41,6 +41,7 @@ dependencies { compile 'com.google.code.gson:gson:2.8.0' compile 'com.github.salomonbrys.kotson:kotson:2.5.0' compile 'com.github.kittinunf.fuel:fuel:1.12.0' + compile 'commons-io:commons-io:2.5' testCompile 'junit:junit:4.12' } diff --git a/src/main/kotlin/de/fabianonline/telegram_backup/CommandLineController.kt b/src/main/kotlin/de/fabianonline/telegram_backup/CommandLineController.kt index c73f832..486e804 100644 --- a/src/main/kotlin/de/fabianonline/telegram_backup/CommandLineController.kt +++ b/src/main/kotlin/de/fabianonline/telegram_backup/CommandLineController.kt @@ -94,7 +94,7 @@ class CommandLineController(val options: CommandLineOptions) { storage = ApiStorage(file_base) logger.info("Creating Client") - client = Kotlogram.getDefaultClient(app, storage, Kotlogram.PROD_DC4, null) + client = Kotlogram.getDefaultClient(app, storage, null, Kotlogram.PROD_DC4) // From now on we have a new catch-all-block that will terminate it's TelegramClient when an exception happens. try { @@ -184,7 +184,7 @@ class CommandLineController(val options: CommandLineOptions) { handler = TelegramUpdateHandler(user_manager, database, file_base, settings) client.close() logger.info("Creating new client") - client = Kotlogram.getDefaultClient(app, storage, Kotlogram.PROD_DC4, handler) + client = Kotlogram.getDefaultClient(app, storage, handler, Kotlogram.PROD_DC4) println("DAEMON mode requested - keeping running.") } } catch (e: Throwable) { diff --git a/src/main/kotlin/de/fabianonline/telegram_backup/DownloadManager.kt b/src/main/kotlin/de/fabianonline/telegram_backup/DownloadManager.kt index 178a4cd..cee8300 100644 --- a/src/main/kotlin/de/fabianonline/telegram_backup/DownloadManager.kt +++ b/src/main/kotlin/de/fabianonline/telegram_backup/DownloadManager.kt @@ -269,10 +269,12 @@ class DownloadManager(val client: TelegramClient, val prog: DownloadProgressInte if (result) { prog.onMediaDownloaded(m) } else { + logger.trace("onMediaFailed") prog.onMediaFailed() } } catch (e: TimeoutException) { // do nothing - skip this file + logger.trace("TimeoutException onMedia") prog.onMediaFailed() } } @@ -300,7 +302,7 @@ class DownloadManager(val client: TelegramClient, val prog: DownloadProgressInte var temp: TLAbsDialogs? = null logger.trace("Calling messagesGetDialogs with offset {}", offset) Utils.obeyFloodWait { - temp = client.messagesGetDialogs(offset, 0, TLInputPeerEmpty(), limit) + temp = client.messagesGetDialogs(false, offset, 0, TLInputPeerEmpty(), limit) } val dialogs = temp!! val last_message = dialogs.messages.filter{ it is TLMessage || it is TLMessageService }.last() @@ -369,8 +371,9 @@ class DownloadManager(val client: TelegramClient, val prog: DownloadProgressInte } @Throws(RpcErrorException::class, IOException::class, TimeoutException::class) - fun downloadFile(targetFilename: String, size: Int, dcId: Int, id: Long, accessHash: Long, prog: DownloadProgressInterface?) { - val loc = TLInputDocumentFileLocation(id, accessHash) + fun downloadFile(targetFilename: String, size: Int, dcId: Int, id: Long, accessHash: Long, version: Int = 0, prog: DownloadProgressInterface?) { + val loc = TLInputDocumentFileLocation(id, accessHash, version) + logger.trace("TLInputDocumentFileLocation: {}", loc) downloadFileFromDc(targetFilename, loc, dcId, size, prog) } @@ -397,14 +400,17 @@ class DownloadManager(val client: TelegramClient, val prog: DownloadProgressInte if (prog != null) prog.onMediaFileDownloadStarted() do { logger.trace("offset: {} block_size: {} size: {}", offset, size, size) - val req = TLRequestUploadGetFile(loc, offset, size) + val req = TLRequestUploadGetFile(loc, offset, 1024*1024) var resp: TLFile? = null try { Utils.obeyFloodWait() { resp = download_client!!.executeRpcQuery(req, dcID) as TLFile } } catch (e: RpcErrorException) { + logger.trace("RpcErrorException") + logger.trace("{}", e.localizedMessage) if (e.getCode() == 400) { + logger.trace("code 400") // Somehow this file is broken. No idea why. Let's skip it for now. return false } diff --git a/src/main/kotlin/de/fabianonline/telegram_backup/LoginManager.kt b/src/main/kotlin/de/fabianonline/telegram_backup/LoginManager.kt index 86aefe0..533f299 100644 --- a/src/main/kotlin/de/fabianonline/telegram_backup/LoginManager.kt +++ b/src/main/kotlin/de/fabianonline/telegram_backup/LoginManager.kt @@ -27,7 +27,7 @@ class LoginManager(val app: TelegramApp, val target_dir: String, val phoneToUse: // We now have an account, so we can create an ApiStorage and TelegramClient. val storage = ApiStorage(file_base) - val client = Kotlogram.getDefaultClient(app, storage, Kotlogram.PROD_DC4, null) + val client = Kotlogram.getDefaultClient(app, storage, null, Kotlogram.PROD_DC4) val sent_code = send_code_to_phone_number(client, phone) println("Telegram sent you a code. Please enter it here.") diff --git a/src/main/kotlin/de/fabianonline/telegram_backup/mediafilemanager/DocumentFileManager.kt b/src/main/kotlin/de/fabianonline/telegram_backup/mediafilemanager/DocumentFileManager.kt index 493c0a6..a3b63d5 100644 --- a/src/main/kotlin/de/fabianonline/telegram_backup/mediafilemanager/DocumentFileManager.kt +++ b/src/main/kotlin/de/fabianonline/telegram_backup/mediafilemanager/DocumentFileManager.kt @@ -75,7 +75,8 @@ open class DocumentFileManager(message: JsonObject, file_base: String) : Abstrac @Throws(RpcErrorException::class, IOException::class, TimeoutException::class) override fun download(prog: DownloadProgressInterface?): Boolean { - DownloadManager.downloadFile(targetPathAndFilename, size, json["dcId"].int, json["id"].long, json["accessHash"].long, prog) + var version: Int = if (json.contains("version")) json["version"].int else 0 + DownloadManager.downloadFile(targetPathAndFilename, size, json["dcId"].int, json["id"].long, json["accessHash"].long, version , prog) return true } } diff --git a/src/main/kotlin/de/fabianonline/telegram_backup/mediafilemanager/FileManagerFactory.kt b/src/main/kotlin/de/fabianonline/telegram_backup/mediafilemanager/FileManagerFactory.kt index 84693a7..2c02bf8 100644 --- a/src/main/kotlin/de/fabianonline/telegram_backup/mediafilemanager/FileManagerFactory.kt +++ b/src/main/kotlin/de/fabianonline/telegram_backup/mediafilemanager/FileManagerFactory.kt @@ -74,6 +74,8 @@ object FileManagerFactory { return UnsupportedFileManager(message, file_base, "contact") } else if (media.isA("messageMediaVenue")) { return UnsupportedFileManager(message, file_base, "venue") + } else if (media.isA("messageMediaGame")) { + return UnsupportedFileManager(message, file_base, "game") } else { AbstractMediaFileManager.throwUnexpectedObjectError(media["_constructor"].string) } diff --git a/src/main/kotlin/de/fabianonline/telegram_backup/mediafilemanager/StickerFileManager.kt b/src/main/kotlin/de/fabianonline/telegram_backup/mediafilemanager/StickerFileManager.kt index 1056b07..838c154 100644 --- a/src/main/kotlin/de/fabianonline/telegram_backup/mediafilemanager/StickerFileManager.kt +++ b/src/main/kotlin/de/fabianonline/telegram_backup/mediafilemanager/StickerFileManager.kt @@ -63,9 +63,10 @@ class StickerFileManager(message: JsonObject, file_base: String) : DocumentFileM private val filenameBase: String get() { - val set = sticker["stickerset"].obj.get("shortName").nullString ?: sticker["stickerset"].obj.get("id").string + //val set = sticker["stickerset"].obj.get("shortName").nullString ?: val hash = sticker["alt"].string.hashCode() - return "${set}_${hash}" + //return "${set}_${hash}" + return "_${hash}" } override val targetFilename: String diff --git a/src/main/resources/templates/html/_messages.mustache b/src/main/resources/templates/html/_messages.mustache index 741e73b..4022934 100644 --- a/src/main/resources/templates/html/_messages.mustache +++ b/src/main/resources/templates/html/_messages.mustache @@ -7,7 +7,7 @@ {{/is_new_date}}