Exemplo n.º 1
0
        public static async Task ManuallyForcePreviewJobs(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 = ThumbnailController.GetPreviewCachePath(pathVideo);

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

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

            await context.Response.WriteAsync($"Started/Attached {count} new jobs");
        }
Exemplo n.º 2
0
        public static async Task ManuallyForceThumbnailJobs(HttpContext context)
        {
            context.Response.Headers.Add(HeaderNames.ContentType, "text/plain");

            if (!Program.Args.CreateResizedThumbnails)
            {
                context.Response.StatusCode = 500; await context.Response.WriteAsync("Thumbnail generation is disabled"); 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(_, 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.PathVideo == null)
                {
                    continue;
                }
                if (vid.PathThumbnail == null)
                {
                    continue;
                }

                var pathCache = ThumbnailController.GetThumbnailCachePath(vid.PathVideo);
                if (File.Exists(pathCache))
                {
                    continue;
                }

                count++;
                JobRegistry.ThumbGenJobs.StartOrQueue((man) => new ThumbnailGenJob(man, vid, pathCache), false);
            }

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