Upload audio as instant link with download button in telethon bot - python

I want to send mp3 file to the user from telethon bot, when I do that with bot.send_file(supports_streaming=True) it arrives with delay like this:
https://i.stack.imgur.com/69oau.png
I also tried bot.upload_file which should upload file on telegram server and return InputFile, but calling bot.send_file(file=input_file) gives the same result.
What I want is to provide instant link to file with download button like this:
https://i.stack.imgur.com/epRQs.png
I've seen this in one audio book bot, it gives this download button immediately even for 200MB files. Help me to implement this please.

Telethon's docs for send_file says you can pass supports_streaming=True.

It seems like telethon doesn't have functionality for this kind of problem yet, but I found super easy solution in aiogram library, it accepts links as well as files which was useful in my case.
https://aiogram.2038.io/api/methods/send_audio/

Related

how to open url using telegram bot python code

I was wondering how to open URL by pressing inlinekeyboard button with my telegram bot using python.
Based on documentation this is supposed to work
button = types.ReplyKeyboardMarkup(one_time_keyboard=False, resize_keyboard=True) button.row( telebot.types.InlineKeyboardButton(text='Binance', url="my url") )
but it is not and I can't figure out why?
any kind of help is appreciated
You're trying to build a ReplyKeyboardMarkup but add an InlineKeyboardButton instead of a ReplyKeyboardButton, which is not supported. ReplyKeyboardMarkups are just shortcuts for sending predefined text messages and don't support opening URLs. See https://core.telegram.org/bots#keyboards.

How to get file from dropbox and upload on my server by using python

I am working on application where I am giving a functionality to user where they can signin from dropbox by using my application but when I am trying to get the file from Dropbox I am unable to do it. When user choose the desired file from dropbox and click on choose and then nothing happen. Can anyone please help out either is it possible to do it or not? If yes, how can we do it? I am at beginner level. Please help me out and explain the whole process to do it in detail.
Are you using public Dropbox files?
Then you just need to fetch the item by URL and download it. If this happens in a browser tool, you'll need JavaScript and not Python to download it.
Or you leave out JS and just use Python to render an HTML page where a button is for a Dropbox file and clicking the button triggers a download of the file. That is a generic HTML task you can search for.
If you need access to sign in Dropbox and view private files, consider using a Python library built around Dropbox.
See the Python Dropbox guide. Are you using a library like that? Please share as your question was vague.
https://www.dropbox.com/developers/documentation/python#
Also please share an explanation of what your logic is or a small code snippet. I can't see what you are doing yet so I don't know where you are missing something or making a mistake.
From the screenshot, I see you're using the Dropbox Chooser. That's a pre-built way to let your end-users select files from their Dropbox accounts and give them to your app.
Make sure you implement the success and cancel callback methods as documented there for the Chooser.
In the success callback, you'll get the information for the selected file(s). That occurs in JavaScript in the browser though, so if you need that on your server, you'll need to write some JavaScript to send that up to your server, e.g., via an AJAX call or a form or whatever means you use in your app.

Is there way to implement redirect to bot / channel in Telegram?

I using Python 3.8.2.
Is it possible to somehow implement in the code so that it goes to the desired # (bot or channel) itself? My further actions are not particularly important. I cannot find information anywhere on how to implement my idea.
Yes, if it was my bot, then I could just insert the TOKEN, but this is not my bot / channel
I have an idea to implement this using Selenium so that it clicks in the browser to the right moment, but maybe there is another way? Yes, this will be related to the Web version, since there are no ideas yet how to implement this in the desktop version.
I will describe the idea in more detail, immediately using the example of Selenium:
There is a code - it contains steps. One of the steps EITHER go to #, or search chats by element (of course, I have to be logged in in the browser)
But maybe there is a simpler way, without Selenium, to implement the step of the script going to the bot / channel page in the Telegram?
You can use telethon library that can allows you to programmatically interact with Telegram, like: start chat, write to anybody, get chat messages history and so on.
Here are simple example and full documentation about how to use it.

Downloading past twitch broadcasts in python

I have been trying to download past broadcasts for a streamer on twitch using python. I found this python code online:
https://gist.github.com/baderj/8340312
However, when I try to call the functions I am getting errors giving me a status 400 message.
Unsure if this is the code I want to download the video (as an mp4) or how to use it properly.
And by video I mean something like this as an example: www(dot)twitch.tv/imaqtpie/v/108909385 //note cant put more than 3 links since I don't have 10 reputation
Any tips on how i should go about doing this?
Here's an example of running it in cmd:
python twitch_past_broadcast_downloader.py 108909385
After running it, it gave me this:
Exception API returned 400
This is where i got the information on running it:
https://www.johannesbader.ch/2014/01/find-video-url-of-twitch-tv-live-streams-or-past-broadcasts/
Huh it's not as easy at it seems ... The code you found on this gist is quite old and Twitch has completely changed its API. Now you will need a Client ID to download videos, in order to limit the amount of video you're downloading.
If you want to correct this gist, here are simple steps you can do :
Register an application : Everything is explained here ! Register you app and keep closely your client id.
Change API route : It is no longer '{base}/api/videos/a{id_}' but {base}/kraken/videos/{id_} (not sure about the last one). You will need to change it inside the python code. The doc is here.
Add the client id to the url : As said in the doc, you need to give a header to the request you make, so add a Client-ID: <client_id> header in the request.
And now I think you will need to start debugging a bit, because it is old code :/
I will try myself to do it and I will edit this answer when I'm finished, but try yourself :)
See ya !
EDIT : Mhhh ... It doesn't seem to be possible anyway to download a video with the API :/ I was thinking only links to API changed, but the chunks section of the response from the video url disappeared and Twitch is no longer giving access to raw videos :/
Really sorry I told you to do that, even with the API I think is no longer possible :/
You can download past broadcasts of Twitch videos with Python library streamlink.
You will need OAuth token which you can generate with the command
streamlink --twitch-oauth-authenticate
Download VODs with:
streamlink --twitch-oauth-token <your-oauth-token> https://www.twitch.tv/videos/<VideoID> best -o <your-output-folder>

Image Uploading Script in Python

I was trying to make an image uploading script for Postimage.org.
I tried searching for an API but it seems that there is not any available. Can anyone help me how to make this script ? I don't have any idea how to make the uploading proccess? I think that something that i should do is open the image file in read binary mode ("rb").
Anyway i am waiting for your suggestions and ideas.
Firstly you should think about what happens when you press the upload button on the website. What your script could do is mimic this functionality, because essentially all it's triggering is a POST request to the web server with the specified information in the form and the image file data. You can initiate HTTP requests (e.g. GET, POST, etc.) using a library such as Requests (http://docs.python-requests.org/en/latest/index.html).
However, as this seems to have been discussed before, I will instead point you in the right direction: Send file using POST from a Python script

Categories