1
0
mirror of https://github.com/fabianonline/telegram_backup.git synced 2024-12-26 06:45:33 +00:00

Moved more settings to IniSettings.

This commit is contained in:
Fabian Schlenz 2018-03-10 23:26:03 +01:00
parent 89cca39409
commit 19973818f8
6 changed files with 20 additions and 29 deletions

View File

@ -137,12 +137,12 @@ class CommandLineController {
val d = DownloadManager(client, CommandLineDownloadProgress())
logger.debug("Calling DownloadManager.downloadMessages with limit {}", CommandLineOptions.val_limit_messages)
d.downloadMessages(CommandLineOptions.val_limit_messages)
logger.debug("CommandLineOptions.cmd_no_media: {}", CommandLineOptions.cmd_no_media)
if (!CommandLineOptions.cmd_no_media) {
logger.debug("IniSettings.download_media: {}", IniSettings.download_media)
if (IniSettings.download_media) {
logger.debug("Calling DownloadManager.downloadMedia")
d.downloadMedia()
} else {
println("Skipping media download because --no-media is set.")
println("Skipping media download because download_media is set to false.")
}
} catch (e: Exception) {
e.printStackTrace()
@ -277,17 +277,12 @@ class CommandLineController {
println(" --trace-telegram Shows lots of debug messages from the library used to access Telegram.")
println(" -A, --list-accounts List all existing accounts ")
println(" --limit-messages <x> Downloads at most the most recent <x> messages.")
println(" --no-media Do not download media files.")
println(" -t, --target <x> Target directory for the files.")
println(" -e, --export <format> Export the database. Valid formats are:")
println(" html - Creates HTML files.")
println(" --pagination <x> Splits the HTML export into multiple HTML pages with <x> messages per page. Default is 5000.")
println(" --no-pagination Disables pagination.")
println(" --license Displays the license of this program.")
println(" --anonymize (Try to) Remove all sensitive information from output. Useful for requesting support.")
println(" --stats Print some usage statistics.")
println(" --with-channels Backup channels as well.")
println(" --with-supergroups Backup supergroups as well.")
}
private fun list_accounts() {

View File

@ -26,18 +26,13 @@ internal object CommandLineOptions {
var cmd_version = false
var cmd_license = false
var cmd_daemon = false
var cmd_no_media = false
var cmd_anonymize = false
var cmd_stats = false
var cmd_channels = false
var cmd_supergroups = false
var cmd_no_pagination = false
var val_account: String? = null
var val_limit_messages: Int? = null
var val_target: String? = null
var val_export: String? = null
var val_test: Int? = null
var val_pagination: Int = Config.DEFAULT_PAGINATION
@JvmStatic
fun parseOptions(args: Array<String>) {
var last_cmd: String? = null
@ -49,7 +44,6 @@ internal object CommandLineOptions {
"--target" -> val_target = arg
"--export" -> val_export = arg
"--test" -> val_test = Integer.parseInt(arg)
"--pagination" -> val_pagination = Integer.parseInt(arg)
}
last_cmd = null
continue
@ -83,18 +77,14 @@ internal object CommandLineOptions {
last_cmd = "--pagination"
continue@loop
}
"--no-pagination" -> cmd_no_pagination = true
"--license" -> cmd_license = true
"-d", "--daemon" -> cmd_daemon = true
"--no-media" -> cmd_no_media = true
"--test" -> {
last_cmd = "--test"
continue@loop
}
"--anonymize" -> cmd_anonymize = true
"--stats" -> cmd_stats = true
"--with-channels" -> cmd_channels = true
"--with-supergroups" -> cmd_supergroups = true
else -> throw RuntimeException("Unknown command " + arg)
}
}

View File

@ -178,7 +178,7 @@ class DownloadManager(internal var client: TelegramClient?, p: DownloadProgressI
}
*/
if (CommandLineOptions.cmd_channels || CommandLineOptions.cmd_supergroups) {
if (IniSettings.download_channels || IniSettings.download_supergroups) {
System.out.println("Processing channels and/or supergroups...")
System.out.println("Please note that only channels/supergroups in the last 100 active chats are processed.")
@ -210,7 +210,7 @@ class DownloadManager(internal var client: TelegramClient?, p: DownloadProgressI
// If this is a channel and we don't want to download channels OR
// it is a supergroups and we don't want to download supergroups, then
if (channels.contains(channel_id) && !CommandLineOptions.cmd_channels || supergroups.contains(channel_id) && !CommandLineOptions.cmd_supergroups) {
if (channels.contains(channel_id) && !IniSettings.download_channels || supergroups.contains(channel_id) && !IniSettings.download_supergroups) {
// Skip this chat.
continue
}

View File

@ -56,8 +56,19 @@ object IniSettings {
fun get(key: String, default: String? = null): String? = settings.get(key)?.last() ?: default
fun getInt(key: String, default: Int? = null): Int? = try { settings.get(key)?.last()?.toInt() } catch (e: NumberFormatException) { null } ?: default
fun getBoolean(key: String, default: Boolean = false): Boolean = settings.get(key)?.last() == "true"
fun getArray(key: String): List<String> = settings.get(key) ?: listOf<String>()
val gmaps_key: String
get() = get("gmaps_key", default=Config.SECRET_GMAPS)!!
val pagination: Boolean
get() = getBoolean("pagination", default=true)
val pagination_size: Int
get() = getInt("pagination_size", default=Config.DEFAULT_PAGINATION)!!
val download_media: Boolean
get() = getBoolean("download_media", default=true)
val download_channels: Boolean
get() = getBoolean("download_channels", default=false)
val download_supergroups: Boolean
get() = getBoolean("download_supergroups", default=false)
}

View File

@ -16,12 +16,6 @@
package de.fabianonline.telegram_backup.exporter
import de.fabianonline.telegram_backup.UserManager
import de.fabianonline.telegram_backup.Database
import de.fabianonline.telegram_backup.anonymize
import de.fabianonline.telegram_backup.toPrettyJson
import de.fabianonline.telegram_backup.CommandLineOptions
import java.io.File
import java.io.PrintWriter
import java.io.OutputStreamWriter
@ -38,6 +32,7 @@ import java.util.HashMap
import com.github.mustachejava.DefaultMustacheFactory
import com.github.mustachejava.Mustache
import com.github.mustachejava.MustacheFactory
import de.fabianonline.telegram_backup.*
import org.slf4j.Logger
import org.slf4j.LoggerFactory
@ -49,7 +44,7 @@ class HTMLExporter {
@Throws(IOException::class)
fun export() {
try {
val pagination = if (CommandLineOptions.cmd_no_pagination) -1 else CommandLineOptions.val_pagination
val pagination = if (IniSettings.pagination) IniSettings.pagination_size else -1
// Create base dir
logger.debug("Creating base dir")

View File

@ -15,8 +15,8 @@
# pagination = true
# pagination_size = 5000
## Don't download media files
# no_media = false
## Download media files
# download_media = true
## Don't download supergroups and channels by default
# download_channels = false