public async Task <EditVideoPageModel> Run() { try { var model = new EditVideoPageModel(); var youtubeService = new YouTubeService(new BaseClientService.Initializer() { // ApiKey = "AIzaSyDxag54giZC4yPfNCa20z_RkVu01Zyehxs", // need to change later ApiKey = "AIzaSyA1N-_xPPAz-O1l-RPe7KouhDUdcobCw_M", //New api key by Suryabhan //ApiKey = "AIzaSyDEyXRUAId5G2kTwitTyyEHi-ZNL09AvLI", ApplicationName = this.GetType().ToString() }); // get category of US region var categories = youtubeService.VideoCategories.List("snippet"); var languages = youtubeService.I18nLanguages.List("snippet"); var playList = youtubeService.Playlists.List("snippet"); //var contents = youtubeService..List("snippet"); //playList.Callbac = true; categories.RegionCode = "US"; // need to change later var listLanguage = languages.Execute().Items.Select(i => new SelectItem() { id = i.Id, name = i.Snippet.Name, }).ToList(); // cast category to a list return to client for render var listCategory = categories.Execute().Items.Where(i => i.Snippet.Assignable == true).Select(i => new SelectItem() { id = i.Id, name = i.Snippet.Title, }).ToList(); model.categories = listCategory; model.languages = listLanguage; model.contents = new List <SelectItem>() { new SelectItem() { id = ((int)EVideoContentType.ForAll).ToString(), name = EVideoContentType.ForAll.ToString(), }, new SelectItem() { id = ((int)EVideoContentType.ForAdult).ToString(), name = EVideoContentType.ForAdult.ToString(), }, new SelectItem() { id = ((int)EVideoContentType.ForKid).ToString(), name = EVideoContentType.ForKid.ToString(), } }; model.levels = new List <SelectItem>() { new SelectItem() { id = ((int)EVideoLevel.Basic).ToString(), name = EVideoLevel.Basic.ToString(), }, new SelectItem() { id = ((int)EVideoLevel.Bronze).ToString(), name = EVideoLevel.Bronze.ToString(), }, new SelectItem() { id = ((int)EVideoLevel.Sliver).ToString(), name = EVideoLevel.Sliver.ToString(), }, new SelectItem() { id = ((int)EVideoLevel.Gold).ToString(), name = EVideoLevel.Gold.ToString(), }, }; model.privacies = new List <SelectItem>() { new SelectItem() { id = ((int)EVideoPrivacy.Standard).ToString(), name = EVideoPrivacy.Standard.ToString(), }, new SelectItem() { id = ((int)EVideoPrivacy.CC).ToString(), name = EVideoPrivacy.CC.ToString(), }, }; return(model); } catch (Exception ex) { return(null); } }
//show videos by region code. public async Task <ResponseModel> GetVideoList(string regionCode) { try { var ApiKey = "AIzaSyA8hPK8F-8BbO-8H6tQZuiopY5nYES1UR0"; var model = new EditVideoPageModel(); var youtubeService = new YouTubeService(new BaseClientService.Initializer() { ApiKey = ApiKey, ApplicationName = this.GetType().ToString() }); // get category of US region //var categories = youtubeService.VideoCategories.List("snippet"); //var languages = youtubeService.I18nLanguages.List("snippet"); //var playList = youtubeService.Playlists.List("snippet"); //var contents = youtubeService..List("snippet"); //gapi.client.youtube.videos.list({ part: 'snippet,id', chart: 'mostPopular', regionCode: 'RU', maxResults: 8 }) //playList.Callbac = true; VideosResource.ListRequest search_response = youtubeService.Videos.List("snippet,contentDetails,statistics"); //search_response.Type = "video"; search_response.RegionCode = regionCode; search_response.Chart = VideosResource.ListRequest.ChartEnum.MostPopular; search_response.MaxResults = 50; //search_response.ChannelId = channelId; VideoListResponse searchresponse = search_response.Execute(); List <string> videos = new List <string>(); List <string> channels = new List <string>(); List <string> playlists = new List <string>(); // Add each result to the appropriate list, and then display the lists of // matching videos, channels, and playlists. List <YoutubeModel> searchmodel = new List <YoutubeModel>(); YoutubeModel obj = null; foreach (var searchResult in searchresponse.Items) { obj = new YoutubeModel(); obj.title = searchResult.Snippet.Title; obj.regionCode = regionCode; obj.url = "https://youtu.be/" + searchResult.Id; obj.description = searchResult.Snippet.Description; obj.picture = GetMainImg(searchResult.Snippet.Thumbnails); obj.thumbnail = GetThumbnailImg(searchResult.Snippet.Thumbnails); obj.publishedAt = searchResult.Snippet.PublishedAt; obj.channelId = searchResult.Snippet.ChannelId; obj.channelTitle = searchResult.Snippet.ChannelTitle; obj.duration = GetDuration(searchResult.ContentDetails.Duration); obj.viewCount = searchResult.Statistics.ViewCount.ToString(); obj.likeCount = searchResult.Statistics.LikeCount.ToString(); obj.dislikeCount = searchResult.Statistics.DislikeCount.ToString(); obj.favoriteCount = searchResult.Statistics.FavoriteCount.ToString(); obj.commentCount = searchResult.Statistics.CommentCount.ToString(); searchmodel.Add(obj); videos.Add(String.Format("{0} ({1})", searchResult.Snippet.Title, "https://youtu.be/" + searchResult.Id)); } response.Data = searchmodel; } catch (Exception ex) { response.Message = ex.Message; } response.Status_Code = 200; response.Success = true; return(response); }