Beispiel #1
0
        public static async Task GetThumbnailDirect(HttpContext context)
        {
            var idx = int.Parse((string)context.Request.RouteValues["idx"]);
            var id  = (string)context.Request.RouteValues["id"];

            if (!(await Program.GetData(idx)).Videos.TryGetValue(id, out var vid))
            {
                context.Response.StatusCode = 404; await context.Response.WriteAsync("Video not found"); return;
            }

            var pathVideo = vid.PathVideo;

            var pathThumbnail = vid.PathThumbnail;

            if (vid.PathThumbnail == null)
            {
                if (pathVideo == null)
                {
                    context.Response.StatusCode = 404; await context.Response.WriteAsync("Video file not found"); return;
                }

                await PreviewController.GetPreviewImage(context, pathVideo, idx, id, 1);

                return;
            }

            var data = await File.ReadAllBytesAsync(pathThumbnail);

            context.Response.Headers.Add(HeaderNames.ContentLength, WebUtility.UrlEncode(data.Length.ToString()));
            context.Response.Headers.Add(HeaderNames.ContentDisposition, "attachment;filename=\"" + WebUtility.UrlEncode(Path.GetFileName(pathThumbnail)) + "\"");

            if (Path.GetExtension(pathThumbnail).EqualsIgnoreCase(".png"))
            {
                context.Response.Headers.Add(HeaderNames.ContentType, "image/png");
            }
            if (Path.GetExtension(pathThumbnail).EqualsIgnoreCase(".svg"))
            {
                context.Response.Headers.Add(HeaderNames.ContentType, "image/svg+xml");
            }
            if (Path.GetExtension(pathThumbnail).EqualsIgnoreCase(".jpg"))
            {
                context.Response.Headers.Add(HeaderNames.ContentType, "image/jpeg");
            }
            if (Path.GetExtension(pathThumbnail).EqualsIgnoreCase(".jpeg"))
            {
                context.Response.Headers.Add(HeaderNames.ContentType, "image/jpeg");
            }
            if (Path.GetExtension(pathThumbnail).EqualsIgnoreCase(".webp"))
            {
                context.Response.Headers.Add(HeaderNames.ContentType, "image/webp");
            }

            await context.Response.BodyWriter.WriteAsync(data);
        }
Beispiel #2
0
        public static async Task ManuallyForcePreviewJobs(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(_, 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)
            {
                var pathVideo = vid.PathVideo;
                if (pathVideo == null)
                {
                    continue;
                }

                var pathCache = PreviewController.GetPreviewCachePath(pathVideo);

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

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

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