Example #1
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) });
        }
Example #2
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;
            }
            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); }
            });
        }
Example #3
0
 static ConsoleCommand()
 {
     ConsoleCommand.Add((token) => Task.Factory.StartNew(() =>
     {
         var builder = new StringBuilder();
         for (var i = 0; i < Commands.Count; i++)
         {
             var a   = Commands.Skip(i).Take(1).First();
             var tip = a.Description;
             if (tip == string.Empty)
             {
                 tip = a.Action.Method.Name;
             }
             builder.AppendLine(string.Format("{0}:{1}", i, tip));
         }
         Info(builder.ToString());
     }), "show menu", true, false);
     ConsoleCommand.Add((token) => Task.CompletedTask, "exit", false, false);
 }
Example #4
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 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);
        }