How to get video file stream from embed url in c# - c#

I tried this below code but video is not playing.
var httpClient = new HttpClient();
var data = await httpClient.GetByteArrayAsync(new Uri("http://www.youtube.com/embed/iRFE-sKOp4I"));
var file = await KnownFolders.MusicLibrary.CreateFileAsync("myfile.mp4", CreationCollisionOption.ReplaceExisting);
var targetStream = await file.OpenAsync(FileAccessMode.ReadWrite);
await targetStream.AsStreamForWrite().WriteAsync(data, 0, data.Length);
await targetStream.FlushAsync();
targetStream.Dispose();
Any one please help me to how to save download..thankyou

I agree with #x..., If you want to download video from Youtube, you need to install the YoutubeExtractor.
But with that same code i can't to download different website videos.
I tested your code with a video download uri "http://video.ch9.ms/ch9/9b56/4f2d0b4d-ea37-4525-8833-128ad6e69b56/uwp01SeriesIntro.mp4", it works fine.
Actually I want to download openload.co/embed/EHmDelqNx94 video is there any possibility..
I just took a look at this video, I find this a web named openload, and this web service share free without limits, but you need to use the develop Api of it. For downloading, you can refer to the download APIs here.
the video url appears after click on play button, is there any way to handle click event by httpclient or any other clients
From the official document of this web, I found this:
get a download link by using download ticket.
You can refer to Download Link.
Update:
i tried openload api, but when get download link it showing captcha error, can you please help me for this
I just reproduced your problem, this is because your source for download is not a public source, it needed authentication. When you get the Download Ticket for download, although the Api said API-Login and API-Key are not required, you need to use the full path https://api.openload.co/1/file/dlticket?file={file}&login={login}&key={key} to get an authenticated ticket, then you can use this ticket to get the download URL.

Related

Download File From Website with URL Authentifikation C#

I am trying to download a file from one of this sites:
1cloudfile
bowfiles
games-database
Mainly games-database.com
I think all of this sites are using a similar System
For example games-database.com:
An example link: https://games-database.com/1JD4
There is one button on this website that opens a new window with a link
<button style="margin-bottom: 30px;" class="btn btn--primary type--uppercase" onclick="window.location = 'https://games-database.com/1JD4?pt=ZUVGTGRtaExNa3hIYkdJMllrcHZkbkJ6TjBGU1p6MDlPbWFXZ3IrNnZDMzI1MnZzVlVJU2hKQT0%3D'; return false;">download</button>
Link: https://games-database.com/1JD4?pt=ZUVGTGRtaExNa3hIYkdJMllrcHZkbkJ6TjBGU1p6MDlPbWFXZ3IrNnZDMzI1MnZzVlVJU2hKQT0%3D
This link is different everytime I refresh the page
It's easy to get this link with HTMLAgility Pack
using HtmlAgilityPack;
var link = doc.DocumentNode.SelectNodes("/html/body/div[2]/section/div/div/div/div[3]/div[2]/button")
.Select(p => p.InnerText).FirstOrDefault();
But when I try to download this I only get the page not the file
The working generated download link after the redirect looks like this:
https://dl5.cdnrobot.xyz/1JD4/Anomic_THE_NEW_GUI.txt?download_token=f58c9315280ed7474c15a329888ac8532e2af1cdaec045f4048bc51fcacd7e75
I don't know if the sites uses cookies or something else but maybe you can load the page in the background and then get the download link by tracking the redirects.
Thanks for everyone who wants to help!
I am on WPF .NET 6.0 btw
[EDIT]
I found a website called https://wheregoes.com and it manages to track the correct download URL
Then it tell me:
Status Code: 200 - Meta-Refresh Redirect
In conclusion I need a way to trace this redirect to get the download URL

Download pdf files from a link

i am working on .Net app that need to download research files from the given link. i checked that most of the published portal show the pdf files on pdf viewer and there to download the file, no .pdf link that can download directly. Can someone recommend how to download files in such cases. example i want to download the pdf from following link https://ietresearch.onlinelibrary.wiley.com/doi/pdf/10.1049/iet-epa.2019.0877 .
As #Philip-Stuyck mentioned in the comments, you can use HttpClient to download the file. Here is the sample code:
using var client = new HttpClient();
var uri = new Uri("https://ietresearch.onlinelibrary.wiley.com/doi/pdf/10.1049/iet-epa.2019.0877");
await using var s = await client.GetStreamAsync(uri);
await using var file = File.Create("iet-epa-localcopy.pdf");
await s.CopyToAsync(file);

Downloading youtube video info

I am trying to download response from this url
http://www.youtube.com/get_video_info?html5=1&video_id=sFwcLC5HC9I
The file it returns can be downloaded from browser, but when I try to save it with c# webclient I get only error message.
errorcode=180&status=fail&reason=HTTP+is+not+supported.
Is there any other way to download file from the API without using HTTP?
What have I tried (a is instance of WebClient):
byte[] policko = a.DownloadData("http://www.youtube.com/get_video_info?html5=1&video_id=sFwcLC5HC9I");
a.DownloadFile("http://www.youtube.com/get_video_info?html5=1&video_id=sFwcLC5HC9I", "filename");
a.DownloadString("http://www.youtube.com/get_video_info?html5=1&video_id=sFwcLC5HC9I");
The response you got indicates that HTTP is not supported for this API call. The next natural choice is HTTPS.
https://www.youtube.com/get_video_info?html5=1&video_id=sFwcLC5HC9I

Downloading a file from an Amazon shared link

I have been tasked with finding a way to save files given a link to someones amazon bucket. These files are attachments uploaded to a ticketing system, and when i used their API to pull the ticket out, i am given a link like the one below(I removed all the private stuff and replaced with XXXXX)
https://s3.amazonaws.com/cdn.XXXXXXX.com/data/helpdesk/attachments/production/36012348362/original/1.jpeg?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=XXXXXXXXXXXXXXXXXFus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20180808T205357Z&X-Amz-Expires=86400&X-Amz-Signature=XXXXXXXXXXXXXX-Amz-SignedHeaders=Host
As you can see, the links time out after 1 day. I am connecting 2 API's together, and i need to be able to upload an actual file into the second API instead of just placing a link that times out after a day. I have tried to use Webclient downloadfileAsync, but all i get is a blank file output. I can go to the link in my browser and do a right click, save image as, so i know its possible, but i havent had any luck programatically. Below is the code snipped i am currently using to try and download it.
using (WebClient wc = new WebClient())
{
wc.DownloadFileAsync(new System.Uri(url), "image.jpg");
}
Any insight or help would be awesome.
Thanks in advance!
I was able to get this working by not using the async version of DownloadFile. Thanks to all the people who helped me resolve this.

Googledrive app for windowsphone?

I am developing a Google Drive application for Windows Phone using URLs provided in the SDK through HTTPWebRequest. Is there an API for WP8 to develop Google Drive applications?
I downloaded all of the content without any problem. While I am uploading the MIMEtype, it is not always uploaded correctly, and is uploaded as an octet stream.
Please can anyone help with how to upload to Google Drive using C# code?
Thanks
Check the "Upload Files" section of the Google Drive SDK :
https://developers.google.com/drive/manage-uploads
i got solution, actually i am using string[] HeaderKeys = { "X-Upload-Content-Type" }; string[] HeaderValues = { "application/vnd.google-apps.folder" } for post method,
here i used request.contentType in the place of X-Upload-Content-Type now i am uploading all files with correct stream.

Categories

Resources