LibreTube/.github/runOnRelease.py

59 lines
1.7 KiB
Python
Raw Normal View History

2023-01-23 18:51:18 +05:30
from pyrogram import Client
2023-11-19 22:37:39 +05:30
from pyrogram.types import InlineKeyboardButton, InlineKeyboardMarkup, InputMediaDocument
2023-01-23 18:51:18 +05:30
from requests import get
from config_file import TG_API_HASH, TG_API_ID, TG_TOKEN
2023-01-23 18:51:18 +05:30
2023-11-19 22:37:39 +05:30
req = get("https://api.github.com/repos/Libre-Tube/LibreTube/releases/latest").json()
2023-01-25 00:41:43 +05:30
TG_CHANNEL = "LibreTube"
2023-01-23 18:51:18 +05:30
def get_changelog():
2023-11-19 22:37:39 +05:30
data = get("https://api.github.com/repos/libre-tube/LibreTube/contents/fastlane/metadata/android/en-US/changelogs").json()
2023-01-23 18:51:18 +05:30
last_log = max([int(file["name"].replace(".txt", "")) for file in data])
log = get(
f"https://github.com/libre-tube/LibreTube/raw/master/fastlane/metadata/android/en-US/changelogs/{last_log}.txt"
).text
return log
buttons = InlineKeyboardMarkup(
[
[
InlineKeyboardButton("Release", url=req.get("html_url")),
InlineKeyboardButton(
"F-droid", url="https://www.f-droid.org/packages/com.github.libretube/"
),
InlineKeyboardButton(
"IzzyOnDroid",
url="https://apt.izzysoft.de/fdroid/index/apk/com.github.libretube",
),
]
]
)
2023-11-19 22:37:39 +05:30
assets, files = req.get("assets"), list()
for file in assets:
with open(name, "wb") as f:
f.write(get(file.get("browser_download_url"), stream=True).content)
2023-01-23 18:51:18 +05:30
files.append(
2023-11-19 22:37:39 +05:30
InputMediaDocument(
2023-11-27 17:17:04 +05:30
file.get("name")
2023-11-19 22:37:39 +05:30
)
2023-01-23 18:51:18 +05:30
)
2023-11-19 22:37:39 +05:30
2023-01-23 18:51:18 +05:30
caption = f"**LibreTube {tag} // Privacy Simplified**\n\n<u>What's Changed?</u>\n```{get_changelog()}```"
2023-11-19 22:37:39 +05:30
2023-01-23 18:51:18 +05:30
with Client("bot", TG_API_ID, TG_API_HASH, bot_token=TG_TOKEN) as app:
app.send_photo(
2023-01-25 00:41:43 +05:30
TG_CHANNEL,
2023-01-23 18:51:18 +05:30
"https://i.ibb.co/LJ9r4hP/LT.jpg",
caption,
reply_markup=buttons,
)
2023-01-25 00:41:43 +05:30
app.send_media_group(TG_CHANNEL, files)