Пример #1
0
        private Task <Model.MediaInfo.MediaInfo> GetMediaInfo(Video item,
                                                              string[] streamFileNames,
                                                              CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            var path     = item.Path;
            var protocol = item.PathProtocol ?? MediaProtocol.File;

            if (item.IsShortcut)
            {
                path     = item.ShortcutPath;
                protocol = _mediaSourceManager.GetPathProtocol(path);
            }

            return(_mediaEncoder.GetMediaInfo(new MediaInfoRequest
            {
                PlayableStreamFileNames = streamFileNames,
                ExtractChapters = true,
                MediaType = DlnaProfileType.Video,
                MediaSource = new MediaSourceInfo
                {
                    Path = path,
                    Protocol = protocol,
                    VideoType = item.VideoType
                }
            }, cancellationToken));
        }
Пример #2
0
        private async Task <(Stream stream, string format)> GetSubtitleStream(
            MediaSourceInfo mediaSource,
            MediaStream subtitleStream,
            CancellationToken cancellationToken)
        {
            string[] inputFiles;

            if (mediaSource.VideoType.HasValue &&
                (mediaSource.VideoType.Value == VideoType.BluRay || mediaSource.VideoType.Value == VideoType.Dvd))
            {
                var mediaSourceItem = (Video)_libraryManager.GetItemById(new Guid(mediaSource.Id));
                inputFiles = mediaSourceItem.GetPlayableStreamFileNames();
            }
            else
            {
                inputFiles = new[] { mediaSource.Path };
            }

            var protocol = mediaSource.Protocol;

            if (subtitleStream.IsExternal)
            {
                protocol = _mediaSourceManager.GetPathProtocol(subtitleStream.Path);
            }

            var fileInfo = await GetReadableFile(mediaSource.Path, inputFiles, protocol, subtitleStream, cancellationToken).ConfigureAwait(false);

            var stream = await GetSubtitleStream(fileInfo.Path, fileInfo.Protocol, fileInfo.IsExternal, cancellationToken).ConfigureAwait(false);

            return(stream, fileInfo.Format);
        }
Пример #3
0
        public async Task <ItemUpdateType> Probe <T>(T item, MetadataRefreshOptions options,
                                                     CancellationToken cancellationToken)
            where T : Audio
        {
            var path     = item.Path;
            var protocol = item.PathProtocol ?? MediaProtocol.File;

            if (!item.IsShortcut || options.EnableRemoteContentProbe)
            {
                if (item.IsShortcut)
                {
                    path     = item.ShortcutPath;
                    protocol = _mediaSourceManager.GetPathProtocol(path);
                }

                var result = await _mediaEncoder.GetMediaInfo(new MediaInfoRequest
                {
                    MediaType   = DlnaProfileType.Audio,
                    MediaSource = new MediaSourceInfo
                    {
                        Path     = path,
                        Protocol = protocol
                    }
                }, cancellationToken).ConfigureAwait(false);

                cancellationToken.ThrowIfCancellationRequested();

                Fetch(item, cancellationToken, result);
            }

            return(ItemUpdateType.MetadataImport);
        }
Пример #4
0
        protected virtual MediaSourceInfo CreateMediaSourceInfo(TunerHostInfo info, ChannelInfo channel)
        {
            var path = channel.Path;

            var supportsDirectPlay   = !info.EnableStreamLooping && info.TunerCount == 0;
            var supportsDirectStream = !info.EnableStreamLooping;

            var protocol = _mediaSourceManager.GetPathProtocol(path);

            var isRemote = true;

            if (Uri.TryCreate(path, UriKind.Absolute, out var uri))
            {
                isRemote = !_networkManager.IsInLocalNetwork(uri.Host);
            }

            var httpHeaders = new Dictionary <string, string>();

            if (protocol == MediaProtocol.Http)
            {
                // Use user-defined user-agent. If there isn't one, make it look like a browser.
                httpHeaders[HeaderNames.UserAgent] = string.IsNullOrWhiteSpace(info.UserAgent) ?
                                                     "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.85 Safari/537.36" :
                                                     info.UserAgent;
            }

            var mediaSource = new MediaSourceInfo
            {
                Path         = path,
                Protocol     = protocol,
                MediaStreams = new List <MediaStream>
                {
                    new MediaStream
                    {
                        Type = MediaStreamType.Video,
                        // Set the index to -1 because we don't know the exact index of the video stream within the container
                        Index        = -1,
                        IsInterlaced = true
                    },
                    new MediaStream
                    {
                        Type = MediaStreamType.Audio,
                        // Set the index to -1 because we don't know the exact index of the audio stream within the container
                        Index = -1
                    }
                },
                RequiresOpening = true,
                RequiresClosing = true,
                RequiresLooping = info.EnableStreamLooping,

                ReadAtNativeFramerate = false,

                Id = channel.Path.GetMD5().ToString("N", CultureInfo.InvariantCulture),
                IsInfiniteStream = true,
                IsRemote         = isRemote,

                IgnoreDts            = true,
                SupportsDirectPlay   = supportsDirectPlay,
                SupportsDirectStream = supportsDirectStream,

                RequiredHttpHeaders = httpHeaders
            };

            mediaSource.InferTotalBitrate();

            return(mediaSource);
        }