예제 #1
0
    private static IEnumerable <VideoHostingInfo> GetVideoInfos(IEnumerable <ExtractionInfo> extractionInfos, string videoTitle)
    {
        var downLoadInfos = new List <VideoHostingInfo>();

        foreach (ExtractionInfo extractionInfo in extractionInfos)
        {
            string itag = VideoHostingHelper.ParseQueryString(extractionInfo.Uri.Query)["itag"];

            int formatCode = int.Parse(itag);

            VideoHostingInfo info = VideoHostingInfo.Defaults.SingleOrDefault(videoInfo => videoInfo.FormatCode == formatCode);

            if (info != null)
            {
                info = new VideoHostingInfo(info)
                {
                    DownloadUrl        = extractionInfo.Uri.ToString(),
                    Title              = videoTitle,
                    RequiresDecryption = extractionInfo.RequiresDecryption
                };
            }

            else
            {
                info = new VideoHostingInfo(formatCode)
                {
                    DownloadUrl = extractionInfo.Uri.ToString()
                };
            }

            downLoadInfos.Add(info);
        }

        return(downLoadInfos);
    }
예제 #2
0
    public IEnumerator DecryptDownloadUrl(VideoHostingInfo videoInfo, Action <VideoHostingInfo> completeCallback)
    {
        IDictionary <string, string> queries = VideoHostingHelper.ParseQueryString(videoInfo.DownloadUrl);

        if (queries.ContainsKey(SIGNATURE_QUERY))
        {
            string encryptedSignature = queries[SIGNATURE_QUERY];

            string decrypted;

            string jsUrl = string.Format("http://s.ytimg.com/yts/jsbin/player{0}.js", videoInfo.HtmlPlayerVersion);
            WWW    www   = new WWW(jsUrl);
            yield return(www);

            try
            {
                decrypted = DeciphererYoutube.DecipherWithVersion(www.text, encryptedSignature, videoInfo.HtmlPlayerVersion);
            }
            catch (Exception ex)
            {
                throw new Exception("Could not decipher signature", ex);
            }

            videoInfo.DownloadUrl        = VideoHostingHelper.ReplaceQueryStringParameter(videoInfo.DownloadUrl, SIGNATURE_QUERY, decrypted);
            videoInfo.RequiresDecryption = false;

            if (completeCallback != null)
            {
                completeCallback(videoInfo);
            }
        }
    }
예제 #3
0
    public void DecryptVideoUrl(VideoHostingInfo videoInfo, Action <VideoHostingInfo> completeCallback)
    {
        foreach (var cachedUrl in _cachedVideoUrls)
        {
            for (int i = 0; i < cachedUrl.Value.Length; i++)
            {
                if (cachedUrl.Value[i].DownloadUrl == videoInfo.DownloadUrl)
                {
                    if (videoInfo.RequiresDecryption && !videoInfo.IsDecrypted)
                    {
                        if (_videoDecryptEnum != null)
                        {
                            _monoObject.StopCoroutine(_videoDecryptEnum);
                        }

                        _decryptionDoneAction = completeCallback;
                        _videoDecryptEnum     = _currentVideoParser.DecryptDownloadUrl(videoInfo, OnDecryptDone);
                        _monoObject.StartCoroutine(_videoDecryptEnum);
                        videoInfo.IsDecrypted = true;
                    }
                    cachedUrl.Value[i] = videoInfo;
                }
            }
        }
    }
예제 #4
0
    public VideoHostingInfo GetBestQualityVideo(VideoHostingInfo[] videoInfos, int maxQuality)
    {
        VideoHostingInfo videoWithBestResolution = new VideoHostingInfo(0);

        foreach (var info in videoInfos)
        {
            if (info.Resolution < maxQuality && info.Resolution > videoWithBestResolution.Resolution)
            {
                videoWithBestResolution = info;
            }
        }

        return(videoWithBestResolution);
    }
예제 #5
0
 internal VideoHostingInfo(VideoHostingInfo info)
     : this(info.FormatCode, info.VideoType, info.Resolution, info.Is3D, info.AudioType, info.AudioBitrate, info.AdaptiveType)
 {
 }
예제 #6
0
 private void OnDecryptDone(VideoHostingInfo videoInfo)
 {
     _decryptionDoneAction(videoInfo);
 }