public async Task ExecuteAsync(CancellationToken cancellationToken) { var url = ConsoleCommand.ReadLine("is url?"); if (string.IsNullOrWhiteSpace(url)) { ConsoleCommand.WriteLine("please input a full url."); return; } var doc = await AngleSharp.BrowsingContext.New(Configuration.Default.WithDefaultLoader()).OpenAsync(url); var elements = doc.QuerySelectorAll("img"); foreach (var element in elements) { if (element.HasAttribute("data-width") == false || element.HasAttribute("data-height") == false) { continue; } var src = element.GetAttribute("data-src"); if (src.StartsWith("//")) { src = $"{doc.BaseUrl.Scheme}:{src}"; } ConsoleCommand.WriteLine(src); await PostToDB.PostAsync("image", src, string.Empty, 0); } }
public async Task ExecuteAsync(CancellationToken cancellationToken) { var url = ConsoleCommand.ReadLine("is url?"); if (string.IsNullOrWhiteSpace(url)) { ConsoleCommand.WriteLine("please input a full url."); return; } var desc = ConsoleCommand.ReadLine("is desc?"); await PostToDB.PostAsync("image", url, desc, 0); }
public async Task ExecuteAsync(CancellationToken cancellationToken) { var url = ConsoleCommand.ReadLine("is file path?"); if (string.IsNullOrWhiteSpace(url)) { ConsoleCommand.WriteLine("please input a full url."); return; } var desc = ConsoleCommand.ReadLine("is desc?"); var imageType = ConsoleCommand.ReadLine("is image type?"); await PostToDB.UploadAsync("image", new SpiderData { Url = string.Empty, Description = desc, ContentType = imageType, Content = File.ReadAllBytes(url) }); }
public async Task ExecuteAsync(CancellationToken cancellationToken) { var url = ConsoleCommand.ReadLine("is file path?"); if (string.IsNullOrWhiteSpace(url)) { ConsoleCommand.WriteLine("please input a full url."); return; } if (url.EndsWith(".m3u8") == false) { return; } var desc = ConsoleCommand.ReadLine("is desc?"); var headtext = ConsoleCommand.ReadLine("is request file or header text?"); if (headtext.EndsWith(".req")) { headtext = System.IO.File.ReadAllText(headtext); } var httpClient = new HttpClient(); var res = await httpClient.GetAsync(url); var response = await res.Content.ReadAsStringAsync(); var uri = new Uri(url); var hosturl = $"{uri.Scheme}://{uri.Host}"; var index = 0; var tses = response.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries).Where(c => c.EndsWith(".ts")).Select(c => new TsFileInfo { Url = c, Index = index++ }).ToArray(); var collectionname = Guid.NewGuid().ToString("n"); Parallel.ForEach(tses, new ParallelOptions { CancellationToken = cancellationToken, MaxDegreeOfParallelism = Environment.ProcessorCount / 2 }, ts => //tses.ForEach(ts=> { try { ConsoleCommand.WriteLine(ts.Url); var headers = headtext.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries).ToDictionary(c => c.Split(':')[0], c => c.Split(':')[1]); headers.Add("path", ts.Url); PostToDB.Post($"video{collectionname}", $"{hosturl}{ts.Url}", desc, ts.Index, headers); } catch (Exception ex) { ConsoleCommand.WriteLine(ex.Message); } }); }
public async Task ExecuteAsync(CancellationToken cancellationToken) { var url = ConsoleCommand.ReadLine("is file path?"); if (string.IsNullOrWhiteSpace(url)) { ConsoleCommand.WriteLine("please input a full url."); return; } var desc = ConsoleCommand.ReadLine("is desc?"); var headtext = ConsoleCommand.ReadLine("is request file or header text?"); if (headtext.EndsWith(".req")) { headtext = System.IO.File.ReadAllText(headtext); } var index = 0; int.TryParse(ConsoleCommand.ReadLine("is index?"), out index); var headers = headtext.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries).ToDictionary(c => c.Split(':')[0], c => c.Split(':')[1]); headers.Add("path", new Uri(url).PathAndQuery); await PostToDB.PostAsync("video", url, desc, index, headers); }