I want to get audio from a video. I send a link to a video -but I can not get a file from it. Perhaps the solution is somewhere close, but I can not guess it.

var video= await youtubeClient.Videos.GetAsync("https://www.youtube.com/watch?v=1La4QzGeaaQ");
Console.WriteLine($"Title: {video.Title}");
Console.WriteLine($"Duration: {video.Duration}");
Console.WriteLine($"Author: {video.Author}");
var streamManifest= await youtubeClient.Videos.Streams.GetManifestAsync("https://www.youtube.com/watch?v=1La4QzGeaaQ");
var streamInfo= (AudioOnlyStreamInfo)streamManifest.GetAudioOnlyStreams().GetWithHighestBitrate(); //get stream here
bot.SendAudioAsync(e.Message.Chat.Id, streamInfo.Url);

What is the problem now? Why didn't you like the code from the question?

EvgeniyZ2022-02-13 15:34:00

@EvgeniyZ file not coming to chat

dasper2022-02-13 15:48:26

How does telegram send files? Everyone has one link or what? If there is one, then with all these manipulations, YouTube gives a personal link for you, with your unique token and other things, it should not work for others. Here you probably need to look in the direction of "save the file and transfer it further", the YouTube library can give you a Stream, which you can already try to send (though I don’t know if telegrams allow you to send a file in streams /bytes). But where to dig, I think you understand.

EvgeniyZ2022-02-13 16:34:23

@EvgeniyZ thought about it, but didn't want to save the files. Nevertheless thank you!

dasper2022-02-13 18:58:29

And I'm not talking about saving, I'm talking about Stream, that is, direct stream transmission, without saving. Well, about saving, I just gave you this as an example, so that it is clear that your bot should be some kind of intermediary between YouTube and the client, because the link is working only for him. But this is now only speculation, nothing more. Try, study, try to give a link to a friend, what do you get, can you reproduce? Also look at how and what exactly is sent by telegram, because I don’t use it at all ... If the link is one-time and the telegram loads on it, then here’s the problem for you.

EvgeniyZ2022-02-13 19:18:11