Added max_file_age to download only newer files.

This commit is contained in:
Fabian Schlenz 2018-03-15 06:48:37 +01:00
parent 6276651b84
commit 968ee831f0
5 changed files with 10 additions and 0 deletions

View File

@ -52,6 +52,7 @@ internal class CommandLineDownloadProgress : DownloadProgressInterface {
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 errors - will be tried again at next run")
println("'_' - Message is older than max_file_age")
println("" + count + " Files to check / download") println("" + count + " Files to check / download")
} }
@ -75,6 +76,8 @@ internal class CommandLineDownloadProgress : DownloadProgressInterface {
showNewLine() showNewLine()
println("Done.") println("Done.")
} }
override fun onMediaTooOld() = show("_")
private fun show(letter: String) { private fun show(letter: String) {
print(letter) print(letter)

View File

@ -326,6 +326,8 @@ class DownloadManager(internal var client: TelegramClient?, p: DownloadProgressI
prog!!.onMediaDownloadedEmpty() prog!!.onMediaDownloadedEmpty()
} else if (m.downloaded) { } else if (m.downloaded) {
prog!!.onMediaAlreadyPresent(m) prog!!.onMediaAlreadyPresent(m)
} else if (IniSettings.max_file_age!=null && (System.currentTimeMillis() / 1000) - msg.date > IniSettings.max_file_age * 24 * 60 * 60) {
prog!!.onMediaTooOld()
} else { } else {
try { try {
val result = m.download() val result = m.download()

View File

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

View File

@ -82,4 +82,5 @@ object IniSettings {
get() = getStringList("whitelist_channels") get() = getStringList("whitelist_channels")
val blacklist_channels: List<String>? val blacklist_channels: List<String>?
get() = getStringList("blacklist_channels") get() = getStringList("blacklist_channels")
val max_file_age = getInt("max_file_age")
} }

View File

@ -18,6 +18,9 @@
## Download media files ## Download media files
# download_media = true # download_media = true
## Only download media files from messages that are never than x days.
## Leave unset to download all media files.
# max_file_age = 7
## Downloads of channels and supergroups ## Downloads of channels and supergroups