1
0
mirror of https://github.com/fabianonline/telegram_backup.git synced 2024-11-22 08:46:15 +00:00

updated telegram schema and fixed bugs with unused methods

This commit is contained in:
Yura Beznos 2018-09-21 14:36:25 +03:00
parent 223a0fdde3
commit 5161df17eb
8 changed files with 23 additions and 12 deletions

View File

@ -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'
}

View File

@ -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) {

View File

@ -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
}

View File

@ -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.")

View File

@ -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
}
}

View File

@ -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)
}

View File

@ -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

View File

@ -7,7 +7,7 @@
{{/is_new_date}}
<li class="message {{#from_me}}from-me{{/from_me}} {{odd_even}} {{#same_user}}same-user{{/same_user}}" data-message-id="{{message_id}}" data-media="{{media_type}}">
<span class="time">{{formatted_time}}</span>
<span class="sender">{{user_first_name}}</span>
<span class="sender">{{user_first_name}} {{#user_last_name}}{{user_last_name}}{{/user_last_name}}</span>
{{#text}}<span class="text">{{text}}</span>{{/text}}
{{#media_sticker}}<span class="sticker"><img src="../stickers/{{media_file}}" /></span>{{/media_sticker}}
{{#media_photo}}<span class="photo"><img src="../{{media_file}}" /></span>{{/media_photo}}