public UserDetailsViewModel(Member member)
        {
            Guard.Against.Null(member, nameof(member));

            // TODO: Get URL format string from central config location
            AvatarUrl    = string.Format(DevBetterWeb.Core.Constants.AVATAR_IMGURL_FORMAT_STRING, member.UserId);
            BlogUrl      = member.BlogUrl;
            TwitchUrl    = member.TwitchUrl;
            TwitterUrl   = member.TwitterUrl;
            GithubUrl    = member.GitHubUrl;
            LinkedInUrl  = member.LinkedInUrl;
            CodinGameUrl = member.CodinGameUrl;

            YouTubeUrl = member.YouTubeUrl;
            if (!(string.IsNullOrEmpty(YouTubeUrl)) && !(YouTubeUrl.Contains("?")))
            {
                YouTubeUrl = YouTubeUrl + "?sub_confirmation=1";
            }

            OtherUrl     = member.OtherUrl;
            AboutInfo    = member.AboutInfo;
            Address      = member.Address;
            Name         = member.UserFullName();
            PEFriendCode = member.PEFriendCode;
            if (!(string.IsNullOrEmpty(member.PEUsername)))
            {
                PEBadgeURL = $"https://projecteuler.net/profile/{member.PEUsername}.png";
            }

            BooksRead       = member.BooksRead !;
            DiscordUsername = member.DiscordUsername;
        }
Example #2
0
        public UserDetailsViewModel(Member member)
        {
            Guard.Against.Null(member, nameof(member));

            BlogUrl      = member.BlogUrl;
            TwitchUrl    = member.TwitchUrl;
            TwitterUrl   = member.TwitterUrl;
            GithubUrl    = member.GitHubUrl;
            LinkedInUrl  = member.LinkedInUrl;
            CodinGameUrl = member.CodinGameUrl;

            YouTubeUrl = member.YouTubeUrl;
            if (!(string.IsNullOrEmpty(YouTubeUrl)) && !(YouTubeUrl.Contains("?")))
            {
                YouTubeUrl = YouTubeUrl + "?sub_confirmation=1";
            }

            OtherUrl     = member.OtherUrl;
            AboutInfo    = member.AboutInfo;
            Address      = member.Address;
            Name         = member.UserFullName();
            PEFriendCode = member.PEFriendCode;
            if (!(string.IsNullOrEmpty(member.PEUsername)))
            {
                PEBadgeURL = $"https://projecteuler.net/profile/{member.PEUsername}.png";
            }

            BooksRead       = member.BooksRead !;
            DiscordUsername = member.DiscordUsername;
        }
Example #3
0
        /// <summary>
        /// The index action for the image file. Creates the view model and renders the view.
        /// </summary>
        /// <param name="currentContent">The current image file.</param>
        /// <param name="extraImageUrlParameters">Text added to the url to the image</param>
        public ActionResult Image(ImageFile currentContent, string extraImageUrlParameters = null)
        {
            string extra = string.IsNullOrEmpty(extraImageUrlParameters) ? "" : extraImageUrlParameters;

            if (!string.IsNullOrEmpty(currentContent.VideoUrl))
            {
                string guessSource = currentContent.VideoUrl.ToLower();
                if (guessSource.Contains("viddler.com"))
                {
                    var viddlerVideo = new ViddlerUrl(currentContent.VideoUrl);
                    var viddlerModel = new VideoViewModel()
                    {
                        CoverImageUrl = _urlResolver.GetUrl(currentContent.ContentLink) + extra,
                        HasCoverImage = true,
                        IframeUrl     = viddlerVideo.GetIframeUrl(true),
                        IframeId      = "viddler-" + viddlerVideo.Id
                    };
                    return(PartialView("_Video", viddlerModel));
                }
                else if (guessSource.Contains("youtube"))
                {
                    var youTubeVideo = new YouTubeUrl(currentContent.VideoUrl);
                    var youTubeModel = new VideoViewModel()
                    {
                        CoverImageUrl = _urlResolver.GetUrl(currentContent.ContentLink) + extra,
                        HasCoverImage = true,
                        IframeUrl     = youTubeVideo.GetIframeUrl(true)
                    };
                    return(PartialView("_Video", youTubeModel));
                }
                else if (guessSource.Contains("vimeo.com"))
                {
                    var vimeoVideo = new VimeoUrl(currentContent.VideoUrl);
                    var vimeoModel = new VideoViewModel()
                    {
                        CoverImageUrl = _urlResolver.GetUrl(currentContent.ContentLink) + extra,
                        HasCoverImage = true,
                        IframeUrl     = vimeoVideo.GetIframeUrl(true)
                    };
                    return(PartialView("_Video", vimeoModel));
                }
            }

            var model = new ImageViewModel(currentContent, Language)
            {
                IsMobile = this.Request.Browser.IsMobileDevice,
                Tag      = ControllerContext.ParentActionViewContext.ViewData["Tag"] as string
            };

            // Add additonal data to it
            model.Url += extra;

            return(PartialView("~/Views/ImageFile/Index.cshtml", model));
        }
Example #4
0
 /// <summary>
 /// Instantiates a new YouTubePage instance that can parse information about YouTube videos from their HTML pages
 /// </summary>
 /// <param name="ytUrl">A YouTubeURL object</param>
 public YouTubeVideoPage(YouTubeUrl ytUrl) : base (ytUrl.LongYTURL.AbsoluteUri)
 {
     VideoUrl = ytUrl;
 }
Example #5
0
        private static void OnHtmlDownloaded(HttpResponse response, YouTubeQuality quality, Action<Exception> onFinished)
        {
            if (response.Successful)
            {
                var urls = new List<YouTubeUrl>();
                try
                {
                    var match = Regex.Match(response.Response, "url_encoded_fmt_stream_map=(.*?)(&|\")");
                    var data = Uri.UnescapeDataString(match.Groups[1].Value);

                    var arr = data.Split(',');
                    foreach (var d in arr)
                    {
                        var tuple = new YouTubeUrl();
                        foreach (var p in d.Split('&'))
                        {
                            var index = p.IndexOf('=');
                            if (index != -1 && index < p.Length)
                            {
                                try
                                {
                                    var key = p.Substring(0, index);
                                    var value = Uri.UnescapeDataString(p.Substring(index + 1));
                                    if (key == "url")
                                        tuple.Url = value;
                                    else if (key == "itag")
                                        tuple.Itag = int.Parse(value);
                                    else if (key == "type" && value.Contains("video/mp4"))
                                        tuple.Type = value;
                                }
                                catch { }
                            }
                        }

                        if (tuple.IsValid)
                            urls.Add(tuple);
                    }

                    var itag = GetQualityIdentifier(quality);
                    foreach (var u in urls.Where(u => u.Itag > itag).ToArray())
                        urls.Remove(u);
                }
                catch (Exception ex)
                {
                    if (onFinished != null)
                        onFinished(ex);
                    return;
                }

                var entry = urls.OrderByDescending(u => u.Itag).FirstOrDefault();
                if (entry != null)
                {
                    if (onFinished != null)
                        onFinished(null);

                    var url = entry.Url;
                    var launcher = new MediaPlayerLauncher
                    {
                        Controls = MediaPlaybackControls.All,
                        Media = new Uri(url, UriKind.Absolute)
                    };
                    launcher.Show();
                }
                else if (onFinished != null)
                    onFinished(new Exception("no_video_urls_found"));
            }
            else if (onFinished != null)
                onFinished(response.Exception);
        }
 /// <summary>
 /// Initializes a new instance of the YouTubeVideoThumbnail class. Provides members related to storing a YouTubeURL, URLs to video thumbnail images, and events related to downloading them.
 /// </summary>
 /// <param name="youtubeuUrl">A validated YouTube URL. (Use YouTubeURL.ValidateYTURL)</param>
 public YouTubeVideoThumbnail(string youtubeuUrl)
 {
     VideoUrl = new YouTubeUrl(youtubeuUrl);
     CreateURLs();
     GetThumbnail();
 }
Example #7
0
 //get YouTube audio links
 public string GetYoutubeUrl(string id)
 {
     return(YouTubeUrl.GetYoutubeUrl(id));
 }
Example #8
0
 //get Youtube
 public async Task <List <WebSong> > SearchYoutube(string title, string artist, int limit = 4, bool includeAudioTag = true)
 {
     return(await YouTubeUrl.SearchYoutube(title, artist, limit, includeAudioTag));
 }
 public YouTubeCommentsPage(YouTubeUrl ytUrl) : base (ytUrl.AllCommentsUri.AbsoluteUri)
 {
     VideoUrl = ytUrl;
 }