bing.com 動画検索

賛否両論あるようだけど、bing.comの動画のサムネイルはおもしろい。これを一度にダウンロードして、同時に再生するプログラムとかを作るとおもしろいと思ったので、手始めにこの動画サムネイルをダウンロード出来ないかどうか試してみた。

簡単にできた。普通にHTMLを処理しているので、形式を変更されると問題なのと、今のところ、最初のページしかフェッチしていないが問題か。ちなみに、次のページに関しては、クエリに、"&first=21"とかっていう感じで先頭のサムネイルの番号を渡せばいいらしい。

using System;
using System.Text;
using System.Net;
using System.Web;
using System.Text.RegularExpressions;

public class BingFlvFetcher
{
 public static void Main(string[] args)
 {
  Console.CancelKeyPress += (o, e) => {throw new ApplicationException("Interrupted by Ctrl-C");};

  string qurl = string.Format("http://www.bing.com/videos/search?q={0}", args[0]);
  
  int id = 0;
  using (WebClient wc = new WebClient())
  {
   byte[] data = wc.DownloadData(qurl);
   string html = Encoding.UTF8.GetString(data);
   Regex re = new Regex("vidInsertPlayer\\(\"([^\"]+)");
   Match m = re.Match(html);
   while (m.Success)
   {
    string href = HttpUtility.UrlDecode(m.Groups[1].ToString());
    Console.WriteLine(href);
    wc.DownloadFile(href, string.Format("{0:D4}.flv", ++id));
    
    m = m.NextMatch();
   }
  }
 }
}