mirror of
https://github.com/fabianonline/telegram_backup.git
synced 2024-11-22 16:56:16 +00:00
Added a setting max_file_size to ignore files bigger than that size in MB.
This commit is contained in:
parent
b1e9346203
commit
7e2d49ef09
@ -51,8 +51,8 @@ internal class CommandLineDownloadProgress : DownloadProgressInterface {
|
|||||||
println("'S' - Sticker 'A' - Audio 'G' - Geolocation")
|
println("'S' - Sticker 'A' - Audio 'G' - Geolocation")
|
||||||
println("'.' - Previously downloaded file 'e' - Empty file")
|
println("'.' - Previously downloaded file 'e' - Empty file")
|
||||||
println("' ' - Ignored media type (weblinks or contacts, for example)")
|
println("' ' - Ignored media type (weblinks or contacts, for example)")
|
||||||
println("'x' - File skipped because of errors - will be tried again at next run")
|
println("'x' - File skipped (because of max_file_age or max_file_size)")
|
||||||
println("'_' - Message is older than max_file_age")
|
println("'!' - Download failed. Will be tried again at next run.")
|
||||||
println("" + count + " Files to check / download")
|
println("" + count + " Files to check / download")
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -77,7 +77,7 @@ internal class CommandLineDownloadProgress : DownloadProgressInterface {
|
|||||||
println("Done.")
|
println("Done.")
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onMediaTooOld() = show("_")
|
override fun onMediaFailed() = show("!")
|
||||||
|
|
||||||
private fun show(letter: String) {
|
private fun show(letter: String) {
|
||||||
print(letter)
|
print(letter)
|
||||||
|
@ -256,18 +256,20 @@ class DownloadManager(val client: TelegramClient, val prog: DownloadProgressInte
|
|||||||
} else if (m.downloaded) {
|
} else if (m.downloaded) {
|
||||||
prog.onMediaAlreadyPresent(m)
|
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) - 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 {
|
} else {
|
||||||
try {
|
try {
|
||||||
val result = m.download()
|
val result = m.download()
|
||||||
if (result) {
|
if (result) {
|
||||||
prog.onMediaDownloaded(m)
|
prog.onMediaDownloaded(m)
|
||||||
} else {
|
} else {
|
||||||
prog.onMediaSkipped()
|
prog.onMediaFailed()
|
||||||
}
|
}
|
||||||
} catch (e: TimeoutException) {
|
} catch (e: TimeoutException) {
|
||||||
// do nothing - skip this file
|
// do nothing - skip this file
|
||||||
prog.onMediaSkipped()
|
prog.onMediaFailed()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -29,5 +29,5 @@ interface DownloadProgressInterface {
|
|||||||
fun onMediaSkipped()
|
fun onMediaSkipped()
|
||||||
fun onMediaAlreadyPresent(file_manager: AbstractMediaFileManager)
|
fun onMediaAlreadyPresent(file_manager: AbstractMediaFileManager)
|
||||||
fun onMediaDownloadFinished()
|
fun onMediaDownloadFinished()
|
||||||
fun onMediaTooOld()
|
fun onMediaFailed()
|
||||||
}
|
}
|
||||||
|
@ -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 whitelist_channels = sf.getStringList("whitelist_channels", default=LinkedList<String>())
|
||||||
val blacklist_channels = sf.getStringList("blacklist_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_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>? {
|
private fun get_setting_list(name: String): List<String>? {
|
||||||
return ini_settings[name]
|
return ini_settings[name]
|
||||||
|
@ -22,6 +22,10 @@
|
|||||||
## Leave unset to download all media files.
|
## Leave unset to download all media files.
|
||||||
# max_file_age = 7
|
# 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
|
## Downloads of channels and supergroups
|
||||||
## Here you can specify which channels and supergroups
|
## Here you can specify which channels and supergroups
|
||||||
|
Loading…
Reference in New Issue
Block a user