From c23ecfecf4a3dd16de41d9602c249886c695f1f5 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 13 Jun 2022 10:11:26 +0000 Subject: [PATCH 01/23] build(deps-dev): bump mypy from 0.942 to 0.961 Bumps [mypy](https://github.com/python/mypy) from 0.942 to 0.961. - [Release notes](https://github.com/python/mypy/releases) - [Commits](https://github.com/python/mypy/compare/v0.942...v0.961) --- updated-dependencies: - dependency-name: mypy dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- dev-requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dev-requirements.txt b/dev-requirements.txt index bd2ba29..6b5e6bc 100644 --- a/dev-requirements.txt +++ b/dev-requirements.txt @@ -1,5 +1,5 @@ mock==4.0.3 -mypy==0.942 +mypy==0.961 pylint==2.13.7 pytest==7.0.1 pytest-cov==3.0.0 From 61ad574a401bfaea1ba053988200a3d05465f7e9 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 18 Jul 2022 10:09:14 +0000 Subject: [PATCH 02/23] build(deps-dev): bump types-pyyaml from 6.0.7 to 6.0.10 Bumps [types-pyyaml](https://github.com/python/typeshed) from 6.0.7 to 6.0.10. - [Release notes](https://github.com/python/typeshed/releases) - [Commits](https://github.com/python/typeshed/commits) --- updated-dependencies: - dependency-name: types-pyyaml dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- dev-requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dev-requirements.txt b/dev-requirements.txt index bd2ba29..a67ef1b 100644 --- a/dev-requirements.txt +++ b/dev-requirements.txt @@ -3,4 +3,4 @@ mypy==0.942 pylint==2.13.7 pytest==7.0.1 pytest-cov==3.0.0 -types-PyYAML==6.0.7 +types-PyYAML==6.0.10 From 46e18505cca73c0d79761784bb1f962ac1bbc806 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 18 Jul 2022 10:09:21 +0000 Subject: [PATCH 03/23] build(deps): bump rich from 12.1.0 to 12.5.1 Bumps [rich](https://github.com/willmcgugan/rich) from 12.1.0 to 12.5.1. - [Release notes](https://github.com/willmcgugan/rich/releases) - [Changelog](https://github.com/Textualize/rich/blob/master/CHANGELOG.md) - [Commits](https://github.com/willmcgugan/rich/compare/v12.1.0...v12.5.1) --- updated-dependencies: - dependency-name: rich dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index def4add..8d87b58 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ Pyrogram==1.4.12 PyYAML==6.0 -rich==12.1.0 +rich==12.5.1 TgCrypto==1.2.3 From 230f47659fb61319f02dd23323bdc36f971872c6 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 18 Jul 2022 10:09:32 +0000 Subject: [PATCH 04/23] build(deps): bump pyrogram from 1.4.12 to 2.0.33 Bumps [pyrogram](https://github.com/pyrogram/pyrogram) from 1.4.12 to 2.0.33. - [Release notes](https://github.com/pyrogram/pyrogram/releases) - [Commits](https://github.com/pyrogram/pyrogram/commits/v2.0.33) --- updated-dependencies: - dependency-name: pyrogram dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index def4add..e78ace1 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ -Pyrogram==1.4.12 +Pyrogram==2.0.33 PyYAML==6.0 rich==12.1.0 TgCrypto==1.2.3 From 4132cbccff7e798d1ffc540347943b70ab47a448 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 18 Jul 2022 12:17:46 +0000 Subject: [PATCH 05/23] build(deps-dev): bump pylint from 2.13.7 to 2.14.5 Bumps [pylint](https://github.com/PyCQA/pylint) from 2.13.7 to 2.14.5. - [Release notes](https://github.com/PyCQA/pylint/releases) - [Commits](https://github.com/PyCQA/pylint/compare/v2.13.7...v2.14.5) --- updated-dependencies: - dependency-name: pylint dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- dev-requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dev-requirements.txt b/dev-requirements.txt index bd2ba29..1df0b9d 100644 --- a/dev-requirements.txt +++ b/dev-requirements.txt @@ -1,6 +1,6 @@ mock==4.0.3 mypy==0.942 -pylint==2.13.7 +pylint==2.14.5 pytest==7.0.1 pytest-cov==3.0.0 types-PyYAML==6.0.7 From 281f1b7d7f1a63e8f089ebaf5b3043f560f8f46b Mon Sep 17 00:00:00 2001 From: Dineshkarthik Date: Mon, 18 Jul 2022 16:45:43 +0200 Subject: [PATCH 06/23] ci: bump checkout & setup-python actions update python version matrix: - 3.6 as pyrogram c2 doesn't support 3.6 + 3.10 + 3.11 --- .github/workflows/main.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index d5f4ed6..4e7ed50 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -13,13 +13,13 @@ jobs: strategy: matrix: os: [ubuntu-latest, macos-latest, windows-latest] - python-version: [ '3.6', '3.7', '3.8', '3.9' ] + python-version: ['3.7', '3.8', '3.9', '3.10', '3.11' ] name: Test - Python ${{ matrix.python-version }} on ${{ matrix.os }} steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Set up Python - uses: actions/setup-python@v2 + uses: actions/setup-python@v4 with: python-version: ${{ matrix.python-version }} - name: Get setuptools Unix From 3043c91b61b8d7406ca05b3f695a464587e83787 Mon Sep 17 00:00:00 2001 From: Dineshkarthik Date: Mon, 18 Jul 2022 16:48:31 +0200 Subject: [PATCH 07/23] refactor: migrate Pyrogram to V2 --- media_downloader.py | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/media_downloader.py b/media_downloader.py index b99502d..c7fcc5f 100644 --- a/media_downloader.py +++ b/media_downloader.py @@ -176,7 +176,7 @@ async def download_media( for retry in range(3): try: if message.media is None: - return message.message_id + return message.id for _type in media_types: _media = getattr(message, _type, None) if _media is None: @@ -196,48 +196,48 @@ async def download_media( ) if download_path: logger.info("Media downloaded - %s", download_path) - DOWNLOADED_IDS.append(message.message_id) + DOWNLOADED_IDS.append(message.id) break except pyrogram.errors.exceptions.bad_request_400.BadRequest: logger.warning( "Message[%d]: file reference expired, refetching...", - message.message_id, + message.id, ) message = await client.get_messages( # type: ignore chat_id=message.chat.id, # type: ignore - message_ids=message.message_id, + message_ids=message.id, ) if retry == 2: # pylint: disable = C0301 logger.error( "Message[%d]: file reference expired for 3 retries, download skipped.", - message.message_id, + message.id, ) - FAILED_IDS.append(message.message_id) + FAILED_IDS.append(message.id) except TypeError: # pylint: disable = C0301 logger.warning( "Timeout Error occurred when downloading Message[%d], retrying after 5 seconds", - message.message_id, + message.id, ) await asyncio.sleep(5) if retry == 2: logger.error( "Message[%d]: Timing out after 3 reties, download skipped.", - message.message_id, + message.id, ) - FAILED_IDS.append(message.message_id) + FAILED_IDS.append(message.id) except Exception as e: # pylint: disable = C0301 logger.error( "Message[%d]: could not be downloaded due to following exception:\n[%s].", - message.message_id, + message.id, e, exc_info=True, ) - FAILED_IDS.append(message.message_id) + FAILED_IDS.append(message.id) break - return message.message_id + return message.id async def process_messages( @@ -312,10 +312,9 @@ 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.iter_history( + messages_iter = client.get_chat_history( config["chat_id"], offset_id=last_read_message_id, - reverse=True, ) messages_list: list = [] pagination_count: int = 0 From 1702ec978881494a17721ca7279753024b784eca Mon Sep 17 00:00:00 2001 From: Dineshkarthik Date: Mon, 18 Jul 2022 16:53:22 +0200 Subject: [PATCH 08/23] ci: specify python 3.11 beta version --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 4e7ed50..8b7aafc 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -13,7 +13,7 @@ jobs: strategy: matrix: os: [ubuntu-latest, macos-latest, windows-latest] - python-version: ['3.7', '3.8', '3.9', '3.10', '3.11' ] + python-version: ['3.7', '3.8', '3.9', '3.10', '3.11.0-beta.4' ] name: Test - Python ${{ matrix.python-version }} on ${{ matrix.os }} steps: From 6d58a01f94af66caf703dfdf0ad96c06267b75ff Mon Sep 17 00:00:00 2001 From: Dineshkarthik Date: Mon, 18 Jul 2022 16:58:19 +0200 Subject: [PATCH 09/23] test: update mock objects to handle pyrogram V2 migration --- tests/test_media_downloader.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/test_media_downloader.py b/tests/test_media_downloader.py index d203ffe..dc6f619 100644 --- a/tests/test_media_downloader.py +++ b/tests/test_media_downloader.py @@ -53,7 +53,7 @@ class Chat: class MockMessage: def __init__(self, **kwargs): - self.message_id = kwargs.get("id") + self.id = kwargs.get("id") self.media = kwargs.get("media") self.audio = kwargs.get("audio", None) self.document = kwargs.get("document", None) @@ -153,7 +153,7 @@ class MockClient: async def stop(self): pass - async def iter_history(self, *args, **kwargs): + async def get_chat_history(self, *args, **kwargs): items = [ MockMessage( id=1213, @@ -219,11 +219,11 @@ class MockClient: async def download_media(self, *args, **kwargs): mock_message = args[0] - if mock_message.message_id in [7, 8]: + if mock_message.id in [7, 8]: raise pyrogram.errors.exceptions.bad_request_400.BadRequest - elif mock_message.message_id == 9: + elif mock_message.id == 9: raise pyrogram.errors.exceptions.unauthorized_401.Unauthorized - elif mock_message.message_id == 11: + elif mock_message.id == 11: raise TypeError return kwargs["file_name"] From 52d980c16ad598a9d24965f5b7c5d98fde64af43 Mon Sep 17 00:00:00 2001 From: Dineshkarthik Date: Mon, 18 Jul 2022 19:12:47 +0200 Subject: [PATCH 10/23] build(package): update classifiers --- setup.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/setup.py b/setup.py index c0d8a92..717a3bb 100644 --- a/setup.py +++ b/setup.py @@ -12,7 +12,7 @@ setup( download_url="https://github.com/Dineshkarthik/telegram_media_downloader/releases/latest", py_modules=["media_downloader"], classifiers=[ - "Development Status :: 4 - Beta", + "Development Status :: 5 - Production/Stable", "Environment :: Console", "Operating System :: OS Independent", "Intended Audience :: Developers", @@ -22,10 +22,11 @@ setup( "Natural Language :: English", "Programming Language :: Python", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7", "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11", "Topic :: Internet", "Topic :: Communications", "Topic :: Communications :: Chat", @@ -37,5 +38,5 @@ setup( "Community": "https://t.me/tgmdnews", "Source": "https://github.com/Dineshkarthik/telegram_media_downloader", }, - python_requires=">=3.6", + python_requires="~=3.7", ) From 3c897b6348e721f8563930c011282c193c5781f4 Mon Sep 17 00:00:00 2001 From: Dineshkarthik Date: Mon, 18 Jul 2022 19:13:23 +0200 Subject: [PATCH 11/23] add: pre-commit config --- .pre-commit-config.yaml | 43 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 .pre-commit-config.yaml diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..b7e56b7 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,43 @@ +# See https://pre-commit.com for more information +# See https://pre-commit.com/hooks.html for more hooks +repos: +- repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.2.0 + hooks: + - id: trailing-whitespace + - id: end-of-file-fixer +- repo: https://github.com/psf/black + rev: 22.3.0 + hooks: + - id: black + name: black + entry: black + types: [python] +- repo: https://github.com/pycqa/isort + rev: 5.10.1 + hooks: + - id: isort + name: isort + entry: isort + types: [python] + args: ["--profile", "black", "--filter-files"] +- repo: https://github.com/pre-commit/mirrors-mypy + rev: V0.961 + hooks: + - id: mypy + name: mypy + entry: mypy + types: [python] + args: [--no-strict-optional, --ignore-missing-imports] +- repo: local + hooks: + - id: pylint + name: pylint + entry: pylint + language: system + types: [python] + args: [ + "-rn", # Only display messages + "-sn", # Don't display the score + "--rcfile=pylintrc" # Link to your config file + ] \ No newline at end of file From edc790a5809975bab463ddbd98830ebbb4cc2756 Mon Sep 17 00:00:00 2001 From: Dineshkarthik Date: Mon, 18 Jul 2022 19:18:36 +0200 Subject: [PATCH 12/23] ci: separate workflows for code quality and unittest --- .github/workflows/code-checks.yml | 20 ++++++++++++++++++++ .github/workflows/{main.yml => unittest.yml} | 8 ++++---- 2 files changed, 24 insertions(+), 4 deletions(-) create mode 100644 .github/workflows/code-checks.yml rename .github/workflows/{main.yml => unittest.yml} (89%) diff --git a/.github/workflows/code-checks.yml b/.github/workflows/code-checks.yml new file mode 100644 index 0000000..e7bc326 --- /dev/null +++ b/.github/workflows/code-checks.yml @@ -0,0 +1,20 @@ +name: Code Quality + +on: + pull_request: + branches: [ master ] + paths-ignore: + - 'README.md' + push: + branches: [ master ] + paths-ignore: + - 'README.md' + +jobs: + pre-commit: + name: Linting + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-python@v4 + - uses: pre-commit/action@v3.0.0 \ No newline at end of file diff --git a/.github/workflows/main.yml b/.github/workflows/unittest.yml similarity index 89% rename from .github/workflows/main.yml rename to .github/workflows/unittest.yml index 8b7aafc..5eb0e9f 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/unittest.yml @@ -3,8 +3,12 @@ name: Unittest on: push: branches: [ master ] + paths-ignore: + - 'README.md' pull_request: branches: [ master ] + paths-ignore: + - 'README.md' jobs: build: @@ -30,10 +34,6 @@ jobs: run: pip install --upgrade --user pip setuptools codecov - name: Install dependencies run: make dev_install - - name: Code Check - Pylint - run: make pylint - - name: Static Type Check - Mypy - run: make static_type_check - name: Test with pytest run: | make -e test From 08d754e5cff730f9f93cd74438ae7fc7178caecc Mon Sep 17 00:00:00 2001 From: Dineshkarthik Date: Mon, 18 Jul 2022 19:24:33 +0200 Subject: [PATCH 13/23] fix: mypy revision --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index b7e56b7..5858ebc 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -22,7 +22,7 @@ repos: types: [python] args: ["--profile", "black", "--filter-files"] - repo: https://github.com/pre-commit/mirrors-mypy - rev: V0.961 + rev: v0.961 hooks: - id: mypy name: mypy From 077e0dc943aaf2ceb57517f6734f44c52d031482 Mon Sep 17 00:00:00 2001 From: Dineshkarthik Date: Mon, 18 Jul 2022 20:01:49 +0200 Subject: [PATCH 14/23] style: pre-commit fix for end-of-line-fixer --- .github/workflows/code-checks.yml | 2 +- .pre-commit-config.yaml | 11 ++++++++--- CONTRIBUTING.md | 6 +++--- Makefile | 4 ++-- README.md | 6 +++--- codecov.yml | 2 +- pylintrc | 2 +- 7 files changed, 19 insertions(+), 14 deletions(-) diff --git a/.github/workflows/code-checks.yml b/.github/workflows/code-checks.yml index e7bc326..7942933 100644 --- a/.github/workflows/code-checks.yml +++ b/.github/workflows/code-checks.yml @@ -17,4 +17,4 @@ jobs: steps: - uses: actions/checkout@v3 - uses: actions/setup-python@v4 - - uses: pre-commit/action@v3.0.0 \ No newline at end of file + - uses: pre-commit/action@v3.0.0 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 5858ebc..62a30db 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -28,8 +28,11 @@ repos: name: mypy entry: mypy types: [python] - args: [--no-strict-optional, --ignore-missing-imports] -- repo: local + args: [--ignore-missing-imports] + files: utils/|media_downloader.py + exclude: tests/ +- repo: https://github.com/pycqa/pylint + rev: v2.14.5 hooks: - id: pylint name: pylint @@ -40,4 +43,6 @@ repos: "-rn", # Only display messages "-sn", # Don't display the score "--rcfile=pylintrc" # Link to your config file - ] \ No newline at end of file + ] + files: utils/|media_downloader.py + exclude: tests/ diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index f6a3678..5b03fa2 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -179,10 +179,10 @@ Must be one of the following: - **style**: Changes that do not affect the meaning of the code (white-space, formatting, etc) - **test**: Additions/updates to tests - **type**: Type annotations - + #### Subject: -Please reference the relevant GitHub issues in your commit message using #1234. +Please reference the relevant GitHub issues in your commit message using #1234. - a subject line with `< 80` chars. - summary in present tense. - not capitalized. @@ -196,4 +196,4 @@ Explain the motivation for the change in the commit message body. This commit me ### Code of Conduct -As a contributor, you can help us keep the community open and inclusive. Please read and follow our [Code of Conduct](https://github.com/Dineshkarthik/telegram_media_downloader/blob/master/CODE_OF_CONDUCT.md). \ No newline at end of file +As a contributor, you can help us keep the community open and inclusive. Please read and follow our [Code of Conduct](https://github.com/Dineshkarthik/telegram_media_downloader/blob/master/CODE_OF_CONDUCT.md). diff --git a/Makefile b/Makefile index 57a56c1..5b2742f 100644 --- a/Makefile +++ b/Makefile @@ -4,7 +4,7 @@ TEST_ARTIFACTS ?= /tmp/coverage install: python3 -m pip install --upgrade pip setuptools - python3 -m pip install -r requirements.txt + python3 -m pip install -r requirements.txt dev_install: install python3 -m pip install -r dev-requirements.txt @@ -23,4 +23,4 @@ test: --cov-report term-missing \ --cov-report html:${TEST_ARTIFACTS} \ --junit-xml=${TEST_ARTIFACTS}/media-downloader.xml \ - tests/ + tests/ diff --git a/README.md b/README.md index 6a7b820..aa29670 100644 --- a/README.md +++ b/README.md @@ -39,21 +39,21 @@ $ git clone https://github.com/Dineshkarthik/telegram_media_downloader.git $ cd telegram_media_downloader $ make install ``` -For Windows which doesn't have `make` inbuilt +For Windows which doesn't have `make` inbuilt ```sh $ git clone https://github.com/Dineshkarthik/telegram_media_downloader.git $ cd telegram_media_downloader $ pip3 install -r requirements.txt ``` -## Configuration +## Configuration All the configurations are passed to the Telegram Media Downloader via `config.yaml` file. **Getting your API Keys:** The very first step requires you to obtain a valid Telegram API key (API id/hash pair): 1. Visit [https://my.telegram.org/apps](https://my.telegram.org/apps) and log in with your Telegram Account. -2. Fill out the form to register a new Telegram application. +2. Fill out the form to register a new Telegram application. 3. Done! The API key consists of two parts: **api_id** and **api_hash**. diff --git a/codecov.yml b/codecov.yml index b18401c..1fbaabe 100644 --- a/codecov.yml +++ b/codecov.yml @@ -10,4 +10,4 @@ coverage: patch: no comment: - require_changes: true \ No newline at end of file + require_changes: true diff --git a/pylintrc b/pylintrc index 8b57c74..b614094 100644 --- a/pylintrc +++ b/pylintrc @@ -251,7 +251,7 @@ indent-after-paren=4 indent-string=' ' # Maximum number of characters on a single line. -max-line-length=80 +max-line-length=90 # Maximum number of lines in a module. max-module-lines= From a9a6634d89031206d559ebf86373868a5362d470 Mon Sep 17 00:00:00 2001 From: Dineshkarthik Date: Mon, 18 Jul 2022 20:03:20 +0200 Subject: [PATCH 15/23] style: change in black and isort autoformat config --- media_downloader.py | 2 +- tests/test_media_downloader.py | 12 ++++++------ tests/utils/test_file_management.py | 10 +++++++--- tests/utils/test_log.py | 2 +- utils/updates.py | 1 + 5 files changed, 16 insertions(+), 11 deletions(-) diff --git a/media_downloader.py b/media_downloader.py index c7fcc5f..5de58b3 100644 --- a/media_downloader.py +++ b/media_downloader.py @@ -281,7 +281,7 @@ async def process_messages( ] ) - last_message_id = max(message_ids) + last_message_id: int = max(message_ids) return last_message_id diff --git a/tests/test_media_downloader.py b/tests/test_media_downloader.py index dc6f619..c2ad2ef 100644 --- a/tests/test_media_downloader.py +++ b/tests/test_media_downloader.py @@ -1,24 +1,24 @@ """Unittest module for media downloader.""" -import os +import asyncio import copy import logging +import os import platform import unittest -import asyncio import mock import pyrogram import pytest from media_downloader import ( - _get_media_meta, _can_download, + _get_media_meta, _is_exist, - download_media, - update_config, begin_import, - process_messages, + download_media, main, + process_messages, + update_config, ) MOCK_DIR: str = "/root/project" diff --git a/tests/utils/test_file_management.py b/tests/utils/test_file_management.py index 7ac188e..057acb1 100644 --- a/tests/utils/test_file_management.py +++ b/tests/utils/test_file_management.py @@ -15,8 +15,12 @@ class FileManagementTestCase(unittest.TestCase): def setUp(self): self.this_dir = os.path.dirname(os.path.abspath(__file__)) self.test_file = os.path.join(self.this_dir, "file-test.txt") - self.test_file_copy_1 = os.path.join(self.this_dir, "file-test-copy1.txt") - self.test_file_copy_2 = os.path.join(self.this_dir, "file-test-copy2.txt") + self.test_file_copy_1 = os.path.join( + self.this_dir, "file-test-copy1.txt" + ) + self.test_file_copy_2 = os.path.join( + self.this_dir, "file-test-copy2.txt" + ) f = open(self.test_file, "w+") f.write("dummy file") f.close() @@ -27,7 +31,7 @@ class FileManagementTestCase(unittest.TestCase): result = get_next_name(self.test_file) excepted_result = os.path.join(self.this_dir, "file-test-copy3.txt") self.assertEqual(result, excepted_result) - + def test_manage_duplicate_file(self): result = manage_duplicate_file(self.test_file_copy_2) self.assertEqual(result, self.test_file_copy_1) diff --git a/tests/utils/test_log.py b/tests/utils/test_log.py index 8cf8fd4..af7f935 100644 --- a/tests/utils/test_log.py +++ b/tests/utils/test_log.py @@ -27,4 +27,4 @@ class MetaTestCase(unittest.TestCase): self.assertEqual(result1, False) result2 = LogFilter().filter(MockLog(funcName="Synced")) - self.assertEqual(result2, True) \ No newline at end of file + self.assertEqual(result2, True) diff --git a/utils/updates.py b/utils/updates.py index 40681cd..e33a84b 100644 --- a/utils/updates.py +++ b/utils/updates.py @@ -7,6 +7,7 @@ from rich.markdown import Markdown from . import __version__ + # pylint: disable = C0301 def check_for_updates() -> None: """Checks for new releases. From 0486e70b830ccbfd3bbe41bc92682f7e11b45103 Mon Sep 17 00:00:00 2001 From: Dineshkarthik Date: Mon, 18 Jul 2022 20:04:29 +0200 Subject: [PATCH 16/23] rm: pyproject.toml file used for black config --- pyproject.toml | 22 ---------------------- 1 file changed, 22 deletions(-) delete mode 100644 pyproject.toml diff --git a/pyproject.toml b/pyproject.toml deleted file mode 100644 index 1c58150..0000000 --- a/pyproject.toml +++ /dev/null @@ -1,22 +0,0 @@ -[tool.black] -line-length = 79 -target-version = ['py36', 'py37', 'py38'] -exclude = ''' -( - /( - \.eggs # exclude a few common directories in the - | \.git # root of the project - | \.hg - | \.mypy_cache - | \.tox - | \.venv - | _build - | buck-out - | build - | dist - | bin - | lib - | include - )/ -) -''' \ No newline at end of file From c36b3af158e0b0bf096266fde205bbb93d9ee19f Mon Sep 17 00:00:00 2001 From: Dineshkarthik Date: Mon, 18 Jul 2022 20:07:04 +0200 Subject: [PATCH 17/23] add: mypy config --- mypy.ini | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 mypy.ini diff --git a/mypy.ini b/mypy.ini new file mode 100644 index 0000000..f96d433 --- /dev/null +++ b/mypy.ini @@ -0,0 +1,8 @@ +[mypy] +warn_return_any = True + +[mypy-yaml.*] +ignore_missing_imports = True + +[mypy-tests.*] +ignore_errors = True From ef12b4f5e2e20ca2f30e1974fe369167a15b18d4 Mon Sep 17 00:00:00 2001 From: Dineshkarthik Date: Mon, 18 Jul 2022 20:08:21 +0200 Subject: [PATCH 18/23] style: change in black and isort autoformat config --- media_downloader.py | 4 +--- tests/test_media_downloader.py | 12 +++--------- tests/utils/test_file_management.py | 8 ++------ utils/__init__.py | 4 +--- utils/meta.py | 4 +--- 5 files changed, 8 insertions(+), 24 deletions(-) diff --git a/media_downloader.py b/media_downloader.py index 5de58b3..c68f8d6 100644 --- a/media_downloader.py +++ b/media_downloader.py @@ -47,9 +47,7 @@ def update_config(config: dict): logger.info("Updated last read message_id to config file") -def _can_download( - _type: str, file_formats: dict, file_format: Optional[str] -) -> bool: +def _can_download(_type: str, file_formats: dict, file_format: Optional[str]) -> bool: """ Check if the given file format can be downloaded. diff --git a/tests/test_media_downloader.py b/tests/test_media_downloader.py index c2ad2ef..758b44c 100644 --- a/tests/test_media_downloader.py +++ b/tests/test_media_downloader.py @@ -134,9 +134,7 @@ async def mock_process_message(*args, **kwargs): async def async_process_messages(client, messages, media_types, file_formats): - result = await process_messages( - client, messages, media_types, file_formats - ) + result = await process_messages(client, messages, media_types, file_formats) return result @@ -289,9 +287,7 @@ class MediaDownloaderTestCase(unittest.TestCase): ) self.assertEqual( ( - platform_generic_path( - "/root/project/document/sample_document.pdf" - ), + platform_generic_path("/root/project/document/sample_document.pdf"), "pdf", ), result, @@ -495,9 +491,7 @@ class MediaDownloaderTestCase(unittest.TestCase): } update_config(conf) mock_open.assert_called_with("config.yaml", "w") - mock_yaml.dump.assert_called_with( - conf, mock.ANY, default_flow_style=False - ) + mock_yaml.dump.assert_called_with(conf, mock.ANY, default_flow_style=False) @mock.patch("media_downloader.update_config") @mock.patch("media_downloader.pyrogram.Client", new=MockClient) diff --git a/tests/utils/test_file_management.py b/tests/utils/test_file_management.py index 057acb1..bf4fc4d 100644 --- a/tests/utils/test_file_management.py +++ b/tests/utils/test_file_management.py @@ -15,12 +15,8 @@ class FileManagementTestCase(unittest.TestCase): def setUp(self): self.this_dir = os.path.dirname(os.path.abspath(__file__)) self.test_file = os.path.join(self.this_dir, "file-test.txt") - self.test_file_copy_1 = os.path.join( - self.this_dir, "file-test-copy1.txt" - ) - self.test_file_copy_2 = os.path.join( - self.this_dir, "file-test-copy2.txt" - ) + self.test_file_copy_1 = os.path.join(self.this_dir, "file-test-copy1.txt") + self.test_file_copy_2 = os.path.join(self.this_dir, "file-test-copy2.txt") f = open(self.test_file, "w+") f.write("dummy file") f.close() diff --git a/utils/__init__.py b/utils/__init__.py index 73171b5..db9d057 100644 --- a/utils/__init__.py +++ b/utils/__init__.py @@ -2,6 +2,4 @@ __version__ = "1.5.1" __license__ = "MIT License" -__copyright__ = ( - "Copyright (C) 2019 Dineshkarthik " -) +__copyright__ = "Copyright (C) 2019 Dineshkarthik " diff --git a/utils/meta.py b/utils/meta.py index 547c610..90354be 100644 --- a/utils/meta.py +++ b/utils/meta.py @@ -6,9 +6,7 @@ from rich.console import Console from . import __copyright__, __license__, __version__ APP_VERSION = f"Telegram Media Downloader {__version__}" -DEVICE_MODEL = ( - f"{platform.python_implementation()} {platform.python_version()}" -) +DEVICE_MODEL = f"{platform.python_implementation()} {platform.python_version()}" SYSTEM_VERSION = f"{platform.system()} {platform.release()}" LANG_CODE = "en" From e19cb26ed4e15a6b5b7cb70e8817c4d8fff63ddb Mon Sep 17 00:00:00 2001 From: Dineshkarthik Date: Mon, 18 Jul 2022 20:16:18 +0200 Subject: [PATCH 19/23] build(deps-dev): add black & isort --- dev-requirements.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/dev-requirements.txt b/dev-requirements.txt index d7f7f7c..014dac7 100644 --- a/dev-requirements.txt +++ b/dev-requirements.txt @@ -1,3 +1,5 @@ +black==22.3.0 +isort==5.10.1 mock==4.0.3 mypy==0.961 pylint==2.14.5 From 4cefa0c85989d345c7c26a852efec179762ef594 Mon Sep 17 00:00:00 2001 From: Dineshkarthik Date: Mon, 18 Jul 2022 20:21:43 +0200 Subject: [PATCH 20/23] ci: specify python version & install dev deps --- .github/workflows/code-checks.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/code-checks.yml b/.github/workflows/code-checks.yml index 7942933..0e89137 100644 --- a/.github/workflows/code-checks.yml +++ b/.github/workflows/code-checks.yml @@ -17,4 +17,8 @@ jobs: steps: - uses: actions/checkout@v3 - uses: actions/setup-python@v4 + with: + python-version: '3.10' + - name: Install dependencies + run: make dev_install - uses: pre-commit/action@v3.0.0 From 8f75cecd5b93eabc2e207ffe421640071e1d59bc Mon Sep 17 00:00:00 2001 From: Dineshkarthik Date: Tue, 19 Jul 2022 12:03:26 +0200 Subject: [PATCH 21/23] build: bump-up telegram-media-downloader version from 1.5.1 to 2.0.0 --- utils/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/__init__.py b/utils/__init__.py index db9d057..6f90d1a 100644 --- a/utils/__init__.py +++ b/utils/__init__.py @@ -1,5 +1,5 @@ """Init namespace""" -__version__ = "1.5.1" +__version__ = "2.0.0" __license__ = "MIT License" __copyright__ = "Copyright (C) 2019 Dineshkarthik " From bdf3312c96384a84d0d21694c23f6b2cd5e9e474 Mon Sep 17 00:00:00 2001 From: Dineshkarthik Date: Tue, 19 Jul 2022 12:04:23 +0200 Subject: [PATCH 22/23] doc: update proxy configuration instructions to match Pyrogram V2 --- README.md | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index aa29670..4a9f06e 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,7 @@ A meta of last read/downloaded message is stored in the config file so that in s ### Support: | Category | Support | |--|--| -|Language | `Python 3.6 ` and above| +|Language | `Python 3.7 ` and above| |Download media types| audio, document, photo, video, video_note, voice| ### ToDo: @@ -123,18 +123,17 @@ All the downloaded media will be stored inside respective direcotry named in t | voice_note | path/to/project/voice_note | ## Proxy -`Socks5` proxy is supported in this project currently. To use it, simply create a `config.ini` file in the path of this project, and edit it with your proxy server info as follow: +`socks4, socks5, http` proxies are supported in this project currently. To use it, add the following to the bottom of your `config.yaml` file -```ini -[proxy] -enabled = True -hostname = 127.0.0.1 -port = 1080 -username = -password = +```yaml +proxy: + scheme: socks5 + hostname: 11.22.33.44 + port: 1234 + username: your_username + password: your_password ``` - -Then the proxy will automatically be enabled. +If your proxy doesn’t require authorization you can omit username and password. Then the proxy will automatically be enabled. ## Contributing ### Contributing Guidelines From 9a53c11a0201aa804d3da65be4d4fb3c6d1bcb1d Mon Sep 17 00:00:00 2001 From: Dineshkarthik Date: Tue, 19 Jul 2022 12:13:56 +0200 Subject: [PATCH 23/23] build(deps-dev): add pre-commit V2.20.0 --- dev-requirements.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/dev-requirements.txt b/dev-requirements.txt index 014dac7..8b32322 100644 --- a/dev-requirements.txt +++ b/dev-requirements.txt @@ -2,6 +2,7 @@ black==22.3.0 isort==5.10.1 mock==4.0.3 mypy==0.961 +pre-commit==2.20.0 pylint==2.14.5 pytest==7.0.1 pytest-cov==3.0.0