Ejemplo n.º 1
0
        public static VideoInfo GetPlayerSources(string url)
        {
            VideoInfo videoInfo = new VideoInfo();

            var    videoID       = VideoLink.GetVideoID(url);
            string videoInfoLink =
                string.Format("https://www.youtube.com/get_video_info?video_id={0}&el=detailpage&hl=en", videoID);

            var rawVideoInfo = WebHelper.GetPageSouce(videoInfoLink);
            var videoPage    = WebHelper.GetPageSouce(url);


            var    dataRegex     = new Regex(@"ytplayer\.config\s*=\s*(\{.+?\});", RegexOptions.Multiline);
            string extractedJson = dataRegex.Match(videoPage).Result("$1");


            videoInfo.rawVideoInfo = JsonHelper.ConvertToJson(rawVideoInfo);
            videoInfo.videoPage    = JObject.Parse(extractedJson);


            Debug.SaveFile(videoInfo.rawVideoInfo.ToString(), "VideoInfoJson");
            Debug.SaveFile(videoInfo.videoPage.ToString(), "VideoPageJson");

            return(videoInfo);
        }
Ejemplo n.º 2
0
        public static async Task <BitmapImage> GetThumbnailAsync(string videoURL, IProgress <DownloadProgressData> progress)
        {
            string videoID  = VideoLink.GetVideoID(videoURL);
            string thumbURL = string.Format("https://i.ytimg.com/vi/{0}/maxresdefault.jpg", videoID);
            string fileName = string.Format("thumb-{0}.jpg", videoID);

            await Task.Run(() => Download.DownloadContent(thumbURL, fileName, Debug.savePath, progress));

            var path = new Uri(Debug.savePath + fileName);

            return(new BitmapImage(path));
        }
Ejemplo n.º 3
0
        public static void GetJsonResponse(string videoURL)
        {
            string videoID = VideoLink.GetVideoID(videoURL);

            string HTMLDetails;
            //string videoDetails = string.Format("https://www.youtube.com/get_video_info?video_id={0}&el=detailpage", videoID);
            string videoDetails = videoURL;

            using (var client = new WebClient())
            {
                client.Encoding = Encoding.UTF8;

                HTMLDetails = client.DownloadString(videoDetails);
            }
            Debug.SaveFile(HTMLDetails, "YoutubeInfo");

            /*
             * var dictionary1 = new Dictionary<string, string>();
             *
             * foreach (string vp in Regex.Split(HTMLDetails, "&"))
             * {
             *  string[] strings = Regex.Split(vp, "=");
             *
             *  dictionary1.Add(strings[0], strings.Length == 2 ? HttpUtility.UrlDecode(strings[1]) : string.Empty);
             * }
             *
             * JObject dic1 = JObject.Parse(JsonConvert.SerializeObject(dictionary1).ToString());
             *
             * SaveFile(dic1.ToString(), "dictionary1");
             *
             * GetNeededData(dic1);
             */


            Regex  dataRegex     = new Regex(@"ytplayer\.config\s*=\s*(\{.+?\});", RegexOptions.Multiline);
            string extractedJson = dataRegex.Match(HTMLDetails).Result("$1");

            Debug.SaveFile(extractedJson, "EmbedPageJSON");

            GetNeededData(JObject.Parse(extractedJson));
        }