From 9a2cef55bc6ecac3fa5767dc9692892072031946 Mon Sep 17 00:00:00 2001 From: Dineshkarthik Date: Wed, 20 Jul 2022 15:59:38 +0200 Subject: [PATCH 1/4] refactor: suppress pyrogram timeout and reconnection warnings --- tests/utils/test_log.py | 4 ++-- utils/log.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/utils/test_log.py b/tests/utils/test_log.py index af7f935..71cf7a1 100644 --- a/tests/utils/test_log.py +++ b/tests/utils/test_log.py @@ -20,11 +20,11 @@ def __init__(self, **kwargs): class MetaTestCase(unittest.TestCase): def test_log_filter(self): - result = LogFilter().filter(MockLog(funcName="send")) + result = LogFilter().filter(MockLog(funcName="invoke")) self.assertEqual(result, False) result1 = LogFilter().filter(MockLog(funcName="get_file")) - self.assertEqual(result1, False) + self.assertEqual(result1, True) result2 = LogFilter().filter(MockLog(funcName="Synced")) self.assertEqual(result2, True) diff --git a/utils/log.py b/utils/log.py index 3b6322b..5d54bbe 100644 --- a/utils/log.py +++ b/utils/log.py @@ -11,6 +11,6 @@ class LogFilter(logging.Filter): # pylint: disable = W0221 def filter(self, record): - if record.funcName in ("send", "get_file"): + if record.funcName in ("invoke"): return False return True From 6c48df4a2751346b79b9e403158533d6508fe197 Mon Sep 17 00:00:00 2001 From: Dineshkarthik Date: Wed, 20 Jul 2022 16:10:25 +0200 Subject: [PATCH 2/4] fix: use own fork of Pyrogram to achieve chronological order of chat history --- media_downloader.py | 6 ++---- requirements.txt | 2 +- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/media_downloader.py b/media_downloader.py index c68f8d6..c482459 100644 --- a/media_downloader.py +++ b/media_downloader.py @@ -2,7 +2,6 @@ import asyncio import logging import os -from datetime import datetime as dt from typing import List, Optional, Tuple, Union import pyrogram @@ -123,7 +122,7 @@ async def _get_media_meta( _type, "{}_{}.{}".format( _type, - dt.utcfromtimestamp(media_obj.date).isoformat(), # type: ignore + media_obj.date.isoformat(), # type: ignore file_format, ), ) @@ -311,8 +310,7 @@ async def begin_import(config: dict, pagination_limit: int) -> dict: await client.start() last_read_message_id: int = config["last_read_message_id"] messages_iter = client.get_chat_history( - config["chat_id"], - offset_id=last_read_message_id, + config["chat_id"], offset_id=last_read_message_id, reverse=True ) messages_list: list = [] pagination_count: int = 0 diff --git a/requirements.txt b/requirements.txt index e2c9d8f..7cad49d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ -Pyrogram==2.0.33 +https://github.com/Dineshkarthik/pyrogram/archive/refs/heads/master.zip PyYAML==6.0 rich==12.5.1 TgCrypto==1.2.3 From 7a8e2dfda761d765f0522679e6d0a0e5adb491ee Mon Sep 17 00:00:00 2001 From: Dineshkarthik Date: Wed, 20 Jul 2022 16:10:59 +0200 Subject: [PATCH 3/4] test: update mock objects to handle pyrogram V2 migration --- tests/test_media_downloader.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/tests/test_media_downloader.py b/tests/test_media_downloader.py index 758b44c..33d7bda 100644 --- a/tests/test_media_downloader.py +++ b/tests/test_media_downloader.py @@ -1,14 +1,13 @@ """Unittest module for media downloader.""" import asyncio import copy -import logging import os import platform import unittest +from datetime import datetime import mock import pyrogram -import pytest from media_downloader import ( _can_download, @@ -158,7 +157,7 @@ async def get_chat_history(self, *args, **kwargs): media=True, voice=MockVoice( mime_type="audio/ogg", - date=1564066430, + date=datetime(2019, 7, 25, 14, 53, 50), ), ), MockMessage( @@ -239,7 +238,7 @@ def test_get_media_meta(self): media=True, voice=MockVoice( mime_type="audio/ogg", - date=1564066430, + date=datetime(2019, 7, 25, 14, 53, 50), ), ) result = self.loop.run_until_complete( @@ -260,7 +259,7 @@ def test_get_media_meta(self): message = MockMessage( id=2, media=True, - photo=MockPhoto(date=1565015712), + photo=MockPhoto(date=datetime(2019, 8, 5, 14, 35, 12)), ) result = self.loop.run_until_complete( async_get_media_meta(message.photo, "photo") @@ -338,7 +337,7 @@ def test_get_media_meta(self): media=True, video_note=MockVideoNote( mime_type="video/mp4", - date=1564066430, + date=datetime(2019, 7, 25, 14, 53, 50), ), ) result = self.loop.run_until_complete( @@ -513,7 +512,7 @@ def test_process_message(self): media=True, voice=MockVoice( mime_type="audio/ogg", - date=1564066340, + date=datetime(2019, 7, 25, 14, 53, 50), ), ), MockMessage( @@ -554,7 +553,7 @@ def test_process_message_when_file_exists(self, mock_is_exist): media=True, voice=MockVoice( mime_type="audio/ogg", - date=1564066340, + date=datetime(2019, 7, 25, 14, 53, 50), ), ), MockMessage( From 90ac5bdf531a6cda49b44335b4c7c7234b526ebe Mon Sep 17 00:00:00 2001 From: Dineshkarthik Date: Wed, 20 Jul 2022 16:11:58 +0200 Subject: [PATCH 4/4] build: bump-up telegram-media-downloader version from 2.0.0 to 2.0.1 --- utils/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/__init__.py b/utils/__init__.py index 6f90d1a..361ca41 100644 --- a/utils/__init__.py +++ b/utils/__init__.py @@ -1,5 +1,5 @@ """Init namespace""" -__version__ = "2.0.0" +__version__ = "2.0.1" __license__ = "MIT License" __copyright__ = "Copyright (C) 2019 Dineshkarthik "