mirror of
https://github.com/Dineshkarthik/telegram_media_downloader.git
synced 2024-12-31 03:01:46 +08:00
Merge pull request #23 from Dineshkarthik/github-actions
GitHub Actions
This commit is contained in:
commit
1df2762963
5 changed files with 68 additions and 125 deletions
|
@ -1,113 +0,0 @@
|
|||
version: 2
|
||||
|
||||
jobs:
|
||||
test-3.6:
|
||||
docker:
|
||||
- image: circleci/python:3.6.9
|
||||
environment:
|
||||
CIRCLE_ARTIFACTS: /tmp/circleci-artifacts
|
||||
CIRCLE_TEST_REPORTS: /tmp/circleci-test-results
|
||||
LOG_DIR: ${CIRCLE_ARTIFACTS}/testresults/
|
||||
steps:
|
||||
- checkout
|
||||
- run:
|
||||
name: Get setuptools
|
||||
shell: /bin/bash
|
||||
command: sudo pip install --upgrade pip setuptools codecov
|
||||
- run:
|
||||
name: Install dependencies
|
||||
shell: /bin/bash
|
||||
command: sudo make deps
|
||||
- run:
|
||||
name: Static Type Check - Mypy
|
||||
shell: /bin/bash
|
||||
command: sudo make static_type_check
|
||||
- run:
|
||||
name: Code Check - Pylint
|
||||
shell: /bin/bash
|
||||
command: sudo make pylint
|
||||
- run:
|
||||
name: Run test
|
||||
shell: /bin/bash
|
||||
command: |
|
||||
sudo make -e test
|
||||
codecov
|
||||
- store_artifacts:
|
||||
path: /tmp/circleci-artifacts
|
||||
|
||||
test-3.7:
|
||||
docker:
|
||||
- image: circleci/python:3.7.8
|
||||
environment:
|
||||
CIRCLE_ARTIFACTS: /tmp/circleci-artifacts
|
||||
CIRCLE_TEST_REPORTS: /tmp/circleci-test-results
|
||||
LOG_DIR: ${CIRCLE_ARTIFACTS}/testresults/
|
||||
steps:
|
||||
- checkout
|
||||
- run:
|
||||
name: Get setuptools
|
||||
shell: /bin/bash
|
||||
command: sudo pip install --upgrade pip setuptools codecov
|
||||
- run:
|
||||
name: Install dependencies
|
||||
shell: /bin/bash
|
||||
command: sudo make deps
|
||||
- run:
|
||||
name: Static Type Check - Mypy
|
||||
shell: /bin/bash
|
||||
command: sudo make static_type_check
|
||||
- run:
|
||||
name: Code Check - Pylint
|
||||
shell: /bin/bash
|
||||
command: sudo make pylint
|
||||
- run:
|
||||
name: Run test
|
||||
shell: /bin/bash
|
||||
command: |
|
||||
sudo make -e test
|
||||
codecov
|
||||
- store_artifacts:
|
||||
path: /tmp/circleci-artifacts
|
||||
|
||||
test-3.8:
|
||||
docker:
|
||||
- image: circleci/python:3.8.3
|
||||
environment:
|
||||
CIRCLE_ARTIFACTS: /tmp/circleci-artifacts
|
||||
CIRCLE_TEST_REPORTS: /tmp/circleci-test-results
|
||||
LOG_DIR: ${CIRCLE_ARTIFACTS}/testresults/
|
||||
steps:
|
||||
- checkout
|
||||
- run:
|
||||
name: Get setuptools
|
||||
shell: /bin/bash
|
||||
command: sudo pip install --upgrade pip setuptools codecov
|
||||
- run:
|
||||
name: Install dependencies
|
||||
shell: /bin/bash
|
||||
command: sudo make deps
|
||||
- run:
|
||||
name: Static Type Check - Mypy
|
||||
shell: /bin/bash
|
||||
command: sudo make static_type_check
|
||||
- run:
|
||||
name: Code Check - Pylint
|
||||
shell: /bin/bash
|
||||
command: sudo make pylint
|
||||
- run:
|
||||
name: Run test
|
||||
shell: /bin/bash
|
||||
command: |
|
||||
sudo make -e test
|
||||
codecov
|
||||
- store_artifacts:
|
||||
path: /tmp/circleci-artifacts
|
||||
|
||||
|
||||
workflows:
|
||||
version: 2
|
||||
tests:
|
||||
jobs:
|
||||
- test-3.6
|
||||
- test-3.7
|
||||
- test-3.8
|
34
.github/workflows/main.yml
vendored
Normal file
34
.github/workflows/main.yml
vendored
Normal file
|
@ -0,0 +1,34 @@
|
|||
name: Unittest
|
||||
|
||||
on: [push]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
|
||||
runs-on: ${{ matrix.os }}
|
||||
strategy:
|
||||
matrix:
|
||||
os: [ubuntu-latest, macos-latest, windows-latest]
|
||||
python-version: [ '3.6', '3.7', '3.8']
|
||||
name: Test - Python ${{ matrix.python-version }} on ${{ matrix.os }}
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: Set up Python
|
||||
uses: actions/setup-python@v2
|
||||
with:
|
||||
python-version: ${{ matrix.python-version }}
|
||||
- name: Get setuptools
|
||||
run: pip install --upgrade pip setuptools codecov
|
||||
- name: Install dependencies
|
||||
run: make deps
|
||||
- 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
|
||||
codecov
|
||||
env:
|
||||
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
|
|
@ -2,12 +2,12 @@
|
|||
<h1 align="center">Telegram Media Downloader</h1>
|
||||
|
||||
<p align="center">
|
||||
<a href="https://circleci.com/gh/Dineshkarthik/telegram_media_downloader/tree/master"><img alt="Build Status" src="https://circleci.com/gh/Dineshkarthik/telegram_media_downloader.svg?style=svg"></a>
|
||||
<a href="https://github.com/Dineshkarthik/telegram_media_downloader/actions"><img alt="Unittest" src="https://github.com/Dineshkarthik/telegram_media_downloader/workflows/Unittest/badge.svg"></a>
|
||||
<a href="https://codecov.io/gh/Dineshkarthik/telegram_media_downloader"><img alt="Coverage Status" src="https://codecov.io/gh/Dineshkarthik/telegram_media_downloader/branch/master/graph/badge.svg"></a>
|
||||
<a href="https://github.com/Dineshkarthik/telegram_media_downloader/blob/master/LICENSE"><img alt="License: MIT" src="https://black.readthedocs.io/en/stable/_static/license.svg"></a>
|
||||
<a href="https://github.com/python/black"><img alt="Code style: black" src="https://img.shields.io/badge/code%20style-black-000000.svg"></a>
|
||||
</p>
|
||||
|
||||
![Unittest]()
|
||||
### Overview:
|
||||
Download all media files from a conversation or a channel that you are a part of from telegram.
|
||||
A meta of last read/downloaded message is stored in the config file so that in such a way it won't download the same media file again.
|
||||
|
|
|
@ -5,8 +5,8 @@ from typing import List, Tuple, Optional
|
|||
from datetime import datetime as dt
|
||||
|
||||
import asyncio
|
||||
import yaml
|
||||
import pyrogram
|
||||
import yaml
|
||||
|
||||
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
import os
|
||||
import copy
|
||||
import logging
|
||||
import platform
|
||||
import unittest
|
||||
|
||||
import mock
|
||||
|
@ -16,7 +17,9 @@ from media_downloader import (
|
|||
process_messages,
|
||||
)
|
||||
|
||||
MOCK_DIR = "/root/project"
|
||||
MOCK_DIR: str = "/root/project"
|
||||
if platform.system() == "Windows":
|
||||
MOCK_DIR = "\\root\\project"
|
||||
MOCK_CONF = {
|
||||
"api_id": 123,
|
||||
"api_hash": "hasw5Tgawsuj67",
|
||||
|
@ -27,6 +30,13 @@ MOCK_CONF = {
|
|||
}
|
||||
|
||||
|
||||
def platform_generic_path(_path: str) -> str:
|
||||
platform_specific_path: str = _path
|
||||
if platform.system() == "Windows":
|
||||
platform_specific_path = platform_specific_path.replace("/", "\\")
|
||||
return platform_specific_path
|
||||
|
||||
|
||||
class MockMessage:
|
||||
def __init__(self, **kwargs):
|
||||
self.message_id = kwargs.get("id")
|
||||
|
@ -130,9 +140,9 @@ class MockClient:
|
|||
|
||||
async def download_media(self, *args, **kwargs):
|
||||
assert "AwADBQADbwAD2oTRVeHe5eXRFftfAg", args[0]
|
||||
assert "/root/project/voice/voice_2019-07-25T14:53:50.ogg", kwargs[
|
||||
"file_name"
|
||||
]
|
||||
assert platform_generic_path(
|
||||
"/root/project/voice/voice_2019-07-25T14:53:50.ogg"
|
||||
), kwargs["file_name"]
|
||||
return kwargs["file_name"]
|
||||
|
||||
|
||||
|
@ -160,7 +170,9 @@ class MediaDownloaderTestCase(unittest.TestCase):
|
|||
self.assertEqual(
|
||||
(
|
||||
"AwADBQADbwAD2oTRVeHe5eXRFftfAg",
|
||||
"/root/project/voice/voice_2019-07-25T14:53:50.ogg",
|
||||
platform_generic_path(
|
||||
"/root/project/voice/voice_2019-07-25T14:53:50.ogg"
|
||||
),
|
||||
"ogg",
|
||||
),
|
||||
result,
|
||||
|
@ -178,7 +190,11 @@ class MediaDownloaderTestCase(unittest.TestCase):
|
|||
async_get_media_meta(message.photo, "photo")
|
||||
)
|
||||
self.assertEqual(
|
||||
("AgADBQAD5KkxG_FPQValJzQsJPyzhHcC", "/root/project/photo/", None),
|
||||
(
|
||||
"AgADBQAD5KkxG_FPQValJzQsJPyzhHcC",
|
||||
platform_generic_path("/root/project/photo/"),
|
||||
None,
|
||||
),
|
||||
result,
|
||||
)
|
||||
|
||||
|
@ -198,7 +214,9 @@ class MediaDownloaderTestCase(unittest.TestCase):
|
|||
self.assertEqual(
|
||||
(
|
||||
"AQADAgADq7LfMgAEIdy5DwAE4w4AAwI",
|
||||
"/root/project/document/sample_document.pdf",
|
||||
platform_generic_path(
|
||||
"/root/project/document/sample_document.pdf"
|
||||
),
|
||||
"pdf",
|
||||
),
|
||||
result,
|
||||
|
@ -220,7 +238,7 @@ class MediaDownloaderTestCase(unittest.TestCase):
|
|||
self.assertEqual(
|
||||
(
|
||||
"AQADAgADq7LfMgAEIdy5DwAE5Q4AAgEC",
|
||||
"/root/project/audio/sample_audio.mp3",
|
||||
platform_generic_path("/root/project/audio/sample_audio.mp3"),
|
||||
"mp3",
|
||||
),
|
||||
result,
|
||||
|
@ -239,7 +257,11 @@ class MediaDownloaderTestCase(unittest.TestCase):
|
|||
async_get_media_meta(message.video, "video")
|
||||
)
|
||||
self.assertEqual(
|
||||
("CQADBQADeQIAAlL60FUCNMBdK8OjlAI", "/root/project/video/", "mp4"),
|
||||
(
|
||||
"CQADBQADeQIAAlL60FUCNMBdK8OjlAI",
|
||||
platform_generic_path("/root/project/video/"),
|
||||
"mp4",
|
||||
),
|
||||
result,
|
||||
)
|
||||
|
||||
|
|
Loading…
Reference in a new issue