Added a setting max_file_size to ignore files bigger than that size in MB.

This commit is contained in:
Fabian Schlenz 2018-04-20 06:08:17 +02:00
parent b1e9346203
commit 7e2d49ef09
5 changed files with 14 additions and 7 deletions

View File

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

View File

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

View File

@ -29,5 +29,5 @@ interface DownloadProgressInterface {
fun onMediaSkipped()
fun onMediaAlreadyPresent(file_manager: AbstractMediaFileManager)
fun onMediaDownloadFinished()
fun onMediaTooOld()
fun onMediaFailed()
}

View File

@ -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<String>())
val blacklist_channels = sf.getStringList("blacklist_channels", default=LinkedList<String>())
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<String>? {
return ini_settings[name]

View File

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