Code Monkey home page Code Monkey logo

pytgcalls's Introduction

pytgcalls logo

A simple and elegant client that allows you to make group voice calls quickly and easily.
Examples Documentation PyPi Channel Chat

PyTgCalls PyPI Downloads

This project allows making Telegram call using MtProto and WebRTC, this is possible thanks to the power of NTgCalls library and @evgeny-nadymov

Example Usage

from pytgcalls import PyTgCalls
from pytgcalls import idle
from pytgcalls.types import MediaStream
...
chat_id = -1001185324811
app = PyTgCalls(client)
app.start()
app.play(
    chat_id,
    MediaStream(
        'http://docs.evostream.com/sample_content/assets/sintel1m720p.mp4',
    )
)
idle()

Features

  • Prebuilt wheels for macOS, Linux and Windows.
  • Supporting all type of MTProto libraries: Pyrogram, Telethon and Hydrogram.
  • Work with voice chats in channels and chats.
  • Join as channels or chats.
  • Mute/unmute, pause/resume, stop/play, volume control and more...

Requirements

How to install?

Here's how to install the PyTgCalls lib, the commands are given below:

# With Git
pip install git+https://github.com/pytgcalls/pytgcalls -U

# With PyPi (Recommended)
pip install py-tgcalls -U

Key Contributors

  • @Laky-64 (DevOps Engineer, Software Architect):
    • Played a crucial role in developing PyTgCalls being an ex developer of pyservercall and of tgcallsjs.
    • Automation with GitHub Actions
  • @kuogi (Senior UI/UX designer, Documenter):
    • As a Senior UI/UX Designer, Kuogi has significantly improved the user interface of our documentation, making it more visually appealing and user-friendly.
    • Played a key role in writing and structuring our documentation, ensuring that it is clear, informative, and accessible to all users.
  • @vrumger (Senior Node.js Developer, Software Architect):
    • Has made important fixes and enhancements to the WebRTC component of the library, improving its stability and performance.
    • Main developer of TgCallsJS
  • @alemidev (Senior Python Developer):
    • Has made important fixes and enhancements to the async part of the library

Junior Developers

  • @TuriOG (Junior Python Developer):
    • Currently working on integrating NTgCalls into PyTgCalls, an important step in expanding the functionality and usability of the library.

Special Thanks

  • @evgeny-nadymov: A heartfelt thank you to Evgeny Nadymov for graciously allowing us to use their code from telegram-react. His contribution has been pivotal to the success of this project.

pytgcalls's People

Contributors

doggyhaha avatar laky-64 avatar null-nick avatar odysseusmax avatar pranav-saraswat avatar pre-commit-ci[bot] avatar roj1512 avatar sunda001 avatar tappo03 avatar turiog avatar usernein avatar vrumger avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pytgcalls's Issues

Add a way for streaming in live from a webcam

Is your feature request related to a problem? Please describe.
From the API there are no way for streaming in live from a webcam

Describe the solution you'd like
A method for streaming from a webcam, maybe with the option of choosing from which webcam (in case there are more webcams connected)

Describe alternatives you've considered

Additional context

Not working on Termux

Traceback (most recent call last):
  File "/data/data/com.termux/files/usr/lib/python3.10/site-packages/psutil/_common.py", line 403, in wrapper
    return cache[key]
KeyError: (('/proc',), frozenset())

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/data/data/com.termux/files/usr/lib/python3.10/site-packages/psutil/_pslinux.py", line 302, in <module>
    set_scputimes_ntuple("/proc")
  File "/data/data/com.termux/files/usr/lib/python3.10/site-packages/psutil/_common.py", line 405, in wrapper
    ret = cache[key] = fun(*args, **kwargs)
  File "/data/data/com.termux/files/usr/lib/python3.10/site-packages/psutil/_pslinux.py", line 269, in set_scputimes_ntuple
    with open_binary('%s/stat' % procfs_path) as f:
  File "/data/data/com.termux/files/usr/lib/python3.10/site-packages/psutil/_common.py", line 711, in open_binary
    return open(fname, "rb", **kwargs)
PermissionError: [Errno 13] Permission denied: '/proc/stat'
Traceback (most recent call last):
  File "/storage/emulated/0/shubhendra/bot/telegram/ban-channel-accounts-in-vc/test.py", line 11, in <module>
    from pytgcalls import PyTgCalls
  File "/data/data/com.termux/files/usr/lib/python3.10/site-packages/pytgcalls/__init__.py", line 2, in <module>
    from .methods.custom_api.custom_api import CustomAPI
  File "/data/data/com.termux/files/usr/lib/python3.10/site-packages/pytgcalls/methods/__init__.py", line 3, in <module>
    from .core import Core
  File "/data/data/com.termux/files/usr/lib/python3.10/site-packages/pytgcalls/methods/core/__init__.py", line 10, in <module>
    from .spawn_process import SpawnProcess
  File "/data/data/com.termux/files/usr/lib/python3.10/site-packages/pytgcalls/methods/core/spawn_process.py", line 2, in <module>
    from collections import Callable
ImportError: cannot import name 'Callable' from 'collections' (/data/data/com.termux/files/usr/lib/python3.10/collections/__init__.py)

Vidio Auto stop

When i am playing yt live or vidio after some min vidio is stoping auto anyway to fix it

Sometimes raw file doesn't play

Sometimes after starting GroupCall, nothing happens, bot will stay mute, and after several seconds, bot will leave voicechat.
I have to execute my code several times to make it play my music.
raw file is ok and has no problems.
i think this is a bug in pytgcalls
thanks

In some cases there are freezes.

In some cases there are freezes. The server is very powerful. But in some cases, videos or music continue to freeze. how did i fix it?

JS Syntax error while calling run(app)

My code:

import pytgcalls
from pyrogram import Client
app = Client('session')

tg = pytgcalls.PyTgCalls(port=6540, log_mode=True)
tg.run(app)
tg.join_group_call(chat_id,  'input.raw', 160)

And this is the error I am getting while running tg.run(app):

/home/chaitanya/my-python-stuff/pytgcalls_tests/pytgcalls/pytgcalls/js/rtc_connection.js:6
    #tgcalls = null;
    ^

SyntaxError: Invalid or unexpected token
    at Module._compile (internal/modules/cjs/loader.js:723:23)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
    at Function.Module._load (internal/modules/cjs/loader.js:585:3)
    at Module.require (internal/modules/cjs/loader.js:692:17)
    at require (internal/modules/cjs/helpers.js:25:18)
    at Object.<anonymous> (/home/chaitanya/my-python-stuff/pytgcalls_tests/pytgcalls/pytgcalls/js/core.js:2:23)
    at Module._compile (internal/modules/cjs/loader.js:778:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)

I don't understand what the problem is, have I set up something wrong?

UpdateGroupCallConnection Problem and Python3.10 support

If do you have problem like:

    from pyrogram.raw.types import UpdateGroupCallConnection
ImportError: cannot import name 'UpdateGroupCallConnection' from 'pyrogram.raw.types' (/python3/site-packages/pyrogram/raw/types/__init__.py)

Or

  File "/python3\site-packages\async_lru.py", line 237, in wrapped
    return (yield from asyncio.shield(fut, loop=_loop))
TypeError: shield() got an unexpected keyword argument 'loop'

Just do this

pip3 uninstall pyrogram && pip3 install git+https://github.com/pyrogram/pyrogram -U

Ffprobe reader returns wrong video dimentions.

Describe the bug
When trying to play some files PyTgCalls raising an invalidvideoproportion error even if the video is valid.

To Reproduce
Steps to reproduce the behavior:

  1. Try to play with some files which has multiple streams

Expected behavior
File should play if it has valid video.

At present its raising an InvalidVideoProportion error since ffprobe is returning wrong values.

ImportError: cannot import name 'EditGroupCallParticipant' from 'pyrogram.raw.functions.phone'

Traceback (most recent call last):
  File "main.py", line 3, in <module>
    from callsmusic import run
  File "/app/callsmusic/__init__.py", line 1, in <module>
    from .callsmusic import pytgcalls, run
  File "/app/callsmusic/callsmusic.py", line 2, in <module>
    from pytgcalls import PyTgCalls
  File "/usr/local/lib/python3.7/dist-packages/pytgcalls/__init__.py", line 2, in <module>
    from .methods.logs.py_logs import PyLogs  # noqa: F401
  File "/usr/local/lib/python3.7/dist-packages/pytgcalls/methods/__init__.py", line 8, in <module>
    from .websocket import WebSocket
  File "/usr/local/lib/python3.7/dist-packages/pytgcalls/methods/websocket/__init__.py", line 2, in <module>
    from .change_volume_voice_call import ChangeVolumeVoiceCall
  File "/usr/local/lib/python3.7/dist-packages/pytgcalls/methods/websocket/change_volume_voice_call.py", line 5, in <module>
    from pyrogram.raw.functions.phone import EditGroupCallParticipant
ImportError: cannot import name 'EditGroupCallParticipant' from 'pyrogram.raw.functions.phone' (/usr/local/lib/python3.7/dist-packages/pyrogram/raw/functions/phone/__init__.py)

Roadmap

This PyTgCalls roadmap. If you have any requests feel free to leave them here/vote on others.

(There are listed only big change updates)

0.0.9 (2021-02-23)

  • Removed need of browser
  • Added js and ts code compilation
  • Kick event listener

0.1.0 (2021-03-10)

  • Added log mode
  • Fixed bugs

0.2.0 (2021-03-12)

  • Added PyPi installation

0.3.0 (2021-03-14)

  • Added long timed audio support
  • Added closed chat listener
  • Added live stream support
  • Added support for schema 126

0.4.0 (2021-03-25)

  • Added invite hash support
  • Closing stream when kicked from group
  • Added Pulse Stream (Beta)
  • Security Fix
  • Added the possibility to get max voice chat can start your server
  • Customizable cache time of get_full_chat

0.6.0 (2021-08-10)

  • Support to multilple instance
  • Module support
  • CustomApi Renewed

0.7.0 (2021-08-21)

  • STDIN and STDOUT binding to JS instead of use Internal Server
  • Custom Exceptions
  • Full Async
  • Defined Raw Updates
  • Linux ARM64v8 support
  • Windows support
  • macOS support
  • Pause and Resume result

0.8.0 (2021-09-07)

  • Pyrogram and Telethon support at same time
  • Mute and Unmute
  • Video calls support
  • Fifo support
  • Remote Audio/Video Playing
  • Internal FFMPEG Piping
  • Image Playing
  • Optional Audio Playing
  • Get group call participants list
  • Decorator when changing partecipants list
  • Pre-Made User Agent

0.9.0 (2022-05-01)

  • Screen sharing (Windows Desktop & Linux Desktop)
  • Add UDP Support
  • Improvements of the FFMpeg Additional Commands

No Date Picked

  • Add record calls support

Incorrect error return

Describe the bug
If a voice chat is scheduled it is returned: pytgcalls.exceptions.TelegramServerError: Already joined into group call

To Reproduce
Steps to reproduce the behavior:

  1. Schedule a voice chat, and use client.join_group_call()
  • OS: Ubuntu 20.04
  • NodeJS Version 17.01
  • Python Version 3.8.10

More information about the error being returned
https://nekobin.com/dabonayogo

Live stream or ffmpeg live conversion stopped

Check before if is changing the size of file (Is a method to check if ffmpeg is alive).

If is alive and stream is stopped, report to the issue with including last debug log and put in to nekobin.

JoinGroupCall with create option

Can you add method for create (start) new voice chat?
can you add change title of voice chat? + update if an admin change the title
can you optimize consume of cpu and ram on linux?

Video Group Call Support

Add the possibility to play Video in light way (VP8 or VP9)

  • Stream Video Reader (i420)
  • Stream Sender
  • Python methods
  • FFmpeg command

Can't install py-tgcalls

Describe the bug
Repositories return a 404 error

To Reproduce
Steps to reproduce the behavior:

  1. python3.10 -m pip install git+https://github.com/pytgcalls/pytgcalls -U
  2. ERROR https://pastebin.com/hEYXQ15a
    Expected behavior
    Successful installation

Log
Error log pip with verbosity 3 https://pastebin.com/BrMWGQ1a

Linux (please complete the following information):

  • OS: [Android 10 (termux)]
  • NodeJS Version [17.8.0]
  • Python Version [3.10.4]

Additional context
node-pre-gyp ERR! install response status 404 Not Found on https://node-webrtc.s3.amazonaws.com/wrtc/v0.4.7/Release/android-arm64.tar.gz
node-pre-gyp ERR! install error
node-pre-gyp ERR! stack Error: response status 404 Not Found on https://node-webrtc.s3.amazonaws.com/wrtc/v0.4.7/Release/android-arm64.tar.gz

Add VoIP::isPlaying()

Is your feature request related to a problem?
I would like to finish the outbound call (calls started by pytgcalls) when the play is over.

Describe the solution you'd like
I would like to have the isPlaying method added into pytgcalls. Some libraries based on libtgvoip are having it.

Describe alternatives you've considered
I couldn't find any alternative. I finishing the call after a manual timeout but I can't check if the audio file is still being played.

Additional context
I can pay for the implementation of it.

Windows Support!

I'm getting this problems

Traceback (most recent call last):
  File "tests/test.py", line 52, in <module>
    call_py.run()
  File "C:\Users\iraci\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\pytgcalls\pytgcalls.py", line 149, in run
    self._spawn_process(
  File "C:\Users\iraci\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\pytgcalls\methods\core\spawn_process.py", line 9, in _spawn_process
    p.start()
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.2288.0_x64__qbz5n2kfra8p0\lib\multiprocessing\process.py", line 121, in start
    self._popen = self._Popen(self)
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.2288.0_x64__qbz5n2kfra8p0\lib\multiprocessing\context.py", line 224, in _Popen
    return _default_context.get_context().Process._Popen(process_obj)
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.2288.0_x64__qbz5n2kfra8p0\lib\multiprocessing\context.py", line 327, in _Popen
    return Popen(process_obj)
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.2288.0_x64__qbz5n2kfra8p0\lib\multiprocessing\popen_spawn_win32.py", line 93, in __init__
    reduction.dump(process_obj, to_child)
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.2288.0_x64__qbz5n2kfra8p0\lib\multiprocessing\reduction.py", line 60, in dump
    ForkingPickler(file, protocol).dump(obj)
TypeError: cannot pickle '_queue.SimpleQueue' object

C:\Users\iraci\PycharmProjects\pytgcalls>Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.2288.0_x64__qbz5n2kfra8p0\lib\multiprocessing\spawn.py", line 107, in spawn_main
    new_handle = reduction.duplicate(pipe_handle,
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.2288.0_x64__qbz5n2kfra8p0\lib\multiprocessing\reduction.py", line 79, in duplicate
    return _winapi.DuplicateHandle(
PermissionError: [WinError 5] Access Denied

Caused by
https://github.com/pytgcalls/pytgcalls/blob/master/pytgcalls/methods/core/spawn_process.py

Called by
https://github.com/pytgcalls/pytgcalls/blob/master/pytgcalls/pytgcalls.py#L149

@pytgcalls.on_stream_end() randomly triggers.

I tried to implement an Auto-Skip to my bot, but when i play a song, on_stream_end triggers after 20-30secs of playing. If i remove the decor, songs play till the end, its not a conversion error so. Thats my code:

@call.on_stream_end()
def auto_skip(chat_id):
    print("AutoSkip")
    sira.task_done(chat_id)
    if sira.is_empty(chat_id):
        call.leave_group_call(chat_id)
        return app.send_message(chat_id, "**⏩ Sono uscito dalla chat vocale poichè nessuna canzone è in riproduzione**")
    else:
        next = sira.get(chat_id)["file_path"]
        file_id = next.replace("raw_files/", "")
        file_id = file_id.replace(".raw", "")
        with ydl:
            info = ydl.extract_info(file_id, download=False)
            call.change_stream(
                chat_id, next
            )
            thumb = info['thumbnail']
        return app.send_message(chat_id, f'▶️ <b>In riproduzione ora:</b> <i>{info["title"]!r}</i><a href={thumb!r}>‎</a>')

'PyTgCalls' from 'pytgcalls'

Traceback (most recent call last):
File "join_vc.py", line 7, in
from pytgcalls import PyTgCalls
ImportError: cannot import name 'PyTgCalls' from 'pytgcalls' (C:\Users\Kerim\AppData\Local\Temp_MEI1875682\pytgcalls_init_.pyc)

What is the way to solve this problem ? It runs on my computer but when I carry it to another it doesn't work :/

Here is my file:

import os
import time
import pyrogram
import pytgcalls

from pyrogram import Client
from pytgcalls import PyTgCalls
from pytgcalls import StreamType
from pytgcalls.types.input_stream import InputAudioStream
from pytgcalls.types.input_stream import InputStream

import argparse

parser = argparse.ArgumentParser(description='A test program.')
parser.add_argument('-session', '--session', help='Session')
parser.add_argument('-api_id', '--api_id', help='api_id')
parser.add_argument('-api_pass', '--api_pass', help='api_pass')
parser.add_argument('-chat', '--chat', help='chat')
args = parser.parse_args()
app = Client(
str(args.session),
api_id=int(args.api_id),
api_hash=str(args.api_pass)
)

print(args.session)
call_py = PyTgCalls(app)
call_py.start()

app.join_chat(str(args.chat))

chat = app.get_chat(args.chat)

print(chat["id"])

file = 'input.raw'
while not os.path.exists(file):
time.sleep(0.125)
call_py.join_group_call(
int(chat["id"]),
InputStream(
InputAudioStream(
file,
),
),
stream_type=StreamType().local_stream,
)
from pytgcalls import idle
idle()

[session] Waiting for 3 seconds before continuing (required by "channels.GetMessages")

Describe the bug
A clear and concise description of what the bug is.

To Reproduce
Steps to reproduce the behavior:

  1. Go to '...'
  2. Click on '....'
  3. See error

Expected behavior
A clear and concise description of what you expected to happen.

Log
If applicable, add logs on ultraverbose mode to help explain your problem.

Linux (please complete the following information):

  • OS: [e.g. Linux Mint 20.1] UBUNTU
  • NodeJS Version 16+
  • Python Version 3.8.6

Additional context
Add any other context about the problem here.

[session] Waiting for 3 seconds before continuing (required by "channels.GetMessages")
What is this warning for?

ERROR:root:joinCallError -> Error: No active voice chat found on XXXXX

Describe the bug
Hi,I have a problem when I using pytgcalls.I start main function from example/multiple_calls/example_multiple.py.And I can login 2 client successfully and I start video group call at group chat.But when I send message(!p1 or !p2) to group chat,the pytgcalls example printf error message
ERROR:root:JOIN_VOICE_CALL_ERROR -> init() got an unexpected keyword argument 'video_stopped'
ERROR:root:joinCallError -> Error: No active voice chat found on XXXXX
I don't know hot to solve this and who can help me.Thank you.

To Reproduce
Steps to reproduce the behavior:

  1. Go to 'start example/multiple_calls/example_multiple.py by python example_multiple.py'
  2. Click on 'phone number to login account A and B'
  3. Using telegram app which is account A to create a group call in a group chat which A and B are all in the group chat
  4. Send message !p2 to start join group call request
  5. The error messages are printf at console

Expected behavior
Can recevie input.raw on account A in group call

Log
ERROR:root:JOIN_VOICE_CALL_ERROR -> init() got an unexpected keyword argument 'video_stopped'
ERROR:root:joinCallError -> Error: No active voice chat found on XXXXX

Window (please complete the following information):

  • OS: [e.g. Window 10]
  • NodeJS Version [e.g. v16.13.0]
  • Python Version [e.g. 3.8.5]

0.8.1 Last Bugs Before the Stable Release

All bugs already reported in version 0.8.1 will be listed here, if you have any others to report, feel free to do so, they will be added to the list.

Please do not ask questions about how PyTgCalls work or how to use them, or if you misuse them unconsciously, Thanks in Advance! ❤️

Know bugs:

  • Leave Group Call every time you call it, raise the OnLeft Update
  • Participants on change raise also him self sometimes
  • Participants on change with anonymous admin raise an error of peer.user_id
  • JoinGroupCalls sometimes doesn't really join
  • Streaming optimization reader side
  • Overflow problem after a while
  • Needed a complete test

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.