public void unsubscribeChannel() { Console.WriteLine("Enter your youtube channel name: "); String yourName = Console.ReadLine(); Console.WriteLine("Enter youtube channel to unsubscribe: "); String channelName = Console.ReadLine(); try { YouTubeChannel subscriber = channels[yourName]; try { YouTubeChannel channel = channels[channelName]; subscriber.unsubscribe(channel); } catch (KeyNotFoundException) { Console.WriteLine("Youtube channel name you want to unsubscribe does not exist!"); } } catch (KeyNotFoundException) { Console.WriteLine("Your youtube channel name is incorrect!"); } }
public void unsubscribeAccount(Dictionary <String, YouTubeChannel> channels) { Console.WriteLine("Enter your google account username: "******"Enter youtube channel to unsubscribe: "); String channelName = Console.ReadLine(); try { GoogleAccount googleAccount = this.googleAccounts[username]; try { YouTubeChannel channel = channels[channelName]; googleAccount.unsubscribe(channel); } catch (KeyNotFoundException) { Console.WriteLine("Youtube channel name you want to unsubscribe does not exist!"); } } catch (KeyNotFoundException) { Console.WriteLine("Your google account name is incorrect!"); } }
public void clearYouTubeChannelNotifications() { Console.WriteLine("Enter youtube channel name: "); String channelName = Console.ReadLine(); try { YouTubeChannel channel = channels[channelName]; channel.clearNotifications(); } catch (KeyNotFoundException) { Console.WriteLine("Youtube channel name does not exist!"); } }
public void addVideoToPlaylist() { Console.WriteLine("Enter youtube channel: "); String channelName = Console.ReadLine(); try { YouTubeChannel channel = channels[channelName]; channel.addVideoToPlaylist(); } catch (KeyNotFoundException) { Console.WriteLine("Youtube channel name does not exist!"); } }
public void switchTypeOfChannel() { Console.WriteLine("Enter youtube channel: "); String channelName = Console.ReadLine(); try { YouTubeChannel channel = channels[channelName]; channel.switchTypeOfChannel(); } catch (KeyNotFoundException) { Console.WriteLine("Youtube channel name does not exist!"); } }
public async Task YouTubeService_GetChannelById() { var service = CreateService(); var channelRequest = service.Channels.List("id,snippet,statistics"); var id = "UC9-y-6csu5WGm29I7JiwpnA"; channelRequest.Id = id; var response = await channelRequest.ExecuteAsync(); var channelItem = Assert.Single(response.Items); var channel = new YouTubeChannel(channelItem); Assert.Equal(id, channel.Id); Assert.Equal("Computerphile", channel.Title); Assert.True(channel.Subscribers > 100000); }
public static void CreateHtmlPage(YouTubeChannel channel, string outputUrl) { var stringWriter = new StringWriter(); using (var writer = new HtmlTextWriter(stringWriter)) { writer.RenderBeginTag(HtmlTextWriterTag.Html); writer.RenderBeginTag(HtmlTextWriterTag.Head); writer.RenderBeginTag(HtmlTextWriterTag.Title); writer.Write("Telerik Academy Videos"); writer.RenderEndTag(); writer.RenderEndTag(); writer.RenderBeginTag(HtmlTextWriterTag.Body); foreach (var video in channel.Videos) { writer.AddAttribute(HtmlTextWriterAttribute.Style, "height: 500px; width: 600px; text-align: center;"); writer.RenderBeginTag(HtmlTextWriterTag.Div); writer.AddAttribute(HtmlTextWriterAttribute.Width, "600px"); writer.AddAttribute(HtmlTextWriterAttribute.Height, "400px;"); writer.AddAttribute(HtmlTextWriterAttribute.Style, "display:block; margin-bottom: 15px;"); writer.AddAttribute(HtmlTextWriterAttribute.Src, $"https://www.youtube.com/embed/{video.VideoID}"); writer.RenderBeginTag(HtmlTextWriterTag.Iframe); writer.RenderEndTag(); writer.AddAttribute(HtmlTextWriterAttribute.Href, $"{video.Link}"); writer.AddAttribute(HtmlTextWriterAttribute.Style, $"padding: 10px; margin: 10px; background-color: red; color: white; text-decoration: none; font-size: 15px; border-radius: 4px;"); writer.RenderBeginTag(HtmlTextWriterTag.A); writer.Write("YouTube Link"); writer.RenderEndTag(); writer.RenderEndTag(); } writer.RenderEndTag(); writer.RenderEndTag(); } File.WriteAllText(outputUrl, stringWriter.ToString(), Encoding.Unicode); stringWriter.Dispose(); }
static void Main(string[] args) { YouTubeChannel Youtube = new YouTubeChannel(); //Create new youtube account! ISubscriber Joey = new User(); ISubscriber Alex = new User(); ISubscriber Gai = new Moderator(); Youtube.Subscribe(Joey); Youtube.Subscribe(Alex); Youtube.Subscribe(Gai); Youtube.NotifySubscribers(); //I upload a new video! Console.WriteLine("Alex unsubscribed"); Youtube.Unsubscribe(Alex); Youtube.NotifySubscribers(); Console.Read(); }
static void Main(string[] args) { YouTubeChannel myChannel = new YouTubeChannel(); ISubscriber joey = new User("Joey"); ISubscriber alex = new User("Alex"); ISubscriber guy = new Moderator(); myChannel.Subscribe(joey); myChannel.Subscribe(alex); myChannel.Subscribe(guy); myChannel.NotifySubscribers(); Console.ReadKey(); myChannel.Unsubscribe(alex); myChannel.NotifySubscribers(); Console.ReadKey(); }
static void Main(string[] args) { //var subject = new Subject(); //var ob1 = new Observer("Observer_1", subject); //var ob2 = new Observer("Observer_2", subject); //subject.Attach(ob1); //subject.Attach(ob2); //subject.State = "UPDATED!!!"; var youtubeChannel = new YouTubeChannel(); var client = new Client("Rami"); var admin = new ChannelAdmin("John"); youtubeChannel.Subscribe(client); youtubeChannel.Subscribe(admin); youtubeChannel.LastVideo = "C# Design Patterns"; Console.ReadLine(); }
static void Main(string[] args) { YouTubeChannel RedChannel = new YouTubeChannel(); // Create new youtube account. ISubscriber Joey = new User(); ISubscriber Alex = new User(); ISubscriber Gal = new Moderator(); RedChannel.Subscribe(Joey); RedChannel.Subscribe(Alex); RedChannel.Subscribe(Gal); Console.WriteLine(" --- I upload a new video. --- "); RedChannel.NotifySubscribers(); // I upload a new video. Console.WriteLine(" --- Alex unsubscribe. --- "); RedChannel.Unsubscribe(Alex); Console.WriteLine(" --- I upload a new video. --- "); RedChannel.NotifySubscribers(); // I upload a new video. Console.ReadKey(); }
public static void Main() { var webClient = new WebClient(); var address = "https://www.youtube.com/feeds/videos.xml?channel_id=UCLC-vbm7OWvpbqzXaoAMGGw"; var xmlUrl = "../../telerik-academy-rss.xml"; webClient.DownloadFile(address, xmlUrl); var doc = new XmlDocument(); doc.Load(xmlUrl); var json = JsonConvert.SerializeXmlNode(doc, Newtonsoft.Json.Formatting.Indented); var telerikRss = JObject.Parse(json)["feed"]; // Task 4. Using LINQ-to-JSON select all video titles and print them on the console. var videoNames = telerikRss["entry"] .Children() .Select(x => x.Value <string>("title")) .ToList(); Console.WriteLine(string.Join("\n", videoNames)); // Task 5. Parse the videos' JSON to POCO. var videos = telerikRss["entry"] .Children() .Select(video => new Video((string)video["title"], (string)video["author"]["name"], (string)video["yt:videoId"], (string)video["link"]["@href"], (DateTime)video["published"])) .ToList(); var telerikChannel = new YouTubeChannel((string)telerikRss["title"], (string)telerikRss["link"][0]["@href"], videos); // Task 6. Using the POCOs create a HTML page that shows all videos from the RSS. // Html located in the project folder! var htmlOutputUrl = "../../telerik-academy-youtube.html"; HtmlWriterPoco.CreateHtmlPage(telerikChannel, htmlOutputUrl); }
/// <summary> /// Assuming the value of the string is a valid channel name, this method will get the videos of the specified /// channel. Theresponse uses pagination, so you might need to make multiple calls to get all videos of a /// channel. /// </summary> /// <param name="channelName">The name of the channel (use the authors name for their default channel).</param> /// <param name="offset">The offset (must be 1 or higher - default is 1).</param> public static YouTubeChannel GetChannel(this string channelName, int offset) { return(YouTubeChannel.GetChannel(channelName, offset)); }
/// <summary> /// Assuming the value of the string is a valid channel name, this method will get the videos of the specified /// channel. Theresponse uses pagination, so you might need to make multiple calls to get all videos of a /// channel. /// </summary> /// <param name="channelName">The name of the channel (use the authors name for their default channel).</param> /// <param name="offset">The offset (must be 1 or higher - default is 1).</param> /// <param name="maxResults">The maximum of videos per page (cannot be greater than 50).</param> public static YouTubeChannel GetChannel(this string channelName, int offset, int maxResults) { return(YouTubeChannel.GetChannel(channelName, offset, maxResults)); }
/// <summary> /// Assuming the value of the string is a valid channel name, this method will get the videos of the specified /// channel. Theresponse uses pagination, so you might need to make multiple calls to get all videos of a /// channel. /// </summary> /// <param name="channelName">The name of the channel (use the authors name for their default channel).</param> public static YouTubeChannel GetChannel(this string channelName) { return(YouTubeChannel.GetChannel(channelName)); }
public static void CallObserverPattern() { var myYouTubeChannel = new YouTubeChannel(); var myTwitterChannel = new TwitterChannel(); //subscriber list ISubscriber prem1 = new PremiumSubscriber(); ISubscriber prem2 = new PremiumSubscriber(); ISubscriber prem3 = new PremiumSubscriber(); ISubscriber reg1 = new RegularSubscriber(); ISubscriber reg2 = new RegularSubscriber(); ISubscriber mod1 = new Moderator(); ISubscriber mod2 = new Moderator(); //register subscribers YouTube Channel myYouTubeChannel.registerSubscriber(prem1); myYouTubeChannel.registerSubscriber(prem2); myYouTubeChannel.registerSubscriber(prem3); myYouTubeChannel.registerSubscriber(reg1); myYouTubeChannel.registerSubscriber(reg2); myYouTubeChannel.registerSubscriber(mod1); myYouTubeChannel.registerSubscriber(mod2); //register subscribers YouTube Channel myTwitterChannel.registerSubscriber(prem1); myTwitterChannel.registerSubscriber(reg1); myTwitterChannel.registerSubscriber(reg2); myTwitterChannel.registerSubscriber(mod1); Console.WriteLine("----------------------------------- registered youtube"); Console.WriteLine("prem1 registered for youtube channel"); Console.WriteLine("prem2 registered for youtube channel"); Console.WriteLine("prem3 registered for youtube channel"); Console.WriteLine("reg1 registered for youtube channel"); Console.WriteLine("reg2 registered for youtube channel"); Console.WriteLine("mod1 registered for youtube channel"); Console.WriteLine("mod2 registered for youtube channel"); Console.WriteLine("----------------------------------- notify subscribers - youtube"); myYouTubeChannel.notifySubscribers(); Console.WriteLine("----------------------------------- registered twitter"); Console.WriteLine("prem1 registered for twitter channel"); Console.WriteLine("reg1 registered for twitter channel"); Console.WriteLine("reg2 registered for twitter channel"); Console.WriteLine("mod1 registered for twitter channel"); //notify subscribers Console.WriteLine("----------------------------------- notify subscribers - twitter"); myTwitterChannel.notifySubscribers(); //pause Console.WriteLine("-------------------------------"); Console.WriteLine("Click button to continue"); Console.ReadKey(); //unregister some of the subscribers YouTube Channel myYouTubeChannel.unregisterSubscriber(prem1); myYouTubeChannel.unregisterSubscriber(prem3); myYouTubeChannel.unregisterSubscriber(reg2); myYouTubeChannel.unregisterSubscriber(mod2); Console.WriteLine("----------------------------------- unregistered youtube"); Console.WriteLine("prem1 unregistered for youtube channel"); Console.WriteLine("prem3 unregistered for youtube channel"); Console.WriteLine("reg2 unregistered for youtube channel"); Console.WriteLine("mod2 unregistered for youtube channel"); Console.WriteLine("----------------------------------- notify subscribers - youtube"); myYouTubeChannel.notifySubscribers(); Console.WriteLine("-----------------------------------"); myTwitterChannel.unregisterSubscriber(prem1); myTwitterChannel.unregisterSubscriber(prem2); myTwitterChannel.unregisterSubscriber(reg1); myTwitterChannel.unregisterSubscriber(mod1); Console.WriteLine("----------------------------------- unregistered twitter"); Console.WriteLine("prem1 unregistered for twitter channel"); Console.WriteLine("prem2 unregistered for twitter channel"); Console.WriteLine("reg1 unregistered for twitter channel"); Console.WriteLine("mod1 unregistered for twitter channel"); //notify subscribers Console.WriteLine("----------------------------------- notify subscribers - twitter"); myTwitterChannel.notifySubscribers(); Console.WriteLine("-----------------------------------"); }
public async Task <ActionResult> YouTubeViewUploads(CancellationToken cancellationToken) { UserCredential credential; string cs = System.Web.HttpContext.Current.Server.MapPath("~/client_secrets_testWebApplication.json"); using (var stream = new FileStream(cs, FileMode.Open, FileAccess.Read)) { credential = await GoogleWebAuthorizationBroker.AuthorizeAsync( GoogleClientSecrets.Load(stream).Secrets, // This OAuth 2.0 access scope allows an application to upload files to the // authenticated user's YouTube channel, but doesn't allow other types of access. new[] { YouTubeService.Scope.Youtube, YouTubeService.Scope.YoutubeUpload }, User.Identity.Name, CancellationToken.None ); } //check scope with this URL //https://www.googleapis.com/oauth2/v1/tokeninfo?access_token={ACCESS-TOKEN} // This bit checks if the token is out of date, // and refreshes the access token using the refresh token. //if (credential.Token.IsExpired(SystemClock.Default)) //{ // if (!await credential.RefreshTokenAsync(CancellationToken.None)) // { // Console.WriteLine("No valid refresh token."); // } //} //var result = await new AuthorizationCodeMvcApp(this, new AppFlowMetadata()).AuthorizeAsync(cancellationToken); //if (result.Credential != null) { var youTubeChannels = new List <YouTubeChannel>(); var service = new YouTubeService(new BaseClientService.Initializer { HttpClientInitializer = credential, ApplicationName = this.ApplicationName }); // Grab users owned channels var channelListRequest = service.Channels.List("snippet,contentDetails"); channelListRequest.Mine = true; var channelListResponse = await channelListRequest.ExecuteAsync(); foreach (var channel in channelListResponse.Items) { var youTubeChannel = new YouTubeChannel(channel); // Grab the ID of the Upload List from the channel var uploadListId = channel.ContentDetails.RelatedPlaylists.Uploads; // Fetch the videos belonging to the Upload List - We'll have to use paging here var nextPageToken = string.Empty; while (nextPageToken != null) { var playlistItemsListRequest = service.PlaylistItems.List("snippet"); playlistItemsListRequest.PlaylistId = uploadListId; playlistItemsListRequest.MaxResults = 50; playlistItemsListRequest.PageToken = nextPageToken; var playlistItemsResponse = await playlistItemsListRequest.ExecuteAsync(); foreach (var playlistItem in playlistItemsResponse.Items) { youTubeChannel.Videos.Add(new YouTubeVideo(playlistItem)); } nextPageToken = playlistItemsResponse.NextPageToken; } youTubeChannels.Add(youTubeChannel); } return(View(youTubeChannels)); } // else // { // return new RedirectResult(result.RedirectUri); // } }