コード例 #1
0
        public static async Task ManuallyForceTranscodeJobs(HttpContext context)
        {
            context.Response.Headers.Add(HeaderNames.ContentType, "text/plain");

            if (!Program.HasValidFFMPEG)
            {
                context.Response.StatusCode = 500; await context.Response.WriteAsync("No ffmpeg installation found"); return;
            }
            if (Program.Args.CacheDir == null)
            {
                context.Response.StatusCode = 500; await context.Response.WriteAsync("No cache directory specified"); return;
            }

            var selector1 = (string)context.Request.RouteValues["selector1"];
            var selector2 = (string)context.Request.RouteValues["selector2"];

            List <DataDirData> selection1;

            if (selector1.ToLower() == "all" || selector1.ToLower() == "*")
            {
                selection1 = (await Task.WhenAll(Program.Args.DataDirs.Select(async(s, i) => await Program.GetData(i)))).ToList();
            }
            else
            {
                selection1 = new[] { await Program.GetData(int.Parse(selector1)) }.ToList();
            }

            List <VideoData> selection2;
            if (selector2.ToLower() == "all" || selector2.ToLower() == "*")
            {
                selection2 = selection1.SelectMany(p => p.Videos.Values).ToList();
            }
            else
            {
                selection2 = selection1.SelectMany(p => p.Videos).Where(p => p.Key == selector2).Select(p => p.Value).ToList();
            }

            var count = 0;
            foreach (var vid in selection2)
            {
                if (!vid.ShouldTranscodeAndCacheVideo())
                {
                    continue;
                }

                var pathVideo = vid.PathVideo;

                var pathCache = VideoController.GetStreamCachePath(pathVideo);

                if (File.Exists(pathCache))
                {
                    continue;
                }

                count++;
                JobRegistry.ConvertJobs.StartOrQueue((man) => new ConvertJob(man, pathVideo, pathCache, vid.DataDirIndex, vid.UID), false);
            }

            await context.Response.WriteAsync($"Started/Attached {count} new jobs");
        }
コード例 #2
0
        public static async Task ManuallyForceTranscodeJobs(HttpContext context)
        {
            if (!Program.HasValidFFMPEG)
            {
                context.Response.StatusCode = 500; await context.Response.WriteAsync("No ffmpeg installation found"); return;
            }
            if (Program.Args.CacheDir == null)
            {
                context.Response.StatusCode = 500; await context.Response.WriteAsync("No cache directory specified"); return;
            }

            var selector1 = (string)context.Request.RouteValues["selector1"];
            var selector2 = (string)context.Request.RouteValues["selector2"];

            List <(string json, Dictionary <string, JObject> obj)> selection1;

            if (selector1.ToLower() == "all" || selector1.ToLower() == "*")
            {
                selection1 = (await Task.WhenAll(Program.Args.DataDirs.Select(async(_, i) => await Program.GetData(i)))).ToList();
            }
            else
            {
                selection1 = new[] { (await Program.GetData(int.Parse(selector1))) }.ToList();
            }

            List <JObject> selection2;

            if (selector2.ToLower() == "all" || selector2.ToLower() == "*")
            {
                selection2 = selection1.Select(p => p.obj).SelectMany(p => p.Values).ToList();
            }
            else
            {
                selection2 = selection1.SelectMany(p => p.obj).Where(p => p.Key == selector2).Select(p => p.Value).ToList();
            }

            var count = 0;

            foreach (var obj in selection2)
            {
                var pathVideo = obj["meta"]?.Value <string>("path_video");
                if (pathVideo == null)
                {
                    continue;
                }

                var pathCache = VideoController.GetStreamCachePath(pathVideo);

                if (File.Exists(pathCache))
                {
                    continue;
                }

                count++;
                JobRegistry.ConvertJobs.StartOrQueue((man) => new ConvertJob(man, pathVideo, pathCache, obj["meta"].Value <int>("datadirindex"), obj["meta"].Value <string>("uid")), false);
            }

            await context.Response.WriteAsync($"Started/Attached {count} new jobs");
        }