refactored tg parser
This commit is contained in:
@ -1,9 +1,9 @@
|
||||
api_hash: cb06da2bf01e15627434223242b6446d
|
||||
api_id: 21648766
|
||||
chat:
|
||||
- chat_id: landigos
|
||||
download_filter: id >= 6949 && id < 6950
|
||||
last_read_message_id: 6949
|
||||
- chat_id: -1001966291562
|
||||
download_filter: id == 2048
|
||||
last_read_message_id: 2048
|
||||
file_formats:
|
||||
video:
|
||||
- all
|
||||
@ -12,7 +12,7 @@ media_types:
|
||||
# in linux please use /
|
||||
# save_path: E:\github\telegram_media_downloader
|
||||
disable_syslog: []
|
||||
save_path: /Users/garickbadalov/PycharmProjects/video_downloader_service/downloads/Telegram/
|
||||
save_path: downloads/Telegram/
|
||||
language: RU
|
||||
web_host: 0.0.0.0
|
||||
web_port: 51256
|
||||
|
@ -14,14 +14,15 @@ from src.parsers.base_parser import BaseParser
|
||||
class TelegramParser(BaseParser):
|
||||
def video_download(self, client: Client = None):
|
||||
url_parse_result = urlparse(self.params["link"])
|
||||
channel, message_id = url_parse_result.path[1:].split('/')
|
||||
channel, message_id = url_parse_result.path[1:].split('/') if "/c/" not in url_parse_result.path else \
|
||||
url_parse_result.path[3:].split('/')
|
||||
if os.path.exists(os.path.join(os.getcwd() + f"/downloads/Telegram/{message_id}.mp4")):
|
||||
raise FileAlreadyExistException(message=f"Telegram/{message_id}.mp4")
|
||||
with open(os.path.join(os.path.abspath(""), "src/parsers/Telegram/telegram_media_downloader/config.yaml"),
|
||||
mode="r+", encoding="utf-8") as f:
|
||||
config = YAML().load(f.read())
|
||||
config["chat"][0]['download_filter'] = f"id >= {message_id} && id < {int(message_id) + 1}"
|
||||
config["chat"][0]['chat_id'] = channel
|
||||
config["chat"][0]['download_filter'] = f"id == {message_id}"
|
||||
config["chat"][0]['chat_id'] = channel if "/c/" not in url_parse_result.path else int(f"-100{channel}")
|
||||
config["chat"][0]['last_read_message_id'] = int(message_id)
|
||||
|
||||
with open(os.path.join(os.path.abspath(""), "src/parsers/Telegram/telegram_media_downloader/config.yaml"),
|
||||
|
Reference in New Issue
Block a user