Last active
February 2, 2025 21:16
-
-
Save MarshalX/3c99fcae532178928d93a7aae6f0efde to your computer and use it in GitHub Desktop.
Example of the most simple way to stream any video to Telegram Live Stream (Group Call) with https://github.com/MarshalX/tgcalls
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# before run this script install required packages via command below | |
# pip3 install -U pytgcalls==3.0.0.dev24 | |
import asyncio | |
import pytgcalls | |
import telethon | |
# EDIT THIS | |
# more info about API keys here https://docs.telethon.dev/en/latest/basic/signing-in.html | |
API_ID = 'ENTER_YOUR_VALUE' | |
API_HASH = 'ENTER_YOUR_VALUE' | |
CHAT_ID = '@tgcallschat' # it can be a channel too | |
INPUT_SOURCE = 'http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4' | |
# EDIT END | |
async def main(client): | |
group_call = pytgcalls.GroupCallFactory( | |
client, pytgcalls.GroupCallFactory.MTPROTO_CLIENT_TYPE.TELETHON | |
).get_group_call() | |
await group_call.join(CHAT_ID) | |
await group_call.start_video(INPUT_SOURCE) | |
await client.run_until_disconnected() | |
if __name__ == '__main__': | |
tele_client = telethon.TelegramClient('pytgcalls', int(API_ID), API_HASH) | |
tele_client.start() | |
asyncio.get_event_loop().run_until_complete(main(tele_client)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# before run this script install required packages via commands below | |
# pip3 install -U pytgcalls==3.0.0.dev24 | |
import asyncio | |
import pytgcalls | |
import pyrogram | |
# EDIT THIS | |
# more info about API keys here https://docs.pyrogram.org/intro/setup#api-keys | |
API_ID = 'ENTER_YOUR_VALUE' | |
API_HASH = 'ENTER_YOUR_VALUE' | |
CHAT_ID = '@tgcallschat' # it can be a channel too | |
INPUT_SOURCE = 'http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4' | |
# EDIT END | |
async def main(client): | |
group_call = pytgcalls.GroupCallFactory(client).get_group_call() | |
await group_call.join(CHAT_ID) | |
await group_call.start_video(INPUT_SOURCE) | |
await pyrogram.idle() | |
if __name__ == '__main__': | |
pyro_client = pyrogram.Client('pytgcalls', API_ID, API_HASH) | |
pyro_client.start() | |
asyncio.get_event_loop().run_until_complete(main(pyro_client)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# some code snippets | |
group_call_factory = GroupCallFactory(telethon) | |
group_call = group_call_factory.get_group_call() | |
await group_call.join('@tgcallschat') | |
# play nothing and stay connected | |
await group_call.start_audio() | |
# play image instead of video | |
await group_call.start_video('image.png', with_audio=False) | |
# play music with image above | |
await group_call.start_audio('music.mp3') | |
# pause media | |
await group_call.set_pause(False) # resume audio + video | |
await group_call.set_pause(True) # pause audio + video | |
await group_call.set_video_pause(False) # resume only ideo | |
await group_call.set_audio_pause(False) # resume only audio | |
# stop media | |
await group_call.stop_media() # stop audio + video | |
await group_call.stop_video() # only video | |
await group_call.stop_audio() # only audio | |
# get states | |
await group_call.is_video_paused | |
await group_call.is_audio_paused | |
await group_call.is_paused # when audio and video paused at the same time | |
await group_call.is_video_running | |
await group_call.is_audio_running | |
await group_call.is_running # when audio and video running at the same time | |
# custom event handlers | |
# gc is instance of GroupCall where event was occurred | |
@group_call.on_audio_playout_ended | |
async def audio_ended(gc, source): | |
print(f'audio ended: {source}') | |
@group_call.on_video_playout_ended | |
async def video_ended(gc, source): | |
print(f'video ended: {source}') | |
@group_call.on_playout_ended | |
async def media_ended(gc, source, media_type): | |
print(f'{media_type} ended: {source}') | |
# more examples with ways how to register own handlers (without decorators too) | |
# here: https://github.com/MarshalX/tgcalls/releases/tag/v2.1.0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# pip3 install pafy | |
# pip3 install youtube_dl | |
import pafy | |
CHAT_ID = '@tgcallschat' | |
YOUTUBE_URL = 'URL TO YOUTUBE VIDEO/LIVE HERE' | |
video = pafy.new(YOUTUBE_URL) | |
video_source = video.getbest().url | |
group_call = group_call_factory.get_group_call() | |
await group_call.join(CHAT_ID) | |
await group_call.start_video(video_source) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I have already deployed vro