gram-js / gramjs

NodeJS/Browser MTProto API Telegram client library,
MIT License
1.31k stars 180 forks source link

Downloadmedia stuck #137

Open zjmqlf opened 3 years ago

zjmqlf commented 3 years ago
const client = new TelegramClient(session, api_id, api_hash, {});
await client.start();
const result = await client.invoke(new Api.messages.GetHistory({
    peer: 'channelId',
    limit: 20,
}));
for (const msg of result.messages) {
    if (msg.media) {
        setTimeout(some code, 600000)
        const buffer = await client.downloadMedia(msg.media, {
            workers: 1,
        });
        //console.log(buffer)
    }
}
};

Downloadmedia usually downloads 500MB files in 2 to 3 minutes, but sometimes 1MB or even 100kb files get stuck after an hour. I don't know whether there is a problem with the files on the server or the network. It's obviously unreasonable to manually close the whole program and run it again for the first time. I plan to set a timer. If 20 media are downloaded, it will get stuck in the fourth round, The downloadmedia status is read after 10 minutes. If the download is not finished, cancel the fourth downloadmedia and automatically run the four downloadmedia. Is there any API to cancel downloadmedia

iAkashPattnaik commented 3 years ago

maybe try increasing the workers the max is 15.

painor commented 3 years ago

This might be related to disconnects. if you have logging on can you check if any disconnects have happened while downloading ?

zjmqlf commented 3 years ago

Logger.setlevel ("error") is set;, Running on the server, I can't see the real-time network speed,The console did not output error messages, and the program did not exit. The program has been stuck downloading

iAkashPattnaik commented 3 years ago

@zjmqlf maybe try commenting the line "Logger.setLevel("error")" and checking.

painor commented 3 years ago

it should be"info" to see disconnects.