diff --git a/config.ini.example b/config.ini.example index bc2405a..95f7d20 100644 --- a/config.ini.example +++ b/config.ini.example @@ -125,3 +125,7 @@ LibraryLogLevel = WARNING # Sets proxy support # Proxy = socks5://user:password@127.0.0.1:1080 # Proxy = http://127.0.0.1:8080 + +# Sets types which can be group, user or channel +# Should be comma separated +FromType = user, channel \ No newline at end of file diff --git a/telegram_export/__main__.py b/telegram_export/__main__.py index 70de853..b590888 100644 --- a/telegram_export/__main__.py +++ b/telegram_export/__main__.py @@ -43,9 +43,11 @@ def load_config(filename): """Load config from the specified file and return the parsed config""" # Get a path to the file. If it was specified, it should be fine. # If it was not specified, assume it's config.ini in the script's dir. - config_dir = appdirs.user_config_dir("telegram-export") + if os.path.isfile('config.ini'): + filename = os.path.join(os.getcwd(), 'config.ini') if not filename: + config_dir = appdirs.user_config_dir("telegram-export") filename = os.path.join(config_dir, 'config.ini') if not os.path.isfile(filename): diff --git a/telegram_export/exporter.py b/telegram_export/exporter.py index 9371cd4..0d97c69 100644 --- a/telegram_export/exporter.py +++ b/telegram_export/exporter.py @@ -2,10 +2,10 @@ import logging import re - +from telethon.tl import types from async_generator import yield_, async_generator from telethon import utils - +from telegram_export.utils import FROM_TYPES from .downloader import Downloader @@ -34,6 +34,10 @@ async def get_entities_iter(mode, in_list, client): assert client is not None async for ent in entities_from_str(client.get_input_entity, in_list): await yield_(ent) + if mode == 'from_type': + assert client is not None + async for ent in entities_from_str(client.get_input_entity, in_list): + await yield_(ent) elif mode == 'blacklist': assert client is not None avoid = set() @@ -77,6 +81,12 @@ async def start(self): self.dumper.config['Blacklist'], self.client): await self.downloader.start(entity) + elif 'FromType' in self.dumper.config: + for dialog in await self.client.get_dialogs(limit=None): + # self.logger.info(type(dialog.entity)) + from_types = tuple(FROM_TYPES[elem.strip()] for elem in self.dumper.config['FromType'].split(',')) + if isinstance(dialog.entity, from_types): + await self.downloader.start(dialog.entity) else: # Neither blacklist nor whitelist - get all for dialog in await self.client.get_dialogs(limit=None): diff --git a/telegram_export/utils.py b/telegram_export/utils.py index 851c888..89a8fb7 100644 --- a/telegram_export/utils.py +++ b/telegram_export/utils.py @@ -41,6 +41,12 @@ 'video/mp4': '.mp4', # To avoid ".m4v" } +FROM_TYPES = { + 'group': types.Chat, + 'user': types.User, + 'channel': types.Channel +} + def encode_msg_entities(entities): """