Esempio n. 1
0
        private static async Task ConvertVideos()
        {
            if (!Program.HasValidFFMPEG)
            {
                Console.WriteLine("Could not [GeneratePreviews] in cron - No ffmpeg installation found"); return;
            }
            if (Program.Args.CacheDir == null)
            {
                Console.WriteLine("Could not [GeneratePreviews] in cron - No cache directory specified"); return;
            }

            LastCronConvertVideos = DateTime.Now;

            var dirs   = (await Task.WhenAll(Program.Args.DataDirs.Select(async(s, i) => await Program.GetData(i)))).ToList();
            var videos = dirs.SelectMany(p => p.Videos.Values).ToList();

            foreach (var vid in videos)
            {
                if (!vid.ShouldTranscodeAndCacheVideo())
                {
                    continue;
                }

                var pathCache = VideoController.GetStreamCachePath(vid.PathVideo);
                if (File.Exists(pathCache))
                {
                    continue;
                }

                JobRegistry.ConvertJobs.StartOrQueue((man) => new ConvertJob(man, vid.PathVideo, pathCache, vid.DataDirIndex, vid.UID), false);
            }
        }
        private (JObject, string, string) ReadVideoDataRaw(string pathVideo)
        {
            var uid = "SHA256" + pathVideo.Sha256().Substring(0, 18);

            var dir = Path.GetDirectoryName(pathVideo);

            if (dir == null)
            {
                return(null, null, null);
            }

            var filenameVideo = Path.GetFileName(pathVideo);

            var filenameBase = Path.GetFileNameWithoutExtension(filenameVideo);

            var pathDesc = Path.Combine(dir, filenameBase + ".description");

            if (!_datafiles.Contains(pathDesc))
            {
                pathDesc = null;
            }

            var pathThumb = Program.ExtThumbnail.Select(ext => Path.Combine(dir, filenameBase + "." + ext)).FirstOrDefault(p => _datafiles.Contains(p));

            var pathSubs = _filesSubs
                           .Where(p => dir == Path.GetDirectoryName(p))
                           .Where(p => Path.GetFileName(p).EndsWith(".vtt"))
                           .Where(p => Path.GetFileName(p).StartsWith(filenameBase + "."))
                           .ToList();

            var vtitle = _spec.UseFilenameAsTitle ? Path.GetFileNameWithoutExtension(pathVideo) : Path.GetFileName(pathVideo);

            var vidData = new JObject
                          (
                new JProperty("meta", new JObject
                              (
                                  new JProperty("uid", uid),
                                  new JProperty("datadirindex", _index),

                                  new JProperty("directory", dir),

                                  new JProperty("filename_base", filenameBase),

                                  new JProperty("path_json", (object)null),
                                  new JProperty("path_toml", (object)null),
                                  new JProperty("path_description", pathDesc),
                                  new JProperty("path_video", pathVideo),
                                  new JProperty("path_video_abs", Path.GetFullPath(pathVideo)),
                                  new JProperty("path_thumbnail", pathThumb),
                                  new JProperty("paths_subtitle", new JObject(pathSubs.Select(p => new JProperty(Path.GetFileNameWithoutExtension(p).Substring(filenameBase.Length + 1), p)))),

                                  new JProperty("cache_file", VideoController.GetStreamCachePath(pathVideo)),
                                  new JProperty("cached", _cacheFiles.Contains(Path.GetFileName(VideoController.GetStreamCachePath(pathVideo)))),
                                  new JProperty("cached_video_fsize", _cacheFiles.Contains(Path.GetFileName(VideoController.GetStreamCachePath(pathVideo))) ? new FileInfo(VideoController.GetStreamCachePath(pathVideo)).Length : 0),

                                  new JProperty("previewscache_file", PreviewController.GetPreviewCachePath(pathVideo)),
                                  new JProperty("cached_previews", _cacheFiles.Contains(Path.GetFileName(PreviewController.GetPreviewCachePath(pathVideo)))),
                                  new JProperty("cached_preview_fsize", _cacheFiles.Contains(Path.GetFileName(PreviewController.GetPreviewCachePath(pathVideo))) ? new FileInfo(PreviewController.GetPreviewCachePath(pathVideo)).Length : 0),

                                  new JProperty("thumbnailcache_file", ThumbnailController.GetThumbnailCachePath(pathVideo)),
                                  new JProperty("cached_thumbnail", _cacheFiles.Contains(Path.GetFileName(ThumbnailController.GetThumbnailCachePath(pathVideo)))),
                                  new JProperty("cached_thumbnail_fsize", _cacheFiles.Contains(Path.GetFileName(ThumbnailController.GetThumbnailCachePath(pathVideo))) ? new FileInfo(ThumbnailController.GetThumbnailCachePath(pathVideo)).Length : 0),

                                  new JProperty("filesize", new FileInfo(pathVideo).Length)
                              )),
                new JProperty("data", new JObject
                              (
                                  new JProperty("title", vtitle),
                                  new JProperty("description", (pathDesc != null) ? File.ReadAllText(pathDesc) : null),
                                  new JProperty("info", new JObject())
                              ))
                          );

            return(vidData, dir, filenameBase);
        }