D
D
Dima Fott2021-02-08 18:25:02
Python
Dima Fott, 2021-02-08 18:25:02

Audio error when using InlineQueryResultAudio?

There is a code that uses a regular expression to catch a link to a track from the site.

URL = 'https://ruv.hotmo.org/search?q='
HEADERS = {'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:71.0) Gecko/20100101 Firefox/71.0', 'accept': '*/*'}

@bot.inline_handler(lambda query: len(query.query) > 0)
def query_text(query):
    try:
        vvod = re.search(r'(.+)', query.query)
    except AttributeError as ex:
        return
    vvod = vvod.group(1)
    try:
        html = requests.get(URL+vvod, headers=HEADERS)
        if html.status_code == 200:
            track = re.search(r'href="(.+)" class="track__download-btn"', html.text)
            executor = re.search(r'<div class="track__desc">(.+)</div>', html.text)
            name = 'test'
            if track and executor and name:
                track = track.group(1)
                executor = executor.group(1)
                button2 = types.InlineQueryResultAudio(
                    id='2', 
                    audio_url=track,
                    title=name,
                    performer=executor
                )
                bot.answer_inline_query(query.id, [button2], cache_time=1)


The problem is that the track appears in the tooltip, but when you try to send it, Failed comes out.602157a4f004a669866995.png

602157ae344d9832977028.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dima Fott, 2021-02-08
@dimkafmlovediankafm

I made the same regex and the same request in the bot's PM - everything works fine.
Made from another site - the same problem, although if you insert a link that the site gives directly - everything works fine. I do through catching - does not work.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question