Exemple #1
0
        public async Task <bool> LoadVideoStreamFromRemoteServer()
        {
            if (IsLoadingVideoStream_RemoteServer)
            {
                return(true);
            }
            IsLoadingVideoStream_RemoteServer = true;

            try
            {
                // clear etc
                Stream.VideoInfo.Clear();
                Stream.VideoInfo_adaptive_fmts.Clear();

                long   nonce = DateTimeUtility.CurrentTimeMillis();
                byte[] ret   = await PrimeTubeAPIs.GetVideoList(string.Format("https://www.youtube.com/watch?v={0}", _videoId), nonce);

                if (ret != null)
                {
                    char[] encryptionKey = CustomXorEncryption.GenerateKey(nonce);

                    PacketReader reader        = new PacketReader(ret);
                    bool         haveVideoInfo = reader.ReadBool();

                    if (!haveVideoInfo)
                    {
                        return(false);
                    }
                    string videoTitle   = CustomXorEncryption.EncryptContent(reader.ReadString(), encryptionKey);
                    int    numVideoURLs = reader.ReadInt();

                    for (int i = 0; i < numVideoURLs; i++)
                    {
                        string fullURL = CustomXorEncryption.EncryptContent(reader.ReadString(), encryptionKey); // full url

                        VideoType videotype = VideoType.NULL;
                        switch (CustomXorEncryption.EncryptContent(reader.ReadString(), encryptionKey)) // container
                        {
                        case "FLV":
                            videotype = VideoType.video_x_flv;
                            break;

                        case "GP3":
                            videotype = VideoType.video_3gpp;
                            break;

                        case "MP4":
                            videotype = VideoType.video_mp4;
                            break;

                        case "WEBM":
                            videotype = VideoType.video_webm;
                            break;
                        }

                        int type = reader.ReadByte() & 0xFF;

                        switch (type)
                        {
                        case 1:     // Audio
                        {
                            string audio = CustomXorEncryption.EncryptContent(reader.ReadString(), encryptionKey);
                            string aq    = CustomXorEncryption.EncryptContent(reader.ReadString(), encryptionKey);

                            Stream.VideoInfo.Add(new VideoInformation(fullURL, VideoType.audio_mp4, "", "", "", VideoQuality.NULL));
                            break;
                        }

                        case 2:     // Video
                        {
                            string video = CustomXorEncryption.EncryptContent(reader.ReadString(), encryptionKey);
                            string vq    = CustomXorEncryption.EncryptContent(reader.ReadString(), encryptionKey);

                            Stream.VideoInfo.Add(new VideoInformation(fullURL, videotype, "", "", "", VideoQuality.hd720));
                            break;
                        }

                        case 3:     // Combined
                        {
                            string video = CustomXorEncryption.EncryptContent(reader.ReadString(), encryptionKey);
                            string vq    = CustomXorEncryption.EncryptContent(reader.ReadString(), encryptionKey);
                            string audio = CustomXorEncryption.EncryptContent(reader.ReadString(), encryptionKey);
                            string aq    = CustomXorEncryption.EncryptContent(reader.ReadString(), encryptionKey);

                            Stream.VideoInfo.Add(new VideoInformation(fullURL, videotype, "", "", "", VideoQuality.hd720));
                            break;
                        }

                        default:
                            break;
                        }
                    }

                    return(true);
                }
            }
            catch (Exception exp)
            {
                return(false);
            }
            finally
            {
                IsLoadingVideoStream_RemoteServer = false;
            }
            return(false);
        }