本文整理汇总了C#中System.Net.WebClient.SkipUntilOrEmpty方法的典型用法代码示例。如果您正苦于以下问题:C# WebClient.SkipUntilOrEmpty方法的具体用法?C# WebClient.SkipUntilOrEmpty怎么用?C# WebClient.SkipUntilOrEmpty使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Net.WebClient
的用法示例。
在下文中一共展示了WebClient.SkipUntilOrEmpty方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
//.........这里部分代码省略.........
// Command: Checkout from https://htmlagilitypack.svn.codeplex.com/svn/trunk, revision HEAD, Fully recursive, Externals included
//// could it be used within a service worker?
//var doc = new HtmlAgilityPack.HtmlDocument();
//doc.LoadHtml(page0);
//var hrefList = doc.DocumentNode.SelectNodes("//a")
// .Select(xp => xp.GetAttributeValue("href", "not found"))
// .ToList();
////var xpage0 = XElement.Parse(
// System.Net.WebUtility.HtmlDecode(page0)
// );
// http://htmlagilitypack.codeplex.com/
//Console.WriteLine("DownloadString ... done " + new { p, hrefList.Count });
//p++;
// https://www.youtube.com/embed/FhEYvOYceNs?
while (!string.IsNullOrEmpty(page0))
{
// <iframe src="//www.youtube.com/embed/umfjGNlxWcw"
// <span class='embed-youtube' style='text-align:center; display: block;'><iframe class='youtube-player' type='text/html' width='640' height='390' src='https://www.youtube.com/embed/8vwzVVJ9lvg?version=3&rel=1&fs=1&showsearch=0&showinfo=1&iv_load_policy=1&wmode=transparent' frameborder='0' allowfullscreen='true'></iframe></span>
var prefix = "//www.youtube.com/embed/";
//var prefix = "https://www.youtube.com/embed/";
var embed = page0.SkipUntilOrEmpty(prefix);
var id = embed.TakeUntilIfAny("\"").TakeUntilIfAny("?");
var link = prefix + id;
page0 = embed.SkipUntilOrEmpty("?");
Console.WriteLine();
try
{
// a running applicaion should know when it can reload itself
// when all running tasks are complete and no new tasks are to be taken.
var videoUrl = link;
bool isYoutubeUrl = DownloadUrlResolver.TryNormalizeYoutubeUrl(videoUrl, out videoUrl);
//Console.WriteLine(new { sw.ElapsedMilliseconds, px, videoUrl });
// wont help
//var y = DownloadUrlResolver.GetDownloadUrls(link);
//var j = DownloadUrlResolver.LoadJson(videoUrl);
var c = new WebClient().DownloadString(videoUrl);
// "Kryon - Timing o..." The YouTube account associated with this video has been terminated due to multiple third-party notifications of copyright infringement.
// <link itemprop="url" href="http://www.youtube.com/user/melania1172">
// { videoUrl = http://youtube.com/watch?v=li0E4_7ap3g, ch_name = , userurl = https://youtube.com/user/ }
示例2: Main
static void Main(string[] args)
{
// if a network has a set of mp4 files
// which are tagged to yt
// can we get their channel info?
// X:\jsc.svn\examples\merge\Test\TestYouTubeExtractor\TestYouTubeExtractor\Program.cs
var p = "r:/media";
// should any calculated data be stored into a local sqlite for any restarts?
// http://blogs.msdn.com/b/csharpfaq/archive/2012/01/23/using-async-for-file-access-alan-berman.aspx
var sw = Stopwatch.StartNew();
Console.WriteLine(new { sw.ElapsedMilliseconds, p });
// can we async/await ourselves onto the other device?
// closer to the data?
foreach (var px in Directory.EnumerateFiles(p, "*.mp4"))
{
Console.WriteLine(new { sw.ElapsedMilliseconds, px } + " before Create");
// whats the link?
// Show Details Severity Code Description Project File Line
//Error Error signing output with public key from file 'taglib-sharp.snk' -- File not found.taglib-sharp CSC
// takes a while
// how would we know how much IO
// is being moved in this api?
// would a jsc nuget allow to augment such performance counters?
TagLib.File videoFile = TagLib.File.Create(px);
Console.WriteLine(new { sw.ElapsedMilliseconds, px } + " after Create");
//TagLib.Mpeg4.AppleTag customTag = (TagLib.Mpeg4.Comm)videoFile.GetTag(TagLib.TagTypes.Apple);
TagLib.Mpeg4.AppleTag customTag = (TagLib.Mpeg4.AppleTag)videoFile.GetTag(TagLib.TagTypes.Apple);
//customTag.SetDashBox("Producer", "Producer1",link);
//customTag.Comment = link;
var link = customTag.Album;
var videoUrl = link;
bool isYoutubeUrl = DownloadUrlResolver.TryNormalizeYoutubeUrl(videoUrl, out videoUrl);
Console.WriteLine(new { sw.ElapsedMilliseconds, px, videoUrl });
// wont help
//var y = DownloadUrlResolver.GetDownloadUrls(link);
//var j = DownloadUrlResolver.LoadJson(videoUrl);
var c = new WebClient().DownloadString(videoUrl);
var ch = c.SkipUntilOrEmpty("<a href=\"/channel/");
var ch_id = ch.TakeUntilOrEmpty("\"");
var ch_name = ch.SkipUntilOrEmpty(">").TakeUntilOrEmpty("<");
Console.WriteLine(new { sw.ElapsedMilliseconds, ch_name, ch_id });
// { ElapsedMilliseconds = 301714, ch_name = TheScariestMovieEver, ch_id = UCo8fiE2-s0SZu6Onb8lNLMQ }
// <a href="/channel/UCo8fiE2-s0SZu6Onb8lNLMQ" class=" yt-uix-sessionlink spf-link g-hovercard" data-ytid="UCo8fiE2-s0SZu6Onb8lNLMQ" data-sessionlink="ei=Ihu5VObLE4_2ygP--4HABQ" data-name="">TheScariestMovieEver</a>
// [95] = {[uid, o8fiE2-s0SZu6Onb8lNLMQ]}
// ElapsedMilliseconds = 0, p = r:/ media }
// ElapsedMilliseconds = 4219, px = r:/ media\'Battle of the Sexes' is Over!EVERYONE LOST!!.mp4 }
// before Create
//ElapsedMilliseconds = 171092, px = r:/media\'Battle of the Sexes' is Over! EVERYONE LOST!!.mp4
// }
// after Create
//ElapsedMilliseconds = 185783, px = r:/media\'Battle of the Sexes' is Over! EVERYONE LOST!!.mp4, videoUrl = http://youtube.com/watch?v=hsVdNrZZM2Q }
//url = http://youtube.com/watch?v=hsVdNrZZM2Q }
// https://www.youtube.com/channel/UCo8fiE2-s0SZu6Onb8lNLMQ
}
}
示例3: DoVideo
// CALLED BY?
public static void DoVideo(string link)
{
//Debugger.Break();
try
{
// a running applicaion should know when it can reload itself
// when all running tasks are complete and no new tasks are to be taken.
var videoUrl = link;
var prefix2 = "//www.youtube.com/watch?v=";
var prefix = "//www.youtube.com/embed/";
//var prefix = "https://www.youtube.com/embed/";
var embed = link.SkipUntilOrNull(prefix) ?? link.SkipUntilOrNull(prefix2);
var id = embed.TakeUntilIfAny("\"").TakeUntilIfAny("?");
bool isYoutubeUrl = DownloadUrlResolver.TryNormalizeYoutubeUrl(videoUrl, out videoUrl);
//Console.WriteLine(new { sw.ElapsedMilliseconds, px, videoUrl });
// wont help
//var y = DownloadUrlResolver.GetDownloadUrls(link);
//var j = DownloadUrlResolver.LoadJson(videoUrl);
var c = new WebClient().DownloadString(videoUrl);
// "Kryon - Timing o..." The YouTube account associated with this video has been terminated due to multiple third-party notifications of copyright infringement.
// <link itemprop="url" href="http://www.youtube.com/user/melania1172">
// { videoUrl = http://youtube.com/watch?v=li0E4_7ap3g, ch_name = , userurl = https://youtube.com/user/ }
//{ url = http://youtube.com/watch?v=li0E4_7ap3g }
//{ err = YoutubeExtractor.YoutubeParseException: Could not parse the Youtube page for URL http://youtube.com/watch?v=li0E4_7ap3g
// <h1 id="unavailable-message" class="message">
// 'IS_UNAVAILABLE_PAGE': false,
var unavailable =
!c.Contains("'IS_UNAVAILABLE_PAGE': false") ?
c.SkipUntilOrEmpty("<h1 id=\"unavailable-message\" class=\"message\">").TakeUntilOrEmpty("<").Trim() : "";
if (unavailable != "")
{
Console.WriteLine(new { videoUrl, unavailable });
Thread.Sleep(3000);
return;
}
var ch = c.SkipUntilOrEmpty(" <div class=\"yt-user-info\">").SkipUntilOrEmpty("<a href=\"/channel/");
var ch_id = ch.TakeUntilOrEmpty("\"");
var ch_name = ch.SkipUntilOrEmpty(">").TakeUntilOrEmpty("<");
// https://www.youtube.com/channel/UCP-Q2vpvpQmdShz-ASBj2fA/videos
// ! originally there were users, now there are thos gplus accounts?
//var usertoken = c.SkipUntilOrEmpty("<link itemprop=\"url\" href=\"http://www.youtube.com/user/");
//var userid = usertoken.TakeUntilOrEmpty("\"");
////var ch_name = ch.SkipUntilOrEmpty(">").TakeUntilOrEmpty("<");
//var userurl = "https://youtube.com/user/" + userid;
Console.WriteLine(new { link, ch_name, ch_id });
//Console.WriteLine(new { page0, link });
// Our test youtube link
//const string link = "https://www.youtube.com/watch?v=BJ9v4ckXyrU";
//Debugger.Break();
// rewrite broke JObject Parse.
// Additional information: Bad JSON escape sequence: \5.Path 'args.afv_ad_tag_restricted_to_instream', line 1, position 3029.
// <script>var ytplayer = ytplayer || {};ytplayer.config =
var ytconfig = c.SkipUntilOrEmpty("<script>var ytplayer = ytplayer || {};ytplayer.config =").TakeUntilOrEmpty(";ytplayer.load =");
dynamic ytconfigJSON = Newtonsoft.Json.JsonConvert.DeserializeObject(ytconfig);
var ytconfigJSON_args = ytconfigJSON.args;
string ytconfigJSON_args_adaptive_fmts = ytconfigJSON.args.adaptive_fmts;
string adaptive_fmts = Uri.UnescapeDataString(ytconfigJSON_args_adaptive_fmts);
// projection_type=3
// + ((dynamic)((Newtonsoft.Json.Linq.JObject)(ytconfigJSON))).args
//var get_video_info = new WebClient().DownloadString("https://www.youtube.com/get_video_info?html5=1&video_id=" + id);
//.........这里部分代码省略.........