Skip to content
This repository has been archived by the owner on Apr 27, 2020. It is now read-only.

Commit

Permalink
Added a setting max_file_size to ignore files bigger than that size i…
Browse files Browse the repository at this point in the history
…n MB.
  • Loading branch information
fabianonline committed Apr 20, 2018
1 parent b1e9346 commit 7e2d49e
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 29,5 @@ interface DownloadProgressInterface {
fun onMediaSkipped()
fun onMediaAlreadyPresent(file_manager: AbstractMediaFileManager)
fun onMediaDownloadFinished()
fun onMediaTooOld()
fun onMediaFailed()
}
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
4 changes: 4 additions & 0 deletions src/main/resources/config.sample.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 7e2d49e

Please sign in to comment.