Skip to content
This repository has been archived by the owner on May 7, 2021. It is now read-only.

Commit

Permalink
添加RestSharp引用
Browse files Browse the repository at this point in the history
  • Loading branch information
htynkn committed May 6, 2013
1 parent b9ee7e5 commit c8b1ee4
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 16 deletions.
30 changes: 14 additions & 16 deletions VideoDownloadHelper.Doudan/Doudan.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
using NSoup.Nodes;
using NSoup;
using System.Net;
using System.Text.RegularExpressions;
using RestSharp;
using VideoDownloadHelper.Toudan;


[assembly: Addin]
Expand Down Expand Up @@ -57,22 +60,17 @@ public List<BaseItem> GetList()

String temp = WebHelper.GetHtmlCodeByWebClientWithGzip(this.Url, "gbk");
Document doc = NSoupClient.Parse(temp);
Elements items = doc.Select("div[class=pack pack_video_card]");
foreach (Element item in items)
{
Element e1 = item.Select("h1[class=caption] a").First;
Element e2 = item.Select("ul[class=info]").First;
String title = e1.Attr("title");
String url = e1.Attr("href");
String time = e2.Select("li").First.OwnText().Substring("时长:".Length);
String upOwner = e2.Select("li a").First.Attr("title");
String key = url.Substring(url.LastIndexOf("/") + 1);
key = key.Remove(key.IndexOf("."));

BaseItem b = new BaseItem() { Url = "http://www.tudou.com/programs/view/" + key + "/", Name = title, Time = time, Owner = upOwner };

this.Items.Add(b);
}

Regex r1=new Regex(@"var lid = '\d+';");
Match m1=r1.Match(doc.Html());
Regex r2 = new Regex(@"\d+");
String lid = r2.Match(m1.ToString()).ToString();
String baseUrl = "http://www.tudou.com/plcover/coverPage/getIndexItems.html?lid={id}&page=1&pageSize=500";

var request = new RestRequest(baseUrl, RestSharp.Method.GET);
request.AddUrlSegment("id",lid);
RestClient rc = new RestClient();
IRestResponse<Message> message= rc.Execute<Message>(request);

return this.Items;
}
Expand Down
12 changes: 12 additions & 0 deletions VideoDownloadHelper.Doudan/DoudanItem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace VideoDownloadHelper.Toudan
{
public class DoudanItem
{
public String title { get; set; }
}
}
13 changes: 13 additions & 0 deletions VideoDownloadHelper.Doudan/Message.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace VideoDownloadHelper.Toudan
{
class Message
{
public int count { get; set; }
public List<DoudanItem> items { get; set; }
}
}
5 changes: 5 additions & 0 deletions VideoDownloadHelper.Doudan/VideoDownloadHelper.Doudan.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@
<HintPath>..\packages\Nsoup\NSoup.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="RestSharp, Version=104.1.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\RestSharp.104.1\lib\net35\RestSharp.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
Expand All @@ -50,6 +53,8 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Doudan.cs" />
<Compile Include="DoudanItem.cs" />
<Compile Include="Message.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
Expand Down
1 change: 1 addition & 0 deletions VideoDownloadHelper.Doudan/packages.config
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Mono.Addins" version="1.0" targetFramework="net35" />
<package id="RestSharp" version="104.1" targetFramework="net35" />
</packages>

0 comments on commit c8b1ee4

Please sign in to comment.