예제 #1
0
 public Engine(UrlDispatcher urlDispatcher)
 {
     this.UrlDispatcher = urlDispatcher;
 }
예제 #2
0
 public void Should_be_Extract_the_Parameters_and_the_Info_in_Dictionary()
 {
     IUrlDispatcher dispatcher = new UrlDispatcher();
     var parameterInfo = dispatcher.Dispatch<HomeController>(p => p.GetById(1));
     parameterInfo.Item2["id"].Should().Be("1");
 }
예제 #3
0
        public IActionResult TransformBilibiliVideo([FromRoute] long aid)
        {
            new Thread(async() =>
            {
                try
                {
                    LogHelper.Info("Got bilibili video av" + aid);
                    var baseVideoInfo = await GetBaseBilibiliVideoInfoAsync(aid);
                    var process       = UrlDispatcher.DispatchVideoUrl("https://www.bilibili.com/video/av" + aid);
                    process.Cookies   = BilibiliCookies;
                    process.Initialize();
                    LogHelper.Info($"Find {process.Videos.Length} videos, create download task.");
                    var partNum = 1;
                    foreach (var videoInfo in process.Videos)
                    {
                        var streamVideoInfo =
                            (StreamDownloader.Core.Processor.CustomProcessor.Bilibili.BilibiliVideoInfo)videoInfo;
                        var bilibiliVideoInfo     = baseVideoInfo.Clone();
                        bilibiliVideoInfo.Cid     = streamVideoInfo.Cid;
                        bilibiliVideoInfo.PartNum = partNum++;
                        if ((await Program.VideoCollection.FindAsync(v => v.Cid == streamVideoInfo.Cid)).Any())
                        {
                            LogHelper.Info($"Video {streamVideoInfo.Cid} already exists.");
                            continue;
                        }

                        var downloader = process
                                         .Process(videoInfo.VideoStreams.OrderByDescending(v => v.Quality).First(),
                                                  "Videos/" + aid + "-" + bilibiliVideoInfo.PartNum).First();
                        LogHelper.Info("Start download " + downloader.DownloadPath);
                        downloader.BeginDownload();
                        while (downloader.Status == DownloadStateEnum.Downloading)
                        {
                            Thread.Sleep(1000);
                        }
                        LogHelper.Info("Download completed " + downloader.DownloadPath);
                        var md5      = FileTools.GetMd5HashFromFile(downloader.DownloadPath);
                        var fileInfo = new FileInfo(downloader.DownloadPath);
                        var url      = AcceleriderApi.CreateUploadTask(md5, fileInfo.Length, fileInfo.Name);
                        if (url == null)
                        {
                            bilibiliVideoInfo.FileName = fileInfo.Name;
                            bilibiliVideoInfo.FileHash = md5;
                            Program.VideoCollection.InsertOne(bilibiliVideoInfo);
                            System.IO.File.Delete(downloader.DownloadPath);
                            return;
                        }

                        var info = new OnedriveUploadInfo()
                        {
                            FilePath  = downloader.DownloadPath,
                            UploadUrl = url
                        };
                        info.Init();
                        var upload = OnedriveUpload.CreateTaskByInfo(info);
                        upload.UploadStateChangedEvent += (sender, e) =>
                        {
                            if (e.NewState == UploadStatusEnum.Completed)
                            {
                                LogHelper.Info("Upload completed: " + md5);
                                AcceleriderApi.ConfirmUpload(md5);
                                bilibiliVideoInfo.FileName = fileInfo.Name;
                                bilibiliVideoInfo.FileHash = md5;
                                Program.VideoCollection.InsertOne(bilibiliVideoInfo);
                                System.IO.File.Delete(downloader.DownloadPath);
                            }
                        };
                        upload.Start();
                        LogHelper.Info("Start upload" + downloader.DownloadPath);
                    }
                }
                catch (Exception ex)
                {
                    LogHelper.Error("Error to process video " + aid, ex: ex);
                }
            })
            {
                IsBackground = true
            }.Start();
            return(Ok());
        }
예제 #4
0
 public void Should_be_able_to_Get_the_Controller_name()
 {
     IUrlDispatcher dispacther = new UrlDispatcher();
     var controllerName = dispacther.Dispatch<HomeController>(p => p.Get());
     controllerName.Item2["controller"].Should().Be("home");
 }
예제 #5
0
        public IncodingMetaCallbackInsertDsl WithTemplateByUrl(Func <UrlDispatcher, string> evaluated)
        {
            var dispatcher = new UrlDispatcher(new UrlHelper(HttpContext.Current.Request.RequestContext));

            return(WithTemplateByUrl(evaluated(dispatcher)));
        }