Example #1
0
        public OpenVideoResults OpenVideo()
        {
            Uri uri;

            try
            {
                uri = new Uri(Session.InitialUrl);
                if ((uri.Scheme.ToLower() != "http" && uri.Scheme.ToLower() != "https") || Utils.GetUrlExtention(Session.InitialUrl).ToLower() == "m3u8")
                {
                    return(null);
                }
            } catch (Exception) { return(null); }

            try
            {
                string url = Session.InitialUrl;
                Session.SingleMovie.UrlType = UrlType.Web;
                if (Regex.IsMatch(uri.DnsSafeHost, @"\.youtube\.", RegexOptions.IgnoreCase))
                {
                    var query = HttpUtility.ParseQueryString(uri.Query);
                    url = uri.Scheme + "://" + uri.Host + uri.AbsolutePath + "?v=" + query["v"];
                }

                string tmpFile = Path.GetTempPath() + Guid.NewGuid().ToString();

                Process proc = new Process
                {
                    StartInfo = new ProcessStartInfo
                    {
                        FileName        = plugin_path,
                        Arguments       = $"--no-check-certificate --skip-download --write-info-json -o \"{tmpFile}\" \"{url}\"",
                        CreateNoWindow  = true,
                        UseShellExecute = false,
                        WindowStyle     = ProcessWindowStyle.Hidden
                    }
                };
                proc.Start();
                while (!proc.HasExited && Player.decoder.interrupt == 0)
                {
                    Thread.Sleep(35);
                }
                if (Player.decoder.interrupt == 1)
                {
                    if (!proc.HasExited)
                    {
                        proc.Kill();
                    }
                    return(null);
                }
                if (!File.Exists($"{tmpFile}.info.json"))
                {
                    return(null);
                }

                // Parse Json Object
                string json = File.ReadAllText($"{tmpFile}.info.json");
                ytdl = JsonConvert.DeserializeObject <YoutubeDLJson>(json, settings);
                if (ytdl == null || ytdl.formats == null || ytdl.formats.Count == 0)
                {
                    return(null);
                }

                Format fmt;
                // Fix Nulls (we are not sure if they have audio/video)
                for (int i = 0; i < ytdl.formats.Count; i++)
                {
                    fmt = ytdl.formats[i];
                    if (ytdl.formats[i].vcodec == null)
                    {
                        ytdl.formats[i].vcodec = "";
                    }
                    if (ytdl.formats[i].acodec == null)
                    {
                        ytdl.formats[i].acodec = "";
                    }

                    //Dump(ytdl.formats[i]);

                    if (HasVideo(fmt))
                    {
                        VideoStreams.Add(new VideoStream()
                        {
                            DecoderInput = new DecoderInput()
                            {
                                Url = fmt.url
                            },
                            BitRate   = (long)fmt.vbr,
                            CodecName = fmt.vcodec,
                            Language  = Language.Get(fmt.language),
                            Width     = (int)fmt.width,
                            Height    = (int)fmt.height,
                            FPS       = fmt.fps
                        });
                    }

                    if (HasAudio(fmt))
                    {
                        AudioStreams.Add(new AudioStream()
                        {
                            DecoderInput = new DecoderInput()
                            {
                                Url = fmt.url
                            },
                            BitRate   = (long)fmt.abr,
                            CodecName = fmt.acodec,
                            Language  = Language.Get(fmt.language)
                        });
                    }
                }

                fmt = GetBestMatch();

                Player.Session.SingleMovie.Title = ytdl.title;

                foreach (var t1 in VideoStreams)
                {
                    if (fmt.url == t1.DecoderInput.Url)
                    {
                        return(new OpenVideoResults(t1));
                    }
                }
            }
            catch (Exception e) { Console.WriteLine($"[Youtube-DL] Error ... {e.Message}"); }

            return(new OpenVideoResults());
            //return formats[formats.Count - 1];
        }
Example #2
0
 public override void OnInitialized()
 {
     base.OnInitialized();
     ytdl = null;
 }