Show time when live event starts

This commit is contained in:
blank X 2021-08-19 01:38:57 +07:00
parent 46d841fa85
commit ec3dac53e7
Signed by: blankie
GPG Key ID: CC15FC822C7F61F5
2 changed files with 14 additions and 0 deletions

View File

@ -9,6 +9,7 @@ storage:
config: config:
notify_chat: 558772678 notify_chat: 558772678
wait_seconds: 1800 wait_seconds: 1800
time_offset: +07:00
channels: channels:
- UCL_qhgtOy0dy1Agp8vkySQg - UCL_qhgtOy0dy1Agp8vkySQg
- UCHsx4Hqa-1ORjQTh9TYDhww - UCHsx4Hqa-1ORjQTh9TYDhww

View File

@ -7,6 +7,7 @@ import asyncio
import logging import logging
import yaml import yaml
import feedparser import feedparser
from datetime import datetime, timedelta
from telethon import TelegramClient from telethon import TelegramClient
from youtube_dl import YoutubeDL from youtube_dl import YoutubeDL
from youtube_dl.extractor import youtube from youtube_dl.extractor import youtube
@ -28,6 +29,12 @@ if config.get('storage'):
storage_message_id = config['storage'].get('storage_message_id') storage_message_id = config['storage'].get('storage_message_id')
notify_chat = config['config']['notify_chat'] notify_chat = config['config']['notify_chat']
wait_seconds = config['config']['wait_seconds'] wait_seconds = config['config']['wait_seconds']
time_offset = config['config'].get('time_offset', '00:00')
time_offset_neg = time_offset.startswith('-')
if time_ottset_neg or time_offset.startswith('+'):
time_offset = time_offset[1:]
hours, minutes = time_offset.split(':')
time_offset_td = timedelta(hours=int(hours), minutes=int(minutes))
channels = config['config']['channels'] channels = config['config']['channels']
invidious_instances = config['config'].get('invidious_instances', []) invidious_instances = config['config'].get('invidious_instances', [])
@ -91,6 +98,12 @@ async def _handle_video(video_id, video_title):
notify_text = 'Live event started' notify_text = 'Live event started'
human_end_schedule_time = match.group(3) human_end_schedule_time = match.group(3)
if end_schedule_time := int(end_schedule_time): if end_schedule_time := int(end_schedule_time):
human_end_schedule_time += ' ('
if time_offset_neg:
human_end_schedule_time += str(datetime.fromtimestamp(end_schedule_time) - time_offset_td)
else:
human_end_schedule_time += str(datetime.fromtimestamp(end_schedule_time) + time_offset_td)
human_end_schedule_time += f' {"-" if time_offset_neg else "+"}{time_offset})'
tmp_wait_time = end_schedule_time - time.time() tmp_wait_time = end_schedule_time - time.time()
if tmp_wait_time > wait_time: if tmp_wait_time > wait_time:
wait_time = tmp_wait_time wait_time = tmp_wait_time