// link de uma playlist = https://www.youtube.com/playlist?list=PLb2HQ45KP0WstF2TXsreWRv-WUr5tqzy1 // link de um video = https://www.youtube.com/watch?v=KxiHM3pQbGQ public ActionResult Index(string link = null) { List <YouTubeVideo> videos = new List <YouTubeVideo>(); if (Request.IsAjaxRequest()) { if (link.Contains("https://www.youtube.com/playlist?list=")) { string[] split = link.Split('='); var playlistId = split[1].ToString(); videos = YouTubeApi.GetPlaylistInfo(playlistId); return(PartialView("_PlaylistVideos", videos)); } else { string[] split = link.Split('='); var videoId = split[1].ToString(); YouTubeVideo video = new YouTubeVideo(videoId); videos.Add(video); return(PartialView("_PlaylistVideos", videos)); } } return(View(videos)); }
protected async override Task LoadImage() { var diAlbumCover = new DirectoryInfo(HurricaneSettings.Instance.CoverDirectory); Image = MusicCoverManager.GetYouTubeImage(this, diAlbumCover); if (Image == null) { Image = MusicCoverManager.GetImage(this, diAlbumCover); } if (Image == null && HurricaneSettings.Instance.Config.LoadAlbumCoverFromInternet) { try { if (!string.IsNullOrEmpty(ThumbnailUrl)) { Image = await YouTubeApi.LoadBitmapImage(this, diAlbumCover); } if (Image == null) { Image = await MusicCoverManager.LoadCoverFromWeb(this, diAlbumCover, Uploader != Artist).ConfigureAwait(false); } } catch (WebException) { //Happens, doesn't matter } } }
public async Task <List <PlayableBase> > GetTracks(ProgressDialogController controller) { var currentPlaylist = this; var resultList = new List <PlayableBase>(); for (int i = 0; i < (int)Math.Ceiling((double)TotalTracks / 50); i++) { var tracks = YouTubeApi.GetPlaylistTracks(await YouTubeApi.GetPlaylist(PlaylistId, currentPlaylist.nextPageToken, 50)); for (int j = 0; j < tracks.Count; j++) { var track = tracks[j]; if (LoadingTracksProcessChanged != null) { LoadingTracksProcessChanged(this, new LoadingTracksEventArgs(i * 50 + j, TotalTracks, track.Title)); } resultList.Add(track.ToPlayable()); if (controller.IsCanceled) { return(null); } } } return(resultList); }
public ValuesController() { var youTubeApi = new YouTubeApi(AppConsts.OAuthGoogleId, AppConsts.OAuthGoogleSecret, AppConsts.AppName); var lastFmApi = new LastFmApi(AppConsts.LastfmApiKey, AppConsts.LastfmApiSecret); this.geniusApi = new GeniusApi(AppConsts.GeniusAccessToken, youTubeApi, lastFmApi, AppConsts.GeniusClientId, AppConsts.GeniusClientSecret); }
public static void ScheduleChannelUpdates() { new[] { YouTubeApi.GetChannelIdForUsername("CaseyNeistat"), YouTubeApi.GetChannelIdForUsername("GaryVaynerchuk"), YouTubeApi.GetChannelIdForUsername("KevinRose"), "UCmh5gdwCx6lN7gEC20leNVA" //DavidDobrik }.ToList().ForEach(SheduleChannelUpdate); }
public void TestMethod1() { string id = "Z1VB6B-cGYo"; string timeStamp = DateTime.Now.Ticks.ToString(); YouTubeApi obj = new YouTubeApi(); // YouTubeApi.GetVideoInfo(id); }
static void Run(CommandLineOptions options) { var youTubeApi = new YouTubeApi(options.YouTubeKey); var playlist = youTubeApi.GetPlaylist(options.YouTubePlaylistID); foreach (var p in playlist) { Console.WriteLine(p.Title); } }
public static void UpdateVideoViewCount(string videoId) { viewCounts.Add(new VideoViewCount { DateTime = DateTime.Now, VideoId = videoId, ViewCount = (long)YouTubeApi.GetViewCount(videoId) }); jobs.TryRemove(videoId, out string jobId); ScheduleUpdateVideoViewCount(videoId); }
public static void UpdateChannel(string channelId) { var playlistId = YouTubeApi.GetUploadsPlaylistId(channelId); var newItems = YouTubeApi.PlaylistItemsByPlaylistId(playlistId) .Except(videos.Get().Select(v => v.VideoId)); foreach (var newItem in newItems) { videos.Add(newItem); } }
public async Task When_getting_videos_then_they_are_saved( [Frozen] IYouTubeServiceWrapper youtubeServiceWrapper, YouTubeApi youTubeApi ) { // Setup youtubeServiceWrapper.GetPlaylists().Returns(new List <Playlist>()); // Act await foreach (var _ in youTubeApi.GetVideos(new List <string>())) { } }
// Get api/yapi public Dictionary <string, int> GetChannel(int videoCount) { Dictionary <string, int> channelId = new Dictionary <string, int>(); //channelId.Add("Test", 1); //YouTubeApi obj = new YouTubeApi(); //string accessToken = Request.Headers.GetValues("Authorization").First().ToString().Split()[1]; //User.Claims.FirstOrDefault(c => c.SomeProperty == "access_token") //YouTubeApi.AccessToken = accessToken; //YouTubeApi obj = new YouTubeApi(); channelId = YouTubeApi.GetChannel(videoCount); return(channelId); }
protected async override Task LoadImage(DirectoryInfo albumCoverDirectory) { if (albumCoverDirectory.Exists) { var imageFile = albumCoverDirectory.GetFiles("*.jpg") .FirstOrDefault(item => item.Name.ToLower() == YouTubeId.ToLower()); if (imageFile != null) { Image = new BitmapImage(new Uri(imageFile.FullName)); return; } Image = MusicCoverManager.GetAlbumImage(this, albumCoverDirectory); if (Image != null) { return; } } if (HurricaneSettings.Instance.Config.LoadAlbumCoverFromInternet) { try { if (!string.IsNullOrEmpty(ThumbnailUrl)) { Image = await YouTubeApi.LoadBitmapImage(this, albumCoverDirectory); if (Image != null) { return; } } Image = await MusicCoverManager.LoadCoverFromWeb(this, albumCoverDirectory, Uploader != Artist); } catch (WebException) { //Happens, doesn't matter } } }
public static void UpdateVideo(string videoId) { videos.UpdateTitle(videoId, YouTubeApi.GetTitle(videoId)); }
public void Initialize(Rendering rendering) { //Get current item var dataSource = rendering.DataSource; if (dataSource.IsNullOrEmpty()) { dataSource = Sitecore.Configuration.Settings.GetSetting("FeedsDataSource", "{AF7BCA0A-4C7F-4ACA-9956-E4801143775A}"); } CurrentItem = Sitecore.Context.Database.GetItem(dataSource); if (CurrentItem != null) { // Get all social feeds items var socialFeeds = CurrentItem.InnerItem.GetChildren().ToList(); FacebookApi = new FacebookApi(); TwitterApi = new TwitterApi(); InstagramApi = new InstagramApi(); YouTubeApi = new YouTubeApi(); PinterestApi = new PinterestApi(); FlickrApi = new FlickrApi(); if (socialFeeds.Any()) { // Get facebook feed item and bind facebook api class properties var facebookFeedItem = socialFeeds.FirstOrDefault(i => i.IsOfType(FacebookFeed.TemplateId)); if (facebookFeedItem != null) { var facebookFeed = new FacebookFeed(facebookFeedItem); if (facebookFeed != null) { if (facebookFeed.FacebookAccount.TargetItem != null) { var facebookAccount = new FacebookAccount(facebookFeed.FacebookAccount.TargetItem); if (facebookAccount.SocialLink != null) { if (!ShowSocialFeed) { ShowSocialFeed = true; } FacebookApi.ApiId = string.Join("|", new string[] { facebookAccount.ApiId.Value, facebookAccount.ApiKey.Value }); FacebookApi.Icon = facebookAccount.SocialLink != null ? MediaManager.GetMediaUrl( new SocialMedia(facebookAccount.SocialLink.TargetItem).SocialIcon.MediaItem) : ""; // new BaseFeed() FacebookApi.Priority = GetPriority(facebookFeed.BaseFeed); } } } } // Get twitter feed item and bind twitter api class properties var twitterFeedItem = socialFeeds.FirstOrDefault(i => i.IsOfType(TwitterFeed.TemplateId)); if (twitterFeedItem != null) { var twitterFeed = new TwitterFeed(twitterFeedItem); if (twitterFeed != null) { if (twitterFeed.TwitterAccount.TargetItem != null) { var twitterAccount = new TwitterAccount(twitterFeed.TwitterAccount.TargetItem); if (!ShowSocialFeed) { ShowSocialFeed = true; } TwitterApi.HashTagsWithTokens = string.Join("|", new string[] { string.Join(",", twitterFeed.Hashtags.GetItems().Select(i => new Hashtag(i).Value.Value)), twitterAccount.TwitterToken.Value, twitterAccount.TwitterTokenSecret.Value, twitterAccount.TwitterConsumerKey.Value, twitterAccount.TwitterConsumerSecret.Value }); TwitterApi.Icon = twitterAccount.SocialLink != null ? MediaManager.GetMediaUrl( new SocialMedia(twitterAccount.SocialLink.TargetItem).SocialIcon.MediaItem) : ""; TwitterApi.Priority = GetPriority(twitterFeed.BaseFeed); } } } // Get instagram feed item and bind instagram api class properties var instagramFeedItem = socialFeeds.FirstOrDefault(i => i.IsOfType(InstagramFeed.TemplateId)); if (instagramFeedItem != null) { var instagramFeed = new InstagramFeed(instagramFeedItem); if (instagramFeed != null) { if (instagramFeed.InstagramAccount.TargetItem != null) { var instagramAccount = new InstagramAccount(instagramFeed.InstagramAccount.TargetItem); if (!ShowSocialFeed) { ShowSocialFeed = true; } InstagramApi.HashTags = string.Join(",", instagramFeed.Hashtags.GetItems().Select(i => new Hashtag(i).Value.Value)); InstagramApi.AccessToken = instagramAccount.AccessToken.Value; InstagramApi.ClientId = instagramAccount.InstagramClientId.Value; InstagramApi.Icon = instagramAccount.SocialLink != null ? MediaManager.GetMediaUrl( new SocialMedia(instagramAccount.SocialLink.TargetItem).SocialIcon.MediaItem) : ""; InstagramApi.Priority = GetPriority(instagramFeed.BaseFeed); } } } // Get youtube feed item and bind youtube api class properties var youTubeFeedItem = socialFeeds.FirstOrDefault(i => i.IsOfType(YoutubeFeed.TemplateId)); if (youTubeFeedItem != null) { var youTubeFeed = new YoutubeFeed(youTubeFeedItem); if (youTubeFeed.YouTubeAccount.TargetItem != null) { var youtubeAccount = new YoutubeAccount(youTubeFeed.YouTubeAccount.TargetItem); if (!ShowSocialFeed) { ShowSocialFeed = true; } YouTubeApi.AccountId = youtubeAccount.AccountId.Value; YouTubeApi.AccountApiKey = youtubeAccount.AccountApiKey.Value; YouTubeApi.Icon = youtubeAccount.SocialLink != null ? MediaManager.GetMediaUrl( new SocialMedia(youtubeAccount.SocialLink.TargetItem).SocialIcon.MediaItem) : ""; YouTubeApi.Priority = GetPriority(youTubeFeed.BaseFeed); } } // Get pinterest feed item and bind pinterest api class properties var pinterestFeedItem = socialFeeds.FirstOrDefault(i => i.IsOfType(PinterestFeed.TemplateId)); if (pinterestFeedItem != null) { var pinterestFeed = new PinterestFeed(pinterestFeedItem); if (pinterestFeed != null && pinterestFeed.PinterestAccount.TargetItem != null) { var pinterestAccount = new PinterestAccount(pinterestFeed.PinterestAccount.TargetItem); if (!ShowSocialFeed) { ShowSocialFeed = true; } PinterestApi.AccountId = pinterestAccount.AccountId.Value; PinterestApi.Icon = pinterestAccount.SocialLink != null ? MediaManager.GetMediaUrl( new SocialMedia(pinterestAccount.SocialLink.TargetItem).SocialIcon.MediaItem) : ""; PinterestApi.Priority = GetPriority(pinterestFeed.BaseFeed); } } // Get flickr feed item and bind flickr api class properties var flickrFeedItem = socialFeeds.FirstOrDefault(i => i.IsOfType(FlickrFeed.TemplateId)); if (flickrFeedItem != null) { var flickrFeed = new FlickrFeed(flickrFeedItem); if (flickrFeed != null) { if (flickrFeed.FlickrAccount.TargetItem != null) { var flickrAccount = new FlickrAccount(flickrFeed.FlickrAccount.TargetItem); if (!ShowSocialFeed) { ShowSocialFeed = true; } FlickrApi.AccountId = flickrAccount.AccountId.Value; FlickrApi.Icon = flickrAccount.SocialLink != null ? MediaManager.GetMediaUrl( new SocialMedia(flickrAccount.SocialLink.TargetItem).SocialIcon.MediaItem) : ""; FlickrApi.Priority = GetPriority(flickrFeed.BaseFeed); } } } } } }
static void Main(string[] args) { //Exception Hnadeling StreamReader streamReader = null; try { streamReader = new StreamReader(@"c:\test.zip"); var content = streamReader.ReadToEnd(); throw new Exception("!"); } catch (Exception ex) { Console.WriteLine("Error Occurred!"); } finally { if (streamReader != null) { streamReader.Dispose(); } } ///Or /// StreamReader streamReader = null; try { //using (var StreamReader = new StreamReader(@"c:\test.zip")) //{ // var content = streamReader.ReadToEnd(); //} var youtube = new YouTubeApi(); var vids = youtube.GetVideos("user"); } catch (Exception ex) { Console.WriteLine(ex.Message); } //Dynamics dynamic dynamic = "test"; dynamic = 10; dynamic a = 10; dynamic bbb = 5; var c = a + bbb; int d = a; long e = d; //Nullables DateTime?date = null; Console.WriteLine(date.GetValueOrDefault()); Console.WriteLine(date.HasValue); //Console.WriteLine(date.Value); DateTime date2 = date.GetValueOrDefault(); DateTime?date3 = date2; ///Linq Extension Methods var books1 = new BookRepository().GetBooks(); var cheapBooks1 = books1.Where(x => x.Price < 10).OrderBy(x => x.Title); //Linq Query Operator var cheaperBooks = from b in books1 where b.Price < 10 orderby b.Title select b.Title; //Extensions string post = "this is long long long post..."; var shortenedPost = post.Shorten(3); Console.WriteLine(shortenedPost); //Events var video = new Video() { Title = "Video Title 1" }; var videoEncoder = new VideoEncoder(); /// Publisher var mailService = new MailService(); // subscriber var messageService = new MessageService(); videoEncoder.videoEncoded += mailService.OnVideoEncoded; videoEncoder.videoEncoded += messageService.OnVideoEncoded; videoEncoder.Encode(video); // => const int factor = 5; Func <int, int> multipler = n => n * factor; Console.WriteLine(multipler(5)); var books = new BookRepository().GetBooks(); //var cheapBooks = books.FindAll(IsCheaperThan10Dollars); var cheapBooks = books.FindAll(b => b.Price < 10); foreach (var book in cheapBooks) { Console.WriteLine(book.Title); } //Delegates var photo = new PhotoProcessor(); var filters = new PhotoFilters(); //PhotoProcessor.PhotoFilterHandler filterHandler = filters.ApplyBrightness; Action <Photo> filterHandler = filters.ApplyBrightness; filterHandler += filters.ApplyContrast; filterHandler += RemoveRedEyeFilter; photo.Process("test", filterHandler); //Generics var numbers = new Generic <int>(); numbers.Add(10); var dictionary = new GenericDictionary <string, Book>(); dictionary.Add("1", new Book()); var NUMBER = new AdvancedTopics.Nullable <int>(); Console.WriteLine("Has Value? " + NUMBER.HasValue); Console.WriteLine("Value: " + NUMBER.GetValueOrDefault()); //Or You can use System.Nullable for this purpose. }
public YouTubeApiTests() { var key = Utils.ReadYouTubeApiKeyFromUserSecrets(); _subject = new YouTubeApi(key); }