1
0
mirror of https://github.com/fabianonline/telegram_backup.git synced 2025-07-17 11:16:23 +00:00

MediaFileManagers now use JSON instead of the TLMessage objects.

This commit is contained in:
2018-04-17 06:36:39 +02:00
parent 6b5b9a669b
commit bb2a291d4f
12 changed files with 143 additions and 112 deletions

View File

@@ -36,6 +36,7 @@ import com.github.badoualy.telegram.tl.api.request.TLRequestUploadGetFile
import org.slf4j.LoggerFactory
import org.slf4j.Logger
import com.google.gson.Gson
import com.github.salomonbrys.kotson.*
import com.github.kittinunf.fuel.Fuel
import com.github.kittinunf.result.Result
import com.github.kittinunf.result.getAs
@@ -243,20 +244,21 @@ class DownloadManager(val client: TelegramClient, val prog: DownloadProgressInte
offset += limit
logger.debug("Database returned {} messages with media", messages.size)
prog.onMediaDownloadStart(messages.size)
for (msg in messages) {
if (msg == null) continue
val m = FileManagerFactory.getFileManager(msg, user_manager, file_base, settings=settings)
for (pair in messages) {
val id = pair.first
val json = pair.second
try {
val m = FileManagerFactory.getFileManager(json, file_base, settings=settings)!!
logger.trace("message {}, {}, {}, {}, {}",
msg.getId(),
msg.getMedia().javaClass.getSimpleName().replace("TLMessageMedia", ""),
m!!.javaClass.getSimpleName(),
id,
m.javaClass.getSimpleName(),
if (m.isEmpty) "empty" else "non-empty",
if (m.downloaded) "downloaded" else "not downloaded")
if (m.isEmpty) {
prog.onMediaDownloadedEmpty()
} else if (m.downloaded) {
prog.onMediaAlreadyPresent(m)
} else if (settings.max_file_age>0 && (System.currentTimeMillis() / 1000) - msg.date > settings.max_file_age * 24 * 60 * 60) {
} else if (settings.max_file_age>0 && (System.currentTimeMillis() / 1000) - json["date"].int > settings.max_file_age * 24 * 60 * 60) {
prog.onMediaTooOld()
} else {
try {
@@ -269,8 +271,13 @@ class DownloadManager(val client: TelegramClient, val prog: DownloadProgressInte
} catch (e: TimeoutException) {
// do nothing - skip this file
prog.onMediaSkipped()
}
}
} catch (e: IllegalStateException) {
println(json.toPrettyJson())
throw e
}
}
}
prog.onMediaDownloadFinished()