Exemplo n.º 1
0
        private void GetVodFromTwitch(ref TwitchChannel channel)
        {
            channel.Path = "";

            var processInfo = new ProcessStartInfo
            {
                FileName  = "streamlink",
                Arguments = $"--stream-url https://www.twitch.tv/{channel.UserName.ToLowerInvariant()} {channel.Quality.ToLowerInvariant()}",
                RedirectStandardOutput = true,
                RedirectStandardError  = true,
                UseShellExecute        = false,
            };

            var process = new Process()
            {
                StartInfo = processInfo,
            };

            process.Start();

            while (!process.StandardOutput.EndOfStream)
            {
                channel.Path += process.StandardOutput.ReadLine();
            }

            channel.Path = channel.Path.Replace(System.Environment.NewLine, "").Trim();
            process.WaitForExit();
        }
Exemplo n.º 2
0
        private Task <IEnumerable <MediaSourceInfo> > GetMediaSources(string id, CancellationToken cancellationToken)
        {
            TwitchChannel tChannel = null;

            foreach (TwitchChannel i in Plugin.Instance.Configuration.TwitchChannels)
            {
                if (i.UserName.Equals(id, StringComparison.InvariantCultureIgnoreCase))
                {
                    tChannel = i;
                    break;
                }
            }

            if (tChannel != null)
            {
                GetVodFromTwitch(ref tChannel);

                if (tChannel.Path.IndexOf("no playable streams", StringComparison.InvariantCultureIgnoreCase) >= 0 || string.IsNullOrWhiteSpace(tChannel.Path))
                {
                    tChannel.Path = $"This channel is not live at this moment. Last checked on {DateTime.Now.ToLongDateString()} {DateTime.Now.ToLongTimeString()}. Will fetch a new link in {REFRESH_MINUTES} {(REFRESH_MINUTES == 1 ? "minute" : "minutes")}.";
                }

                return(Task.FromResult <IEnumerable <MediaSourceInfo> >(new List <MediaSourceInfo>
                {
                    new MediaSourceInfo()
                    {
                        DirectStreamUrl = tChannel.Path,
                        Path = tChannel.Path,
                        SupportsDirectPlay = true,
                        SupportsDirectStream = true,
                        SupportsTranscoding = false,
                        IsInfiniteStream = true,
                        Name = $"{tChannel.UserName}_{tChannel.Path.ToLowerInvariant().Substring(tChannel.Path.Length - 5)}",
                        Id = $"stream_{tChannel.Path.ToLowerInvariant().Substring(tChannel.Path.Length - 5)}",
                        Type = MediaSourceType.Default,
                        Protocol = MediaProtocol.Http,
                    }
                }));
            }

            return(Task.FromResult(Enumerable.Empty <MediaSourceInfo>()));
        }