分享一下视频采集优酷的asp.net2.0代码

其实很简单,不过写出来以后,发现采集很慢,不会ASP,所以也没有看懂别人的ASP的,希望知道的留下言,帮帮忙,谢谢了。

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;
using System.Text;
using System.Net;
using System.Text.RegularExpressions;

public partial class admin_GetData : System.Web.UI.Page
{
    ArrayList urls = new ArrayList();
    ArrayList flashs=new ArrayList();
    int ID;
    int num;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["admin"] == null)
        {
            Response.Redirect("login.aspx");
        }
    }

    //获取网页源代码
    private string getCode(string url)
    {
        WebRequest wrequest = WebRequest.Create(url);
        WebResponse wresponse = wrequest.GetResponse();
        Stream resStream = wresponse.GetResponseStream();
        StreamReader sr = new StreamReader(resStream, Encoding.UTF8);
        string theCode = sr.ReadToEnd();
        resStream.Close();
        sr.Close();
        return theCode;
    }
    //获取本专辑的视频个数
    private void getNum(string codes)
    {
        string reg="视频: <span class=/"num/">//d+</span>";
        Match mc = Regex.Match(codes, reg);
        string s = Regex.Replace(mc.ToString(), @"[^/d]+", "");
        num = Int32.Parse(s);
        //Response.Write("<script>alert('" + s + "')</script>");
    }
    //获取视频ID
    private void getID(string url)
    {
        string s = Regex.Replace(url, @"[^/d]+", "");
        ID = Int32.Parse(s);
    }
    //抓取得播放页
    private void getPlay(string codes)
    {
        string reg = @"http://v.youku.com/v_playlist/(/w*|/d*)+/.htm.";
        Match mc = Regex.Match(codes, reg);
        string url = mc.ToString();
        url = url.Substring(0, url.Length - 6);
        for (int i = 0; i < num; i++)
        {
            urls.Add(url + i.ToString() + ".html"); 
        }
    }
    //从播放页获取flasH地址
    private string getFlash(string url)
    {
        string reg = "var videoId2=/".+/"";
        Match mc = Regex.Match(getCode(url), reg);
        string s = mc.ToString();
        s = s.Substring(14, s.Length - 15);
        return s;
    }
    //设置FLASH
    private void setFlash()
    {
        string s = "http://player.youku.com/player.php/Type/Folder/Fid/" + ID.ToString() + "/Ob/";
        for (int i = 0; i < num; i++)
        {
            flashs.Add(s + i.ToString() + "/sid/" + getFlash(urls[i].ToString()) + "/v.swf");
        }
    }

    protected void Button3_Click(object sender, EventArgs e)
    {
        string codes = getCode(this.TextBox1.Text);
        this.getNum(codes);
        this.getID(this.TextBox1.Text);
        this.getPlay(codes);
        this.setFlash();
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < num-1; i++)
        {
            sb.Append(flashs[i] + "|");
        }
        sb.Append(flashs[num - 1]);
        this.TextBox2.Text = sb.ToString();
    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        Response.Redirect("addVideo.aspx?flashs=" + this.TextBox2.Text);
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值