コード例 #1
0
    public string GetReplacementJellyfinPath(
        List <JellyfinPathReplacement> pathReplacements,
        string path,
        bool log = true)
    {
        Option <JellyfinPathReplacement> maybeReplacement = pathReplacements
                                                            .SingleOrDefault(
            r =>
        {
            if (string.IsNullOrWhiteSpace(r.JellyfinPath))
            {
                return(false);
            }

            string separatorChar = IsWindows(r.JellyfinMediaSource, path) ? @"\" : @"/";
            string prefix        = r.JellyfinPath.EndsWith(separatorChar)
                        ? r.JellyfinPath
                        : r.JellyfinPath + separatorChar;
            return(path.StartsWith(prefix));
        });

        foreach (JellyfinPathReplacement replacement in maybeReplacement)
        {
            string finalPath = path.Replace(replacement.JellyfinPath, replacement.LocalPath);
            if (IsWindows(replacement.JellyfinMediaSource, path) &&
                !_runtimeInfo.IsOSPlatform(OSPlatform.Windows))
            {
                finalPath = finalPath.Replace(@"\", @"/");
            }
            else if (!IsWindows(replacement.JellyfinMediaSource, path) &&
                     _runtimeInfo.IsOSPlatform(OSPlatform.Windows))
            {
                finalPath = finalPath.Replace(@"/", @"\");
            }

            if (log)
            {
                _logger.LogInformation(
                    "Replacing jellyfin path {JellyfinPath} with {LocalPath} resulting in {FinalPath}",
                    replacement.JellyfinPath,
                    replacement.LocalPath,
                    finalPath);
            }

            return(finalPath);
        }

        return(path);
    }
コード例 #2
0
    public async Task StartAsync(CancellationToken cancellationToken)
    {
        using IServiceScope scope       = _serviceScopeFactory.CreateScope();
        await using TvContext dbContext = scope.ServiceProvider.GetRequiredService <TvContext>();

        IRuntimeInfo runtimeInfo = scope.ServiceProvider.GetRequiredService <IRuntimeInfo>();

        if (runtimeInfo != null && runtimeInfo.IsOSPlatform(OSPlatform.Linux) &&
            Directory.Exists("/dev/dri"))
        {
            ILocalFileSystem localFileSystem = scope.ServiceProvider.GetRequiredService <ILocalFileSystem>();
            IMemoryCache     memoryCache     = scope.ServiceProvider.GetRequiredService <IMemoryCache>();

            var devices = localFileSystem.ListFiles("/dev/dri")
                          .Filter(s => s.StartsWith("/dev/dri/render"))
                          .ToList();

            memoryCache.Set("ffmpeg.render_devices", devices);
        }
    }