Al sana nasıl olduğuna dair youtube dan video indirmeyi örnekler olarak göstereyim ( tabi .Net dilinde kodlama bu )

emojileri forum kendi yerleştiriyor saçma olmuş biraz ama idare et birde http ve https olaylarını artık sen halledersin.

Birde görünüme takılma örnekler kolsun diye bu kadar basit bir görünüm sahip zaten amac kodlama mantıgını vermek

View kısmı için







YouTube URL:
td>


td>
tr>

td>

Width="100" />
td>
tr>

asp:DropDownList>
td>


td>
tr>
table>



div>

Process yani işlem kısmı için
protected void btnProcess_Click(object sender, EventArgs e)
{
try
{
Uri videoUri = new Uri(txtYouTubeURL.Text);
string videoID = HttpUtility.ParseQueryString(videoUri.Query).Get("v");
string videoInfoUrl = "http://www.youtube.com/get_video_info?video_id=" + videoID;

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(videoInfoUrl);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();

Stream responseStream = response.GetResponseStream();
StreamReader reader = new StreamReader(responseStream, Encoding.GetEncoding("utf-8"));

string videoInfo = HttpUtility.HtmlDecode(reader.ReadToEnd());

NameValueCollection videoParams = HttpUtility.ParseQueryString(videoInfo);

if (videoParams["reason"] != null)
{
lblMessage.Text = videoParams["reason"];
return;
}

string[] videoURLs = videoParams["url_encoded_fmt_stream_map"].Split(',');

foreach (string vURL in videoURLs)
{
string sURL = HttpUtility.HtmlDecode(vURL);

NameValueCollection urlParams = HttpUtility.ParseQueryString(sURL);
string videoFormat = HttpUtility.HtmlDecode(urlParams["type"]);

sURL = HttpUtility.HtmlDecode(urlParams["url"]);
sURL += "&signature=" + HttpUtility.HtmlDecode(urlParams["sig"]);
sURL += "&type=" + videoFormat;
sURL += "&title=" + HttpUtility.HtmlDecode(videoParams["title"]);

videoFormat = urlParams["quality"] + " - " + videoFormat.Split(';')[0].Split('/')[1];

ddlVideoFormats.Items.Add(new ListItem(videoFormat, sURL));
}

btnProcess.Enabled = false;
ddlVideoFormats.Visible = true;
btnDownload.Visible = true;
lblMessage.Text = string.Empty;
}
catch (Exception ex)
{
lblMessage.Text = ex.Message;
lblMessage.ForeColor = Color.Red;
return;
}
}

private void Completed(object sender, AsyncCompletedEventArgs e)
{
lblMessage.Text = "Video downloaded on: " + DateTime.Now.ToString();
lblMessage.ForeColor = Color.Green;
}


buda button click için

protected void btnDownload_Click(object sender, EventArgs e)
{
try
{
string sURL = ddlVideoFormats.SelectedValue;

if (string.IsNullOrEmpty(sURL))
{
lblMessage.Text = "Unable to locate the Video.";
return;
}

NameValueCollection urlParams = HttpUtility.ParseQueryString(sURL);

string videoTitle = urlParams["title"] + " " + ddlVideoFormats.SelectedItem.Text;
string videoFormt = HttpUtility.HtmlDecode(urlParams["type"]);
videoFormt = videoFormt.Split(';')[0].Split('/')[1];

string downloadPath = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
string sFilePath = string.Format(Path.Combine(downloadPath, "Downloads\\{0}.{1}"), videoTitle, videoFormt);

WebClient webClient = new WebClient();
webClient.DownloadFileCompleted += new AsyncCompletedEventHandler(Completed);
webClient.DownloadFileAsync(new Uri(sURL), sFilePath);
}
catch (Exception ex)
{
lblMessage.Text = ex.Message;
lblMessage.ForeColor = Color.Red;
return;
}
}