I try to download a video (any) from the Sibnet service, test for receiving a link to a video file, and successfully receive a normal Url , but at the same time, if you make a request to read a data stream, nothing happens and the data stream is always empty, although the response code is 200 .

In general, in order to get a link to the file, you need to do the following, get a link to the mpd file, rename mpd to mp4 , and make a request. If you do all this using a browser, it turns out that when you request the Url , you are redirected to one of the sibnet servers where the file is located (or rather, access from there will be allowed, the link is always different) . In my case, when requesting such an Url redirection occurs, and HttpClient simply reads the response of the headers, no more.

The code below is operational, but cannot read the content.

What can be done so that the content can be read, and so that the redirection works?

 public class Program { public static void Main(string[] args) { CookieCollection cookieCollection = new CookieCollection(); CookieContainer container = new CookieContainer(); container.Add(cookieCollection); HttpClientHandler clientHandler = new HttpClientHandler { AllowAutoRedirect = true, UseCookies = true }; HttpClient client = new HttpClient(clientHandler, true) { BaseAddress = new Uri("https://video.sibnet.ru/") }; string result = client.GetStringAsync ( new Uri( "/shell.php?videoid=3490241", UriKind.Relative) ).GetAwaiter().GetResult(); Regex regex = new Regex(@"\[\{src\:\s?\""(?<FilePath>[^\""]+)\"""); Match match = regex.Match(result); Console.WriteLine(match.Groups["FilePath"].Value.Replace("mpd", "mp4").Replace("m3u8", "mp4")); client.DefaultRequestHeaders.Referrer = new Uri(client.BaseAddress.OriginalString + "/shell.php?videoid=3490241"); client.DefaultRequestHeaders.Add("Origin", "https://video.sibnet.ru"); HttpResponseMessage message = client .GetAsync(new Uri(match.Groups["FilePath"].Value.Replace("mpd", "mp4").Replace("m3u8", "mp4"), UriKind.Relative)).GetAwaiter().GetResult(); message = message.EnsureSuccessStatusCode(); Stream fileData = message.Content.ReadAsStreamAsync().GetAwaiter().GetResult(); FileStream file = File.Create("sibnet.mp4"); byte[] data = new byte[8388608]; // 8 Mb 1024*1024*8 int offset = 0; while ((offset = fileData.Read(data, 0, data.Length)) != 0) file.Write(data, offset, data.Length); file.Close(); fileData.Close(); client.Dispose(); } 

    1 answer 1

    It turns out the problem was different, so that sibnet would give a link to the full file, you need to send a POST request with the content buffer_method: full , then you can find the full link to the file in the source code, but you should remember that sibnet checks 2 headers Origin and Referer . In general, the code below can be safely used as for downloading (any) video from sibnet .

    But I still have a question, how can I use the resulting Stream write down, for example, a file to a file or, for example, to a local socket server (streaming on a local network)?

     public class Program { public static async Task Main(string[] args) { Uri loadUri = new Uri("/shell.php?videoid=3490241", UriKind.Relative); Regex regex = new Regex(@"src\:\s?\""(?<FilePath>[^\""]+)\"""); CookieCollection cookieCollection = new CookieCollection(); CookieContainer container = new CookieContainer(); container.Add(cookieCollection); HttpClientHandler clientHandler = new HttpClientHandler { AllowAutoRedirect = true, UseCookies = true }; HttpClient client = new HttpClient(clientHandler, true) { BaseAddress = new Uri("https://video.sibnet.ru/") }; HttpResponseMessage result = await client.PostAsync(loadUri, new FormUrlEncodedContent(new []{new KeyValuePair<string, string>("buffer_method", "full")})); Match match = regex.Match(await result.Content.ReadAsStringAsync()); Console.WriteLine(match.Groups["FilePath"].Value); client.DefaultRequestHeaders.Referrer = new Uri(client.BaseAddress, loadUri); client.DefaultRequestHeaders.Add("Origin", client.BaseAddress.OriginalString); Stream message = await client.GetStreamAsync(new Uri(match.Groups["FilePath"].Value, UriKind.Relative)); FileStream file = File.Create("sibnet.mp4"); await message.CopyToAsync(file, 8388608); message.Dispose(); file.Dispose(); client.Dispose(); } }