Skip to content

Commit

Permalink
Merge pull request #159 from Dineshkarthik/feature-check-for-new-rele…
Browse files Browse the repository at this point in the history
…ases

Check for new releases
  • Loading branch information
Dineshkarthik authored Feb 14, 2022
2 parents af9bcbe + 0ec1b2a commit b2688c0
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ A meta of last read/downloaded message is stored in the config file so that in s
| Category | Support |
|--|--|
|Language | `Python 3.6 ` and above|
|Download media types| audio, document, photo, video, voice|
|Download media types| audio, document, photo, video, video_note, voice|

### ToDo:
- Add support for multiple channels/chats.
Expand Down
2 changes: 2 additions & 0 deletions media_downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from utils.file_management import get_next_name, manage_duplicate_file
from utils.log import LogFilter
from utils.meta import print_meta
from utils.updates import check_for_updates

logging.basicConfig(
level=logging.INFO,
Expand Down Expand Up @@ -360,6 +361,7 @@ def main():
len(set(FAILED_IDS)),
)
update_config(updated_config)
check_for_updates()


if __name__ == "__main__":
Expand Down
2 changes: 1 addition & 1 deletion utils/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Init namespace"""

__version__ = "1.4.0"
__version__ = "1.4.1"
__license__ = "MIT License"
__copyright__ = (
"Copyright (C) 2019 Dineshkarthik <https://github.com/Dineshkarthik>"
Expand Down
38 changes: 38 additions & 0 deletions utils/updates.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
"""Utility module to check for new release of telegram-media-downloader"""
import http.client
import json

from rich.console import Console
from rich.markdown import Markdown

from . import __version__

# pylint: disable = C0301
def check_for_updates() -> None:
"""Checks for new releases.
Using Github API checks for new release and prints information of new release if available.
"""
try:
headers: dict = {
"Content-Type": "application/json",
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 Safari/537.36",
}
conn = http.client.HTTPSConnection("api.github.com")
conn.request(
method="GET",
url="/repos/Dineshkarthik/telegram_media_downloader/releases/latest",
headers=headers,
)
res = conn.getresponse()
latest_release: dict = json.loads(res.read().decode("utf-8"))
if f"v{__version__}" != latest_release["tag_name"]:
update_message: str = (
f"## New versionof Telegram-Media-Downloader is available - {latest_release['name']}\n"
f"You are using an outdated version v{__version__} please pull in the changes using `git pull` or download the latest release.\n\n"
f"Find more details about the latest release here - {latest_release['html_url']}"
)
console = Console()
console.print(Markdown(update_message))
except Exception:
pass

0 comments on commit b2688c0

Please sign in to comment.