Yıllar önce Adsense için blog’larken kendim için bu kodu yazmıştım, sanırım daha önce böyle bir kod paylaşan olmamıştır. En azından kendim yazmadan önce bakmıştım ama bulamamıştım. Aşağıdaki kod arama kriteriniz sonucu istediğiniz adet youtube video embed kodunu size veriyor. Temelinde sadece youtube’un arama sonuç sayfasının html’lerini inceleyip string ayrıştırma ile loop içinde dönüp istediğiniz kriterlerdeki verileri size dönüyor.
protected void btnSearch_Click(object sender, EventArgs e)
{
listUrl.Items.Clear();
try
{
for (int i = 1; i < = Convert.ToInt32(txtCount.Text)/20; i +=1)
{
string site = "http://www.youtube.com/results?search_query=" + (txtSearch.Text).Replace(' ', '+') + "&page="+i;
Uri MyUrl = new Uri(site);
WebRequest WebReq = WebRequest.Create(MyUrl);
HttpWebRequest HWebReq = (HttpWebRequest)WebReq;
WebResponse WebResp = WebReq.GetResponse();
Stream WebRespStream = WebResp.GetResponseStream();
StreamReader StrReader = new StreamReader(WebRespStream);
ArrayList WebDataArray = new ArrayList();
string line = null;
while ((line = StrReader.ReadLine()) != null)
{
if (line.Contains("/watch?v="))
WebDataArray.Add(line);
}
foreach (string myurl in WebDataArray)
{
getRecursiveVideo(myurl);
}
}
}
catch (Exception ex)
{
}
lblcount.Text = listUrl.Items.Count.ToString();
}
public void getRecursiveVideo(string imgUrl)
{
int StartPos, EndPos;
int TirnakPos;
if ((StartPos = imgUrl.IndexOf("/watch?v=")) != -1)
{
StartPos += 9;
TirnakPos = imgUrl.IndexOf('\"', StartPos);
EndPos = TirnakPos;
if (EndPos > StartPos)
{
string BulunanUrl = imgUrl.Substring(StartPos, EndPos - StartPos);
ListItem l = new ListItem();
l.Text = BulunanUrl;
if (!listUrl.Items.Contains(l))
{
listUrl.Items.Add(BulunanUrl);
urlHolder.InnerHtml += "Click" + "";
}
int uzunluk = imgUrl.Length;
string newurl = imgUrl.Substring(EndPos, uzunluk - EndPos);
if ((newurl.IndexOf("/watch?v=")) != -1)
getRecursiveVideo(newurl);
else
return;
}
}
}
follow:
hocam elıne sağlık suan sık kullanılanlra ekledım,inşallah işime yarıyacaktır yane sorunum,youtube den link lerı eklettıgım zaman verıtabanıma embed kodları otomatık olarak video bulucaktır inşallah =) dogrumudur hocam sence bulucakmıdır
hocam yaa sizden bişi rica ediceğim acaba örnek olarak projeı upload edebılırmısınız
yane biz acemiler için list ıtem falan aklım cok karıstı lütfen hocam