From c8b6cc39ac4e921f852d2479208a8b9fdff7eab0 Mon Sep 17 00:00:00 2001 From: ArabCoders Date: Sun, 21 Jan 2024 00:12:53 +0300 Subject: [PATCH] initial work to add version checker. --- .github/workflows/main.yml | 1 + app/main.py | 26 +++++++++++++++++++++++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 5e055c04..2107b203 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -92,6 +92,7 @@ jobs: cache-to: type=gha, scope=${{ github.workflow }} - name: Version tag + if: github.event_name != 'pull_request' uses: arabcoders/action-python-autotagger@master with: token: ${{ secrets.GITHUB_TOKEN }} diff --git a/app/main.py b/app/main.py index 2f8fdfe0..52be5d8a 100644 --- a/app/main.py +++ b/app/main.py @@ -8,7 +8,7 @@ import random from Config import Config from DownloadQueue import DownloadQueue from Utils import ObjectSerializer, Notifier -from aiohttp import web +from aiohttp import web, client from aiohttp.web import Request, Response from Webhooks import Webhooks from player.M3u8 import M3u8 @@ -128,6 +128,30 @@ class Main: await self.sio.emit('initial_data', self.serializer.encode(data), to=sid) + async def version_check(self): + try: + with client.ClientSession() as session: + async with session.get('https://api.github.com/repos/ytptube/ytptube/tags') as r: + if r.status != 200: + return + + tags = await r.json() + + for tag in tags: + tagName = tag.get('name') + splitTagName = tagName.split('-') + if len(splitTagName) > 1: + tagName = splitTagName[0] + cvDate = self.config.version.split('-') + if tagName > cvDate[0]: + self.config.new_version_available = True + self.logger.info( + f'New version {tagName} available at') + break + + except Exception as e: + pass + def addTasks(self): tasks_file: str = os.path.join(self.config.config_path, 'tasks.json') if not os.path.exists(tasks_file):