mirror of
https://github.com/fabianonline/telegram_backup.git
synced 2024-11-22 16:56:16 +00:00
Moved more settings to IniSettings.
This commit is contained in:
parent
89cca39409
commit
19973818f8
@ -137,12 +137,12 @@ class CommandLineController {
|
|||||||
val d = DownloadManager(client, CommandLineDownloadProgress())
|
val d = DownloadManager(client, CommandLineDownloadProgress())
|
||||||
logger.debug("Calling DownloadManager.downloadMessages with limit {}", CommandLineOptions.val_limit_messages)
|
logger.debug("Calling DownloadManager.downloadMessages with limit {}", CommandLineOptions.val_limit_messages)
|
||||||
d.downloadMessages(CommandLineOptions.val_limit_messages)
|
d.downloadMessages(CommandLineOptions.val_limit_messages)
|
||||||
logger.debug("CommandLineOptions.cmd_no_media: {}", CommandLineOptions.cmd_no_media)
|
logger.debug("IniSettings.download_media: {}", IniSettings.download_media)
|
||||||
if (!CommandLineOptions.cmd_no_media) {
|
if (IniSettings.download_media) {
|
||||||
logger.debug("Calling DownloadManager.downloadMedia")
|
logger.debug("Calling DownloadManager.downloadMedia")
|
||||||
d.downloadMedia()
|
d.downloadMedia()
|
||||||
} else {
|
} else {
|
||||||
println("Skipping media download because --no-media is set.")
|
println("Skipping media download because download_media is set to false.")
|
||||||
}
|
}
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
e.printStackTrace()
|
e.printStackTrace()
|
||||||
@ -277,17 +277,12 @@ class CommandLineController {
|
|||||||
println(" --trace-telegram Shows lots of debug messages from the library used to access Telegram.")
|
println(" --trace-telegram Shows lots of debug messages from the library used to access Telegram.")
|
||||||
println(" -A, --list-accounts List all existing accounts ")
|
println(" -A, --list-accounts List all existing accounts ")
|
||||||
println(" --limit-messages <x> Downloads at most the most recent <x> messages.")
|
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(" -t, --target <x> Target directory for the files.")
|
||||||
println(" -e, --export <format> Export the database. Valid formats are:")
|
println(" -e, --export <format> Export the database. Valid formats are:")
|
||||||
println(" html - Creates HTML files.")
|
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(" --license Displays the license of this program.")
|
||||||
println(" --anonymize (Try to) Remove all sensitive information from output. Useful for requesting support.")
|
println(" --anonymize (Try to) Remove all sensitive information from output. Useful for requesting support.")
|
||||||
println(" --stats Print some usage statistics.")
|
println(" --stats Print some usage statistics.")
|
||||||
println(" --with-channels Backup channels as well.")
|
|
||||||
println(" --with-supergroups Backup supergroups as well.")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun list_accounts() {
|
private fun list_accounts() {
|
||||||
|
@ -26,18 +26,13 @@ internal object CommandLineOptions {
|
|||||||
var cmd_version = false
|
var cmd_version = false
|
||||||
var cmd_license = false
|
var cmd_license = false
|
||||||
var cmd_daemon = false
|
var cmd_daemon = false
|
||||||
var cmd_no_media = false
|
|
||||||
var cmd_anonymize = false
|
var cmd_anonymize = false
|
||||||
var cmd_stats = 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_account: String? = null
|
||||||
var val_limit_messages: Int? = null
|
var val_limit_messages: Int? = null
|
||||||
var val_target: String? = null
|
var val_target: String? = null
|
||||||
var val_export: String? = null
|
var val_export: String? = null
|
||||||
var val_test: Int? = null
|
var val_test: Int? = null
|
||||||
var val_pagination: Int = Config.DEFAULT_PAGINATION
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun parseOptions(args: Array<String>) {
|
fun parseOptions(args: Array<String>) {
|
||||||
var last_cmd: String? = null
|
var last_cmd: String? = null
|
||||||
@ -49,7 +44,6 @@ internal object CommandLineOptions {
|
|||||||
"--target" -> val_target = arg
|
"--target" -> val_target = arg
|
||||||
"--export" -> val_export = arg
|
"--export" -> val_export = arg
|
||||||
"--test" -> val_test = Integer.parseInt(arg)
|
"--test" -> val_test = Integer.parseInt(arg)
|
||||||
"--pagination" -> val_pagination = Integer.parseInt(arg)
|
|
||||||
}
|
}
|
||||||
last_cmd = null
|
last_cmd = null
|
||||||
continue
|
continue
|
||||||
@ -83,18 +77,14 @@ internal object CommandLineOptions {
|
|||||||
last_cmd = "--pagination"
|
last_cmd = "--pagination"
|
||||||
continue@loop
|
continue@loop
|
||||||
}
|
}
|
||||||
"--no-pagination" -> cmd_no_pagination = true
|
|
||||||
"--license" -> cmd_license = true
|
"--license" -> cmd_license = true
|
||||||
"-d", "--daemon" -> cmd_daemon = true
|
"-d", "--daemon" -> cmd_daemon = true
|
||||||
"--no-media" -> cmd_no_media = true
|
|
||||||
"--test" -> {
|
"--test" -> {
|
||||||
last_cmd = "--test"
|
last_cmd = "--test"
|
||||||
continue@loop
|
continue@loop
|
||||||
}
|
}
|
||||||
"--anonymize" -> cmd_anonymize = true
|
"--anonymize" -> cmd_anonymize = true
|
||||||
"--stats" -> cmd_stats = true
|
"--stats" -> cmd_stats = true
|
||||||
"--with-channels" -> cmd_channels = true
|
|
||||||
"--with-supergroups" -> cmd_supergroups = true
|
|
||||||
else -> throw RuntimeException("Unknown command " + arg)
|
else -> throw RuntimeException("Unknown command " + arg)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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("Processing channels and/or supergroups...")
|
||||||
System.out.println("Please note that only channels/supergroups in the last 100 active chats are processed.")
|
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
|
// 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
|
// 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.
|
// Skip this chat.
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
@ -56,8 +56,19 @@ object IniSettings {
|
|||||||
|
|
||||||
fun get(key: String, default: String? = null): String? = settings.get(key)?.last() ?: default
|
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 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>()
|
fun getArray(key: String): List<String> = settings.get(key) ?: listOf<String>()
|
||||||
|
|
||||||
val gmaps_key: String
|
val gmaps_key: String
|
||||||
get() = get("gmaps_key", default=Config.SECRET_GMAPS)!!
|
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)
|
||||||
}
|
}
|
||||||
|
@ -16,12 +16,6 @@
|
|||||||
|
|
||||||
package de.fabianonline.telegram_backup.exporter
|
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.File
|
||||||
import java.io.PrintWriter
|
import java.io.PrintWriter
|
||||||
import java.io.OutputStreamWriter
|
import java.io.OutputStreamWriter
|
||||||
@ -38,6 +32,7 @@ import java.util.HashMap
|
|||||||
import com.github.mustachejava.DefaultMustacheFactory
|
import com.github.mustachejava.DefaultMustacheFactory
|
||||||
import com.github.mustachejava.Mustache
|
import com.github.mustachejava.Mustache
|
||||||
import com.github.mustachejava.MustacheFactory
|
import com.github.mustachejava.MustacheFactory
|
||||||
|
import de.fabianonline.telegram_backup.*
|
||||||
|
|
||||||
import org.slf4j.Logger
|
import org.slf4j.Logger
|
||||||
import org.slf4j.LoggerFactory
|
import org.slf4j.LoggerFactory
|
||||||
@ -49,7 +44,7 @@ class HTMLExporter {
|
|||||||
@Throws(IOException::class)
|
@Throws(IOException::class)
|
||||||
fun export() {
|
fun export() {
|
||||||
try {
|
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
|
// Create base dir
|
||||||
logger.debug("Creating base dir")
|
logger.debug("Creating base dir")
|
||||||
|
@ -15,8 +15,8 @@
|
|||||||
# pagination = true
|
# pagination = true
|
||||||
# pagination_size = 5000
|
# pagination_size = 5000
|
||||||
|
|
||||||
## Don't download media files
|
## Download media files
|
||||||
# no_media = false
|
# download_media = true
|
||||||
|
|
||||||
## Don't download supergroups and channels by default
|
## Don't download supergroups and channels by default
|
||||||
# download_channels = false
|
# download_channels = false
|
||||||
|
Loading…
Reference in New Issue
Block a user