mirror of
https://github.com/fabianonline/telegram_backup.git
synced 2024-12-25 14:25:35 +00:00
WIP: Even moar rewriting.
This commit is contained in:
parent
eea08a5559
commit
ebff71b208
@ -30,6 +30,8 @@ import org.slf4j.LoggerFactory
|
||||
import org.slf4j.Logger
|
||||
|
||||
class CommandLineController(val options: CommandLineOptions) {
|
||||
val logger = LoggerFactory.getLogger(CommandLineController::class.java)
|
||||
|
||||
init {
|
||||
val storage: ApiStorage
|
||||
val app: TelegramApp
|
||||
@ -37,7 +39,7 @@ class CommandLineController(val options: CommandLineOptions) {
|
||||
val file_base: String
|
||||
val phone_number: String
|
||||
val handler: TelegramUpdateHandler
|
||||
val client: TelegramClient
|
||||
var client: TelegramClient
|
||||
val user_manager: UserManager
|
||||
val inisettings: IniSettings
|
||||
val database: Database
|
||||
@ -91,11 +93,8 @@ class CommandLineController(val options: CommandLineOptions) {
|
||||
logger.info("Initializing ApiStorage")
|
||||
storage = ApiStorage(file_base)
|
||||
|
||||
logger.info("Initializing TelegramUpdateHandler")
|
||||
handler = TelegramUpdateHandler()
|
||||
|
||||
logger.info("Creating Client")
|
||||
client = Kotlogram.getDefaultClient(app, storage, Kotlogram.PROD_DC4, handler)
|
||||
client = Kotlogram.getDefaultClient(app, storage, Kotlogram.PROD_DC4, null)
|
||||
|
||||
// From now on we have a new catch-all-block that will terminate it's TelegramClient when an exception happens.
|
||||
try {
|
||||
@ -126,9 +125,9 @@ class CommandLineController(val options: CommandLineOptions) {
|
||||
|
||||
if (options.val_test != null) {
|
||||
if (options.val_test == 1) {
|
||||
TestFeatures.test1()
|
||||
TestFeatures(database).test1()
|
||||
} else if (options.val_test == 2) {
|
||||
TestFeatures.test2()
|
||||
TestFeatures(database).test2()
|
||||
} else {
|
||||
System.out.println("Unknown test " + options.val_test)
|
||||
}
|
||||
@ -139,7 +138,7 @@ class CommandLineController(val options: CommandLineOptions) {
|
||||
logger.debug("options.val_export: {}", export)
|
||||
if (export != null) {
|
||||
if (export.toLowerCase().equals("html")) {
|
||||
HTMLExporter().export()
|
||||
HTMLExporter(database, user_manager, ini=inisettings, file_base=file_base).export()
|
||||
System.exit(0)
|
||||
} else {
|
||||
show_error("Unknown export format '${export}'.")
|
||||
@ -184,22 +183,24 @@ class CommandLineController(val options: CommandLineOptions) {
|
||||
} else {
|
||||
println("Skipping media download because download_media is set to false.")
|
||||
}
|
||||
|
||||
if (options.cmd_daemon) {
|
||||
logger.info("Initializing TelegramUpdateHandler")
|
||||
handler = TelegramUpdateHandler(user_manager, database)
|
||||
client.close()
|
||||
logger.info("Creating new client")
|
||||
client = Kotlogram.getDefaultClient(app, storage, Kotlogram.PROD_DC4, handler)
|
||||
println("DAEMON mode requested - keeping running.")
|
||||
}
|
||||
} catch (e: Throwable) {
|
||||
println("An error occured!")
|
||||
e.printStackTrace()
|
||||
logger.error("Exception caught!", e)
|
||||
// If we encountered an exception, we definitely don't want to start the daemon mode now.
|
||||
options.cmd_daemon = false
|
||||
} finally {
|
||||
if (options.cmd_daemon) {
|
||||
handler.activate()
|
||||
println("DAEMON mode requested - keeping running.")
|
||||
} else {
|
||||
client.close()
|
||||
println()
|
||||
println("----- EXIT -----")
|
||||
System.exit(0)
|
||||
}
|
||||
client.close()
|
||||
println()
|
||||
println("----- EXIT -----")
|
||||
System.exit(0)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -26,7 +26,6 @@ class CommandLineOptions(args: Array<String>) {
|
||||
var cmd_version = false
|
||||
var cmd_license = false
|
||||
var cmd_daemon = false
|
||||
var cmd_anonymize = false
|
||||
var cmd_stats = false
|
||||
var cmd_list_channels = false
|
||||
var val_account: String? = null
|
||||
@ -84,7 +83,7 @@ class CommandLineOptions(args: Array<String>) {
|
||||
last_cmd = "--test"
|
||||
continue@loop
|
||||
}
|
||||
"--anonymize" -> cmd_anonymize = true
|
||||
"--anonymize" -> Utils.anonymize = true
|
||||
"--stats" -> cmd_stats = true
|
||||
"--list-channels" -> cmd_list_channels = true
|
||||
else -> throw RuntimeException("Unknown command " + arg)
|
||||
|
@ -69,7 +69,7 @@ class Database constructor(val file_base: String, val user_manager: UserManager)
|
||||
}
|
||||
|
||||
// Run updates
|
||||
val updates = DatabaseUpdates(conn!!, this)
|
||||
val updates = DatabaseUpdates(conn, this)
|
||||
updates.doUpdates()
|
||||
|
||||
println("Database is ready.")
|
||||
@ -489,13 +489,7 @@ class Database constructor(val file_base: String, val user_manager: UserManager)
|
||||
ps_insert_or_replace.close()
|
||||
}
|
||||
|
||||
fun fetchSetting(key: String): String? {
|
||||
val rs = stmt.executeQuery("SELECT value FROM settings WHERE key='${key}'")
|
||||
rs.next()
|
||||
val result = rs.getString(1)
|
||||
rs.close()
|
||||
return result
|
||||
}
|
||||
fun fetchSetting(key: String): String? = queryString("SELECT value FROM settings WHERE key='${key}'")
|
||||
|
||||
fun saveSetting(key: String, value: String?) {
|
||||
val ps = conn.prepareStatement("INSERT OR REPLACE INTO settings (key, value) VALUES (?, ?)")
|
||||
|
@ -18,7 +18,6 @@ package de.fabianonline.telegram_backup
|
||||
|
||||
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.mediafilemanager.FileManagerFactory
|
||||
import de.fabianonline.telegram_backup.mediafilemanager.AbstractMediaFileManager
|
||||
|
@ -1,6 +1,15 @@
|
||||
package de.fabianonline.telegram_backup
|
||||
|
||||
import com.github.badoualy.telegram.api.Kotlogram
|
||||
import com.github.badoualy.telegram.api.TelegramApp
|
||||
import com.github.badoualy.telegram.api.TelegramClient
|
||||
import com.github.badoualy.telegram.tl.api.TLUser
|
||||
import com.github.badoualy.telegram.tl.api.account.TLPassword
|
||||
import com.github.badoualy.telegram.tl.api.auth.TLSentCode
|
||||
import com.github.badoualy.telegram.tl.core.TLBytes
|
||||
import com.github.badoualy.telegram.tl.exception.RpcErrorException
|
||||
import java.security.MessageDigest
|
||||
import java.util.*
|
||||
|
||||
class LoginManager(val app: TelegramApp, val target_dir: String, val phoneToUse: String?) {
|
||||
fun run() {
|
||||
@ -31,7 +40,7 @@ class LoginManager(val app: TelegramApp, val target_dir: String, val phoneToUse:
|
||||
val pw = getPassword()
|
||||
verify_password(client, pw)
|
||||
}
|
||||
System.out.println("Everything seems fine. Please run this tool again with '--account +" + user.user!!.getPhone().anonymize() + " to use this account.")
|
||||
System.out.println("Everything seems fine. Please run this tool again with '--account ${phone} to use this account.")
|
||||
}
|
||||
|
||||
private fun send_code_to_phone_number(client: TelegramClient, phone: String): TLSentCode {
|
||||
|
@ -1,52 +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 <http://www.gnu.org/licenses/>. */
|
||||
|
||||
package de.fabianonline.telegram_backup
|
||||
|
||||
import com.github.badoualy.telegram.tl.api.*
|
||||
import java.lang.StringBuilder
|
||||
import java.io.File
|
||||
|
||||
object StickerConverter {
|
||||
fun makeFilenameWithPath(attr: TLDocumentAttributeSticker): String {
|
||||
val file = StringBuilder()
|
||||
file.append(makePath())
|
||||
file.append(makeFilename(attr))
|
||||
return file.toString()
|
||||
}
|
||||
|
||||
fun makeFilename(attr: TLDocumentAttributeSticker): String {
|
||||
val file = StringBuilder()
|
||||
if (attr.getStickerset() is TLInputStickerSetShortName) {
|
||||
file.append((attr.getStickerset() as TLInputStickerSetShortName).getShortName())
|
||||
} else if (attr.getStickerset() is TLInputStickerSetID) {
|
||||
file.append((attr.getStickerset() as TLInputStickerSetID).getId())
|
||||
}
|
||||
file.append("_")
|
||||
file.append(attr.getAlt().hashCode())
|
||||
file.append(".webp")
|
||||
return file.toString()
|
||||
}
|
||||
|
||||
fun makePath(): String {
|
||||
val path = Config.FILE_BASE +
|
||||
File.separatorChar +
|
||||
Config.FILE_STICKER_BASE +
|
||||
File.separatorChar
|
||||
File(path).mkdirs()
|
||||
return path
|
||||
}
|
||||
}
|
@ -26,48 +26,39 @@ import de.fabianonline.telegram_backup.Database
|
||||
import de.fabianonline.telegram_backup.UserManager
|
||||
import de.fabianonline.telegram_backup.mediafilemanager.AbstractMediaFileManager
|
||||
import de.fabianonline.telegram_backup.mediafilemanager.FileManagerFactory
|
||||
import org.slf4j.LoggerFactory
|
||||
|
||||
internal class TelegramUpdateHandler : UpdateCallback {
|
||||
private var user: UserManager? = null
|
||||
private var db: Database? = null
|
||||
var debug = false
|
||||
|
||||
fun activate() {
|
||||
this.user = UserManager.getInstance()
|
||||
this.db = Database.getInstance()
|
||||
}
|
||||
internal class TelegramUpdateHandler(val user_manager: UserManager, val db: Database) : UpdateCallback {
|
||||
val logger = LoggerFactory.getLogger(TelegramUpdateHandler::class.java)
|
||||
|
||||
override fun onUpdates(client: TelegramClient, updates: TLUpdates) {
|
||||
if (db == null) return
|
||||
if (debug) System.out.println("onUpdates - " + updates.getUpdates().size + " Updates, " + updates.getUsers().size + " Users, " + updates.getChats().size + " Chats")
|
||||
|
||||
logger.debug("onUpdates - " + updates.getUpdates().size + " Updates, " + updates.getUsers().size + " Users, " + updates.getChats().size + " Chats")
|
||||
for (update in updates.getUpdates()) {
|
||||
processUpdate(update, client)
|
||||
if (debug) System.out.println(" " + update.javaClass.getName())
|
||||
logger.debug(" " + update.javaClass.getName())
|
||||
}
|
||||
db!!.saveUsers(updates.getUsers())
|
||||
db!!.saveChats(updates.getChats())
|
||||
db.saveUsers(updates.getUsers())
|
||||
db.saveChats(updates.getChats())
|
||||
}
|
||||
|
||||
override fun onUpdatesCombined(client: TelegramClient, updates: TLUpdatesCombined) {
|
||||
if (db == null) return
|
||||
if (debug) System.out.println("onUpdatesCombined")
|
||||
logger.debug("onUpdatesCombined")
|
||||
for (update in updates.getUpdates()) {
|
||||
processUpdate(update, client)
|
||||
}
|
||||
db!!.saveUsers(updates.getUsers())
|
||||
db!!.saveChats(updates.getChats())
|
||||
db.saveUsers(updates.getUsers())
|
||||
db.saveChats(updates.getChats())
|
||||
}
|
||||
|
||||
override fun onUpdateShort(client: TelegramClient, update: TLUpdateShort) {
|
||||
if (db == null) return
|
||||
if (debug) System.out.println("onUpdateShort")
|
||||
logger.debug("onUpdateShort")
|
||||
processUpdate(update.getUpdate(), client)
|
||||
if (debug) System.out.println(" " + update.getUpdate().javaClass.getName())
|
||||
logger.debug(" " + update.getUpdate().javaClass.getName())
|
||||
}
|
||||
|
||||
override fun onShortChatMessage(client: TelegramClient, message: TLUpdateShortChatMessage) {
|
||||
if (db == null) return
|
||||
if (debug) System.out.println("onShortChatMessage - " + message.getMessage())
|
||||
logger.debug("onShortChatMessage - " + message.getMessage())
|
||||
val msg = TLMessage(
|
||||
message.getOut(),
|
||||
message.getMentioned(),
|
||||
@ -85,21 +76,20 @@ internal class TelegramUpdateHandler : UpdateCallback {
|
||||
message.getEntities(), null, null)
|
||||
val vector = TLVector<TLAbsMessage>(TLAbsMessage::class.java)
|
||||
vector.add(msg)
|
||||
db!!.saveMessages(vector, Kotlogram.API_LAYER)
|
||||
db.saveMessages(vector, Kotlogram.API_LAYER)
|
||||
System.out.print('.')
|
||||
}
|
||||
|
||||
override fun onShortMessage(client: TelegramClient, message: TLUpdateShortMessage) {
|
||||
val m = message
|
||||
if (db == null) return
|
||||
if (debug) System.out.println("onShortMessage - " + m.getOut() + " - " + m.getUserId() + " - " + m.getMessage())
|
||||
logger.debug("onShortMessage - " + m.getOut() + " - " + m.getUserId() + " - " + m.getMessage())
|
||||
val from_id: Int
|
||||
val to_id: Int
|
||||
if (m.getOut() == true) {
|
||||
from_id = user!!.user!!.getId()
|
||||
from_id = user_manager.id
|
||||
to_id = m.getUserId()
|
||||
} else {
|
||||
to_id = user!!.user!!.getId()
|
||||
to_id = user_manager.id
|
||||
from_id = m.getUserId()
|
||||
}
|
||||
val msg = TLMessage(
|
||||
@ -119,18 +109,16 @@ internal class TelegramUpdateHandler : UpdateCallback {
|
||||
m.getEntities(), null, null)
|
||||
val vector = TLVector<TLAbsMessage>(TLAbsMessage::class.java)
|
||||
vector.add(msg)
|
||||
db!!.saveMessages(vector, Kotlogram.API_LAYER)
|
||||
db.saveMessages(vector, Kotlogram.API_LAYER)
|
||||
System.out.print('.')
|
||||
}
|
||||
|
||||
override fun onShortSentMessage(client: TelegramClient, message: TLUpdateShortSentMessage) {
|
||||
if (db == null) return
|
||||
System.out.println("onShortSentMessage")
|
||||
logger.debug("onShortSentMessage")
|
||||
}
|
||||
|
||||
override fun onUpdateTooLong(client: TelegramClient) {
|
||||
if (db == null) return
|
||||
System.out.println("onUpdateTooLong")
|
||||
logger.debug("onUpdateTooLong")
|
||||
}
|
||||
|
||||
private fun processUpdate(update: TLAbsUpdate, client: TelegramClient) {
|
||||
@ -138,10 +126,10 @@ internal class TelegramUpdateHandler : UpdateCallback {
|
||||
val abs_msg = update.getMessage()
|
||||
val vector = TLVector<TLAbsMessage>(TLAbsMessage::class.java)
|
||||
vector.add(abs_msg)
|
||||
db!!.saveMessages(vector, Kotlogram.API_LAYER)
|
||||
db.saveMessages(vector, Kotlogram.API_LAYER)
|
||||
System.out.print('.')
|
||||
if (abs_msg is TLMessage) {
|
||||
val fm = FileManagerFactory.getFileManager(abs_msg, user!!, client)
|
||||
val fm = FileManagerFactory.getFileManager(abs_msg, user_manager)
|
||||
if (fm != null && !fm.isEmpty && !fm.downloaded) {
|
||||
try {
|
||||
fm.download()
|
||||
|
@ -10,7 +10,7 @@ import java.sql.ResultSet
|
||||
import java.io.IOException
|
||||
import java.nio.charset.Charset
|
||||
|
||||
internal object TestFeatures {
|
||||
internal class TestFeatures(val db: Database) {
|
||||
fun test1() {
|
||||
// Tests entries in a cache4.db in the current working directory for compatibility
|
||||
try {
|
||||
@ -24,31 +24,22 @@ internal object TestFeatures {
|
||||
var conn: Connection
|
||||
var stmt: Statement? = null
|
||||
|
||||
try {
|
||||
conn = DriverManager.getConnection(path)
|
||||
stmt = conn.createStatement()
|
||||
} catch (e: SQLException) {
|
||||
CommandLineController.show_error("Could not connect to SQLITE database.")
|
||||
}
|
||||
conn = DriverManager.getConnection(path)
|
||||
stmt = conn.createStatement()
|
||||
|
||||
var unsupported_constructor = 0
|
||||
var success = 0
|
||||
|
||||
try {
|
||||
val rs = stmt!!.executeQuery("SELECT data FROM messages")
|
||||
while (rs.next()) {
|
||||
try {
|
||||
TLApiContext.getInstance().deserializeMessage(rs.getBytes(1))
|
||||
} catch (e: com.github.badoualy.telegram.tl.exception.UnsupportedConstructorException) {
|
||||
unsupported_constructor++
|
||||
} catch (e: IOException) {
|
||||
System.out.println("IOException: " + e)
|
||||
}
|
||||
|
||||
success++
|
||||
val rs = stmt.executeQuery("SELECT data FROM messages")
|
||||
while (rs.next()) {
|
||||
try {
|
||||
TLApiContext.getInstance().deserializeMessage(rs.getBytes(1))
|
||||
} catch (e: com.github.badoualy.telegram.tl.exception.UnsupportedConstructorException) {
|
||||
unsupported_constructor++
|
||||
} catch (e: IOException) {
|
||||
System.out.println("IOException: " + e)
|
||||
}
|
||||
} catch (e: SQLException) {
|
||||
System.out.println("SQL exception: " + e)
|
||||
success++
|
||||
}
|
||||
|
||||
System.out.println("Success: " + success)
|
||||
@ -59,7 +50,6 @@ internal object TestFeatures {
|
||||
// Prints system.encoding and default charset
|
||||
System.out.println("Default Charset: " + Charset.defaultCharset())
|
||||
System.out.println("file.encoding: " + System.getProperty("file.encoding"))
|
||||
val db = Database.getInstance()
|
||||
System.out.println("Database encoding: " + db.getEncoding())
|
||||
}
|
||||
}
|
||||
|
@ -48,7 +48,7 @@ class UserManager(val client: TelegramClient) {
|
||||
tl_user = full_user.getUser().getAsUser()
|
||||
}
|
||||
|
||||
fun toString(): String {
|
||||
override fun toString(): String {
|
||||
val sb = StringBuilder()
|
||||
sb.append(tl_user.getFirstName() ?: "")
|
||||
if (tl_user.getLastName() != null) {
|
||||
|
@ -32,6 +32,8 @@ object Utils {
|
||||
@JvmField public val VERSION_1_NEWER = 1
|
||||
@JvmField public val VERSION_2_NEWER = 2
|
||||
|
||||
var anonymize = false
|
||||
|
||||
private val logger = LoggerFactory.getLogger(Utils::class.java) as Logger
|
||||
|
||||
fun print_accounts(file_base: String) {
|
||||
@ -193,7 +195,7 @@ object Utils {
|
||||
}
|
||||
|
||||
fun String.anonymize(): String {
|
||||
return if (!CommandLineOptions.cmd_anonymize) this else this.replace(Regex("[0-9]"), "1").replace(Regex("[A-Z]"), "A").replace(Regex("[a-z]"), "a") + " (ANONYMIZED)"
|
||||
return if (Utils.anonymize) this else this.replace(Regex("[0-9]"), "1").replace(Regex("[A-Z]"), "A").replace(Regex("[a-z]"), "a") + " (ANONYMIZED)"
|
||||
}
|
||||
|
||||
fun Any.toJson(): String = Gson().toJson(this)
|
||||
|
@ -37,18 +37,15 @@ import de.fabianonline.telegram_backup.*
|
||||
import org.slf4j.Logger
|
||||
import org.slf4j.LoggerFactory
|
||||
|
||||
class HTMLExporter {
|
||||
val db = Database.getInstance()
|
||||
val user = UserManager.getInstance()
|
||||
|
||||
class HTMLExporter(val db: Database, val user: UserManager, val ini: IniSettings, val file_base: String) {
|
||||
@Throws(IOException::class)
|
||||
fun export() {
|
||||
try {
|
||||
val pagination = if (IniSettings.pagination) IniSettings.pagination_size else -1
|
||||
val pagination = if (ini.pagination) ini.pagination_size else -1
|
||||
|
||||
// Create base dir
|
||||
logger.debug("Creating base dir")
|
||||
val base = user.fileBase + "files" + File.separatorChar
|
||||
val base = file_base + "files" + File.separatorChar
|
||||
File(base).mkdirs()
|
||||
File(base + "dialogs").mkdirs()
|
||||
|
||||
|
@ -17,33 +17,16 @@
|
||||
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.Config
|
||||
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
|
||||
|
||||
abstract class AbstractMediaFileManager(protected var message: TLMessage, protected var user: UserManager) {
|
||||
abstract class AbstractMediaFileManager(protected var message: TLMessage, protected var user: UserManager, val file_base: String) {
|
||||
open var isEmpty = false
|
||||
abstract val size: Int
|
||||
abstract val extension: String
|
||||
@ -56,7 +39,7 @@ abstract class AbstractMediaFileManager(protected var message: TLMessage, protec
|
||||
|
||||
open val targetPath: String
|
||||
get() {
|
||||
val path = user.fileBase + Config.FILE_FILES_BASE + File.separatorChar
|
||||
val path = file_base + Config.FILE_FILES_BASE + File.separatorChar
|
||||
File(path).mkdirs()
|
||||
return path
|
||||
}
|
||||
|
@ -17,32 +17,15 @@
|
||||
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
|
||||
|
||||
open class DocumentFileManager(msg: TLMessage, user: UserManager) : AbstractMediaFileManager(msg, user) {
|
||||
open class DocumentFileManager(msg: TLMessage, user: UserManager, file_base: String) : AbstractMediaFileManager(msg, user, file_base) {
|
||||
protected var doc: TLDocument? = null
|
||||
override lateinit var extension: String
|
||||
|
||||
|
@ -18,7 +18,6 @@ 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 com.github.badoualy.telegram.api.TelegramClient
|
||||
|
@ -17,33 +17,15 @@
|
||||
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 de.fabianonline.telegram_backup.IniSettings
|
||||
|
||||
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
|
||||
|
||||
class GeoFileManager(msg: TLMessage, user: UserManager) : AbstractMediaFileManager(msg, user) {
|
||||
class GeoFileManager(msg: TLMessage, user: UserManager, file_base: String) : AbstractMediaFileManager(msg, user, file_base) {
|
||||
protected lateinit var geo: TLGeoPoint
|
||||
|
||||
// We don't know the size, so we just guess.
|
||||
|
@ -17,32 +17,15 @@
|
||||
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
|
||||
|
||||
class PhotoFileManager(msg: TLMessage, user: UserManager) : AbstractMediaFileManager(msg, user) {
|
||||
class PhotoFileManager(msg: TLMessage, user: UserManager, file_base: String) : AbstractMediaFileManager(msg, user, file_base) {
|
||||
private lateinit var photo: TLPhoto
|
||||
override var size = 0
|
||||
private lateinit var photo_size: TLPhotoSize
|
||||
|
@ -18,7 +18,6 @@ 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 de.fabianonline.telegram_backup.Config
|
||||
@ -50,7 +49,7 @@ import java.util.concurrent.TimeoutException
|
||||
|
||||
import org.apache.commons.io.FileUtils
|
||||
|
||||
class StickerFileManager(msg: TLMessage, user: UserManager) : DocumentFileManager(msg, user) {
|
||||
class StickerFileManager(msg: TLMessage, user: UserManager, file_base: String) : DocumentFileManager(msg, user, file_base) {
|
||||
|
||||
override val isSticker = true
|
||||
|
||||
@ -80,7 +79,7 @@ class StickerFileManager(msg: TLMessage, user: UserManager) : DocumentFileManage
|
||||
|
||||
override val targetPath: String
|
||||
get() {
|
||||
val path = user.fileBase + Config.FILE_FILES_BASE + File.separatorChar + Config.FILE_STICKER_BASE + File.separatorChar
|
||||
val path = file_base + Config.FILE_FILES_BASE + File.separatorChar + Config.FILE_STICKER_BASE + File.separatorChar
|
||||
File(path).mkdirs()
|
||||
return path
|
||||
}
|
||||
@ -94,19 +93,6 @@ class StickerFileManager(msg: TLMessage, user: UserManager) : DocumentFileManage
|
||||
override val description: String
|
||||
get() = "Sticker"
|
||||
|
||||
@Throws(RpcErrorException::class, IOException::class, TimeoutException::class)
|
||||
override fun download(): Boolean {
|
||||
val old_file = Config.FILE_BASE + File.separatorChar + Config.FILE_STICKER_BASE + File.separatorChar + targetFilename
|
||||
|
||||
logger.trace("Old filename exists: {}", File(old_file).exists())
|
||||
|
||||
if (File(old_file).exists()) {
|
||||
Files.copy(Paths.get(old_file), Paths.get(targetPathAndFilename), StandardCopyOption.REPLACE_EXISTING)
|
||||
return true
|
||||
}
|
||||
return super.download()
|
||||
}
|
||||
|
||||
companion object {
|
||||
private val logger = LoggerFactory.getLogger(StickerFileManager::class.java)
|
||||
}
|
||||
|
@ -17,33 +17,10 @@
|
||||
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 de.fabianonline.telegram_backup.Config
|
||||
|
||||
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
|
||||
|
||||
class UnsupportedFileManager(msg: TLMessage, user: UserManager, type: String) : AbstractMediaFileManager(msg, user) {
|
||||
class UnsupportedFileManager(msg: TLMessage, user: UserManager, type: String, file_base: String) : AbstractMediaFileManager(msg, user, file_base) {
|
||||
override var name = type
|
||||
override val targetFilename = ""
|
||||
override val targetPath = ""
|
||||
|
Loading…
Reference in New Issue
Block a user