diff --git a/src/main/kotlin/de/fabianonline/telegram_backup/CommandLineDownloadProgress.kt b/src/main/kotlin/de/fabianonline/telegram_backup/CommandLineDownloadProgress.kt index 90824cd..1085c16 100644 --- a/src/main/kotlin/de/fabianonline/telegram_backup/CommandLineDownloadProgress.kt +++ b/src/main/kotlin/de/fabianonline/telegram_backup/CommandLineDownloadProgress.kt @@ -51,8 +51,8 @@ internal class CommandLineDownloadProgress : DownloadProgressInterface { println("'S' - Sticker 'A' - Audio 'G' - Geolocation") println("'.' - Previously downloaded file 'e' - Empty file") println("' ' - Ignored media type (weblinks or contacts, for example)") - println("'x' - File skipped because of errors - will be tried again at next run") - println("'_' - Message is older than max_file_age") + println("'x' - File skipped (because of max_file_age or max_file_size)") + println("'!' - Download failed. Will be tried again at next run.") println("" + count + " Files to check / download") } @@ -77,7 +77,7 @@ internal class CommandLineDownloadProgress : DownloadProgressInterface { println("Done.") } - override fun onMediaTooOld() = show("_") + override fun onMediaFailed() = show("!") private fun show(letter: String) { print(letter) diff --git a/src/main/kotlin/de/fabianonline/telegram_backup/DownloadManager.kt b/src/main/kotlin/de/fabianonline/telegram_backup/DownloadManager.kt index f17c78e..c52a656 100644 --- a/src/main/kotlin/de/fabianonline/telegram_backup/DownloadManager.kt +++ b/src/main/kotlin/de/fabianonline/telegram_backup/DownloadManager.kt @@ -256,18 +256,20 @@ class DownloadManager(val client: TelegramClient, val prog: DownloadProgressInte } 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) { - prog.onMediaTooOld() + prog.onMediaSkipped() + } else if (settings.max_file_size>0 && settings.max_file_size*1024*1024 > m.size) { + prog.onMediaSkipped() } else { try { val result = m.download() if (result) { prog.onMediaDownloaded(m) } else { - prog.onMediaSkipped() + prog.onMediaFailed() } } catch (e: TimeoutException) { // do nothing - skip this file - prog.onMediaSkipped() + prog.onMediaFailed() } } } diff --git a/src/main/kotlin/de/fabianonline/telegram_backup/DownloadProgressInterface.kt b/src/main/kotlin/de/fabianonline/telegram_backup/DownloadProgressInterface.kt index 6829831..348781c 100644 --- a/src/main/kotlin/de/fabianonline/telegram_backup/DownloadProgressInterface.kt +++ b/src/main/kotlin/de/fabianonline/telegram_backup/DownloadProgressInterface.kt @@ -29,5 +29,5 @@ interface DownloadProgressInterface { fun onMediaSkipped() fun onMediaAlreadyPresent(file_manager: AbstractMediaFileManager) fun onMediaDownloadFinished() - fun onMediaTooOld() + fun onMediaFailed() } diff --git a/src/main/kotlin/de/fabianonline/telegram_backup/Settings.kt b/src/main/kotlin/de/fabianonline/telegram_backup/Settings.kt index c882301..1826b6f 100644 --- a/src/main/kotlin/de/fabianonline/telegram_backup/Settings.kt +++ b/src/main/kotlin/de/fabianonline/telegram_backup/Settings.kt @@ -28,6 +28,7 @@ class Settings(val file_base: String, val database: Database, val cli_settings: val whitelist_channels = sf.getStringList("whitelist_channels", default=LinkedList()) val blacklist_channels = sf.getStringList("blacklist_channels", default=LinkedList()) val max_file_age = sf.getInt("max_file_age", default=-1) + val max_file_size = sf.getInt("max_file_size", default=-1) private fun get_setting_list(name: String): List? { return ini_settings[name] diff --git a/src/main/resources/config.sample.ini b/src/main/resources/config.sample.ini index 1a4d88e..ca08d31 100644 --- a/src/main/resources/config.sample.ini +++ b/src/main/resources/config.sample.ini @@ -22,6 +22,10 @@ ## Leave unset to download all media files. # max_file_age = 7 +## Only download media files that are smaller than x MB. +## Leave unset to download media files regardless of their size. +# max_file_size = 5 + ## Downloads of channels and supergroups ## Here you can specify which channels and supergroups