GithubHelp home page GithubHelp logo

tulir / tgfilestream Goto Github PK

View Code? Open in Web Editor NEW
192.0 21.0 718.0 40 KB

A Telegram bot that can stream Telegram files to users over HTTP.

License: GNU Affero General Public License v3.0

Python 100.00%
telegram-bot telethon python asyncio aiohttp

tgfilestream's Introduction

tgfilestream

A Telegram bot that can stream Telegram files to users over HTTP.

Setup

Install dependencies (see requirements.txt), configure environment variables (see below) and run with python3 -m tgfilestream.

A reverse proxy is recommended to add TLS. When using a reverse proxy, keep HOST as-is, but add the publicly accessible URL to PUBLIC_URL. The URL should include the protocol, e.g. https://example.com.

Environment variables

  • TG_API_ID (required) - Your Telegram API ID.
  • TG_API_HASH (required) - Your Telegram API hash.
  • PORT (defaults to 8080) - The port to listen at.
  • HOST (defaults to localhost) - The host to listen at.
  • PUBLIC_URL (defaults to http://localhost:8080) - The prefix for links that the bot gives.
  • TRUST_FORWARD_HEADERS (defaults to false) - Whether or not to trust X-Forwarded-For headers when logging requests.
  • DEBUG (defaults to false) - Whether or not to enable extra prints.
  • LOG_CONFIG - Path to a Python basic log config. Overrides DEBUG.
  • REQUEST_LIMIT (default 5) - The maximum number of requests a single IP can have active at a time.
  • CONNECTION_LIMIT (default 20) - The maximum number of connections to a single Telegram datacenter.
  • TG_START_MESG - The message that should be shown in Telegram chat, in case of non-media message.
  • TG_G_C_MESG - The message that should be shown in a Telegram Group chat.
  • TG_SESSION_NAME (defaults to tgfilestream) - The name of the Telethon session file to use.
  • TG_BOT_FATHER_TOKEN (defaults to None) - This option is mutually exclusive to TG_SESSION_NAME, and if set, the client will login as a bot, instead of an user.

tgfilestream's People

Contributors

odysseusmax avatar spechide avatar tulir 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

tgfilestream's Issues

Download does not start

The download from the provided link does not start. I've set everything correctly (I think, I've set HOST to 0.0.0.0 and PUBLIC_URL to http://serverip:8080), the bot provides a link (in stdout because I needed the link there), the link seem to work correctly because I can see the file name and the weight, but the download is stuck at 0%

How do I start the bot

Please make instructions, or tell me and I'll contribute them. It doesn't say anywhere where I should put in the api id's and so on.

Please add detailed instruction

Hello.
I am teying to run this bot on my own server (ubuntu 18.04) but i had no luck.

It would be awesome to add how to run the bot.

thanks.

Bot stopped responding

Hi. Somehow after some time, the bot stop responding to some users. There is no error in log, everything looks fine from it but the bot itself will either not responding or take a long time to respond in Telegram. Also the download never starts, it will just loading until browser timeout.

Can you possibly guess what is the cause?

I am using default value for REQUEST_LIMIT and CONNECTION_LIMIT if they matter.
Also I am hosting the script on i7-4770k 32GB RAM server.

Thanks.

Requirements changed

Hey @tulir
so I was trying the project and I countered an error about telethon package, the requirements file installs the newest one but the project dependence was Telethon 1.10.10.
I can pull request and fix it if it's okay

thanks for your awesome repo

How to add connection limit per link

Hi, i need to add connection limit per each link, can i do this with TGFileStream?
(also connection limit per IP doesn't work for me btw, I can download with 32 connections even if I set limitations)

Import Error

Traceback (most recent call last):
File "/usr/lib64/python3.6/runpy.py", line 193, in _run_module_as_main
"main", mod_spec)
File "/usr/lib64/python3.6/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/root/tgfilestream/tgfilestream/main.py", line 22, in
from .telegram import client, transfer
File "/root/tgfilestream/tgfilestream/telegram.py", line 20, in
from .paralleltransfer import ParallelTransferrer
File "/root/tgfilestream/tgfilestream/paralleltransfer.py", line 17, in
from contextlib import asynccontextmanager
ImportError: cannot import name 'asynccontextmanager'

404: not found

Hi
after create link, i get error 404: not found.
i check with source, and find bug in line 63
this line return NONE : message = cast(Message, await client.get_messages(entity=peer, ids=msg_id))
How i can fix it?

bad link for quote file

For files SourceData-2367(2).bin generate url link in tg msg url='http://shtxt.info:8081/10428973817370732/SourceData-2367(2'

Message(
 id=607046,
 to_id=PeerUser(
  user_id=881691
 ),
 date=datetime.datetime(2020, 1, 17, 23, 2, 49, tzinfo=datetime.timezone.utc),
 message='',
 out=False,
 mentioned=False,
 media_unread=False,
 silent=False,
 post=False,
 from_scheduled=False,
 legacy=False,
 edit_hide=False,
 from_id=737175067,
 fwd_from=MessageFwdHeader(
  date=datetime.datetime(2020, 1, 17, 23, 2, 18, tzinfo=datetime.timezone.utc),
  from_id=881691,
  from_name=None,
  channel_id=None,
  channel_post=None,
  post_author=None,
  saved_from_peer=None,
  saved_from_msg_id=None
 ),
 via_bot_id=None,
 reply_to_msg_id=None,
 media=MessageMediaDocument(
  document=Document(
   id=5264830663021823536,
   access_hash=6128510746949776469,
   file_reference=b'\x01\x00\tCF^">\x0f\x01\n\x82HS\xb8\x0f\x83w\xe2<\xa6G.Q\x84',
   date=datetime.datetime(2020, 1, 17, 23, 2, 17, tzinfo=datetime.timezone.utc),
   mime_type='application/octet-stream',
   size=3828,
   dc_id=2,
   attributes=[
    DocumentAttributeFilename(
     file_name='SourceData-2367(2).bin'
    ),
   ],
   thumbs=[
   ]
  ),
  ttl_seconds=None
 ),
 reply_markup=None,
 entities=[
 ],
 views=None,
 edit_date=None,
 post_author=None,
 grouped_id=None,
 restriction_reason=[
 ]
)
Message(
 id=607047,
 to_id=PeerUser(
  user_id=737175067
 ),
 date=datetime.datetime(2020, 1, 17, 23, 2, 49, tzinfo=datetime.timezone.utc),
 message='Link to download file: http://shtxt.info:8081/10428973817370732/SourceData-2367(2).bin.bin)',
 out=True,
 mentioned=False,
 media_unread=False,
 silent=False,
 post=False,
 from_scheduled=False,
 legacy=False,
 edit_hide=False,
 from_id=881691,
 fwd_from=None,
 via_bot_id=None,
 reply_to_msg_id=607046,
 media=None,
 reply_markup=None,
 entities=[
  MessageEntityTextUrl(
   offset=23,
   length=63,
   url='http://shtxt.info:8081/10428973817370732/SourceData-2367(2'
  ),
 ],
 views=None,
 edit_date=None,
 post_author=None,
 grouped_id=None,
 restriction_reason=[
 ]
)

Have any example for this package?

Hi
I install this package and run it
After open http://localhost:8080/ I get error : 404: Not Found
Where can I set file id for download?

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.